aboutsummaryrefslogtreecommitdiffstats
path: root/arch/v850/lib
diff options
context:
space:
mode:
Diffstat (limited to 'arch/v850/lib')
-rw-r--r--arch/v850/lib/Makefile6
-rw-r--r--arch/v850/lib/ashldi3.c62
-rw-r--r--arch/v850/lib/ashrdi3.c63
-rw-r--r--arch/v850/lib/checksum.c154
-rw-r--r--arch/v850/lib/lshrdi3.c62
-rw-r--r--arch/v850/lib/memcpy.c92
-rw-r--r--arch/v850/lib/memset.c68
-rw-r--r--arch/v850/lib/muldi3.c61
-rw-r--r--arch/v850/lib/negdi2.c25
9 files changed, 593 insertions, 0 deletions
diff --git a/arch/v850/lib/Makefile b/arch/v850/lib/Makefile
new file mode 100644
index 000000000000..1c78b728a117
--- /dev/null
+++ b/arch/v850/lib/Makefile
@@ -0,0 +1,6 @@
1#
2# arch/v850/lib/Makefile
3#
4
5lib-y = ashrdi3.o ashldi3.o lshrdi3.o muldi3.o negdi2.o \
6 checksum.o memcpy.o memset.o
diff --git a/arch/v850/lib/ashldi3.c b/arch/v850/lib/ashldi3.c
new file mode 100644
index 000000000000..9e792d53f0e4
--- /dev/null
+++ b/arch/v850/lib/ashldi3.c
@@ -0,0 +1,62 @@
1/* ashldi3.c extracted from gcc-2.95.2/libgcc2.c which is: */
2/* Copyright (C) 1989, 92-98, 1999 Free Software Foundation, Inc.
3
4This file is part of GNU CC.
5
6GNU CC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU CC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU CC; see the file COPYING. If not, write to
18the Free Software Foundation, 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
20
21#define BITS_PER_UNIT 8
22
23typedef int SItype __attribute__ ((mode (SI)));
24typedef unsigned int USItype __attribute__ ((mode (SI)));
25typedef int DItype __attribute__ ((mode (DI)));
26typedef int word_type __attribute__ ((mode (__word__)));
27
28struct DIstruct {SItype high, low;};
29
30typedef union
31{
32 struct DIstruct s;
33 DItype ll;
34} DIunion;
35
36DItype
37__ashldi3 (DItype u, word_type b)
38{
39 DIunion w;
40 word_type bm;
41 DIunion uu;
42
43 if (b == 0)
44 return u;
45
46 uu.ll = u;
47
48 bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
49 if (bm <= 0)
50 {
51 w.s.low = 0;
52 w.s.high = (USItype)uu.s.low << -bm;
53 }
54 else
55 {
56 USItype carries = (USItype)uu.s.low >> bm;
57 w.s.low = (USItype)uu.s.low << b;
58 w.s.high = ((USItype)uu.s.high << b) | carries;
59 }
60
61 return w.ll;
62}
diff --git a/arch/v850/lib/ashrdi3.c b/arch/v850/lib/ashrdi3.c
new file mode 100644
index 000000000000..78efb65e315a
--- /dev/null
+++ b/arch/v850/lib/ashrdi3.c
@@ -0,0 +1,63 @@
1/* ashrdi3.c extracted from gcc-2.7.2/libgcc2.c which is: */
2/* Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
3
4This file is part of GNU CC.
5
6GNU CC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU CC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU CC; see the file COPYING. If not, write to
18the Free Software Foundation, 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
20
21#define BITS_PER_UNIT 8
22
23typedef int SItype __attribute__ ((mode (SI)));
24typedef unsigned int USItype __attribute__ ((mode (SI)));
25typedef int DItype __attribute__ ((mode (DI)));
26typedef int word_type __attribute__ ((mode (__word__)));
27
28struct DIstruct {SItype high, low;};
29
30typedef union
31{
32 struct DIstruct s;
33 DItype ll;
34} DIunion;
35
36DItype
37__ashrdi3 (DItype u, word_type b)
38{
39 DIunion w;
40 word_type bm;
41 DIunion uu;
42
43 if (b == 0)
44 return u;
45
46 uu.ll = u;
47
48 bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
49 if (bm <= 0)
50 {
51 /* w.s.high = 1..1 or 0..0 */
52 w.s.high = uu.s.high >> (sizeof (SItype) * BITS_PER_UNIT - 1);
53 w.s.low = uu.s.high >> -bm;
54 }
55 else
56 {
57 USItype carries = (USItype)uu.s.high << bm;
58 w.s.high = uu.s.high >> b;
59 w.s.low = ((USItype)uu.s.low >> b) | carries;
60 }
61
62 return w.ll;
63}
diff --git a/arch/v850/lib/checksum.c b/arch/v850/lib/checksum.c
new file mode 100644
index 000000000000..d308b724c023
--- /dev/null
+++ b/arch/v850/lib/checksum.c
@@ -0,0 +1,154 @@
1/*
2 * INET An implementation of the TCP/IP protocol suite for the LINUX
3 * operating system. INET is implemented using the BSD Socket
4 * interface as the means of communication with the user level.
5 *
6 * MIPS specific IP/TCP/UDP checksumming routines
7 *
8 * Authors: Ralf Baechle, <ralf@waldorf-gmbh.de>
9 * Lots of code moved from tcp.c and ip.c; see those files
10 * for more names.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version
15 * 2 of the License, or (at your option) any later version.
16 *
17 * $Id: checksum.c,v 1.1 2002/09/28 14:58:40 gerg Exp $
18 */
19#include <net/checksum.h>
20#include <linux/module.h>
21#include <linux/types.h>
22#include <asm/byteorder.h>
23#include <asm/string.h>
24#include <asm/uaccess.h>
25
26static inline unsigned short from32to16 (unsigned long sum)
27{
28 unsigned int result;
29 /*
30 %0 %1
31 hsw %1, %0 H L L H
32 add %1, %0 H L H+L+C H+L
33 */
34 asm ("hsw %1, %0; add %1, %0" : "=&r" (result) : "r" (sum));
35 return result >> 16;
36}
37
38static inline unsigned int do_csum(const unsigned char * buff, int len)
39{
40 int odd, count;
41 unsigned int result = 0;
42
43 if (len <= 0)
44 goto out;
45 odd = 1 & (unsigned long) buff;
46 if (odd) {
47 result = be16_to_cpu(*buff);
48 len--;
49 buff++;
50 }
51 count = len >> 1; /* nr of 16-bit words.. */
52 if (count) {
53 if (2 & (unsigned long) buff) {
54 result += *(unsigned short *) buff;
55 count--;
56 len -= 2;
57 buff += 2;
58 }
59 count >>= 1; /* nr of 32-bit words.. */
60 if (count) {
61 unsigned int carry = 0;
62 do {
63 unsigned int w = *(unsigned int *) buff;
64 count--;
65 buff += 4;
66 result += carry;
67 result += w;
68 carry = (w > result);
69 } while (count);
70 result += carry;
71 result = (result & 0xffff) + (result >> 16);
72 }
73 if (len & 2) {
74 result += *(unsigned short *) buff;
75 buff += 2;
76 }
77 }
78 if (len & 1)
79 result += le16_to_cpu(*buff);
80 result = from32to16(result);
81 if (odd)
82 result = ((result >> 8) & 0xff) | ((result & 0xff) << 8);
83out:
84 return result;
85}
86
87/*
88 * This is a version of ip_compute_csum() optimized for IP headers,
89 * which always checksum on 4 octet boundaries.
90 */
91unsigned short ip_fast_csum(unsigned char * iph, unsigned int ihl)
92{
93 return ~do_csum(iph,ihl*4);
94}
95
96/*
97 * this routine is used for miscellaneous IP-like checksums, mainly
98 * in icmp.c
99 */
100unsigned short ip_compute_csum(const unsigned char * buff, int len)
101{
102 return ~do_csum(buff,len);
103}
104
105/*
106 * computes a partial checksum, e.g. for TCP/UDP fragments
107 */
108unsigned int csum_partial(const unsigned char *buff, int len, unsigned int sum)
109{
110 unsigned int result = do_csum(buff, len);
111
112 /* add in old sum, and carry.. */
113 result += sum;
114 if(sum > result)
115 result += 1;
116 return result;
117}
118
119EXPORT_SYMBOL(csum_partial);
120
121/*
122 * copy while checksumming, otherwise like csum_partial
123 */
124unsigned int csum_partial_copy(const unsigned char *src, unsigned char *dst,
125 int len, unsigned int sum)
126{
127 /*
128 * It's 2:30 am and I don't feel like doing it real ...
129 * This is lots slower than the real thing (tm)
130 */
131 sum = csum_partial(src, len, sum);
132 memcpy(dst, src, len);
133
134 return sum;
135}
136
137/*
138 * Copy from userspace and compute checksum. If we catch an exception
139 * then zero the rest of the buffer.
140 */
141unsigned int csum_partial_copy_from_user (const unsigned char *src, unsigned char *dst,
142 int len, unsigned int sum,
143 int *err_ptr)
144{
145 int missing;
146
147 missing = copy_from_user(dst, src, len);
148 if (missing) {
149 memset(dst + len - missing, 0, missing);
150 *err_ptr = -EFAULT;
151 }
152
153 return csum_partial(dst, len, sum);
154}
diff --git a/arch/v850/lib/lshrdi3.c b/arch/v850/lib/lshrdi3.c
new file mode 100644
index 000000000000..93b1cb6fdee8
--- /dev/null
+++ b/arch/v850/lib/lshrdi3.c
@@ -0,0 +1,62 @@
1/* lshrdi3.c extracted from gcc-2.7.2/libgcc2.c which is: */
2/* Copyright (C) 1989, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
3
4This file is part of GNU CC.
5
6GNU CC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 2, or (at your option)
9any later version.
10
11GNU CC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along with GNU CC; see the file COPYING. If not, write to
18the Free Software Foundation, 59 Temple Place - Suite 330,
19Boston, MA 02111-1307, USA. */
20
21#define BITS_PER_UNIT 8
22
23typedef int SItype __attribute__ ((mode (SI)));
24typedef unsigned int USItype __attribute__ ((mode (SI)));
25typedef int DItype __attribute__ ((mode (DI)));
26typedef int word_type __attribute__ ((mode (__word__)));
27
28struct DIstruct {SItype high, low;};
29
30typedef union
31{
32 struct DIstruct s;
33 DItype ll;
34} DIunion;
35
36DItype
37__lshrdi3 (DItype u, word_type b)
38{
39 DIunion w;
40 word_type bm;
41 DIunion uu;
42
43 if (b == 0)
44 return u;
45
46 uu.ll = u;
47
48 bm = (sizeof (SItype) * BITS_PER_UNIT) - b;
49 if (bm <= 0)
50 {
51 w.s.high = 0;
52 w.s.low = (USItype)uu.s.high >> -bm;
53 }
54 else
55 {
56 USItype carries = (USItype)uu.s.high << bm;
57 w.s.high = (USItype)uu.s.high >> b;
58 w.s.low = ((USItype)uu.s.low >> b) | carries;
59 }
60
61 return w.ll;
62}
diff --git a/arch/v850/lib/memcpy.c b/arch/v850/lib/memcpy.c
new file mode 100644
index 000000000000..492847b3e612
--- /dev/null
+++ b/arch/v850/lib/memcpy.c
@@ -0,0 +1,92 @@
1/*
2 * arch/v850/lib/memcpy.c -- Memory copying
3 *
4 * Copyright (C) 2001,02 NEC Corporation
5 * Copyright (C) 2001,02 Miles Bader <miles@gnu.org>
6 *
7 * This file is subject to the terms and conditions of the GNU General
8 * Public License. See the file COPYING in the main directory of this
9 * archive for more details.
10 *
11 * Written by Miles Bader <miles@gnu.org>
12 */
13
14#include <linux/types.h>
15#include <asm/string.h>
16
17#define CHUNK_SIZE 32 /* bytes */
18#define CHUNK_ALIGNED(addr) (((unsigned long)addr & 0x3) == 0)
19
20/* Note that this macro uses 8 call-clobbered registers (not including
21 R1), which are few enough so that the following functions don't need
22 to spill anything to memory. It also uses R1, which is nominally
23 reserved for the assembler, but here it should be OK. */
24#define COPY_CHUNK(src, dst) \
25 asm ("mov %0, ep;" \
26 "sld.w 0[ep], r1; sld.w 4[ep], r12;" \
27 "sld.w 8[ep], r13; sld.w 12[ep], r14;" \
28 "sld.w 16[ep], r15; sld.w 20[ep], r17;" \
29 "sld.w 24[ep], r18; sld.w 28[ep], r19;" \
30 "mov %1, ep;" \
31 "sst.w r1, 0[ep]; sst.w r12, 4[ep];" \
32 "sst.w r13, 8[ep]; sst.w r14, 12[ep];" \
33 "sst.w r15, 16[ep]; sst.w r17, 20[ep];" \
34 "sst.w r18, 24[ep]; sst.w r19, 28[ep]" \
35 :: "r" (src), "r" (dst) \
36 : "r1", "r12", "r13", "r14", "r15", \
37 "r17", "r18", "r19", "ep", "memory");
38
39void *memcpy (void *dst, const void *src, __kernel_size_t size)
40{
41 char *_dst = dst;
42 const char *_src = src;
43
44 if (size >= CHUNK_SIZE && CHUNK_ALIGNED(_src) && CHUNK_ALIGNED(_dst)) {
45 /* Copy large blocks efficiently. */
46 unsigned count;
47 for (count = size / CHUNK_SIZE; count; count--) {
48 COPY_CHUNK (_src, _dst);
49 _src += CHUNK_SIZE;
50 _dst += CHUNK_SIZE;
51 }
52 size %= CHUNK_SIZE;
53 }
54
55 if (size > 0)
56 do
57 *_dst++ = *_src++;
58 while (--size);
59
60 return dst;
61}
62
63void *memmove (void *dst, const void *src, __kernel_size_t size)
64{
65 if ((unsigned long)dst < (unsigned long)src
66 || (unsigned long)src + size < (unsigned long)dst)
67 return memcpy (dst, src, size);
68 else {
69 char *_dst = dst + size;
70 const char *_src = src + size;
71
72 if (size >= CHUNK_SIZE
73 && CHUNK_ALIGNED (_src) && CHUNK_ALIGNED (_dst))
74 {
75 /* Copy large blocks efficiently. */
76 unsigned count;
77 for (count = size / CHUNK_SIZE; count; count--) {
78 _src -= CHUNK_SIZE;
79 _dst -= CHUNK_SIZE;
80 COPY_CHUNK (_src, _dst);
81 }
82 size %= CHUNK_SIZE;
83 }
84
85 if (size > 0)
86 do
87 *--_dst = *--_src;
88 while (--size);
89
90 return _dst;
91 }
92}
diff --git a/arch/v850/lib/memset.c b/arch/v850/lib/memset.c
new file mode 100644
index 000000000000..d1b2ad821b15
--- /dev/null
+++ b/arch/v850/lib/memset.c
@@ -0,0 +1,68 @@
1/*
2 * arch/v850/lib/memset.c -- Memory initialization
3 *
4 * Copyright (C) 2001,02,04 NEC Corporation
5 * Copyright (C) 2001,02,04 Miles Bader <miles@gnu.org>
6 *
7 * This file is subject to the terms and conditions of the GNU General
8 * Public License. See the file COPYING in the main directory of this
9 * archive for more details.
10 *
11 * Written by Miles Bader <miles@gnu.org>
12 */
13
14#include <linux/types.h>
15
16void *memset (void *dst, int val, __kernel_size_t count)
17{
18 if (count) {
19 register unsigned loop;
20 register void *ptr asm ("ep") = dst;
21
22 /* replicate VAL into a long. */
23 val &= 0xff;
24 val |= val << 8;
25 val |= val << 16;
26
27 /* copy initial unaligned bytes. */
28 if ((long)ptr & 1) {
29 *(char *)ptr = val;
30 ptr = (void *)((char *)ptr + 1);
31 count--;
32 }
33 if (count > 2 && ((long)ptr & 2)) {
34 *(short *)ptr = val;
35 ptr = (void *)((short *)ptr + 1);
36 count -= 2;
37 }
38
39 /* 32-byte copying loop. */
40 for (loop = count / 32; loop; loop--) {
41 asm ("sst.w %0, 0[ep]; sst.w %0, 4[ep];"
42 "sst.w %0, 8[ep]; sst.w %0, 12[ep];"
43 "sst.w %0, 16[ep]; sst.w %0, 20[ep];"
44 "sst.w %0, 24[ep]; sst.w %0, 28[ep]"
45 :: "r" (val) : "memory");
46 ptr += 32;
47 }
48 count %= 32;
49
50 /* long copying loop. */
51 for (loop = count / 4; loop; loop--) {
52 *(long *)ptr = val;
53 ptr = (void *)((long *)ptr + 1);
54 }
55 count %= 4;
56
57 /* finish up with any trailing bytes. */
58 if (count & 2) {
59 *(short *)ptr = val;
60 ptr = (void *)((short *)ptr + 1);
61 }
62 if (count & 1) {
63 *(char *)ptr = val;
64 }
65 }
66
67 return dst;
68}
diff --git a/arch/v850/lib/muldi3.c b/arch/v850/lib/muldi3.c
new file mode 100644
index 000000000000..277ca25c82c8
--- /dev/null
+++ b/arch/v850/lib/muldi3.c
@@ -0,0 +1,61 @@
1/* muldi3.c extracted from gcc-2.7.2.3/libgcc2.c and
2 gcc-2.7.2.3/longlong.h which is: */
3/* Copyright (C) 1989, 1992, 1993, 1994, 1995, 2001 Free Software Foundation, Inc.
4
5This file is part of GNU CC.
6
7GNU CC is free software; you can redistribute it and/or modify
8it under the terms of the GNU General Public License as published by
9the Free Software Foundation; either version 2, or (at your option)
10any later version.
11
12GNU CC is distributed in the hope that it will be useful,
13but WITHOUT ANY WARRANTY; without even the implied warranty of
14MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15GNU General Public License for more details.
16
17You should have received a copy of the GNU General Public License
18along with GNU CC; see the file COPYING. If not, write to
19the Free Software Foundation, 59 Temple Place - Suite 330,
20Boston, MA 02111-1307, USA. */
21
22#define umul_ppmm(w1, w0, u, v) \
23 __asm__ ("mulu %3, %0, %1" \
24 : "=r" ((USItype)(w0)), \
25 "=r" ((USItype)(w1)) \
26 : "%0" ((USItype)(u)), \
27 "r" ((USItype)(v)))
28
29#define __umulsidi3(u, v) \
30 ({DIunion __w; \
31 umul_ppmm (__w.s.high, __w.s.low, u, v); \
32 __w.ll; })
33
34typedef int SItype __attribute__ ((mode (SI)));
35typedef unsigned int USItype __attribute__ ((mode (SI)));
36typedef int DItype __attribute__ ((mode (DI)));
37typedef int word_type __attribute__ ((mode (__word__)));
38
39struct DIstruct {SItype high, low;};
40
41typedef union
42{
43 struct DIstruct s;
44 DItype ll;
45} DIunion;
46
47DItype
48__muldi3 (DItype u, DItype v)
49{
50 DIunion w;
51 DIunion uu, vv;
52
53 uu.ll = u,
54 vv.ll = v;
55
56 w.ll = __umulsidi3 (uu.s.low, vv.s.low);
57 w.s.high += ((USItype) uu.s.low * (USItype) vv.s.high
58 + (USItype) uu.s.high * (USItype) vv.s.low);
59
60 return w.ll;
61}
diff --git a/arch/v850/lib/negdi2.c b/arch/v850/lib/negdi2.c
new file mode 100644
index 000000000000..571e04fc619a
--- /dev/null
+++ b/arch/v850/lib/negdi2.c
@@ -0,0 +1,25 @@
1/*
2 * arch/v850/lib/negdi2.c -- 64-bit negation
3 *
4 * Copyright (C) 2001 NEC Corporation
5 * Copyright (C) 2001 Miles Bader <miles@gnu.org>
6 *
7 * This file is subject to the terms and conditions of the GNU General
8 * Public License. See the file COPYING in the main directory of this
9 * archive for more details.
10 *
11 * Written by Miles Bader <miles@gnu.org>
12 */
13
14typedef int DItype __attribute__ ((mode (DI)));
15
16DItype __negdi2 (DItype x)
17{
18 __asm__ __volatile__
19 ("not r6, r10;"
20 "add 1, r10;"
21 "setf c, r6;"
22 "not r7, r11;"
23 "add r6, r11"
24 ::: "r6", "r7", "r10", "r11");
25}