2 * linux/arch/m32r/kernel/entry.S
4 * Copyright (c) 2001, 2002 Hirokazu Takata, Hitoshi Yamamoto, H. Kondo
5 * Copyright (c) 2003 Hitoshi Yamamoto
6 * Copyright (c) 2004 Hirokazu Takata <takata at linux-m32r.org>
8 * Taken from i386 version.
9 * Copyright (C) 1991, 1992 Linus Torvalds
13 * entry.S contains the system-call and fault low-level handling routines.
14 * This also contains the timer-interrupt handler, as well as all interrupts
15 * and faults that can result in a task-switch.
17 * NOTE: This code handles signal-recognition, which happens every time
18 * after a timer-interrupt and after each system call.
20 * Stack layout in 'ret_from_system_call':
21 * ptrace needs to have all regs on the stack.
22 * if the order here is changed, it needs to be
23 * updated in fork.c:copy_thread, signal.c:do_signal,
24 * ptrace.c and ptrace.h
30 * @(0x0c,sp) - *pt_regs
41 * @(0x38,sp) - syscall_nr
44 * @(0x44,sp) - acc1h ; ISA_DSP_LEVEL2 only
45 * @(0x48,sp) - acc1l ; ISA_DSP_LEVEL2 only
50 * @(0x5c,sp) - spu (cr3)
51 * @(0x60,sp) - fp (r13)
52 * @(0x64,sp) - lr (r14)
53 * @(0x68,sp) - spi (cr2)
54 * @(0x6c,sp) - orig_r0
57 #include <linux/linkage.h>
59 #include <asm/unistd.h>
60 #include <asm/assembler.h>
61 #include <asm/thread_info.h>
62 #include <asm/errno.h>
63 #include <asm/segment.h>
67 #include <asm/mmu_context.h>
69 #if !defined(CONFIG_MMU)
70 #define sys_madvise sys_ni_syscall
71 #define sys_readahead sys_ni_syscall
72 #define sys_mprotect sys_ni_syscall
73 #define sys_msync sys_ni_syscall
74 #define sys_mlock sys_ni_syscall
75 #define sys_munlock sys_ni_syscall
76 #define sys_mlockall sys_ni_syscall
77 #define sys_munlockall sys_ni_syscall
78 #define sys_mremap sys_ni_syscall
79 #define sys_mincore sys_ni_syscall
80 #define sys_remap_file_pages sys_ni_syscall
81 #endif /* CONFIG_MMU */
84 #define R5(reg) @(0x04,reg)
85 #define R6(reg) @(0x08,reg)
86 #define PTREGS(reg) @(0x0C,reg)
87 #define R0(reg) @(0x10,reg)
88 #define R1(reg) @(0x14,reg)
89 #define R2(reg) @(0x18,reg)
90 #define R3(reg) @(0x1C,reg)
91 #define R7(reg) @(0x20,reg)
92 #define R8(reg) @(0x24,reg)
93 #define R9(reg) @(0x28,reg)
94 #define R10(reg) @(0x2C,reg)
95 #define R11(reg) @(0x30,reg)
96 #define R12(reg) @(0x34,reg)
97 #define SYSCALL_NR(reg) @(0x38,reg)
98 #define ACC0H(reg) @(0x3C,reg)
99 #define ACC0L(reg) @(0x40,reg)
100 #define ACC1H(reg) @(0x44,reg)
101 #define ACC1L(reg) @(0x48,reg)
102 #define PSW(reg) @(0x4C,reg)
103 #define BPC(reg) @(0x50,reg)
104 #define BBPSW(reg) @(0x54,reg)
105 #define BBPC(reg) @(0x58,reg)
106 #define SPU(reg) @(0x5C,reg)
107 #define FP(reg) @(0x60,reg) /* FP = R13 */
108 #define LR(reg) @(0x64,reg)
109 #define SP(reg) @(0x68,reg)
110 #define ORIG_R0(reg) @(0x6C,reg)
112 #define nr_syscalls ((syscall_table_size)/4)
114 #ifdef CONFIG_PREEMPT
115 #define preempt_stop(x) DISABLE_INTERRUPTS(x)
117 #define preempt_stop(x)
118 #define resume_kernel restore_all
128 * Return to user mode is not as complex as all this looks,
129 * but we want the default path for a system call return to
130 * go as quickly as possible which is why some of this is
131 * less clear than it otherwise should be.
134 ; userspace resumption stub bypassing syscall exit tracing
140 #ifdef CONFIG_ISA_M32R2
141 and3 r4, r4, #0x8800 ; check BSM and BPM bits
143 and3 r4, r4, #0x8000 ; check BSM bit
145 beqz r4, resume_kernel
146 ENTRY(resume_userspace)
147 DISABLE_INTERRUPTS(r4) ; make sure we don't miss an interrupt
148 ; setting need_resched or sigpending
149 ; between sampling and the iret
151 ld r9, @(TI_FLAGS, r8)
152 and3 r4, r9, #_TIF_WORK_MASK ; is there any work to be done on
153 ; int/exception return?
154 bnez r4, work_pending
157 #ifdef CONFIG_PREEMPT
160 ld r9, @(TI_PRE_COUNT, r8) ; non-zero preempt_count ?
163 ld r9, @(TI_FLAGS, r8) ; need_resched set ?
164 and3 r4, r9, #_TIF_NEED_RESCHED
166 ld r4, PSW(sp) ; interrupts off (exception path) ?
169 LDIMM (r4, PREEMPT_ACTIVE)
170 st r4, @(TI_PRE_COUNT, r8)
171 ENABLE_INTERRUPTS(r4)
174 st r4, @(TI_PRE_COUNT, r8)
175 DISABLE_INTERRUPTS(r4)
179 ; system call handler stub
181 SWITCH_TO_KERNEL_STACK
183 ENABLE_INTERRUPTS(r4) ; Enable interrupt
184 st sp, PTREGS(sp) ; implicit pt_regs parameter
185 cmpui r7, #NR_syscalls
187 st r7, SYSCALL_NR(sp) ; syscall_nr
188 ; system call tracing in operation
190 ld r9, @(TI_FLAGS, r8)
191 and3 r4, r9, #_TIF_SYSCALL_TRACE
192 bnez r4, syscall_trace_entry
194 slli r7, #2 ; table jump for the system call
195 LDIMM (r4, sys_call_table)
198 jl r7 ; execute system call
199 st r0, R0(sp) ; save the return value
201 DISABLE_INTERRUPTS(r4) ; make sure we don't miss an interrupt
202 ; setting need_resched or sigpending
203 ; between sampling and the iret
204 ld r9, @(TI_FLAGS, r8)
205 and3 r4, r9, #_TIF_ALLWORK_MASK ; current->work
206 bnez r4, syscall_exit_work
210 # perform work that needs to be done immediately before resumption
214 and3 r4, r9, #_TIF_NEED_RESCHED
215 beqz r4, work_notifysig
218 DISABLE_INTERRUPTS(r4) ; make sure we don't miss an interrupt
219 ; setting need_resched or sigpending
220 ; between sampling and the iret
221 ld r9, @(TI_FLAGS, r8)
222 and3 r4, r9, #_TIF_WORK_MASK ; is there any work to be done other
223 ; than syscall tracing?
225 and3 r4, r4, #_TIF_NEED_RESCHED
226 bnez r4, work_resched
228 work_notifysig: ; deal with pending signals and
229 ; notify-resume requests
230 mv r0, sp ; arg1 : struct pt_regs *regs
231 ldi r1, #0 ; arg2 : sigset_t *oldset
232 mv r2, r9 ; arg3 : __u32 thread_info_flags
236 ; perform syscall exit tracing
249 ld r7, SYSCALL_NR(sp)
250 cmpui r7, #NR_syscalls
254 ; perform syscall exit tracing
257 ld r9, @(TI_FLAGS, r8)
258 and3 r4, r9, #_TIF_SYSCALL_TRACE
259 beqz r4, work_pending
260 ENABLE_INTERRUPTS(r4) ; could let do_syscall_trace() call
281 .equ ei_vec_table, eit_vector + 0x0200
287 #if defined(CONFIG_CHIP_M32700)
288 ; WORKAROUND: force to clear SM bit and use the kernel stack (SPI).
289 SWITCH_TO_KERNEL_STACK
292 mv r1, sp ; arg1(regs)
294 seth r0, #shigh(M32R_ICU_ISTS_ADDR)
295 ld r0, @(low(M32R_ICU_ISTS_ADDR),r0)
297 #if defined(CONFIG_SMP)
299 * If IRQ == 0 --> Nothing to do, Not write IMASK
300 * If IRQ == IPI --> Do IPI handler, Not write IMASK
301 * If IRQ != 0, IPI --> Do do_IRQ(), Write IMASK
304 srli r0, #24 ; r0(irq_num<<2)
306 #if defined(CONFIG_CHIP_M32700)
307 /* WORKAROUND: IMASK bug M32700-TS1, TS2 chip. */
309 ld24 r14, #0x00070000
310 seth r0, #shigh(M32R_ICU_IMASK_ADDR)
311 st r14, @(low(M32R_ICU_IMASK_ADDR),r0)
315 #endif /* CONFIG_CHIP_M32700 */
316 beqz r0, 1f ; if (!irq_num) goto exit
318 cmpi r0, #(M32R_IRQ_IPI0<<2) ; ISN < IPI0 check
320 cmpi r0, #((M32R_IRQ_IPI7+1)<<2) ; ISN > IPI7 check
322 LDIMM (r2, ei_vec_table)
325 beqz r2, 1f ; if (no IPI handler) goto exit
326 mv r0, r1 ; arg0(regs)
335 #else /* not CONFIG_SMP */
336 srli r0, #22 ; r0(irq)
337 #endif /* not CONFIG_SMP */
339 #if defined(CONFIG_PLAT_HAS_INT1ICU)
340 add3 r2, r0, #-(M32R_IRQ_INT1) ; INT1# interrupt
342 seth r0, #shigh(M32R_INT1ICU_ISTS)
343 lduh r0, @(low(M32R_INT1ICU_ISTS),r0) ; bit10-6 : ISN
346 addi r0, #(M32R_INT1ICU_IRQ_BASE)
350 #endif /* CONFIG_PLAT_HAS_INT1ICU */
351 #if defined(CONFIG_PLAT_HAS_INT0ICU)
352 add3 r2, r0, #-(M32R_IRQ_INT0) ; INT0# interrupt
354 seth r0, #shigh(M32R_INT0ICU_ISTS)
355 lduh r0, @(low(M32R_INT0ICU_ISTS),r0) ; bit10-6 : ISN
358 add3 r0, r0, #(M32R_INT0ICU_IRQ_BASE)
362 #endif /* CONFIG_PLAT_HAS_INT0ICU */
363 #if defined(CONFIG_PLAT_HAS_INT2ICU)
364 add3 r2, r0, #-(M32R_IRQ_INT2) ; INT2# interrupt
366 seth r0, #shigh(M32R_INT2ICU_ISTS)
367 lduh r0, @(low(M32R_INT2ICU_ISTS),r0) ; bit10-6 : ISN
370 add3 r0, r0, #(M32R_INT2ICU_IRQ_BASE)
374 #endif /* CONFIG_PLAT_HAS_INT2ICU */
379 seth r0, #shigh(M32R_ICU_IMASK_ADDR)
380 st r14, @(low(M32R_ICU_IMASK_ADDR),r0)
384 * Default EIT handler
388 .asciz "Unknown interrupt\n"
391 ENTRY(default_eit_handler)
398 LDIMM (r0, __KERNEL_DS)
414 * Access Exception handler
417 SWITCH_TO_KERNEL_STACK
420 seth r2, #shigh(MMU_REG_BASE) /* Check status register */
421 ld r4, @(low(MESTS_offset),r2)
422 st r4, @(low(MESTS_offset),r2)
424 #ifdef CONFIG_CHIP_M32700
425 and3 r1, r1, #0x0000ffff
426 ; WORKAROUND: ignore TME bit for the M32700(TS1).
427 #endif /* CONFIG_CHIP_M32700 */
430 ld r2, @(low(MDEVA_offset),r2) ; set address
437 mvfc r2, bpc ; set address
447 * r0 : struct pt_regs *regs
448 * r1 : unsigned long error-code
449 * r2 : unsigned long address
451 * +------+------+------+------+
452 * | bit3 | bit2 | bit1 | bit0 |
453 * +------+------+------+------+
454 * bit 3 == 0:means data, 1:means instruction
455 * bit 2 == 0:means kernel, 1:means user-mode
456 * bit 1 == 0:means read, 1:means write
457 * bit 0 == 0:means no page found 1:means protection fault
462 #endif /* CONFIG_MMU */
465 ENTRY(alignment_check)
466 /* void alignment_check(int error_code) */
467 SWITCH_TO_KERNEL_STACK
469 ldi r1, #0x30 ; error_code
471 bl do_alignment_check
473 bra ret_from_exception
476 /* void rie_handler(int error_code) */
477 SWITCH_TO_KERNEL_STACK
479 ldi r1, #0x20 ; error_code
485 /* void pie_handler(int error_code) */
486 SWITCH_TO_KERNEL_STACK
488 ldi r1, #0 ; error_code ; FIXME
494 /* void debug_trap(void) */
495 .global withdraw_debug_trap
496 SWITCH_TO_KERNEL_STACK
499 bl withdraw_debug_trap
500 ldi r1, #0 ; error_code
506 /* void ill_trap(void) */
507 SWITCH_TO_KERNEL_STACK
509 ldi r1, #0 ; error_code ; FIXME
514 ENTRY(cache_flushing_handler)
515 /* void _flush_cache_all(void); */
516 .global _flush_cache_all
517 SWITCH_TO_KERNEL_STACK
540 #include "syscall_table.S"
542 syscall_table_size=(.-sys_call_table)