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
18 .macro CFI_START_OSF_FRAME func
27 .cfi_rel_offset $gp, 16
28 .cfi_rel_offset $16, 24
29 .cfi_rel_offset $17, 32
30 .cfi_rel_offset $18, 40
33 .macro CFI_END_OSF_FRAME func
35 .size \func, . - \func
39 * This defines the normal kernel pt-regs layout.
41 * regs 9-15 preserved by C code
42 * regs 16-18 saved by PAL-code
43 * regs 29-30 saved and set up by PAL-code
44 * JRP - Save regs 16-18 in a special area of the stack, so that
45 * the palcode-provided values are available to the signal handler.
50 .cfi_adjust_cfa_offset SP_OFF
59 .cfi_rel_offset $2, 16
60 .cfi_rel_offset $3, 24
61 .cfi_rel_offset $4, 32
62 .cfi_rel_offset $28, 144
82 .cfi_rel_offset $5, 40
83 .cfi_rel_offset $6, 48
84 .cfi_rel_offset $7, 56
85 .cfi_rel_offset $8, 64
86 .cfi_rel_offset $19, 72
87 .cfi_rel_offset $20, 80
88 .cfi_rel_offset $21, 88
89 .cfi_rel_offset $22, 96
90 .cfi_rel_offset $23, 104
91 .cfi_rel_offset $24, 112
92 .cfi_rel_offset $25, 120
93 .cfi_rel_offset $26, 128
94 .cfi_rel_offset $27, 136
104 ldq $20, HAE_CACHE($19)
112 ldq $20, HAE_REG($19)
113 stq $21, HAE_CACHE($19)
125 addq $sp, SP_OFF, $sp
145 .cfi_adjust_cfa_offset -SP_OFF
148 .macro DO_SWITCH_STACK
149 bsr $1, do_switch_stack
150 .cfi_adjust_cfa_offset SWITCH_STACK_SIZE
151 .cfi_rel_offset $9, 0
152 .cfi_rel_offset $10, 8
153 .cfi_rel_offset $11, 16
154 .cfi_rel_offset $12, 24
155 .cfi_rel_offset $13, 32
156 .cfi_rel_offset $14, 40
157 .cfi_rel_offset $15, 48
160 .macro UNDO_SWITCH_STACK
161 bsr $1, undo_switch_stack
169 .cfi_adjust_cfa_offset -SWITCH_STACK_SIZE
173 * Non-syscall kernel entry points.
176 CFI_START_OSF_FRAME entInt
179 lda $26, ret_from_sys_call
183 CFI_END_OSF_FRAME entInt
185 CFI_START_OSF_FRAME entArith
188 lda $26, ret_from_sys_call
192 CFI_END_OSF_FRAME entArith
194 CFI_START_OSF_FRAME entMM
196 /* save $9 - $15 so the inline exception code can manipulate them. */
198 .cfi_adjust_cfa_offset 64
206 .cfi_rel_offset $9, 0
207 .cfi_rel_offset $10, 8
208 .cfi_rel_offset $11, 16
209 .cfi_rel_offset $12, 24
210 .cfi_rel_offset $13, 32
211 .cfi_rel_offset $14, 40
212 .cfi_rel_offset $15, 48
214 /* handle the fault */
217 jsr $26, do_page_fault
218 /* reload the registers after the exception code played. */
234 .cfi_adjust_cfa_offset -64
235 /* finish up the syscall as normal. */
237 CFI_END_OSF_FRAME entMM
239 CFI_START_OSF_FRAME entIF
242 lda $26, ret_from_sys_call
246 CFI_END_OSF_FRAME entIF
248 CFI_START_OSF_FRAME entUna
250 .cfi_adjust_cfa_offset 256
252 .cfi_rel_offset $0, 0
254 ldq $0, 256($sp) /* get PS */
258 and $0, 8, $0 /* user mode? */
260 bne $0, entUnaUser /* yup -> do user-level unaligned fault */
272 /* 16-18 PAL-saved */
285 .cfi_rel_offset $1, 1*8
286 .cfi_rel_offset $2, 2*8
287 .cfi_rel_offset $3, 3*8
288 .cfi_rel_offset $4, 4*8
289 .cfi_rel_offset $5, 5*8
290 .cfi_rel_offset $6, 6*8
291 .cfi_rel_offset $7, 7*8
292 .cfi_rel_offset $8, 8*8
293 .cfi_rel_offset $9, 9*8
294 .cfi_rel_offset $10, 10*8
295 .cfi_rel_offset $11, 11*8
296 .cfi_rel_offset $12, 12*8
297 .cfi_rel_offset $13, 13*8
298 .cfi_rel_offset $14, 14*8
299 .cfi_rel_offset $15, 15*8
300 .cfi_rel_offset $19, 19*8
301 .cfi_rel_offset $20, 20*8
302 .cfi_rel_offset $21, 21*8
303 .cfi_rel_offset $22, 22*8
304 .cfi_rel_offset $23, 23*8
305 .cfi_rel_offset $24, 24*8
306 .cfi_rel_offset $25, 25*8
307 .cfi_rel_offset $26, 26*8
308 .cfi_rel_offset $27, 27*8
309 .cfi_rel_offset $28, 28*8
310 .cfi_rel_offset $29, 29*8
331 /* 16-18 PAL-saved */
370 .cfi_adjust_cfa_offset -256
376 ldq $0, 0($sp) /* restore original $0 */
377 lda $sp, 256($sp) /* pop entUna's stack frame */
379 .cfi_adjust_cfa_offset -256
380 SAVE_ALL /* setup normal kernel stack */
382 .cfi_adjust_cfa_offset 64
390 .cfi_rel_offset $9, 0
391 .cfi_rel_offset $10, 8
392 .cfi_rel_offset $11, 16
393 .cfi_rel_offset $12, 24
394 .cfi_rel_offset $13, 32
395 .cfi_rel_offset $14, 40
396 .cfi_rel_offset $15, 48
400 jsr $26, do_entUnaUser
416 .cfi_adjust_cfa_offset -64
418 CFI_END_OSF_FRAME entUna
420 CFI_START_OSF_FRAME entDbg
423 lda $26, ret_from_sys_call
427 CFI_END_OSF_FRAME entDbg
430 * The system call entry point is special. Most importantly, it looks
431 * like a function call to userspace as far as clobbered registers. We
432 * do preserve the argument registers (for syscall restarts) and $26
433 * (for leaf syscall functions).
435 * So much for theory. We don't take advantage of this yet.
437 * Note that a0-a2 are not saved by PALcode as with the other entry points.
442 .type entSys, @function
443 .cfi_startproc simple
444 .cfi_return_column 64
446 .cfi_rel_offset 64, 8
447 .cfi_rel_offset $gp, 16
452 lda $4, NR_syscalls($31)
453 stq $16, SP_OFF+24($sp)
454 lda $5, sys_call_table
455 lda $27, sys_ni_syscall
458 stq $17, SP_OFF+32($sp)
460 stq $18, SP_OFF+40($sp)
461 .cfi_rel_offset $16, SP_OFF+24
462 .cfi_rel_offset $17, SP_OFF+32
463 .cfi_rel_offset $18, SP_OFF+40
464 #ifdef CONFIG_AUDITSYSCALL
465 lda $6, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
469 blbs $3, strace /* check for SYSCALL_TRACE in disguise */
473 1: jsr $26, ($27), sys_ni_syscall
475 blt $0, $syscall_error /* the call failed */
478 stq $31, 72($sp) /* a3=0 => no error */
481 .globl ret_from_sys_call
483 cmovne $26, 0, $18 /* $18 = 0 => non-restartable */
486 beq $0, ret_to_kernel
488 /* Make sure need_resched and sigpending don't change between
489 sampling and the rti. */
492 ldl $17, TI_FLAGS($8)
493 and $17, _TIF_WORK_MASK, $2
496 ldl $2, TI_STATUS($8)
497 and $2, TS_SAVED_FP | TS_RESTORE_FP, $3
513 * Some system calls (e.g., ptrace) can return arbitrary
514 * values which might normally be mistaken as error numbers.
515 * Those functions must zero $0 (v0) directly in the stack
516 * frame to indicate that a negative return value wasn't an
519 ldq $18, 0($sp) /* old syscall nr (zero if success) */
520 beq $18, $ret_success
522 ldq $19, 72($sp) /* .. and this a3 */
523 subq $31, $0, $0 /* with error in v0 */
524 addq $31, 1, $1 /* set a3 for errno return */
526 mov $31, $26 /* tell "ret_from_sys_call" we can restart */
527 stq $1, 72($sp) /* a3 for return */
531 * Do all cleanup when returning from all interrupts and system calls.
536 * $18: The old syscall number, or zero if this is not a return
537 * from a syscall that errored and is possibly restartable.
538 * $19: The old a3 value
542 .type work_pending, @function
544 and $17, _TIF_NOTIFY_RESUME | _TIF_SIGPENDING | _TIF_NOTIFY_SIGNAL, $2
545 bne $2, $work_notifysig
549 * We can get here only if we returned from syscall without SIGPENDING
550 * or got through work_notifysig already. Either case means no syscall
551 * restarts for us, so let $18 and $19 burn.
560 jsr $26, do_work_pending
565 * PTRACE syscall handler
569 .type strace, @function
571 /* set up signal stack, call syscall_trace */
572 // NB: if anyone adds preemption, this block will need to be protected
573 ldl $1, TI_STATUS($8)
574 and $1, TS_SAVED_FP, $3
575 or $1, TS_SAVED_FP, $2
577 stl $2, TI_STATUS($8)
581 jsr $26, syscall_trace_enter /* returns the syscall number */
584 /* get the arguments back.. */
585 ldq $16, SP_OFF+24($sp)
586 ldq $17, SP_OFF+32($sp)
587 ldq $18, SP_OFF+40($sp)
592 /* get the system call pointer.. */
593 lda $1, NR_syscalls($31)
594 lda $2, sys_call_table
595 lda $27, sys_ni_syscall
600 1: jsr $26, ($27), sys_gettimeofday
605 blt $0, $strace_error /* the call failed */
607 stq $31, 72($sp) /* a3=0 => no error */
608 stq $0, 0($sp) /* save return value */
611 jsr $26, syscall_trace_leave
613 br $31, ret_from_sys_call
617 ldq $18, 0($sp) /* old syscall nr (zero if success) */
618 beq $18, $strace_success
619 ldq $19, 72($sp) /* .. and this a3 */
621 subq $31, $0, $0 /* with error in v0 */
622 addq $31, 1, $1 /* set a3 for errno return */
624 stq $1, 72($sp) /* a3 for return */
627 mov $18, $9 /* save old syscall number */
628 mov $19, $10 /* save old a3 */
629 jsr $26, syscall_trace_leave
634 mov $31, $26 /* tell "ret_from_sys_call" we can restart */
636 CFI_END_OSF_FRAME entSys
639 * Save and restore the switch stack -- aka the balance of the user context.
643 .type do_switch_stack, @function
644 .cfi_startproc simple
645 .cfi_return_column 64
649 lda $sp, -SWITCH_STACK_SIZE($sp)
650 .cfi_adjust_cfa_offset SWITCH_STACK_SIZE
661 .size do_switch_stack, .-do_switch_stack
664 .type undo_switch_stack, @function
665 .cfi_startproc simple
677 lda $sp, SWITCH_STACK_SIZE($sp)
680 .size undo_switch_stack, .-undo_switch_stack
682 #define FR(n) n * 8 + TI_FP($8)
685 .type __save_fpu, @function
687 #define V(n) stt $f##n, FR(n)
688 V( 0); V( 1); V( 2); V( 3)
689 V( 4); V( 5); V( 6); V( 7)
690 V( 8); V( 9); V(10); V(11)
691 V(12); V(13); V(14); V(15)
692 V(16); V(17); V(18); V(19)
693 V(20); V(21); V(22); V(23)
694 V(24); V(25); V(26); V(27)
695 mf_fpcr $f0 # get fpcr
697 stt $f0, FR(31) # save fpcr in slot of $f31
698 ldt $f0, FR(0) # don't let "__save_fpu" change fp state.
701 .size __save_fpu, .-__save_fpu
705 and $3, TS_RESTORE_FP, $3
706 bic $2, TS_SAVED_FP | TS_RESTORE_FP, $2
708 #define V(n) ldt $f##n, FR(n)
709 ldt $f30, FR(31) # get saved fpcr
710 V( 0); V( 1); V( 2); V( 3)
711 mt_fpcr $f30 # install saved fpcr
712 V( 4); V( 5); V( 6); V( 7)
713 V( 8); V( 9); V(10); V(11)
714 V(12); V(13); V(14); V(15)
715 V(16); V(17); V(18); V(19)
716 V(20); V(21); V(22); V(23)
717 V(24); V(25); V(26); V(27)
719 1: stl $2, TI_STATUS($8)
725 * The meat of the context switch code.
728 .globl alpha_switch_to
729 .type alpha_switch_to, @function
733 ldl $1, TI_STATUS($8)
734 and $1, TS_RESTORE_FP, $3
736 or $1, TS_RESTORE_FP | TS_SAVED_FP, $2
737 and $1, TS_SAVED_FP, $3
738 stl $2, TI_STATUS($8)
749 .size alpha_switch_to, .-alpha_switch_to
752 * New processes begin life here.
761 jmp $31, schedule_tail
765 * ... and new kernel threads - here
768 .globl ret_from_kernel_thread
769 .ent ret_from_kernel_thread
770 ret_from_kernel_thread:
772 jsr $26, schedule_tail
777 .end ret_from_kernel_thread
781 * Special system calls. Most of these are special in that they either
782 * have to play switch_stack games.
785 .macro fork_like name
791 bsr $1, do_switch_stack
792 // NB: if anyone adds preemption, this block will need to be protected
793 ldl $1, TI_STATUS($8)
794 and $1, TS_SAVED_FP, $3
795 or $1, TS_SAVED_FP, $2
797 stl $2, TI_STATUS($8)
802 lda $sp, SWITCH_STACK_SIZE($sp)
812 .macro sigreturn_like name
818 lda $9, ret_from_straced
820 lda $sp, -SWITCH_STACK_SIZE($sp)
823 jsr $26, syscall_trace_leave
824 1: br $1, undo_switch_stack
829 sigreturn_like sigreturn
830 sigreturn_like rt_sigreturn
833 .globl alpha_syscall_zero
834 .ent alpha_syscall_zero
837 /* Special because it needs to do something opposite to
838 force_successful_syscall_return(). We use the saved
839 syscall number for that, zero meaning "not an error".
840 That works nicely, but for real syscall 0 we need to
841 make sure that this logics doesn't get confused.
842 Store a non-zero there - -ENOSYS we need in register
843 for our return value will do just fine.
849 .end alpha_syscall_zero