aboutsummaryrefslogtreecommitdiffstats
path: root/arch/h8300/lib
diff options
context:
space:
mode:
Diffstat (limited to 'arch/h8300/lib')
-rw-r--r--arch/h8300/lib/Makefile8
-rw-r--r--arch/h8300/lib/abs.S21
-rw-r--r--arch/h8300/lib/ashrdi3.c63
-rw-r--r--arch/h8300/lib/checksum.c159
-rw-r--r--arch/h8300/lib/memcpy.S84
-rw-r--r--arch/h8300/lib/memset.S61
-rw-r--r--arch/h8300/lib/romfs.S58
7 files changed, 454 insertions, 0 deletions
diff --git a/arch/h8300/lib/Makefile b/arch/h8300/lib/Makefile
new file mode 100644
index 000000000000..98272b66f4e5
--- /dev/null
+++ b/arch/h8300/lib/Makefile
@@ -0,0 +1,8 @@
1#
2# Makefile for H8/300-specific library files..
3#
4
5.S.o:
6 $(CC) $(AFLAGS) -D__ASSEMBLY__ -c $< -o $@
7
8lib-y = ashrdi3.o checksum.o memcpy.o memset.o abs.o romfs.o
diff --git a/arch/h8300/lib/abs.S b/arch/h8300/lib/abs.S
new file mode 100644
index 000000000000..cabdd46b41db
--- /dev/null
+++ b/arch/h8300/lib/abs.S
@@ -0,0 +1,21 @@
1;;; abs.S
2
3#include <asm/linkage.h>
4
5#if defined(__H8300H__)
6 .h8300h
7#endif
8#if defined(__H8300S__)
9 .h8300s
10#endif
11 .text
12.global SYMBOL_NAME(abs)
13
14;;; int abs(int n)
15SYMBOL_NAME_LABEL(abs)
16 mov.l er0,er0
17 bpl 1f
18 neg.l er0
191:
20 rts
21
diff --git a/arch/h8300/lib/ashrdi3.c b/arch/h8300/lib/ashrdi3.c
new file mode 100644
index 000000000000..78efb65e315a
--- /dev/null
+++ b/arch/h8300/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/h8300/lib/checksum.c b/arch/h8300/lib/checksum.c
new file mode 100644
index 000000000000..5aa688d9242d
--- /dev/null
+++ b/arch/h8300/lib/checksum.c
@@ -0,0 +1,159 @@
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 * IP/TCP/UDP checksumming routines
7 *
8 * Authors: Jorge Cwik, <jorge@laser.satlink.net>
9 * Arnt Gulbrandsen, <agulbra@nvg.unit.no>
10 * Tom May, <ftom@netcom.com>
11 * Andreas Schwab, <schwab@issan.informatik.uni-dortmund.de>
12 * Lots of code moved from tcp.c and ip.c; see those files
13 * for more names.
14 *
15 * 03/02/96 Jes Sorensen, Andreas Schwab, Roman Hodek:
16 * Fixed some nasty bugs, causing some horrible crashes.
17 * A: At some points, the sum (%0) was used as
18 * length-counter instead of the length counter
19 * (%1). Thanks to Roman Hodek for pointing this out.
20 * B: GCC seems to mess up if one uses too many
21 * data-registers to hold input values and one tries to
22 * specify d0 and d1 as scratch registers. Letting gcc choose these
23 * registers itself solves the problem.
24 *
25 * This program is free software; you can redistribute it and/or
26 * modify it under the terms of the GNU General Public License
27 * as published by the Free Software Foundation; either version
28 * 2 of the License, or (at your option) any later version.
29 */
30
31/* Revised by Kenneth Albanowski for m68knommu. Basic problem: unaligned access kills, so most
32 of the assembly has to go. */
33
34#include <net/checksum.h>
35#include <linux/module.h>
36
37static inline unsigned short from32to16(unsigned long x)
38{
39 /* add up 16-bit and 16-bit for 16+c bit */
40 x = (x & 0xffff) + (x >> 16);
41 /* add up carry.. */
42 x = (x & 0xffff) + (x >> 16);
43 return x;
44}
45
46static unsigned long do_csum(const unsigned char * buff, int len)
47{
48 int odd, count;
49 unsigned long result = 0;
50
51 if (len <= 0)
52 goto out;
53 odd = 1 & (unsigned long) buff;
54 if (odd) {
55 result = *buff;
56 len--;
57 buff++;
58 }
59 count = len >> 1; /* nr of 16-bit words.. */
60 if (count) {
61 if (2 & (unsigned long) buff) {
62 result += *(unsigned short *) buff;
63 count--;
64 len -= 2;
65 buff += 2;
66 }
67 count >>= 1; /* nr of 32-bit words.. */
68 if (count) {
69 unsigned long carry = 0;
70 do {
71 unsigned long w = *(unsigned long *) buff;
72 count--;
73 buff += 4;
74 result += carry;
75 result += w;
76 carry = (w > result);
77 } while (count);
78 result += carry;
79 result = (result & 0xffff) + (result >> 16);
80 }
81 if (len & 2) {
82 result += *(unsigned short *) buff;
83 buff += 2;
84 }
85 }
86 if (len & 1)
87 result += (*buff << 8);
88 result = from32to16(result);
89 if (odd)
90 result = ((result >> 8) & 0xff) | ((result & 0xff) << 8);
91out:
92 return result;
93}
94
95/*
96 * This is a version of ip_compute_csum() optimized for IP headers,
97 * which always checksum on 4 octet boundaries.
98 */
99unsigned short ip_fast_csum(unsigned char * iph, unsigned int ihl)
100{
101 return ~do_csum(iph,ihl*4);
102}
103
104/*
105 * computes the checksum of a memory block at buff, length len,
106 * and adds in "sum" (32-bit)
107 *
108 * returns a 32-bit number suitable for feeding into itself
109 * or csum_tcpudp_magic
110 *
111 * this function must be called with even lengths, except
112 * for the last fragment, which may be odd
113 *
114 * it's best to have buff aligned on a 32-bit boundary
115 */
116unsigned int csum_partial(const unsigned char * buff, int len, unsigned int sum)
117{
118 unsigned int result = do_csum(buff, len);
119
120 /* add in old sum, and carry.. */
121 result += sum;
122 /* 16+c bits -> 16 bits */
123 result = (result & 0xffff) + (result >> 16);
124 return result;
125}
126
127EXPORT_SYMBOL(csum_partial);
128
129/*
130 * this routine is used for miscellaneous IP-like checksums, mainly
131 * in icmp.c
132 */
133unsigned short ip_compute_csum(const unsigned char * buff, int len)
134{
135 return ~do_csum(buff,len);
136}
137
138/*
139 * copy from fs while checksumming, otherwise like csum_partial
140 */
141
142unsigned int
143csum_partial_copy_from_user(const char *src, char *dst, int len, int sum, int *csum_err)
144{
145 if (csum_err) *csum_err = 0;
146 memcpy(dst, src, len);
147 return csum_partial(dst, len, sum);
148}
149
150/*
151 * copy from ds while checksumming, otherwise like csum_partial
152 */
153
154unsigned int
155csum_partial_copy(const char *src, char *dst, int len, int sum)
156{
157 memcpy(dst, src, len);
158 return csum_partial(dst, len, sum);
159}
diff --git a/arch/h8300/lib/memcpy.S b/arch/h8300/lib/memcpy.S
new file mode 100644
index 000000000000..fdcbc1ee673c
--- /dev/null
+++ b/arch/h8300/lib/memcpy.S
@@ -0,0 +1,84 @@
1;;; memcpy.S
2
3#include <asm/linkage.h>
4
5#if defined(__H8300H__)
6 .h8300h
7#endif
8#if defined(__H8300S__)
9 .h8300s
10#endif
11
12 .text
13.global SYMBOL_NAME(memcpy)
14
15;;; void *memcpy(void *to, void *from, size_t n)
16SYMBOL_NAME_LABEL(memcpy)
17 mov.l er2,er2
18 bne 1f
19 rts
201:
21 ;; address check
22 bld #0,r0l
23 bxor #0,r1l
24 bcs 4f
25 mov.l er4,@-sp
26 mov.l er0,@-sp
27 btst #0,r0l
28 beq 1f
29 ;; (aligned even) odd address
30 mov.b @er1,r3l
31 mov.b r3l,@er0
32 adds #1,er1
33 adds #1,er0
34 dec.l #1,er2
35 beq 3f
361:
37 ;; n < sizeof(unsigned long) check
38 sub.l er4,er4
39 adds #4,er4 ; loop count check value
40 cmp.l er4,er2
41 blo 2f
42 ;; unsigned long copy
431:
44 mov.l @er1,er3
45 mov.l er3,@er0
46 adds #4,er0
47 adds #4,er1
48 subs #4,er2
49 cmp.l er4,er2
50 bcc 1b
51 ;; rest
522:
53 mov.l er2,er2
54 beq 3f
551:
56 mov.b @er1,r3l
57 mov.b r3l,@er0
58 adds #1,er1
59 adds #1,er0
60 dec.l #1,er2
61 bne 1b
623:
63 mov.l @sp+,er0
64 mov.l @sp+,er4
65 rts
66
67 ;; odd <- even / even <- odd
684:
69 mov.l er4,er3
70 mov.l er2,er4
71 mov.l er5,er2
72 mov.l er1,er5
73 mov.l er6,er1
74 mov.l er0,er6
751:
76 eepmov.w
77 mov.w r4,r4
78 bne 1b
79 dec.w #1,e4
80 bpl 1b
81 mov.l er1,er6
82 mov.l er2,er5
83 mov.l er3,er4
84 rts
diff --git a/arch/h8300/lib/memset.S b/arch/h8300/lib/memset.S
new file mode 100644
index 000000000000..59abdf9485a5
--- /dev/null
+++ b/arch/h8300/lib/memset.S
@@ -0,0 +1,61 @@
1/* memset.S */
2
3#include <asm/linkage.h>
4
5#if defined(__H8300H__)
6 .h8300h
7#endif
8#if defined(__H8300S__)
9 .h8300s
10#endif
11 .text
12
13.global SYMBOL_NAME(memset)
14
15;;void *memset(*ptr, int c, size_t count)
16;; ptr = er0
17;; c = er1(r1l)
18;; count = er2
19SYMBOL_NAME_LABEL(memset)
20 btst #0,r0l
21 beq 2f
22
23 ;; odd address
241:
25 mov.b r1l,@er0
26 adds #1,er0
27 dec.l #1,er2
28 beq 6f
29
30 ;; even address
312:
32 mov.l er2,er3
33 cmp.l #4,er2
34 blo 4f
35 ;; count>=4 -> count/4
36#if defined(__H8300H__)
37 shlr.l er2
38 shlr.l er2
39#endif
40#if defined(__H8300S__)
41 shlr.l #2,er2
42#endif
43 ;; byte -> long
44 mov.b r1l,r1h
45 mov.w r1,e1
463:
47 mov.l er1,@er0
48 adds #4,er0
49 dec.l #1,er2
50 bne 3b
514:
52 ;; count % 4
53 and.b #3,r3l
54 beq 6f
555:
56 mov.b r1l,@er0
57 adds #1,er0
58 dec.b r3l
59 bne 5b
606:
61 rts
diff --git a/arch/h8300/lib/romfs.S b/arch/h8300/lib/romfs.S
new file mode 100644
index 000000000000..b72f93a47e31
--- /dev/null
+++ b/arch/h8300/lib/romfs.S
@@ -0,0 +1,58 @@
1/* romfs move to __ebss */
2
3#include <asm/linkage.h>
4#include <linux/config.h>
5
6#if defined(__H8300H__)
7 .h8300h
8#endif
9#if defined(__H8300S__)
10 .h8300s
11#endif
12
13#define BLKOFFSET 512
14
15 .text
16.globl __move_romfs
17_romfs_sig_len = 8
18
19__move_romfs:
20 mov.l #__sbss,er0
21 mov.l #_romfs_sig,er1
22 mov.b #_romfs_sig_len,r3l
231: /* check romfs image */
24 mov.b @er0+,r2l
25 mov.b @er1+,r2h
26 cmp.b r2l,r2h
27 bne 2f
28 dec.b r3l
29 bne 1b
30
31 /* find romfs image */
32 mov.l @__sbss+8,er0 /* romfs length(be) */
33 mov.l #__sbss,er1
34 add.l er0,er1 /* romfs image end */
35 mov.l #__ebss,er2
36 add.l er0,er2 /* distination address */
37#if defined(CONFIG_INTELFLASH)
38 add.l #BLKOFFSET,er2
39#endif
40 adds #2,er0
41 adds #1,er0
42 shlr er0
43 shlr er0 /* transfer length */
441:
45 mov.l @er1,er3 /* copy image */
46 mov.l er3,@er2
47 subs #4,er1
48 subs #4,er2
49 dec.l #1,er0
50 bpl 1b
512:
52 rts
53
54 .section .rodata
55_romfs_sig:
56 .ascii "-rom1fs-"
57
58 .end