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_GP \
212 lwi r2, r1, PT_R2; /* restore SDA */ \
220 lwi r10, r1, PT_R10; \
221 lwi r11, r1, PT_R11; /* restore clobbered regs after rval */\
222 lwi r12, r1, PT_R12; \
223 lwi r13, r1, PT_R13; /* restore SDA2 */ \
224 lwi r14, r1, PT_PC; /* RESTORE_LINK PC, before IRQ/trap */\
225 lwi r15, r1, PT_R15; /* restore LP */ \
226 lwi r16, r1, PT_R16; \
227 lwi r17, r1, PT_R17; \
228 lwi r18, r1, PT_R18; /* restore asm scratch reg */ \
229 lwi r19, r1, PT_R19; \
230 lwi r20, r1, PT_R20; \
231 lwi r21, r1, PT_R21; \
232 lwi r22, r1, PT_R22; \
233 lwi r23, r1, PT_R23; \
234 lwi r24, r1, PT_R24; \
235 lwi r25, r1, PT_R25; \
236 lwi r26, r1, PT_R26; \
237 lwi r27, r1, PT_R27; \
238 lwi r28, r1, PT_R28; \
239 lwi r29, r1, PT_R29; \
240 lwi r30, r1, PT_R30; \
241 lwi r31, r1, PT_R31; /* Restore cur task reg */
243 #define RESTORE_REGS \
244 lwi r11, r1, PT_MSR; \
248 #define RESTORE_REGS_RTBD \
249 lwi r11, r1, PT_MSR; \
250 andni r11, r11, MSR_EIP; /* clear EIP */ \
251 ori r11, r11, MSR_EE | MSR_BIP; /* set EE and BIP */ \
256 swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)); /* save stack */ \
257 /* See if already in kernel mode.*/ \
259 andi r1, r1, MSR_UMS; \
261 /* Kernel-mode state save. */ \
262 /* Reload kernel stack-ptr. */ \
263 lwi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)); \
264 /* FIXME: I can add these two lines to one */ \
265 /* tophys(r1,r1); */ \
266 /* addik r1, r1, -PT_SIZE; */ \
267 addik r1, r1, CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START - PT_SIZE; \
270 swi r1, r1, PT_MODE; \
271 1: /* User-mode state save. */ \
272 lwi r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); /* get saved current */\
274 lwi r1, r1, TS_THREAD_INFO; /* get the thread info */ \
275 /* MS these three instructions can be added to one */ \
276 /* addik r1, r1, THREAD_SIZE; */ \
277 /* tophys(r1,r1); */ \
278 /* addik r1, r1, -PT_SIZE; */ \
279 addik r1, r1, THREAD_SIZE + CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START - PT_SIZE; \
281 lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); \
282 swi r11, r1, PT_R1; /* Store user SP. */ \
283 swi r0, r1, PT_MODE; /* Was in user-mode. */ \
284 /* MS: I am clearing UMS even in case when I come from kernel space */ \
286 2: lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
293 * System calls are handled here.
296 * Syscall number in r12, args in r5-r10
299 * Trap entered via brki instruction, so BIP bit is set, and interrupts
300 * are masked. This is nice, means we don't have to CLI before state save
302 C_ENTRY(_user_exception):
303 swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)) /* save stack */
304 addi r14, r14, 4 /* return address is 4 byte after call */
306 lwi r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); /* get saved current */
308 lwi r1, r1, TS_THREAD_INFO; /* get stack from task_struct */
309 /* calculate kernel stack pointer from task struct 8k */
310 addik r1, r1, THREAD_SIZE;
313 addik r1, r1, -PT_SIZE; /* Make room on the stack. */
318 swi r0, r1, PT_MODE; /* Was in user-mode. */
319 lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
320 swi r11, r1, PT_R1; /* Store user SP. */
322 2: lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
323 /* Save away the syscall number. */
327 /* where the trap should return need -8 to adjust for rtsd r15, 8*/
328 /* Jump to the appropriate function for the system call number in r12
329 * (r12 is not preserved), or return an error if r12 is not valid. The LP
330 * register should point to the location where
331 * the called function should return. [note that MAKE_SYS_CALL uses label 1] */
333 /* Step into virtual mode */
337 lwi r11, CURRENT_TASK, TS_THREAD_INFO /* get thread info */
338 lwi r11, r11, TI_FLAGS /* get flags in thread info */
339 andi r11, r11, _TIF_WORK_SYSCALL_MASK
342 addik r3, r0, -ENOSYS
344 brlid r15, do_syscall_trace_enter
347 # do_syscall_trace_enter returns the new syscall nr.
356 /* Jump to the appropriate function for the system call number in r12
357 * (r12 is not preserved), or return an error if r12 is not valid.
358 * The LP register should point to the location where the called function
359 * should return. [note that MAKE_SYS_CALL uses label 1] */
360 /* See if the system call number is valid */
362 addi r11, r12, -__NR_syscalls;
364 /* Figure out which function to use for this system call. */
365 /* Note Microblaze barrel shift is optional, so don't rely on it */
366 add r12, r12, r12; /* convert num -> ptr */
368 addi r30, r0, 1 /* restarts allowed */
371 /* Trac syscalls and stored them to syscall_debug_table */
372 /* The first syscall location stores total syscall number */
373 lwi r3, r0, syscall_debug_table
375 swi r3, r0, syscall_debug_table
376 lwi r3, r12, syscall_debug_table
378 swi r3, r12, syscall_debug_table
381 # Find and jump into the syscall handler.
382 lwi r12, r12, sys_call_table
383 /* where the trap should return need -8 to adjust for rtsd r15, 8 */
384 addi r15, r0, ret_from_trap-8
387 /* The syscall number is invalid, return an error. */
390 addi r3, r0, -ENOSYS;
392 /* Entry point used to return from a syscall/trap */
393 /* We re-enable BIP bit before state restore */
394 C_ENTRY(ret_from_trap):
398 lwi r11, r1, PT_MODE;
399 /* See if returning to kernel mode, if so, skip resched &c. */
401 /* We're returning to user mode, so check for various conditions that
402 * trigger rescheduling. */
403 /* FIXME: Restructure all these flag checks. */
404 lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */
405 lwi r11, r11, TI_FLAGS; /* get flags in thread info */
406 andi r11, r11, _TIF_WORK_SYSCALL_MASK
409 brlid r15, do_syscall_trace_leave
412 /* We're returning to user mode, so check for various conditions that
413 * trigger rescheduling. */
414 /* get thread info from current task */
415 lwi r11, CURRENT_TASK, TS_THREAD_INFO;
416 lwi r19, r11, TI_FLAGS; /* get flags in thread info */
417 andi r11, r19, _TIF_NEED_RESCHED;
420 bralid r15, schedule; /* Call scheduler */
421 nop; /* delay slot */
424 /* Maybe handle a signal */
426 andi r11, r19, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME;
427 beqi r11, 4f; /* Signals to handle, handle them */
429 addik r5, r1, 0; /* Arg 1: struct pt_regs *regs */
430 bralid r15, do_notify_resume; /* Handle any signals */
431 add r6, r30, r0; /* Arg 2: int in_syscall */
432 add r30, r0, r0 /* no more restarts */
435 /* Finally, return to user state. */
436 4: set_bip; /* Ints masked for state restore */
437 swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */
441 addik r1, r1, PT_SIZE /* Clean up stack space. */
442 lwi r1, r1, PT_R1 - PT_SIZE;/* Restore user stack pointer. */
445 /* Return to kernel state. */
446 2: set_bip; /* Ints masked for state restore */
450 addik r1, r1, PT_SIZE /* Clean up stack space. */
453 TRAP_return: /* Make global symbol for debugging */
454 rtbd r14, 0; /* Instructions to return from an IRQ */
458 /* This the initial entry point for a new child thread, with an appropriate
459 stack in place that makes it look the the child is in the middle of an
460 syscall. This function is actually `returned to' from switch_thread
461 (copy_thread makes ret_from_fork the return address in each new thread's
463 C_ENTRY(ret_from_fork):
464 bralid r15, schedule_tail; /* ...which is schedule_tail's arg */
465 add r5, r3, r0; /* switch_thread returns the prev task */
466 /* ( in the delay slot ) */
467 brid ret_from_trap; /* Do normal trap return */
468 add r3, r0, r0; /* Child's fork call should return 0. */
470 C_ENTRY(ret_from_kernel_thread):
471 bralid r15, schedule_tail; /* ...which is schedule_tail's arg */
472 add r5, r3, r0; /* switch_thread returns the prev task */
473 /* ( in the delay slot ) */
474 brald r15, r20 /* fn was left in r20 */
475 addk r5, r0, r19 /* ... and argument - in r19 */
479 C_ENTRY(sys_rt_sigreturn_wrapper):
480 addik r30, r0, 0 /* no restarts */
481 brid sys_rt_sigreturn /* Do real work */
482 addik r5, r1, 0; /* add user context as 1st arg */
485 * HW EXCEPTION rutine start
487 C_ENTRY(full_exception_trap):
488 /* adjust exception address for privileged instruction
489 * for finding where is it */
491 SAVE_STATE /* Save registers */
492 /* PC, before IRQ/trap - this is one instruction above */
495 /* FIXME this can be store directly in PT_ESR reg.
496 * I tested it but there is a fault */
497 /* where the trap should return need -8 to adjust for rtsd r15, 8 */
498 addik r15, r0, ret_from_exc - 8
500 mfs r7, rfsr; /* save FSR */
501 mts rfsr, r0; /* Clear sticky fsr */
502 rted r0, full_exception
503 addik r5, r1, 0 /* parameter struct pt_regs * regs */
506 * Unaligned data trap.
508 * Unaligned data trap last on 4k page is handled here.
510 * Trap entered via exception, so EE bit is set, and interrupts
511 * are masked. This is nice, means we don't have to CLI before state save
513 * The assembler routine is in "arch/microblaze/kernel/hw_exception_handler.S"
515 C_ENTRY(unaligned_data_trap):
516 /* MS: I have to save r11 value and then restore it because
517 * set_bit, clear_eip, set_ee use r11 as temp register if MSR
518 * instructions are not used. We don't need to do if MSR instructions
519 * are used and they use r0 instead of r11.
520 * I am using ENTRY_SP which should be primary used only for stack
522 swi r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
523 set_bip; /* equalize initial state for all possible entries */
526 lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
527 SAVE_STATE /* Save registers.*/
528 /* PC, before IRQ/trap - this is one instruction above */
531 /* where the trap should return need -8 to adjust for rtsd r15, 8 */
532 addik r15, r0, ret_from_exc-8
533 mfs r3, resr /* ESR */
534 mfs r4, rear /* EAR */
535 rtbd r0, _unaligned_data_exception
536 addik r7, r1, 0 /* parameter struct pt_regs * regs */
541 * If the real exception handler (from hw_exception_handler.S) didn't find
542 * the mapping for the process, then we're thrown here to handle such situation.
544 * Trap entered via exceptions, so EE bit is set, and interrupts
545 * are masked. This is nice, means we don't have to CLI before state save
547 * Build a standard exception frame for TLB Access errors. All TLB exceptions
548 * will bail out to this point if they can't resolve the lightweight TLB fault.
550 * The C function called is in "arch/microblaze/mm/fault.c", declared as:
551 * void do_page_fault(struct pt_regs *regs,
552 * unsigned long address,
553 * unsigned long error_code)
555 /* data and intruction trap - which is choose is resolved int fault.c */
556 C_ENTRY(page_fault_data_trap):
557 SAVE_STATE /* Save registers.*/
558 /* PC, before IRQ/trap - this is one instruction above */
561 /* where the trap should return need -8 to adjust for rtsd r15, 8 */
562 addik r15, r0, ret_from_exc-8
563 mfs r6, rear /* parameter unsigned long address */
564 mfs r7, resr /* parameter unsigned long error_code */
565 rted r0, do_page_fault
566 addik r5, r1, 0 /* parameter struct pt_regs * regs */
568 C_ENTRY(page_fault_instr_trap):
569 SAVE_STATE /* Save registers.*/
570 /* PC, before IRQ/trap - this is one instruction above */
573 /* where the trap should return need -8 to adjust for rtsd r15, 8 */
574 addik r15, r0, ret_from_exc-8
575 mfs r6, rear /* parameter unsigned long address */
576 ori r7, r0, 0 /* parameter unsigned long error_code */
577 rted r0, do_page_fault
578 addik r5, r1, 0 /* parameter struct pt_regs * regs */
580 /* Entry point used to return from an exception. */
581 C_ENTRY(ret_from_exc):
582 lwi r11, r1, PT_MODE;
583 bnei r11, 2f; /* See if returning to kernel mode, */
584 /* ... if so, skip resched &c. */
586 /* We're returning to user mode, so check for various conditions that
587 trigger rescheduling. */
589 lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */
590 lwi r19, r11, TI_FLAGS; /* get flags in thread info */
591 andi r11, r19, _TIF_NEED_RESCHED;
594 /* Call the scheduler before returning from a syscall/trap. */
595 bralid r15, schedule; /* Call scheduler */
596 nop; /* delay slot */
599 /* Maybe handle a signal */
600 5: andi r11, r19, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME;
601 beqi r11, 4f; /* Signals to handle, handle them */
604 * Handle a signal return; Pending signals should be in r18.
606 * Not all registers are saved by the normal trap/interrupt entry
607 * points (for instance, call-saved registers (because the normal
608 * C-compiler calling sequence in the kernel makes sure they're
609 * preserved), and call-clobbered registers in the case of
610 * traps), but signal handlers may want to examine or change the
611 * complete register state. Here we save anything not saved by
612 * the normal entry sequence, so that it may be safely restored
613 * (in a possibly modified form) after do_notify_resume returns. */
614 addik r5, r1, 0; /* Arg 1: struct pt_regs *regs */
615 bralid r15, do_notify_resume; /* Handle any signals */
616 addi r6, r0, 0; /* Arg 2: int in_syscall */
619 /* Finally, return to user state. */
620 4: set_bip; /* Ints masked for state restore */
621 swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */
626 addik r1, r1, PT_SIZE /* Clean up stack space. */
628 lwi r1, r1, PT_R1 - PT_SIZE; /* Restore user stack pointer. */
630 /* Return to kernel state. */
631 2: set_bip; /* Ints masked for state restore */
635 addik r1, r1, PT_SIZE /* Clean up stack space. */
639 EXC_return: /* Make global symbol for debugging */
640 rtbd r14, 0; /* Instructions to return from an IRQ */
644 * HW EXCEPTION rutine end
648 * Hardware maskable interrupts.
650 * The stack-pointer (r1) should have already been saved to the memory
651 * location PER_CPU(ENTRY_SP).
654 /* MS: we are in physical address */
655 /* Save registers, switch to proper stack, convert SP to virtual.*/
656 swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP))
657 /* MS: See if already in kernel mode. */
663 /* Kernel-mode state save. */
664 lwi r1, r0, TOPHYS(PER_CPU(ENTRY_SP))
665 tophys(r1,r1); /* MS: I have in r1 physical address where stack is */
667 /* MS: Make room on the stack -> activation record */
668 addik r1, r1, -PT_SIZE;
671 swi r1, r1, PT_MODE; /* 0 - user mode, 1 - kernel mode */
673 /* User-mode state save. */
674 /* MS: get the saved current */
675 lwi r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
677 lwi r1, r1, TS_THREAD_INFO;
678 addik r1, r1, THREAD_SIZE;
681 addik r1, r1, -PT_SIZE;
685 lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
689 lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
691 addik r15, r0, irq_call;
692 irq_call:rtbd r0, do_IRQ;
695 /* MS: we are in virtual mode */
697 lwi r11, r1, PT_MODE;
701 lwi r11, CURRENT_TASK, TS_THREAD_INFO;
702 lwi r19, r11, TI_FLAGS; /* MS: get flags from thread info */
703 andi r11, r19, _TIF_NEED_RESCHED;
705 bralid r15, schedule;
706 nop; /* delay slot */
709 /* Maybe handle a signal */
710 5: andi r11, r19, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME;
711 beqid r11, no_intr_resched
712 /* Handle a signal return; Pending signals should be in r18. */
713 addik r5, r1, 0; /* Arg 1: struct pt_regs *regs */
714 bralid r15, do_notify_resume; /* Handle any signals */
715 addi r6, r0, 0; /* Arg 2: int in_syscall */
718 /* Finally, return to user state. */
720 /* Disable interrupts, we are now committed to the state restore */
722 swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE);
726 addik r1, r1, PT_SIZE /* MS: Clean up stack space. */
727 lwi r1, r1, PT_R1 - PT_SIZE;
729 /* MS: Return to kernel state. */
731 #ifdef CONFIG_PREEMPTION
732 lwi r11, CURRENT_TASK, TS_THREAD_INFO;
733 /* MS: get preempt_count from thread info */
734 lwi r5, r11, TI_PREEMPT_COUNT;
737 lwi r5, r11, TI_FLAGS; /* get flags in thread info */
738 andi r5, r5, _TIF_NEED_RESCHED;
739 beqi r5, restore /* if zero jump over */
741 /* interrupts are off that's why I am calling preempt_chedule_irq */
742 bralid r15, preempt_schedule_irq
746 VM_OFF /* MS: turn off MMU */
749 addik r1, r1, PT_SIZE /* MS: Clean up stack space. */
752 IRQ_return: /* MS: Make global symbol for debugging */
757 * Debug trap for KGDB. Enter to _debug_exception by brki r16, 0x18
758 * and call handling function with saved pt_regs
760 C_ENTRY(_debug_exception):
761 /* BIP bit is set on entry, no interrupts can occur */
762 swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP))
768 /* MS: Kernel-mode state save - kgdb */
769 lwi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)); /* Reload kernel stack-ptr*/
771 /* BIP bit is set on entry, no interrupts can occur */
772 addik r1, r1, CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START - PT_SIZE;
774 /* save all regs to pt_reg structure */
775 swi r0, r1, PT_R0; /* R0 must be saved too */
776 swi r14, r1, PT_R14 /* rewrite saved R14 value */
777 swi r16, r1, PT_PC; /* PC and r16 are the same */
778 /* save special purpose registers to pt_regs */
786 /* stack pointer is in physical address at it is decrease
787 * by PT_SIZE but we need to get correct R1 value */
788 addik r11, r1, CONFIG_KERNEL_START - CONFIG_KERNEL_BASE_ADDR + PT_SIZE;
790 /* MS: r31 - current pointer isn't changed */
793 addi r5, r1, 0 /* pass pt_reg address as the first arg */
794 addik r15, r0, dbtrap_call; /* return address */
795 rtbd r0, microblaze_kgdb_break
798 /* MS: Place handler for brki from kernel space if KGDB is OFF.
799 * It is very unlikely that another brki instruction is called. */
802 /* MS: User-mode state save - gdb */
803 1: lwi r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); /* get saved current */
805 lwi r1, r1, TS_THREAD_INFO; /* get the thread info */
806 addik r1, r1, THREAD_SIZE; /* calculate kernel stack pointer */
809 addik r1, r1, -PT_SIZE; /* Make room on the stack. */
811 swi r16, r1, PT_PC; /* Save LP */
812 swi r0, r1, PT_MODE; /* Was in user-mode. */
813 lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
814 swi r11, r1, PT_R1; /* Store user SP. */
815 lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
819 addik r15, r0, dbtrap_call;
820 dbtrap_call: /* Return point for kernel/user entry + 8 because of rtsd r15, 8 */
821 rtbd r0, sw_exception
824 /* MS: The first instruction for the second part of the gdb/kgdb */
825 set_bip; /* Ints masked for state restore */
826 lwi r11, r1, PT_MODE;
828 /* MS: Return to user space - gdb */
830 /* Get current task ptr into r11 */
831 lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */
832 lwi r19, r11, TI_FLAGS; /* get flags in thread info */
833 andi r11, r19, _TIF_NEED_RESCHED;
836 /* Call the scheduler before returning from a syscall/trap. */
837 bralid r15, schedule; /* Call scheduler */
838 nop; /* delay slot */
841 /* Maybe handle a signal */
842 5: andi r11, r19, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME;
843 beqi r11, 4f; /* Signals to handle, handle them */
845 addik r5, r1, 0; /* Arg 1: struct pt_regs *regs */
846 bralid r15, do_notify_resume; /* Handle any signals */
847 addi r6, r0, 0; /* Arg 2: int in_syscall */
850 /* Finally, return to user state. */
851 4: swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */
854 /* MS: Restore all regs */
856 addik r1, r1, PT_SIZE /* Clean up stack space */
857 lwi r1, r1, PT_R1 - PT_SIZE; /* Restore user stack pointer */
858 DBTRAP_return_user: /* MS: Make global symbol for debugging */
859 rtbd r16, 0; /* MS: Instructions to return from a debug trap */
862 /* MS: Return to kernel state - kgdb */
865 /* MS: Restore all regs */
869 addik r1, r1, PT_SIZE; /* MS: Clean up stack space */
871 DBTRAP_return_kernel: /* MS: Make global symbol for debugging */
872 rtbd r16, 0; /* MS: Instructions to return from a debug trap */
877 /* prepare return value */
878 addk r3, r0, CURRENT_TASK
880 /* save registers in cpu_context */
881 /* use r11 and r12, volatile registers, as temp register */
882 /* give start of cpu_context for previous process */
883 addik r11, r5, TI_CPU_CONTEXT
886 /* skip volatile registers.
887 * they are saved on stack when we jumped to _switch_to() */
888 /* dedicated registers */
895 /* save non-volatile registers */
908 /* special purpose registers */
918 /* update r31, the current-give me pointer to task which will be next */
919 lwi CURRENT_TASK, r6, TI_TASK
920 /* stored it to current_save too */
921 swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE)
923 /* get new process' cpu context and restore */
924 /* give me start where start context of next task */
925 addik r11, r6, TI_CPU_CONTEXT
927 /* non-volatile registers */
940 /* dedicated registers */
947 /* skip volatile registers */
951 /* special purpose registers */
961 brai 0; /* Jump to reset vector */
963 /* These are compiled and loaded into high memory, then
964 * copied into place in mach_early_setup */
965 .section .init.ivt, "ax"
966 #if CONFIG_MANUAL_RESET_VECTOR
968 brai CONFIG_MANUAL_RESET_VECTOR
971 brai TOPHYS(_user_exception); /* syscall handler */
973 brai TOPHYS(_interrupt); /* Interrupt handler */
975 brai TOPHYS(_debug_exception); /* debug trap handler */
977 brai TOPHYS(_hw_exception_handler); /* HW exception handler */
980 #include "syscall_table.S"
982 syscall_table_size=(.-sys_call_table)
989 .ascii "IRQ (PREEMPTED)\0"
990 type_SYSCALL_PREEMPT:
991 .ascii " SYSCALL (PREEMPTED)\0"
994 * Trap decoding for stack unwinder
995 * Tuples are (start addr, end addr, string)
996 * If return address lies on [start addr, end addr],
997 * unwinder displays 'string'
1001 .global microblaze_trap_handlers
1002 microblaze_trap_handlers:
1003 /* Exact matches come first */
1004 .word ret_from_trap; .word ret_from_trap ; .word type_SYSCALL
1005 .word ret_from_irq ; .word ret_from_irq ; .word type_IRQ
1006 /* Fuzzy matches go here */
1007 .word ret_from_irq ; .word no_intr_resched ; .word type_IRQ_PREEMPT
1008 .word ret_from_trap; .word TRAP_return ; .word type_SYSCALL_PREEMPT
1010 .word 0 ; .word 0 ; .word 0