Skip to content

Commit 96cf518

Browse files
committed
unicore32 additional architecture files: low-level lib: misc
This patch implements the rest low-level libraries. Signed-off-by: Guan Xuetao <gxt@mprc.pku.edu.cn> Acked-by: Arnd Bergmann <arnd@arndb.de>
1 parent 77c93b2 commit 96cf518

10 files changed

Lines changed: 662 additions & 0 deletions

File tree

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
/*
2+
* linux/arch/unicore32/include/asm/assembler.h
3+
*
4+
* Code specific to PKUnity SoC and UniCore ISA
5+
*
6+
* Copyright (C) 2001-2010 GUAN Xue-tao
7+
*
8+
* This program is free software; you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License version 2 as
10+
* published by the Free Software Foundation.
11+
*
12+
* Do not include any C declarations in this file - it is included by
13+
* assembler source.
14+
*/
15+
#ifndef __ASSEMBLY__
16+
#error "Only include this from assembly code"
17+
#endif
18+
19+
#include <asm/ptrace.h>
20+
21+
/*
22+
* Little Endian independent macros for shifting bytes within registers.
23+
*/
24+
#define pull >>
25+
#define push <<
26+
#define get_byte_0 << #0
27+
#define get_byte_1 >> #8
28+
#define get_byte_2 >> #16
29+
#define get_byte_3 >> #24
30+
#define put_byte_0 << #0
31+
#define put_byte_1 << #8
32+
#define put_byte_2 << #16
33+
#define put_byte_3 << #24
34+
35+
#define cadd cmpadd
36+
#define cand cmpand
37+
#define csub cmpsub
38+
#define cxor cmpxor
39+
40+
/*
41+
* Enable and disable interrupts
42+
*/
43+
.macro disable_irq, temp
44+
mov \temp, asr
45+
andn \temp, \temp, #0xFF
46+
or \temp, \temp, #PSR_I_BIT | PRIV_MODE
47+
mov.a asr, \temp
48+
.endm
49+
50+
.macro enable_irq, temp
51+
mov \temp, asr
52+
andn \temp, \temp, #0xFF
53+
or \temp, \temp, #PRIV_MODE
54+
mov.a asr, \temp
55+
.endm
56+
57+
#define USER(x...) \
58+
9999: x; \
59+
.pushsection __ex_table, "a"; \
60+
.align 3; \
61+
.long 9999b, 9001f; \
62+
.popsection
63+
64+
.macro notcond, cond, nexti = .+8
65+
.ifc \cond, eq
66+
bne \nexti
67+
.else; .ifc \cond, ne
68+
beq \nexti
69+
.else; .ifc \cond, ea
70+
bub \nexti
71+
.else; .ifc \cond, ub
72+
bea \nexti
73+
.else; .ifc \cond, fs
74+
bns \nexti
75+
.else; .ifc \cond, ns
76+
bfs \nexti
77+
.else; .ifc \cond, fv
78+
bnv \nexti
79+
.else; .ifc \cond, nv
80+
bfv \nexti
81+
.else; .ifc \cond, ua
82+
beb \nexti
83+
.else; .ifc \cond, eb
84+
bua \nexti
85+
.else; .ifc \cond, eg
86+
bsl \nexti
87+
.else; .ifc \cond, sl
88+
beg \nexti
89+
.else; .ifc \cond, sg
90+
bel \nexti
91+
.else; .ifc \cond, el
92+
bsg \nexti
93+
.else; .ifnc \cond, al
94+
.error "Unknown cond in notcond macro argument"
95+
.endif; .endif; .endif; .endif; .endif; .endif; .endif
96+
.endif; .endif; .endif; .endif; .endif; .endif; .endif
97+
.endif
98+
.endm
99+
100+
.macro usracc, instr, reg, ptr, inc, cond, rept, abort
101+
.rept \rept
102+
notcond \cond, .+8
103+
9999 :
104+
.if \inc == 1
105+
\instr\()b.u \reg, [\ptr], #\inc
106+
.elseif \inc == 4
107+
\instr\()w.u \reg, [\ptr], #\inc
108+
.else
109+
.error "Unsupported inc macro argument"
110+
.endif
111+
112+
.pushsection __ex_table, "a"
113+
.align 3
114+
.long 9999b, \abort
115+
.popsection
116+
.endr
117+
.endm
118+
119+
.macro strusr, reg, ptr, inc, cond = al, rept = 1, abort = 9001f
120+
usracc st, \reg, \ptr, \inc, \cond, \rept, \abort
121+
.endm
122+
123+
.macro ldrusr, reg, ptr, inc, cond = al, rept = 1, abort = 9001f
124+
usracc ld, \reg, \ptr, \inc, \cond, \rept, \abort
125+
.endm
126+
127+
.macro nop8
128+
.rept 8
129+
nop
130+
.endr
131+
.endm
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* linux/arch/unicore32/include/asm/bitops.h
3+
*
4+
* Code specific to PKUnity SoC and UniCore ISA
5+
*
6+
* Copyright (C) 2001-2010 GUAN Xue-tao
7+
*
8+
* This program is free software; you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License version 2 as
10+
* published by the Free Software Foundation.
11+
*/
12+
13+
#ifndef __UNICORE_BITOPS_H__
14+
#define __UNICORE_BITOPS_H__
15+
16+
#define find_next_bit __uc32_find_next_bit
17+
#define find_next_zero_bit __uc32_find_next_zero_bit
18+
19+
#define find_first_bit __uc32_find_first_bit
20+
#define find_first_zero_bit __uc32_find_first_zero_bit
21+
22+
#define _ASM_GENERIC_BITOPS_FLS_H_
23+
#define _ASM_GENERIC_BITOPS___FLS_H_
24+
#define _ASM_GENERIC_BITOPS_FFS_H_
25+
#define _ASM_GENERIC_BITOPS___FFS_H_
26+
/*
27+
* On UNICORE, those functions can be implemented around
28+
* the cntlz instruction for much better code efficiency.
29+
*/
30+
31+
static inline int fls(int x)
32+
{
33+
int ret;
34+
35+
asm("cntlz\t%0, %1" : "=r" (ret) : "r" (x) : "cc");
36+
ret = 32 - ret;
37+
38+
return ret;
39+
}
40+
41+
#define __fls(x) (fls(x) - 1)
42+
#define ffs(x) ({ unsigned long __t = (x); fls(__t & -__t); })
43+
#define __ffs(x) (ffs(x) - 1)
44+
45+
#include <asm-generic/bitops.h>
46+
47+
#endif /* __UNICORE_BITOPS_H__ */
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* linux/arch/unicore32/include/asm/checksum.h
3+
*
4+
* Code specific to PKUnity SoC and UniCore ISA
5+
*
6+
* Copyright (C) 2001-2010 GUAN Xue-tao
7+
*
8+
* This program is free software; you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License version 2 as
10+
* published by the Free Software Foundation.
11+
*
12+
* IP checksum routines
13+
*/
14+
#ifndef __UNICORE_CHECKSUM_H__
15+
#define __UNICORE_CHECKSUM_H__
16+
17+
/*
18+
* computes the checksum of the TCP/UDP pseudo-header
19+
* returns a 16-bit checksum, already complemented
20+
*/
21+
22+
static inline __wsum
23+
csum_tcpudp_nofold(__be32 saddr, __be32 daddr, unsigned short len,
24+
unsigned short proto, __wsum sum)
25+
{
26+
__asm__(
27+
"add.a %0, %1, %2\n"
28+
"addc.a %0, %0, %3\n"
29+
"addc.a %0, %0, %4 << #8\n"
30+
"addc.a %0, %0, %5\n"
31+
"addc %0, %0, #0\n"
32+
: "=&r"(sum)
33+
: "r" (sum), "r" (daddr), "r" (saddr), "r" (len), "Ir" (htons(proto))
34+
: "cc");
35+
return sum;
36+
}
37+
#define csum_tcpudp_nofold csum_tcpudp_nofold
38+
39+
#include <asm-generic/checksum.h>
40+
41+
#endif

‎arch/unicore32/include/asm/delay.h‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* linux/arch/unicore32/include/asm/delay.h
3+
*
4+
* Code specific to PKUnity SoC and UniCore ISA
5+
*
6+
* Copyright (C) 2001-2010 GUAN Xue-tao
7+
*
8+
* This program is free software; you can redistribute it and/or modify
9+
* it under the terms of the GNU General Public License version 2 as
10+
* published by the Free Software Foundation.
11+
*
12+
* Delay routines, using a pre-computed "loops_per_second" value.
13+
*/
14+
#ifndef __UNICORE_DELAY_H__
15+
#define __UNICORE_DELAY_H__
16+
17+
#include <asm/param.h> /* HZ */
18+
19+
extern void __delay(int loops);
20+
21+
/*
22+
* This function intentionally does not exist; if you see references to
23+
* it, it means that you're calling udelay() with an out of range value.
24+
*
25+
* With currently imposed limits, this means that we support a max delay
26+
* of 2000us. Further limits: HZ<=1000 and bogomips<=3355
27+
*/
28+
extern void __bad_udelay(void);
29+
30+
/*
31+
* division by multiplication: you don't have to worry about
32+
* loss of precision.
33+
*
34+
* Use only for very small delays ( < 1 msec). Should probably use a
35+
* lookup table, really, as the multiplications take much too long with
36+
* short delays. This is a "reasonable" implementation, though (and the
37+
* first constant multiplications gets optimized away if the delay is
38+
* a constant)
39+
*/
40+
extern void __udelay(unsigned long usecs);
41+
extern void __const_udelay(unsigned long);
42+
43+
#define MAX_UDELAY_MS 2
44+
45+
#define udelay(n) \
46+
(__builtin_constant_p(n) ? \
47+
((n) > (MAX_UDELAY_MS * 1000) ? __bad_udelay() : \
48+
__const_udelay((n) * ((2199023U*HZ)>>11))) : \
49+
__udelay(n))
50+
51+
#endif /* __UNICORE_DELAY_H__ */
52+

0 commit comments

Comments
 (0)