2 * arch/s390/kernel/entry64.S
3 * S390 low-level entry points.
5 * Copyright (C) IBM Corp. 1999,2010
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/init.h>
13 #include <linux/linkage.h>
14 #include <asm/cache.h>
15 #include <asm/errno.h>
16 #include <asm/ptrace.h>
17 #include <asm/thread_info.h>
18 #include <asm/asm-offsets.h>
19 #include <asm/unistd.h>
23 * Stack layout for the system_call stack entry.
24 * The first few entries are identical to the user_regs_struct.
26 SP_PTREGS = STACK_FRAME_OVERHEAD
27 SP_ARGS = STACK_FRAME_OVERHEAD + __PT_ARGS
28 SP_PSW = STACK_FRAME_OVERHEAD + __PT_PSW
29 SP_R0 = STACK_FRAME_OVERHEAD + __PT_GPRS
30 SP_R1 = STACK_FRAME_OVERHEAD + __PT_GPRS + 8
31 SP_R2 = STACK_FRAME_OVERHEAD + __PT_GPRS + 16
32 SP_R3 = STACK_FRAME_OVERHEAD + __PT_GPRS + 24
33 SP_R4 = STACK_FRAME_OVERHEAD + __PT_GPRS + 32
34 SP_R5 = STACK_FRAME_OVERHEAD + __PT_GPRS + 40
35 SP_R6 = STACK_FRAME_OVERHEAD + __PT_GPRS + 48
36 SP_R7 = STACK_FRAME_OVERHEAD + __PT_GPRS + 56
37 SP_R8 = STACK_FRAME_OVERHEAD + __PT_GPRS + 64
38 SP_R9 = STACK_FRAME_OVERHEAD + __PT_GPRS + 72
39 SP_R10 = STACK_FRAME_OVERHEAD + __PT_GPRS + 80
40 SP_R11 = STACK_FRAME_OVERHEAD + __PT_GPRS + 88
41 SP_R12 = STACK_FRAME_OVERHEAD + __PT_GPRS + 96
42 SP_R13 = STACK_FRAME_OVERHEAD + __PT_GPRS + 104
43 SP_R14 = STACK_FRAME_OVERHEAD + __PT_GPRS + 112
44 SP_R15 = STACK_FRAME_OVERHEAD + __PT_GPRS + 120
45 SP_ORIG_R2 = STACK_FRAME_OVERHEAD + __PT_ORIG_GPR2
46 SP_ILC = STACK_FRAME_OVERHEAD + __PT_ILC
47 SP_SVCNR = STACK_FRAME_OVERHEAD + __PT_SVCNR
48 SP_SIZE = STACK_FRAME_OVERHEAD + __PT_SIZE
50 STACK_SHIFT = PAGE_SHIFT + THREAD_ORDER
51 STACK_SIZE = 1 << STACK_SHIFT
53 _TIF_WORK_SVC = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
54 _TIF_MCCK_PENDING | _TIF_RESTART_SVC | _TIF_PER_TRAP )
55 _TIF_WORK_INT = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
57 _TIF_SYSCALL = (_TIF_SYSCALL_TRACE>>8 | _TIF_SYSCALL_AUDIT>>8 | \
58 _TIF_SECCOMP>>8 | _TIF_SYSCALL_TRACEPOINT>>8)
59 _TIF_EXIT_SIE = (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_MCCK_PENDING)
61 #define BASED(name) name-system_call(%r13)
64 #if defined(CONFIG_KVM) || defined(CONFIG_KVM_MODULE)
65 tm __LC_MACHINE_FLAGS+6,0x20 # MACHINE_FLAG_SPP
67 .insn s,0xb2800000,\newpp
71 .macro HANDLE_SIE_INTERCEPT
72 #if defined(CONFIG_KVM) || defined(CONFIG_KVM_MODULE)
73 tm __TI_flags+6(%r12),_TIF_SIE>>8
75 SPP __LC_CMF_HPP # set host id
76 clc SP_PSW+8(8,%r15),BASED(.Lsie_loop)
78 clc SP_PSW+8(8,%r15),BASED(.Lsie_done)
80 mvc SP_PSW+8(8,%r15),BASED(.Lsie_loop)
85 #ifdef CONFIG_TRACE_IRQFLAGS
88 brasl %r14,trace_hardirqs_on_caller
93 brasl %r14,trace_hardirqs_off_caller
97 #define TRACE_IRQS_OFF
100 #ifdef CONFIG_LOCKDEP
101 .macro LOCKDEP_SYS_EXIT
102 tm SP_PSW+1(%r15),0x01 # returning to user ?
104 brasl %r14,lockdep_sys_exit
108 #define LOCKDEP_SYS_EXIT
111 .macro UPDATE_VTIME lc_from,lc_to,lc_sum
119 * Register usage in interrupt handlers:
120 * R9 - pointer to current task structure
121 * R13 - pointer to literal pool
122 * R14 - return register for function calls
123 * R15 - kernel stack pointer
126 .macro SAVE_ALL_SVC psworg,savearea
127 stmg %r11,%r15,\savearea
128 lg %r15,__LC_KERNEL_STACK # problem state -> load ksp
129 aghi %r15,-SP_SIZE # make room for registers & psw
130 lg %r11,__LC_LAST_BREAK
133 .macro SAVE_ALL_PGM psworg,savearea
134 stmg %r11,%r15,\savearea
135 tm \psworg+1,0x01 # test problem state bit
136 #ifdef CONFIG_CHECK_STACK
138 tml %r15,STACK_SIZE - CONFIG_STACK_GUARD
145 1: lg %r15,__LC_KERNEL_STACK # problem state -> load ksp
146 2: aghi %r15,-SP_SIZE # make room for registers & psw
147 larl %r13,system_call
148 lg %r11,__LC_LAST_BREAK
151 .macro SAVE_ALL_ASYNC psworg,savearea
152 stmg %r11,%r15,\savearea
153 larl %r13,system_call
154 lg %r11,__LC_LAST_BREAK
156 tm \psworg+1,0x01 # test problem state bit
157 jnz 1f # from user -> load kernel stack
158 clc \psworg+8(8),BASED(.Lcritical_end)
160 clc \psworg+8(8),BASED(.Lcritical_start)
162 brasl %r14,cleanup_critical
163 tm 1(%r12),0x01 # retest problem state after cleanup
165 0: lg %r14,__LC_ASYNC_STACK # are we already on the async. stack ?
167 srag %r14,%r14,STACK_SHIFT
168 #ifdef CONFIG_CHECK_STACK
170 tml %r15,STACK_SIZE - CONFIG_STACK_GUARD
176 1: lg %r15,__LC_ASYNC_STACK # load async stack
177 2: aghi %r15,-SP_SIZE # make room for registers & psw
180 .macro CREATE_STACK_FRAME savearea
181 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
182 stg %r2,SP_ORIG_R2(%r15) # store original content of gpr 2
183 mvc SP_R11(40,%r15),\savearea # move %r11-%r15 to stack
184 stmg %r0,%r10,SP_R0(%r15) # store gprs %r0-%r10 to kernel stack
187 .macro RESTORE_ALL psworg,sync
188 mvc \psworg(16),SP_PSW(%r15) # move user PSW to lowcore
190 ni \psworg+1,0xfd # clear wait state bit
192 lg %r14,__LC_VDSO_PER_CPU
193 lmg %r0,%r13,SP_R0(%r15) # load gprs 0-13 of user
195 mvc __VDSO_ECTG_BASE(16,%r14),__LC_EXIT_TIMER
196 lmg %r14,%r15,SP_R14(%r15) # load grps 14-15 of user
197 lpswe \psworg # back to caller
203 stg %r11,__TI_last_break(%r12)
208 mvc __SF_EMPTY(1,%r15),SP_PSW(%r15)
209 ni __SF_EMPTY(%r15),0xbf
213 .section .kprobes.text, "ax"
216 * Scheduler resume function, called by switch_to
217 * gpr2 = (task_struct *) prev
218 * gpr3 = (task_struct *) next
223 lg %r4,__THREAD_info(%r2) # get thread_info of prev
224 lg %r5,__THREAD_info(%r3) # get thread_info of next
225 tm __TI_flags+7(%r4),_TIF_MCCK_PENDING # machine check pending?
227 ni __TI_flags+7(%r4),255-_TIF_MCCK_PENDING # clear flag in prev
228 oi __TI_flags+7(%r5),_TIF_MCCK_PENDING # set it in next
229 0: stmg %r6,%r15,__SF_GPRS(%r15) # store gprs of prev task
230 stg %r15,__THREAD_ksp(%r2) # store kernel stack of prev
231 lg %r15,__THREAD_ksp(%r3) # load kernel stack of next
232 lctl %c4,%c4,__TASK_pid(%r3) # load pid to control reg. 4
233 lmg %r6,%r15,__SF_GPRS(%r15) # load gprs of next task
234 stg %r3,__LC_CURRENT # store task struct of next
235 mvc __LC_CURRENT_PID+4(4,%r0),__TASK_pid(%r3) # store pid of next
236 stg %r5,__LC_THREAD_INFO # store thread info of next
237 aghi %r5,STACK_SIZE # end of kernel stack of next
238 stg %r5,__LC_KERNEL_STACK # store end of kernel stack
243 * SVC interrupt handler routine. System calls are synchronous events and
244 * are executed with interrupts enabled.
248 stpt __LC_SYNC_ENTER_TIMER
250 SAVE_ALL_SVC __LC_SVC_OLD_PSW,__LC_SAVE_AREA
251 CREATE_STACK_FRAME __LC_SAVE_AREA
252 mvc SP_PSW(16,%r15),__LC_SVC_OLD_PSW
253 mvc SP_ILC(4,%r15),__LC_SVC_ILC
254 lg %r12,__LC_THREAD_INFO # load pointer to thread_info struct
256 UPDATE_VTIME __LC_EXIT_TIMER,__LC_SYNC_ENTER_TIMER,__LC_USER_TIMER
258 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
260 mvc __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
263 llgh %r7,SP_SVCNR(%r15)
264 slag %r7,%r7,2 # shift and test for svc 0
266 # svc 0: system call number in %r1
267 llgfr %r1,%r1 # clear high word in r1
270 sth %r1,SP_SVCNR(%r15)
271 slag %r7,%r1,2 # shift and test for svc 0
273 larl %r10,sys_call_table
275 tm __TI_flags+5(%r12),(_TIF_31BIT>>16) # running in 31 bit mode ?
277 larl %r10,sys_call_table_emu # use 31 bit emulation system calls
280 tm __TI_flags+6(%r12),_TIF_SYSCALL
281 mvc SP_ARGS(8,%r15),SP_R7(%r15)
282 lgf %r8,0(%r7,%r10) # load address of system call routine
284 basr %r14,%r8 # call sys_xxxx
285 stg %r2,SP_R2(%r15) # store return value (change R2 on stack)
290 tm __TI_flags+7(%r12),_TIF_WORK_SVC
291 jnz sysc_work # there is work to do (signals etc.)
293 RESTORE_ALL __LC_RETURN_PSW,1
297 # There is work to do, but first we need to check if we return to userspace.
300 tm SP_PSW+1(%r15),0x01 # returning to user ?
304 # One of the work bits is on. Find out which one.
307 tm __TI_flags+7(%r12),_TIF_MCCK_PENDING
309 tm __TI_flags+7(%r12),_TIF_NEED_RESCHED
311 tm __TI_flags+7(%r12),_TIF_SIGPENDING
313 tm __TI_flags+7(%r12),_TIF_NOTIFY_RESUME
314 jo sysc_notify_resume
315 tm __TI_flags+7(%r12),_TIF_RESTART_SVC
317 tm __TI_flags+7(%r12),_TIF_PER_TRAP
319 j sysc_return # beware of critical section cleanup
322 # _TIF_NEED_RESCHED is set, call schedule
325 larl %r14,sysc_return
326 jg schedule # return point is sysc_return
329 # _TIF_MCCK_PENDING is set, call handler
332 larl %r14,sysc_return
333 jg s390_handle_mcck # TIF bit will be cleared by handler
336 # _TIF_SIGPENDING is set, call do_signal
339 ni __TI_flags+7(%r12),255-_TIF_PER_TRAP # clear TIF_PER_TRAP
340 la %r2,SP_PTREGS(%r15) # load pt_regs
341 brasl %r14,do_signal # call do_signal
342 tm __TI_flags+7(%r12),_TIF_RESTART_SVC
344 tm __TI_flags+7(%r12),_TIF_PER_TRAP
349 # _TIF_NOTIFY_RESUME is set, call do_notify_resume
352 la %r2,SP_PTREGS(%r15) # load pt_regs
353 larl %r14,sysc_return
354 jg do_notify_resume # call do_notify_resume
357 # _TIF_RESTART_SVC is set, set up registers and restart svc
360 ni __TI_flags+7(%r12),255-_TIF_RESTART_SVC # clear TIF_RESTART_SVC
361 lg %r7,SP_R2(%r15) # load new svc number
362 mvc SP_R2(8,%r15),SP_ORIG_R2(%r15) # restore first argument
363 lmg %r2,%r6,SP_R2(%r15) # load svc arguments
364 sth %r7,SP_SVCNR(%r15)
366 j sysc_nr_ok # restart svc
369 # _TIF_PER_TRAP is set, call do_per_trap
372 ni __TI_flags+7(%r12),255-_TIF_PER_TRAP # clear TIF_PER_TRAP
373 xc SP_SVCNR(2,%r15),SP_SVCNR(%r15) # clear svc number
374 la %r2,SP_PTREGS(%r15) # address of register-save area
375 larl %r14,sysc_return # load adr. of system return
379 # call tracehook_report_syscall_entry/tracehook_report_syscall_exit before
380 # and after the system call
383 la %r2,SP_PTREGS(%r15) # load pt_regs
385 llgh %r0,SP_SVCNR(%r15)
387 brasl %r14,do_syscall_trace_enter
391 sllg %r7,%r2,2 # svc number *4
394 lmg %r3,%r6,SP_R3(%r15)
395 mvc SP_ARGS(8,%r15),SP_R7(%r15)
396 lg %r2,SP_ORIG_R2(%r15)
397 basr %r14,%r8 # call sys_xxx
398 stg %r2,SP_R2(%r15) # store return value
400 tm __TI_flags+6(%r12),_TIF_SYSCALL
402 la %r2,SP_PTREGS(%r15) # load pt_regs
403 larl %r14,sysc_return # return point is sysc_return
404 jg do_syscall_trace_exit
407 # a new process exits the kernel with ret_from_fork
410 lg %r13,__LC_SVC_NEW_PSW+8
411 lg %r12,__LC_THREAD_INFO # load pointer to thread_info struct
412 tm SP_PSW+1(%r15),0x01 # forking a kernel thread ?
414 stg %r15,SP_R15(%r15) # store stack pointer for new kthread
415 0: brasl %r14,schedule_tail
417 stosm 24(%r15),0x03 # reenable interrupts
421 # kernel_execve function needs to deal with pt_regs that is not
425 stmg %r12,%r15,96(%r15)
428 stg %r14,__SF_BACKCHAIN(%r15)
429 la %r12,SP_PTREGS(%r15)
430 xc 0(__PT_SIZE,%r12),0(%r12)
436 lmg %r12,%r15,96(%r15)
439 0: stnsm __SF_EMPTY(%r15),0xfc # disable interrupts
440 lg %r15,__LC_KERNEL_STACK # load ksp
441 aghi %r15,-SP_SIZE # make room for registers & psw
442 lg %r13,__LC_SVC_NEW_PSW+8
443 mvc SP_PTREGS(__PT_SIZE,%r15),0(%r12) # copy pt_regs
444 lg %r12,__LC_THREAD_INFO
445 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
446 stosm __SF_EMPTY(%r15),0x03 # reenable interrupts
447 brasl %r14,execve_tail
451 * Program check handler routine
454 ENTRY(pgm_check_handler)
456 * First we need to check for a special case:
457 * Single stepping an instruction that disables the PER event mask will
458 * cause a PER event AFTER the mask has been set. Example: SVC or LPSW.
459 * For a single stepped SVC the program check handler gets control after
460 * the SVC new PSW has been loaded. But we want to execute the SVC first and
461 * then handle the PER event. Therefore we update the SVC old PSW to point
462 * to the pgm_check_handler and branch to the SVC handler after we checked
463 * if we have to load the kernel stack register.
464 * For every other possible cause for PER event without the PER mask set
465 * we just ignore the PER event (FIXME: is there anything we have to do
468 stpt __LC_SYNC_ENTER_TIMER
469 tm __LC_PGM_INT_CODE+1,0x80 # check whether we got a per exception
470 jnz pgm_per # got per exception -> special case
471 SAVE_ALL_PGM __LC_PGM_OLD_PSW,__LC_SAVE_AREA
472 CREATE_STACK_FRAME __LC_SAVE_AREA
473 xc SP_ILC(4,%r15),SP_ILC(%r15)
474 mvc SP_PSW(16,%r15),__LC_PGM_OLD_PSW
475 lg %r12,__LC_THREAD_INFO # load pointer to thread_info struct
477 tm SP_PSW+1(%r15),0x01 # interrupting from user ?
479 UPDATE_VTIME __LC_EXIT_TIMER,__LC_SYNC_ENTER_TIMER,__LC_USER_TIMER
480 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
481 mvc __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
484 stg %r11,SP_ARGS(%r15)
485 lgf %r3,__LC_PGM_ILC # load program interruption code
486 lg %r4,__LC_TRANS_EXC_CODE
491 larl %r1,pgm_check_table
492 lg %r1,0(%r8,%r1) # load address of handler routine
493 la %r2,SP_PTREGS(%r15) # address of register-save area
494 basr %r14,%r1 # branch to interrupt-handler
499 # handle per exception
502 tm __LC_PGM_OLD_PSW,0x40 # test if per event recording is on
503 jnz pgm_per_std # ok, normal per event from user space
504 # ok its one of the special cases, now we need to find out which one
505 clc __LC_PGM_OLD_PSW(16),__LC_SVC_NEW_PSW
507 # no interesting special case, ignore PER event
508 lpswe __LC_PGM_OLD_PSW
511 # Normal per exception
514 SAVE_ALL_PGM __LC_PGM_OLD_PSW,__LC_SAVE_AREA
515 CREATE_STACK_FRAME __LC_SAVE_AREA
516 mvc SP_PSW(16,%r15),__LC_PGM_OLD_PSW
517 lg %r12,__LC_THREAD_INFO # load pointer to thread_info struct
519 tm SP_PSW+1(%r15),0x01 # interrupting from user ?
521 UPDATE_VTIME __LC_EXIT_TIMER,__LC_SYNC_ENTER_TIMER,__LC_USER_TIMER
522 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
523 mvc __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
526 lg %r1,__TI_task(%r12)
527 tm SP_PSW+1(%r15),0x01 # kernel per event ?
529 mvc __THREAD_per_cause(2,%r1),__LC_PER_CAUSE
530 mvc __THREAD_per_address(8,%r1),__LC_PER_ADDRESS
531 mvc __THREAD_per_paid(1,%r1),__LC_PER_PAID
532 oi __TI_flags+7(%r12),_TIF_PER_TRAP # set TIF_PER_TRAP
533 lgf %r3,__LC_PGM_ILC # load program interruption code
534 lg %r4,__LC_TRANS_EXC_CODE
537 ngr %r8,%r3 # clear per-event-bit and ilc
540 larl %r1,pgm_check_table
541 lg %r1,0(%r8,%r1) # load address of handler routine
542 la %r2,SP_PTREGS(%r15) # address of register-save area
543 basr %r14,%r1 # branch to interrupt-handler
548 # it was a single stepped SVC that is causing all the trouble
551 SAVE_ALL_PGM __LC_SVC_OLD_PSW,__LC_SAVE_AREA
552 CREATE_STACK_FRAME __LC_SAVE_AREA
553 mvc SP_PSW(16,%r15),__LC_SVC_OLD_PSW
554 mvc SP_ILC(4,%r15),__LC_SVC_ILC
555 lg %r12,__LC_THREAD_INFO # load pointer to thread_info struct
556 UPDATE_VTIME __LC_EXIT_TIMER,__LC_SYNC_ENTER_TIMER,__LC_USER_TIMER
557 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
558 mvc __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
560 lg %r8,__TI_task(%r12)
561 mvc __THREAD_per_cause(2,%r8),__LC_PER_CAUSE
562 mvc __THREAD_per_address(8,%r8),__LC_PER_ADDRESS
563 mvc __THREAD_per_paid(1,%r8),__LC_PER_PAID
564 oi __TI_flags+7(%r12),_TIF_PER_TRAP # set TIF_PER_TRAP
565 stosm __SF_EMPTY(%r15),0x03 # reenable interrupts
566 lmg %r2,%r6,SP_R2(%r15) # load svc arguments
570 # per was called from kernel, must be kprobes
574 xc SP_SVCNR(2,%r15),SP_SVCNR(%r15) # clear svc number
575 la %r2,SP_PTREGS(%r15) # address of register-save area
576 brasl %r14,do_per_trap
580 * IO interrupt handler routine
582 ENTRY(io_int_handler)
584 stpt __LC_ASYNC_ENTER_TIMER
585 SAVE_ALL_ASYNC __LC_IO_OLD_PSW,__LC_SAVE_AREA+40
586 CREATE_STACK_FRAME __LC_SAVE_AREA+40
587 mvc SP_PSW(16,%r15),0(%r12) # move user PSW to stack
588 lg %r12,__LC_THREAD_INFO # load pointer to thread_info struct
590 tm SP_PSW+1(%r15),0x01 # interrupting from user ?
592 UPDATE_VTIME __LC_EXIT_TIMER,__LC_ASYNC_ENTER_TIMER,__LC_USER_TIMER
593 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
594 mvc __LC_LAST_UPDATE_TIMER(8),__LC_ASYNC_ENTER_TIMER
598 la %r2,SP_PTREGS(%r15) # address of register-save area
599 brasl %r14,do_IRQ # call standard irq handler
604 tm __TI_flags+7(%r12),_TIF_WORK_INT
605 jnz io_work # there is work to do (signals etc.)
607 RESTORE_ALL __LC_RETURN_PSW,0
611 # There is work todo, find out in which context we have been interrupted:
612 # 1) if we return to user space we can do all _TIF_WORK_INT work
613 # 2) if we return to kernel code and kvm is enabled check if we need to
614 # modify the psw to leave SIE
615 # 3) if we return to kernel code and preemptive scheduling is enabled check
616 # the preemption counter and if it is zero call preempt_schedule_irq
617 # Before any work can be done, a switch to the kernel stack is required.
620 tm SP_PSW+1(%r15),0x01 # returning to user ?
621 jo io_work_user # yes -> do resched & signal
622 #ifdef CONFIG_PREEMPT
623 # check for preemptive scheduling
624 icm %r0,15,__TI_precount(%r12)
625 jnz io_restore # preemption is disabled
626 tm __TI_flags+7(%r12),_TIF_NEED_RESCHED
628 # switch to kernel stack
631 mvc SP_PTREGS(__PT_SIZE,%r1),SP_PTREGS(%r15)
632 xc __SF_BACKCHAIN(8,%r1),__SF_BACKCHAIN(%r1) # clear back chain
634 # TRACE_IRQS_ON already done at io_return, call
635 # TRACE_IRQS_OFF to keep things symmetrical
637 brasl %r14,preempt_schedule_irq
644 # Need to do work before returning to userspace, switch to kernel stack
647 lg %r1,__LC_KERNEL_STACK
649 mvc SP_PTREGS(__PT_SIZE,%r1),SP_PTREGS(%r15)
650 xc __SF_BACKCHAIN(8,%r1),__SF_BACKCHAIN(%r1) # clear back chain
654 # One of the work bits is on. Find out which one.
655 # Checked are: _TIF_SIGPENDING, _TIF_NOTIFY_RESUME, _TIF_NEED_RESCHED
656 # and _TIF_MCCK_PENDING
659 tm __TI_flags+7(%r12),_TIF_MCCK_PENDING
661 tm __TI_flags+7(%r12),_TIF_NEED_RESCHED
663 tm __TI_flags+7(%r12),_TIF_SIGPENDING
665 tm __TI_flags+7(%r12),_TIF_NOTIFY_RESUME
667 j io_return # beware of critical section cleanup
670 # _TIF_MCCK_PENDING is set, call handler
673 # TRACE_IRQS_ON already done at io_return
674 brasl %r14,s390_handle_mcck # TIF bit will be cleared by handler
679 # _TIF_NEED_RESCHED is set, call schedule
682 # TRACE_IRQS_ON already done at io_return
683 stosm __SF_EMPTY(%r15),0x03 # reenable interrupts
684 brasl %r14,schedule # call scheduler
685 stnsm __SF_EMPTY(%r15),0xfc # disable I/O and ext. interrupts
690 # _TIF_SIGPENDING or is set, call do_signal
693 # TRACE_IRQS_ON already done at io_return
694 stosm __SF_EMPTY(%r15),0x03 # reenable interrupts
695 la %r2,SP_PTREGS(%r15) # load pt_regs
696 brasl %r14,do_signal # call do_signal
697 stnsm __SF_EMPTY(%r15),0xfc # disable I/O and ext. interrupts
702 # _TIF_NOTIFY_RESUME or is set, call do_notify_resume
705 # TRACE_IRQS_ON already done at io_return
706 stosm __SF_EMPTY(%r15),0x03 # reenable interrupts
707 la %r2,SP_PTREGS(%r15) # load pt_regs
708 brasl %r14,do_notify_resume # call do_notify_resume
709 stnsm __SF_EMPTY(%r15),0xfc # disable I/O and ext. interrupts
714 * External interrupt handler routine
716 ENTRY(ext_int_handler)
718 stpt __LC_ASYNC_ENTER_TIMER
719 SAVE_ALL_ASYNC __LC_EXT_OLD_PSW,__LC_SAVE_AREA+40
720 CREATE_STACK_FRAME __LC_SAVE_AREA+40
721 mvc SP_PSW(16,%r15),0(%r12) # move user PSW to stack
722 lg %r12,__LC_THREAD_INFO # load pointer to thread_info struct
724 tm SP_PSW+1(%r15),0x01 # interrupting from user ?
726 UPDATE_VTIME __LC_EXIT_TIMER,__LC_ASYNC_ENTER_TIMER,__LC_USER_TIMER
727 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
728 mvc __LC_LAST_UPDATE_TIMER(8),__LC_ASYNC_ENTER_TIMER
733 la %r2,SP_PTREGS(%r15) # address of register-save area
734 llgf %r3,__LC_CPU_ADDRESS # get cpu address + interruption code
735 llgf %r4,__LC_EXT_PARAMS # get external parameter
736 lg %r5,__LC_EXT_PARAMS2-4096(%r1) # get 64 bit external parameter
743 * Machine check handler routines
745 ENTRY(mcck_int_handler)
747 la %r1,4095 # revalidate r1
748 spt __LC_CPU_TIMER_SAVE_AREA-4095(%r1) # revalidate cpu timer
749 lmg %r0,%r15,__LC_GPREGS_SAVE_AREA-4095(%r1)# revalidate gprs
750 stmg %r11,%r15,__LC_SAVE_AREA+80
751 larl %r13,system_call
752 lg %r11,__LC_LAST_BREAK
753 la %r12,__LC_MCK_OLD_PSW
754 tm __LC_MCCK_CODE,0x80 # system damage?
755 jo mcck_int_main # yes -> rest of mcck code invalid
757 mvc __LC_MCCK_ENTER_TIMER(8),__LC_CPU_TIMER_SAVE_AREA-4095(%r14)
758 tm __LC_MCCK_CODE+5,0x02 # stored cpu timer value valid?
760 la %r14,__LC_SYNC_ENTER_TIMER
761 clc 0(8,%r14),__LC_ASYNC_ENTER_TIMER
763 la %r14,__LC_ASYNC_ENTER_TIMER
764 0: clc 0(8,%r14),__LC_EXIT_TIMER
766 la %r14,__LC_EXIT_TIMER
767 0: clc 0(8,%r14),__LC_LAST_UPDATE_TIMER
769 la %r14,__LC_LAST_UPDATE_TIMER
771 mvc __LC_MCCK_ENTER_TIMER(8),0(%r14)
772 1: tm __LC_MCCK_CODE+2,0x09 # mwp + ia of old psw valid?
773 jno mcck_int_main # no -> skip cleanup critical
774 tm __LC_MCK_OLD_PSW+1,0x01 # test problem state bit
775 jnz mcck_int_main # from user -> load kernel stack
776 clc __LC_MCK_OLD_PSW+8(8),BASED(.Lcritical_end)
778 clc __LC_MCK_OLD_PSW+8(8),BASED(.Lcritical_start)
780 brasl %r14,cleanup_critical
782 lg %r14,__LC_PANIC_STACK # are we already on the panic stack?
784 srag %r14,%r14,PAGE_SHIFT
786 lg %r15,__LC_PANIC_STACK # load panic stack
787 0: aghi %r15,-SP_SIZE # make room for registers & psw
788 CREATE_STACK_FRAME __LC_SAVE_AREA+80
789 mvc SP_PSW(16,%r15),0(%r12)
790 lg %r12,__LC_THREAD_INFO # load pointer to thread_info struct
791 tm __LC_MCCK_CODE+2,0x08 # mwp of old psw valid?
792 jno mcck_no_vtime # no -> no timer update
794 tm SP_PSW+1(%r15),0x01 # interrupting from user ?
796 UPDATE_VTIME __LC_EXIT_TIMER,__LC_MCCK_ENTER_TIMER,__LC_USER_TIMER
797 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
798 mvc __LC_LAST_UPDATE_TIMER(8),__LC_MCCK_ENTER_TIMER
801 la %r2,SP_PTREGS(%r15) # load pt_regs
802 brasl %r14,s390_do_machine_check
803 tm SP_PSW+1(%r15),0x01 # returning to user ?
805 lg %r1,__LC_KERNEL_STACK # switch to kernel stack
807 mvc SP_PTREGS(__PT_SIZE,%r1),SP_PTREGS(%r15)
808 xc __SF_BACKCHAIN(8,%r1),__SF_BACKCHAIN(%r1) # clear back chain
810 stosm __SF_EMPTY(%r15),0x04 # turn dat on
811 tm __TI_flags+7(%r12),_TIF_MCCK_PENDING
814 brasl %r14,s390_handle_mcck
817 mvc __LC_RETURN_MCCK_PSW(16),SP_PSW(%r15) # move return PSW
818 ni __LC_RETURN_MCCK_PSW+1,0xfd # clear wait state bit
819 lmg %r0,%r15,SP_R0(%r15) # load gprs 0-15
820 tm __LC_RETURN_MCCK_PSW+1,0x01 # returning to user ?
823 0: lpswe __LC_RETURN_MCCK_PSW # back to caller
827 * Restart interruption handler, kick starter for additional CPUs
831 ENTRY(restart_int_handler)
834 spt restart_vtime-restart_base(%r1)
835 stck __LC_LAST_UPDATE_CLOCK
836 mvc __LC_LAST_UPDATE_TIMER(8),restart_vtime-restart_base(%r1)
837 mvc __LC_EXIT_TIMER(8),restart_vtime-restart_base(%r1)
838 lg %r15,__LC_SAVE_AREA+120 # load ksp
839 lghi %r10,__LC_CREGS_SAVE_AREA
840 lctlg %c0,%c15,0(%r10) # get new ctl regs
841 lghi %r10,__LC_AREGS_SAVE_AREA
843 lmg %r6,%r15,__SF_GPRS(%r15) # load registers from clone
844 lg %r1,__LC_THREAD_INFO
845 mvc __LC_USER_TIMER(8),__TI_user_timer(%r1)
846 mvc __LC_SYSTEM_TIMER(8),__TI_system_timer(%r1)
847 xc __LC_STEAL_TIMER(8),__LC_STEAL_TIMER
848 stosm __SF_EMPTY(%r15),0x04 # now we can turn dat on
849 brasl %r14,start_secondary
852 .long 0x7fffffff,0xffffffff
856 * If we do not run with SMP enabled, let the new CPU crash ...
858 ENTRY(restart_int_handler)
861 lpswe restart_crash-restart_base(%r1)
864 .long 0x000a0000,0x00000000,0x00000000,0x00000000
869 # PSW restart interrupt handler
871 ENTRY(psw_restart_int_handler)
872 stg %r15,__LC_SAVE_AREA_64(%r0) # save r15
873 larl %r15,restart_stack # load restart stack
875 aghi %r15,-SP_SIZE # make room for pt_regs
876 stmg %r0,%r14,SP_R0(%r15) # store gprs %r0-%r14 to stack
877 mvc SP_R15(8,%r15),__LC_SAVE_AREA_64(%r0)# store saved %r15 to stack
878 mvc SP_PSW(16,%r15),__LC_RST_OLD_PSW(%r0)# store restart old psw
879 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15) # set backchain to 0
880 brasl %r14,do_restart
882 larl %r14,restart_psw_crash # load disabled wait PSW if
883 lpswe 0(%r14) # do_restart returns
886 .quad 0x0002000080000000,0x0000000000000000 + restart_psw_crash
888 .section .kprobes.text, "ax"
890 #ifdef CONFIG_CHECK_STACK
892 * The synchronous or the asynchronous stack overflowed. We are dead.
893 * No need to properly save the registers, we are going to panic anyway.
894 * Setup a pt_regs so that show_trace can provide a good call trace.
897 lg %r15,__LC_PANIC_STACK # change to panic stack
899 mvc SP_PSW(16,%r15),0(%r12) # move user PSW to stack
900 stmg %r0,%r10,SP_R0(%r15) # store gprs %r0-%r10 to kernel stack
901 la %r1,__LC_SAVE_AREA
902 chi %r12,__LC_SVC_OLD_PSW
904 chi %r12,__LC_PGM_OLD_PSW
906 la %r1,__LC_SAVE_AREA+40
907 0: mvc SP_R11(40,%r15),0(%r1) # move %r11-%r15 to stack
908 mvc SP_ARGS(8,%r15),__LC_LAST_BREAK
909 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15) # clear back chain
910 la %r2,SP_PTREGS(%r15) # load pt_regs
911 jg kernel_stack_overflow
914 cleanup_table_system_call:
915 .quad system_call, sysc_do_svc
916 cleanup_table_sysc_tif:
917 .quad sysc_tif, sysc_restore
918 cleanup_table_sysc_restore:
919 .quad sysc_restore, sysc_done
920 cleanup_table_io_tif:
921 .quad io_tif, io_restore
922 cleanup_table_io_restore:
923 .quad io_restore, io_done
926 clc 8(8,%r12),BASED(cleanup_table_system_call)
928 clc 8(8,%r12),BASED(cleanup_table_system_call+8)
929 jl cleanup_system_call
931 clc 8(8,%r12),BASED(cleanup_table_sysc_tif)
933 clc 8(8,%r12),BASED(cleanup_table_sysc_tif+8)
936 clc 8(8,%r12),BASED(cleanup_table_sysc_restore)
938 clc 8(8,%r12),BASED(cleanup_table_sysc_restore+8)
939 jl cleanup_sysc_restore
941 clc 8(8,%r12),BASED(cleanup_table_io_tif)
943 clc 8(8,%r12),BASED(cleanup_table_io_tif+8)
946 clc 8(8,%r12),BASED(cleanup_table_io_restore)
948 clc 8(8,%r12),BASED(cleanup_table_io_restore+8)
949 jl cleanup_io_restore
954 mvc __LC_RETURN_PSW(16),0(%r12)
955 clc __LC_RETURN_PSW+8(8),BASED(cleanup_system_call_insn+8)
957 mvc __LC_SYNC_ENTER_TIMER(8),__LC_MCCK_ENTER_TIMER
958 cghi %r12,__LC_MCK_OLD_PSW
960 mvc __LC_SYNC_ENTER_TIMER(8),__LC_ASYNC_ENTER_TIMER
961 0: cghi %r12,__LC_MCK_OLD_PSW
962 la %r12,__LC_SAVE_AREA+80
964 la %r12,__LC_SAVE_AREA+40
965 0: clc __LC_RETURN_PSW+8(8),BASED(cleanup_system_call_insn+16)
967 clc __LC_RETURN_PSW+8(8),BASED(cleanup_system_call_insn)
969 mvc __LC_SAVE_AREA(40),0(%r12)
970 0: lg %r15,__LC_KERNEL_STACK # problem state -> load ksp
971 aghi %r15,-SP_SIZE # make room for registers & psw
974 CREATE_STACK_FRAME __LC_SAVE_AREA
975 mvc SP_PSW(16,%r15),__LC_SVC_OLD_PSW
976 mvc SP_ILC(4,%r15),__LC_SVC_ILC
977 mvc 8(8,%r12),__LC_THREAD_INFO
979 clc __LC_RETURN_PSW+8(8),BASED(cleanup_system_call_insn+24)
981 UPDATE_VTIME __LC_EXIT_TIMER,__LC_SYNC_ENTER_TIMER,__LC_USER_TIMER
983 clc __LC_RETURN_PSW+8(8),BASED(cleanup_system_call_insn+32)
985 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
987 mvc __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
989 lg %r12,__LC_THREAD_INFO
991 stg %r11,__TI_last_break(%r12)
992 0: mvc __LC_RETURN_PSW+8(8),BASED(cleanup_table_system_call+8)
993 la %r12,__LC_RETURN_PSW
995 cleanup_system_call_insn:
1003 mvc __LC_RETURN_PSW(8),0(%r12)
1004 mvc __LC_RETURN_PSW+8(8),BASED(cleanup_table_sysc_tif)
1005 la %r12,__LC_RETURN_PSW
1008 cleanup_sysc_restore:
1009 clc 8(8,%r12),BASED(cleanup_sysc_restore_insn)
1011 clc 8(8,%r12),BASED(cleanup_sysc_restore_insn+8)
1013 mvc __LC_EXIT_TIMER(8),__LC_MCCK_ENTER_TIMER
1014 cghi %r12,__LC_MCK_OLD_PSW
1016 mvc __LC_EXIT_TIMER(8),__LC_ASYNC_ENTER_TIMER
1017 0: mvc __LC_RETURN_PSW(16),SP_PSW(%r15)
1018 cghi %r12,__LC_MCK_OLD_PSW
1019 la %r12,__LC_SAVE_AREA+80
1021 la %r12,__LC_SAVE_AREA+40
1022 1: mvc 0(40,%r12),SP_R11(%r15)
1023 lmg %r0,%r10,SP_R0(%r15)
1024 lg %r15,SP_R15(%r15)
1025 2: la %r12,__LC_RETURN_PSW
1027 cleanup_sysc_restore_insn:
1029 .quad sysc_done - 16
1032 mvc __LC_RETURN_PSW(8),0(%r12)
1033 mvc __LC_RETURN_PSW+8(8),BASED(cleanup_table_io_tif)
1034 la %r12,__LC_RETURN_PSW
1038 clc 8(8,%r12),BASED(cleanup_io_restore_insn)
1040 clc 8(8,%r12),BASED(cleanup_io_restore_insn+8)
1042 mvc __LC_EXIT_TIMER(8),__LC_MCCK_ENTER_TIMER
1043 0: mvc __LC_RETURN_PSW(16),SP_PSW(%r15)
1044 mvc __LC_SAVE_AREA+80(40),SP_R11(%r15)
1045 lmg %r0,%r10,SP_R0(%r15)
1046 lg %r15,SP_R15(%r15)
1047 1: la %r12,__LC_RETURN_PSW
1049 cleanup_io_restore_insn:
1058 .quad __critical_start
1060 .quad __critical_end
1062 #if defined(CONFIG_KVM) || defined(CONFIG_KVM_MODULE)
1064 * sie64a calling convention:
1065 * %r2 pointer to sie control block
1066 * %r3 guest register save area
1069 stmg %r6,%r14,__SF_GPRS(%r15) # save kernel registers
1070 stg %r2,__SF_EMPTY(%r15) # save control block pointer
1071 stg %r3,__SF_EMPTY+8(%r15) # save guest register save area
1072 lmg %r0,%r13,0(%r3) # load guest gprs 0-13
1073 lg %r14,__LC_THREAD_INFO # pointer thread_info struct
1074 oi __TI_flags+6(%r14),_TIF_SIE>>8
1076 lg %r14,__LC_THREAD_INFO # pointer thread_info struct
1077 tm __TI_flags+7(%r14),_TIF_EXIT_SIE
1079 lg %r14,__SF_EMPTY(%r15) # get control block pointer
1080 SPP __SF_EMPTY(%r15) # set guest id
1083 SPP __LC_CMF_HPP # set host id
1084 lg %r14,__LC_THREAD_INFO # pointer thread_info struct
1086 ni __TI_flags+6(%r14),255-(_TIF_SIE>>8)
1087 lg %r14,__SF_EMPTY+8(%r15) # load guest register save area
1088 stmg %r0,%r13,0(%r14) # save guest gprs 0-13
1089 lmg %r6,%r14,__SF_GPRS(%r15) # restore kernel registers
1093 lg %r14,__LC_THREAD_INFO # pointer thread_info struct
1094 ni __TI_flags+6(%r14),255-(_TIF_SIE>>8)
1095 lg %r14,__SF_EMPTY+8(%r15) # load guest register save area
1096 stmg %r0,%r13,0(%r14) # save guest gprs 0-13
1097 lmg %r6,%r14,__SF_GPRS(%r15) # restore kernel registers
1107 .section __ex_table,"a"
1108 .quad sie_loop,sie_fault
1112 .section .rodata, "a"
1113 #define SYSCALL(esa,esame,emu) .long esame
1114 .globl sys_call_table
1116 #include "syscalls.S"
1119 #ifdef CONFIG_COMPAT
1121 #define SYSCALL(esa,esame,emu) .long emu
1123 #include "syscalls.S"