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, $18 /* $18 = 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. */
323 ldl $17, TI_FLAGS($8)
324 and $17, _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 $18, 0($sp) /* old syscall nr (zero if success) */
345 beq $18, $ret_success
347 ldq $19, 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 * $18: The old syscall number, or zero if this is not a return
368 * from a syscall that errored and is possibly restartable.
369 * $19: The old a3 value
375 and $17, _TIF_NOTIFY_RESUME | _TIF_SIGPENDING, $2
376 bne $2, $work_notifysig
380 * We can get here only if we returned from syscall without SIGPENDING
381 * or got through work_notifysig already. Either case means no syscall
382 * restarts for us, so let $18 and $19 burn.
390 bsr $1, do_switch_stack
391 jsr $26, do_work_pending
392 bsr $1, undo_switch_stack
397 * PTRACE syscall handler
403 /* set up signal stack, call syscall_trace */
404 bsr $1, do_switch_stack
405 jsr $26, syscall_trace_enter /* returns the syscall number */
406 bsr $1, undo_switch_stack
408 /* get the arguments back.. */
409 ldq $16, SP_OFF+24($sp)
410 ldq $17, SP_OFF+32($sp)
411 ldq $18, SP_OFF+40($sp)
416 /* get the system call pointer.. */
417 lda $1, NR_SYSCALLS($31)
418 lda $2, sys_call_table
419 lda $27, alpha_ni_syscall
424 1: jsr $26, ($27), sys_gettimeofday
429 blt $0, $strace_error /* the call failed */
430 stq $31, 72($sp) /* a3=0 => no error */
432 stq $0, 0($sp) /* save return value */
434 bsr $1, do_switch_stack
435 jsr $26, syscall_trace_leave
436 bsr $1, undo_switch_stack
437 br $31, ret_from_sys_call
441 ldq $18, 0($sp) /* old syscall nr (zero if success) */
442 beq $18, $strace_success
443 ldq $19, 72($sp) /* .. and this a3 */
445 subq $31, $0, $0 /* with error in v0 */
446 addq $31, 1, $1 /* set a3 for errno return */
448 stq $1, 72($sp) /* a3 for return */
450 bsr $1, do_switch_stack
451 mov $18, $9 /* save old syscall number */
452 mov $19, $10 /* save old a3 */
453 jsr $26, syscall_trace_leave
456 bsr $1, undo_switch_stack
458 mov $31, $26 /* tell "ret_from_sys_call" we can restart */
463 * Save and restore the switch stack -- aka the balance of the user context.
469 lda $sp, -SWITCH_STACK_SIZE($sp)
506 mf_fpcr $f0 # get fpcr
510 stt $f0, 312($sp) # save fpcr in slot of $f31
511 ldt $f0, 64($sp) # dont let "do_switch_stack" change fp state.
516 .ent undo_switch_stack
526 ldt $f30, 312($sp) # get saved fpcr
531 mt_fpcr $f30 # install saved fpcr
559 lda $sp, SWITCH_STACK_SIZE($sp)
561 .end undo_switch_stack
564 * The meat of the context switch code.
568 .globl alpha_switch_to
572 bsr $1, do_switch_stack
575 bsr $1, undo_switch_stack
582 * New processes begin life here.
589 lda $26, ret_from_sys_call
591 jmp $31, schedule_tail
595 * ... and new kernel threads - here
598 .globl ret_from_kernel_thread
599 .ent ret_from_kernel_thread
600 ret_from_kernel_thread:
602 jsr $26, schedule_tail
606 mov $31, $19 /* to disable syscall restarts */
608 .end ret_from_kernel_thread
612 * Special system calls. Most of these are special in that they either
613 * have to play switch_stack games or in some way use the pt_regs struct.
621 bsr $1, do_switch_stack
622 bis $31, SIGCHLD, $16
628 bsr $1, undo_switch_stack
638 bsr $1, do_switch_stack
639 /* $16, $17, $18, $19, $20 come from the user. */
641 bsr $1, undo_switch_stack
651 bsr $1, do_switch_stack
653 bsr $1, undo_switch_stack
662 lda $9, ret_from_straced
665 lda $18, -SWITCH_STACK_SIZE($sp)
666 lda $sp, -SWITCH_STACK_SIZE($sp)
667 jsr $26, do_sigreturn
669 jsr $26, syscall_trace_leave
670 1: br $1, undo_switch_stack
675 .globl sys_rt_sigreturn
676 .ent sys_rt_sigreturn
679 lda $9, ret_from_straced
682 lda $18, -SWITCH_STACK_SIZE($sp)
683 lda $sp, -SWITCH_STACK_SIZE($sp)
684 jsr $26, do_rt_sigreturn
686 jsr $26, syscall_trace_leave
687 1: br $1, undo_switch_stack
689 .end sys_rt_sigreturn
692 .globl alpha_ni_syscall
693 .ent alpha_ni_syscall
696 /* Special because it also implements overflow handling via
697 syscall number 0. And if you recall, zero is a special
698 trigger for "not an error". Store large non-zero there. */
703 .end alpha_ni_syscall