2 * Low-level system-call handling, trap handlers and context-switching
4 * Copyright (C) 2008-2009 Michal Simek <monstr@monstr.eu>
5 * Copyright (C) 2008-2009 PetaLogix
6 * Copyright (C) 2003 John Williams <jwilliams@itee.uq.edu.au>
7 * Copyright (C) 2001,2002 NEC Corporation
8 * Copyright (C) 2001,2002 Miles Bader <miles@gnu.org>
10 * This file is subject to the terms and conditions of the GNU General
11 * Public License. See the file COPYING in the main directory of this
12 * archive for more details.
14 * Written by Miles Bader <miles@gnu.org>
15 * Heavily modified by John Williams for Microblaze
18 #include <linux/sys.h>
19 #include <linux/linkage.h>
21 #include <asm/entry.h>
22 #include <asm/current.h>
23 #include <asm/processor.h>
24 #include <asm/exceptions.h>
25 #include <asm/asm-offsets.h>
26 #include <asm/thread_info.h>
29 #include <asm/unistd.h>
31 #include <linux/errno.h>
32 #include <asm/signal.h>
37 /* Create space for syscalls counting. */
39 .global syscall_debug_table
42 .space (__NR_syscalls * 4)
45 #define C_ENTRY(name) .globl name; .align 4; name
48 * Various ways of setting and clearing BIP in flags reg.
49 * This is mucky, but necessary using microblaze version that
50 * allows msr ops to write to BIP
52 #if CONFIG_XILINX_MICROBLAZE0_USE_MSR_INSTR
92 msrclr r0, MSR_VMS | MSR_UMS
97 andi r11, r11, ~MSR_BIP
103 ori r11, r11, MSR_BIP
109 andi r11, r11, ~MSR_EIP
121 andi r11, r11, ~MSR_IE
133 ori r11, r11, MSR_VMS
134 andni r11, r11, MSR_UMS
140 ori r11, r11, MSR_VMS
141 andni r11, r11, MSR_UMS
147 andni r11, r11, MSR_UMS
153 andni r11, r11, (MSR_VMS|MSR_UMS)
158 /* Define how to call high-level functions. With MMU, virtual mode must be
159 * enabled when calling the high-level function. Clobbers R11.
160 * VM_ON, VM_OFF, DO_JUMP_BIPCLR, DO_CALL
163 /* turn on virtual protected mode save */
170 /* turn off virtual protected mode save and user mode save*/
173 rted r0, TOPHYS(1f); \
178 swi r2, r1, PT_R2; /* Save SDA */ \
186 swi r10, r1, PT_R10; \
187 swi r11, r1, PT_R11; /* save clobbered regs after rval */\
188 swi r12, r1, PT_R12; \
189 swi r13, r1, PT_R13; /* Save SDA2 */ \
190 swi r14, r1, PT_PC; /* PC, before IRQ/trap */ \
191 swi r15, r1, PT_R15; /* Save LP */ \
192 swi r16, r1, PT_R16; \
193 swi r17, r1, PT_R17; \
194 swi r18, r1, PT_R18; /* Save asm scratch reg */ \
195 swi r19, r1, PT_R19; \
196 swi r20, r1, PT_R20; \
197 swi r21, r1, PT_R21; \
198 swi r22, r1, PT_R22; \
199 swi r23, r1, PT_R23; \
200 swi r24, r1, PT_R24; \
201 swi r25, r1, PT_R25; \
202 swi r26, r1, PT_R26; \
203 swi r27, r1, PT_R27; \
204 swi r28, r1, PT_R28; \
205 swi r29, r1, PT_R29; \
206 swi r30, r1, PT_R30; \
207 swi r31, r1, PT_R31; /* Save current task reg */ \
208 mfs r11, rmsr; /* save MSR */ \
211 #define RESTORE_REGS \
212 lwi r11, r1, PT_MSR; \
214 lwi r2, r1, PT_R2; /* restore SDA */ \
222 lwi r10, r1, PT_R10; \
223 lwi r11, r1, PT_R11; /* restore clobbered regs after rval */\
224 lwi r12, r1, PT_R12; \
225 lwi r13, r1, PT_R13; /* restore SDA2 */ \
226 lwi r14, r1, PT_PC; /* RESTORE_LINK PC, before IRQ/trap */\
227 lwi r15, r1, PT_R15; /* restore LP */ \
228 lwi r16, r1, PT_R16; \
229 lwi r17, r1, PT_R17; \
230 lwi r18, r1, PT_R18; /* restore asm scratch reg */ \
231 lwi r19, r1, PT_R19; \
232 lwi r20, r1, PT_R20; \
233 lwi r21, r1, PT_R21; \
234 lwi r22, r1, PT_R22; \
235 lwi r23, r1, PT_R23; \
236 lwi r24, r1, PT_R24; \
237 lwi r25, r1, PT_R25; \
238 lwi r26, r1, PT_R26; \
239 lwi r27, r1, PT_R27; \
240 lwi r28, r1, PT_R28; \
241 lwi r29, r1, PT_R29; \
242 lwi r30, r1, PT_R30; \
243 lwi r31, r1, PT_R31; /* Restore cur task reg */
246 swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)); /* save stack */ \
247 /* See if already in kernel mode.*/ \
249 andi r1, r1, MSR_UMS; \
251 /* Kernel-mode state save. */ \
252 /* Reload kernel stack-ptr. */ \
253 lwi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)); \
254 /* FIXME: I can add these two lines to one */ \
255 /* tophys(r1,r1); */ \
256 /* addik r1, r1, -PT_SIZE; */ \
257 addik r1, r1, CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START - PT_SIZE; \
260 swi r1, r1, PT_MODE; \
261 1: /* User-mode state save. */ \
262 lwi r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); /* get saved current */\
264 lwi r1, r1, TS_THREAD_INFO; /* get the thread info */ \
265 /* MS these three instructions can be added to one */ \
266 /* addik r1, r1, THREAD_SIZE; */ \
267 /* tophys(r1,r1); */ \
268 /* addik r1, r1, -PT_SIZE; */ \
269 addik r1, r1, THREAD_SIZE + CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START - PT_SIZE; \
271 lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); \
272 swi r11, r1, PT_R1; /* Store user SP. */ \
273 swi r0, r1, PT_MODE; /* Was in user-mode. */ \
274 /* MS: I am clearing UMS even in case when I come from kernel space */ \
276 2: lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
283 * System calls are handled here.
286 * Syscall number in r12, args in r5-r10
289 * Trap entered via brki instruction, so BIP bit is set, and interrupts
290 * are masked. This is nice, means we don't have to CLI before state save
292 C_ENTRY(_user_exception):
293 swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)) /* save stack */
294 addi r14, r14, 4 /* return address is 4 byte after call */
296 lwi r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); /* get saved current */
298 lwi r1, r1, TS_THREAD_INFO; /* get stack from task_struct */
299 /* calculate kernel stack pointer from task struct 8k */
300 addik r1, r1, THREAD_SIZE;
303 addik r1, r1, -PT_SIZE; /* Make room on the stack. */
308 swi r0, r1, PT_MODE; /* Was in user-mode. */
309 lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
310 swi r11, r1, PT_R1; /* Store user SP. */
312 2: lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
313 /* Save away the syscall number. */
317 /* where the trap should return need -8 to adjust for rtsd r15, 8*/
318 /* Jump to the appropriate function for the system call number in r12
319 * (r12 is not preserved), or return an error if r12 is not valid. The LP
320 * register should point to the location where
321 * the called function should return. [note that MAKE_SYS_CALL uses label 1] */
323 /* Step into virtual mode */
327 lwi r11, CURRENT_TASK, TS_THREAD_INFO /* get thread info */
328 lwi r11, r11, TI_FLAGS /* get flags in thread info */
329 andi r11, r11, _TIF_WORK_SYSCALL_MASK
332 addik r3, r0, -ENOSYS
334 brlid r15, do_syscall_trace_enter
337 # do_syscall_trace_enter returns the new syscall nr.
346 /* Jump to the appropriate function for the system call number in r12
347 * (r12 is not preserved), or return an error if r12 is not valid.
348 * The LP register should point to the location where the called function
349 * should return. [note that MAKE_SYS_CALL uses label 1] */
350 /* See if the system call number is valid */
351 addi r11, r12, -__NR_syscalls;
353 /* Figure out which function to use for this system call. */
354 /* Note Microblaze barrel shift is optional, so don't rely on it */
355 add r12, r12, r12; /* convert num -> ptr */
357 addi r30, r0, 1 /* restarts allowed */
360 /* Trac syscalls and stored them to syscall_debug_table */
361 /* The first syscall location stores total syscall number */
362 lwi r3, r0, syscall_debug_table
364 swi r3, r0, syscall_debug_table
365 lwi r3, r12, syscall_debug_table
367 swi r3, r12, syscall_debug_table
370 # Find and jump into the syscall handler.
371 lwi r12, r12, sys_call_table
372 /* where the trap should return need -8 to adjust for rtsd r15, 8 */
373 addi r15, r0, ret_from_trap-8
376 /* The syscall number is invalid, return an error. */
378 rtsd r15, 8; /* looks like a normal subroutine return */
379 addi r3, r0, -ENOSYS;
381 /* Entry point used to return from a syscall/trap */
382 /* We re-enable BIP bit before state restore */
383 C_ENTRY(ret_from_trap):
387 lwi r11, r1, PT_MODE;
388 /* See if returning to kernel mode, if so, skip resched &c. */
390 /* We're returning to user mode, so check for various conditions that
391 * trigger rescheduling. */
392 /* FIXME: Restructure all these flag checks. */
393 lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */
394 lwi r11, r11, TI_FLAGS; /* get flags in thread info */
395 andi r11, r11, _TIF_WORK_SYSCALL_MASK
398 brlid r15, do_syscall_trace_leave
401 /* We're returning to user mode, so check for various conditions that
402 * trigger rescheduling. */
403 /* get thread info from current task */
404 lwi r11, CURRENT_TASK, TS_THREAD_INFO;
405 lwi r19, r11, TI_FLAGS; /* get flags in thread info */
406 andi r11, r19, _TIF_NEED_RESCHED;
409 bralid r15, schedule; /* Call scheduler */
410 nop; /* delay slot */
413 /* Maybe handle a signal */
415 andi r11, r19, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME;
416 beqi r11, 4f; /* Signals to handle, handle them */
418 addik r5, r1, 0; /* Arg 1: struct pt_regs *regs */
419 bralid r15, do_notify_resume; /* Handle any signals */
420 add r6, r30, r0; /* Arg 2: int in_syscall */
421 add r30, r0, r0 /* no more restarts */
424 /* Finally, return to user state. */
425 4: set_bip; /* Ints masked for state restore */
426 swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */
430 addik r1, r1, PT_SIZE /* Clean up stack space. */
431 lwi r1, r1, PT_R1 - PT_SIZE;/* Restore user stack pointer. */
434 /* Return to kernel state. */
435 2: set_bip; /* Ints masked for state restore */
439 addik r1, r1, PT_SIZE /* Clean up stack space. */
442 TRAP_return: /* Make global symbol for debugging */
443 rtbd r14, 0; /* Instructions to return from an IRQ */
447 /* This the initial entry point for a new child thread, with an appropriate
448 stack in place that makes it look the the child is in the middle of an
449 syscall. This function is actually `returned to' from switch_thread
450 (copy_thread makes ret_from_fork the return address in each new thread's
452 C_ENTRY(ret_from_fork):
453 bralid r15, schedule_tail; /* ...which is schedule_tail's arg */
454 add r5, r3, r0; /* switch_thread returns the prev task */
455 /* ( in the delay slot ) */
456 brid ret_from_trap; /* Do normal trap return */
457 add r3, r0, r0; /* Child's fork call should return 0. */
459 C_ENTRY(ret_from_kernel_thread):
460 bralid r15, schedule_tail; /* ...which is schedule_tail's arg */
461 add r5, r3, r0; /* switch_thread returns the prev task */
462 /* ( in the delay slot ) */
463 brald r15, r20 /* fn was left in r20 */
464 addk r5, r0, r19 /* ... and argument - in r19 */
468 C_ENTRY(sys_rt_sigreturn_wrapper):
469 addik r30, r0, 0 /* no restarts */
470 brid sys_rt_sigreturn /* Do real work */
471 addik r5, r1, 0; /* add user context as 1st arg */
474 * HW EXCEPTION rutine start
476 C_ENTRY(full_exception_trap):
477 /* adjust exception address for privileged instruction
478 * for finding where is it */
480 SAVE_STATE /* Save registers */
481 /* PC, before IRQ/trap - this is one instruction above */
484 /* FIXME this can be store directly in PT_ESR reg.
485 * I tested it but there is a fault */
486 /* where the trap should return need -8 to adjust for rtsd r15, 8 */
487 addik r15, r0, ret_from_exc - 8
489 mfs r7, rfsr; /* save FSR */
490 mts rfsr, r0; /* Clear sticky fsr */
491 rted r0, full_exception
492 addik r5, r1, 0 /* parameter struct pt_regs * regs */
495 * Unaligned data trap.
497 * Unaligned data trap last on 4k page is handled here.
499 * Trap entered via exception, so EE bit is set, and interrupts
500 * are masked. This is nice, means we don't have to CLI before state save
502 * The assembler routine is in "arch/microblaze/kernel/hw_exception_handler.S"
504 C_ENTRY(unaligned_data_trap):
505 /* MS: I have to save r11 value and then restore it because
506 * set_bit, clear_eip, set_ee use r11 as temp register if MSR
507 * instructions are not used. We don't need to do if MSR instructions
508 * are used and they use r0 instead of r11.
509 * I am using ENTRY_SP which should be primary used only for stack
511 swi r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
512 set_bip; /* equalize initial state for all possible entries */
515 lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
516 SAVE_STATE /* Save registers.*/
517 /* PC, before IRQ/trap - this is one instruction above */
520 /* where the trap should return need -8 to adjust for rtsd r15, 8 */
521 addik r15, r0, ret_from_exc-8
522 mfs r3, resr /* ESR */
523 mfs r4, rear /* EAR */
524 rtbd r0, _unaligned_data_exception
525 addik r7, r1, 0 /* parameter struct pt_regs * regs */
530 * If the real exception handler (from hw_exception_handler.S) didn't find
531 * the mapping for the process, then we're thrown here to handle such situation.
533 * Trap entered via exceptions, so EE bit is set, and interrupts
534 * are masked. This is nice, means we don't have to CLI before state save
536 * Build a standard exception frame for TLB Access errors. All TLB exceptions
537 * will bail out to this point if they can't resolve the lightweight TLB fault.
539 * The C function called is in "arch/microblaze/mm/fault.c", declared as:
540 * void do_page_fault(struct pt_regs *regs,
541 * unsigned long address,
542 * unsigned long error_code)
544 /* data and intruction trap - which is choose is resolved int fault.c */
545 C_ENTRY(page_fault_data_trap):
546 SAVE_STATE /* Save registers.*/
547 /* PC, before IRQ/trap - this is one instruction above */
550 /* where the trap should return need -8 to adjust for rtsd r15, 8 */
551 addik r15, r0, ret_from_exc-8
552 mfs r6, rear /* parameter unsigned long address */
553 mfs r7, resr /* parameter unsigned long error_code */
554 rted r0, do_page_fault
555 addik r5, r1, 0 /* parameter struct pt_regs * regs */
557 C_ENTRY(page_fault_instr_trap):
558 SAVE_STATE /* Save registers.*/
559 /* PC, before IRQ/trap - this is one instruction above */
562 /* where the trap should return need -8 to adjust for rtsd r15, 8 */
563 addik r15, r0, ret_from_exc-8
564 mfs r6, rear /* parameter unsigned long address */
565 ori r7, r0, 0 /* parameter unsigned long error_code */
566 rted r0, do_page_fault
567 addik r5, r1, 0 /* parameter struct pt_regs * regs */
569 /* Entry point used to return from an exception. */
570 C_ENTRY(ret_from_exc):
571 lwi r11, r1, PT_MODE;
572 bnei r11, 2f; /* See if returning to kernel mode, */
573 /* ... if so, skip resched &c. */
575 /* We're returning to user mode, so check for various conditions that
576 trigger rescheduling. */
578 lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */
579 lwi r19, r11, TI_FLAGS; /* get flags in thread info */
580 andi r11, r19, _TIF_NEED_RESCHED;
583 /* Call the scheduler before returning from a syscall/trap. */
584 bralid r15, schedule; /* Call scheduler */
585 nop; /* delay slot */
588 /* Maybe handle a signal */
589 5: andi r11, r19, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME;
590 beqi r11, 4f; /* Signals to handle, handle them */
593 * Handle a signal return; Pending signals should be in r18.
595 * Not all registers are saved by the normal trap/interrupt entry
596 * points (for instance, call-saved registers (because the normal
597 * C-compiler calling sequence in the kernel makes sure they're
598 * preserved), and call-clobbered registers in the case of
599 * traps), but signal handlers may want to examine or change the
600 * complete register state. Here we save anything not saved by
601 * the normal entry sequence, so that it may be safely restored
602 * (in a possibly modified form) after do_notify_resume returns. */
603 addik r5, r1, 0; /* Arg 1: struct pt_regs *regs */
604 bralid r15, do_notify_resume; /* Handle any signals */
605 addi r6, r0, 0; /* Arg 2: int in_syscall */
608 /* Finally, return to user state. */
609 4: set_bip; /* Ints masked for state restore */
610 swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */
615 addik r1, r1, PT_SIZE /* Clean up stack space. */
617 lwi r1, r1, PT_R1 - PT_SIZE; /* Restore user stack pointer. */
619 /* Return to kernel state. */
620 2: set_bip; /* Ints masked for state restore */
624 addik r1, r1, PT_SIZE /* Clean up stack space. */
628 EXC_return: /* Make global symbol for debugging */
629 rtbd r14, 0; /* Instructions to return from an IRQ */
633 * HW EXCEPTION rutine end
637 * Hardware maskable interrupts.
639 * The stack-pointer (r1) should have already been saved to the memory
640 * location PER_CPU(ENTRY_SP).
643 /* MS: we are in physical address */
644 /* Save registers, switch to proper stack, convert SP to virtual.*/
645 swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP))
646 /* MS: See if already in kernel mode. */
652 /* Kernel-mode state save. */
653 lwi r1, r0, TOPHYS(PER_CPU(ENTRY_SP))
654 tophys(r1,r1); /* MS: I have in r1 physical address where stack is */
656 /* MS: Make room on the stack -> activation record */
657 addik r1, r1, -PT_SIZE;
660 swi r1, r1, PT_MODE; /* 0 - user mode, 1 - kernel mode */
662 /* User-mode state save. */
663 /* MS: get the saved current */
664 lwi r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
666 lwi r1, r1, TS_THREAD_INFO;
667 addik r1, r1, THREAD_SIZE;
670 addik r1, r1, -PT_SIZE;
674 lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
678 lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
680 addik r15, r0, irq_call;
681 irq_call:rtbd r0, do_IRQ;
684 /* MS: we are in virtual mode */
686 lwi r11, r1, PT_MODE;
690 lwi r11, CURRENT_TASK, TS_THREAD_INFO;
691 lwi r19, r11, TI_FLAGS; /* MS: get flags from thread info */
692 andi r11, r19, _TIF_NEED_RESCHED;
694 bralid r15, schedule;
695 nop; /* delay slot */
698 /* Maybe handle a signal */
699 5: andi r11, r19, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME;
700 beqid r11, no_intr_resched
701 /* Handle a signal return; Pending signals should be in r18. */
702 addik r5, r1, 0; /* Arg 1: struct pt_regs *regs */
703 bralid r15, do_notify_resume; /* Handle any signals */
704 addi r6, r0, 0; /* Arg 2: int in_syscall */
707 /* Finally, return to user state. */
709 /* Disable interrupts, we are now committed to the state restore */
711 swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE);
715 addik r1, r1, PT_SIZE /* MS: Clean up stack space. */
716 lwi r1, r1, PT_R1 - PT_SIZE;
718 /* MS: Return to kernel state. */
720 #ifdef CONFIG_PREEMPT
721 lwi r11, CURRENT_TASK, TS_THREAD_INFO;
722 /* MS: get preempt_count from thread info */
723 lwi r5, r11, TI_PREEMPT_COUNT;
726 lwi r5, r11, TI_FLAGS; /* get flags in thread info */
727 andi r5, r5, _TIF_NEED_RESCHED;
728 beqi r5, restore /* if zero jump over */
731 /* interrupts are off that's why I am calling preempt_chedule_irq */
732 bralid r15, preempt_schedule_irq
734 lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */
735 lwi r5, r11, TI_FLAGS; /* get flags in thread info */
736 andi r5, r5, _TIF_NEED_RESCHED;
737 bnei r5, preempt /* if non zero jump to resched */
740 VM_OFF /* MS: turn off MMU */
743 addik r1, r1, PT_SIZE /* MS: Clean up stack space. */
746 IRQ_return: /* MS: Make global symbol for debugging */
751 * Debug trap for KGDB. Enter to _debug_exception by brki r16, 0x18
752 * and call handling function with saved pt_regs
754 C_ENTRY(_debug_exception):
755 /* BIP bit is set on entry, no interrupts can occur */
756 swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP))
762 /* MS: Kernel-mode state save - kgdb */
763 lwi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)); /* Reload kernel stack-ptr*/
765 /* BIP bit is set on entry, no interrupts can occur */
766 addik r1, r1, CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START - PT_SIZE;
768 /* save all regs to pt_reg structure */
769 swi r0, r1, PT_R0; /* R0 must be saved too */
770 swi r14, r1, PT_R14 /* rewrite saved R14 value */
771 swi r16, r1, PT_PC; /* PC and r16 are the same */
772 /* save special purpose registers to pt_regs */
780 /* stack pointer is in physical address at it is decrease
781 * by PT_SIZE but we need to get correct R1 value */
782 addik r11, r1, CONFIG_KERNEL_START - CONFIG_KERNEL_BASE_ADDR + PT_SIZE;
784 /* MS: r31 - current pointer isn't changed */
787 addi r5, r1, 0 /* pass pt_reg address as the first arg */
788 addik r15, r0, dbtrap_call; /* return address */
789 rtbd r0, microblaze_kgdb_break
792 /* MS: Place handler for brki from kernel space if KGDB is OFF.
793 * It is very unlikely that another brki instruction is called. */
796 /* MS: User-mode state save - gdb */
797 1: lwi r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); /* get saved current */
799 lwi r1, r1, TS_THREAD_INFO; /* get the thread info */
800 addik r1, r1, THREAD_SIZE; /* calculate kernel stack pointer */
803 addik r1, r1, -PT_SIZE; /* Make room on the stack. */
805 swi r16, r1, PT_PC; /* Save LP */
806 swi r0, r1, PT_MODE; /* Was in user-mode. */
807 lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
808 swi r11, r1, PT_R1; /* Store user SP. */
809 lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
813 addik r15, r0, dbtrap_call;
814 dbtrap_call: /* Return point for kernel/user entry + 8 because of rtsd r15, 8 */
815 rtbd r0, sw_exception
818 /* MS: The first instruction for the second part of the gdb/kgdb */
819 set_bip; /* Ints masked for state restore */
820 lwi r11, r1, PT_MODE;
822 /* MS: Return to user space - gdb */
824 /* Get current task ptr into r11 */
825 lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */
826 lwi r19, r11, TI_FLAGS; /* get flags in thread info */
827 andi r11, r19, _TIF_NEED_RESCHED;
830 /* Call the scheduler before returning from a syscall/trap. */
831 bralid r15, schedule; /* Call scheduler */
832 nop; /* delay slot */
835 /* Maybe handle a signal */
836 5: andi r11, r19, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME;
837 beqi r11, 4f; /* Signals to handle, handle them */
839 addik r5, r1, 0; /* Arg 1: struct pt_regs *regs */
840 bralid r15, do_notify_resume; /* Handle any signals */
841 addi r6, r0, 0; /* Arg 2: int in_syscall */
844 /* Finally, return to user state. */
845 4: swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */
848 /* MS: Restore all regs */
850 addik r1, r1, PT_SIZE /* Clean up stack space */
851 lwi r1, r1, PT_R1 - PT_SIZE; /* Restore user stack pointer */
852 DBTRAP_return_user: /* MS: Make global symbol for debugging */
853 rtbd r16, 0; /* MS: Instructions to return from a debug trap */
856 /* MS: Return to kernel state - kgdb */
859 /* MS: Restore all regs */
863 addik r1, r1, PT_SIZE; /* MS: Clean up stack space */
865 DBTRAP_return_kernel: /* MS: Make global symbol for debugging */
866 rtbd r16, 0; /* MS: Instructions to return from a debug trap */
871 /* prepare return value */
872 addk r3, r0, CURRENT_TASK
874 /* save registers in cpu_context */
875 /* use r11 and r12, volatile registers, as temp register */
876 /* give start of cpu_context for previous process */
877 addik r11, r5, TI_CPU_CONTEXT
880 /* skip volatile registers.
881 * they are saved on stack when we jumped to _switch_to() */
882 /* dedicated registers */
889 /* save non-volatile registers */
902 /* special purpose registers */
912 /* update r31, the current-give me pointer to task which will be next */
913 lwi CURRENT_TASK, r6, TI_TASK
914 /* stored it to current_save too */
915 swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE)
917 /* get new process' cpu context and restore */
918 /* give me start where start context of next task */
919 addik r11, r6, TI_CPU_CONTEXT
921 /* non-volatile registers */
934 /* dedicated registers */
941 /* skip volatile registers */
945 /* special purpose registers */
955 brai 0; /* Jump to reset vector */
957 /* These are compiled and loaded into high memory, then
958 * copied into place in mach_early_setup */
959 .section .init.ivt, "ax"
960 #if CONFIG_MANUAL_RESET_VECTOR
962 brai CONFIG_MANUAL_RESET_VECTOR
965 brai TOPHYS(_user_exception); /* syscall handler */
967 brai TOPHYS(_interrupt); /* Interrupt handler */
969 brai TOPHYS(_debug_exception); /* debug trap handler */
971 brai TOPHYS(_hw_exception_handler); /* HW exception handler */
974 #include "syscall_table.S"
976 syscall_table_size=(.-sys_call_table)
983 .ascii "IRQ (PREEMPTED)\0"
984 type_SYSCALL_PREEMPT:
985 .ascii " SYSCALL (PREEMPTED)\0"
988 * Trap decoding for stack unwinder
989 * Tuples are (start addr, end addr, string)
990 * If return address lies on [start addr, end addr],
991 * unwinder displays 'string'
995 .global microblaze_trap_handlers
996 microblaze_trap_handlers:
997 /* Exact matches come first */
998 .word ret_from_trap; .word ret_from_trap ; .word type_SYSCALL
999 .word ret_from_irq ; .word ret_from_irq ; .word type_IRQ
1000 /* Fuzzy matches go here */
1001 .word ret_from_irq ; .word no_intr_resched ; .word type_IRQ_PREEMPT
1002 .word ret_from_trap; .word TRAP_return ; .word type_SYSCALL_PREEMPT
1004 .word 0 ; .word 0 ; .word 0