2 * Copyright (C) 2007-2009 Michal Simek <monstr@monstr.eu>
3 * Copyright (C) 2007-2009 PetaLogix
4 * Copyright (C) 2006 Atmark Techno, Inc.
6 * This file is subject to the terms and conditions of the GNU General Public
7 * License. See the file "COPYING" in the main directory of this archive
11 #include <linux/linkage.h>
12 #include <asm/thread_info.h>
13 #include <linux/errno.h>
14 #include <asm/entry.h>
15 #include <asm/asm-offsets.h>
16 #include <asm/registers.h>
17 #include <asm/unistd.h>
18 #include <asm/percpu.h>
19 #include <asm/signal.h>
21 #if CONFIG_XILINX_MICROBLAZE0_USE_MSR_INSTR
36 andi r11, r11, ~MSR_IE
48 andi r11, r11, ~MSR_BIP
54 swi r1, r0, PER_CPU(ENTRY_SP) /* save the current sp */
55 swi r11, r0, PER_CPU(R11_SAVE) /* temporarily save r11 */
56 lwi r11, r0, PER_CPU(KM) /* load mode indicator */
59 brid 2f /* jump over */
60 addik r1, r1, (-PT_SIZE) /* room for pt_regs (delay slot) */
61 1: /* switch to kernel stack */
62 lwi r1, r0, PER_CPU(CURRENT_SAVE) /* get the saved current */
63 lwi r1, r1, TS_THREAD_INFO /* get the thread info */
64 /* calculate kernel stack pointer */
65 addik r1, r1, THREAD_SIZE - PT_SIZE
67 swi r11, r1, PT_MODE /* store the mode */
68 lwi r11, r0, PER_CPU(R11_SAVE) /* reload r11 */
100 /* special purpose registers */
109 /* reload original stack pointer and save it */
110 lwi r11, r0, PER_CPU(ENTRY_SP)
112 /* update mode indicator we are in kernel mode */
114 swi r11, r0, PER_CPU(KM)
116 lwi r31, r0, PER_CPU(CURRENT_SAVE)
117 /* prepare the link register, the argument and jump */
118 addik r15, r0, ret_from_intr - 8
125 bneid r11, no_intr_resched
127 lwi r6, r31, TS_THREAD_INFO /* get thread info */
128 lwi r19, r6, TI_FLAGS /* get flags in thread info */
129 /* do an extra work if any bits are set */
131 andi r11, r19, _TIF_NEED_RESCHED
135 1: andi r11, r19, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME
136 beqid r11, no_intr_resched
138 bralid r15, do_notify_resume
142 /* Disable interrupts, we are now committed to the state restore */
145 /* save mode indicator */
147 swi r11, r0, PER_CPU(KM)
150 swi r31, r0, PER_CPU(CURRENT_SAVE)
152 /* special purpose registers */
199 ENTRY(_user_exception)
200 swi r1, r0, PER_CPU(ENTRY_SP) /* save the current sp */
201 swi r11, r0, PER_CPU(R11_SAVE) /* temporarily save r11 */
202 lwi r11, r0, PER_CPU(KM) /* load mode indicator */
203 beqid r11, 1f /* Already in kernel mode? */
205 brid 2f /* jump over */
206 addik r1, r1, (-PT_SIZE) /* Room for pt_regs (delay slot) */
207 1: /* Switch to kernel stack */
208 lwi r1, r0, PER_CPU(CURRENT_SAVE) /* get the saved current */
209 lwi r1, r1, TS_THREAD_INFO /* get the thread info */
210 /* calculate kernel stack pointer */
211 addik r1, r1, THREAD_SIZE - PT_SIZE
213 swi r11, r1, PT_MODE /* store the mode */
214 lwi r11, r0, PER_CPU(R11_SAVE) /* reload r11 */
215 /* save them on stack */
217 swi r3, r1, PT_R3 /* r3: _always_ in clobber list; see unistd.h */
218 swi r4, r1, PT_R4 /* r4: _always_ in clobber list; see unistd.h */
226 /* r12: _always_ in clobber list; see unistd.h */
229 /* r14: _always_ in clobber list; see unistd.h */
231 /* but we want to return to the next inst. */
233 swi r14, r1, PT_PC /* increment by 4 and store in pc */
253 nop /* make sure IE bit is in effect */
254 clear_bip /* once IE is in effect it is safe to clear BIP */
257 /* special purpose registers */
266 /* reload original stack pointer and save it */
267 lwi r11, r0, PER_CPU(ENTRY_SP)
269 /* update mode indicator we are in kernel mode */
271 swi r11, r0, PER_CPU(KM)
273 lwi r31, r0, PER_CPU(CURRENT_SAVE)
274 /* re-enable interrupts now we are in kernel mode */
277 /* See if the system call number is valid. */
278 addi r11, r12, -__NR_syscalls
279 bgei r11, 1f /* return to user if not valid */
280 /* Figure out which function to use for this system call. */
281 /* Note Microblaze barrel shift is optional, so don't rely on it */
282 add r12, r12, r12 /* convert num -> ptr */
284 lwi r12, r12, sys_call_table /* Get function pointer */
285 addik r15, r0, ret_to_user-8 /* set return address */
286 bra r12 /* Make the system call. */
287 bri 0 /* won't reach here */
289 brid ret_to_user /* jump to syscall epilogue */
290 addi r3, r0, -ENOSYS /* set errno in delay slot */
293 * Debug traps are like a system call, but entered via brki r14, 0x60
294 * All we need to do is send the SIGTRAP signal to current, ptrace and
295 * do_notify_resume will handle the rest
297 ENTRY(_debug_exception)
298 swi r1, r0, PER_CPU(ENTRY_SP) /* save the current sp */
299 lwi r1, r0, PER_CPU(CURRENT_SAVE) /* get the saved current */
300 lwi r1, r1, TS_THREAD_INFO /* get the thread info */
301 addik r1, r1, THREAD_SIZE - PT_SIZE /* get the kernel stack */
302 swi r11, r0, PER_CPU(R11_SAVE) /* temporarily save r11 */
303 lwi r11, r0, PER_CPU(KM) /* load mode indicator */
305 swi r11, r1, PT_MODE /* store the mode */
306 lwi r11, r0, PER_CPU(R11_SAVE) /* reload r11 */
307 /* save them on stack */
309 swi r3, r1, PT_R3 /* r3: _always_ in clobber list; see unistd.h */
310 swi r4, r1, PT_R4 /* r4: _always_ in clobber list; see unistd.h */
318 /* r12: _always_ in clobber list; see unistd.h */
321 /* r14: _always_ in clobber list; see unistd.h */
323 swi r14, r1, PT_PC /* Will return to interrupted instruction */
343 nop /* make sure IE bit is in effect */
344 clear_bip /* once IE is in effect it is safe to clear BIP */
347 /* special purpose registers */
356 /* reload original stack pointer and save it */
357 lwi r11, r0, PER_CPU(ENTRY_SP)
359 /* update mode indicator we are in kernel mode */
361 swi r11, r0, PER_CPU(KM)
363 lwi r31, r0, PER_CPU(CURRENT_SAVE)
364 /* re-enable interrupts now we are in kernel mode */
367 addi r5, r0, SIGTRAP /* sending the trap signal */
368 add r6, r0, r31 /* to current */
370 add r7, r0, r0 /* 3rd param zero */
372 /* Restore r3/r4 to work around how ret_to_user works */
380 /* struct task_struct *_switch_to(struct thread_info *prev,
381 struct thread_info *next); */
383 /* prepare return value */
386 /* save registers in cpu_context */
387 /* use r11 and r12, volatile registers, as temp register */
388 addik r11, r5, TI_CPU_CONTEXT
391 /* skip volatile registers.
392 * they are saved on stack when we jumped to _switch_to() */
393 /* dedicated registers */
400 /* save non-volatile registers */
413 /* special purpose registers */
423 /* update r31, the current */
425 swi r31, r0, PER_CPU(CURRENT_SAVE)
427 /* get new process' cpu context and restore */
428 addik r11, r6, TI_CPU_CONTEXT
430 /* special purpose registers */
439 /* non-volatile registers */
452 /* dedicated registers */
459 /* skip volatile registers */
469 brlid r15, schedule_tail
471 swi r31, r1, PT_R31 /* save r31 in user context. */
472 /* will soon be restored to r31 in ret_to_user */
480 andi r11, r19, _TIF_NEED_RESCHED
484 1: andi r11, r19, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME
485 beqi r11, no_work_pending
487 bralid r15, do_notify_resume
494 swi r4, r1, PT_R4 /* return val */
495 swi r3, r1, PT_R3 /* return val */
497 lwi r6, r31, TS_THREAD_INFO /* get thread info */
498 lwi r19, r6, TI_FLAGS /* get flags in thread info */
499 bnei r19, work_pending /* do an extra work if any bits are set */
504 swi r31, r0, PER_CPU(CURRENT_SAVE)
505 /* save mode indicator */
507 swi r18, r0, PER_CPU(KM)
509 /* special purpose registers */
546 lwi r4, r1, PT_R4 /* return val */
547 lwi r3, r1, PT_R3 /* return val */
555 brid microblaze_vfork
559 brid microblaze_clone
563 brid microblaze_execve
566 sys_rt_sigreturn_wrapper:
567 brid sys_rt_sigreturn
570 /* Interrupt vector table */
571 .section .init.ivt, "ax"
577 brai _hw_exception_handler
579 brai _debug_exception
582 #include "syscall_table.S"
584 syscall_table_size=(.-sys_call_table)
591 .ascii "IRQ (PREEMPTED)\0"
592 type_SYSCALL_PREEMPT:
593 .ascii " SYSCALL (PREEMPTED)\0"
596 * Trap decoding for stack unwinder
597 * Tuples are (start addr, end addr, string)
598 * If return address lies on [start addr, end addr],
599 * unwinder displays 'string'
603 .global microblaze_trap_handlers
604 microblaze_trap_handlers:
605 /* Exact matches come first */
606 .word ret_to_user ; .word ret_to_user ; .word type_SYSCALL
607 .word ret_from_intr; .word ret_from_intr ; .word type_IRQ
608 /* Fuzzy matches go here */
609 .word ret_from_intr; .word no_intr_resched; .word type_IRQ_PREEMPT
610 .word work_pending ; .word no_work_pending; .word type_SYSCALL_PREEMPT
612 .word 0 ; .word 0 ; .word 0