2 * arch/s390/kernel/entry64.S
3 * S390 low-level entry points.
5 * Copyright (C) IBM Corp. 1999,2006
6 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
7 * Hartmut Penner (hp@de.ibm.com),
8 * Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com),
9 * Heiko Carstens <heiko.carstens@de.ibm.com>
12 #include <linux/sys.h>
13 #include <linux/linkage.h>
14 #include <asm/cache.h>
15 #include <asm/lowcore.h>
16 #include <asm/errno.h>
17 #include <asm/ptrace.h>
18 #include <asm/thread_info.h>
19 #include <asm/asm-offsets.h>
20 #include <asm/unistd.h>
24 * Stack layout for the system_call stack entry.
25 * The first few entries are identical to the user_regs_struct.
27 SP_PTREGS = STACK_FRAME_OVERHEAD
28 SP_ARGS = STACK_FRAME_OVERHEAD + __PT_ARGS
29 SP_PSW = STACK_FRAME_OVERHEAD + __PT_PSW
30 SP_R0 = STACK_FRAME_OVERHEAD + __PT_GPRS
31 SP_R1 = STACK_FRAME_OVERHEAD + __PT_GPRS + 8
32 SP_R2 = STACK_FRAME_OVERHEAD + __PT_GPRS + 16
33 SP_R3 = STACK_FRAME_OVERHEAD + __PT_GPRS + 24
34 SP_R4 = STACK_FRAME_OVERHEAD + __PT_GPRS + 32
35 SP_R5 = STACK_FRAME_OVERHEAD + __PT_GPRS + 40
36 SP_R6 = STACK_FRAME_OVERHEAD + __PT_GPRS + 48
37 SP_R7 = STACK_FRAME_OVERHEAD + __PT_GPRS + 56
38 SP_R8 = STACK_FRAME_OVERHEAD + __PT_GPRS + 64
39 SP_R9 = STACK_FRAME_OVERHEAD + __PT_GPRS + 72
40 SP_R10 = STACK_FRAME_OVERHEAD + __PT_GPRS + 80
41 SP_R11 = STACK_FRAME_OVERHEAD + __PT_GPRS + 88
42 SP_R12 = STACK_FRAME_OVERHEAD + __PT_GPRS + 96
43 SP_R13 = STACK_FRAME_OVERHEAD + __PT_GPRS + 104
44 SP_R14 = STACK_FRAME_OVERHEAD + __PT_GPRS + 112
45 SP_R15 = STACK_FRAME_OVERHEAD + __PT_GPRS + 120
46 SP_ORIG_R2 = STACK_FRAME_OVERHEAD + __PT_ORIG_GPR2
47 SP_ILC = STACK_FRAME_OVERHEAD + __PT_ILC
48 SP_TRAP = STACK_FRAME_OVERHEAD + __PT_TRAP
49 SP_SIZE = STACK_FRAME_OVERHEAD + __PT_SIZE
51 STACK_SHIFT = PAGE_SHIFT + THREAD_ORDER
52 STACK_SIZE = 1 << STACK_SHIFT
54 _TIF_WORK_SVC = (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK | _TIF_NEED_RESCHED | \
55 _TIF_MCCK_PENDING | _TIF_RESTART_SVC | _TIF_SINGLE_STEP )
56 _TIF_WORK_INT = (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK | _TIF_NEED_RESCHED | \
59 #define BASED(name) name-system_call(%r13)
61 .macro STORE_TIMER lc_offset
62 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
67 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
68 .macro UPDATE_VTIME lc_from,lc_to,lc_sum
77 * Register usage in interrupt handlers:
78 * R9 - pointer to current task structure
79 * R13 - pointer to literal pool
80 * R14 - return register for function calls
81 * R15 - kernel stack pointer
84 .macro SAVE_ALL_BASE savearea
85 stmg %r12,%r15,\savearea
89 .macro SAVE_ALL_SYNC psworg,savearea
91 tm \psworg+1,0x01 # test problem state bit
92 jz 2f # skip stack setup save
93 lg %r15,__LC_KERNEL_STACK # problem state -> load ksp
94 #ifdef CONFIG_CHECK_STACK
96 2: tml %r15,STACK_SIZE - CONFIG_STACK_GUARD
103 .macro SAVE_ALL_ASYNC psworg,savearea
105 tm \psworg+1,0x01 # test problem state bit
106 jnz 1f # from user -> load kernel stack
107 clc \psworg+8(8),BASED(.Lcritical_end)
109 clc \psworg+8(8),BASED(.Lcritical_start)
111 brasl %r14,cleanup_critical
112 tm 1(%r12),0x01 # retest problem state after cleanup
114 0: lg %r14,__LC_ASYNC_STACK # are we already on the async. stack ?
116 srag %r14,%r14,STACK_SHIFT
118 1: lg %r15,__LC_ASYNC_STACK # load async stack
119 #ifdef CONFIG_CHECK_STACK
121 2: tml %r15,STACK_SIZE - CONFIG_STACK_GUARD
128 .macro CREATE_STACK_FRAME psworg,savearea
129 aghi %r15,-SP_SIZE # make room for registers & psw
130 mvc SP_PSW(16,%r15),0(%r12) # move user PSW to stack
132 stg %r2,SP_ORIG_R2(%r15) # store original content of gpr 2
133 icm %r12,12,__LC_SVC_ILC
134 stmg %r0,%r11,SP_R0(%r15) # store gprs %r0-%r11 to kernel stack
136 mvc SP_R12(32,%r15),\savearea # move %r12-%r15 to stack
138 stg %r12,__SF_BACKCHAIN(%r15)
141 .macro RESTORE_ALL psworg,sync
142 mvc \psworg(16),SP_PSW(%r15) # move user PSW to lowcore
144 ni \psworg+1,0xfd # clear wait state bit
146 lmg %r0,%r15,SP_R0(%r15) # load gprs 0-15 of user
147 STORE_TIMER __LC_EXIT_TIMER
148 lpswe \psworg # back to caller
152 * Scheduler resume function, called by switch_to
153 * gpr2 = (task_struct *) prev
154 * gpr3 = (task_struct *) next
160 tm __THREAD_per+4(%r3),0xe8 # is the new process using per ?
161 jz __switch_to_noper # if not we're fine
162 stctg %c9,%c11,__SF_EMPTY(%r15)# We are using per stuff
163 clc __THREAD_per(24,%r3),__SF_EMPTY(%r15)
164 je __switch_to_noper # we got away without bashing TLB's
165 lctlg %c9,%c11,__THREAD_per(%r3) # Nope we didn't
167 lg %r4,__THREAD_info(%r2) # get thread_info of prev
168 tm __TI_flags+7(%r4),_TIF_MCCK_PENDING # machine check pending?
169 jz __switch_to_no_mcck
170 ni __TI_flags+7(%r4),255-_TIF_MCCK_PENDING # clear flag in prev
171 lg %r4,__THREAD_info(%r3) # get thread_info of next
172 oi __TI_flags+7(%r4),_TIF_MCCK_PENDING # set it in next
174 stmg %r6,%r15,__SF_GPRS(%r15)# store __switch_to registers of prev task
175 stg %r15,__THREAD_ksp(%r2) # store kernel stack to prev->tss.ksp
176 lg %r15,__THREAD_ksp(%r3) # load kernel stack from next->tss.ksp
177 lmg %r6,%r15,__SF_GPRS(%r15)# load __switch_to registers of next task
178 stg %r3,__LC_CURRENT # __LC_CURRENT = current task struct
179 lctl %c4,%c4,__TASK_pid(%r3) # load pid to control reg. 4
180 lg %r3,__THREAD_info(%r3) # load thread_info from task struct
181 stg %r3,__LC_THREAD_INFO
183 stg %r3,__LC_KERNEL_STACK # __LC_KERNEL_STACK = new kernel stack
188 * SVC interrupt handler routine. System calls are synchronous events and
189 * are executed with interrupts enabled.
194 STORE_TIMER __LC_SYNC_ENTER_TIMER
196 SAVE_ALL_BASE __LC_SAVE_AREA
197 SAVE_ALL_SYNC __LC_SVC_OLD_PSW,__LC_SAVE_AREA
198 CREATE_STACK_FRAME __LC_SVC_OLD_PSW,__LC_SAVE_AREA
199 llgh %r7,__LC_SVC_INT_CODE # get svc number from lowcore
200 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
202 tm SP_PSW+1(%r15),0x01 # interrupting from user ?
204 UPDATE_VTIME __LC_EXIT_TIMER,__LC_SYNC_ENTER_TIMER,__LC_USER_TIMER
206 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
208 mvc __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
211 lg %r9,__LC_THREAD_INFO # load pointer to thread_info struct
212 slag %r7,%r7,2 # *4 and test for svc 0
214 # svc 0: system call number in %r1
215 cl %r1,BASED(.Lnr_syscalls)
217 lgfr %r7,%r1 # clear high word in r1
218 slag %r7,%r7,2 # svc 0: system call number in %r1
220 mvc SP_ARGS(8,%r15),SP_R7(%r15)
222 larl %r10,sys_call_table
224 tm __TI_flags+5(%r9),(_TIF_31BIT>>16) # running in 31 bit mode ?
226 larl %r10,sys_call_table_emu # use 31 bit emulation system calls
229 tm __TI_flags+7(%r9),(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT)
230 lgf %r8,0(%r7,%r10) # load address of system call routine
232 basr %r14,%r8 # call sys_xxxx
233 stg %r2,SP_R2(%r15) # store return value (change R2 on stack)
234 # ATTENTION: check sys_execve_glue before
235 # changing anything here !!
238 tm SP_PSW+1(%r15),0x01 # returning to user ?
240 tm __TI_flags+7(%r9),_TIF_WORK_SVC
241 jnz sysc_work # there is work to do (signals etc.)
243 RESTORE_ALL __LC_RETURN_PSW,1
246 # recheck if there is more work to do
249 tm __TI_flags+7(%r9),_TIF_WORK_SVC
250 jz sysc_leave # there is no work to do
252 # One of the work bits is on. Find out which one.
255 tm __TI_flags+7(%r9),_TIF_MCCK_PENDING
257 tm __TI_flags+7(%r9),_TIF_NEED_RESCHED
259 tm __TI_flags+7(%r9),(_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK)
261 tm __TI_flags+7(%r9),_TIF_RESTART_SVC
263 tm __TI_flags+7(%r9),_TIF_SINGLE_STEP
268 # _TIF_NEED_RESCHED is set, call schedule
271 larl %r14,sysc_work_loop
272 jg schedule # return point is sysc_return
275 # _TIF_MCCK_PENDING is set, call handler
278 larl %r14,sysc_work_loop
279 jg s390_handle_mcck # TIF bit will be cleared by handler
282 # _TIF_SIGPENDING or _TIF_RESTORE_SIGMASK is set, call do_signal
285 ni __TI_flags+7(%r9),255-_TIF_SINGLE_STEP # clear TIF_SINGLE_STEP
286 la %r2,SP_PTREGS(%r15) # load pt_regs
287 brasl %r14,do_signal # call do_signal
288 tm __TI_flags+7(%r9),_TIF_RESTART_SVC
290 tm __TI_flags+7(%r9),_TIF_SINGLE_STEP
295 # _TIF_RESTART_SVC is set, set up registers and restart svc
298 ni __TI_flags+7(%r9),255-_TIF_RESTART_SVC # clear TIF_RESTART_SVC
299 lg %r7,SP_R2(%r15) # load new svc number
301 mvc SP_R2(8,%r15),SP_ORIG_R2(%r15) # restore first argument
302 lmg %r2,%r6,SP_R2(%r15) # load svc arguments
303 j sysc_do_restart # restart svc
306 # _TIF_SINGLE_STEP is set, call do_single_step
309 ni __TI_flags+7(%r9),255-_TIF_SINGLE_STEP # clear TIF_SINGLE_STEP
310 lhi %r0,__LC_PGM_OLD_PSW
311 sth %r0,SP_TRAP(%r15) # set trap indication to pgm check
312 la %r2,SP_PTREGS(%r15) # address of register-save area
313 larl %r14,sysc_return # load adr. of system return
314 jg do_single_step # branch to do_sigtrap
318 # call syscall_trace before and after system call
319 # special linkage: %r12 contains the return address for trace_svc
322 la %r2,SP_PTREGS(%r15) # load pt_regs
326 brasl %r14,syscall_trace
330 lg %r7,SP_R2(%r15) # strace might have changed the
331 sll %r7,2 # system call
334 lmg %r3,%r6,SP_R3(%r15)
335 lg %r2,SP_ORIG_R2(%r15)
336 basr %r14,%r8 # call sys_xxx
337 stg %r2,SP_R2(%r15) # store return value
339 tm __TI_flags+7(%r9),(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT)
341 la %r2,SP_PTREGS(%r15) # load pt_regs
343 larl %r14,sysc_return # return point is sysc_return
347 # a new process exits the kernel with ret_from_fork
351 lg %r13,__LC_SVC_NEW_PSW+8
352 lg %r9,__LC_THREAD_INFO # load pointer to thread_info struct
353 tm SP_PSW+1(%r15),0x01 # forking a kernel thread ?
355 stg %r15,SP_R15(%r15) # store stack pointer for new kthread
356 0: brasl %r14,schedule_tail
357 stosm 24(%r15),0x03 # reenable interrupts
361 # clone, fork, vfork, exec and sigreturn need glue,
362 # because they all expect pt_regs as parameter,
363 # but are called with different parameter.
364 # return-address is set up above
367 la %r2,SP_PTREGS(%r15) # load pt_regs
368 jg sys_clone # branch to sys_clone
372 la %r2,SP_PTREGS(%r15) # load pt_regs
373 jg sys32_clone # branch to sys32_clone
377 la %r2,SP_PTREGS(%r15) # load pt_regs
378 jg sys_fork # branch to sys_fork
381 la %r2,SP_PTREGS(%r15) # load pt_regs
382 jg sys_vfork # branch to sys_vfork
385 la %r2,SP_PTREGS(%r15) # load pt_regs
386 lgr %r12,%r14 # save return address
387 brasl %r14,sys_execve # call sys_execve
388 ltgr %r2,%r2 # check if execve failed
389 bnz 0(%r12) # it did fail -> store result in gpr2
390 b 6(%r12) # SKIP STG 2,SP_R2(15) in
391 # system_call/sysc_tracesys
394 la %r2,SP_PTREGS(%r15) # load pt_regs
395 lgr %r12,%r14 # save return address
396 brasl %r14,sys32_execve # call sys32_execve
397 ltgr %r2,%r2 # check if execve failed
398 bnz 0(%r12) # it did fail -> store result in gpr2
399 b 6(%r12) # SKIP STG 2,SP_R2(15) in
400 # system_call/sysc_tracesys
404 la %r2,SP_PTREGS(%r15) # load pt_regs as parameter
405 jg sys_sigreturn # branch to sys_sigreturn
408 sys32_sigreturn_glue:
409 la %r2,SP_PTREGS(%r15) # load pt_regs as parameter
410 jg sys32_sigreturn # branch to sys32_sigreturn
413 sys_rt_sigreturn_glue:
414 la %r2,SP_PTREGS(%r15) # load pt_regs as parameter
415 jg sys_rt_sigreturn # branch to sys_sigreturn
418 sys32_rt_sigreturn_glue:
419 la %r2,SP_PTREGS(%r15) # load pt_regs as parameter
420 jg sys32_rt_sigreturn # branch to sys32_sigreturn
423 sys_sigaltstack_glue:
424 la %r4,SP_PTREGS(%r15) # load pt_regs as parameter
425 jg sys_sigaltstack # branch to sys_sigreturn
428 sys32_sigaltstack_glue:
429 la %r4,SP_PTREGS(%r15) # load pt_regs as parameter
430 jg sys32_sigaltstack_wrapper # branch to sys_sigreturn
434 * Program check handler routine
437 .globl pgm_check_handler
440 * First we need to check for a special case:
441 * Single stepping an instruction that disables the PER event mask will
442 * cause a PER event AFTER the mask has been set. Example: SVC or LPSW.
443 * For a single stepped SVC the program check handler gets control after
444 * the SVC new PSW has been loaded. But we want to execute the SVC first and
445 * then handle the PER event. Therefore we update the SVC old PSW to point
446 * to the pgm_check_handler and branch to the SVC handler after we checked
447 * if we have to load the kernel stack register.
448 * For every other possible cause for PER event without the PER mask set
449 * we just ignore the PER event (FIXME: is there anything we have to do
452 STORE_TIMER __LC_SYNC_ENTER_TIMER
453 SAVE_ALL_BASE __LC_SAVE_AREA
454 tm __LC_PGM_INT_CODE+1,0x80 # check whether we got a per exception
455 jnz pgm_per # got per exception -> special case
456 SAVE_ALL_SYNC __LC_PGM_OLD_PSW,__LC_SAVE_AREA
457 CREATE_STACK_FRAME __LC_PGM_OLD_PSW,__LC_SAVE_AREA
458 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
459 tm SP_PSW+1(%r15),0x01 # interrupting from user ?
461 UPDATE_VTIME __LC_EXIT_TIMER,__LC_SYNC_ENTER_TIMER,__LC_USER_TIMER
462 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
463 mvc __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
466 lg %r9,__LC_THREAD_INFO # load pointer to thread_info struct
467 lgf %r3,__LC_PGM_ILC # load program interruption code
472 larl %r1,pgm_check_table
473 lg %r1,0(%r8,%r1) # load address of handler routine
474 la %r2,SP_PTREGS(%r15) # address of register-save area
475 larl %r14,sysc_return
476 br %r1 # branch to interrupt-handler
479 # handle per exception
482 tm __LC_PGM_OLD_PSW,0x40 # test if per event recording is on
483 jnz pgm_per_std # ok, normal per event from user space
484 # ok its one of the special cases, now we need to find out which one
485 clc __LC_PGM_OLD_PSW(16),__LC_SVC_NEW_PSW
487 # no interesting special case, ignore PER event
488 lmg %r12,%r15,__LC_SAVE_AREA
489 lpswe __LC_PGM_OLD_PSW
492 # Normal per exception
495 SAVE_ALL_SYNC __LC_PGM_OLD_PSW,__LC_SAVE_AREA
496 CREATE_STACK_FRAME __LC_PGM_OLD_PSW,__LC_SAVE_AREA
497 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
498 tm SP_PSW+1(%r15),0x01 # interrupting from user ?
500 UPDATE_VTIME __LC_EXIT_TIMER,__LC_SYNC_ENTER_TIMER,__LC_USER_TIMER
501 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
502 mvc __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
505 lg %r9,__LC_THREAD_INFO # load pointer to thread_info struct
506 lg %r1,__TI_task(%r9)
507 mvc __THREAD_per+__PER_atmid(2,%r1),__LC_PER_ATMID
508 mvc __THREAD_per+__PER_address(8,%r1),__LC_PER_ADDRESS
509 mvc __THREAD_per+__PER_access_id(1,%r1),__LC_PER_ACCESS_ID
510 oi __TI_flags+7(%r9),_TIF_SINGLE_STEP # set TIF_SINGLE_STEP
511 lgf %r3,__LC_PGM_ILC # load program interruption code
513 ngr %r8,%r3 # clear per-event-bit and ilc
518 # it was a single stepped SVC that is causing all the trouble
521 SAVE_ALL_SYNC __LC_SVC_OLD_PSW,__LC_SAVE_AREA
522 CREATE_STACK_FRAME __LC_SVC_OLD_PSW,__LC_SAVE_AREA
523 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
524 tm SP_PSW+1(%r15),0x01 # interrupting from user ?
526 UPDATE_VTIME __LC_EXIT_TIMER,__LC_SYNC_ENTER_TIMER,__LC_USER_TIMER
527 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
528 mvc __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
531 llgh %r7,__LC_SVC_INT_CODE # get svc number from lowcore
532 lg %r9,__LC_THREAD_INFO # load pointer to thread_info struct
533 lg %r1,__TI_task(%r9)
534 mvc __THREAD_per+__PER_atmid(2,%r1),__LC_PER_ATMID
535 mvc __THREAD_per+__PER_address(8,%r1),__LC_PER_ADDRESS
536 mvc __THREAD_per+__PER_access_id(1,%r1),__LC_PER_ACCESS_ID
537 oi __TI_flags+7(%r9),_TIF_SINGLE_STEP # set TIF_SINGLE_STEP
538 stosm __SF_EMPTY(%r15),0x03 # reenable interrupts
542 * IO interrupt handler routine
544 .globl io_int_handler
546 STORE_TIMER __LC_ASYNC_ENTER_TIMER
548 SAVE_ALL_BASE __LC_SAVE_AREA+32
549 SAVE_ALL_ASYNC __LC_IO_OLD_PSW,__LC_SAVE_AREA+32
550 CREATE_STACK_FRAME __LC_IO_OLD_PSW,__LC_SAVE_AREA+32
551 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
552 tm SP_PSW+1(%r15),0x01 # interrupting from user ?
554 UPDATE_VTIME __LC_EXIT_TIMER,__LC_ASYNC_ENTER_TIMER,__LC_USER_TIMER
555 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
556 mvc __LC_LAST_UPDATE_TIMER(8),__LC_ASYNC_ENTER_TIMER
559 lg %r9,__LC_THREAD_INFO # load pointer to thread_info struct
560 la %r2,SP_PTREGS(%r15) # address of register-save area
561 brasl %r14,do_IRQ # call standard irq handler
564 tm SP_PSW+1(%r15),0x01 # returning to user ?
565 #ifdef CONFIG_PREEMPT
566 jno io_preempt # no -> check for preemptive scheduling
568 jno io_leave # no-> skip resched & signal
570 tm __TI_flags+7(%r9),_TIF_WORK_INT
571 jnz io_work # there is work to do (signals etc.)
573 RESTORE_ALL __LC_RETURN_PSW,0
576 #ifdef CONFIG_PREEMPT
578 icm %r0,15,__TI_precount(%r9)
580 # switch to kernel stack
583 mvc SP_PTREGS(__PT_SIZE,%r1),SP_PTREGS(%r15)
584 xc __SF_BACKCHAIN(8,%r1),__SF_BACKCHAIN(%r1) # clear back chain
587 tm __TI_flags+7(%r9),_TIF_NEED_RESCHED
590 mvc __TI_precount(4,%r9),0(%r1)
591 stosm __SF_EMPTY(%r15),0x03 # reenable interrupts
592 brasl %r14,schedule # call schedule
593 stnsm __SF_EMPTY(%r15),0xfc # disable I/O and ext. interrupts
594 xc __TI_precount(4,%r9),__TI_precount(%r9)
599 # switch to kernel stack, then check TIF bits
602 lg %r1,__LC_KERNEL_STACK
604 mvc SP_PTREGS(__PT_SIZE,%r1),SP_PTREGS(%r15)
605 xc __SF_BACKCHAIN(8,%r1),__SF_BACKCHAIN(%r1) # clear back chain
608 # One of the work bits is on. Find out which one.
609 # Checked are: _TIF_SIGPENDING, _TIF_RESTORE_SIGPENDING, _TIF_NEED_RESCHED
610 # and _TIF_MCCK_PENDING
613 tm __TI_flags+7(%r9),_TIF_MCCK_PENDING
615 tm __TI_flags+7(%r9),_TIF_NEED_RESCHED
617 tm __TI_flags+7(%r9),(_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK)
622 # _TIF_MCCK_PENDING is set, call handler
625 larl %r14,io_work_loop
626 jg s390_handle_mcck # TIF bit will be cleared by handler
629 # _TIF_NEED_RESCHED is set, call schedule
632 stosm __SF_EMPTY(%r15),0x03 # reenable interrupts
633 brasl %r14,schedule # call scheduler
634 stnsm __SF_EMPTY(%r15),0xfc # disable I/O and ext. interrupts
635 tm __TI_flags+7(%r9),_TIF_WORK_INT
636 jz io_leave # there is no work to do
640 # _TIF_SIGPENDING or _TIF_RESTORE_SIGMASK is set, call do_signal
643 stosm __SF_EMPTY(%r15),0x03 # reenable interrupts
644 la %r2,SP_PTREGS(%r15) # load pt_regs
645 brasl %r14,do_signal # call do_signal
646 stnsm __SF_EMPTY(%r15),0xfc # disable I/O and ext. interrupts
650 * External interrupt handler routine
652 .globl ext_int_handler
654 STORE_TIMER __LC_ASYNC_ENTER_TIMER
656 SAVE_ALL_BASE __LC_SAVE_AREA+32
657 SAVE_ALL_ASYNC __LC_EXT_OLD_PSW,__LC_SAVE_AREA+32
658 CREATE_STACK_FRAME __LC_EXT_OLD_PSW,__LC_SAVE_AREA+32
659 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
660 tm SP_PSW+1(%r15),0x01 # interrupting from user ?
662 UPDATE_VTIME __LC_EXIT_TIMER,__LC_ASYNC_ENTER_TIMER,__LC_USER_TIMER
663 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
664 mvc __LC_LAST_UPDATE_TIMER(8),__LC_ASYNC_ENTER_TIMER
667 lg %r9,__LC_THREAD_INFO # load pointer to thread_info struct
668 la %r2,SP_PTREGS(%r15) # address of register-save area
669 llgh %r3,__LC_EXT_INT_CODE # get interruption code
676 * Machine check handler routines
678 .globl mcck_int_handler
680 la %r1,4095 # revalidate r1
681 spt __LC_CPU_TIMER_SAVE_AREA-4095(%r1) # revalidate cpu timer
682 lmg %r0,%r15,__LC_GPREGS_SAVE_AREA-4095(%r1)# revalidate gprs
683 SAVE_ALL_BASE __LC_SAVE_AREA+64
684 la %r12,__LC_MCK_OLD_PSW
685 tm __LC_MCCK_CODE,0x80 # system damage?
686 jo mcck_int_main # yes -> rest of mcck code invalid
687 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
689 mvc __LC_SAVE_AREA+104(8),__LC_ASYNC_ENTER_TIMER
690 mvc __LC_ASYNC_ENTER_TIMER(8),__LC_CPU_TIMER_SAVE_AREA-4095(%r14)
691 tm __LC_MCCK_CODE+5,0x02 # stored cpu timer value valid?
693 la %r14,__LC_SYNC_ENTER_TIMER
694 clc 0(8,%r14),__LC_ASYNC_ENTER_TIMER
696 la %r14,__LC_ASYNC_ENTER_TIMER
697 0: clc 0(8,%r14),__LC_EXIT_TIMER
699 la %r14,__LC_EXIT_TIMER
700 0: clc 0(8,%r14),__LC_LAST_UPDATE_TIMER
702 la %r14,__LC_LAST_UPDATE_TIMER
704 mvc __LC_ASYNC_ENTER_TIMER(8),0(%r14)
707 tm __LC_MCCK_CODE+2,0x09 # mwp + ia of old psw valid?
708 jno mcck_int_main # no -> skip cleanup critical
709 tm __LC_MCK_OLD_PSW+1,0x01 # test problem state bit
710 jnz mcck_int_main # from user -> load kernel stack
711 clc __LC_MCK_OLD_PSW+8(8),BASED(.Lcritical_end)
713 clc __LC_MCK_OLD_PSW+8(8),BASED(.Lcritical_start)
715 brasl %r14,cleanup_critical
717 lg %r14,__LC_PANIC_STACK # are we already on the panic stack?
719 srag %r14,%r14,PAGE_SHIFT
721 lg %r15,__LC_PANIC_STACK # load panic stack
722 0: CREATE_STACK_FRAME __LC_MCK_OLD_PSW,__LC_SAVE_AREA+64
723 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
724 tm __LC_MCCK_CODE+2,0x08 # mwp of old psw valid?
725 jno mcck_no_vtime # no -> no timer update
726 tm SP_PSW+1(%r15),0x01 # interrupting from user ?
728 UPDATE_VTIME __LC_EXIT_TIMER,__LC_ASYNC_ENTER_TIMER,__LC_USER_TIMER
729 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
730 mvc __LC_LAST_UPDATE_TIMER(8),__LC_ASYNC_ENTER_TIMER
733 lg %r9,__LC_THREAD_INFO # load pointer to thread_info struct
734 la %r2,SP_PTREGS(%r15) # load pt_regs
735 brasl %r14,s390_do_machine_check
736 tm SP_PSW+1(%r15),0x01 # returning to user ?
738 lg %r1,__LC_KERNEL_STACK # switch to kernel stack
740 mvc SP_PTREGS(__PT_SIZE,%r1),SP_PTREGS(%r15)
741 xc __SF_BACKCHAIN(8,%r1),__SF_BACKCHAIN(%r1) # clear back chain
743 stosm __SF_EMPTY(%r15),0x04 # turn dat on
744 tm __TI_flags+7(%r9),_TIF_MCCK_PENDING
746 brasl %r14,s390_handle_mcck
748 mvc __LC_RETURN_MCCK_PSW(16),SP_PSW(%r15) # move return PSW
749 ni __LC_RETURN_MCCK_PSW+1,0xfd # clear wait state bit
750 lmg %r0,%r15,SP_R0(%r15) # load gprs 0-15
751 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
752 mvc __LC_ASYNC_ENTER_TIMER(8),__LC_SAVE_AREA+104
753 tm __LC_RETURN_MCCK_PSW+1,0x01 # returning to user ?
758 lpswe __LC_RETURN_MCCK_PSW # back to caller
762 * Restart interruption handler, kick starter for additional CPUs
764 .globl restart_int_handler
766 lg %r15,__LC_SAVE_AREA+120 # load ksp
767 lghi %r10,__LC_CREGS_SAVE_AREA
768 lctlg %c0,%c15,0(%r10) # get new ctl regs
769 lghi %r10,__LC_AREGS_SAVE_AREA
771 lmg %r6,%r15,__SF_GPRS(%r15) # load registers from clone
772 stosm __SF_EMPTY(%r15),0x04 # now we can turn dat on
776 * If we do not run with SMP enabled, let the new CPU crash ...
778 .globl restart_int_handler
782 lpswe restart_crash-restart_base(%r1)
785 .long 0x000a0000,0x00000000,0x00000000,0x00000000
789 #ifdef CONFIG_CHECK_STACK
791 * The synchronous or the asynchronous stack overflowed. We are dead.
792 * No need to properly save the registers, we are going to panic anyway.
793 * Setup a pt_regs so that show_trace can provide a good call trace.
796 lg %r15,__LC_PANIC_STACK # change to panic stack
798 mvc SP_PSW(16,%r15),0(%r12) # move user PSW to stack
799 stmg %r0,%r11,SP_R0(%r15) # store gprs %r0-%r11 to kernel stack
800 la %r1,__LC_SAVE_AREA
801 chi %r12,__LC_SVC_OLD_PSW
803 chi %r12,__LC_PGM_OLD_PSW
805 la %r1,__LC_SAVE_AREA+16
806 0: mvc SP_R12(32,%r15),0(%r1) # move %r12-%r15 to stack
807 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15) # clear back chain
808 la %r2,SP_PTREGS(%r15) # load pt_regs
809 jg kernel_stack_overflow
812 cleanup_table_system_call:
813 .quad system_call, sysc_do_svc
814 cleanup_table_sysc_return:
815 .quad sysc_return, sysc_leave
816 cleanup_table_sysc_leave:
817 .quad sysc_leave, sysc_work_loop
818 cleanup_table_sysc_work_loop:
819 .quad sysc_work_loop, sysc_reschedule
820 cleanup_table_io_return:
821 .quad io_return, io_leave
822 cleanup_table_io_leave:
823 .quad io_leave, io_done
824 cleanup_table_io_work_loop:
825 .quad io_work_loop, io_mcck_pending
828 clc 8(8,%r12),BASED(cleanup_table_system_call)
830 clc 8(8,%r12),BASED(cleanup_table_system_call+8)
831 jl cleanup_system_call
833 clc 8(8,%r12),BASED(cleanup_table_sysc_return)
835 clc 8(8,%r12),BASED(cleanup_table_sysc_return+8)
836 jl cleanup_sysc_return
838 clc 8(8,%r12),BASED(cleanup_table_sysc_leave)
840 clc 8(8,%r12),BASED(cleanup_table_sysc_leave+8)
841 jl cleanup_sysc_leave
843 clc 8(8,%r12),BASED(cleanup_table_sysc_work_loop)
845 clc 8(8,%r12),BASED(cleanup_table_sysc_work_loop+8)
846 jl cleanup_sysc_return
848 clc 8(8,%r12),BASED(cleanup_table_io_return)
850 clc 8(8,%r12),BASED(cleanup_table_io_return+8)
853 clc 8(8,%r12),BASED(cleanup_table_io_leave)
855 clc 8(8,%r12),BASED(cleanup_table_io_leave+8)
858 clc 8(8,%r12),BASED(cleanup_table_io_work_loop)
860 clc 8(8,%r12),BASED(cleanup_table_io_work_loop+8)
866 mvc __LC_RETURN_PSW(16),0(%r12)
867 cghi %r12,__LC_MCK_OLD_PSW
869 la %r12,__LC_SAVE_AREA+32
871 0: la %r12,__LC_SAVE_AREA+64
873 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
874 clc __LC_RETURN_PSW+8(8),BASED(cleanup_system_call_insn+8)
876 mvc __LC_SYNC_ENTER_TIMER(8),__LC_ASYNC_ENTER_TIMER
877 0: clc __LC_RETURN_PSW+8(8),BASED(cleanup_system_call_insn+16)
880 clc __LC_RETURN_PSW+8(8),BASED(cleanup_system_call_insn)
882 mvc __LC_SAVE_AREA(32),0(%r12)
884 stg %r12,__LC_SAVE_AREA+96 # argh
885 SAVE_ALL_SYNC __LC_SVC_OLD_PSW,__LC_SAVE_AREA
886 CREATE_STACK_FRAME __LC_SVC_OLD_PSW,__LC_SAVE_AREA
887 lg %r12,__LC_SAVE_AREA+96 # argh
889 llgh %r7,__LC_SVC_INT_CODE
890 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
892 clc __LC_RETURN_PSW+8(8),BASED(cleanup_system_call_insn+24)
894 tm SP_PSW+1(%r15),0x01 # interrupting from user ?
896 UPDATE_VTIME __LC_EXIT_TIMER,__LC_SYNC_ENTER_TIMER,__LC_USER_TIMER
898 clc __LC_RETURN_PSW+8(8),BASED(cleanup_system_call_insn+32)
900 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
902 mvc __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
905 mvc __LC_RETURN_PSW+8(8),BASED(cleanup_table_system_call+8)
906 la %r12,__LC_RETURN_PSW
908 cleanup_system_call_insn:
910 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
918 mvc __LC_RETURN_PSW(8),0(%r12)
919 mvc __LC_RETURN_PSW+8(8),BASED(cleanup_table_sysc_return)
920 la %r12,__LC_RETURN_PSW
924 clc 8(8,%r12),BASED(cleanup_sysc_leave_insn)
926 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
927 mvc __LC_EXIT_TIMER(8),__LC_ASYNC_ENTER_TIMER
928 clc 8(8,%r12),BASED(cleanup_sysc_leave_insn+8)
931 mvc __LC_RETURN_PSW(16),SP_PSW(%r15)
932 cghi %r12,__LC_MCK_OLD_PSW
934 mvc __LC_SAVE_AREA+64(32),SP_R12(%r15)
936 0: mvc __LC_SAVE_AREA+32(32),SP_R12(%r15)
937 1: lmg %r0,%r11,SP_R0(%r15)
939 2: la %r12,__LC_RETURN_PSW
941 cleanup_sysc_leave_insn:
942 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
943 .quad sysc_leave + 16
945 .quad sysc_leave + 12
948 mvc __LC_RETURN_PSW(8),0(%r12)
949 mvc __LC_RETURN_PSW+8(8),BASED(cleanup_table_io_work_loop)
950 la %r12,__LC_RETURN_PSW
954 clc 8(8,%r12),BASED(cleanup_io_leave_insn)
956 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
957 mvc __LC_EXIT_TIMER(8),__LC_ASYNC_ENTER_TIMER
958 clc 8(8,%r12),BASED(cleanup_io_leave_insn+8)
961 mvc __LC_RETURN_PSW(16),SP_PSW(%r15)
962 cghi %r12,__LC_MCK_OLD_PSW
964 mvc __LC_SAVE_AREA+64(32),SP_R12(%r15)
966 0: mvc __LC_SAVE_AREA+32(32),SP_R12(%r15)
967 1: lmg %r0,%r11,SP_R0(%r15)
969 2: la %r12,__LC_RETURN_PSW
971 cleanup_io_leave_insn:
972 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
982 .Lc_pactive: .long PREEMPT_ACTIVE
983 .Lnr_syscalls: .long NR_syscalls
984 .L0x0130: .short 0x130
985 .L0x0140: .short 0x140
986 .L0x0150: .short 0x150
987 .L0x0160: .short 0x160
988 .L0x0170: .short 0x170
990 .quad __critical_start
994 .section .rodata, "a"
995 #define SYSCALL(esa,esame,emu) .long esame
997 #include "syscalls.S"
1000 #ifdef CONFIG_COMPAT
1002 #define SYSCALL(esa,esame,emu) .long emu
1004 #include "syscalls.S"