1 /* SPDX-License-Identifier: GPL-2.0 */
3 * arch/alpha/kernel/entry.S
8 #include <asm/asm-offsets.h>
9 #include <asm/thread_info.h>
11 #include <asm/errno.h>
12 #include <asm/unistd.h>
16 .cfi_sections .debug_frame
20 #define SWITCH_STACK_SIZE 64
22 .macro CFI_START_OSF_FRAME func
31 .cfi_rel_offset $gp, 16
32 .cfi_rel_offset $16, 24
33 .cfi_rel_offset $17, 32
34 .cfi_rel_offset $18, 40
37 .macro CFI_END_OSF_FRAME func
39 .size \func, . - \func
43 * This defines the normal kernel pt-regs layout.
45 * regs 9-15 preserved by C code
46 * regs 16-18 saved by PAL-code
47 * regs 29-30 saved and set up by PAL-code
48 * JRP - Save regs 16-18 in a special area of the stack, so that
49 * the palcode-provided values are available to the signal handler.
54 .cfi_adjust_cfa_offset SP_OFF
63 .cfi_rel_offset $2, 16
64 .cfi_rel_offset $3, 24
65 .cfi_rel_offset $4, 32
66 .cfi_rel_offset $28, 144
86 .cfi_rel_offset $5, 40
87 .cfi_rel_offset $6, 48
88 .cfi_rel_offset $7, 56
89 .cfi_rel_offset $8, 64
90 .cfi_rel_offset $19, 72
91 .cfi_rel_offset $20, 80
92 .cfi_rel_offset $21, 88
93 .cfi_rel_offset $22, 96
94 .cfi_rel_offset $23, 104
95 .cfi_rel_offset $24, 112
96 .cfi_rel_offset $25, 120
97 .cfi_rel_offset $26, 128
98 .cfi_rel_offset $27, 136
108 ldq $20, HAE_CACHE($19)
116 ldq $20, HAE_REG($19)
117 stq $21, HAE_CACHE($19)
129 addq $sp, SP_OFF, $sp
149 .cfi_adjust_cfa_offset -SP_OFF
152 .macro DO_SWITCH_STACK
153 bsr $1, do_switch_stack
154 .cfi_adjust_cfa_offset SWITCH_STACK_SIZE
155 .cfi_rel_offset $9, 0
156 .cfi_rel_offset $10, 8
157 .cfi_rel_offset $11, 16
158 .cfi_rel_offset $12, 24
159 .cfi_rel_offset $13, 32
160 .cfi_rel_offset $14, 40
161 .cfi_rel_offset $15, 48
164 .macro UNDO_SWITCH_STACK
165 bsr $1, undo_switch_stack
173 .cfi_adjust_cfa_offset -SWITCH_STACK_SIZE
177 * Non-syscall kernel entry points.
180 CFI_START_OSF_FRAME entInt
183 lda $26, ret_from_sys_call
187 CFI_END_OSF_FRAME entInt
189 CFI_START_OSF_FRAME entArith
192 lda $26, ret_from_sys_call
196 CFI_END_OSF_FRAME entArith
198 CFI_START_OSF_FRAME entMM
200 /* save $9 - $15 so the inline exception code can manipulate them. */
202 .cfi_adjust_cfa_offset 56
210 .cfi_rel_offset $9, 0
211 .cfi_rel_offset $10, 8
212 .cfi_rel_offset $11, 16
213 .cfi_rel_offset $12, 24
214 .cfi_rel_offset $13, 32
215 .cfi_rel_offset $14, 40
216 .cfi_rel_offset $15, 48
218 /* handle the fault */
221 jsr $26, do_page_fault
222 /* reload the registers after the exception code played. */
238 .cfi_adjust_cfa_offset -56
239 /* finish up the syscall as normal. */
241 CFI_END_OSF_FRAME entMM
243 CFI_START_OSF_FRAME entIF
246 lda $26, ret_from_sys_call
250 CFI_END_OSF_FRAME entIF
252 CFI_START_OSF_FRAME entUna
254 .cfi_adjust_cfa_offset 256
256 .cfi_rel_offset $0, 0
258 ldq $0, 256($sp) /* get PS */
262 and $0, 8, $0 /* user mode? */
264 bne $0, entUnaUser /* yup -> do user-level unaligned fault */
276 /* 16-18 PAL-saved */
289 .cfi_rel_offset $1, 1*8
290 .cfi_rel_offset $2, 2*8
291 .cfi_rel_offset $3, 3*8
292 .cfi_rel_offset $4, 4*8
293 .cfi_rel_offset $5, 5*8
294 .cfi_rel_offset $6, 6*8
295 .cfi_rel_offset $7, 7*8
296 .cfi_rel_offset $8, 8*8
297 .cfi_rel_offset $9, 9*8
298 .cfi_rel_offset $10, 10*8
299 .cfi_rel_offset $11, 11*8
300 .cfi_rel_offset $12, 12*8
301 .cfi_rel_offset $13, 13*8
302 .cfi_rel_offset $14, 14*8
303 .cfi_rel_offset $15, 15*8
304 .cfi_rel_offset $19, 19*8
305 .cfi_rel_offset $20, 20*8
306 .cfi_rel_offset $21, 21*8
307 .cfi_rel_offset $22, 22*8
308 .cfi_rel_offset $23, 23*8
309 .cfi_rel_offset $24, 24*8
310 .cfi_rel_offset $25, 25*8
311 .cfi_rel_offset $26, 26*8
312 .cfi_rel_offset $27, 27*8
313 .cfi_rel_offset $28, 28*8
314 .cfi_rel_offset $29, 29*8
335 /* 16-18 PAL-saved */
374 .cfi_adjust_cfa_offset -256
380 ldq $0, 0($sp) /* restore original $0 */
381 lda $sp, 256($sp) /* pop entUna's stack frame */
383 .cfi_adjust_cfa_offset -256
384 SAVE_ALL /* setup normal kernel stack */
386 .cfi_adjust_cfa_offset 56
394 .cfi_rel_offset $9, 0
395 .cfi_rel_offset $10, 8
396 .cfi_rel_offset $11, 16
397 .cfi_rel_offset $12, 24
398 .cfi_rel_offset $13, 32
399 .cfi_rel_offset $14, 40
400 .cfi_rel_offset $15, 48
404 jsr $26, do_entUnaUser
420 .cfi_adjust_cfa_offset -56
422 CFI_END_OSF_FRAME entUna
424 CFI_START_OSF_FRAME entDbg
427 lda $26, ret_from_sys_call
431 CFI_END_OSF_FRAME entDbg
434 * The system call entry point is special. Most importantly, it looks
435 * like a function call to userspace as far as clobbered registers. We
436 * do preserve the argument registers (for syscall restarts) and $26
437 * (for leaf syscall functions).
439 * So much for theory. We don't take advantage of this yet.
441 * Note that a0-a2 are not saved by PALcode as with the other entry points.
446 .type entSys, @function
447 .cfi_startproc simple
448 .cfi_return_column 64
450 .cfi_rel_offset 64, 8
451 .cfi_rel_offset $gp, 16
456 lda $4, NR_syscalls($31)
457 stq $16, SP_OFF+24($sp)
458 lda $5, sys_call_table
459 lda $27, sys_ni_syscall
462 stq $17, SP_OFF+32($sp)
464 stq $18, SP_OFF+40($sp)
465 .cfi_rel_offset $16, SP_OFF+24
466 .cfi_rel_offset $17, SP_OFF+32
467 .cfi_rel_offset $18, SP_OFF+40
468 #ifdef CONFIG_AUDITSYSCALL
469 lda $6, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
473 blbs $3, strace /* check for SYSCALL_TRACE in disguise */
477 1: jsr $26, ($27), sys_ni_syscall
479 blt $0, $syscall_error /* the call failed */
482 stq $31, 72($sp) /* a3=0 => no error */
485 .globl ret_from_sys_call
487 cmovne $26, 0, $18 /* $18 = 0 => non-restartable */
490 beq $0, ret_to_kernel
492 /* Make sure need_resched and sigpending don't change between
493 sampling and the rti. */
496 ldl $17, TI_FLAGS($8)
497 and $17, _TIF_WORK_MASK, $2
500 ldl $2, TI_STATUS($8)
501 and $2, TS_SAVED_FP | TS_RESTORE_FP, $3
517 * Some system calls (e.g., ptrace) can return arbitrary
518 * values which might normally be mistaken as error numbers.
519 * Those functions must zero $0 (v0) directly in the stack
520 * frame to indicate that a negative return value wasn't an
523 ldq $18, 0($sp) /* old syscall nr (zero if success) */
524 beq $18, $ret_success
526 ldq $19, 72($sp) /* .. and this a3 */
527 subq $31, $0, $0 /* with error in v0 */
528 addq $31, 1, $1 /* set a3 for errno return */
530 mov $31, $26 /* tell "ret_from_sys_call" we can restart */
531 stq $1, 72($sp) /* a3 for return */
535 * Do all cleanup when returning from all interrupts and system calls.
540 * $18: The old syscall number, or zero if this is not a return
541 * from a syscall that errored and is possibly restartable.
542 * $19: The old a3 value
546 .type work_pending, @function
548 and $17, _TIF_NOTIFY_RESUME | _TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL, $2
549 bne $2, $work_notifysig
553 * We can get here only if we returned from syscall without SIGPENDING
554 * or got through work_notifysig already. Either case means no syscall
555 * restarts for us, so let $18 and $19 burn.
564 jsr $26, do_work_pending
569 * PTRACE syscall handler
573 .type strace, @function
575 /* set up signal stack, call syscall_trace */
576 // NB: if anyone adds preemption, this block will need to be protected
577 ldl $1, TI_STATUS($8)
578 and $1, TS_SAVED_FP, $3
579 or $1, TS_SAVED_FP, $2
581 stl $2, TI_STATUS($8)
585 jsr $26, syscall_trace_enter /* returns the syscall number */
588 /* get the arguments back.. */
589 ldq $16, SP_OFF+24($sp)
590 ldq $17, SP_OFF+32($sp)
591 ldq $18, SP_OFF+40($sp)
596 /* get the system call pointer.. */
597 lda $1, NR_syscalls($31)
598 lda $2, sys_call_table
599 lda $27, sys_ni_syscall
604 1: jsr $26, ($27), sys_gettimeofday
609 blt $0, $strace_error /* the call failed */
611 stq $31, 72($sp) /* a3=0 => no error */
612 stq $0, 0($sp) /* save return value */
615 jsr $26, syscall_trace_leave
617 br $31, ret_from_sys_call
621 ldq $18, 0($sp) /* old syscall nr (zero if success) */
622 beq $18, $strace_success
623 ldq $19, 72($sp) /* .. and this a3 */
625 subq $31, $0, $0 /* with error in v0 */
626 addq $31, 1, $1 /* set a3 for errno return */
628 stq $1, 72($sp) /* a3 for return */
631 mov $18, $9 /* save old syscall number */
632 mov $19, $10 /* save old a3 */
633 jsr $26, syscall_trace_leave
638 mov $31, $26 /* tell "ret_from_sys_call" we can restart */
640 CFI_END_OSF_FRAME entSys
643 * Save and restore the switch stack -- aka the balance of the user context.
647 .type do_switch_stack, @function
648 .cfi_startproc simple
649 .cfi_return_column 64
653 lda $sp, -SWITCH_STACK_SIZE($sp)
654 .cfi_adjust_cfa_offset SWITCH_STACK_SIZE
665 .size do_switch_stack, .-do_switch_stack
668 .type undo_switch_stack, @function
669 .cfi_startproc simple
681 lda $sp, SWITCH_STACK_SIZE($sp)
684 .size undo_switch_stack, .-undo_switch_stack
686 #define FR(n) n * 8 + TI_FP($8)
689 .type __save_fpu, @function
691 #define V(n) stt $f##n, FR(n)
692 V( 0); V( 1); V( 2); V( 3)
693 V( 4); V( 5); V( 6); V( 7)
694 V( 8); V( 9); V(10); V(11)
695 V(12); V(13); V(14); V(15)
696 V(16); V(17); V(18); V(19)
697 V(20); V(21); V(22); V(23)
698 V(24); V(25); V(26); V(27)
699 mf_fpcr $f0 # get fpcr
701 stt $f0, FR(31) # save fpcr in slot of $f31
702 ldt $f0, FR(0) # don't let "__save_fpu" change fp state.
705 .size __save_fpu, .-__save_fpu
709 and $3, TS_RESTORE_FP, $3
710 bic $2, TS_SAVED_FP | TS_RESTORE_FP, $2
712 #define V(n) ldt $f##n, FR(n)
713 ldt $f30, FR(31) # get saved fpcr
714 V( 0); V( 1); V( 2); V( 3)
715 mt_fpcr $f30 # install saved fpcr
716 V( 4); V( 5); V( 6); V( 7)
717 V( 8); V( 9); V(10); V(11)
718 V(12); V(13); V(14); V(15)
719 V(16); V(17); V(18); V(19)
720 V(20); V(21); V(22); V(23)
721 V(24); V(25); V(26); V(27)
723 1: stl $2, TI_STATUS($8)
729 * The meat of the context switch code.
732 .globl alpha_switch_to
733 .type alpha_switch_to, @function
737 ldl $1, TI_STATUS($8)
738 and $1, TS_RESTORE_FP, $3
740 or $1, TS_RESTORE_FP | TS_SAVED_FP, $2
741 and $1, TS_SAVED_FP, $3
742 stl $2, TI_STATUS($8)
753 .size alpha_switch_to, .-alpha_switch_to
756 * New processes begin life here.
765 jmp $31, schedule_tail
769 * ... and new kernel threads - here
772 .globl ret_from_kernel_thread
773 .ent ret_from_kernel_thread
774 ret_from_kernel_thread:
776 jsr $26, schedule_tail
781 .end ret_from_kernel_thread
785 * Special system calls. Most of these are special in that they either
786 * have to play switch_stack games.
789 .macro fork_like name
795 bsr $1, do_switch_stack
796 // NB: if anyone adds preemption, this block will need to be protected
797 ldl $1, TI_STATUS($8)
798 and $1, TS_SAVED_FP, $3
799 or $1, TS_SAVED_FP, $2
801 stl $2, TI_STATUS($8)
806 lda $sp, SWITCH_STACK_SIZE($sp)
815 .macro sigreturn_like name
821 lda $9, ret_from_straced
823 lda $sp, -SWITCH_STACK_SIZE($sp)
826 jsr $26, syscall_trace_leave
827 1: br $1, undo_switch_stack
832 sigreturn_like sigreturn
833 sigreturn_like rt_sigreturn
836 .globl alpha_syscall_zero
837 .ent alpha_syscall_zero
840 /* Special because it needs to do something opposite to
841 force_successful_syscall_return(). We use the saved
842 syscall number for that, zero meaning "not an error".
843 That works nicely, but for real syscall 0 we need to
844 make sure that this logics doesn't get confused.
845 Store a non-zero there - -ENOSYS we need in register
846 for our return value will do just fine.
852 .end alpha_syscall_zero