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
471 1: jsr $26, ($27), alpha_ni_syscall
473 blt $0, $syscall_error /* the call failed */
475 stq $31, 72($sp) /* a3=0 => no error */
478 .globl ret_from_sys_call
480 cmovne $26, 0, $18 /* $18 = 0 => non-restartable */
483 beq $0, ret_to_kernel
485 /* Make sure need_resched and sigpending don't change between
486 sampling and the rti. */
489 ldl $17, TI_FLAGS($8)
490 and $17, _TIF_WORK_MASK, $2
506 * Some system calls (e.g., ptrace) can return arbitrary
507 * values which might normally be mistaken as error numbers.
508 * Those functions must zero $0 (v0) directly in the stack
509 * frame to indicate that a negative return value wasn't an
512 ldq $18, 0($sp) /* old syscall nr (zero if success) */
513 beq $18, $ret_success
515 ldq $19, 72($sp) /* .. and this a3 */
516 subq $31, $0, $0 /* with error in v0 */
517 addq $31, 1, $1 /* set a3 for errno return */
519 mov $31, $26 /* tell "ret_from_sys_call" we can restart */
520 stq $1, 72($sp) /* a3 for return */
525 stq $31, 72($sp) /* a3=0 => no error */
529 * Do all cleanup when returning from all interrupts and system calls.
534 * $18: The old syscall number, or zero if this is not a return
535 * from a syscall that errored and is possibly restartable.
536 * $19: The old a3 value
540 .type work_pending, @function
542 and $17, _TIF_NOTIFY_RESUME | _TIF_SIGPENDING, $2
543 bne $2, $work_notifysig
547 * We can get here only if we returned from syscall without SIGPENDING
548 * or got through work_notifysig already. Either case means no syscall
549 * restarts for us, so let $18 and $19 burn.
558 jsr $26, do_work_pending
563 * PTRACE syscall handler
567 .type strace, @function
569 /* set up signal stack, call syscall_trace */
571 jsr $26, syscall_trace_enter /* returns the syscall number */
574 /* get the arguments back.. */
575 ldq $16, SP_OFF+24($sp)
576 ldq $17, SP_OFF+32($sp)
577 ldq $18, SP_OFF+40($sp)
582 /* get the system call pointer.. */
583 lda $1, NR_SYSCALLS($31)
584 lda $2, sys_call_table
585 lda $27, alpha_ni_syscall
590 1: jsr $26, ($27), sys_gettimeofday
595 blt $0, $strace_error /* the call failed */
596 stq $31, 72($sp) /* a3=0 => no error */
598 stq $0, 0($sp) /* save return value */
601 jsr $26, syscall_trace_leave
603 br $31, ret_from_sys_call
607 ldq $18, 0($sp) /* old syscall nr (zero if success) */
608 beq $18, $strace_success
609 ldq $19, 72($sp) /* .. and this a3 */
611 subq $31, $0, $0 /* with error in v0 */
612 addq $31, 1, $1 /* set a3 for errno return */
614 stq $1, 72($sp) /* a3 for return */
617 mov $18, $9 /* save old syscall number */
618 mov $19, $10 /* save old a3 */
619 jsr $26, syscall_trace_leave
624 mov $31, $26 /* tell "ret_from_sys_call" we can restart */
626 CFI_END_OSF_FRAME entSys
629 * Save and restore the switch stack -- aka the balance of the user context.
633 .type do_switch_stack, @function
634 .cfi_startproc simple
635 .cfi_return_column 64
639 lda $sp, -SWITCH_STACK_SIZE($sp)
640 .cfi_adjust_cfa_offset SWITCH_STACK_SIZE
677 mf_fpcr $f0 # get fpcr
681 stt $f0, 312($sp) # save fpcr in slot of $f31
682 ldt $f0, 64($sp) # dont let "do_switch_stack" change fp state.
685 .size do_switch_stack, .-do_switch_stack
688 .type undo_switch_stack, @function
689 .cfi_startproc simple
701 ldt $f30, 312($sp) # get saved fpcr
706 mt_fpcr $f30 # install saved fpcr
734 lda $sp, SWITCH_STACK_SIZE($sp)
737 .size undo_switch_stack, .-undo_switch_stack
740 * The meat of the context switch code.
744 .globl alpha_switch_to
745 .type alpha_switch_to, @function
756 .size alpha_switch_to, .-alpha_switch_to
759 * New processes begin life here.
766 lda $26, ret_from_sys_call
768 jmp $31, schedule_tail
772 * ... and new kernel threads - here
775 .globl ret_from_kernel_thread
776 .ent ret_from_kernel_thread
777 ret_from_kernel_thread:
779 jsr $26, schedule_tail
783 mov $31, $19 /* to disable syscall restarts */
785 .end ret_from_kernel_thread
789 * Special system calls. Most of these are special in that they either
790 * have to play switch_stack games or in some way use the pt_regs struct.
793 .macro fork_like name
799 bsr $1, do_switch_stack
802 lda $sp, SWITCH_STACK_SIZE($sp)
816 lda $9, ret_from_straced
818 lda $sp, -SWITCH_STACK_SIZE($sp)
819 jsr $26, do_sigreturn
821 jsr $26, syscall_trace_leave
822 1: br $1, undo_switch_stack
827 .globl sys_rt_sigreturn
828 .ent sys_rt_sigreturn
831 lda $9, ret_from_straced
833 lda $sp, -SWITCH_STACK_SIZE($sp)
834 jsr $26, do_rt_sigreturn
836 jsr $26, syscall_trace_leave
837 1: br $1, undo_switch_stack
839 .end sys_rt_sigreturn
842 .globl alpha_ni_syscall
843 .ent alpha_ni_syscall
846 /* Special because it also implements overflow handling via
847 syscall number 0. And if you recall, zero is a special
848 trigger for "not an error". Store large non-zero there. */
853 .end alpha_ni_syscall