1 /* SPDX-License-Identifier: GPL-2.0
3 * arch/sh/kernel/cpu/sh3/entry.S
5 * Copyright (C) 1999, 2000, 2002 Niibe Yutaka
6 * Copyright (C) 2003 - 2012 Paul Mundt
9 #include <linux/errno.h>
10 #include <linux/linkage.h>
11 #include <asm/asm-offsets.h>
12 #include <asm/thread_info.h>
13 #include <asm/unistd.h>
14 #include <cpu/mmu_context.h>
16 #include <asm/cache.h>
19 ! GNU as (as of 2.9.1) changes bf/s into bt/s and bra, when the address
20 ! to be jumped is too far, but it causes illegal slot exception.
23 * entry.S contains the system-call and fault low-level handling routines.
24 * This also contains the timer-interrupt handler, as well as all interrupts
25 * and faults that can result in a task-switch.
27 * NOTE: This code handles signal-recognition, which happens every time
28 * after a timer-interrupt and after each system call.
30 * NOTE: This code uses a convention that instructions in the delay slot
31 * of a transfer-control instruction are indented by an extra space, thus:
33 * jmp @k0 ! control-transfer instruction
34 * ldc k1, ssr ! delay slot
36 * Stack layout in 'ret_from_syscall':
37 * ptrace needs to have all regs on the stack.
38 * if the order here is changed, it needs to be
39 * updated in ptrace.c and ptrace.h
53 /* Offsets to the stack */
54 OFF_R0 = 0 /* Return value. New ABI also arg4 */
55 OFF_R1 = 4 /* New ABI: arg5 */
56 OFF_R2 = 8 /* New ABI: arg6 */
57 OFF_R3 = 12 /* New ABI: syscall_nr */
58 OFF_R4 = 16 /* New ABI: arg0 */
59 OFF_R5 = 20 /* New ABI: arg1 */
60 OFF_R6 = 24 /* New ABI: arg2 */
61 OFF_R7 = 28 /* New ABI: arg3 */
73 #define g_imask r6 /* r6_bank1 */
74 #define k_g_imask r6_bank /* r6_bank1 */
75 #define current r7 /* r7_bank1 */
77 #include <asm/entry-macros.S>
80 * Kernel mode register usage:
83 * k2 scratch (Exception code)
84 * k3 scratch (Return address)
87 * k6 Global Interrupt Mask (0--15 << 4)
88 * k7 CURRENT_THREAD_INFO (pointer to current thread info)
92 ! TLB Miss / Initial Page write exception handling
94 ! TLB hits, but the access violate the protection.
95 ! It can be valid access, such as stack grow and/or C-O-W.
98 ! Find the pmd/pte entry and loadtlb
99 ! If it's not found, cause address error (SEGV)
101 ! Although this could be written in assembly language (and it'd be faster),
102 ! this first version depends *much* on C implementation.
105 #if defined(CONFIG_MMU)
108 bra call_handle_tlbmiss
112 ENTRY(tlb_miss_store)
113 bra call_handle_tlbmiss
114 mov #FAULT_CODE_WRITE, r5
117 ENTRY(initial_page_write)
118 bra call_handle_tlbmiss
119 mov #FAULT_CODE_INITIAL, r5
122 ENTRY(tlb_protection_violation_load)
123 bra call_do_page_fault
124 mov #FAULT_CODE_PROT, r5
127 ENTRY(tlb_protection_violation_store)
128 bra call_do_page_fault
129 mov #(FAULT_CODE_PROT | FAULT_CODE_WRITE), r5
159 2: .long handle_tlbmiss
160 3: .long do_page_fault
161 4: .long ret_from_exception
164 ENTRY(address_error_load)
166 mov #0,r5 ! writeaccess = 0
169 ENTRY(address_error_store)
171 mov #1,r5 ! writeaccess = 1
176 mov.l @r0, r6 ! address
183 2: .long do_address_error
184 #endif /* CONFIG_MMU */
186 #if defined(CONFIG_SH_STANDARD_BIOS)
187 /* Unwind the stack and jmp to the debug entry */
188 ENTRY(sh_bios_handler)
193 lds k2, pr ! restore pr
202 2: .long gdb_vbr_vector
203 #endif /* CONFIG_SH_STANDARD_BIOS */
206 ! - restore r0, r1, r2, r3, r4, r5, r6, r7 from the stack
208 ! - restore r8, r9, r10, r11, r12, r13, r14, r15 from the stack
209 ! - restore spc, pr*, ssr, gbr, mach, macl, skip default tra
210 ! k2 returns original pr
211 ! k3 returns original sr
212 ! k4 returns original stack pointer
213 ! r8 passes SR bitmask, overwritten with restored data on return
215 ! BL=0 on entry, on exit BL=1 (depending on r8).
238 mov.l @r15+, k4 ! original stack pointer
240 mov.l @r15+, k2 ! original PR
241 mov.l @r15+, k3 ! original SR
246 add #4, r15 ! Skip syscall number
253 lds k2, pr ! restore pr
255 ! Calculate new SR value
256 mov k3, k2 ! original SR value
260 and k1, k2 ! Mask original SR value
262 mov k3, k0 ! Calculate IMASK-bits
270 6: or k0, k2 ! Set the IMASK-bits
278 5: .long 0x00001000 ! DSP
281 ! common exception handler
282 #include "../../entry-common.S"
284 ! Exception Vector Base
286 ! Should be aligned page boundary.
292 ! 0x100: General exception vector
297 sts pr, k3 ! save original pr value in k3
301 ! - switch to kernel stack
302 ! k0 returns original sp (after roll back)
308 ! Check for roll back gRB (User and Kernel)
316 cmp/hs k0, k1 ! test k1 (saved PC) >= k0 (saved r0)
322 ldc k0, spc ! PC = saved r0 + r15 - 2
323 2: mov k1, r15 ! SP = r1
326 ! Switch to kernel stack if needed
327 stc ssr, k0 ! Is it from kernel space?
328 shll k0 ! Check MD bit (bit30) by shifting it into...
329 shll k0 ! ...the T bit
330 bt/s 1f ! It's a kernel to kernel transition.
331 mov r15, k0 ! save original stack to k0
332 /* User space to kernel */
333 mov #(THREAD_SIZE >> 10), k1
334 shll8 k1 ! k1 := THREAD_SIZE
337 mov k1, r15 ! change to kernel stack
344 ! 0x400: Instruction and Data TLB miss exception vector
348 sts pr, k3 ! save original pr value in k3
351 mova exception_data, k0
353 ! Setup stack and save DSP context (k0 contains original r15 on return)
357 ! Save registers / Switch to bank 0
358 mov.l 5f, k2 ! vector register address
359 mov.l 1f, k4 ! SR bits to clear in k4
360 bsr save_regs ! needs original pr value in k3
361 mov.l @k2, k2 ! read out vector and keep in k2
363 handle_exception_special:
366 ! Setup return address and jump to exception handler
367 mov.l 7f, r9 ! fetch return address
368 stc r2_bank, r0 ! k2 (vector)
372 mov.l @(r0, r10), r10
374 lds r9, pr ! put return address in pr
376 .align L1_CACHE_SHIFT
379 ! - save default tra, macl, mach, gbr, ssr, pr* and spc on the stack
380 ! - save r15*, r14, r13, r12, r11, r10, r9, r8 on the stack
382 ! - save r7, r6, r5, r4, r3, r2, r1, r0 on the stack
383 ! k0 contains original stack pointer*
385 ! k3 passes original pr*
386 ! k4 passes SR bitmask
387 ! BL=1 on entry, on exit BL=0.
391 mov.l k1, @-r15 ! set TRA (default: -1)
396 mov.l k3, @-r15 ! original pr in k3
399 mov.l k0, @-r15 ! original stack pointer in k0
408 mov.l 0f, k3 ! SR bits to set in k3
413 ! - modify SR for bank switch
414 ! - save r7, r6, r5, r4, r3, r2, r1, r0 on the stack
415 ! k3 passes bits to set in SR
416 ! k4 passes bits to clear in SR
435 ! 0x600: Interrupt / NMI vector
438 ENTRY(handle_interrupt)
439 sts pr, k3 ! save original pr value in k3
440 mova exception_data, k0
442 ! Setup stack and save DSP context (k0 contains original r15 on return)
446 ! Save registers / Switch to bank 0
447 mov.l 1f, k4 ! SR bits to clear in k4
448 bsr save_regs ! needs original pr value in k3
449 mov #-1, k2 ! default vector kept in k2
453 stc sr, r0 ! get status register
461 ! Setup return address and jump to do_IRQ
462 mov.l 4f, r9 ! fetch return address
463 lds r9, pr ! put return address in pr
466 mov.l @r4, r4 ! pass INTEVT vector as arg0
470 mov r4, r0 ! save vector->jmp table offset for later
472 shlr2 r4 ! vector to IRQ# conversion
475 cmp/hs r5, r4 ! is it a valid IRQ?
479 * We got here as a result of taking the INTEVT path for something
480 * that isn't a valid hard IRQ, therefore we bypass the do_IRQ()
481 * path and special case the event dispatch instead. This is the
482 * expected path for the NMI (and any other brilliantly implemented
483 * exception), which effectively wants regular exception dispatch
484 * but is unfortunately reported through INTEVT rather than
490 mov r15, r8 ! trap handlers take saved regs in r8
493 jmp @r9 ! Off to do_IRQ() we go.
494 mov r15, r5 ! pass saved registers as arg1
496 ENTRY(exception_none)
500 .align L1_CACHE_SHIFT
502 0: .long 0x000080f0 ! FD=1, IMASK=15
503 1: .long 0xcfffffff ! RB=0, BL=0
506 4: .long ret_from_irq
508 6: .long exception_handling_table
509 7: .long ret_from_exception