2 * arch/sh/kernel/cpu/sh3/entry.S
4 * Copyright (C) 1999, 2000, 2002 Niibe Yutaka
5 * Copyright (C) 2003 - 2006 Paul Mundt
7 * This file is subject to the terms and conditions of the GNU General Public
8 * License. See the file "COPYING" in the main directory of this archive
11 #include <linux/sys.h>
12 #include <linux/errno.h>
13 #include <linux/linkage.h>
14 #include <asm/asm-offsets.h>
15 #include <asm/thread_info.h>
16 #include <asm/unistd.h>
17 #include <cpu/mmu_context.h>
21 ! GNU as (as of 2.9.1) changes bf/s into bt/s and bra, when the address
22 ! to be jumped is too far, but it causes illegal slot exception.
25 * entry.S contains the system-call and fault low-level handling routines.
26 * This also contains the timer-interrupt handler, as well as all interrupts
27 * and faults that can result in a task-switch.
29 * NOTE: This code handles signal-recognition, which happens every time
30 * after a timer-interrupt and after each system call.
32 * NOTE: This code uses a convention that instructions in the delay slot
33 * of a transfer-control instruction are indented by an extra space, thus:
35 * jmp @k0 ! control-transfer instruction
36 * ldc k1, ssr ! delay slot
38 * Stack layout in 'ret_from_syscall':
39 * ptrace needs to have all regs on the stack.
40 * if the order here is changed, it needs to be
41 * updated in ptrace.c and ptrace.h
55 #if defined(CONFIG_KGDB_NMI)
56 NMI_VEC = 0x1c0 ! Must catch early for debounce
59 /* Offsets to the stack */
60 OFF_R0 = 0 /* Return value. New ABI also arg4 */
61 OFF_R1 = 4 /* New ABI: arg5 */
62 OFF_R2 = 8 /* New ABI: arg6 */
63 OFF_R3 = 12 /* New ABI: syscall_nr */
64 OFF_R4 = 16 /* New ABI: arg0 */
65 OFF_R5 = 20 /* New ABI: arg1 */
66 OFF_R6 = 24 /* New ABI: arg2 */
67 OFF_R7 = 28 /* New ABI: arg3 */
80 #define g_imask r6 /* r6_bank1 */
81 #define k_g_imask r6_bank /* r6_bank1 */
82 #define current r7 /* r7_bank1 */
84 #include <asm/entry-macros.S>
87 * Kernel mode register usage:
90 * k2 scratch (Exception code)
91 * k3 scratch (Return address)
94 * k6 Global Interrupt Mask (0--15 << 4)
95 * k7 CURRENT_THREAD_INFO (pointer to current thread info)
99 ! TLB Miss / Initial Page write exception handling
101 ! TLB hits, but the access violate the protection.
102 ! It can be valid access, such as stack grow and/or C-O-W.
105 ! Find the pmd/pte entry and loadtlb
106 ! If it's not found, cause address error (SEGV)
108 ! Although this could be written in assembly language (and it'd be faster),
109 ! this first version depends *much* on C implementation.
112 #if defined(CONFIG_MMU)
119 ENTRY(tlb_miss_store)
124 ENTRY(initial_page_write)
129 ENTRY(tlb_protection_violation_load)
134 ENTRY(tlb_protection_violation_store)
161 2: .long __do_page_fault
162 3: .long do_page_fault
165 ENTRY(address_error_load)
167 mov #0,r5 ! writeaccess = 0
170 ENTRY(address_error_store)
172 mov #1,r5 ! writeaccess = 1
177 mov.l @r0, r6 ! address
184 2: .long do_address_error
185 #endif /* CONFIG_MMU */
187 #if defined(CONFIG_SH_STANDARD_BIOS)
188 /* Unwind the stack and jmp to the debug entry */
189 ENTRY(sh_bios_handler)
199 mov.l 1f, r9 ! BL =1, RB=1, IMASK=0x0F
201 ldc r8, sr ! here, change the register bank
224 2: .long gdb_vbr_vector
225 #endif /* CONFIG_SH_STANDARD_BIOS */
239 or r9, r8 ! BL =1, RB=1
240 ldc r8, sr ! here, change the register bank
249 mov.l @r15+, k4 ! original stack pointer
252 mov.l @r15+, k3 ! original SR
256 add #4, r15 ! Skip syscall number
259 mov.l @r15+, k0 ! DSP mode marker
261 cmp/eq k0, k1 ! Do we have a DSP stack frame?
264 stc sr, k0 ! Enable CPU DSP mode
265 or k1, k0 ! (within kernel it may be disabled)
267 mov r2, k0 ! Backup r2
269 ! Restore DSP registers from stack
288 mov k0, r2 ! Restore r2
292 ! Calculate new SR value
293 mov k3, k2 ! original SR value
297 and k1, k2 ! Mask orignal SR value
299 mov k3, k0 ! Calculate IMASK-bits
307 6: or k0, k2 ! Set the IMASK-bits
310 #if defined(CONFIG_KGDB_NMI)
316 mov.l @r15+, k2 ! restore EXPEVT
322 5: .long 0x00001000 ! DSP
323 #ifdef CONFIG_KGDB_NMI
328 ! common exception handler
329 #include "../../entry-common.S"
331 ! Exception Vector Base
333 ! Should be aligned page boundary.
343 #ifdef CONFIG_CPU_SUBTYPE_SHX3
346 ! Is EXPEVT larger than 0x800?
352 ! then add 0x580 (k2 is 0xd80 or 0xda0)
366 2: .long ret_from_exception
381 #if defined(CONFIG_KGDB_NMI)
382 ! Debounce (filter nested NMI)
396 #endif /* defined(CONFIG_KGDB_NMI) */
398 mov #-1, k2 ! interrupt exception marker
403 3: .long ret_from_irq
404 4: .long ret_from_exception
409 ENTRY(handle_exception)
410 ! Using k0, k1 for scratch registers (r0_bank1, r1_bank),
411 ! save all registers onto stack.
415 ! Check for roll back gRB (User and Kernel)
423 cmp/hs k0, k1 ! test k1 (saved PC) >= k0 (saved r0)
429 ldc k0, spc ! PC = saved r0 + r15 - 2
430 2: mov k1, r15 ! SP = r1
434 stc ssr, k0 ! Is it from kernel space?
435 shll k0 ! Check MD bit (bit30) by shifting it into...
436 shll k0 ! ...the T bit
437 bt/s 1f ! It's a kernel to kernel transition.
438 mov r15, k0 ! save original stack to k0
439 /* User space to kernel */
440 mov #(THREAD_SIZE >> 10), k1
441 shll8 k1 ! k1 := THREAD_SIZE
444 mov k1, r15 ! change to kernel stack
449 mov.l r2, @-r15 ! Save r2, we need another reg
452 tst r2, k4 ! Check if in DSP mode
453 mov.l @r15+, r2 ! Restore r2 now
455 mov #0, k4 ! Set marker for no stack frame
457 mov r2, k4 ! Backup r2 (in k4) for later
459 ! Save DSP registers on stack
470 ! GAS is broken, does not generate correct "movs.l Ds,@-As" instr.
472 ! FIXME: Make sure that this is still the case with newer toolchains,
473 ! as we're not at all interested in supporting ancient toolchains at
474 ! this point. -- PFM.
477 .word 0xf653 ! movs.l a1, @-r2
478 .word 0xf6f3 ! movs.l a0g, @-r2
479 .word 0xf6d3 ! movs.l a1g, @-r2
480 .word 0xf6c3 ! movs.l m0, @-r2
481 .word 0xf6e3 ! movs.l m1, @-r2
484 mov k4, r2 ! Restore r2
485 mov.l 1f, k4 ! Force DSP stack frame
487 mov.l k4, @-r15 ! Push DSP mode marker onto stack
489 ! Save the user registers on the stack.
490 mov.l k2, @-r15 ! EXPEVT
493 mov.l k4, @-r15 ! set TRA (default: -1)
502 lds k3, pr ! Set the return address to pr
504 mov.l k0, @-r15 ! save orignal stack
513 stc sr, r8 ! Back to normal register bank, and
514 or k1, r8 ! Block all interrupts
517 ldc r8, sr ! ...changed here.
529 * This gets a bit tricky.. in the INTEVT case we don't want to use
530 * the VBR offset as a destination in the jump call table, since all
531 * of the destinations are the same. In this case, (interrupt) sets
532 * a marker in r2 (now r2_bank since SR.RB changed), which we check
533 * to determine the exception type. For all other exceptions, we
534 * forcibly read EXPEVT from memory and fix up the jump address, in
535 * the interrupt exception case we jump to do_IRQ() and defer the
536 * INTEVT read until there. As a bonus, we can also clean up the SR.RB
537 * checks that do_IRQ() was doing..
541 bf interrupt_exception
553 1: .long 0x00001000 ! DSP=1
554 2: .long 0x000080f0 ! FD=1, IMASK=15
555 3: .long 0xcfffffff ! RB=0, BL=0
556 4: .long exception_handling_table
572 ENTRY(exception_none)