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
476 1: jsr $26, ($27), sys_ni_syscall
478 blt $0, $syscall_error /* the call failed */
480 stq $31, 72($sp) /* a3=0 => no error */
483 .globl ret_from_sys_call
485 cmovne $26, 0, $18 /* $18 = 0 => non-restartable */
488 beq $0, ret_to_kernel
490 /* Make sure need_resched and sigpending don't change between
491 sampling and the rti. */
494 ldl $17, TI_FLAGS($8)
495 and $17, _TIF_WORK_MASK, $2
511 * Some system calls (e.g., ptrace) can return arbitrary
512 * values which might normally be mistaken as error numbers.
513 * Those functions must zero $0 (v0) directly in the stack
514 * frame to indicate that a negative return value wasn't an
517 ldq $18, 0($sp) /* old syscall nr (zero if success) */
518 beq $18, $ret_success
520 ldq $19, 72($sp) /* .. and this a3 */
521 subq $31, $0, $0 /* with error in v0 */
522 addq $31, 1, $1 /* set a3 for errno return */
524 mov $31, $26 /* tell "ret_from_sys_call" we can restart */
525 stq $1, 72($sp) /* a3 for return */
530 stq $31, 72($sp) /* a3=0 => no error */
534 * Do all cleanup when returning from all interrupts and system calls.
539 * $18: The old syscall number, or zero if this is not a return
540 * from a syscall that errored and is possibly restartable.
541 * $19: The old a3 value
545 .type work_pending, @function
547 and $17, _TIF_NOTIFY_RESUME | _TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL, $2
548 bne $2, $work_notifysig
552 * We can get here only if we returned from syscall without SIGPENDING
553 * or got through work_notifysig already. Either case means no syscall
554 * restarts for us, so let $18 and $19 burn.
563 jsr $26, do_work_pending
568 * PTRACE syscall handler
572 .type strace, @function
574 /* set up signal stack, call syscall_trace */
576 jsr $26, syscall_trace_enter /* returns the syscall number */
579 /* get the arguments back.. */
580 ldq $16, SP_OFF+24($sp)
581 ldq $17, SP_OFF+32($sp)
582 ldq $18, SP_OFF+40($sp)
587 /* get the system call pointer.. */
588 lda $1, NR_SYSCALLS($31)
589 lda $2, sys_call_table
590 lda $27, sys_ni_syscall
595 1: jsr $26, ($27), sys_gettimeofday
600 blt $0, $strace_error /* the call failed */
601 stq $31, 72($sp) /* a3=0 => no error */
603 stq $0, 0($sp) /* save return value */
606 jsr $26, syscall_trace_leave
608 br $31, ret_from_sys_call
612 ldq $18, 0($sp) /* old syscall nr (zero if success) */
613 beq $18, $strace_success
614 ldq $19, 72($sp) /* .. and this a3 */
616 subq $31, $0, $0 /* with error in v0 */
617 addq $31, 1, $1 /* set a3 for errno return */
619 stq $1, 72($sp) /* a3 for return */
622 mov $18, $9 /* save old syscall number */
623 mov $19, $10 /* save old a3 */
624 jsr $26, syscall_trace_leave
629 mov $31, $26 /* tell "ret_from_sys_call" we can restart */
631 CFI_END_OSF_FRAME entSys
634 * Save and restore the switch stack -- aka the balance of the user context.
638 .type do_switch_stack, @function
639 .cfi_startproc simple
640 .cfi_return_column 64
644 lda $sp, -SWITCH_STACK_SIZE($sp)
645 .cfi_adjust_cfa_offset SWITCH_STACK_SIZE
682 mf_fpcr $f0 # get fpcr
686 stt $f0, 312($sp) # save fpcr in slot of $f31
687 ldt $f0, 64($sp) # dont let "do_switch_stack" change fp state.
690 .size do_switch_stack, .-do_switch_stack
693 .type undo_switch_stack, @function
694 .cfi_startproc simple
706 ldt $f30, 312($sp) # get saved fpcr
711 mt_fpcr $f30 # install saved fpcr
739 lda $sp, SWITCH_STACK_SIZE($sp)
742 .size undo_switch_stack, .-undo_switch_stack
745 * The meat of the context switch code.
749 .globl alpha_switch_to
750 .type alpha_switch_to, @function
761 .size alpha_switch_to, .-alpha_switch_to
764 * New processes begin life here.
771 lda $26, ret_from_sys_call
773 jmp $31, schedule_tail
777 * ... and new kernel threads - here
780 .globl ret_from_kernel_thread
781 .ent ret_from_kernel_thread
782 ret_from_kernel_thread:
784 jsr $26, schedule_tail
789 .end ret_from_kernel_thread
793 * Special system calls. Most of these are special in that they either
794 * have to play switch_stack games.
797 .macro fork_like name
803 bsr $1, do_switch_stack
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