xref: /openbmc/linux/arch/arm/lib/io-readsw-armv4.S (revision 82003e04)
1/*
2 *  linux/arch/arm/lib/io-readsw-armv4.S
3 *
4 *  Copyright (C) 1995-2000 Russell King
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
9 */
10#include <linux/linkage.h>
11#include <asm/assembler.h>
12#include <asm/export.h>
13
14		.macro	pack, rd, hw1, hw2
15#ifndef __ARMEB__
16		orr	\rd, \hw1, \hw2, lsl #16
17#else
18		orr	\rd, \hw2, \hw1, lsl #16
19#endif
20		.endm
21
22.Linsw_align:	movs	ip, r1, lsl #31
23		bne	.Linsw_noalign
24		ldrh	ip, [r0]
25		sub	r2, r2, #1
26		strh	ip, [r1], #2
27
28ENTRY(__raw_readsw)
29		teq	r2, #0
30		reteq	lr
31		tst	r1, #3
32		bne	.Linsw_align
33
34		stmfd	sp!, {r4, r5, lr}
35
36		subs	r2, r2, #8
37		bmi	.Lno_insw_8
38
39.Linsw_8_lp:	ldrh	r3, [r0]
40		ldrh	r4, [r0]
41		pack	r3, r3, r4
42
43		ldrh	r4, [r0]
44		ldrh	r5, [r0]
45		pack	r4, r4, r5
46
47		ldrh	r5, [r0]
48		ldrh	ip, [r0]
49		pack	r5, r5, ip
50
51		ldrh	ip, [r0]
52		ldrh	lr, [r0]
53		pack	ip, ip, lr
54
55		subs	r2, r2, #8
56		stmia	r1!, {r3 - r5, ip}
57		bpl	.Linsw_8_lp
58
59.Lno_insw_8:	tst	r2, #4
60		beq	.Lno_insw_4
61
62		ldrh	r3, [r0]
63		ldrh	r4, [r0]
64		pack	r3, r3, r4
65
66		ldrh	r4, [r0]
67		ldrh	ip, [r0]
68		pack	r4, r4, ip
69
70		stmia	r1!, {r3, r4}
71
72.Lno_insw_4:	movs	r2, r2, lsl #31
73		bcc	.Lno_insw_2
74
75		ldrh	r3, [r0]
76		ldrh	ip, [r0]
77		pack	r3, r3, ip
78		str	r3, [r1], #4
79
80.Lno_insw_2:	ldrneh	r3, [r0]
81		strneh	r3, [r1]
82
83		ldmfd	sp!, {r4, r5, pc}
84
85#ifdef __ARMEB__
86#define _BE_ONLY_(code...)	code
87#define _LE_ONLY_(code...)
88#define push_hbyte0		lsr #8
89#define pull_hbyte1		lsl #24
90#else
91#define _BE_ONLY_(code...)
92#define _LE_ONLY_(code...) code
93#define push_hbyte0		lsl #24
94#define pull_hbyte1		lsr #8
95#endif
96
97.Linsw_noalign:	stmfd	sp!, {r4, lr}
98		ldrccb	ip, [r1, #-1]!
99		bcc	1f
100
101		ldrh	ip, [r0]
102		sub	r2, r2, #1
103   _BE_ONLY_(	mov	ip, ip, ror #8		)
104		strb	ip, [r1], #1
105   _LE_ONLY_(	mov	ip, ip, lsr #8		)
106   _BE_ONLY_(	mov	ip, ip, lsr #24		)
107
1081:		subs	r2, r2, #2
109		bmi	3f
110   _BE_ONLY_(	mov	ip, ip, lsl #24		)
111
1122:		ldrh	r3, [r0]
113		ldrh	r4, [r0]
114		subs	r2, r2, #2
115		orr	ip, ip, r3, lsl #8
116		orr	ip, ip, r4, push_hbyte0
117		str	ip, [r1], #4
118		mov	ip, r4, pull_hbyte1
119		bpl	2b
120
121   _BE_ONLY_(	mov	ip, ip, lsr #24		)
122
1233:		tst	r2, #1
124		strb	ip, [r1], #1
125		ldrneh	ip, [r0]
126   _BE_ONLY_(	movne	ip, ip, ror #8		)
127		strneb	ip, [r1], #1
128   _LE_ONLY_(	movne	ip, ip, lsr #8		)
129   _BE_ONLY_(	movne	ip, ip, lsr #24		)
130		strneb	ip, [r1]
131		ldmfd	sp!, {r4, pc}
132ENDPROC(__raw_readsw)
133EXPORT_SYMBOL(__raw_readsw)
134