1 /* SPDX-License-Identifier: GPL-2.0 */
4 * linux/arch/h8300/kernel/entry.S
6 * Yoshinori Sato <ysato@users.sourceforge.jp>
7 * David McCullough <davidm@snapgear.com>
13 * include exception/interrupt gateway
17 #include <linux/sys.h>
18 #include <asm/unistd.h>
19 #include <asm/setup.h>
20 #include <asm/segment.h>
21 #include <asm/linkage.h>
22 #include <asm/asm-offsets.h>
23 #include <asm/thread_info.h>
24 #include <asm/errno.h>
26 #if defined(CONFIG_CPU_H8300H)
53 #if defined(CONFIG_CPU_H8S)
71 mov.w @(USEREXR:16,er0),r1
72 mov.w r1,@(LEXR-LER3:16,sp) /* copy EXR */
75 mov.w @(LEXR-LER1:16,sp),r1 /* restore EXR */
77 mov.w r1,@(USEREXR:16,er0)
82 /* CPU context save/restore macros. */
86 stc ccr,r0l /* check kernel mode */
92 mov.l @sp,er0 /* restore saved er0 */
93 orc #0x10,ccr /* switch kernel stack */
95 sub.l #(LRET-LORIG),sp /* allocate LORIG - LRET */
98 mov.l @(USERRET:16,er0),er1 /* copy the RET addr */
99 mov.l er1,@(LRET-LER3:16,sp)
102 mov.l @(LORIG-LER3:16,sp),er0
103 mov.l er0,@(LER0-LER3:16,sp) /* copy ER0 */
104 mov.w e1,r1 /* e1 highbyte = ccr */
105 and #0xef,r1h /* mask mode? flag */
109 mov.l @sp,er0 /* restore saved er0 */
110 subs #2,sp /* set dummy ccr */
111 subs #4,sp /* set dummp sp */
113 mov.w @(LRET-LER3:16,sp),r1 /* copy old ccr */
117 mov.w r1,@(LCCR-LER3:16,sp) /* set ccr */
119 mov.l er2,@(LSP-LER3:16,sp) /* set usp */
120 mov.l er6,@-sp /* syscall arg #6 */
121 mov.l er5,@-sp /* syscall arg #5 */
122 mov.l er4,@-sp /* syscall arg #4 */
130 mov.w @(LCCR-LER1:16,sp),r0 /* check kernel mode */
135 mov.l @(LSP-LER1:16,sp),er0
136 mov.l @(LER0-LER1:16,sp),er1 /* restore ER0 */
139 mov.w @(LCCR-LER1:16,sp),r1 /* restore the RET addr */
141 mov.b @(LRET+1-LER1:16,sp),r1l
143 mov.w @(LRET+2-LER1:16,sp),r1
144 mov.l er1,@(USERRET:16,er0)
147 add.l #(LRET-LER1),sp /* remove LORIG - LRET */
149 andc #0xef,ccr /* switch to user mode */
157 adds #4,sp /* remove the sw created LVEC */
162 .globl ret_from_exception
164 .globl ret_from_kernel_thread
165 .globl ret_from_interrupt
166 .globl _interrupt_redirect_table
167 .globl _sw_ksp,_sw_usp
169 .globl _interrupt_entry
173 #if defined(CONFIG_ROMKERNEL)
174 .section .int_redirect,"ax"
175 _interrupt_redirect_table:
176 #if defined(CONFIG_CPU_H8300H)
181 #if defined(CONFIG_CPU_H8S)
189 jsr @_interrupt_entry /* NMI */
190 jmp @_system_call /* TRAPA #0 (System call) */
192 #if defined(CONFIG_KGDB)
197 jmp @_trace_break /* TRAPA #3 (breakpoint) */
199 jsr @_interrupt_entry
202 #if defined(CONFIG_RAMKERNEL)
203 .globl _interrupt_redirect_table
205 _interrupt_redirect_table:
213 /* r1l is saved ccr */
222 mov.l @er0,er0 /* LVEC address */
223 #if defined(CONFIG_ROMKERNEL)
224 sub.l #_interrupt_redirect_table,er0
226 #if defined(CONFIG_RAMKERNEL)
227 mov.l @_interrupt_redirect_table,er1
233 subs #4,er1 /* adjust ret_pc */
234 #if defined(CONFIG_CPU_H8S)
238 jmp @ret_from_interrupt
241 subs #4,sp /* dummy LVEC */
243 /* er0: syscall nr */
247 /* save top of frame */
253 mov.l @(TI_FLAGS:16,er2),er2
254 and.w #_TIF_WORK_SYSCALL_MASK,r2
257 jsr @do_syscall_trace_enter
259 cmp.l #__NR_syscalls,er4
262 mov.l #_sys_call_table,er0
265 beq ret_from_exception:16
266 mov.l @(LER1:16,sp),er0
267 mov.l @(LER2:16,sp),er1
268 mov.l @(LER3:16,sp),er2
270 mov.l er0,@(LER0:16,sp) /* save the return value */
273 mov.l @(TI_FLAGS:16,er2),er2
274 and.w #_TIF_WORK_SYSCALL_MASK,r2
277 jsr @do_syscall_trace_leave
284 mov.l er0,@(LER0:16,sp)
287 #if !defined(CONFIG_PREEMPTION)
288 #define resume_kernel restore_all
292 #if defined(CONFIG_PREEMPTION)
296 mov.b @(LCCR+1:16,sp),r0l
298 bne resume_kernel:16 /* return from kernel */
302 and.w #0xe000,r4 /* er4 <- current thread info */
303 mov.l @(TI_FLAGS:16,er4),er1
304 and.l #_TIF_WORK_MASK,er1
307 btst #TIF_NEED_RESCHED,r1l
311 subs #4,er0 /* er0: pt_regs */
312 jsr @do_notify_resume
313 bra resume_userspace:8
318 bra resume_userspace:8
320 RESTORE_ALL /* Does RTE */
322 #if defined(CONFIG_PREEMPTION)
324 mov.l @(TI_PRE_COUNT:16,er4),er0
327 mov.l @(TI_FLAGS:16,er4),er0
328 btst #TIF_NEED_RESCHED,r0l
330 mov.b @(LCCR+1:16,sp),r0l /* Interrupt Enabled? */
334 jsr @preempt_schedule_irq
341 jmp @ret_from_exception
343 ret_from_kernel_thread:
346 mov.l @(LER4:16,sp),er0
347 mov.l @(LER5:16,sp),er1
349 jmp @ret_from_exception
353 * Beware - when entering resume, offset of tss is in d1,
354 * prev (the current task) is in a0, next (the new task)
355 * is in a1 and d2.b is non-zero if the mm structure is
356 * shared between the tasks, so don't change these
357 * registers until their contents are no longer needed.
363 mov.w r3,@(THREAD_CCR+2:16,er0)
365 /* disable interrupts */
368 mov.l er3,@(THREAD_USP:16,er0)
369 mov.l sp,@(THREAD_KSP:16,er0)
371 /* Skip address space switching if they are the same. */
372 /* FIXME: what did we hack out of here, this does nothing! */
374 mov.l @(THREAD_USP:16,er1),er0
376 mov.l @(THREAD_KSP:16,er1),sp
378 /* restore status register */
379 mov.w @(THREAD_CCR+2:16,er1),r3
389 mov.l er1,@(LORIG,sp)
394 mov.w @(-2:16,er1),r2
403 jmp @ret_from_exception
408 mov.l @_interrupt_redirect_table, er0
412 jmp @_interrupt_entry
414 #if defined(CONFIG_KGDB)
425 jmp @ret_from_exception