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>
34 /* The size of a state save frame. */
35 #define STATE_SAVE_SIZE (PT_SIZE + STATE_SAVE_ARG_SPACE)
37 /* The offset of the struct pt_regs in a `state save frame' on the stack. */
38 #define PTO STATE_SAVE_ARG_SPACE /* 24 the space for args */
40 #define C_ENTRY(name) .globl name; .align 4; name
43 * Various ways of setting and clearing BIP in flags reg.
44 * This is mucky, but necessary using microblaze version that
45 * allows msr ops to write to BIP
47 #if CONFIG_XILINX_MICROBLAZE0_USE_MSR_INSTR
102 andi r11, r11, ~MSR_BIP
110 ori r11, r11, MSR_BIP
118 andi r11, r11, ~MSR_EIP
134 andi r11, r11, ~MSR_IE
150 ori r11, r11, MSR_VMS
151 andni r11, r11, MSR_UMS
159 ori r11, r11, MSR_VMS
160 andni r11, r11, MSR_UMS
168 andni r11, r11, (MSR_VMS|MSR_UMS)
174 /* Define how to call high-level functions. With MMU, virtual mode must be
175 * enabled when calling the high-level function. Clobbers R11.
176 * VM_ON, VM_OFF, DO_JUMP_BIPCLR, DO_CALL
179 /* turn on virtual protected mode save */
185 /* turn off virtual protected mode save and user mode save*/
188 rted r0, TOPHYS(1f); \
192 swi r2, r1, PTO+PT_R2; /* Save SDA */ \
193 swi r5, r1, PTO+PT_R5; \
194 swi r6, r1, PTO+PT_R6; \
195 swi r7, r1, PTO+PT_R7; \
196 swi r8, r1, PTO+PT_R8; \
197 swi r9, r1, PTO+PT_R9; \
198 swi r10, r1, PTO+PT_R10; \
199 swi r11, r1, PTO+PT_R11; /* save clobbered regs after rval */\
200 swi r12, r1, PTO+PT_R12; \
201 swi r13, r1, PTO+PT_R13; /* Save SDA2 */ \
202 swi r14, r1, PTO+PT_PC; /* PC, before IRQ/trap */ \
203 swi r15, r1, PTO+PT_R15; /* Save LP */ \
204 swi r18, r1, PTO+PT_R18; /* Save asm scratch reg */ \
205 swi r19, r1, PTO+PT_R19; \
206 swi r20, r1, PTO+PT_R20; \
207 swi r21, r1, PTO+PT_R21; \
208 swi r22, r1, PTO+PT_R22; \
209 swi r23, r1, PTO+PT_R23; \
210 swi r24, r1, PTO+PT_R24; \
211 swi r25, r1, PTO+PT_R25; \
212 swi r26, r1, PTO+PT_R26; \
213 swi r27, r1, PTO+PT_R27; \
214 swi r28, r1, PTO+PT_R28; \
215 swi r29, r1, PTO+PT_R29; \
216 swi r30, r1, PTO+PT_R30; \
217 swi r31, r1, PTO+PT_R31; /* Save current task reg */ \
218 mfs r11, rmsr; /* save MSR */ \
220 swi r11, r1, PTO+PT_MSR;
222 #define RESTORE_REGS \
223 lwi r11, r1, PTO+PT_MSR; \
226 lwi r2, r1, PTO+PT_R2; /* restore SDA */ \
227 lwi r5, r1, PTO+PT_R5; \
228 lwi r6, r1, PTO+PT_R6; \
229 lwi r7, r1, PTO+PT_R7; \
230 lwi r8, r1, PTO+PT_R8; \
231 lwi r9, r1, PTO+PT_R9; \
232 lwi r10, r1, PTO+PT_R10; \
233 lwi r11, r1, PTO+PT_R11; /* restore clobbered regs after rval */\
234 lwi r12, r1, PTO+PT_R12; \
235 lwi r13, r1, PTO+PT_R13; /* restore SDA2 */ \
236 lwi r14, r1, PTO+PT_PC; /* RESTORE_LINK PC, before IRQ/trap */\
237 lwi r15, r1, PTO+PT_R15; /* restore LP */ \
238 lwi r18, r1, PTO+PT_R18; /* restore asm scratch reg */ \
239 lwi r19, r1, PTO+PT_R19; \
240 lwi r20, r1, PTO+PT_R20; \
241 lwi r21, r1, PTO+PT_R21; \
242 lwi r22, r1, PTO+PT_R22; \
243 lwi r23, r1, PTO+PT_R23; \
244 lwi r24, r1, PTO+PT_R24; \
245 lwi r25, r1, PTO+PT_R25; \
246 lwi r26, r1, PTO+PT_R26; \
247 lwi r27, r1, PTO+PT_R27; \
248 lwi r28, r1, PTO+PT_R28; \
249 lwi r29, r1, PTO+PT_R29; \
250 lwi r30, r1, PTO+PT_R30; \
251 lwi r31, r1, PTO+PT_R31; /* Restore cur task reg */
258 * System calls are handled here.
261 * Syscall number in r12, args in r5-r10
264 * Trap entered via brki instruction, so BIP bit is set, and interrupts
265 * are masked. This is nice, means we don't have to CLI before state save
267 C_ENTRY(_user_exception):
268 swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)) /* save stack */
269 addi r14, r14, 4 /* return address is 4 byte after call */
270 swi r11, r0, TOPHYS(r0_ram + PTO + PT_R11); /* Save r11 */
272 lwi r11, r0, TOPHYS(PER_CPU(KM));/* See if already in kernel mode.*/
273 beqi r11, 1f; /* Jump ahead if coming from user */
274 /* Kernel-mode state save. */
275 lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); /* Reload kernel stack-ptr*/
277 swi r11, r1, (PT_R1-PT_SIZE); /* Save original SP. */
278 lwi r11, r0, TOPHYS(r0_ram + PTO + PT_R11); /* restore r11 */
280 addik r1, r1, -STATE_SAVE_SIZE; /* Make room on the stack. */
283 addi r11, r0, 1; /* Was in kernel-mode. */
284 swi r11, r1, PTO+PT_MODE; /* pt_regs -> kernel mode */
286 nop; /* Fill delay slot */
288 /* User-mode state save. */
290 lwi r11, r0, TOPHYS(r0_ram + PTO + PT_R11); /* restore r11 */
291 lwi r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); /* get saved current */
293 lwi r1, r1, TS_THREAD_INFO; /* get stack from task_struct */
294 /* calculate kernel stack pointer from task struct 8k */
295 addik r1, r1, THREAD_SIZE;
298 addik r1, r1, -STATE_SAVE_SIZE; /* Make room on the stack. */
301 swi r0, r1, PTO+PT_MODE; /* Was in user-mode. */
302 lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
303 swi r11, r1, PTO+PT_R1; /* Store user SP. */
305 swi r11, r0, TOPHYS(PER_CPU(KM)); /* Now we're in kernel-mode. */
306 2: lwi r31, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); /* get saved current */
307 /* Save away the syscall number. */
308 swi r12, r1, PTO+PT_R0;
311 /* where the trap should return need -8 to adjust for rtsd r15, 8*/
312 /* Jump to the appropriate function for the system call number in r12
313 * (r12 is not preserved), or return an error if r12 is not valid. The LP
314 * register should point to the location where
315 * the called function should return. [note that MAKE_SYS_CALL uses label 1] */
317 # Step into virtual mode.
323 add r11, r0, CURRENT_TASK /* Get current task ptr into r11 */
324 lwi r11, r11, TS_THREAD_INFO /* get thread info */
325 lwi r11, r11, TI_FLAGS /* get flags in thread info */
326 andi r11, r11, _TIF_WORK_SYSCALL_MASK
329 addik r3, r0, -ENOSYS
330 swi r3, r1, PTO + PT_R3
331 brlid r15, do_syscall_trace_enter
332 addik r5, r1, PTO + PT_R0
334 # do_syscall_trace_enter returns the new syscall nr.
336 lwi r5, r1, PTO+PT_R5;
337 lwi r6, r1, PTO+PT_R6;
338 lwi r7, r1, PTO+PT_R7;
339 lwi r8, r1, PTO+PT_R8;
340 lwi r9, r1, PTO+PT_R9;
341 lwi r10, r1, PTO+PT_R10;
343 /* Jump to the appropriate function for the system call number in r12
344 * (r12 is not preserved), or return an error if r12 is not valid.
345 * The LP register should point to the location where the called function
346 * should return. [note that MAKE_SYS_CALL uses label 1] */
347 /* See if the system call number is valid */
348 addi r11, r12, -__NR_syscalls;
350 /* Figure out which function to use for this system call. */
351 /* Note Microblaze barrel shift is optional, so don't rely on it */
352 add r12, r12, r12; /* convert num -> ptr */
355 /* Trac syscalls and stored them to r0_ram */
356 lwi r3, r12, 0x400 + r0_ram
358 swi r3, r12, 0x400 + r0_ram
360 # Find and jump into the syscall handler.
361 lwi r12, r12, sys_call_table
362 /* where the trap should return need -8 to adjust for rtsd r15, 8 */
363 la r15, r0, ret_from_trap-8
366 /* The syscall number is invalid, return an error. */
368 addi r3, r0, -ENOSYS;
369 rtsd r15,8; /* looks like a normal subroutine return */
373 /* Entry point used to return from a syscall/trap */
374 /* We re-enable BIP bit before state restore */
375 C_ENTRY(ret_from_trap):
376 set_bip; /* Ints masked for state restore*/
377 lwi r11, r1, PTO+PT_MODE;
378 /* See if returning to kernel mode, if so, skip resched &c. */
381 /* We're returning to user mode, so check for various conditions that
382 * trigger rescheduling. */
383 # FIXME: Restructure all these flag checks.
384 add r11, r0, CURRENT_TASK; /* Get current task ptr into r11 */
385 lwi r11, r11, TS_THREAD_INFO; /* get thread info */
386 lwi r11, r11, TI_FLAGS; /* get flags in thread info */
387 andi r11, r11, _TIF_WORK_SYSCALL_MASK
390 swi r3, r1, PTO + PT_R3
391 swi r4, r1, PTO + PT_R4
392 brlid r15, do_syscall_trace_leave
393 addik r5, r1, PTO + PT_R0
394 lwi r3, r1, PTO + PT_R3
395 lwi r4, r1, PTO + PT_R4
398 /* We're returning to user mode, so check for various conditions that
399 * trigger rescheduling. */
400 /* Get current task ptr into r11 */
401 add r11, r0, CURRENT_TASK; /* Get current task ptr into r11 */
402 lwi r11, r11, TS_THREAD_INFO; /* get thread info */
403 lwi r11, r11, TI_FLAGS; /* get flags in thread info */
404 andi r11, r11, _TIF_NEED_RESCHED;
407 swi r3, r1, PTO + PT_R3; /* store syscall result */
408 swi r4, r1, PTO + PT_R4;
409 bralid r15, schedule; /* Call scheduler */
410 nop; /* delay slot */
411 lwi r3, r1, PTO + PT_R3; /* restore syscall result */
412 lwi r4, r1, PTO + PT_R4;
414 /* Maybe handle a signal */
415 5: add r11, r0, CURRENT_TASK; /* Get current task ptr into r11 */
416 lwi r11, r11, TS_THREAD_INFO; /* get thread info */
417 lwi r11, r11, TI_FLAGS; /* get flags in thread info */
418 andi r11, r11, _TIF_SIGPENDING;
419 beqi r11, 1f; /* Signals to handle, handle them */
421 swi r3, r1, PTO + PT_R3; /* store syscall result */
422 swi r4, r1, PTO + PT_R4;
423 la r5, r1, PTO; /* Arg 1: struct pt_regs *regs */
424 add r6, r0, r0; /* Arg 2: sigset_t *oldset */
425 addi r7, r0, 1; /* Arg 3: int in_syscall */
426 bralid r15, do_signal; /* Handle any signals */
428 lwi r3, r1, PTO + PT_R3; /* restore syscall result */
429 lwi r4, r1, PTO + PT_R4;
431 /* Finally, return to user state. */
432 1: swi r0, r0, PER_CPU(KM); /* Now officially in user state. */
433 add r11, r0, CURRENT_TASK; /* Get current task ptr into r11 */
434 swi r11, r0, PER_CPU(CURRENT_SAVE); /* save current */
438 addik r1, r1, STATE_SAVE_SIZE /* Clean up stack space. */
439 lwi r1, r1, PT_R1 - PT_SIZE;/* Restore user stack pointer. */
442 /* Return to kernel state. */
446 addik r1, r1, STATE_SAVE_SIZE /* Clean up stack space. */
449 TRAP_return: /* Make global symbol for debugging */
450 rtbd r14, 0; /* Instructions to return from an IRQ */
454 /* These syscalls need access to the struct pt_regs on the stack, so we
455 implement them in assembly (they're basically all wrappers anyway). */
457 C_ENTRY(sys_fork_wrapper):
458 addi r5, r0, SIGCHLD /* Arg 0: flags */
459 lwi r6, r1, PTO+PT_R1 /* Arg 1: child SP (use parent's) */
460 la r7, r1, PTO /* Arg 2: parent context */
461 add r8. r0, r0 /* Arg 3: (unused) */
462 add r9, r0, r0; /* Arg 4: (unused) */
463 add r10, r0, r0; /* Arg 5: (unused) */
464 brid do_fork /* Do real work (tail-call) */
467 /* This the initial entry point for a new child thread, with an appropriate
468 stack in place that makes it look the the child is in the middle of an
469 syscall. This function is actually `returned to' from switch_thread
470 (copy_thread makes ret_from_fork the return address in each new thread's
472 C_ENTRY(ret_from_fork):
473 bralid r15, schedule_tail; /* ...which is schedule_tail's arg */
474 add r3, r5, r0; /* switch_thread returns the prev task */
475 /* ( in the delay slot ) */
476 add r3, r0, r0; /* Child's fork call should return 0. */
477 brid ret_from_trap; /* Do normal trap return */
481 brid microblaze_vfork /* Do real work (tail-call) */
485 bnei r6, 1f; /* See if child SP arg (arg 1) is 0. */
486 lwi r6, r1, PTO+PT_R1; /* If so, use paret's stack ptr */
487 1: la r7, r1, PTO; /* Arg 2: parent context */
488 add r8, r0, r0; /* Arg 3: (unused) */
489 add r9, r0, r0; /* Arg 4: (unused) */
490 add r10, r0, r0; /* Arg 5: (unused) */
491 brid do_fork /* Do real work (tail-call) */
495 la r8, r1, PTO; /* add user context as 4th arg */
496 brid microblaze_execve; /* Do real work (tail-call).*/
499 C_ENTRY(sys_rt_sigsuspend_wrapper):
500 swi r3, r1, PTO+PT_R3; /* restore saved r3, r4 registers */
501 swi r4, r1, PTO+PT_R4;
502 la r7, r1, PTO; /* add user context as 3rd arg */
503 brlid r15, sys_rt_sigsuspend; /* Do real work.*/
505 lwi r3, r1, PTO+PT_R3; /* restore saved r3, r4 registers */
506 lwi r4, r1, PTO+PT_R4;
507 bri ret_from_trap /* fall through will not work here due to align */
510 C_ENTRY(sys_rt_sigreturn_wrapper):
511 swi r3, r1, PTO+PT_R3; /* restore saved r3, r4 registers */
512 swi r4, r1, PTO+PT_R4;
513 la r5, r1, PTO; /* add user context as 1st arg */
514 brlid r15, sys_rt_sigreturn /* Do real work */
516 lwi r3, r1, PTO+PT_R3; /* restore saved r3, r4 registers */
517 lwi r4, r1, PTO+PT_R4;
518 bri ret_from_trap /* fall through will not work here due to align */
522 * HW EXCEPTION rutine start
526 swi r11, r0, TOPHYS(r0_ram + PTO + PT_R11); /* Save r11 */ \
527 set_bip; /*equalize initial state for all possible entries*/\
531 /* See if already in kernel mode.*/ \
532 lwi r11, r0, TOPHYS(PER_CPU(KM)); \
533 beqi r11, 1f; /* Jump ahead if coming from user */\
534 /* Kernel-mode state save. */ \
535 /* Reload kernel stack-ptr. */ \
536 lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); \
538 swi r11, r1, (PT_R1-PT_SIZE); /* Save original SP. */ \
539 lwi r11, r0, TOPHYS(r0_ram + PTO + PT_R11); /* restore r11 */\
540 addik r1, r1, -STATE_SAVE_SIZE; /* Make room on the stack. */\
541 /* store return registers separately because \
542 * this macros is use for others exceptions */ \
543 swi r3, r1, PTO + PT_R3; \
544 swi r4, r1, PTO + PT_R4; \
546 /* PC, before IRQ/trap - this is one instruction above */ \
547 swi r17, r1, PTO+PT_PC; \
549 addi r11, r0, 1; /* Was in kernel-mode. */ \
550 swi r11, r1, PTO+PT_MODE; \
552 nop; /* Fill delay slot */ \
553 1: /* User-mode state save. */ \
554 lwi r11, r0, TOPHYS(r0_ram + PTO + PT_R11); /* restore r11 */\
555 lwi r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); /* get saved current */\
557 lwi r1, r1, TS_THREAD_INFO; /* get the thread info */ \
558 addik r1, r1, THREAD_SIZE; /* calculate kernel stack pointer */\
561 addik r1, r1, -STATE_SAVE_SIZE; /* Make room on the stack. */\
562 /* store return registers separately because this macros \
563 * is use for others exceptions */ \
564 swi r3, r1, PTO + PT_R3; \
565 swi r4, r1, PTO + PT_R4; \
567 /* PC, before IRQ/trap - this is one instruction above FIXME*/ \
568 swi r17, r1, PTO+PT_PC; \
570 swi r0, r1, PTO+PT_MODE; /* Was in user-mode. */ \
571 lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); \
572 swi r11, r1, PTO+PT_R1; /* Store user SP. */ \
574 swi r11, r0, TOPHYS(PER_CPU(KM)); /* Now we're in kernel-mode.*/\
575 2: lwi r31, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); /* get saved current */\
576 /* Save away the syscall number. */ \
577 swi r0, r1, PTO+PT_R0; \
580 C_ENTRY(full_exception_trap):
581 swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)) /* save stack */
582 /* adjust exception address for privileged instruction
583 * for finding where is it */
585 SAVE_STATE /* Save registers */
586 /* FIXME this can be store directly in PT_ESR reg.
587 * I tested it but there is a fault */
588 /* where the trap should return need -8 to adjust for rtsd r15, 8 */
589 la r15, r0, ret_from_exc - 8
590 la r5, r1, PTO /* parameter struct pt_regs * regs */
593 mfs r7, rfsr; /* save FSR */
595 mts rfsr, r0; /* Clear sticky fsr */
597 la r12, r0, full_exception
603 * Unaligned data trap.
605 * Unaligned data trap last on 4k page is handled here.
607 * Trap entered via exception, so EE bit is set, and interrupts
608 * are masked. This is nice, means we don't have to CLI before state save
610 * The assembler routine is in "arch/microblaze/kernel/hw_exception_handler.S"
612 C_ENTRY(unaligned_data_trap):
613 swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)) /* save stack */
614 SAVE_STATE /* Save registers.*/
615 /* where the trap should return need -8 to adjust for rtsd r15, 8 */
616 la r15, r0, ret_from_exc-8
617 mfs r3, resr /* ESR */
619 mfs r4, rear /* EAR */
621 la r7, r1, PTO /* parameter struct pt_regs * regs */
622 la r12, r0, _unaligned_data_exception
624 rtbd r12, 0; /* interrupts enabled */
630 * If the real exception handler (from hw_exception_handler.S) didn't find
631 * the mapping for the process, then we're thrown here to handle such situation.
633 * Trap entered via exceptions, so EE bit is set, and interrupts
634 * are masked. This is nice, means we don't have to CLI before state save
636 * Build a standard exception frame for TLB Access errors. All TLB exceptions
637 * will bail out to this point if they can't resolve the lightweight TLB fault.
639 * The C function called is in "arch/microblaze/mm/fault.c", declared as:
640 * void do_page_fault(struct pt_regs *regs,
641 * unsigned long address,
642 * unsigned long error_code)
644 /* data and intruction trap - which is choose is resolved int fault.c */
645 C_ENTRY(page_fault_data_trap):
646 swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)) /* save stack */
647 SAVE_STATE /* Save registers.*/
648 /* where the trap should return need -8 to adjust for rtsd r15, 8 */
649 la r15, r0, ret_from_exc-8
650 la r5, r1, PTO /* parameter struct pt_regs * regs */
651 mfs r6, rear /* parameter unsigned long address */
653 mfs r7, resr /* parameter unsigned long error_code */
655 la r12, r0, do_page_fault
657 rtbd r12, 0; /* interrupts enabled */
660 C_ENTRY(page_fault_instr_trap):
661 swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP)) /* save stack */
662 SAVE_STATE /* Save registers.*/
663 /* where the trap should return need -8 to adjust for rtsd r15, 8 */
664 la r15, r0, ret_from_exc-8
665 la r5, r1, PTO /* parameter struct pt_regs * regs */
666 mfs r6, rear /* parameter unsigned long address */
668 ori r7, r0, 0 /* parameter unsigned long error_code */
669 la r12, r0, do_page_fault
671 rtbd r12, 0; /* interrupts enabled */
674 /* Entry point used to return from an exception. */
675 C_ENTRY(ret_from_exc):
676 set_bip; /* Ints masked for state restore*/
677 lwi r11, r1, PTO+PT_MODE;
678 bnei r11, 2f; /* See if returning to kernel mode, */
679 /* ... if so, skip resched &c. */
681 /* We're returning to user mode, so check for various conditions that
682 trigger rescheduling. */
683 /* Get current task ptr into r11 */
684 add r11, r0, CURRENT_TASK; /* Get current task ptr into r11 */
685 lwi r11, r11, TS_THREAD_INFO; /* get thread info */
686 lwi r11, r11, TI_FLAGS; /* get flags in thread info */
687 andi r11, r11, _TIF_NEED_RESCHED;
690 /* Call the scheduler before returning from a syscall/trap. */
691 bralid r15, schedule; /* Call scheduler */
692 nop; /* delay slot */
694 /* Maybe handle a signal */
695 5: add r11, r0, CURRENT_TASK; /* Get current task ptr into r11 */
696 lwi r11, r11, TS_THREAD_INFO; /* get thread info */
697 lwi r11, r11, TI_FLAGS; /* get flags in thread info */
698 andi r11, r11, _TIF_SIGPENDING;
699 beqi r11, 1f; /* Signals to handle, handle them */
702 * Handle a signal return; Pending signals should be in r18.
704 * Not all registers are saved by the normal trap/interrupt entry
705 * points (for instance, call-saved registers (because the normal
706 * C-compiler calling sequence in the kernel makes sure they're
707 * preserved), and call-clobbered registers in the case of
708 * traps), but signal handlers may want to examine or change the
709 * complete register state. Here we save anything not saved by
710 * the normal entry sequence, so that it may be safely restored
711 * (in a possibly modified form) after do_signal returns.
712 * store return registers separately because this macros is use
713 * for others exceptions */
714 swi r3, r1, PTO + PT_R3;
715 swi r4, r1, PTO + PT_R4;
716 la r5, r1, PTO; /* Arg 1: struct pt_regs *regs */
717 add r6, r0, r0; /* Arg 2: sigset_t *oldset */
718 addi r7, r0, 0; /* Arg 3: int in_syscall */
719 bralid r15, do_signal; /* Handle any signals */
721 lwi r3, r1, PTO+PT_R3; /* restore saved r3, r4 registers */
722 lwi r4, r1, PTO+PT_R4;
724 /* Finally, return to user state. */
725 1: swi r0, r0, PER_CPU(KM); /* Now officially in user state. */
726 add r11, r0, CURRENT_TASK; /* Get current task ptr into r11 */
727 swi r11, r0, PER_CPU(CURRENT_SAVE); /* save current */
731 lwi r3, r1, PTO+PT_R3; /* restore saved r3, r4 registers */
732 lwi r4, r1, PTO+PT_R4;
734 addik r1, r1, STATE_SAVE_SIZE /* Clean up stack space. */
736 lwi r1, r1, PT_R1 - PT_SIZE; /* Restore user stack pointer. */
738 /* Return to kernel state. */
741 lwi r3, r1, PTO+PT_R3; /* restore saved r3, r4 registers */
742 lwi r4, r1, PTO+PT_R4;
744 addik r1, r1, STATE_SAVE_SIZE /* Clean up stack space. */
748 EXC_return: /* Make global symbol for debugging */
749 rtbd r14, 0; /* Instructions to return from an IRQ */
753 * HW EXCEPTION rutine end
757 * Hardware maskable interrupts.
759 * The stack-pointer (r1) should have already been saved to the memory
760 * location PER_CPU(ENTRY_SP).
763 /* MS: we are in physical address */
764 /* Save registers, switch to proper stack, convert SP to virtual.*/
765 swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP))
766 swi r11, r0, TOPHYS(PER_CPU(R11_SAVE));
767 /* MS: See if already in kernel mode. */
768 lwi r11, r0, TOPHYS(PER_CPU(KM));
769 beqi r11, 1f; /* MS: Jump ahead if coming from user */
771 /* Kernel-mode state save. */
773 tophys(r1,r11); /* MS: I have in r1 physical address where stack is */
774 /* MS: Save original SP - position PT_R1 to next stack frame 4 *1 - 152*/
775 swi r11, r1, (PT_R1 - PT_SIZE);
776 /* MS: restore r11 because of saving in SAVE_REGS */
777 lwi r11, r0, TOPHYS(PER_CPU(R11_SAVE));
779 /* MS: Make room on the stack -> activation record */
780 addik r1, r1, -STATE_SAVE_SIZE;
781 /* MS: store return registers separately because
782 * this macros is use for others exceptions */
783 swi r3, r1, PTO + PT_R3;
784 swi r4, r1, PTO + PT_R4;
787 addi r11, r0, 1; /* MS: Was in kernel-mode. */
788 swi r11, r1, PTO + PT_MODE; /* MS: and save it */
790 nop; /* MS: Fill delay slot */
793 /* User-mode state save. */
794 /* MS: restore r11 -> FIXME move before SAVE_REG */
795 lwi r11, r0, TOPHYS(PER_CPU(R11_SAVE));
796 /* MS: get the saved current */
797 lwi r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
799 lwi r1, r1, TS_THREAD_INFO;
800 addik r1, r1, THREAD_SIZE;
803 addik r1, r1, -STATE_SAVE_SIZE;
804 swi r3, r1, PTO+PT_R3;
805 swi r4, r1, PTO+PT_R4;
808 swi r0, r1, PTO + PT_MODE;
809 lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
810 swi r11, r1, PTO+PT_R1;
811 /* setup kernel mode to KM */
813 swi r11, r0, TOPHYS(PER_CPU(KM));
816 lwi r31, r0, TOPHYS(PER_CPU(CURRENT_SAVE));
817 swi r0, r1, PTO + PT_R0;
822 la r15, r0, irq_call;
823 irq_call:rtbd r11, 0;
826 /* MS: we are in virtual mode */
828 lwi r11, r1, PTO + PT_MODE;
831 add r11, r0, CURRENT_TASK;
832 lwi r11, r11, TS_THREAD_INFO;
833 lwi r11, r11, TI_FLAGS; /* MS: get flags from thread info */
834 andi r11, r11, _TIF_NEED_RESCHED;
836 bralid r15, schedule;
837 nop; /* delay slot */
839 /* Maybe handle a signal */
840 5: add r11, r0, CURRENT_TASK;
841 lwi r11, r11, TS_THREAD_INFO; /* MS: get thread info */
842 lwi r11, r11, TI_FLAGS; /* get flags in thread info */
843 andi r11, r11, _TIF_SIGPENDING;
844 beqid r11, no_intr_resched
845 /* Handle a signal return; Pending signals should be in r18. */
846 addi r7, r0, 0; /* Arg 3: int in_syscall */
847 la r5, r1, PTO; /* Arg 1: struct pt_regs *regs */
848 bralid r15, do_signal; /* Handle any signals */
849 add r6, r0, r0; /* Arg 2: sigset_t *oldset */
851 /* Finally, return to user state. */
853 /* Disable interrupts, we are now committed to the state restore */
855 swi r0, r0, PER_CPU(KM); /* MS: Now officially in user state. */
856 add r11, r0, CURRENT_TASK;
857 swi r11, r0, PER_CPU(CURRENT_SAVE);
860 lwi r3, r1, PTO + PT_R3; /* MS: restore saved r3, r4 registers */
861 lwi r4, r1, PTO + PT_R4;
863 addik r1, r1, STATE_SAVE_SIZE /* MS: Clean up stack space. */
864 lwi r1, r1, PT_R1 - PT_SIZE;
866 /* MS: Return to kernel state. */
867 2: VM_OFF /* MS: turn off MMU */
869 lwi r3, r1, PTO + PT_R3; /* MS: restore saved r3, r4 registers */
870 lwi r4, r1, PTO + PT_R4;
872 addik r1, r1, STATE_SAVE_SIZE /* MS: Clean up stack space. */
875 IRQ_return: /* MS: Make global symbol for debugging */
881 * We enter dbtrap in "BIP" (breakpoint) mode.
882 * So we exit the breakpoint mode with an 'rtbd' and proceed with the
884 * however, wait to save state first
886 C_ENTRY(_debug_exception):
887 /* BIP bit is set on entry, no interrupts can occur */
888 swi r1, r0, TOPHYS(PER_CPU(ENTRY_SP))
890 swi r11, r0, TOPHYS(r0_ram + PTO + PT_R11); /* Save r11 */
891 set_bip; /*equalize initial state for all possible entries*/
894 lwi r11, r0, TOPHYS(PER_CPU(KM));/* See if already in kernel mode.*/
895 beqi r11, 1f; /* Jump ahead if coming from user */
896 /* Kernel-mode state save. */
897 lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP)); /* Reload kernel stack-ptr*/
899 swi r11, r1, (PT_R1-PT_SIZE); /* Save original SP. */
900 lwi r11, r0, TOPHYS(r0_ram + PTO + PT_R11); /* restore r11 */
902 addik r1, r1, -STATE_SAVE_SIZE; /* Make room on the stack. */
903 swi r3, r1, PTO + PT_R3;
904 swi r4, r1, PTO + PT_R4;
907 addi r11, r0, 1; /* Was in kernel-mode. */
908 swi r11, r1, PTO + PT_MODE;
910 nop; /* Fill delay slot */
911 1: /* User-mode state save. */
912 lwi r11, r0, TOPHYS(r0_ram + PTO + PT_R11); /* restore r11 */
913 lwi r1, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); /* get saved current */
915 lwi r1, r1, TS_THREAD_INFO; /* get the thread info */
916 addik r1, r1, THREAD_SIZE; /* calculate kernel stack pointer */
919 addik r1, r1, -STATE_SAVE_SIZE; /* Make room on the stack. */
920 swi r3, r1, PTO + PT_R3;
921 swi r4, r1, PTO + PT_R4;
924 swi r0, r1, PTO+PT_MODE; /* Was in user-mode. */
925 lwi r11, r0, TOPHYS(PER_CPU(ENTRY_SP));
926 swi r11, r1, PTO+PT_R1; /* Store user SP. */
928 swi r11, r0, TOPHYS(PER_CPU(KM)); /* Now we're in kernel-mode. */
929 2: lwi r31, r0, TOPHYS(PER_CPU(CURRENT_SAVE)); /* get saved current */
930 /* Save away the syscall number. */
931 swi r0, r1, PTO+PT_R0;
934 addi r5, r0, SIGTRAP /* send the trap signal */
935 add r6, r0, CURRENT_TASK; /* Get current task ptr into r11 */
936 addk r7, r0, r0 /* 3rd param zero */
939 la r11, r0, send_sig;
940 la r15, r0, dbtrap_call;
941 dbtrap_call: rtbd r11, 0;
944 set_bip; /* Ints masked for state restore*/
945 lwi r11, r1, PTO+PT_MODE;
948 /* Get current task ptr into r11 */
949 add r11, r0, CURRENT_TASK; /* Get current task ptr into r11 */
950 lwi r11, r11, TS_THREAD_INFO; /* get thread info */
951 lwi r11, r11, TI_FLAGS; /* get flags in thread info */
952 andi r11, r11, _TIF_NEED_RESCHED;
955 /* Call the scheduler before returning from a syscall/trap. */
957 bralid r15, schedule; /* Call scheduler */
958 nop; /* delay slot */
959 /* XXX Is PT_DTRACE handling needed here? */
960 /* XXX m68knommu also checks TASK_STATE & TASK_COUNTER here. */
962 /* Maybe handle a signal */
963 5: add r11, r0, CURRENT_TASK; /* Get current task ptr into r11 */
964 lwi r11, r11, TS_THREAD_INFO; /* get thread info */
965 lwi r11, r11, TI_FLAGS; /* get flags in thread info */
966 andi r11, r11, _TIF_SIGPENDING;
967 beqi r11, 1f; /* Signals to handle, handle them */
969 /* Handle a signal return; Pending signals should be in r18. */
970 /* Not all registers are saved by the normal trap/interrupt entry
971 points (for instance, call-saved registers (because the normal
972 C-compiler calling sequence in the kernel makes sure they're
973 preserved), and call-clobbered registers in the case of
974 traps), but signal handlers may want to examine or change the
975 complete register state. Here we save anything not saved by
976 the normal entry sequence, so that it may be safely restored
977 (in a possibly modified form) after do_signal returns. */
979 la r5, r1, PTO; /* Arg 1: struct pt_regs *regs */
980 add r6, r0, r0; /* Arg 2: sigset_t *oldset */
981 addi r7, r0, 0; /* Arg 3: int in_syscall */
982 bralid r15, do_signal; /* Handle any signals */
986 /* Finally, return to user state. */
987 1: swi r0, r0, PER_CPU(KM); /* Now officially in user state. */
988 add r11, r0, CURRENT_TASK; /* Get current task ptr into r11 */
989 swi r11, r0, PER_CPU(CURRENT_SAVE); /* save current */
993 lwi r3, r1, PTO+PT_R3; /* restore saved r3, r4 registers */
994 lwi r4, r1, PTO+PT_R4;
996 addik r1, r1, STATE_SAVE_SIZE /* Clean up stack space. */
999 lwi r1, r1, PT_R1 - PT_SIZE;
1000 /* Restore user stack pointer. */
1003 /* Return to kernel state. */
1006 lwi r3, r1, PTO+PT_R3; /* restore saved r3, r4 registers */
1007 lwi r4, r1, PTO+PT_R4;
1009 addik r1, r1, STATE_SAVE_SIZE /* Clean up stack space. */
1013 DBTRAP_return: /* Make global symbol for debugging */
1014 rtbd r14, 0; /* Instructions to return from an IRQ */
1020 /* prepare return value */
1023 /* save registers in cpu_context */
1024 /* use r11 and r12, volatile registers, as temp register */
1025 /* give start of cpu_context for previous process */
1026 addik r11, r5, TI_CPU_CONTEXT
1029 /* skip volatile registers.
1030 * they are saved on stack when we jumped to _switch_to() */
1031 /* dedicated registers */
1032 swi r13, r11, CC_R13
1033 swi r14, r11, CC_R14
1034 swi r15, r11, CC_R15
1035 swi r16, r11, CC_R16
1036 swi r17, r11, CC_R17
1037 swi r18, r11, CC_R18
1038 /* save non-volatile registers */
1039 swi r19, r11, CC_R19
1040 swi r20, r11, CC_R20
1041 swi r21, r11, CC_R21
1042 swi r22, r11, CC_R22
1043 swi r23, r11, CC_R23
1044 swi r24, r11, CC_R24
1045 swi r25, r11, CC_R25
1046 swi r26, r11, CC_R26
1047 swi r27, r11, CC_R27
1048 swi r28, r11, CC_R28
1049 swi r29, r11, CC_R29
1050 swi r30, r11, CC_R30
1051 /* special purpose registers */
1054 swi r12, r11, CC_MSR
1057 swi r12, r11, CC_EAR
1060 swi r12, r11, CC_ESR
1063 swi r12, r11, CC_FSR
1065 /* update r31, the current */
1066 lwi r31, r6, TI_TASK/* give me pointer to task which will be next */
1067 /* stored it to current_save too */
1068 swi r31, r0, PER_CPU(CURRENT_SAVE)
1070 /* get new process' cpu context and restore */
1071 /* give me start where start context of next task */
1072 addik r11, r6, TI_CPU_CONTEXT
1074 /* non-volatile registers */
1075 lwi r30, r11, CC_R30
1076 lwi r29, r11, CC_R29
1077 lwi r28, r11, CC_R28
1078 lwi r27, r11, CC_R27
1079 lwi r26, r11, CC_R26
1080 lwi r25, r11, CC_R25
1081 lwi r24, r11, CC_R24
1082 lwi r23, r11, CC_R23
1083 lwi r22, r11, CC_R22
1084 lwi r21, r11, CC_R21
1085 lwi r20, r11, CC_R20
1086 lwi r19, r11, CC_R19
1087 /* dedicated registers */
1088 lwi r18, r11, CC_R18
1089 lwi r17, r11, CC_R17
1090 lwi r16, r11, CC_R16
1091 lwi r15, r11, CC_R15
1092 lwi r14, r11, CC_R14
1093 lwi r13, r11, CC_R13
1094 /* skip volatile registers */
1098 /* special purpose registers */
1099 lwi r12, r11, CC_FSR
1102 lwi r12, r11, CC_MSR
1110 brai 0x70; /* Jump back to FS-boot */
1115 swi r5, r0, 0x250 + TOPHYS(r0_ram)
1118 swi r5, r0, 0x254 + TOPHYS(r0_ram)
1121 /* These are compiled and loaded into high memory, then
1122 * copied into place in mach_early_setup */
1123 .section .init.ivt, "ax"
1125 /* this is very important - here is the reset vector */
1126 /* in current MMU branch you don't care what is here - it is
1127 * used from bootloader site - but this is correct for FS-BOOT */
1130 brai TOPHYS(_user_exception); /* syscall handler */
1131 brai TOPHYS(_interrupt); /* Interrupt handler */
1132 brai TOPHYS(_break); /* nmi trap handler */
1133 brai TOPHYS(_hw_exception_handler); /* HW exception handler */
1136 brai TOPHYS(_debug_exception); /* debug trap handler*/
1138 .section .rodata,"a"
1139 #include "syscall_table.S"
1141 syscall_table_size=(.-sys_call_table)