Index: uspace/lib/softint/Makefile
===================================================================
--- uspace/lib/softint/Makefile	(revision 46c0498a16f50b4b26a1a77e39d699962cd5a946)
+++ uspace/lib/softint/Makefile	(revision d27ed127903ea6d811485f75c5dc394ec19f814e)
@@ -45,5 +45,6 @@
 
 GENERIC_SOURCES = \
-	generic/division.c
+	generic/division.c\
+	generic/multiplication.c
 
 GENERIC_OBJECTS := $(addsuffix .o,$(basename $(GENERIC_SOURCES)))
Index: uspace/lib/softint/generic/multiplication.c
===================================================================
--- uspace/lib/softint/generic/multiplication.c	(revision d27ed127903ea6d811485f75c5dc394ec19f814e)
+++ uspace/lib/softint/generic/multiplication.c	(revision d27ed127903ea6d811485f75c5dc394ec19f814e)
@@ -0,0 +1,131 @@
+/*
+ * Copyright (c) 2009 Josef Cejka
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup softint
+ * @{
+ */ 
+/**
+ * @file
+ * SW implementation of 32 and 64 bit multiplication.
+ */
+
+#include <multiplication.h>
+#include <stdint.h> 
+
+/** Set 1 to return MAX_INT64 or MIN_INT64 on overflow */
+#ifndef SOFTINT_CHECK_OF
+# define SOFTINT_CHECK_OF 0
+#endif
+
+/**
+ * Multiply two integers and return long long as result. 
+ * This function is overflow safe.
+ * @param a
+ * @param b
+ * @result
+ */
+static unsigned long long mul(unsigned int a, unsigned int b) {
+	unsigned int a1, a2, b1, b2;
+	unsigned long long t1, t2, t3;	
+
+	a1 = a >> 16;
+	a2 = a & MAX_UINT16;
+	b1 = b >> 16;
+	b2 = b & MAX_UINT16;
+
+	t1 = a1 * b1;
+	t2 = a1*b2;
+	t2 += a2*b1;
+	t3 = a2*b2;
+
+	t3 = (((t1 << 16) + t2) << 16) + t3; 
+
+	return t3;
+}
+
+/** Emulate multiplication of two 64-bit long long integers.
+ *
+ */
+long long __muldi3 (long long a, long long b)
+{
+	long long result;
+	unsigned long long t1,t2;
+	unsigned long long a1, a2, b1, b2;
+	char neg = 0;
+
+	if (a < 0) {
+		neg = !neg;
+		a = -a;
+	}
+
+	if (b < 0) {
+		neg = !neg;
+		b = -b;
+	}
+
+	a1 = a >> 32;
+	b1 = b >> 32;
+
+	a2 = a & (MAX_UINT32);
+	b2 = b & (MAX_UINT32);
+
+	if (SOFTINT_CHECK_OF && (a1 != 0) && (b1 != 0)) {
+		// error, overflow
+		return (neg?MIN_INT64:MAX_INT64);
+	}
+
+	// (if OF checked) a1 or b1 is zero => result fits in 64 bits, no need to another overflow check
+	t1 = mul(a1,b2) + mul(b1,a2);	
+
+	if (SOFTINT_CHECK_OF && t1 > MAX_UINT32) {
+		// error, overflow
+		return (neg?MIN_INT64:MAX_INT64);
+	}
+
+	t1 = t1 << 32;
+	t2 = mul(a2,b2);
+	t2 += t1;
+
+	/* t2 & (1ull << 63) - if this bit is set in unsigned long long,
+	 * result does not fit in signed one */
+	if (SOFTINT_CHECK_OF && ((t2 < t1) || (t2 & (1ull << 63)))) {
+		// error, overflow
+		return (neg?MIN_INT64:MAX_INT64);
+	}
+
+	result = t2;
+
+	if (neg) {
+		result = -result;
+	}
+
+	return result;
+}	
+
+/** @}
+ */
Index: uspace/lib/softint/include/multiplication.h
===================================================================
--- uspace/lib/softint/include/multiplication.h	(revision d27ed127903ea6d811485f75c5dc394ec19f814e)
+++ uspace/lib/softint/include/multiplication.h	(revision d27ed127903ea6d811485f75c5dc394ec19f814e)
@@ -0,0 +1,47 @@
+/*
+ * Copyright (c) 2009 Josef Cejka
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * - Redistributions of source code must retain the above copyright
+ *   notice, this list of conditions and the following disclaimer.
+ * - Redistributions in binary form must reproduce the above copyright
+ *   notice, this list of conditions and the following disclaimer in the
+ *   documentation and/or other materials provided with the distribution.
+ * - The name of the author may not be used to endorse or promote products
+ *   derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/** @addtogroup softint
+ * @{
+ */ 
+/**
+ * @file
+ */
+
+#ifndef __SOFTINT_MULTIPLICATION_H__
+#define __SOFTINT_MULTIPLICATION_H__
+
+/* 64 bit multiplication */
+long long __muldi3(long long a, long long b);
+
+#endif
+
+/** @}
+ */
+
+
