[PATCH v5 09/15] h8300: library functions

2015-02-21 Thread Yoshinori Sato
Signed-off-by: Yoshinori Sato 
---
 arch/h8300/lib/Makefile|   7 ++
 arch/h8300/lib/abs.S   |  20 ++
 arch/h8300/lib/ashldi3.c   |  24 +++
 arch/h8300/lib/ashrdi3.c   |  24 +++
 arch/h8300/lib/checksum.c  | 167 +
 arch/h8300/lib/libgcc.h|  77 +
 arch/h8300/lib/lshrdi3.c   |  23 +++
 arch/h8300/lib/memcpy.S|  85 +++
 arch/h8300/lib/memset.S|  69 +++
 arch/h8300/lib/moddivsi3.S |  72 +++
 arch/h8300/lib/modsi3.S|  72 +++
 arch/h8300/lib/muldi3.c|  44 
 arch/h8300/lib/mulsi3.S|  38 +++
 arch/h8300/lib/strncpy.S   |  34 +
 arch/h8300/lib/ucmpdi2.c   |  17 +
 arch/h8300/lib/udivsi3.S   |  76 +
 16 files changed, 849 insertions(+)
 create mode 100644 arch/h8300/lib/Makefile
 create mode 100644 arch/h8300/lib/abs.S
 create mode 100644 arch/h8300/lib/ashldi3.c
 create mode 100644 arch/h8300/lib/ashrdi3.c
 create mode 100644 arch/h8300/lib/checksum.c
 create mode 100644 arch/h8300/lib/libgcc.h
 create mode 100644 arch/h8300/lib/lshrdi3.c
 create mode 100644 arch/h8300/lib/memcpy.S
 create mode 100644 arch/h8300/lib/memset.S
 create mode 100644 arch/h8300/lib/moddivsi3.S
 create mode 100644 arch/h8300/lib/modsi3.S
 create mode 100644 arch/h8300/lib/muldi3.c
 create mode 100644 arch/h8300/lib/mulsi3.S
 create mode 100644 arch/h8300/lib/strncpy.S
 create mode 100644 arch/h8300/lib/ucmpdi2.c
 create mode 100644 arch/h8300/lib/udivsi3.S

diff --git a/arch/h8300/lib/Makefile b/arch/h8300/lib/Makefile
new file mode 100644
index 000..8311a9f
--- /dev/null
+++ b/arch/h8300/lib/Makefile
@@ -0,0 +1,7 @@
+#
+# Makefile for H8/300-specific library files..
+#
+
+lib-y  = checksum.o memcpy.o memset.o abs.o strncpy.o \
+mulsi3.o udivsi3.o muldi3.o moddivsi3.o \
+ashldi3.o lshrdi3.o ashrdi3.o ucmpdi2.o
diff --git a/arch/h8300/lib/abs.S b/arch/h8300/lib/abs.S
new file mode 100644
index 000..efda749
--- /dev/null
+++ b/arch/h8300/lib/abs.S
@@ -0,0 +1,20 @@
+;;; abs.S
+
+#include 
+
+#if defined(CONFIG_CPU_H8300H)
+   .h8300h
+#endif
+#if defined(CONFIG_CPU_H8S)
+   .h8300s
+#endif
+   .text
+.global _abs
+
+;;; int abs(int n)
+_abs:
+   mov.l   er0,er0
+   bpl 1f
+   neg.l   er0
+1:
+   rts
diff --git a/arch/h8300/lib/ashldi3.c b/arch/h8300/lib/ashldi3.c
new file mode 100644
index 000..c6aa8ea
--- /dev/null
+++ b/arch/h8300/lib/ashldi3.c
@@ -0,0 +1,24 @@
+#include "libgcc.h"
+
+DWtype
+__ashldi3(DWtype u, word_type b)
+{
+   const DWunion uu = {.ll = u};
+   const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
+   DWunion w;
+
+   if (b == 0)
+   return u;
+
+   if (bm <= 0) {
+   w.s.low = 0;
+   w.s.high = (UWtype) uu.s.low << -bm;
+   } else {
+   const UWtype carries = (UWtype) uu.s.low >> bm;
+
+   w.s.low = (UWtype) uu.s.low << b;
+   w.s.high = ((UWtype) uu.s.high << b) | carries;
+   }
+
+   return w.ll;
+}
diff --git a/arch/h8300/lib/ashrdi3.c b/arch/h8300/lib/ashrdi3.c
new file mode 100644
index 000..070adf9
--- /dev/null
+++ b/arch/h8300/lib/ashrdi3.c
@@ -0,0 +1,24 @@
+#include "libgcc.h"
+
+DWtype __ashrdi3(DWtype u, word_type b)
+{
+   const DWunion uu = {.ll = u};
+   const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
+   DWunion w;
+
+   if (b == 0)
+   return u;
+
+   if (bm <= 0) {
+   /* w.s.high = 1..1 or 0..0 */
+   w.s.high = uu.s.high >> (sizeof (Wtype) * BITS_PER_UNIT - 1);
+   w.s.low = uu.s.high >> -bm;
+   } else {
+   const UWtype carries = (UWtype) uu.s.high << bm;
+
+   w.s.high = uu.s.high >> b;
+   w.s.low = ((UWtype) uu.s.low >> b) | carries;
+   }
+
+   return w.ll;
+}
diff --git a/arch/h8300/lib/checksum.c b/arch/h8300/lib/checksum.c
new file mode 100644
index 000..ae28469
--- /dev/null
+++ b/arch/h8300/lib/checksum.c
@@ -0,0 +1,167 @@
+/*
+ * INETAn implementation of the TCP/IP protocol suite for the 
LINUX
+ * operating system.  INET is implemented using the  BSD Socket
+ * interface as the means of communication with the user level.
+ *
+ * IP/TCP/UDP checksumming routines
+ *
+ * Authors:Jorge Cwik, 
+ * Arnt Gulbrandsen, 
+ * Tom May, 
+ * Andreas Schwab, 
+ * Lots of code moved from tcp.c and ip.c; see those files
+ * for more names.
+ *
+ * 03/02/96Jes Sorensen, Andreas Schwab, Roman Hodek:
+ * Fixed some nasty bugs, causing some horrible crashes.
+ * A: At some points, the sum (%0) was used as
+ * length-counter instead of the length counter
+ * (%1). Thanks to Roman Hodek for pointing this out.
+ * 

[PATCH v5 09/15] h8300: library functions

2015-02-21 Thread Yoshinori Sato
Signed-off-by: Yoshinori Sato ys...@users.sourceforge.jp
---
 arch/h8300/lib/Makefile|   7 ++
 arch/h8300/lib/abs.S   |  20 ++
 arch/h8300/lib/ashldi3.c   |  24 +++
 arch/h8300/lib/ashrdi3.c   |  24 +++
 arch/h8300/lib/checksum.c  | 167 +
 arch/h8300/lib/libgcc.h|  77 +
 arch/h8300/lib/lshrdi3.c   |  23 +++
 arch/h8300/lib/memcpy.S|  85 +++
 arch/h8300/lib/memset.S|  69 +++
 arch/h8300/lib/moddivsi3.S |  72 +++
 arch/h8300/lib/modsi3.S|  72 +++
 arch/h8300/lib/muldi3.c|  44 
 arch/h8300/lib/mulsi3.S|  38 +++
 arch/h8300/lib/strncpy.S   |  34 +
 arch/h8300/lib/ucmpdi2.c   |  17 +
 arch/h8300/lib/udivsi3.S   |  76 +
 16 files changed, 849 insertions(+)
 create mode 100644 arch/h8300/lib/Makefile
 create mode 100644 arch/h8300/lib/abs.S
 create mode 100644 arch/h8300/lib/ashldi3.c
 create mode 100644 arch/h8300/lib/ashrdi3.c
 create mode 100644 arch/h8300/lib/checksum.c
 create mode 100644 arch/h8300/lib/libgcc.h
 create mode 100644 arch/h8300/lib/lshrdi3.c
 create mode 100644 arch/h8300/lib/memcpy.S
 create mode 100644 arch/h8300/lib/memset.S
 create mode 100644 arch/h8300/lib/moddivsi3.S
 create mode 100644 arch/h8300/lib/modsi3.S
 create mode 100644 arch/h8300/lib/muldi3.c
 create mode 100644 arch/h8300/lib/mulsi3.S
 create mode 100644 arch/h8300/lib/strncpy.S
 create mode 100644 arch/h8300/lib/ucmpdi2.c
 create mode 100644 arch/h8300/lib/udivsi3.S

diff --git a/arch/h8300/lib/Makefile b/arch/h8300/lib/Makefile
new file mode 100644
index 000..8311a9f
--- /dev/null
+++ b/arch/h8300/lib/Makefile
@@ -0,0 +1,7 @@
+#
+# Makefile for H8/300-specific library files..
+#
+
+lib-y  = checksum.o memcpy.o memset.o abs.o strncpy.o \
+mulsi3.o udivsi3.o muldi3.o moddivsi3.o \
+ashldi3.o lshrdi3.o ashrdi3.o ucmpdi2.o
diff --git a/arch/h8300/lib/abs.S b/arch/h8300/lib/abs.S
new file mode 100644
index 000..efda749
--- /dev/null
+++ b/arch/h8300/lib/abs.S
@@ -0,0 +1,20 @@
+;;; abs.S
+
+#include asm/linkage.h
+
+#if defined(CONFIG_CPU_H8300H)
+   .h8300h
+#endif
+#if defined(CONFIG_CPU_H8S)
+   .h8300s
+#endif
+   .text
+.global _abs
+
+;;; int abs(int n)
+_abs:
+   mov.l   er0,er0
+   bpl 1f
+   neg.l   er0
+1:
+   rts
diff --git a/arch/h8300/lib/ashldi3.c b/arch/h8300/lib/ashldi3.c
new file mode 100644
index 000..c6aa8ea
--- /dev/null
+++ b/arch/h8300/lib/ashldi3.c
@@ -0,0 +1,24 @@
+#include libgcc.h
+
+DWtype
+__ashldi3(DWtype u, word_type b)
+{
+   const DWunion uu = {.ll = u};
+   const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
+   DWunion w;
+
+   if (b == 0)
+   return u;
+
+   if (bm = 0) {
+   w.s.low = 0;
+   w.s.high = (UWtype) uu.s.low  -bm;
+   } else {
+   const UWtype carries = (UWtype) uu.s.low  bm;
+
+   w.s.low = (UWtype) uu.s.low  b;
+   w.s.high = ((UWtype) uu.s.high  b) | carries;
+   }
+
+   return w.ll;
+}
diff --git a/arch/h8300/lib/ashrdi3.c b/arch/h8300/lib/ashrdi3.c
new file mode 100644
index 000..070adf9
--- /dev/null
+++ b/arch/h8300/lib/ashrdi3.c
@@ -0,0 +1,24 @@
+#include libgcc.h
+
+DWtype __ashrdi3(DWtype u, word_type b)
+{
+   const DWunion uu = {.ll = u};
+   const word_type bm = (sizeof (Wtype) * BITS_PER_UNIT) - b;
+   DWunion w;
+
+   if (b == 0)
+   return u;
+
+   if (bm = 0) {
+   /* w.s.high = 1..1 or 0..0 */
+   w.s.high = uu.s.high  (sizeof (Wtype) * BITS_PER_UNIT - 1);
+   w.s.low = uu.s.high  -bm;
+   } else {
+   const UWtype carries = (UWtype) uu.s.high  bm;
+
+   w.s.high = uu.s.high  b;
+   w.s.low = ((UWtype) uu.s.low  b) | carries;
+   }
+
+   return w.ll;
+}
diff --git a/arch/h8300/lib/checksum.c b/arch/h8300/lib/checksum.c
new file mode 100644
index 000..ae28469
--- /dev/null
+++ b/arch/h8300/lib/checksum.c
@@ -0,0 +1,167 @@
+/*
+ * INETAn implementation of the TCP/IP protocol suite for the 
LINUX
+ * operating system.  INET is implemented using the  BSD Socket
+ * interface as the means of communication with the user level.
+ *
+ * IP/TCP/UDP checksumming routines
+ *
+ * Authors:Jorge Cwik, jo...@laser.satlink.net
+ * Arnt Gulbrandsen, agul...@nvg.unit.no
+ * Tom May, f...@netcom.com
+ * Andreas Schwab, sch...@issan.informatik.uni-dortmund.de
+ * Lots of code moved from tcp.c and ip.c; see those files
+ * for more names.
+ *
+ * 03/02/96Jes Sorensen, Andreas Schwab, Roman Hodek:
+ * Fixed some nasty bugs, causing some horrible crashes.
+ * A: At some points, the sum (%0) was used as
+ *