2 * arch/sh/kernel/cpu/sh2a/entry.S
4 * The SH-2A exception entry
6 * Copyright (C) 2008 Yoshinori Sato
7 * Based on arch/sh/kernel/cpu/sh2/entry.S
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
14 #include <linux/linkage.h>
15 #include <asm/asm-offsets.h>
16 #include <asm/thread_info.h>
17 #include <cpu/mmu_context.h>
18 #include <asm/unistd.h>
19 #include <asm/errno.h>
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 */
36 #include <asm/entry-macros.S>
38 ENTRY(exception_handler)
45 ! r1 = vector (pseudo EXPEVT / INTEVT / TRA)
49 bld.b #6,@(0,r2) !previus SR.MD
50 bst.b #6,@(4*4,r15) !set cpu mode to SR.MD
52 ! switch to kernel mode
53 bset.b #6,@(0,r2) !set SR.MD
54 mov.l $current_thread_info,r2
56 mov #(THREAD_SIZE >> 8),r0
58 add r2,r0 ! r0 = kernel stack tail
59 mov r15,r2 ! r2 = user stack top
60 mov r0,r15 ! switch kernel stack
66 mov.l r0,@-r15 ! original SR
69 mov.l r0,@-r15 ! original PC
71 add #(3+2)*4,r0 ! rewind r0 - r3 + exception frame
72 lds r0,pr ! pr = original SP
73 movmu.l r3,@-r15 ! save regs
74 mov r2,r8 ! r8 = previus stack top
75 mov r1,r9 ! r9 = interrupt vector
76 ! restore previous stack
85 add #-((OFF_TRA + 4) - OFF_PC) + 5*4,r15
87 mov r2,r8 ! r8 = previous stack top
88 mov r1,r9 ! r9 = interrupt vector
89 ! restore exception frame & regs
90 mov.l @r8+,r2 ! old R2
91 mov.l @r8+,r0 ! old R0
92 mov.l @r8+,r1 ! old R1
93 mov.l @r8+,r10 ! old PC
94 mov.l @r8+,r11 ! old SR
96 mov.l r10,@(OFF_PC,r15)
97 mov.l r11,@(OFF_SR,r15)
98 mov.l r8,@(OFF_SP,r15) ! save old sp
108 ! dispatch exception / interrupt
111 bt interrupt_entry ! vec >= 64 is interrupt
114 bt trap_entry ! 64 > vec >= 32 is trap
120 mov.l @r8,r8 ! exception handler address
123 mov.l 8f,r8 ! unhandled exception
138 4: .long exception_handling_table
139 5: .long ret_from_exception
140 6: .long ret_from_irq
142 8: .long exception_error
146 cmp/ge r8,r9 ! vector 0x20-0x2f is systemcall
148 add #-0x10,r9 ! convert SH2 to SH3/4 ABI
151 bra system_call ! jump common systemcall entry
154 #if defined(CONFIG_SH_STANDARD_BIOS)
155 /* Unwind the stack and jmp to the debug entry */
156 ENTRY(sh_bios_handler)
163 mov.l @(OFF_SP,r0),r1
164 mov.l @(OFF_SR,r2),r3
166 mov.l @(OFF_SP,r2),r3
183 1: .long gdb_vbr_vector
184 #endif /* CONFIG_SH_STANDARD_BIOS */
186 ENTRY(address_error_trap_handler)
188 mov.l @(OFF_PC,r15),r6 ! pc
191 mov #0,r5 ! writeaccess is unknown
194 1: .long do_address_error
199 ldc r0,sr ! all interrupt block (same BL = 1)
200 ! restore special register
201 ! overlap exception frame
211 bld.b #6,@(OFF_SR,r15)
212 bst.b #6,@(0,r2) ! save CPU mode
213 mov.l @(OFF_SR,r0),r1
215 shlr2 r1 ! clear MD bit
216 mov.l @(OFF_SP,r0),r2
218 mov.l r2,@(OFF_SP,r0) ! point exception frame top
219 mov.l r1,@(4,r2) ! set sr
220 mov.l @(OFF_PC,r0),r1
221 mov.l r1,@r2 ! set pc
222 get_current_thread_info r0, r1
223 mov.l $current_thread_info,r1
231 $current_thread_info:
232 .long __current_thread_info
236 ! common exception handler
237 #include "../../entry-common.S"
241 ! bit30 = MD (compatible SH3/4)
246 __current_thread_info:
249 ENTRY(exception_handling_table)