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>
15 .cfi_sections .debug_frame
19 #define SWITCH_STACK_SIZE 320
21 .macro CFI_START_OSF_FRAME func
30 .cfi_rel_offset $gp, 16
31 .cfi_rel_offset $16, 24
32 .cfi_rel_offset $17, 32
33 .cfi_rel_offset $18, 40
36 .macro CFI_END_OSF_FRAME func
38 .size \func, . - \func
42 * This defines the normal kernel pt-regs layout.
44 * regs 9-15 preserved by C code
45 * regs 16-18 saved by PAL-code
46 * regs 29-30 saved and set up by PAL-code
47 * JRP - Save regs 16-18 in a special area of the stack, so that
48 * the palcode-provided values are available to the signal handler.
53 .cfi_adjust_cfa_offset SP_OFF
62 .cfi_rel_offset $2, 16
63 .cfi_rel_offset $3, 24
64 .cfi_rel_offset $4, 32
65 .cfi_rel_offset $28, 144
85 .cfi_rel_offset $5, 40
86 .cfi_rel_offset $6, 48
87 .cfi_rel_offset $7, 56
88 .cfi_rel_offset $8, 64
89 .cfi_rel_offset $19, 72
90 .cfi_rel_offset $20, 80
91 .cfi_rel_offset $21, 88
92 .cfi_rel_offset $22, 96
93 .cfi_rel_offset $23, 104
94 .cfi_rel_offset $24, 112
95 .cfi_rel_offset $25, 120
96 .cfi_rel_offset $26, 128
97 .cfi_rel_offset $27, 136
107 ldq $20, HAE_CACHE($19)
115 ldq $20, HAE_REG($19)
116 stq $21, HAE_CACHE($19)
128 addq $sp, SP_OFF, $sp
148 .cfi_adjust_cfa_offset -SP_OFF
151 .macro DO_SWITCH_STACK
152 bsr $1, do_switch_stack
153 .cfi_adjust_cfa_offset SWITCH_STACK_SIZE
154 .cfi_rel_offset $9, 0
155 .cfi_rel_offset $10, 8
156 .cfi_rel_offset $11, 16
157 .cfi_rel_offset $12, 24
158 .cfi_rel_offset $13, 32
159 .cfi_rel_offset $14, 40
160 .cfi_rel_offset $15, 48
161 /* We don't really care about the FP registers for debugging. */
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
475 1: jsr $26, ($27), alpha_ni_syscall
477 blt $0, $syscall_error /* the call failed */
479 stq $31, 72($sp) /* a3=0 => no error */
482 .globl ret_from_sys_call
484 cmovne $26, 0, $18 /* $18 = 0 => non-restartable */
487 beq $0, ret_to_kernel
489 /* Make sure need_resched and sigpending don't change between
490 sampling and the rti. */
493 ldl $17, TI_FLAGS($8)
494 and $17, _TIF_WORK_MASK, $2
510 * Some system calls (e.g., ptrace) can return arbitrary
511 * values which might normally be mistaken as error numbers.
512 * Those functions must zero $0 (v0) directly in the stack
513 * frame to indicate that a negative return value wasn't an
516 ldq $18, 0($sp) /* old syscall nr (zero if success) */
517 beq $18, $ret_success
519 ldq $19, 72($sp) /* .. and this a3 */
520 subq $31, $0, $0 /* with error in v0 */
521 addq $31, 1, $1 /* set a3 for errno return */
523 mov $31, $26 /* tell "ret_from_sys_call" we can restart */
524 stq $1, 72($sp) /* a3 for return */
529 stq $31, 72($sp) /* a3=0 => no error */
533 * Do all cleanup when returning from all interrupts and system calls.
538 * $18: The old syscall number, or zero if this is not a return
539 * from a syscall that errored and is possibly restartable.
540 * $19: The old a3 value
544 .type work_pending, @function
546 and $17, _TIF_NOTIFY_RESUME | _TIF_SIGPENDING, $2
547 bne $2, $work_notifysig
551 * We can get here only if we returned from syscall without SIGPENDING
552 * or got through work_notifysig already. Either case means no syscall
553 * restarts for us, so let $18 and $19 burn.
562 jsr $26, do_work_pending
567 * PTRACE syscall handler
571 .type strace, @function
573 /* set up signal stack, call syscall_trace */
575 jsr $26, syscall_trace_enter /* returns the syscall number */
578 /* get the arguments back.. */
579 ldq $16, SP_OFF+24($sp)
580 ldq $17, SP_OFF+32($sp)
581 ldq $18, SP_OFF+40($sp)
586 /* get the system call pointer.. */
587 lda $1, NR_SYSCALLS($31)
588 lda $2, sys_call_table
589 lda $27, alpha_ni_syscall
594 1: jsr $26, ($27), sys_gettimeofday
599 blt $0, $strace_error /* the call failed */
600 stq $31, 72($sp) /* a3=0 => no error */
602 stq $0, 0($sp) /* save return value */
605 jsr $26, syscall_trace_leave
607 br $31, ret_from_sys_call
611 ldq $18, 0($sp) /* old syscall nr (zero if success) */
612 beq $18, $strace_success
613 ldq $19, 72($sp) /* .. and this a3 */
615 subq $31, $0, $0 /* with error in v0 */
616 addq $31, 1, $1 /* set a3 for errno return */
618 stq $1, 72($sp) /* a3 for return */
621 mov $18, $9 /* save old syscall number */
622 mov $19, $10 /* save old a3 */
623 jsr $26, syscall_trace_leave
628 mov $31, $26 /* tell "ret_from_sys_call" we can restart */
630 CFI_END_OSF_FRAME entSys
633 * Save and restore the switch stack -- aka the balance of the user context.
637 .type do_switch_stack, @function
638 .cfi_startproc simple
639 .cfi_return_column 64
643 lda $sp, -SWITCH_STACK_SIZE($sp)
644 .cfi_adjust_cfa_offset SWITCH_STACK_SIZE
681 mf_fpcr $f0 # get fpcr
685 stt $f0, 312($sp) # save fpcr in slot of $f31
686 ldt $f0, 64($sp) # dont let "do_switch_stack" change fp state.
689 .size do_switch_stack, .-do_switch_stack
692 .type undo_switch_stack, @function
693 .cfi_startproc simple
705 ldt $f30, 312($sp) # get saved fpcr
710 mt_fpcr $f30 # install saved fpcr
738 lda $sp, SWITCH_STACK_SIZE($sp)
741 .size undo_switch_stack, .-undo_switch_stack
744 * The meat of the context switch code.
748 .globl alpha_switch_to
749 .type alpha_switch_to, @function
760 .size alpha_switch_to, .-alpha_switch_to
763 * New processes begin life here.
770 lda $26, ret_from_sys_call
772 jmp $31, schedule_tail
776 * ... and new kernel threads - here
779 .globl ret_from_kernel_thread
780 .ent ret_from_kernel_thread
781 ret_from_kernel_thread:
783 jsr $26, schedule_tail
787 mov $31, $19 /* to disable syscall restarts */
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 or in some way use the pt_regs struct.
797 .macro fork_like name
803 bsr $1, do_switch_stack
806 lda $sp, SWITCH_STACK_SIZE($sp)
820 lda $9, ret_from_straced
822 lda $sp, -SWITCH_STACK_SIZE($sp)
823 jsr $26, do_sigreturn
825 jsr $26, syscall_trace_leave
826 1: br $1, undo_switch_stack
831 .globl sys_rt_sigreturn
832 .ent sys_rt_sigreturn
835 lda $9, ret_from_straced
837 lda $sp, -SWITCH_STACK_SIZE($sp)
838 jsr $26, do_rt_sigreturn
840 jsr $26, syscall_trace_leave
841 1: br $1, undo_switch_stack
843 .end sys_rt_sigreturn
846 .globl alpha_ni_syscall
847 .ent alpha_ni_syscall
850 /* Special because it also implements overflow handling via
851 syscall number 0. And if you recall, zero is a special
852 trigger for "not an error". Store large non-zero there. */
857 .end alpha_ni_syscall