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 320
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
162 /* We don't really care about the FP registers for debugging. */
165 .macro UNDO_SWITCH_STACK
166 bsr $1, undo_switch_stack
174 .cfi_adjust_cfa_offset -SWITCH_STACK_SIZE
178 * Non-syscall kernel entry points.
181 CFI_START_OSF_FRAME entInt
184 lda $26, ret_from_sys_call
188 CFI_END_OSF_FRAME entInt
190 CFI_START_OSF_FRAME entArith
193 lda $26, ret_from_sys_call
197 CFI_END_OSF_FRAME entArith
199 CFI_START_OSF_FRAME entMM
201 /* save $9 - $15 so the inline exception code can manipulate them. */
203 .cfi_adjust_cfa_offset 56
211 .cfi_rel_offset $9, 0
212 .cfi_rel_offset $10, 8
213 .cfi_rel_offset $11, 16
214 .cfi_rel_offset $12, 24
215 .cfi_rel_offset $13, 32
216 .cfi_rel_offset $14, 40
217 .cfi_rel_offset $15, 48
219 /* handle the fault */
222 jsr $26, do_page_fault
223 /* reload the registers after the exception code played. */
239 .cfi_adjust_cfa_offset -56
240 /* finish up the syscall as normal. */
242 CFI_END_OSF_FRAME entMM
244 CFI_START_OSF_FRAME entIF
247 lda $26, ret_from_sys_call
251 CFI_END_OSF_FRAME entIF
253 CFI_START_OSF_FRAME entUna
255 .cfi_adjust_cfa_offset 256
257 .cfi_rel_offset $0, 0
259 ldq $0, 256($sp) /* get PS */
263 and $0, 8, $0 /* user mode? */
265 bne $0, entUnaUser /* yup -> do user-level unaligned fault */
277 /* 16-18 PAL-saved */
290 .cfi_rel_offset $1, 1*8
291 .cfi_rel_offset $2, 2*8
292 .cfi_rel_offset $3, 3*8
293 .cfi_rel_offset $4, 4*8
294 .cfi_rel_offset $5, 5*8
295 .cfi_rel_offset $6, 6*8
296 .cfi_rel_offset $7, 7*8
297 .cfi_rel_offset $8, 8*8
298 .cfi_rel_offset $9, 9*8
299 .cfi_rel_offset $10, 10*8
300 .cfi_rel_offset $11, 11*8
301 .cfi_rel_offset $12, 12*8
302 .cfi_rel_offset $13, 13*8
303 .cfi_rel_offset $14, 14*8
304 .cfi_rel_offset $15, 15*8
305 .cfi_rel_offset $19, 19*8
306 .cfi_rel_offset $20, 20*8
307 .cfi_rel_offset $21, 21*8
308 .cfi_rel_offset $22, 22*8
309 .cfi_rel_offset $23, 23*8
310 .cfi_rel_offset $24, 24*8
311 .cfi_rel_offset $25, 25*8
312 .cfi_rel_offset $26, 26*8
313 .cfi_rel_offset $27, 27*8
314 .cfi_rel_offset $28, 28*8
315 .cfi_rel_offset $29, 29*8
336 /* 16-18 PAL-saved */
375 .cfi_adjust_cfa_offset -256
381 ldq $0, 0($sp) /* restore original $0 */
382 lda $sp, 256($sp) /* pop entUna's stack frame */
384 .cfi_adjust_cfa_offset -256
385 SAVE_ALL /* setup normal kernel stack */
387 .cfi_adjust_cfa_offset 56
395 .cfi_rel_offset $9, 0
396 .cfi_rel_offset $10, 8
397 .cfi_rel_offset $11, 16
398 .cfi_rel_offset $12, 24
399 .cfi_rel_offset $13, 32
400 .cfi_rel_offset $14, 40
401 .cfi_rel_offset $15, 48
405 jsr $26, do_entUnaUser
421 .cfi_adjust_cfa_offset -56
423 CFI_END_OSF_FRAME entUna
425 CFI_START_OSF_FRAME entDbg
428 lda $26, ret_from_sys_call
432 CFI_END_OSF_FRAME entDbg
435 * The system call entry point is special. Most importantly, it looks
436 * like a function call to userspace as far as clobbered registers. We
437 * do preserve the argument registers (for syscall restarts) and $26
438 * (for leaf syscall functions).
440 * So much for theory. We don't take advantage of this yet.
442 * Note that a0-a2 are not saved by PALcode as with the other entry points.
447 .type entSys, @function
448 .cfi_startproc simple
449 .cfi_return_column 64
451 .cfi_rel_offset 64, 8
452 .cfi_rel_offset $gp, 16
457 lda $4, NR_SYSCALLS($31)
458 stq $16, SP_OFF+24($sp)
459 lda $5, sys_call_table
460 lda $27, sys_ni_syscall
463 stq $17, SP_OFF+32($sp)
465 stq $18, SP_OFF+40($sp)
466 .cfi_rel_offset $16, SP_OFF+24
467 .cfi_rel_offset $17, SP_OFF+32
468 .cfi_rel_offset $18, SP_OFF+40
469 #ifdef CONFIG_AUDITSYSCALL
470 lda $6, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
474 blbs $3, strace /* check for SYSCALL_TRACE in disguise */
478 1: jsr $26, ($27), sys_ni_syscall
480 blt $0, $syscall_error /* the call failed */
483 stq $31, 72($sp) /* a3=0 => no error */
486 .globl ret_from_sys_call
488 cmovne $26, 0, $18 /* $18 = 0 => non-restartable */
491 beq $0, ret_to_kernel
493 /* Make sure need_resched and sigpending don't change between
494 sampling and the rti. */
497 ldl $17, TI_FLAGS($8)
498 and $17, _TIF_WORK_MASK, $2
514 * Some system calls (e.g., ptrace) can return arbitrary
515 * values which might normally be mistaken as error numbers.
516 * Those functions must zero $0 (v0) directly in the stack
517 * frame to indicate that a negative return value wasn't an
520 ldq $18, 0($sp) /* old syscall nr (zero if success) */
521 beq $18, $ret_success
523 ldq $19, 72($sp) /* .. and this a3 */
524 subq $31, $0, $0 /* with error in v0 */
525 addq $31, 1, $1 /* set a3 for errno return */
527 mov $31, $26 /* tell "ret_from_sys_call" we can restart */
528 stq $1, 72($sp) /* a3 for return */
532 * Do all cleanup when returning from all interrupts and system calls.
537 * $18: The old syscall number, or zero if this is not a return
538 * from a syscall that errored and is possibly restartable.
539 * $19: The old a3 value
543 .type work_pending, @function
545 and $17, _TIF_NOTIFY_RESUME | _TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL, $2
546 bne $2, $work_notifysig
550 * We can get here only if we returned from syscall without SIGPENDING
551 * or got through work_notifysig already. Either case means no syscall
552 * restarts for us, so let $18 and $19 burn.
561 jsr $26, do_work_pending
566 * PTRACE syscall handler
570 .type strace, @function
572 /* set up signal stack, call syscall_trace */
574 jsr $26, syscall_trace_enter /* returns the syscall number */
577 /* get the arguments back.. */
578 ldq $16, SP_OFF+24($sp)
579 ldq $17, SP_OFF+32($sp)
580 ldq $18, SP_OFF+40($sp)
585 /* get the system call pointer.. */
586 lda $1, NR_SYSCALLS($31)
587 lda $2, sys_call_table
588 lda $27, sys_ni_syscall
593 1: jsr $26, ($27), sys_gettimeofday
598 blt $0, $strace_error /* the call failed */
600 stq $31, 72($sp) /* a3=0 => no error */
601 stq $0, 0($sp) /* save return value */
604 jsr $26, syscall_trace_leave
606 br $31, ret_from_sys_call
610 ldq $18, 0($sp) /* old syscall nr (zero if success) */
611 beq $18, $strace_success
612 ldq $19, 72($sp) /* .. and this a3 */
614 subq $31, $0, $0 /* with error in v0 */
615 addq $31, 1, $1 /* set a3 for errno return */
617 stq $1, 72($sp) /* a3 for return */
620 mov $18, $9 /* save old syscall number */
621 mov $19, $10 /* save old a3 */
622 jsr $26, syscall_trace_leave
627 mov $31, $26 /* tell "ret_from_sys_call" we can restart */
629 CFI_END_OSF_FRAME entSys
632 * Save and restore the switch stack -- aka the balance of the user context.
636 .type do_switch_stack, @function
637 .cfi_startproc simple
638 .cfi_return_column 64
642 lda $sp, -SWITCH_STACK_SIZE($sp)
643 .cfi_adjust_cfa_offset SWITCH_STACK_SIZE
680 mf_fpcr $f0 # get fpcr
684 stt $f0, 312($sp) # save fpcr in slot of $f31
685 ldt $f0, 64($sp) # dont let "do_switch_stack" change fp state.
688 .size do_switch_stack, .-do_switch_stack
691 .type undo_switch_stack, @function
692 .cfi_startproc simple
704 ldt $f30, 312($sp) # get saved fpcr
709 mt_fpcr $f30 # install saved fpcr
737 lda $sp, SWITCH_STACK_SIZE($sp)
740 .size undo_switch_stack, .-undo_switch_stack
743 * The meat of the context switch code.
747 .globl alpha_switch_to
748 .type alpha_switch_to, @function
759 .size alpha_switch_to, .-alpha_switch_to
762 * New processes begin life here.
771 jmp $31, schedule_tail
775 * ... and new kernel threads - here
778 .globl ret_from_kernel_thread
779 .ent ret_from_kernel_thread
780 ret_from_kernel_thread:
782 jsr $26, schedule_tail
787 .end ret_from_kernel_thread
791 * Special system calls. Most of these are special in that they either
792 * have to play switch_stack games.
795 .macro fork_like name
801 bsr $1, do_switch_stack
804 lda $sp, SWITCH_STACK_SIZE($sp)
813 .macro sigreturn_like name
819 lda $9, ret_from_straced
821 lda $sp, -SWITCH_STACK_SIZE($sp)
824 jsr $26, syscall_trace_leave
825 1: br $1, undo_switch_stack
830 sigreturn_like sigreturn
831 sigreturn_like rt_sigreturn
834 .globl alpha_syscall_zero
835 .ent alpha_syscall_zero
838 /* Special because it needs to do something opposite to
839 force_successful_syscall_return(). We use the saved
840 syscall number for that, zero meaning "not an error".
841 That works nicely, but for real syscall 0 we need to
842 make sure that this logics doesn't get confused.
843 Store a non-zero there - -ENOSYS we need in register
844 for our return value will do just fine.
850 .end alpha_syscall_zero