2 * arch/alpha/kernel/entry.S
7 #include <asm/asm-offsets.h>
8 #include <asm/thread_info.h>
10 #include <asm/errno.h>
11 #include <asm/unistd.h>
18 #define SWITCH_STACK_SIZE 320
21 * This defines the normal kernel pt-regs layout.
23 * regs 9-15 preserved by C code
24 * regs 16-18 saved by PAL-code
25 * regs 29-30 saved and set up by PAL-code
26 * JRP - Save regs 16-18 in a special area of the stack, so that
27 * the palcode-provided values are available to the signal handler.
31 subq $sp, SP_OFF, $sp; \
46 ldq $2, HAE_CACHE($2); \
65 ldq $20, HAE_CACHE($19); \
73 ldq $20, HAE_REG($19); \
74 stq $21, HAE_CACHE($19); \
90 * Non-syscall kernel entry points.
99 lda $26, ret_from_sys_call
111 lda $26, ret_from_sys_call
122 /* save $9 - $15 so the inline exception code can manipulate them. */
132 /* handle the fault */
135 jsr $26, do_page_fault
136 /* reload the registers after the exception code played. */
145 /* finish up the syscall as normal. */
155 lda $26, ret_from_sys_call
167 ldq $0, 256($sp) /* get PS */
171 and $0, 8, $0 /* user mode? */
173 bne $0, entUnaUser /* yup -> do user-level unaligned fault */
185 /* 16-18 PAL-saved */
218 /* 16-18 PAL-saved */
237 ldq $0, 0($sp) /* restore original $0 */
238 lda $sp, 256($sp) /* pop entUna's stack frame */
239 SAVE_ALL /* setup normal kernel stack */
251 jsr $26, do_entUnaUser
269 lda $26, ret_from_sys_call
276 * The system call entry point is special. Most importantly, it looks
277 * like a function call to userspace as far as clobbered registers. We
278 * do preserve the argument registers (for syscall restarts) and $26
279 * (for leaf syscall functions).
281 * So much for theory. We don't take advantage of this yet.
283 * Note that a0-a2 are not saved by PALcode as with the other entry points.
288 .globl ret_from_sys_call
294 lda $4, NR_SYSCALLS($31)
295 stq $16, SP_OFF+24($sp)
296 lda $5, sys_call_table
297 lda $27, sys_ni_syscall
300 stq $17, SP_OFF+32($sp)
302 stq $18, SP_OFF+40($sp)
306 1: jsr $26, ($27), alpha_ni_syscall
308 blt $0, $syscall_error /* the call failed */
310 stq $31, 72($sp) /* a3=0 => no error */
314 cmovne $26, 0, $19 /* $19 = 0 => non-restartable */
317 beq $0, ret_to_kernel
319 /* Make sure need_resched and sigpending don't change between
320 sampling and the rti. */
324 and $5, _TIF_WORK_MASK, $2
338 * Some system calls (e.g., ptrace) can return arbitrary
339 * values which might normally be mistaken as error numbers.
340 * Those functions must zero $0 (v0) directly in the stack
341 * frame to indicate that a negative return value wasn't an
344 ldq $19, 0($sp) /* old syscall nr (zero if success) */
345 beq $19, $ret_success
347 ldq $20, 72($sp) /* .. and this a3 */
348 subq $31, $0, $0 /* with error in v0 */
349 addq $31, 1, $1 /* set a3 for errno return */
351 mov $31, $26 /* tell "ret_from_sys_call" we can restart */
352 stq $1, 72($sp) /* a3 for return */
357 stq $31, 72($sp) /* a3=0 => no error */
362 * Do all cleanup when returning from all interrupts and system calls.
367 * $19: The old syscall number, or zero if this is not a return
368 * from a syscall that errored and is possibly restartable.
369 * $20: The old a3 value
375 and $5, _TIF_NEED_RESCHED, $2
376 beq $2, $work_notifysig
380 stq $19, 0($sp) /* save syscall nr */
381 stq $20, 8($sp) /* and error indication (a3) */
386 /* Make sure need_resched and sigpending don't change between
387 sampling and the rti. */
391 and $5, _TIF_WORK_MASK, $2
393 and $5, _TIF_NEED_RESCHED, $2
394 bne $2, $work_resched
398 bsr $1, do_switch_stack
401 mov $19, $9 /* save old syscall number */
402 mov $20, $10 /* save old a3 */
403 and $5, _TIF_SIGPENDING, $2
404 cmovne $2, 0, $9 /* we don't want double syscall restarts */
405 jsr $26, do_notify_resume
408 bsr $1, undo_switch_stack
413 * PTRACE syscall handler
419 /* set up signal stack, call syscall_trace */
420 bsr $1, do_switch_stack
421 jsr $26, syscall_trace_enter /* returns the syscall number */
422 bsr $1, undo_switch_stack
424 /* get the arguments back.. */
425 ldq $16, SP_OFF+24($sp)
426 ldq $17, SP_OFF+32($sp)
427 ldq $18, SP_OFF+40($sp)
432 /* get the system call pointer.. */
433 lda $1, NR_SYSCALLS($31)
434 lda $2, sys_call_table
435 lda $27, alpha_ni_syscall
440 1: jsr $26, ($27), sys_gettimeofday
445 blt $0, $strace_error /* the call failed */
446 stq $31, 72($sp) /* a3=0 => no error */
448 stq $0, 0($sp) /* save return value */
450 bsr $1, do_switch_stack
451 jsr $26, syscall_trace_leave
452 bsr $1, undo_switch_stack
453 br $31, ret_from_sys_call
457 ldq $19, 0($sp) /* old syscall nr (zero if success) */
458 beq $19, $strace_success
459 ldq $20, 72($sp) /* .. and this a3 */
461 subq $31, $0, $0 /* with error in v0 */
462 addq $31, 1, $1 /* set a3 for errno return */
464 stq $1, 72($sp) /* a3 for return */
466 bsr $1, do_switch_stack
467 mov $19, $9 /* save old syscall number */
468 mov $20, $10 /* save old a3 */
469 jsr $26, syscall_trace_leave
472 bsr $1, undo_switch_stack
474 mov $31, $26 /* tell "ret_from_sys_call" we can restart */
479 * Save and restore the switch stack -- aka the balance of the user context.
485 lda $sp, -SWITCH_STACK_SIZE($sp)
522 mf_fpcr $f0 # get fpcr
526 stt $f0, 312($sp) # save fpcr in slot of $f31
527 ldt $f0, 64($sp) # dont let "do_switch_stack" change fp state.
532 .ent undo_switch_stack
542 ldt $f30, 312($sp) # get saved fpcr
547 mt_fpcr $f30 # install saved fpcr
575 lda $sp, SWITCH_STACK_SIZE($sp)
577 .end undo_switch_stack
580 * The meat of the context switch code.
584 .globl alpha_switch_to
588 bsr $1, do_switch_stack
591 bsr $1, undo_switch_stack
598 * New processes begin life here.
605 lda $26, ret_from_sys_call
607 jmp $31, schedule_tail
611 * ... and new kernel threads - here
614 .globl ret_from_kernel_thread
615 .ent ret_from_kernel_thread
616 ret_from_kernel_thread:
618 jsr $26, schedule_tail
626 .end ret_from_kernel_thread
628 .globl ret_from_kernel_execve
630 .ent ret_from_kernel_execve
631 ret_from_kernel_execve:
633 /* Avoid the HAE being gratuitously wrong, to avoid restoring it. */
634 ldq $2, alpha_mv+HAE_CACHE
635 stq $2, 152($sp) /* HAE */
636 mov $31, $19 /* to disable syscall restarts */
639 .end ret_from_kernel_execve
643 * Special system calls. Most of these are special in that they either
644 * have to play switch_stack games or in some way use the pt_regs struct.
652 bsr $1, do_switch_stack
653 bis $31, SIGCHLD, $16
659 bsr $1, undo_switch_stack
669 bsr $1, do_switch_stack
670 /* $16, $17, $18, $19, $20 come from the user. */
672 bsr $1, undo_switch_stack
682 bsr $1, do_switch_stack
684 bsr $1, undo_switch_stack
693 lda $9, ret_from_straced
696 lda $18, -SWITCH_STACK_SIZE($sp)
697 lda $sp, -SWITCH_STACK_SIZE($sp)
698 jsr $26, do_sigreturn
700 jsr $26, syscall_trace_leave
701 1: br $1, undo_switch_stack
706 .globl sys_rt_sigreturn
707 .ent sys_rt_sigreturn
710 lda $9, ret_from_straced
713 lda $18, -SWITCH_STACK_SIZE($sp)
714 lda $sp, -SWITCH_STACK_SIZE($sp)
715 jsr $26, do_rt_sigreturn
717 jsr $26, syscall_trace_leave
718 1: br $1, undo_switch_stack
720 .end sys_rt_sigreturn
723 .globl alpha_ni_syscall
724 .ent alpha_ni_syscall
727 /* Special because it also implements overflow handling via
728 syscall number 0. And if you recall, zero is a special
729 trigger for "not an error". Store large non-zero there. */
734 .end alpha_ni_syscall