2 * S390 low-level entry points.
4 * Copyright IBM Corp. 1999, 2012
5 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
6 * Hartmut Penner (hp@de.ibm.com),
7 * Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com),
8 * Heiko Carstens <heiko.carstens@de.ibm.com>
11 #include <linux/init.h>
12 #include <linux/linkage.h>
13 #include <asm/cache.h>
14 #include <asm/errno.h>
15 #include <asm/ptrace.h>
16 #include <asm/thread_info.h>
17 #include <asm/asm-offsets.h>
18 #include <asm/unistd.h>
23 __PT_R1 = __PT_GPRS + 8
24 __PT_R2 = __PT_GPRS + 16
25 __PT_R3 = __PT_GPRS + 24
26 __PT_R4 = __PT_GPRS + 32
27 __PT_R5 = __PT_GPRS + 40
28 __PT_R6 = __PT_GPRS + 48
29 __PT_R7 = __PT_GPRS + 56
30 __PT_R8 = __PT_GPRS + 64
31 __PT_R9 = __PT_GPRS + 72
32 __PT_R10 = __PT_GPRS + 80
33 __PT_R11 = __PT_GPRS + 88
34 __PT_R12 = __PT_GPRS + 96
35 __PT_R13 = __PT_GPRS + 104
36 __PT_R14 = __PT_GPRS + 112
37 __PT_R15 = __PT_GPRS + 120
39 STACK_SHIFT = PAGE_SHIFT + THREAD_ORDER
40 STACK_SIZE = 1 << STACK_SHIFT
42 _TIF_WORK_SVC = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
43 _TIF_MCCK_PENDING | _TIF_PER_TRAP )
44 _TIF_WORK_INT = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
46 _TIF_TRACE = (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SECCOMP | \
47 _TIF_SYSCALL_TRACEPOINT)
48 _TIF_EXIT_SIE = (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_MCCK_PENDING)
50 #define BASED(name) name-system_call(%r13)
53 #ifdef CONFIG_TRACE_IRQFLAGS
55 brasl %r14,trace_hardirqs_on_caller
60 #ifdef CONFIG_TRACE_IRQFLAGS
62 brasl %r14,trace_hardirqs_off_caller
66 .macro LOCKDEP_SYS_EXIT
68 tm __PT_PSW+1(%r11),0x01 # returning to user ?
70 brasl %r14,lockdep_sys_exit
75 #if defined(CONFIG_KVM) || defined(CONFIG_KVM_MODULE)
76 tm __LC_MACHINE_FLAGS+6,0x20 # MACHINE_FLAG_SPP
78 .insn s,0xb2800000,\newpp
82 .macro HANDLE_SIE_INTERCEPT scratch
83 #if defined(CONFIG_KVM) || defined(CONFIG_KVM_MODULE)
84 tmhh %r8,0x0001 # interrupting from user ?
87 slg \scratch,BASED(.Lsie_loop)
88 clg \scratch,BASED(.Lsie_length)
90 lg %r9,BASED(.Lsie_loop)
91 SPP BASED(.Lhost_id) # set host id
95 .macro CHECK_STACK stacksize,savearea
96 #ifdef CONFIG_CHECK_STACK
97 tml %r15,\stacksize - CONFIG_STACK_GUARD
103 .macro SWITCH_ASYNC savearea,stack,shift
104 tmhh %r8,0x0001 # interrupting from user ?
107 slg %r14,BASED(.Lcritical_start)
108 clg %r14,BASED(.Lcritical_length)
110 lghi %r11,\savearea # inside critical section, do cleanup
111 brasl %r14,cleanup_critical
112 tmhh %r8,0x0001 # retest problem state after cleanup
114 0: lg %r14,\stack # are we already on the target stack?
116 srag %r14,%r14,\shift
118 CHECK_STACK 1<<\shift,\savearea
120 1: lg %r15,\stack # load target stack
121 2: aghi %r15,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
122 la %r11,STACK_FRAME_OVERHEAD(%r15)
125 .macro UPDATE_VTIME scratch,enter_timer
126 lg \scratch,__LC_EXIT_TIMER
127 slg \scratch,\enter_timer
128 alg \scratch,__LC_USER_TIMER
129 stg \scratch,__LC_USER_TIMER
130 lg \scratch,__LC_LAST_UPDATE_TIMER
131 slg \scratch,__LC_EXIT_TIMER
132 alg \scratch,__LC_SYSTEM_TIMER
133 stg \scratch,__LC_SYSTEM_TIMER
134 mvc __LC_LAST_UPDATE_TIMER(8),\enter_timer
137 .macro LAST_BREAK scratch
138 srag \scratch,%r10,23
140 stg %r10,__TI_last_break(%r12)
144 stg %r8,__LC_RETURN_PSW
145 ni __LC_RETURN_PSW,0xbf
150 #ifdef CONFIG_HAVE_MARCH_Z9_109_FEATURES
151 .insn s,0xb27c0000,\savearea # store clock fast
153 .insn s,0xb2050000,\savearea # store clock
157 .section .kprobes.text, "ax"
160 * Scheduler resume function, called by switch_to
161 * gpr2 = (task_struct *) prev
162 * gpr3 = (task_struct *) next
167 stmg %r6,%r15,__SF_GPRS(%r15) # store gprs of prev task
168 stg %r15,__THREAD_ksp(%r2) # store kernel stack of prev
169 lg %r4,__THREAD_info(%r2) # get thread_info of prev
170 lg %r5,__THREAD_info(%r3) # get thread_info of next
172 aghi %r15,STACK_SIZE # end of kernel stack of next
173 stg %r3,__LC_CURRENT # store task struct of next
174 stg %r5,__LC_THREAD_INFO # store thread info of next
175 stg %r15,__LC_KERNEL_STACK # store end of kernel stack
176 lctl %c4,%c4,__TASK_pid(%r3) # load pid to control reg. 4
177 mvc __LC_CURRENT_PID+4(4,%r0),__TASK_pid(%r3) # store pid of next
178 lg %r15,__THREAD_ksp(%r3) # load kernel stack of next
179 tm __TI_flags+7(%r4),_TIF_MCCK_PENDING # machine check pending?
181 ni __TI_flags+7(%r4),255-_TIF_MCCK_PENDING # clear flag in prev
182 oi __TI_flags+7(%r5),_TIF_MCCK_PENDING # set it in next
183 0: lmg %r6,%r15,__SF_GPRS(%r15) # load gprs of next task
188 * SVC interrupt handler routine. System calls are synchronous events and
189 * are executed with interrupts enabled.
193 stpt __LC_SYNC_ENTER_TIMER
195 stmg %r8,%r15,__LC_SAVE_AREA_SYNC
196 lg %r10,__LC_LAST_BREAK
197 lg %r12,__LC_THREAD_INFO
198 larl %r13,system_call
200 lg %r15,__LC_KERNEL_STACK
201 aghi %r15,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
202 la %r11,STACK_FRAME_OVERHEAD(%r15) # pointer to pt_regs
204 UPDATE_VTIME %r13,__LC_SYNC_ENTER_TIMER
206 stmg %r0,%r7,__PT_R0(%r11)
207 mvc __PT_R8(64,%r11),__LC_SAVE_AREA_SYNC
208 mvc __PT_PSW(16,%r11),__LC_SVC_OLD_PSW
209 mvc __PT_INT_CODE(4,%r11),__LC_SVC_ILC
211 oi __TI_flags+7(%r12),_TIF_SYSCALL
212 llgh %r8,__PT_INT_CODE+2(%r11)
213 slag %r8,%r8,2 # shift and test for svc 0
215 # svc 0: system call number in %r1
216 llgfr %r1,%r1 # clear high word in r1
219 sth %r1,__PT_INT_CODE+2(%r11)
222 larl %r10,sys_call_table # 64 bit system call table
224 tm __TI_flags+5(%r12),(_TIF_31BIT>>16)
226 larl %r10,sys_call_table_emu # 31 bit system call table
229 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
230 stg %r2,__PT_ORIG_GPR2(%r11)
231 stg %r7,STACK_FRAME_OVERHEAD(%r15)
232 lgf %r9,0(%r8,%r10) # get system call add.
233 tm __TI_flags+6(%r12),_TIF_TRACE >> 8
235 basr %r14,%r9 # call sys_xxxx
236 stg %r2,__PT_R2(%r11) # store return value
241 tm __PT_PSW+1(%r11),0x01 # returning to user ?
243 tm __TI_flags+7(%r12),_TIF_WORK_SVC
244 jnz sysc_work # check for work
245 ni __TI_flags+7(%r12),255-_TIF_SYSCALL
247 lg %r14,__LC_VDSO_PER_CPU
248 lmg %r0,%r10,__PT_R0(%r11)
249 mvc __LC_RETURN_PSW(16),__PT_PSW(%r11)
251 mvc __VDSO_ECTG_BASE(16,%r14),__LC_EXIT_TIMER
252 lmg %r11,%r15,__PT_R11(%r11)
253 lpswe __LC_RETURN_PSW
257 # One of the work bits is on. Find out which one.
260 tm __TI_flags+7(%r12),_TIF_MCCK_PENDING
262 tm __TI_flags+7(%r12),_TIF_NEED_RESCHED
264 tm __TI_flags+7(%r12),_TIF_SIGPENDING
266 tm __TI_flags+7(%r12),_TIF_NOTIFY_RESUME
267 jo sysc_notify_resume
268 tm __TI_flags+7(%r12),_TIF_PER_TRAP
270 j sysc_return # beware of critical section cleanup
273 # _TIF_NEED_RESCHED is set, call schedule
276 larl %r14,sysc_return
280 # _TIF_MCCK_PENDING is set, call handler
283 larl %r14,sysc_return
284 jg s390_handle_mcck # TIF bit will be cleared by handler
287 # _TIF_SIGPENDING is set, call do_signal
290 ni __TI_flags+7(%r12),255-_TIF_PER_TRAP # clear TIF_PER_TRAP
291 lgr %r2,%r11 # pass pointer to pt_regs
293 tm __TI_flags+7(%r12),_TIF_SYSCALL
295 lmg %r2,%r7,__PT_R2(%r11) # load svc arguments
296 lghi %r8,0 # svc 0 returns -ENOSYS
297 lh %r1,__PT_INT_CODE+2(%r11) # load new svc number
299 jnl sysc_nr_ok # invalid svc number -> do svc 0
301 j sysc_nr_ok # restart svc
304 # _TIF_NOTIFY_RESUME is set, call do_notify_resume
307 lgr %r2,%r11 # pass pointer to pt_regs
308 larl %r14,sysc_return
312 # _TIF_PER_TRAP is set, call do_per_trap
315 ni __TI_flags+7(%r12),255-(_TIF_SYSCALL | _TIF_PER_TRAP)
316 lgr %r2,%r11 # pass pointer to pt_regs
317 larl %r14,sysc_return
321 # call tracehook_report_syscall_entry/tracehook_report_syscall_exit before
322 # and after the system call
325 lgr %r2,%r11 # pass pointer to pt_regs
327 llgh %r0,__PT_INT_CODE+2(%r11)
328 stg %r0,__PT_R2(%r11)
329 brasl %r14,do_syscall_trace_enter
336 lmg %r3,%r7,__PT_R3(%r11)
337 stg %r7,STACK_FRAME_OVERHEAD(%r15)
338 lg %r2,__PT_ORIG_GPR2(%r11)
339 basr %r14,%r9 # call sys_xxx
340 stg %r2,__PT_R2(%r11) # store return value
342 tm __TI_flags+6(%r12),_TIF_TRACE >> 8
344 lgr %r2,%r11 # pass pointer to pt_regs
345 larl %r14,sysc_return
346 jg do_syscall_trace_exit
349 # a new process exits the kernel with ret_from_fork
352 la %r11,STACK_FRAME_OVERHEAD(%r15)
353 lg %r12,__LC_THREAD_INFO
354 tm __PT_PSW+1(%r11),0x01 # forking a kernel thread ?
356 stg %r15,__PT_R15(%r11) # store stack pointer for new kthread
357 0: brasl %r14,schedule_tail
359 ssm __LC_SVC_NEW_PSW # reenable interrupts
363 # kernel_execve function needs to deal with pt_regs that is not
367 stmg %r12,%r15,96(%r15)
369 aghi %r15,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
370 stg %r14,__SF_BACKCHAIN(%r15)
371 la %r12,STACK_FRAME_OVERHEAD(%r15)
372 xc 0(__PT_SIZE,%r12),0(%r12)
377 aghi %r15,(STACK_FRAME_OVERHEAD + __PT_SIZE)
378 lmg %r12,%r15,96(%r15)
381 0: ssm __LC_PGM_NEW_PSW # disable I/O and ext. interrupts
382 lg %r15,__LC_KERNEL_STACK # load ksp
383 aghi %r15,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
384 la %r11,STACK_FRAME_OVERHEAD(%r15)
385 mvc 0(__PT_SIZE,%r11),0(%r12) # copy pt_regs
386 lg %r12,__LC_THREAD_INFO
387 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
388 ssm __LC_SVC_NEW_PSW # reenable interrupts
389 brasl %r14,execve_tail
393 * Program check handler routine
396 ENTRY(pgm_check_handler)
397 stpt __LC_SYNC_ENTER_TIMER
398 stmg %r8,%r15,__LC_SAVE_AREA_SYNC
399 lg %r10,__LC_LAST_BREAK
400 lg %r12,__LC_THREAD_INFO
401 larl %r13,system_call
402 lmg %r8,%r9,__LC_PGM_OLD_PSW
403 HANDLE_SIE_INTERCEPT %r14
404 tmhh %r8,0x0001 # test problem state bit
405 jnz 1f # -> fault in user space
406 tmhh %r8,0x4000 # PER bit set in old PSW ?
407 jnz 0f # -> enabled, can't be a double fault
408 tm __LC_PGM_ILC+3,0x80 # check for per exception
409 jnz pgm_svcper # -> single stepped svc
410 0: CHECK_STACK STACK_SIZE,__LC_SAVE_AREA_SYNC
412 1: UPDATE_VTIME %r14,__LC_SYNC_ENTER_TIMER
414 lg %r15,__LC_KERNEL_STACK
415 2: aghi %r15,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
416 la %r11,STACK_FRAME_OVERHEAD(%r15)
417 stmg %r0,%r7,__PT_R0(%r11)
418 mvc __PT_R8(64,%r11),__LC_SAVE_AREA_SYNC
419 stmg %r8,%r9,__PT_PSW(%r11)
420 mvc __PT_INT_CODE(4,%r11),__LC_PGM_ILC
421 mvc __PT_INT_PARM_LONG(8,%r11),__LC_TRANS_EXC_CODE
422 stg %r10,__PT_ARGS(%r11)
423 tm __LC_PGM_ILC+3,0x80 # check for per exception
425 lg %r1,__TI_task(%r12)
426 tmhh %r8,0x0001 # kernel per event ?
428 oi __TI_flags+7(%r12),_TIF_PER_TRAP
429 mvc __THREAD_per_address(8,%r1),__LC_PER_ADDRESS
430 mvc __THREAD_per_cause(2,%r1),__LC_PER_CAUSE
431 mvc __THREAD_per_paid(1,%r1),__LC_PER_PAID
433 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
434 larl %r1,pgm_check_table
435 llgh %r10,__PT_INT_CODE+2(%r11)
439 lg %r1,0(%r10,%r1) # load address of handler routine
440 lgr %r2,%r11 # pass pointer to pt_regs
441 basr %r14,%r1 # branch to interrupt-handler
445 # PER event in supervisor state, must be kprobes
449 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
450 lgr %r2,%r11 # pass pointer to pt_regs
451 brasl %r14,do_per_trap
455 # single stepped system call
458 oi __TI_flags+7(%r12),_TIF_PER_TRAP
459 mvc __LC_RETURN_PSW(8),__LC_SVC_NEW_PSW
461 stg %r14,__LC_RETURN_PSW+8
462 lpswe __LC_RETURN_PSW # branch to sysc_per and enable irqs
465 * IO interrupt handler routine
467 ENTRY(io_int_handler)
469 stpt __LC_ASYNC_ENTER_TIMER
470 stmg %r8,%r15,__LC_SAVE_AREA_ASYNC
471 lg %r10,__LC_LAST_BREAK
472 lg %r12,__LC_THREAD_INFO
473 larl %r13,system_call
474 lmg %r8,%r9,__LC_IO_OLD_PSW
475 HANDLE_SIE_INTERCEPT %r14
476 SWITCH_ASYNC __LC_SAVE_AREA_ASYNC,__LC_ASYNC_STACK,STACK_SHIFT
477 tmhh %r8,0x0001 # interrupting from user?
479 UPDATE_VTIME %r14,__LC_ASYNC_ENTER_TIMER
482 stmg %r0,%r7,__PT_R0(%r11)
483 mvc __PT_R8(64,%r11),__LC_SAVE_AREA_ASYNC
484 stmg %r8,%r9,__PT_PSW(%r11)
486 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
487 lgr %r2,%r11 # pass pointer to pt_regs
493 tm __TI_flags+7(%r12),_TIF_WORK_INT
494 jnz io_work # there is work to do (signals etc.)
496 lg %r14,__LC_VDSO_PER_CPU
497 lmg %r0,%r10,__PT_R0(%r11)
498 mvc __LC_RETURN_PSW(16),__PT_PSW(%r11)
500 mvc __VDSO_ECTG_BASE(16,%r14),__LC_EXIT_TIMER
501 lmg %r11,%r15,__PT_R11(%r11)
502 lpswe __LC_RETURN_PSW
506 # There is work todo, find out in which context we have been interrupted:
507 # 1) if we return to user space we can do all _TIF_WORK_INT work
508 # 2) if we return to kernel code and kvm is enabled check if we need to
509 # modify the psw to leave SIE
510 # 3) if we return to kernel code and preemptive scheduling is enabled check
511 # the preemption counter and if it is zero call preempt_schedule_irq
512 # Before any work can be done, a switch to the kernel stack is required.
515 tm __PT_PSW+1(%r11),0x01 # returning to user ?
516 jo io_work_user # yes -> do resched & signal
517 #ifdef CONFIG_PREEMPT
518 # check for preemptive scheduling
519 icm %r0,15,__TI_precount(%r12)
520 jnz io_restore # preemption is disabled
521 tm __TI_flags+7(%r12),_TIF_NEED_RESCHED
523 # switch to kernel stack
524 lg %r1,__PT_R15(%r11)
525 aghi %r1,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
526 mvc STACK_FRAME_OVERHEAD(__PT_SIZE,%r1),0(%r11)
527 xc __SF_BACKCHAIN(8,%r1),__SF_BACKCHAIN(%r1)
528 la %r11,STACK_FRAME_OVERHEAD(%r1)
530 # TRACE_IRQS_ON already done at io_return, call
531 # TRACE_IRQS_OFF to keep things symmetrical
533 brasl %r14,preempt_schedule_irq
540 # Need to do work before returning to userspace, switch to kernel stack
543 lg %r1,__LC_KERNEL_STACK
544 aghi %r1,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
545 mvc STACK_FRAME_OVERHEAD(__PT_SIZE,%r1),0(%r11)
546 xc __SF_BACKCHAIN(8,%r1),__SF_BACKCHAIN(%r1)
547 la %r11,STACK_FRAME_OVERHEAD(%r1)
551 # One of the work bits is on. Find out which one.
552 # Checked are: _TIF_SIGPENDING, _TIF_NOTIFY_RESUME, _TIF_NEED_RESCHED
553 # and _TIF_MCCK_PENDING
556 tm __TI_flags+7(%r12),_TIF_MCCK_PENDING
558 tm __TI_flags+7(%r12),_TIF_NEED_RESCHED
560 tm __TI_flags+7(%r12),_TIF_SIGPENDING
562 tm __TI_flags+7(%r12),_TIF_NOTIFY_RESUME
564 j io_return # beware of critical section cleanup
567 # _TIF_MCCK_PENDING is set, call handler
570 # TRACE_IRQS_ON already done at io_return
571 brasl %r14,s390_handle_mcck # TIF bit will be cleared by handler
576 # _TIF_NEED_RESCHED is set, call schedule
579 # TRACE_IRQS_ON already done at io_return
580 ssm __LC_SVC_NEW_PSW # reenable interrupts
581 brasl %r14,schedule # call scheduler
582 ssm __LC_PGM_NEW_PSW # disable I/O and ext. interrupts
587 # _TIF_SIGPENDING or is set, call do_signal
590 # TRACE_IRQS_ON already done at io_return
591 ssm __LC_SVC_NEW_PSW # reenable interrupts
592 lgr %r2,%r11 # pass pointer to pt_regs
594 ssm __LC_PGM_NEW_PSW # disable I/O and ext. interrupts
599 # _TIF_NOTIFY_RESUME or is set, call do_notify_resume
602 # TRACE_IRQS_ON already done at io_return
603 ssm __LC_SVC_NEW_PSW # reenable interrupts
604 lgr %r2,%r11 # pass pointer to pt_regs
605 brasl %r14,do_notify_resume
606 ssm __LC_PGM_NEW_PSW # disable I/O and ext. interrupts
611 * External interrupt handler routine
613 ENTRY(ext_int_handler)
615 stpt __LC_ASYNC_ENTER_TIMER
616 stmg %r8,%r15,__LC_SAVE_AREA_ASYNC
617 lg %r10,__LC_LAST_BREAK
618 lg %r12,__LC_THREAD_INFO
619 larl %r13,system_call
620 lmg %r8,%r9,__LC_EXT_OLD_PSW
621 HANDLE_SIE_INTERCEPT %r14
622 SWITCH_ASYNC __LC_SAVE_AREA_ASYNC,__LC_ASYNC_STACK,STACK_SHIFT
623 tmhh %r8,0x0001 # interrupting from user ?
625 UPDATE_VTIME %r14,__LC_ASYNC_ENTER_TIMER
628 stmg %r0,%r7,__PT_R0(%r11)
629 mvc __PT_R8(64,%r11),__LC_SAVE_AREA_ASYNC
630 stmg %r8,%r9,__PT_PSW(%r11)
632 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
634 lgr %r2,%r11 # pass pointer to pt_regs
635 llgf %r3,__LC_EXT_CPU_ADDR # get cpu address + interruption code
636 llgf %r4,__LC_EXT_PARAMS # get external parameter
637 lg %r5,__LC_EXT_PARAMS2-4096(%r1) # get 64 bit external parameter
642 * Load idle PSW. The second "half" of this function is in cleanup_idle.
645 stg %r3,__SF_EMPTY(%r15)
646 larl %r1,psw_idle_lpsw+4
647 stg %r1,__SF_EMPTY+8(%r15)
648 STCK __CLOCK_IDLE_ENTER(%r2)
649 stpt __TIMER_IDLE_ENTER(%r2)
651 lpswe __SF_EMPTY(%r15)
658 * Machine check handler routines
660 ENTRY(mcck_int_handler)
662 la %r1,4095 # revalidate r1
663 spt __LC_CPU_TIMER_SAVE_AREA-4095(%r1) # revalidate cpu timer
664 lmg %r0,%r15,__LC_GPREGS_SAVE_AREA-4095(%r1)# revalidate gprs
665 lg %r10,__LC_LAST_BREAK
666 lg %r12,__LC_THREAD_INFO
667 larl %r13,system_call
668 lmg %r8,%r9,__LC_MCK_OLD_PSW
669 HANDLE_SIE_INTERCEPT %r14
670 tm __LC_MCCK_CODE,0x80 # system damage?
671 jo mcck_panic # yes -> rest of mcck code invalid
672 lghi %r14,__LC_CPU_TIMER_SAVE_AREA
673 mvc __LC_MCCK_ENTER_TIMER(8),0(%r14)
674 tm __LC_MCCK_CODE+5,0x02 # stored cpu timer value valid?
676 la %r14,__LC_SYNC_ENTER_TIMER
677 clc 0(8,%r14),__LC_ASYNC_ENTER_TIMER
679 la %r14,__LC_ASYNC_ENTER_TIMER
680 0: clc 0(8,%r14),__LC_EXIT_TIMER
682 la %r14,__LC_EXIT_TIMER
683 1: clc 0(8,%r14),__LC_LAST_UPDATE_TIMER
685 la %r14,__LC_LAST_UPDATE_TIMER
687 mvc __LC_MCCK_ENTER_TIMER(8),0(%r14)
688 3: tm __LC_MCCK_CODE+2,0x09 # mwp + ia of old psw valid?
689 jno mcck_panic # no -> skip cleanup critical
690 SWITCH_ASYNC __LC_GPREGS_SAVE_AREA+64,__LC_PANIC_STACK,PAGE_SHIFT
691 tm %r8,0x0001 # interrupting from user ?
693 UPDATE_VTIME %r14,__LC_MCCK_ENTER_TIMER
696 lghi %r14,__LC_GPREGS_SAVE_AREA
697 mvc __PT_R0(128,%r11),0(%r14)
698 stmg %r8,%r9,__PT_PSW(%r11)
699 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
700 lgr %r2,%r11 # pass pointer to pt_regs
701 brasl %r14,s390_do_machine_check
702 tm __PT_PSW+1(%r11),0x01 # returning to user ?
704 lg %r1,__LC_KERNEL_STACK # switch to kernel stack
705 aghi %r1,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
706 mvc STACK_FRAME_OVERHEAD(__PT_SIZE,%r1),0(%r11)
707 xc __SF_BACKCHAIN(8,%r1),__SF_BACKCHAIN(%r1)
708 la %r11,STACK_FRAME_OVERHEAD(%r1)
710 ssm __LC_PGM_NEW_PSW # turn dat on, keep irqs off
711 tm __TI_flags+7(%r12),_TIF_MCCK_PENDING
714 brasl %r14,s390_handle_mcck
717 lg %r14,__LC_VDSO_PER_CPU
718 lmg %r0,%r10,__PT_R0(%r11)
719 mvc __LC_RETURN_MCCK_PSW(16),__PT_PSW(%r11) # move return PSW
720 tm __LC_RETURN_MCCK_PSW+1,0x01 # returning to user ?
723 mvc __VDSO_ECTG_BASE(16,%r14),__LC_EXIT_TIMER
724 0: lmg %r11,%r15,__PT_R11(%r11)
725 lpswe __LC_RETURN_MCCK_PSW
728 lg %r14,__LC_PANIC_STACK
730 srag %r14,%r14,PAGE_SHIFT
732 lg %r15,__LC_PANIC_STACK
733 0: aghi %r15,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
737 # PSW restart interrupt handler
739 ENTRY(restart_int_handler)
740 stg %r15,__LC_SAVE_AREA_RESTART
741 lg %r15,__LC_RESTART_STACK
742 aghi %r15,-__PT_SIZE # create pt_regs on stack
743 xc 0(__PT_SIZE,%r15),0(%r15)
744 stmg %r0,%r14,__PT_R0(%r15)
745 mvc __PT_R15(8,%r15),__LC_SAVE_AREA_RESTART
746 mvc __PT_PSW(16,%r15),__LC_RST_OLD_PSW # store restart old psw
747 aghi %r15,-STACK_FRAME_OVERHEAD # create stack frame on stack
748 xc 0(STACK_FRAME_OVERHEAD,%r15),0(%r15)
749 lg %r1,__LC_RESTART_FN # load fn, parm & source cpu
750 lg %r2,__LC_RESTART_DATA
751 lg %r3,__LC_RESTART_SOURCE
752 ltgr %r3,%r3 # test source cpu address
753 jm 1f # negative -> skip source stop
754 0: sigp %r4,%r3,SIGP_SENSE # sigp sense to source cpu
755 brc 10,0b # wait for status stored
756 1: basr %r14,%r1 # call function
757 stap __SF_EMPTY(%r15) # store cpu address
758 llgh %r3,__SF_EMPTY(%r15)
759 2: sigp %r4,%r3,SIGP_STOP # sigp stop to current cpu
763 .section .kprobes.text, "ax"
765 #ifdef CONFIG_CHECK_STACK
767 * The synchronous or the asynchronous stack overflowed. We are dead.
768 * No need to properly save the registers, we are going to panic anyway.
769 * Setup a pt_regs so that show_trace can provide a good call trace.
772 lg %r11,__LC_PANIC_STACK # change to panic stack
773 aghi %r11,-__PT_SIZE # create pt_regs
774 stmg %r0,%r7,__PT_R0(%r11)
775 stmg %r8,%r9,__PT_PSW(%r11)
776 mvc __PT_R8(64,%r11),0(%r14)
777 stg %r10,__PT_ORIG_GPR2(%r11) # store last break to orig_gpr2
779 aghi %r15,-STACK_FRAME_OVERHEAD
780 xc __SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
781 lgr %r2,%r11 # pass pointer to pt_regs
782 jg kernel_stack_overflow
799 clg %r9,BASED(cleanup_table) # system_call
801 clg %r9,BASED(cleanup_table+8) # sysc_do_svc
802 jl cleanup_system_call
803 clg %r9,BASED(cleanup_table+16) # sysc_tif
805 clg %r9,BASED(cleanup_table+24) # sysc_restore
807 clg %r9,BASED(cleanup_table+32) # sysc_done
808 jl cleanup_sysc_restore
809 clg %r9,BASED(cleanup_table+40) # io_tif
811 clg %r9,BASED(cleanup_table+48) # io_restore
813 clg %r9,BASED(cleanup_table+56) # io_done
814 jl cleanup_io_restore
815 clg %r9,BASED(cleanup_table+64) # psw_idle
817 clg %r9,BASED(cleanup_table+72) # psw_idle_end
823 # check if stpt has been executed
824 clg %r9,BASED(cleanup_system_call_insn)
826 mvc __LC_SYNC_ENTER_TIMER(8),__LC_ASYNC_ENTER_TIMER
827 cghi %r11,__LC_SAVE_AREA_ASYNC
829 mvc __LC_SYNC_ENTER_TIMER(8),__LC_MCCK_ENTER_TIMER
830 0: # check if stmg has been executed
831 clg %r9,BASED(cleanup_system_call_insn+8)
833 mvc __LC_SAVE_AREA_SYNC(64),0(%r11)
834 0: # check if base register setup + TIF bit load has been done
835 clg %r9,BASED(cleanup_system_call_insn+16)
837 # set up saved registers r10 and r12
838 stg %r10,16(%r11) # r10 last break
839 stg %r12,32(%r11) # r12 thread-info pointer
840 0: # check if the user time update has been done
841 clg %r9,BASED(cleanup_system_call_insn+24)
843 lg %r15,__LC_EXIT_TIMER
844 slg %r15,__LC_SYNC_ENTER_TIMER
845 alg %r15,__LC_USER_TIMER
846 stg %r15,__LC_USER_TIMER
847 0: # check if the system time update has been done
848 clg %r9,BASED(cleanup_system_call_insn+32)
850 lg %r15,__LC_LAST_UPDATE_TIMER
851 slg %r15,__LC_EXIT_TIMER
852 alg %r15,__LC_SYSTEM_TIMER
853 stg %r15,__LC_SYSTEM_TIMER
854 0: # update accounting time stamp
855 mvc __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
860 mvc __TI_last_break(8,%r12),16(%r11)
861 0: # set up saved register r11
862 lg %r15,__LC_KERNEL_STACK
864 stg %r15,24(%r11) # r11 pt_regs pointer
866 mvc __PT_R8(64,%r15),__LC_SAVE_AREA_SYNC
867 stmg %r0,%r7,__PT_R0(%r15)
868 mvc __PT_PSW(16,%r15),__LC_SVC_OLD_PSW
869 mvc __PT_INT_CODE(4,%r15),__LC_SVC_ILC
870 # setup saved register r15
871 aghi %r15,-STACK_FRAME_OVERHEAD
872 stg %r15,56(%r11) # r15 stack pointer
873 # set new psw address and exit
876 cleanup_system_call_insn:
887 cleanup_sysc_restore:
888 clg %r9,BASED(cleanup_sysc_restore_insn)
890 lg %r9,24(%r11) # get saved pointer to pt_regs
891 mvc __LC_RETURN_PSW(16),__PT_PSW(%r9)
892 mvc 0(64,%r11),__PT_R8(%r9)
893 lmg %r0,%r7,__PT_R0(%r9)
894 0: lmg %r8,%r9,__LC_RETURN_PSW
896 cleanup_sysc_restore_insn:
904 clg %r9,BASED(cleanup_io_restore_insn)
906 lg %r9,24(%r11) # get saved r11 pointer to pt_regs
907 mvc __LC_RETURN_PSW(16),__PT_PSW(%r9)
908 mvc 0(64,%r11),__PT_R8(%r9)
909 lmg %r0,%r7,__PT_R0(%r9)
910 0: lmg %r8,%r9,__LC_RETURN_PSW
912 cleanup_io_restore_insn:
916 # copy interrupt clock & cpu timer
917 mvc __CLOCK_IDLE_EXIT(8,%r2),__LC_INT_CLOCK
918 mvc __TIMER_IDLE_EXIT(8,%r2),__LC_ASYNC_ENTER_TIMER
919 cghi %r11,__LC_SAVE_AREA_ASYNC
921 mvc __CLOCK_IDLE_EXIT(8,%r2),__LC_MCCK_CLOCK
922 mvc __TIMER_IDLE_EXIT(8,%r2),__LC_MCCK_ENTER_TIMER
923 0: # check if stck & stpt have been executed
924 clg %r9,BASED(cleanup_idle_insn)
926 mvc __CLOCK_IDLE_ENTER(8,%r2),__CLOCK_IDLE_EXIT(%r2)
927 mvc __TIMER_IDLE_ENTER(8,%r2),__TIMER_IDLE_EXIT(%r2)
928 1: # account system time going idle
929 lg %r9,__LC_STEAL_TIMER
930 alg %r9,__CLOCK_IDLE_ENTER(%r2)
931 slg %r9,__LC_LAST_UPDATE_CLOCK
932 stg %r9,__LC_STEAL_TIMER
933 mvc __LC_LAST_UPDATE_CLOCK(8),__CLOCK_IDLE_EXIT(%r2)
934 lg %r9,__LC_SYSTEM_TIMER
935 alg %r9,__LC_LAST_UPDATE_TIMER
936 slg %r9,__TIMER_IDLE_ENTER(%r2)
937 stg %r9,__LC_SYSTEM_TIMER
938 mvc __LC_LAST_UPDATE_TIMER(8),__TIMER_IDLE_EXIT(%r2)
940 nihh %r8,0xfffd # clear wait state bit
941 lg %r9,48(%r11) # return from psw_idle
951 .quad __critical_start
953 .quad __critical_end - __critical_start
956 #if defined(CONFIG_KVM) || defined(CONFIG_KVM_MODULE)
958 * sie64a calling convention:
959 * %r2 pointer to sie control block
960 * %r3 guest register save area
963 stmg %r6,%r14,__SF_GPRS(%r15) # save kernel registers
964 stg %r2,__SF_EMPTY(%r15) # save control block pointer
965 stg %r3,__SF_EMPTY+8(%r15) # save guest register save area
966 xc __SF_EMPTY+16(8,%r15),__SF_EMPTY+16(%r15) # host id == 0
967 lmg %r0,%r13,0(%r3) # load guest gprs 0-13
969 lg %r14,__LC_THREAD_INFO # pointer thread_info struct
970 tm __TI_flags+7(%r14),_TIF_EXIT_SIE
972 lg %r14,__LC_GMAP # get gmap pointer
975 lctlg %c1,%c1,__GMAP_ASCE(%r14) # load primary asce
977 lg %r14,__SF_EMPTY(%r15) # get control block pointer
978 SPP __SF_EMPTY(%r15) # set guest id
981 SPP __SF_EMPTY+16(%r15) # set host id
982 lg %r14,__LC_THREAD_INFO # pointer thread_info struct
984 lctlg %c1,%c1,__LC_USER_ASCE # load primary asce
985 lg %r14,__SF_EMPTY+8(%r15) # load guest register save area
986 stmg %r0,%r13,0(%r14) # save guest gprs 0-13
987 lmg %r6,%r14,__SF_GPRS(%r15) # restore kernel registers
991 lctlg %c1,%c1,__LC_USER_ASCE # load primary asce
992 lg %r14,__LC_THREAD_INFO # pointer thread_info struct
993 lg %r14,__SF_EMPTY+8(%r15) # load guest register save area
994 stmg %r0,%r13,0(%r14) # save guest gprs 0-13
995 lmg %r6,%r14,__SF_GPRS(%r15) # restore kernel registers
1003 .quad sie_done - sie_loop
1007 .section __ex_table,"a"
1008 .quad sie_loop,sie_fault
1012 .section .rodata, "a"
1013 #define SYSCALL(esa,esame,emu) .long esame
1014 .globl sys_call_table
1016 #include "syscalls.S"
1019 #ifdef CONFIG_COMPAT
1021 #define SYSCALL(esa,esame,emu) .long emu
1023 #include "syscalls.S"