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>
30 #include <asm/xilinx_mb_manager.h>
32 #include <linux/errno.h>
33 #include <asm/signal.h>
39 /* Create space for syscalls counting. */
41 .global syscall_debug_table
44 .space (__NR_syscalls * 4)
47 #define C_ENTRY(name) .globl name; .align 4; name
50 * Various ways of setting and clearing BIP in flags reg.
51 * This is mucky, but necessary using microblaze version that
52 * allows msr ops to write to BIP
54 #if CONFIG_XILINX_MICROBLAZE0_USE_MSR_INSTR
94 msrclr r0, MSR_VMS | MSR_UMS
99 andi r11, r11, ~MSR_BIP
105 ori r11, r11, MSR_BIP
111 andi r11, r11, ~MSR_EIP
123 andi r11, r11, ~MSR_IE
135 ori r11, r11, MSR_VMS
136 andni r11, r11, MSR_UMS
142 ori r11, r11, MSR_VMS
143 andni r11, r11, MSR_UMS
149 andni r11, r11, MSR_UMS
155 andni r11, r11, (MSR_VMS|MSR_UMS)
160 /* Define how to call high-level functions. With MMU, virtual mode must be
161 * enabled when calling the high-level function. Clobbers R11.
162 * VM_ON, VM_OFF, DO_JUMP_BIPCLR, DO_CALL
165 /* turn on virtual protected mode save */
172 /* turn off virtual protected mode save and user mode save*/
175 rted r0, TOPHYS(1f); \
180 swi r2, r1, PT_R2; /* Save SDA */ \
188 swi r10, r1, PT_R10; \
189 swi r11, r1, PT_R11; /* save clobbered regs after rval */\
190 swi r12, r1, PT_R12; \
191 swi r13, r1, PT_R13; /* Save SDA2 */ \
192 swi r14, r1, PT_PC; /* PC, before IRQ/trap */ \
193 swi r15, r1, PT_R15; /* Save LP */ \
194 swi r16, r1, PT_R16; \
195 swi r17, r1, PT_R17; \
196 swi r18, r1, PT_R18; /* Save asm scratch reg */ \
197 swi r19, r1, PT_R19; \
198 swi r20, r1, PT_R20; \
199 swi r21, r1, PT_R21; \
200 swi r22, r1, PT_R22; \
201 swi r23, r1, PT_R23; \
202 swi r24, r1, PT_R24; \
203 swi r25, r1, PT_R25; \
204 swi r26, r1, PT_R26; \
205 swi r27, r1, PT_R27; \
206 swi r28, r1, PT_R28; \
207 swi r29, r1, PT_R29; \
208 swi r30, r1, PT_R30; \
209 swi r31, r1, PT_R31; /* Save current task reg */ \
210 mfs r11, rmsr; /* save MSR */ \
213 #define RESTORE_REGS_GP \
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 */
245 #define RESTORE_REGS \
246 lwi r11, r1, PT_MSR; \
250 #define RESTORE_REGS_RTBD \
251 lwi r11, r1, PT_MSR; \
252 andni r11, r11, MSR_EIP; /* clear EIP */ \
253 ori r11, r11, MSR_EE | MSR_BIP; /* set EE and BIP */ \
258 swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)); /* save stack */ \
259 /* See if already in kernel mode.*/ \
261 andi r1, r1, MSR_UMS; \
263 /* Kernel-mode state save. */ \
264 /* Reload kernel stack-ptr. */ \
265 lwi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)); \
266 /* FIXME: I can add these two lines to one */ \
267 /* tophys(r1,r1); */ \
268 /* addik r1, r1, -PT_SIZE; */ \
269 addik r1, r1, CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START - PT_SIZE; \
272 swi r1, r1, PT_MODE; \
273 1: /* User-mode state save. */ \
274 lwi r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); /* get saved current */\
276 lwi r1, r1, TS_THREAD_INFO; /* get the thread info */ \
277 /* MS these three instructions can be added to one */ \
278 /* addik r1, r1, THREAD_SIZE; */ \
279 /* tophys(r1,r1); */ \
280 /* addik r1, r1, -PT_SIZE; */ \
281 addik r1, r1, THREAD_SIZE + CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START - PT_SIZE; \
283 lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); \
284 swi r11, r1, PT_R1; /* Store user SP. */ \
285 swi r0, r1, PT_MODE; /* Was in user-mode. */ \
286 /* MS: I am clearing UMS even in case when I come from kernel space */ \
288 2: lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
294 C_ENTRY(mb_flush_dcache):
295 addik r1, r1, -PT_SIZE
298 addik r3, r0, cpuinfo
308 addik r1, r1, PT_SIZE
312 C_ENTRY(mb_invalidate_icache):
313 addik r1, r1, -PT_SIZE
316 addik r3, r0, cpuinfo
326 addik r1, r1, PT_SIZE
333 * System calls are handled here.
336 * Syscall number in r12, args in r5-r10
339 * Trap entered via brki instruction, so BIP bit is set, and interrupts
340 * are masked. This is nice, means we don't have to CLI before state save
342 C_ENTRY(_user_exception):
343 swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)) /* save stack */
344 addi r14, r14, 4 /* return address is 4 byte after call */
346 lwi r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); /* get saved current */
348 lwi r1, r1, TS_THREAD_INFO; /* get stack from task_struct */
349 /* calculate kernel stack pointer from task struct 8k */
350 addik r1, r1, THREAD_SIZE;
353 addik r1, r1, -PT_SIZE; /* Make room on the stack. */
358 swi r0, r1, PT_MODE; /* Was in user-mode. */
359 lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
360 swi r11, r1, PT_R1; /* Store user SP. */
362 2: lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
363 /* Save away the syscall number. */
367 /* where the trap should return need -8 to adjust for rtsd r15, 8*/
368 /* Jump to the appropriate function for the system call number in r12
369 * (r12 is not preserved), or return an error if r12 is not valid. The LP
370 * register should point to the location where
371 * the called function should return. [note that MAKE_SYS_CALL uses label 1] */
373 /* Step into virtual mode */
377 lwi r11, CURRENT_TASK, TS_THREAD_INFO /* get thread info */
378 lwi r11, r11, TI_FLAGS /* get flags in thread info */
379 andi r11, r11, _TIF_WORK_SYSCALL_MASK
382 addik r3, r0, -ENOSYS
384 brlid r15, do_syscall_trace_enter
387 # do_syscall_trace_enter returns the new syscall nr.
396 /* Jump to the appropriate function for the system call number in r12
397 * (r12 is not preserved), or return an error if r12 is not valid.
398 * The LP register should point to the location where the called function
399 * should return. [note that MAKE_SYS_CALL uses label 1] */
400 /* See if the system call number is valid */
402 addi r11, r12, -__NR_syscalls;
404 /* Figure out which function to use for this system call. */
405 /* Note Microblaze barrel shift is optional, so don't rely on it */
406 add r12, r12, r12; /* convert num -> ptr */
408 addi r30, r0, 1 /* restarts allowed */
411 /* Trac syscalls and stored them to syscall_debug_table */
412 /* The first syscall location stores total syscall number */
413 lwi r3, r0, syscall_debug_table
415 swi r3, r0, syscall_debug_table
416 lwi r3, r12, syscall_debug_table
418 swi r3, r12, syscall_debug_table
421 # Find and jump into the syscall handler.
422 lwi r12, r12, sys_call_table
423 /* where the trap should return need -8 to adjust for rtsd r15, 8 */
424 addi r15, r0, ret_from_trap-8
427 /* The syscall number is invalid, return an error. */
430 addi r3, r0, -ENOSYS;
432 /* Entry point used to return from a syscall/trap */
433 /* We re-enable BIP bit before state restore */
434 C_ENTRY(ret_from_trap):
438 lwi r11, r1, PT_MODE;
439 /* See if returning to kernel mode, if so, skip resched &c. */
441 /* We're returning to user mode, so check for various conditions that
442 * trigger rescheduling. */
443 /* FIXME: Restructure all these flag checks. */
444 lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */
445 lwi r11, r11, TI_FLAGS; /* get flags in thread info */
446 andi r11, r11, _TIF_WORK_SYSCALL_MASK
449 brlid r15, do_syscall_trace_leave
452 /* We're returning to user mode, so check for various conditions that
453 * trigger rescheduling. */
454 /* get thread info from current task */
455 lwi r11, CURRENT_TASK, TS_THREAD_INFO;
456 lwi r19, r11, TI_FLAGS; /* get flags in thread info */
457 andi r11, r19, _TIF_NEED_RESCHED;
460 bralid r15, schedule; /* Call scheduler */
461 nop; /* delay slot */
464 /* Maybe handle a signal */
466 andi r11, r19, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME;
467 beqi r11, 4f; /* Signals to handle, handle them */
469 addik r5, r1, 0; /* Arg 1: struct pt_regs *regs */
470 bralid r15, do_notify_resume; /* Handle any signals */
471 add r6, r30, r0; /* Arg 2: int in_syscall */
472 add r30, r0, r0 /* no more restarts */
475 /* Finally, return to user state. */
476 4: set_bip; /* Ints masked for state restore */
477 swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */
481 addik r1, r1, PT_SIZE /* Clean up stack space. */
482 lwi r1, r1, PT_R1 - PT_SIZE;/* Restore user stack pointer. */
485 /* Return to kernel state. */
486 2: set_bip; /* Ints masked for state restore */
490 addik r1, r1, PT_SIZE /* Clean up stack space. */
493 TRAP_return: /* Make global symbol for debugging */
494 rtbd r14, 0; /* Instructions to return from an IRQ */
498 /* This the initial entry point for a new child thread, with an appropriate
499 stack in place that makes it look like the child is in the middle of a
500 syscall. This function is actually `returned to' from switch_thread
501 (copy_thread makes ret_from_fork the return address in each new thread's
503 C_ENTRY(ret_from_fork):
504 bralid r15, schedule_tail; /* ...which is schedule_tail's arg */
505 add r5, r3, r0; /* switch_thread returns the prev task */
506 /* ( in the delay slot ) */
507 brid ret_from_trap; /* Do normal trap return */
508 add r3, r0, r0; /* Child's fork call should return 0. */
510 C_ENTRY(ret_from_kernel_thread):
511 bralid r15, schedule_tail; /* ...which is schedule_tail's arg */
512 add r5, r3, r0; /* switch_thread returns the prev task */
513 /* ( in the delay slot ) */
514 brald r15, r20 /* fn was left in r20 */
515 addk r5, r0, r19 /* ... and argument - in r19 */
519 C_ENTRY(sys_rt_sigreturn_wrapper):
520 addik r30, r0, 0 /* no restarts */
521 brid sys_rt_sigreturn /* Do real work */
522 addik r5, r1, 0; /* add user context as 1st arg */
525 * HW EXCEPTION rutine start
527 C_ENTRY(full_exception_trap):
528 /* adjust exception address for privileged instruction
529 * for finding where is it */
531 SAVE_STATE /* Save registers */
532 /* PC, before IRQ/trap - this is one instruction above */
535 /* FIXME this can be store directly in PT_ESR reg.
536 * I tested it but there is a fault */
537 /* where the trap should return need -8 to adjust for rtsd r15, 8 */
538 addik r15, r0, ret_from_exc - 8
540 mfs r7, rfsr; /* save FSR */
541 mts rfsr, r0; /* Clear sticky fsr */
542 rted r0, full_exception
543 addik r5, r1, 0 /* parameter struct pt_regs * regs */
546 * Unaligned data trap.
548 * Unaligned data trap last on 4k page is handled here.
550 * Trap entered via exception, so EE bit is set, and interrupts
551 * are masked. This is nice, means we don't have to CLI before state save
553 * The assembler routine is in "arch/microblaze/kernel/hw_exception_handler.S"
555 C_ENTRY(unaligned_data_trap):
556 /* MS: I have to save r11 value and then restore it because
557 * set_bit, clear_eip, set_ee use r11 as temp register if MSR
558 * instructions are not used. We don't need to do if MSR instructions
559 * are used and they use r0 instead of r11.
560 * I am using ENTRY_SP which should be primary used only for stack
562 swi r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
563 set_bip; /* equalize initial state for all possible entries */
566 lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
567 SAVE_STATE /* Save registers.*/
568 /* PC, before IRQ/trap - this is one instruction above */
571 /* where the trap should return need -8 to adjust for rtsd r15, 8 */
572 addik r15, r0, ret_from_exc-8
573 mfs r3, resr /* ESR */
574 mfs r4, rear /* EAR */
575 rtbd r0, _unaligned_data_exception
576 addik r7, r1, 0 /* parameter struct pt_regs * regs */
581 * If the real exception handler (from hw_exception_handler.S) didn't find
582 * the mapping for the process, then we're thrown here to handle such situation.
584 * Trap entered via exceptions, so EE bit is set, and interrupts
585 * are masked. This is nice, means we don't have to CLI before state save
587 * Build a standard exception frame for TLB Access errors. All TLB exceptions
588 * will bail out to this point if they can't resolve the lightweight TLB fault.
590 * The C function called is in "arch/microblaze/mm/fault.c", declared as:
591 * void do_page_fault(struct pt_regs *regs,
592 * unsigned long address,
593 * unsigned long error_code)
595 /* data and intruction trap - which is choose is resolved int fault.c */
596 C_ENTRY(page_fault_data_trap):
597 SAVE_STATE /* Save registers.*/
598 /* PC, before IRQ/trap - this is one instruction above */
601 /* where the trap should return need -8 to adjust for rtsd r15, 8 */
602 addik r15, r0, ret_from_exc-8
603 mfs r6, rear /* parameter unsigned long address */
604 mfs r7, resr /* parameter unsigned long error_code */
605 rted r0, do_page_fault
606 addik r5, r1, 0 /* parameter struct pt_regs * regs */
608 C_ENTRY(page_fault_instr_trap):
609 SAVE_STATE /* Save registers.*/
610 /* PC, before IRQ/trap - this is one instruction above */
613 /* where the trap should return need -8 to adjust for rtsd r15, 8 */
614 addik r15, r0, ret_from_exc-8
615 mfs r6, rear /* parameter unsigned long address */
616 ori r7, r0, 0 /* parameter unsigned long error_code */
617 rted r0, do_page_fault
618 addik r5, r1, 0 /* parameter struct pt_regs * regs */
620 /* Entry point used to return from an exception. */
621 C_ENTRY(ret_from_exc):
622 lwi r11, r1, PT_MODE;
623 bnei r11, 2f; /* See if returning to kernel mode, */
624 /* ... if so, skip resched &c. */
626 /* We're returning to user mode, so check for various conditions that
627 trigger rescheduling. */
629 lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */
630 lwi r19, r11, TI_FLAGS; /* get flags in thread info */
631 andi r11, r19, _TIF_NEED_RESCHED;
634 /* Call the scheduler before returning from a syscall/trap. */
635 bralid r15, schedule; /* Call scheduler */
636 nop; /* delay slot */
639 /* Maybe handle a signal */
640 5: andi r11, r19, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME;
641 beqi r11, 4f; /* Signals to handle, handle them */
644 * Handle a signal return; Pending signals should be in r18.
646 * Not all registers are saved by the normal trap/interrupt entry
647 * points (for instance, call-saved registers (because the normal
648 * C-compiler calling sequence in the kernel makes sure they're
649 * preserved), and call-clobbered registers in the case of
650 * traps), but signal handlers may want to examine or change the
651 * complete register state. Here we save anything not saved by
652 * the normal entry sequence, so that it may be safely restored
653 * (in a possibly modified form) after do_notify_resume returns. */
654 addik r5, r1, 0; /* Arg 1: struct pt_regs *regs */
655 bralid r15, do_notify_resume; /* Handle any signals */
656 addi r6, r0, 0; /* Arg 2: int in_syscall */
659 /* Finally, return to user state. */
660 4: set_bip; /* Ints masked for state restore */
661 swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */
666 addik r1, r1, PT_SIZE /* Clean up stack space. */
668 lwi r1, r1, PT_R1 - PT_SIZE; /* Restore user stack pointer. */
670 /* Return to kernel state. */
671 2: set_bip; /* Ints masked for state restore */
675 addik r1, r1, PT_SIZE /* Clean up stack space. */
679 EXC_return: /* Make global symbol for debugging */
680 rtbd r14, 0; /* Instructions to return from an IRQ */
684 * HW EXCEPTION rutine end
688 * Hardware maskable interrupts.
690 * The stack-pointer (r1) should have already been saved to the memory
691 * location PER_CPU(ENTRY_SP).
694 /* MS: we are in physical address */
695 /* Save registers, switch to proper stack, convert SP to virtual.*/
696 swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP))
697 /* MS: See if already in kernel mode. */
703 /* Kernel-mode state save. */
704 lwi r1, r0, TOPHYS(PER_CPU(ENTRY_SP))
705 tophys(r1,r1); /* MS: I have in r1 physical address where stack is */
707 /* MS: Make room on the stack -> activation record */
708 addik r1, r1, -PT_SIZE;
711 swi r1, r1, PT_MODE; /* 0 - user mode, 1 - kernel mode */
713 /* User-mode state save. */
714 /* MS: get the saved current */
715 lwi r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
717 lwi r1, r1, TS_THREAD_INFO;
718 addik r1, r1, THREAD_SIZE;
721 addik r1, r1, -PT_SIZE;
725 lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
729 lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
731 addik r15, r0, irq_call;
732 irq_call:rtbd r0, do_IRQ;
735 /* MS: we are in virtual mode */
737 lwi r11, r1, PT_MODE;
741 lwi r11, CURRENT_TASK, TS_THREAD_INFO;
742 lwi r19, r11, TI_FLAGS; /* MS: get flags from thread info */
743 andi r11, r19, _TIF_NEED_RESCHED;
745 bralid r15, schedule;
746 nop; /* delay slot */
749 /* Maybe handle a signal */
750 5: andi r11, r19, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME;
751 beqid r11, no_intr_resched
752 /* Handle a signal return; Pending signals should be in r18. */
753 addik r5, r1, 0; /* Arg 1: struct pt_regs *regs */
754 bralid r15, do_notify_resume; /* Handle any signals */
755 addi r6, r0, 0; /* Arg 2: int in_syscall */
758 /* Finally, return to user state. */
760 /* Disable interrupts, we are now committed to the state restore */
762 swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE);
766 addik r1, r1, PT_SIZE /* MS: Clean up stack space. */
767 lwi r1, r1, PT_R1 - PT_SIZE;
769 /* MS: Return to kernel state. */
771 #ifdef CONFIG_PREEMPTION
772 lwi r11, CURRENT_TASK, TS_THREAD_INFO;
773 /* MS: get preempt_count from thread info */
774 lwi r5, r11, TI_PREEMPT_COUNT;
777 lwi r5, r11, TI_FLAGS; /* get flags in thread info */
778 andi r5, r5, _TIF_NEED_RESCHED;
779 beqi r5, restore /* if zero jump over */
781 /* interrupts are off that's why I am calling preempt_chedule_irq */
782 bralid r15, preempt_schedule_irq
786 VM_OFF /* MS: turn off MMU */
789 addik r1, r1, PT_SIZE /* MS: Clean up stack space. */
792 IRQ_return: /* MS: Make global symbol for debugging */
796 #ifdef CONFIG_MB_MANAGER
798 #define PT_PID PT_SIZE
799 #define PT_TLBI PT_SIZE + 4
800 #define PT_ZPR PT_SIZE + 8
801 #define PT_TLBL0 PT_SIZE + 12
802 #define PT_TLBH0 PT_SIZE + 16
804 C_ENTRY(_xtmr_manager_reset):
805 lwi r1, r0, xmb_manager_stackpointer
812 /* restore Special purpose registers */
822 #if CONFIG_XILINX_MICROBLAZE0_USE_FPU
827 /* restore all the tlb's */
828 addik r3, r0, TOPHYS(tlb_skip)
829 addik r6, r0, PT_TLBL0
830 addik r7, r0, PT_TLBH0
840 bgtid r3, restore_tlb
843 lwi r5, r0, TOPHYS(xmb_manager_dev)
844 lwi r8, r0, TOPHYS(xmb_manager_reset_callback)
846 /* return from reset need -8 to adjust for rtsd r15, 8 */
847 addik r15, r0, ret_from_reset - 8
852 set_bip /* Ints masked for state restore */
854 /* MS: Restore all regs */
858 addik r1, r1, PT_SIZE + 36
863 * Break handler for MB Manager. Enter to _xmb_manager_break by
864 * injecting fault in one of the TMR Microblaze core.
865 * FIXME: This break handler supports getting
866 * called from kernel space only.
868 C_ENTRY(_xmb_manager_break):
870 * Reserve memory in the stack for context store/restore
871 * (which includes memory for storing tlbs (max two tlbs))
873 addik r1, r1, -PT_SIZE - 36
874 swi r1, r0, xmb_manager_stackpointer
876 swi r14, r1, PT_R14 /* rewrite saved R14 value */
877 swi r16, r1, PT_PC; /* PC and r16 are the same */
879 lwi r6, r0, TOPHYS(xmb_manager_baseaddr)
880 lwi r7, r0, TOPHYS(xmb_manager_crval)
882 * When the break vector gets asserted because of error injection,
883 * the break signal must be blocked before exiting from the
884 * break handler, below code configures the tmr manager
885 * control register to block break signal.
889 /* Save the special purpose registers */
899 #if CONFIG_XILINX_MICROBLAZE0_USE_FPU
906 /* Save all the tlb's */
907 addik r3, r0, TOPHYS(tlb_skip)
908 addik r6, r0, PT_TLBL0
909 addik r7, r0, PT_TLBH0
922 lwi r5, r0, TOPHYS(xmb_manager_dev)
923 lwi r8, r0, TOPHYS(xmb_manager_callback)
924 /* return from break need -8 to adjust for rtsd r15, 8 */
925 addik r15, r0, ret_from_break - 8
930 /* flush the d-cache */
931 bralid r15, mb_flush_dcache
935 * To make sure microblaze i-cache is in a proper state
936 * invalidate the i-cache.
938 bralid r15, mb_invalidate_icache
941 set_bip; /* Ints masked for state restore */
951 * Debug trap for KGDB. Enter to _debug_exception by brki r16, 0x18
952 * and call handling function with saved pt_regs
954 C_ENTRY(_debug_exception):
955 /* BIP bit is set on entry, no interrupts can occur */
956 swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP))
962 /* MS: Kernel-mode state save - kgdb */
963 lwi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)); /* Reload kernel stack-ptr*/
965 /* BIP bit is set on entry, no interrupts can occur */
966 addik r1, r1, CONFIG_KERNEL_BASE_ADDR - CONFIG_KERNEL_START - PT_SIZE;
968 /* save all regs to pt_reg structure */
969 swi r0, r1, PT_R0; /* R0 must be saved too */
970 swi r14, r1, PT_R14 /* rewrite saved R14 value */
971 swi r16, r1, PT_PC; /* PC and r16 are the same */
972 /* save special purpose registers to pt_regs */
980 /* stack pointer is in physical address at it is decrease
981 * by PT_SIZE but we need to get correct R1 value */
982 addik r11, r1, CONFIG_KERNEL_START - CONFIG_KERNEL_BASE_ADDR + PT_SIZE;
984 /* MS: r31 - current pointer isn't changed */
987 addi r5, r1, 0 /* pass pt_reg address as the first arg */
988 addik r15, r0, dbtrap_call; /* return address */
989 rtbd r0, microblaze_kgdb_break
992 /* MS: Place handler for brki from kernel space if KGDB is OFF.
993 * It is very unlikely that another brki instruction is called. */
996 /* MS: User-mode state save - gdb */
997 1: lwi r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); /* get saved current */
999 lwi r1, r1, TS_THREAD_INFO; /* get the thread info */
1000 addik r1, r1, THREAD_SIZE; /* calculate kernel stack pointer */
1003 addik r1, r1, -PT_SIZE; /* Make room on the stack. */
1005 swi r16, r1, PT_PC; /* Save LP */
1006 swi r0, r1, PT_MODE; /* Was in user-mode. */
1007 lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
1008 swi r11, r1, PT_R1; /* Store user SP. */
1009 lwi CURRENT_TASK, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
1013 addik r15, r0, dbtrap_call;
1014 dbtrap_call: /* Return point for kernel/user entry + 8 because of rtsd r15, 8 */
1015 rtbd r0, sw_exception
1018 /* MS: The first instruction for the second part of the gdb/kgdb */
1019 set_bip; /* Ints masked for state restore */
1020 lwi r11, r1, PT_MODE;
1022 /* MS: Return to user space - gdb */
1024 /* Get current task ptr into r11 */
1025 lwi r11, CURRENT_TASK, TS_THREAD_INFO; /* get thread info */
1026 lwi r19, r11, TI_FLAGS; /* get flags in thread info */
1027 andi r11, r19, _TIF_NEED_RESCHED;
1030 /* Call the scheduler before returning from a syscall/trap. */
1031 bralid r15, schedule; /* Call scheduler */
1032 nop; /* delay slot */
1035 /* Maybe handle a signal */
1036 5: andi r11, r19, _TIF_SIGPENDING | _TIF_NOTIFY_RESUME;
1037 beqi r11, 4f; /* Signals to handle, handle them */
1039 addik r5, r1, 0; /* Arg 1: struct pt_regs *regs */
1040 bralid r15, do_notify_resume; /* Handle any signals */
1041 addi r6, r0, 0; /* Arg 2: int in_syscall */
1044 /* Finally, return to user state. */
1045 4: swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE); /* save current */
1048 /* MS: Restore all regs */
1050 addik r1, r1, PT_SIZE /* Clean up stack space */
1051 lwi r1, r1, PT_R1 - PT_SIZE; /* Restore user stack pointer */
1052 DBTRAP_return_user: /* MS: Make global symbol for debugging */
1053 rtbd r16, 0; /* MS: Instructions to return from a debug trap */
1056 /* MS: Return to kernel state - kgdb */
1059 /* MS: Restore all regs */
1061 lwi r14, r1, PT_R14;
1063 addik r1, r1, PT_SIZE; /* MS: Clean up stack space */
1065 DBTRAP_return_kernel: /* MS: Make global symbol for debugging */
1066 rtbd r16, 0; /* MS: Instructions to return from a debug trap */
1071 /* prepare return value */
1072 addk r3, r0, CURRENT_TASK
1074 /* save registers in cpu_context */
1075 /* use r11 and r12, volatile registers, as temp register */
1076 /* give start of cpu_context for previous process */
1077 addik r11, r5, TI_CPU_CONTEXT
1080 /* skip volatile registers.
1081 * they are saved on stack when we jumped to _switch_to() */
1082 /* dedicated registers */
1083 swi r13, r11, CC_R13
1084 swi r14, r11, CC_R14
1085 swi r15, r11, CC_R15
1086 swi r16, r11, CC_R16
1087 swi r17, r11, CC_R17
1088 swi r18, r11, CC_R18
1089 /* save non-volatile registers */
1090 swi r19, r11, CC_R19
1091 swi r20, r11, CC_R20
1092 swi r21, r11, CC_R21
1093 swi r22, r11, CC_R22
1094 swi r23, r11, CC_R23
1095 swi r24, r11, CC_R24
1096 swi r25, r11, CC_R25
1097 swi r26, r11, CC_R26
1098 swi r27, r11, CC_R27
1099 swi r28, r11, CC_R28
1100 swi r29, r11, CC_R29
1101 swi r30, r11, CC_R30
1102 /* special purpose registers */
1104 swi r12, r11, CC_MSR
1106 swi r12, r11, CC_EAR
1108 swi r12, r11, CC_ESR
1110 swi r12, r11, CC_FSR
1112 /* update r31, the current-give me pointer to task which will be next */
1113 lwi CURRENT_TASK, r6, TI_TASK
1114 /* stored it to current_save too */
1115 swi CURRENT_TASK, r0, PER_CPU(CURRENT_SAVE)
1117 /* get new process' cpu context and restore */
1118 /* give me start where start context of next task */
1119 addik r11, r6, TI_CPU_CONTEXT
1121 /* non-volatile registers */
1122 lwi r30, r11, CC_R30
1123 lwi r29, r11, CC_R29
1124 lwi r28, r11, CC_R28
1125 lwi r27, r11, CC_R27
1126 lwi r26, r11, CC_R26
1127 lwi r25, r11, CC_R25
1128 lwi r24, r11, CC_R24
1129 lwi r23, r11, CC_R23
1130 lwi r22, r11, CC_R22
1131 lwi r21, r11, CC_R21
1132 lwi r20, r11, CC_R20
1133 lwi r19, r11, CC_R19
1134 /* dedicated registers */
1135 lwi r18, r11, CC_R18
1136 lwi r17, r11, CC_R17
1137 lwi r16, r11, CC_R16
1138 lwi r15, r11, CC_R15
1139 lwi r14, r11, CC_R14
1140 lwi r13, r11, CC_R13
1141 /* skip volatile registers */
1145 /* special purpose registers */
1146 lwi r12, r11, CC_FSR
1148 lwi r12, r11, CC_MSR
1154 #ifdef CONFIG_MB_MANAGER
1155 .global xmb_inject_err
1159 .type xmb_inject_err, @function
1161 addik r1, r1, -PT_SIZE
1164 /* Switch to real mode */
1169 bralid r15, XMB_INJECT_ERR_OFFSET
1172 /* enable virtual mode */
1174 /* barrier for instructions and data accesses */
1178 * Enable Interrupts, Virtual Protected Mode, equalize
1179 * initial state for all possible entries.
1185 addik r1, r1, PT_SIZE
1191 .global xmb_manager_dev
1192 .global xmb_manager_baseaddr
1193 .global xmb_manager_crval
1194 .global xmb_manager_callback
1195 .global xmb_manager_reset_callback
1196 .global xmb_manager_stackpointer
1200 xmb_manager_baseaddr:
1204 xmb_manager_callback:
1206 xmb_manager_reset_callback:
1208 xmb_manager_stackpointer:
1212 * When the break vector gets asserted because of error injection,
1213 * the break signal must be blocked before exiting from the
1214 * break handler, Below api updates the manager address and
1215 * control register and error count callback arguments,
1216 * which will be used by the break handler to block the
1217 * break and call the callback function.
1219 .global xmb_manager_register
1222 .ent xmb_manager_register
1223 .type xmb_manager_register, @function
1224 xmb_manager_register:
1225 swi r5, r0, xmb_manager_baseaddr
1226 swi r6, r0, xmb_manager_crval
1227 swi r7, r0, xmb_manager_callback
1228 swi r8, r0, xmb_manager_dev
1229 swi r9, r0, xmb_manager_reset_callback
1233 .end xmb_manager_register
1238 brai 0; /* Jump to reset vector */
1240 /* These are compiled and loaded into high memory, then
1241 * copied into place in mach_early_setup */
1242 .section .init.ivt, "ax"
1243 #if CONFIG_MANUAL_RESET_VECTOR && !defined(CONFIG_MB_MANAGER)
1245 brai CONFIG_MANUAL_RESET_VECTOR
1246 #elif defined(CONFIG_MB_MANAGER)
1248 brai TOPHYS(_xtmr_manager_reset);
1251 brai TOPHYS(_user_exception); /* syscall handler */
1253 brai TOPHYS(_interrupt); /* Interrupt handler */
1254 #ifdef CONFIG_MB_MANAGER
1256 brai TOPHYS(_xmb_manager_break); /* microblaze manager break handler */
1259 brai TOPHYS(_debug_exception); /* debug trap handler */
1262 brai TOPHYS(_hw_exception_handler); /* HW exception handler */
1264 #ifdef CONFIG_MB_MANAGER
1266 * For TMR Inject API which injects the error should
1267 * be executed from LMB.
1268 * TMR Inject is programmed with address of 0x200 so that
1269 * when program counter matches with this address error will
1270 * be injected. 0x200 is expected to be next available bram
1271 * offset, hence used for this api.
1273 .org XMB_INJECT_ERR_OFFSET
1280 .section .rodata,"a"
1281 #include "syscall_table.S"
1283 syscall_table_size=(.-sys_call_table)
1290 .ascii "IRQ (PREEMPTED)\0"
1291 type_SYSCALL_PREEMPT:
1292 .ascii " SYSCALL (PREEMPTED)\0"
1295 * Trap decoding for stack unwinder
1296 * Tuples are (start addr, end addr, string)
1297 * If return address lies on [start addr, end addr],
1298 * unwinder displays 'string'
1302 .global microblaze_trap_handlers
1303 microblaze_trap_handlers:
1304 /* Exact matches come first */
1305 .word ret_from_trap; .word ret_from_trap ; .word type_SYSCALL
1306 .word ret_from_irq ; .word ret_from_irq ; .word type_IRQ
1307 /* Fuzzy matches go here */
1308 .word ret_from_irq ; .word no_intr_resched ; .word type_IRQ_PREEMPT
1309 .word ret_from_trap; .word TRAP_return ; .word type_SYSCALL_PREEMPT
1311 .word 0 ; .word 0 ; .word 0