Skip to content

Commit de39840

Browse files
Yoshinori Satopmundt
authored andcommitted
sh: Exception vector rework and SH-2/SH-2A support.
This splits out common bits from the existing exception handler for use between SH-2/SH-2A and SH-3/4, and adds support for the SH-2/2A exceptions. Signed-off-by: Yoshinori Sato <ysato@users.sourceforge.jp> Signed-off-by: Paul Mundt <lethal@linux-sh.org>
1 parent 0983b31 commit de39840

7 files changed

Lines changed: 767 additions & 332 deletions

File tree

‎arch/sh/kernel/cpu/sh2/entry.S‎

Lines changed: 325 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,325 @@
1+
/*
2+
* arch/sh/kernel/cpu/sh2/entry.S
3+
*
4+
* The SH-2 exception entry
5+
*
6+
* Copyright (C) 2005,2006 Yoshinori Sato
7+
* Copyright (C) 2005 AXE,Inc.
8+
*
9+
* This file is subject to the terms and conditions of the GNU General Public
10+
* License. See the file "COPYING" in the main directory of this archive
11+
* for more details.
12+
*/
13+
14+
#include <linux/linkage.h>
15+
#include <asm/asm-offsets.h>
16+
#include <asm/thread_info.h>
17+
#include <asm/cpu/mmu_context.h>
18+
#include <asm/unistd.h>
19+
#include <asm/errno.h>
20+
#include <asm/page.h>
21+
22+
/* Offsets to the stack */
23+
OFF_R0 = 0 /* Return value. New ABI also arg4 */
24+
OFF_R1 = 4 /* New ABI: arg5 */
25+
OFF_R2 = 8 /* New ABI: arg6 */
26+
OFF_R3 = 12 /* New ABI: syscall_nr */
27+
OFF_R4 = 16 /* New ABI: arg0 */
28+
OFF_R5 = 20 /* New ABI: arg1 */
29+
OFF_R6 = 24 /* New ABI: arg2 */
30+
OFF_R7 = 28 /* New ABI: arg3 */
31+
OFF_SP = (15*4)
32+
OFF_PC = (16*4)
33+
OFF_SR = (16*4+2*4)
34+
OFF_TRA = (16*4+6*4)
35+
36+
#include <asm/entry-macros.S>
37+
38+
ENTRY(exception_handler)
39+
! already saved r0/r1
40+
mov.l r2,@-sp
41+
mov.l r3,@-sp
42+
mov r0,r1
43+
cli
44+
mov.l $cpu_mode,r2
45+
mov.l @r2,r0
46+
mov.l @(5*4,r15),r3 ! previous SR
47+
shll2 r3 ! set "S" flag
48+
rotl r0 ! T <- "S" flag
49+
rotl r0 ! "S" flag is LSB
50+
rotcr r3 ! T -> r3:b30
51+
shlr r3
52+
shlr r0
53+
bt/s 1f
54+
mov.l r3,@(5*4,r15) ! copy cpu mode to SR
55+
! switch to kernel mode
56+
mov #1,r0
57+
rotr r0
58+
rotr r0
59+
mov.l r0,@r2 ! enter kernel mode
60+
mov.l $current_thread_info,r2
61+
mov.l @r2,r2
62+
mov #0x20,r0
63+
shll8 r0
64+
add r2,r0
65+
mov r15,r2 ! r2 = user stack top
66+
mov r0,r15 ! switch kernel stack
67+
add #-4,r15 ! dummy
68+
mov.l r1,@-r15 ! TRA
69+
sts.l macl, @-r15
70+
sts.l mach, @-r15
71+
stc.l gbr, @-r15
72+
mov.l @(4*4,r2),r0
73+
mov.l @(5*4,r2),r1
74+
mov.l r1,@-r15 ! original SR
75+
sts.l pr,@-r15
76+
mov.l r0,@-r15 ! original PC
77+
mov r2,r3
78+
add #(4+2)*4,r3 ! rewind r0 - r3 + exception frame
79+
mov.l r3,@-r15 ! original SP
80+
mov.l r14,@-r15
81+
mov.l r13,@-r15
82+
mov.l r12,@-r15
83+
mov.l r11,@-r15
84+
mov.l r10,@-r15
85+
mov.l r9,@-r15
86+
mov.l r8,@-r15
87+
mov.l r7,@-r15
88+
mov.l r6,@-r15
89+
mov.l r5,@-r15
90+
mov.l r4,@-r15
91+
mov r2,r8 ! copy user -> kernel stack
92+
mov.l @r8+,r3
93+
mov.l r3,@-r15
94+
mov.l @r8+,r2
95+
mov.l r2,@-r15
96+
mov.l @r8+,r1
97+
mov.l r1,@-r15
98+
mov.l @r8+,r0
99+
bra 2f
100+
mov.l r0,@-r15
101+
1:
102+
! in kernel exception
103+
mov #(22-4-4-1)*4+4,r0
104+
mov r15,r2
105+
sub r0,r15
106+
mov.l @r2+,r0 ! old R3
107+
mov.l r0,@-r15
108+
mov.l @r2+,r0 ! old R2
109+
mov.l r0,@-r15
110+
mov.l @r2+,r0 ! old R1
111+
mov.l r0,@-r15
112+
mov.l @r2+,r0 ! old R0
113+
mov.l r0,@-r15
114+
mov.l @r2+,r3 ! old PC
115+
mov.l @r2+,r0 ! old SR
116+
add #-4,r2 ! exception frame stub (sr)
117+
mov.l r1,@-r2 ! TRA
118+
sts.l macl, @-r2
119+
sts.l mach, @-r2
120+
stc.l gbr, @-r2
121+
mov.l r0,@-r2 ! save old SR
122+
sts.l pr,@-r2
123+
mov.l r3,@-r2 ! save old PC
124+
mov r2,r0
125+
add #8*4,r0
126+
mov.l r0,@-r2 ! save old SP
127+
mov.l r14,@-r2
128+
mov.l r13,@-r2
129+
mov.l r12,@-r2
130+
mov.l r11,@-r2
131+
mov.l r10,@-r2
132+
mov.l r9,@-r2
133+
mov.l r8,@-r2
134+
mov.l r7,@-r2
135+
mov.l r6,@-r2
136+
mov.l r5,@-r2
137+
mov.l r4,@-r2
138+
mov.l @(OFF_R0,r15),r0
139+
mov.l @(OFF_R1,r15),r1
140+
mov.l @(OFF_R2,r15),r2
141+
mov.l @(OFF_R3,r15),r3
142+
2:
143+
mov #OFF_TRA,r8
144+
add r15,r8
145+
mov.l @r8,r9
146+
mov #64,r8
147+
cmp/hs r8,r9
148+
bt interrupt_entry ! vec >= 64 is interrupt
149+
mov #32,r8
150+
cmp/hs r8,r9
151+
bt trap_entry ! 64 > vec >= 32 is trap
152+
mov.l 4f,r8
153+
mov r9,r4
154+
shll2 r9
155+
add r9,r8
156+
mov.l @r8,r8
157+
mov #0,r9
158+
cmp/eq r9,r8
159+
bf 3f
160+
mov.l 8f,r8 ! unhandled exception
161+
3:
162+
mov.l 5f,r10
163+
jmp @r8
164+
lds r10,pr
165+
166+
interrupt_entry:
167+
mov r9,r4
168+
mov.l 6f,r9
169+
mov.l 7f,r8
170+
jmp @r8
171+
lds r9,pr
172+
173+
.align 2
174+
4: .long exception_handling_table
175+
5: .long ret_from_exception
176+
6: .long ret_from_irq
177+
7: .long do_IRQ
178+
8: .long do_exception_error
179+
180+
trap_entry:
181+
add #-0x10,r9
182+
shll2 r9 ! TRA
183+
mov #OFF_TRA,r8
184+
add r15,r8
185+
mov.l r9,@r8
186+
mov r9,r8
187+
sti
188+
bra system_call
189+
nop
190+
191+
.align 2
192+
1: .long syscall_exit
193+
2: .long break_point_trap_software
194+
3: .long NR_syscalls
195+
4: .long sys_call_table
196+
197+
#if defined(CONFIG_SH_STANDARD_BIOS)
198+
/* Unwind the stack and jmp to the debug entry */
199+
debug_kernel_fw:
200+
mov r15,r0
201+
add #(22-4)*4-4,r0
202+
ldc.l @r0+,gbr
203+
lds.l @r0+,mach
204+
lds.l @r0+,macl
205+
mov r15,r0
206+
mov.l @(OFF_SP,r0),r1
207+
mov #OFF_SR,r2
208+
mov.l @(r0,r2),r3
209+
mov.l r3,@-r1
210+
mov #OFF_SP,r2
211+
mov.l @(r0,r2),r3
212+
mov.l r3,@-r1
213+
mov r15,r0
214+
add #(22-4)*4-8,r0
215+
mov.l 1f,r2
216+
mov.l @r2,r2
217+
stc sr,r3
218+
mov.l r2,@r0
219+
mov.l r3,@r0
220+
mov.l r1,@(8,r0)
221+
mov.l @r15+, r0
222+
mov.l @r15+, r1
223+
mov.l @r15+, r2
224+
mov.l @r15+, r3
225+
mov.l @r15+, r4
226+
mov.l @r15+, r5
227+
mov.l @r15+, r6
228+
mov.l @r15+, r7
229+
mov.l @r15+, r8
230+
mov.l @r15+, r9
231+
mov.l @r15+, r10
232+
mov.l @r15+, r11
233+
mov.l @r15+, r12
234+
mov.l @r15+, r13
235+
mov.l @r15+, r14
236+
add #8,r15
237+
lds.l @r15+, pr
238+
rte
239+
mov.l @r15+,r15
240+
.align 2
241+
1: .long gdb_vbr_vector
242+
#endif /* CONFIG_SH_STANDARD_BIOS */
243+
244+
ENTRY(address_error_handler)
245+
mov r15,r4 ! regs
246+
add #4,r4
247+
mov #OFF_PC,r0
248+
mov.l @(r0,r15),r6 ! pc
249+
mov.l 1f,r0
250+
jmp @r0
251+
mov #0,r5 ! writeaccess is unknown
252+
.align 2
253+
254+
1: .long do_address_error
255+
256+
restore_all:
257+
cli
258+
mov r15,r0
259+
mov.l $cpu_mode,r2
260+
mov #OFF_SR,r3
261+
mov.l @(r0,r3),r1
262+
mov.l r1,@r2
263+
shll2 r1 ! clear MD bit
264+
shlr2 r1
265+
mov.l @(OFF_SP,r0),r2
266+
add #-8,r2
267+
mov.l r2,@(OFF_SP,r0) ! point exception frame top
268+
mov.l r1,@(4,r2) ! set sr
269+
mov #OFF_PC,r3
270+
mov.l @(r0,r3),r1
271+
mov.l r1,@r2 ! set pc
272+
add #4*16+4,r0
273+
lds.l @r0+,pr
274+
add #4,r0 ! skip sr
275+
ldc.l @r0+,gbr
276+
lds.l @r0+,mach
277+
lds.l @r0+,macl
278+
get_current_thread_info r0, r1
279+
mov.l $current_thread_info,r1
280+
mov.l r0,@r1
281+
mov.l @r15+,r0
282+
mov.l @r15+,r1
283+
mov.l @r15+,r2
284+
mov.l @r15+,r3
285+
mov.l @r15+,r4
286+
mov.l @r15+,r5
287+
mov.l @r15+,r6
288+
mov.l @r15+,r7
289+
mov.l @r15+,r8
290+
mov.l @r15+,r9
291+
mov.l @r15+,r10
292+
mov.l @r15+,r11
293+
mov.l @r15+,r12
294+
mov.l @r15+,r13
295+
mov.l @r15+,r14
296+
mov.l @r15,r15
297+
rte
298+
nop
299+
2:
300+
mov.l 1f,r8
301+
mov.l 2f,r9
302+
jmp @r9
303+
lds r8,pr
304+
305+
.align 2
306+
$current_thread_info:
307+
.long __current_thread_info
308+
$cpu_mode:
309+
.long __cpu_mode
310+
311+
! common exception handler
312+
#include "../../entry-common.S"
313+
314+
.data
315+
! cpu operation mode
316+
! bit30 = MD (compatible SH3/4)
317+
__cpu_mode:
318+
.long 0x40000000
319+
320+
.section .bss
321+
__current_thread_info:
322+
.long 0
323+
324+
ENTRY(exception_handling_table)
325+
.space 4*32

‎arch/sh/kernel/cpu/sh2/ex.S‎

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* arch/sh/kernel/cpu/sh2/ex.S
3+
*
4+
* The SH-2 exception vector table
5+
*
6+
* Copyright (C) 2005 Yoshinori Sato
7+
*
8+
* This file is subject to the terms and conditions of the GNU General Public
9+
* License. See the file "COPYING" in the main directory of this archive
10+
* for more details.
11+
*/
12+
13+
#include <linux/linkage.h>
14+
15+
!
16+
! convert Exception Vector to Exception Number
17+
!
18+
exception_entry:
19+
no = 0
20+
.rept 256
21+
mov.l r0,@-sp
22+
mov #no,r0
23+
bra exception_trampoline
24+
and #0xff,r0
25+
no = no + 1
26+
.endr
27+
exception_trampoline:
28+
mov.l r1,@-sp
29+
mov.l $exception_handler,r1
30+
jmp @r1
31+
32+
.align 2
33+
$exception_entry:
34+
.long exception_entry
35+
$exception_handler:
36+
.long exception_handler
37+
!
38+
! Exception Vector Base
39+
!
40+
.align 2
41+
ENTRY(vbr_base)
42+
vector = 0
43+
.rept 256
44+
.long exception_entry + vector * 8
45+
vector = vector + 1
46+
.endr

‎arch/sh/kernel/cpu/sh3/Makefile‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Makefile for the Linux/SuperH SH-3 backends.
33
#
44

5-
obj-y := ex.o probe.o
5+
obj-y := ex.o probe.o entry.o
66

77
# CPU subtype setup
88
obj-$(CONFIG_CPU_SUBTYPE_SH7705) += setup-sh7705.o

0 commit comments

Comments
 (0)