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 */
301 /* Kernel-mode state save - kernel execve */
302 lwi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)); /* Reload kernel stack-ptr*/
305 addik r1, r1, -PT_SIZE; /* Make room on the stack. */
308 swi r1, r1, PT_MODE; /* pt_regs -> kernel mode */
310 nop; /* Fill delay slot */
312 /* User-mode state save. */
314 lwi r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); /* get saved current */
316 lwi r1, r1, TS_THREAD_INFO; /* get stack from task_struct */
317 /* calculate kernel stack pointer from task struct 8k */
318 addik r1, r1, THREAD_SIZE;
321 addik r1, r1, -PT_SIZE; /* Make room on the stack. */
326 swi r0, r1, PT_MODE; /* Was in user-mode. */
327 lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
328 swi r11, r1, PT_R1; /* Store user SP. */
330 2: lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
331 /* Save away the syscall number. */
335 /* where the trap should return need -8 to adjust for rtsd r15, 8*/
336 /* Jump to the appropriate function for the system call number in r12
337 * (r12 is not preserved), or return an error if r12 is not valid. The LP
338 * register should point to the location where
339 * the called function should return. [note that MAKE_SYS_CALL uses label 1] */
341 /* Step into virtual mode */
345 lwi r11, CURRENT_TASK, TS_THREAD_INFO /* get thread info */
346 lwi r11, r11, TI_FLAGS /* get flags in thread info */
347 andi r11, r11, _TIF_WORK_SYSCALL_MASK
350 addik r3, r0, -ENOSYS
352 brlid r15, do_syscall_trace_enter
355 # do_syscall_trace_enter returns the new syscall nr.
364 /* Jump to the appropriate function for the system call number in r12
365 * (r12 is not preserved), or return an error if r12 is not valid.
366 * The LP register should point to the location where the called function
367 * should return. [note that MAKE_SYS_CALL uses label 1] */
368 /* See if the system call number is valid */
369 addi r11, r12, -__NR_syscalls;
371 /* Figure out which function to use for this system call. */
372 /* Note Microblaze barrel shift is optional, so don't rely on it */
373 add r12, r12, r12; /* convert num -> ptr */
377 /* Trac syscalls and stored them to syscall_debug_table */
378 /* The first syscall location stores total syscall number */
379 lwi r3, r0, syscall_debug_table
381 swi r3, r0, syscall_debug_table
382 lwi r3, r12, syscall_debug_table
384 swi r3, r12, syscall_debug_table
387 # Find and jump into the syscall handler.
388 lwi r12, r12, sys_call_table
389 /* where the trap should return need -8 to adjust for rtsd r15, 8 */
390 addi r15, r0, ret_from_trap-8
393 /* The syscall number is invalid, return an error. */
395 rtsd r15, 8; /* looks like a normal subroutine return */
396 addi r3, r0, -ENOSYS;
398 /* Entry point used to return from a syscall/trap */
399 /* We re-enable BIP bit before state restore */
400 C_ENTRY(ret_from_trap):
404 lwi r11, r1, PT_MODE;
405 /* See if returning to kernel mode, if so, skip resched &c. */
407 /* We're returning to user mode, so check for various conditions that
408 * trigger rescheduling. */
409 /* FIXME: Restructure all these flag checks. */
410 lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */
411 lwi r11, r11, TI_FLAGS; /* get flags in thread info */
412 andi r11, r11, _TIF_WORK_SYSCALL_MASK
415 brlid r15, do_syscall_trace_leave
418 /* We're returning to user mode, so check for various conditions that
419 * trigger rescheduling. */
420 /* get thread info from current task */
421 lwi r11, CURRENT_TASK, TS_THREAD_INFO;
422 lwi r11, r11, TI_FLAGS; /* get flags in thread info */
423 andi r11, r11, _TIF_NEED_RESCHED;
426 bralid r15, schedule; /* Call scheduler */
427 nop; /* delay slot */
429 /* Maybe handle a signal */
430 5: /* get thread info from current task*/
431 lwi r11, CURRENT_TASK, TS_THREAD_INFO;
432 lwi r11, r11, TI_FLAGS; /* get flags in thread info */
433 andi r11, r11, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME;
434 beqi r11, 1f; /* Signals to handle, handle them */
436 addik r5, r1, 0; /* Arg 1: struct pt_regs *regs */
437 bralid r15, do_notify_resume; /* Handle any signals */
438 addi r6, r0, 1; /* Arg 2: int in_syscall */
440 /* Finally, return to user state. */
441 1: set_bip; /* Ints masked for state restore */
442 swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */
446 addik r1, r1, PT_SIZE /* Clean up stack space. */
447 lwi r1, r1, PT_R1 - PT_SIZE;/* Restore user stack pointer. */
450 /* Return to kernel state. */
451 2: set_bip; /* Ints masked for state restore */
455 addik r1, r1, PT_SIZE /* Clean up stack space. */
458 TRAP_return: /* Make global symbol for debugging */
459 rtbd r14, 0; /* Instructions to return from an IRQ */
463 /* These syscalls need access to the struct pt_regs on the stack, so we
464 implement them in assembly (they're basically all wrappers anyway). */
466 C_ENTRY(sys_fork_wrapper):
467 addi r5, r0, SIGCHLD /* Arg 0: flags */
468 lwi r6, r1, PT_R1 /* Arg 1: child SP (use parent's) */
469 addik r7, r1, 0 /* Arg 2: parent context */
470 add r8, r0, r0 /* Arg 3: (unused) */
471 add r9, r0, r0; /* Arg 4: (unused) */
472 brid do_fork /* Do real work (tail-call) */
473 add r10, r0, r0; /* Arg 5: (unused) */
475 /* This the initial entry point for a new child thread, with an appropriate
476 stack in place that makes it look the the child is in the middle of an
477 syscall. This function is actually `returned to' from switch_thread
478 (copy_thread makes ret_from_fork the return address in each new thread's
480 C_ENTRY(ret_from_fork):
481 bralid r15, schedule_tail; /* ...which is schedule_tail's arg */
482 add r3, r5, r0; /* switch_thread returns the prev task */
483 /* ( in the delay slot ) */
484 brid ret_from_trap; /* Do normal trap return */
485 add r3, r0, r0; /* Child's fork call should return 0. */
488 brid microblaze_vfork /* Do real work (tail-call) */
492 bnei r6, 1f; /* See if child SP arg (arg 1) is 0. */
493 lwi r6, r1, PT_R1; /* If so, use paret's stack ptr */
494 1: addik r7, r1, 0; /* Arg 2: parent context */
495 lwi r9, r1, PT_R8; /* parent tid. */
496 lwi r10, r1, PT_R9; /* child tid. */
497 /* do_fork will pick up TLS from regs->r10. */
498 brid do_fork /* Do real work (tail-call) */
499 add r8, r0, r0; /* Arg 3: (unused) */
502 brid microblaze_execve; /* Do real work (tail-call).*/
503 addik r8, r1, 0; /* add user context as 4th arg */
505 C_ENTRY(sys_rt_sigreturn_wrapper):
506 brid sys_rt_sigreturn /* Do real work */
507 addik r5, r1, 0; /* add user context as 1st arg */
510 * HW EXCEPTION rutine start
512 C_ENTRY(full_exception_trap):
513 /* adjust exception address for privileged instruction
514 * for finding where is it */
516 SAVE_STATE /* Save registers */
517 /* PC, before IRQ/trap - this is one instruction above */
520 /* FIXME this can be store directly in PT_ESR reg.
521 * I tested it but there is a fault */
522 /* where the trap should return need -8 to adjust for rtsd r15, 8 */
523 addik r15, r0, ret_from_exc - 8
525 mfs r7, rfsr; /* save FSR */
526 mts rfsr, r0; /* Clear sticky fsr */
527 rted r0, full_exception
528 addik r5, r1, 0 /* parameter struct pt_regs * regs */
531 * Unaligned data trap.
533 * Unaligned data trap last on 4k page is handled here.
535 * Trap entered via exception, so EE bit is set, and interrupts
536 * are masked. This is nice, means we don't have to CLI before state save
538 * The assembler routine is in "arch/microblaze/kernel/hw_exception_handler.S"
540 C_ENTRY(unaligned_data_trap):
541 /* MS: I have to save r11 value and then restore it because
542 * set_bit, clear_eip, set_ee use r11 as temp register if MSR
543 * instructions are not used. We don't need to do if MSR instructions
544 * are used and they use r0 instead of r11.
545 * I am using ENTRY_SP which should be primary used only for stack
547 swi r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
548 set_bip; /* equalize initial state for all possible entries */
551 lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
552 SAVE_STATE /* Save registers.*/
553 /* PC, before IRQ/trap - this is one instruction above */
556 /* where the trap should return need -8 to adjust for rtsd r15, 8 */
557 addik r15, r0, ret_from_exc-8
558 mfs r3, resr /* ESR */
559 mfs r4, rear /* EAR */
560 rtbd r0, _unaligned_data_exception
561 addik r7, r1, 0 /* parameter struct pt_regs * regs */
566 * If the real exception handler (from hw_exception_handler.S) didn't find
567 * the mapping for the process, then we're thrown here to handle such situation.
569 * Trap entered via exceptions, so EE bit is set, and interrupts
570 * are masked. This is nice, means we don't have to CLI before state save
572 * Build a standard exception frame for TLB Access errors. All TLB exceptions
573 * will bail out to this point if they can't resolve the lightweight TLB fault.
575 * The C function called is in "arch/microblaze/mm/fault.c", declared as:
576 * void do_page_fault(struct pt_regs *regs,
577 * unsigned long address,
578 * unsigned long error_code)
580 /* data and intruction trap - which is choose is resolved int fault.c */
581 C_ENTRY(page_fault_data_trap):
582 SAVE_STATE /* Save registers.*/
583 /* PC, before IRQ/trap - this is one instruction above */
586 /* where the trap should return need -8 to adjust for rtsd r15, 8 */
587 addik r15, r0, ret_from_exc-8
588 mfs r6, rear /* parameter unsigned long address */
589 mfs r7, resr /* parameter unsigned long error_code */
590 rted r0, do_page_fault
591 addik r5, r1, 0 /* parameter struct pt_regs * regs */
593 C_ENTRY(page_fault_instr_trap):
594 SAVE_STATE /* Save registers.*/
595 /* PC, before IRQ/trap - this is one instruction above */
598 /* where the trap should return need -8 to adjust for rtsd r15, 8 */
599 addik r15, r0, ret_from_exc-8
600 mfs r6, rear /* parameter unsigned long address */
601 ori r7, r0, 0 /* parameter unsigned long error_code */
602 rted r0, do_page_fault
603 addik r5, r1, 0 /* parameter struct pt_regs * regs */
605 /* Entry point used to return from an exception. */
606 C_ENTRY(ret_from_exc):
607 lwi r11, r1, PT_MODE;
608 bnei r11, 2f; /* See if returning to kernel mode, */
609 /* ... if so, skip resched &c. */
611 /* We're returning to user mode, so check for various conditions that
612 trigger rescheduling. */
613 lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */
614 lwi r11, r11, TI_FLAGS; /* get flags in thread info */
615 andi r11, r11, _TIF_NEED_RESCHED;
618 /* Call the scheduler before returning from a syscall/trap. */
619 bralid r15, schedule; /* Call scheduler */
620 nop; /* delay slot */
622 /* Maybe handle a signal */
623 5: lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */
624 lwi r11, r11, TI_FLAGS; /* get flags in thread info */
625 andi r11, r11, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME;
626 beqi r11, 1f; /* Signals to handle, handle them */
629 * Handle a signal return; Pending signals should be in r18.
631 * Not all registers are saved by the normal trap/interrupt entry
632 * points (for instance, call-saved registers (because the normal
633 * C-compiler calling sequence in the kernel makes sure they're
634 * preserved), and call-clobbered registers in the case of
635 * traps), but signal handlers may want to examine or change the
636 * complete register state. Here we save anything not saved by
637 * the normal entry sequence, so that it may be safely restored
638 * (in a possibly modified form) after do_notify_resume returns. */
639 addik r5, r1, 0; /* Arg 1: struct pt_regs *regs */
640 bralid r15, do_notify_resume; /* Handle any signals */
641 addi r6, r0, 0; /* Arg 2: int in_syscall */
643 /* Finally, return to user state. */
644 1: set_bip; /* Ints masked for state restore */
645 swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */
650 addik r1, r1, PT_SIZE /* Clean up stack space. */
652 lwi r1, r1, PT_R1 - PT_SIZE; /* Restore user stack pointer. */
654 /* Return to kernel state. */
655 2: set_bip; /* Ints masked for state restore */
659 addik r1, r1, PT_SIZE /* Clean up stack space. */
663 EXC_return: /* Make global symbol for debugging */
664 rtbd r14, 0; /* Instructions to return from an IRQ */
668 * HW EXCEPTION rutine end
672 * Hardware maskable interrupts.
674 * The stack-pointer (r1) should have already been saved to the memory
675 * location PER_CPU(ENTRY_SP).
678 /* MS: we are in physical address */
679 /* Save registers, switch to proper stack, convert SP to virtual.*/
680 swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP))
681 /* MS: See if already in kernel mode. */
687 /* Kernel-mode state save. */
688 lwi r1, r0, TOPHYS(PER_CPU(ENTRY_SP))
689 tophys(r1,r1); /* MS: I have in r1 physical address where stack is */
691 /* MS: Make room on the stack -> activation record */
692 addik r1, r1, -PT_SIZE;
695 swi r1, r1, PT_MODE; /* 0 - user mode, 1 - kernel mode */
697 /* User-mode state save. */
698 /* MS: get the saved current */
699 lwi r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
701 lwi r1, r1, TS_THREAD_INFO;
702 addik r1, r1, THREAD_SIZE;
705 addik r1, r1, -PT_SIZE;
709 lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
713 lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
715 addik r15, r0, irq_call;
716 irq_call:rtbd r0, do_IRQ;
719 /* MS: we are in virtual mode */
721 lwi r11, r1, PT_MODE;
724 lwi r11, CURRENT_TASK, TS_THREAD_INFO;
725 lwi r11, r11, TI_FLAGS; /* MS: get flags from thread info */
726 andi r11, r11, _TIF_NEED_RESCHED;
728 bralid r15, schedule;
729 nop; /* delay slot */
731 /* Maybe handle a signal */
732 5: lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* MS: get thread info */
733 lwi r11, r11, TI_FLAGS; /* get flags in thread info */
734 andi r11, r11, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME;
735 beqid r11, no_intr_resched
736 /* Handle a signal return; Pending signals should be in r18. */
737 addik r5, r1, 0; /* Arg 1: struct pt_regs *regs */
738 bralid r15, do_notify_resume; /* Handle any signals */
739 addi r6, r0, 0; /* Arg 2: int in_syscall */
741 /* Finally, return to user state. */
743 /* Disable interrupts, we are now committed to the state restore */
745 swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE);
749 addik r1, r1, PT_SIZE /* MS: Clean up stack space. */
750 lwi r1, r1, PT_R1 - PT_SIZE;
752 /* MS: Return to kernel state. */
754 #ifdef CONFIG_PREEMPT
755 lwi r11, CURRENT_TASK, TS_THREAD_INFO;
756 /* MS: get preempt_count from thread info */
757 lwi r5, r11, TI_PREEMPT_COUNT;
760 lwi r5, r11, TI_FLAGS; /* get flags in thread info */
761 andi r5, r5, _TIF_NEED_RESCHED;
762 beqi r5, restore /* if zero jump over */
765 /* interrupts are off that's why I am calling preempt_chedule_irq */
766 bralid r15, preempt_schedule_irq
768 lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */
769 lwi r5, r11, TI_FLAGS; /* get flags in thread info */
770 andi r5, r5, _TIF_NEED_RESCHED;
771 bnei r5, preempt /* if non zero jump to resched */
774 VM_OFF /* MS: turn off MMU */
777 addik r1, r1, PT_SIZE /* MS: Clean up stack space. */
780 IRQ_return: /* MS: Make global symbol for debugging */
785 * Debug trap for KGDB. Enter to _debug_exception by brki r16, 0x18
786 * and call handling function with saved pt_regs
788 C_ENTRY(_debug_exception):
789 /* BIP bit is set on entry, no interrupts can occur */
790 swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP))
796 /* MS: Kernel-mode state save - kgdb */
797 lwi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)); /* Reload kernel stack-ptr*/
799 /* BIP bit is set on entry, no interrupts can occur */
800 addik r1, r1, CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START - PT_SIZE;
802 /* save all regs to pt_reg structure */
803 swi r0, r1, PT_R0; /* R0 must be saved too */
804 swi r14, r1, PT_R14 /* rewrite saved R14 value */
805 swi r16, r1, PT_PC; /* PC and r16 are the same */
806 /* save special purpose registers to pt_regs */
814 /* stack pointer is in physical address at it is decrease
815 * by PT_SIZE but we need to get correct R1 value */
816 addik r11, r1, CONFIG_KERNEL_START - CONFIG_KERNEL_BASE_ADDR + PT_SIZE;
818 /* MS: r31 - current pointer isn't changed */
821 addi r5, r1, 0 /* pass pt_reg address as the first arg */
822 addik r15, r0, dbtrap_call; /* return address */
823 rtbd r0, microblaze_kgdb_break
826 /* MS: Place handler for brki from kernel space if KGDB is OFF.
827 * It is very unlikely that another brki instruction is called. */
830 /* MS: User-mode state save - gdb */
831 1: lwi r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); /* get saved current */
833 lwi r1, r1, TS_THREAD_INFO; /* get the thread info */
834 addik r1, r1, THREAD_SIZE; /* calculate kernel stack pointer */
837 addik r1, r1, -PT_SIZE; /* Make room on the stack. */
839 swi r16, r1, PT_PC; /* Save LP */
840 swi r0, r1, PT_MODE; /* Was in user-mode. */
841 lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
842 swi r11, r1, PT_R1; /* Store user SP. */
843 lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
847 addik r15, r0, dbtrap_call;
848 dbtrap_call: /* Return point for kernel/user entry + 8 because of rtsd r15, 8 */
849 rtbd r0, sw_exception
852 /* MS: The first instruction for the second part of the gdb/kgdb */
853 set_bip; /* Ints masked for state restore */
854 lwi r11, r1, PT_MODE;
856 /* MS: Return to user space - gdb */
857 /* Get current task ptr into r11 */
858 lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */
859 lwi r11, r11, TI_FLAGS; /* get flags in thread info */
860 andi r11, r11, _TIF_NEED_RESCHED;
863 /* Call the scheduler before returning from a syscall/trap. */
864 bralid r15, schedule; /* Call scheduler */
865 nop; /* delay slot */
867 /* Maybe handle a signal */
868 5: lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */
869 lwi r11, r11, TI_FLAGS; /* get flags in thread info */
870 andi r11, r11, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME;
871 beqi r11, 1f; /* Signals to handle, handle them */
873 addik r5, r1, 0; /* Arg 1: struct pt_regs *regs */
874 bralid r15, do_notify_resume; /* Handle any signals */
875 addi r6, r0, 0; /* Arg 2: int in_syscall */
877 /* Finally, return to user state. */
878 1: swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */
881 /* MS: Restore all regs */
883 addik r1, r1, PT_SIZE /* Clean up stack space */
884 lwi r1, r1, PT_R1 - PT_SIZE; /* Restore user stack pointer */
885 DBTRAP_return_user: /* MS: Make global symbol for debugging */
886 rtbd r16, 0; /* MS: Instructions to return from a debug trap */
889 /* MS: Return to kernel state - kgdb */
892 /* MS: Restore all regs */
896 addik r1, r1, PT_SIZE; /* MS: Clean up stack space */
898 DBTRAP_return_kernel: /* MS: Make global symbol for debugging */
899 rtbd r16, 0; /* MS: Instructions to return from a debug trap */
904 /* prepare return value */
905 addk r3, r0, CURRENT_TASK
907 /* save registers in cpu_context */
908 /* use r11 and r12, volatile registers, as temp register */
909 /* give start of cpu_context for previous process */
910 addik r11, r5, TI_CPU_CONTEXT
913 /* skip volatile registers.
914 * they are saved on stack when we jumped to _switch_to() */
915 /* dedicated registers */
922 /* save non-volatile registers */
935 /* special purpose registers */
945 /* update r31, the current-give me pointer to task which will be next */
946 lwi CURRENT_TASK, r6, TI_TASK
947 /* stored it to current_save too */
948 swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE)
950 /* get new process' cpu context and restore */
951 /* give me start where start context of next task */
952 addik r11, r6, TI_CPU_CONTEXT
954 /* non-volatile registers */
967 /* dedicated registers */
974 /* skip volatile registers */
978 /* special purpose registers */
988 brai 0; /* Jump to reset vector */
990 /* These are compiled and loaded into high memory, then
991 * copied into place in mach_early_setup */
992 .section .init.ivt, "ax"
993 #if CONFIG_MANUAL_RESET_VECTOR
995 brai CONFIG_MANUAL_RESET_VECTOR
998 brai TOPHYS(_user_exception); /* syscall handler */
1000 brai TOPHYS(_interrupt); /* Interrupt handler */
1002 brai TOPHYS(_debug_exception); /* debug trap handler */
1004 brai TOPHYS(_hw_exception_handler); /* HW exception handler */
1006 .section .rodata,"a"
1007 #include "syscall_table.S"
1009 syscall_table_size=(.-sys_call_table)
1016 .ascii "IRQ (PREEMPTED)\0"
1017 type_SYSCALL_PREEMPT:
1018 .ascii " SYSCALL (PREEMPTED)\0"
1021 * Trap decoding for stack unwinder
1022 * Tuples are (start addr, end addr, string)
1023 * If return address lies on [start addr, end addr],
1024 * unwinder displays 'string'
1028 .global microblaze_trap_handlers
1029 microblaze_trap_handlers:
1030 /* Exact matches come first */
1031 .word ret_from_trap; .word ret_from_trap ; .word type_SYSCALL
1032 .word ret_from_irq ; .word ret_from_irq ; .word type_IRQ
1033 /* Fuzzy matches go here */
1034 .word ret_from_irq ; .word no_intr_resched ; .word type_IRQ_PREEMPT
1035 .word ret_from_trap; .word TRAP_return ; .word type_SYSCALL_PREEMPT
1037 .word 0 ; .word 0 ; .word 0