2 * arch/s390/kernel/entry.S
3 * S390 low-level entry points.
6 * Copyright (C) 1999,2000 IBM Deutschland Entwicklung GmbH, IBM Corporation
7 * Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
8 * Hartmut Penner (hp@de.ibm.com),
9 * Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com),
10 * Heiko Carstens <heiko.carstens@de.ibm.com>
13 #include <linux/sys.h>
14 #include <linux/linkage.h>
15 #include <linux/config.h>
16 #include <asm/cache.h>
17 #include <asm/lowcore.h>
18 #include <asm/errno.h>
19 #include <asm/ptrace.h>
20 #include <asm/thread_info.h>
21 #include <asm/offsets.h>
22 #include <asm/unistd.h>
26 * Stack layout for the system_call stack entry.
27 * The first few entries are identical to the user_regs_struct.
29 SP_PTREGS = STACK_FRAME_OVERHEAD
30 SP_ARGS = STACK_FRAME_OVERHEAD + __PT_ARGS
31 SP_PSW = STACK_FRAME_OVERHEAD + __PT_PSW
32 SP_R0 = STACK_FRAME_OVERHEAD + __PT_GPRS
33 SP_R1 = STACK_FRAME_OVERHEAD + __PT_GPRS + 4
34 SP_R2 = STACK_FRAME_OVERHEAD + __PT_GPRS + 8
35 SP_R3 = STACK_FRAME_OVERHEAD + __PT_GPRS + 12
36 SP_R4 = STACK_FRAME_OVERHEAD + __PT_GPRS + 16
37 SP_R5 = STACK_FRAME_OVERHEAD + __PT_GPRS + 20
38 SP_R6 = STACK_FRAME_OVERHEAD + __PT_GPRS + 24
39 SP_R7 = STACK_FRAME_OVERHEAD + __PT_GPRS + 28
40 SP_R8 = STACK_FRAME_OVERHEAD + __PT_GPRS + 32
41 SP_R9 = STACK_FRAME_OVERHEAD + __PT_GPRS + 36
42 SP_R10 = STACK_FRAME_OVERHEAD + __PT_GPRS + 40
43 SP_R11 = STACK_FRAME_OVERHEAD + __PT_GPRS + 44
44 SP_R12 = STACK_FRAME_OVERHEAD + __PT_GPRS + 48
45 SP_R13 = STACK_FRAME_OVERHEAD + __PT_GPRS + 52
46 SP_R14 = STACK_FRAME_OVERHEAD + __PT_GPRS + 56
47 SP_R15 = STACK_FRAME_OVERHEAD + __PT_GPRS + 60
48 SP_ORIG_R2 = STACK_FRAME_OVERHEAD + __PT_ORIG_GPR2
49 SP_ILC = STACK_FRAME_OVERHEAD + __PT_ILC
50 SP_TRAP = STACK_FRAME_OVERHEAD + __PT_TRAP
51 SP_SIZE = STACK_FRAME_OVERHEAD + __PT_SIZE
53 _TIF_WORK_SVC = (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_MCCK_PENDING | \
54 _TIF_RESTART_SVC | _TIF_SINGLE_STEP )
55 _TIF_WORK_INT = (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_MCCK_PENDING)
57 STACK_SHIFT = PAGE_SHIFT + THREAD_ORDER
58 STACK_SIZE = 1 << STACK_SHIFT
60 #define BASED(name) name-system_call(%r13)
63 * Register usage in interrupt handlers:
64 * R9 - pointer to current task structure
65 * R13 - pointer to literal pool
66 * R14 - return register for function calls
67 * R15 - kernel stack pointer
70 .macro STORE_TIMER lc_offset
71 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
76 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
77 .macro UPDATE_VTIME lc_from,lc_to,lc_sum
87 1: stm %r10,%r11,\lc_sum
91 .macro SAVE_ALL_BASE savearea
92 stm %r12,%r15,\savearea
93 l %r13,__LC_SVC_NEW_PSW+4 # load &system_call to %r13
96 .macro SAVE_ALL psworg,savearea,sync
99 tm \psworg+1,0x01 # test problem state bit
100 bz BASED(2f) # skip stack setup save
101 l %r15,__LC_KERNEL_STACK # problem state -> load ksp
103 tm \psworg+1,0x01 # test problem state bit
104 bnz BASED(1f) # from user -> load async stack
105 clc \psworg+4(4),BASED(.Lcritical_end)
107 clc \psworg+4(4),BASED(.Lcritical_start)
109 l %r14,BASED(.Lcleanup_critical)
111 tm 0(%r12),0x01 # retest problem state after cleanup
113 0: l %r14,__LC_ASYNC_STACK # are we already on the async stack ?
117 1: l %r15,__LC_ASYNC_STACK
119 #ifdef CONFIG_CHECK_STACK
121 2: tml %r15,STACK_SIZE - CONFIG_STACK_GUARD
122 bz BASED(stack_overflow)
128 .macro CREATE_STACK_FRAME psworg,savearea
129 s %r15,BASED(.Lc_spsize) # make room for registers & psw
130 mvc SP_PSW(8,%r15),0(%r12) # move user PSW to stack
132 st %r2,SP_ORIG_R2(%r15) # store original content of gpr 2
133 icm %r12,12,__LC_SVC_ILC
134 stm %r0,%r11,SP_R0(%r15) # store gprs %r0-%r11 to kernel stack
136 mvc SP_R12(16,%r15),\savearea # move %r12-%r15 to stack
138 st %r12,__SF_BACKCHAIN(%r15) # clear back chain
141 .macro RESTORE_ALL sync
142 mvc __LC_RETURN_PSW(8),SP_PSW(%r15) # move user PSW to lowcore
144 ni __LC_RETURN_PSW+1,0xfd # clear wait state bit
146 lm %r0,%r15,SP_R0(%r15) # load gprs 0-15 of user
147 STORE_TIMER __LC_EXIT_TIMER
148 lpsw __LC_RETURN_PSW # back to caller
152 * Scheduler resume function, called by switch_to
153 * gpr2 = (task_struct *) prev
154 * gpr3 = (task_struct *) next
162 tm __THREAD_per(%r3),0xe8 # new process is using per ?
163 bz __switch_to_noper-__switch_to_base(%r1) # if not we're fine
164 stctl %c9,%c11,__SF_EMPTY(%r15) # We are using per stuff
165 clc __THREAD_per(12,%r3),__SF_EMPTY(%r15)
166 be __switch_to_noper-__switch_to_base(%r1) # we got away w/o bashing TLB's
167 lctl %c9,%c11,__THREAD_per(%r3) # Nope we didn't
169 l %r4,__THREAD_info(%r2) # get thread_info of prev
170 tm __TI_flags+3(%r4),_TIF_MCCK_PENDING # machine check pending?
171 bz __switch_to_no_mcck-__switch_to_base(%r1)
172 ni __TI_flags+3(%r4),255-_TIF_MCCK_PENDING # clear flag in prev
173 l %r4,__THREAD_info(%r3) # get thread_info of next
174 oi __TI_flags+3(%r4),_TIF_MCCK_PENDING # set it in next
176 stm %r6,%r15,__SF_GPRS(%r15)# store __switch_to registers of prev task
177 st %r15,__THREAD_ksp(%r2) # store kernel stack to prev->tss.ksp
178 l %r15,__THREAD_ksp(%r3) # load kernel stack from next->tss.ksp
179 lm %r6,%r15,__SF_GPRS(%r15)# load __switch_to registers of next task
180 st %r3,__LC_CURRENT # __LC_CURRENT = current task struct
181 lctl %c4,%c4,__TASK_pid(%r3) # load pid to control reg. 4
182 l %r3,__THREAD_info(%r3) # load thread_info from task struct
183 st %r3,__LC_THREAD_INFO
185 st %r3,__LC_KERNEL_STACK # __LC_KERNEL_STACK = new kernel stack
190 * SVC interrupt handler routine. System calls are synchronous events and
191 * are executed with interrupts enabled.
196 STORE_TIMER __LC_SYNC_ENTER_TIMER
198 SAVE_ALL_BASE __LC_SAVE_AREA
199 SAVE_ALL __LC_SVC_OLD_PSW,__LC_SAVE_AREA,1
200 CREATE_STACK_FRAME __LC_SVC_OLD_PSW,__LC_SAVE_AREA
201 lh %r7,0x8a # get svc number from lowcore
202 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
204 tm SP_PSW+1(%r15),0x01 # interrupting from user ?
205 bz BASED(sysc_do_svc)
206 UPDATE_VTIME __LC_EXIT_TIMER,__LC_SYNC_ENTER_TIMER,__LC_USER_TIMER
208 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
210 mvc __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
213 l %r9,__LC_THREAD_INFO # load pointer to thread_info struct
214 sla %r7,2 # *4 and test for svc 0
215 bnz BASED(sysc_nr_ok) # svc number > 0
216 # svc 0: system call number in %r1
217 cl %r1,BASED(.Lnr_syscalls)
218 bnl BASED(sysc_nr_ok)
219 lr %r7,%r1 # copy svc number to %r7
222 mvc SP_ARGS(4,%r15),SP_R7(%r15)
224 tm __TI_flags+3(%r9),(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT)
225 l %r8,sys_call_table-system_call(%r7,%r13) # get system call addr.
226 bnz BASED(sysc_tracesys)
227 basr %r14,%r8 # call sys_xxxx
228 st %r2,SP_R2(%r15) # store return value (change R2 on stack)
229 # ATTENTION: check sys_execve_glue before
230 # changing anything here !!
233 tm SP_PSW+1(%r15),0x01 # returning to user ?
234 bno BASED(sysc_leave)
235 tm __TI_flags+3(%r9),_TIF_WORK_SVC
236 bnz BASED(sysc_work) # there is work to do (signals etc.)
241 # recheck if there is more work to do
244 tm __TI_flags+3(%r9),_TIF_WORK_SVC
245 bz BASED(sysc_leave) # there is no work to do
247 # One of the work bits is on. Find out which one.
250 tm __TI_flags+3(%r9),_TIF_MCCK_PENDING
251 bo BASED(sysc_mcck_pending)
252 tm __TI_flags+3(%r9),_TIF_NEED_RESCHED
253 bo BASED(sysc_reschedule)
254 tm __TI_flags+3(%r9),_TIF_SIGPENDING
255 bo BASED(sysc_sigpending)
256 tm __TI_flags+3(%r9),_TIF_RESTART_SVC
257 bo BASED(sysc_restart)
258 tm __TI_flags+3(%r9),_TIF_SINGLE_STEP
259 bo BASED(sysc_singlestep)
263 # _TIF_NEED_RESCHED is set, call schedule
266 l %r1,BASED(.Lschedule)
267 la %r14,BASED(sysc_work_loop)
268 br %r1 # call scheduler
271 # _TIF_MCCK_PENDING is set, call handler
274 l %r1,BASED(.Ls390_handle_mcck)
275 la %r14,BASED(sysc_work_loop)
276 br %r1 # TIF bit will be cleared by handler
279 # _TIF_SIGPENDING is set, call do_signal
282 ni __TI_flags+3(%r9),255-_TIF_SINGLE_STEP # clear TIF_SINGLE_STEP
283 la %r2,SP_PTREGS(%r15) # load pt_regs
284 sr %r3,%r3 # clear *oldset
285 l %r1,BASED(.Ldo_signal)
286 basr %r14,%r1 # call do_signal
287 tm __TI_flags+3(%r9),_TIF_RESTART_SVC
288 bo BASED(sysc_restart)
289 tm __TI_flags+3(%r9),_TIF_SINGLE_STEP
290 bo BASED(sysc_singlestep)
291 b BASED(sysc_leave) # out of here, do NOT recheck
294 # _TIF_RESTART_SVC is set, set up registers and restart svc
297 ni __TI_flags+3(%r9),255-_TIF_RESTART_SVC # clear TIF_RESTART_SVC
298 l %r7,SP_R2(%r15) # load new svc number
300 mvc SP_R2(4,%r15),SP_ORIG_R2(%r15) # restore first argument
301 lm %r2,%r6,SP_R2(%r15) # load svc arguments
302 b BASED(sysc_do_restart) # restart svc
305 # _TIF_SINGLE_STEP is set, call do_single_step
308 ni __TI_flags+3(%r9),255-_TIF_SINGLE_STEP # clear TIF_SINGLE_STEP
309 mvi SP_TRAP+1(%r15),0x28 # set trap indication to pgm check
310 la %r2,SP_PTREGS(%r15) # address of register-save area
311 l %r1,BASED(.Lhandle_per) # load adr. of per handler
312 la %r14,BASED(sysc_return) # load adr. of system return
313 br %r1 # branch to do_single_step
318 # call trace before and after sys_call
322 la %r2,SP_PTREGS(%r15) # load pt_regs
327 clc SP_R2(4,%r15),BASED(.Lnr_syscalls)
328 bnl BASED(sysc_tracenogo)
329 l %r7,SP_R2(%r15) # strace might have changed the
330 sll %r7,2 # system call
331 l %r8,sys_call_table-system_call(%r7,%r13)
333 lm %r3,%r6,SP_R3(%r15)
334 l %r2,SP_ORIG_R2(%r15)
335 basr %r14,%r8 # call sys_xxx
336 st %r2,SP_R2(%r15) # store return value
338 tm __TI_flags+3(%r9),(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT)
339 bz BASED(sysc_return)
341 la %r2,SP_PTREGS(%r15) # load pt_regs
343 la %r14,BASED(sysc_return)
347 # a new process exits the kernel with ret_from_fork
351 l %r13,__LC_SVC_NEW_PSW+4
352 l %r9,__LC_THREAD_INFO # load pointer to thread_info struct
353 tm SP_PSW+1(%r15),0x01 # forking a kernel thread ?
355 st %r15,SP_R15(%r15) # store stack pointer for new kthread
356 0: l %r1,BASED(.Lschedtail)
358 stosm __SF_EMPTY(%r15),0x03 # reenable interrupts
362 # clone, fork, vfork, exec and sigreturn need glue,
363 # because they all expect pt_regs as parameter,
364 # but are called with different parameter.
365 # return-address is set up above
368 la %r2,SP_PTREGS(%r15) # load pt_regs
370 br %r1 # branch to sys_clone
373 la %r2,SP_PTREGS(%r15) # load pt_regs
375 br %r1 # branch to sys_fork
378 la %r2,SP_PTREGS(%r15) # load pt_regs
380 br %r1 # branch to sys_vfork
383 la %r2,SP_PTREGS(%r15) # load pt_regs
384 l %r1,BASED(.Lexecve)
385 lr %r12,%r14 # save return address
386 basr %r14,%r1 # call sys_execve
387 ltr %r2,%r2 # check if execve failed
388 bnz 0(%r12) # it did fail -> store result in gpr2
389 b 4(%r12) # SKIP ST 2,SP_R2(15) after BASR 14,8
390 # in system_call/sysc_tracesys
393 la %r2,SP_PTREGS(%r15) # load pt_regs as parameter
394 l %r1,BASED(.Lsigreturn)
395 br %r1 # branch to sys_sigreturn
397 sys_rt_sigreturn_glue:
398 la %r2,SP_PTREGS(%r15) # load pt_regs as parameter
399 l %r1,BASED(.Lrt_sigreturn)
400 br %r1 # branch to sys_sigreturn
403 # sigsuspend and rt_sigsuspend need pt_regs as an additional
404 # parameter and they have to skip the store of %r2 into the
405 # user register %r2 because the return value was set in
406 # sigsuspend and rt_sigsuspend already and must not be overwritten!
410 lr %r5,%r4 # move mask back
411 lr %r4,%r3 # move history1 parameter
412 lr %r3,%r2 # move history0 parameter
413 la %r2,SP_PTREGS(%r15) # load pt_regs as first parameter
414 l %r1,BASED(.Lsigsuspend)
415 la %r14,4(%r14) # skip store of return value
416 br %r1 # branch to sys_sigsuspend
418 sys_rt_sigsuspend_glue:
419 lr %r4,%r3 # move sigsetsize parameter
420 lr %r3,%r2 # move unewset parameter
421 la %r2,SP_PTREGS(%r15) # load pt_regs as first parameter
422 l %r1,BASED(.Lrt_sigsuspend)
423 la %r14,4(%r14) # skip store of return value
424 br %r1 # branch to sys_rt_sigsuspend
426 sys_sigaltstack_glue:
427 la %r4,SP_PTREGS(%r15) # load pt_regs as parameter
428 l %r1,BASED(.Lsigaltstack)
429 br %r1 # branch to sys_sigreturn
433 * Program check handler routine
436 .globl pgm_check_handler
439 * First we need to check for a special case:
440 * Single stepping an instruction that disables the PER event mask will
441 * cause a PER event AFTER the mask has been set. Example: SVC or LPSW.
442 * For a single stepped SVC the program check handler gets control after
443 * the SVC new PSW has been loaded. But we want to execute the SVC first and
444 * then handle the PER event. Therefore we update the SVC old PSW to point
445 * to the pgm_check_handler and branch to the SVC handler after we checked
446 * if we have to load the kernel stack register.
447 * For every other possible cause for PER event without the PER mask set
448 * we just ignore the PER event (FIXME: is there anything we have to do
451 STORE_TIMER __LC_SYNC_ENTER_TIMER
452 SAVE_ALL_BASE __LC_SAVE_AREA
453 tm __LC_PGM_INT_CODE+1,0x80 # check whether we got a per exception
454 bnz BASED(pgm_per) # got per exception -> special case
455 SAVE_ALL __LC_PGM_OLD_PSW,__LC_SAVE_AREA,1
456 CREATE_STACK_FRAME __LC_PGM_OLD_PSW,__LC_SAVE_AREA
457 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
458 tm SP_PSW+1(%r15),0x01 # interrupting from user ?
459 bz BASED(pgm_no_vtime)
460 UPDATE_VTIME __LC_EXIT_TIMER,__LC_SYNC_ENTER_TIMER,__LC_USER_TIMER
461 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
462 mvc __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
465 l %r9,__LC_THREAD_INFO # load pointer to thread_info struct
466 l %r3,__LC_PGM_ILC # load program interruption code
470 l %r7,BASED(.Ljump_table)
472 l %r7,0(%r8,%r7) # load address of handler routine
473 la %r2,SP_PTREGS(%r15) # address of register-save area
474 la %r14,BASED(sysc_return)
475 br %r7 # branch to interrupt-handler
478 # handle per exception
481 tm __LC_PGM_OLD_PSW,0x40 # test if per event recording is on
482 bnz BASED(pgm_per_std) # ok, normal per event from user space
483 # ok its one of the special cases, now we need to find out which one
484 clc __LC_PGM_OLD_PSW(8),__LC_SVC_NEW_PSW
486 # no interesting special case, ignore PER event
487 lm %r12,%r15,__LC_SAVE_AREA
491 # Normal per exception
494 SAVE_ALL __LC_PGM_OLD_PSW,__LC_SAVE_AREA,1
495 CREATE_STACK_FRAME __LC_PGM_OLD_PSW,__LC_SAVE_AREA
496 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
497 tm SP_PSW+1(%r15),0x01 # interrupting from user ?
498 bz BASED(pgm_no_vtime2)
499 UPDATE_VTIME __LC_EXIT_TIMER,__LC_SYNC_ENTER_TIMER,__LC_USER_TIMER
500 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
501 mvc __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
504 l %r9,__LC_THREAD_INFO # load pointer to thread_info struct
506 mvc __THREAD_per+__PER_atmid(2,%r1),__LC_PER_ATMID
507 mvc __THREAD_per+__PER_address(4,%r1),__LC_PER_ADDRESS
508 mvc __THREAD_per+__PER_access_id(1,%r1),__LC_PER_ACCESS_ID
509 oi __TI_flags+3(%r9),_TIF_SINGLE_STEP # set TIF_SINGLE_STEP
510 l %r3,__LC_PGM_ILC # load program interruption code
512 nr %r8,%r3 # clear per-event-bit and ilc
513 be BASED(sysc_return) # only per or per+check ?
517 # it was a single stepped SVC that is causing all the trouble
520 SAVE_ALL __LC_SVC_OLD_PSW,__LC_SAVE_AREA,1
521 CREATE_STACK_FRAME __LC_SVC_OLD_PSW,__LC_SAVE_AREA
522 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
523 tm SP_PSW+1(%r15),0x01 # interrupting from user ?
524 bz BASED(pgm_no_vtime3)
525 UPDATE_VTIME __LC_EXIT_TIMER,__LC_SYNC_ENTER_TIMER,__LC_USER_TIMER
526 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
527 mvc __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
530 lh %r7,0x8a # get svc number from lowcore
531 l %r9,__LC_THREAD_INFO # load pointer to thread_info struct
533 mvc __THREAD_per+__PER_atmid(2,%r1),__LC_PER_ATMID
534 mvc __THREAD_per+__PER_address(4,%r1),__LC_PER_ADDRESS
535 mvc __THREAD_per+__PER_access_id(1,%r1),__LC_PER_ACCESS_ID
536 oi __TI_flags+3(%r9),_TIF_SINGLE_STEP # set TIF_SINGLE_STEP
537 stosm __SF_EMPTY(%r15),0x03 # reenable interrupts
541 * IO interrupt handler routine
544 .globl io_int_handler
546 STORE_TIMER __LC_ASYNC_ENTER_TIMER
548 SAVE_ALL_BASE __LC_SAVE_AREA+16
549 SAVE_ALL __LC_IO_OLD_PSW,__LC_SAVE_AREA+16,0
550 CREATE_STACK_FRAME __LC_IO_OLD_PSW,__LC_SAVE_AREA+16
551 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
552 tm SP_PSW+1(%r15),0x01 # interrupting from user ?
553 bz BASED(io_no_vtime)
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 l %r9,__LC_THREAD_INFO # load pointer to thread_info struct
560 l %r1,BASED(.Ldo_IRQ) # load address of do_IRQ
561 la %r2,SP_PTREGS(%r15) # address of register-save area
562 basr %r14,%r1 # branch to standard irq handler
565 tm SP_PSW+1(%r15),0x01 # returning to user ?
566 #ifdef CONFIG_PREEMPT
567 bno BASED(io_preempt) # no -> check for preemptive scheduling
569 bno BASED(io_leave) # no-> skip resched & signal
571 tm __TI_flags+3(%r9),_TIF_WORK_INT
572 bnz BASED(io_work) # there is work to do (signals etc.)
576 #ifdef CONFIG_PREEMPT
578 icm %r0,15,__TI_precount(%r9)
581 s %r1,BASED(.Lc_spsize)
582 mvc SP_PTREGS(__PT_SIZE,%r1),SP_PTREGS(%r15)
583 xc __SF_BACKCHAIN(4,%r1),__SF_BACKCHAIN(%r1) # clear back chain
586 tm __TI_flags+3(%r9),_TIF_NEED_RESCHED
588 mvc __TI_precount(4,%r9),BASED(.Lc_pactive)
589 stosm __SF_EMPTY(%r15),0x03 # reenable interrupts
590 l %r1,BASED(.Lschedule)
591 basr %r14,%r1 # call schedule
592 stnsm __SF_EMPTY(%r15),0xfc # disable I/O and ext. interrupts
593 xc __TI_precount(4,%r9),__TI_precount(%r9)
594 b BASED(io_resume_loop)
598 # switch to kernel stack, then check the TIF bits
601 l %r1,__LC_KERNEL_STACK
602 s %r1,BASED(.Lc_spsize)
603 mvc SP_PTREGS(__PT_SIZE,%r1),SP_PTREGS(%r15)
604 xc __SF_BACKCHAIN(4,%r1),__SF_BACKCHAIN(%r1) # clear back chain
607 # One of the work bits is on. Find out which one.
608 # Checked are: _TIF_SIGPENDING, _TIF_NEED_RESCHED and _TIF_MCCK_PENDING
611 tm __TI_flags+3(%r9),_TIF_MCCK_PENDING
612 bo BASED(io_mcck_pending)
613 tm __TI_flags+3(%r9),_TIF_NEED_RESCHED
614 bo BASED(io_reschedule)
615 tm __TI_flags+3(%r9),_TIF_SIGPENDING
616 bo BASED(io_sigpending)
620 # _TIF_MCCK_PENDING is set, call handler
623 l %r1,BASED(.Ls390_handle_mcck)
624 l %r14,BASED(io_work_loop)
625 br %r1 # TIF bit will be cleared by handler
628 # _TIF_NEED_RESCHED is set, call schedule
631 l %r1,BASED(.Lschedule)
632 stosm __SF_EMPTY(%r15),0x03 # reenable interrupts
633 basr %r14,%r1 # call scheduler
634 stnsm __SF_EMPTY(%r15),0xfc # disable I/O and ext. interrupts
635 tm __TI_flags+3(%r9),_TIF_WORK_INT
636 bz BASED(io_leave) # there is no work to do
637 b BASED(io_work_loop)
640 # _TIF_SIGPENDING is set, call do_signal
643 stosm __SF_EMPTY(%r15),0x03 # reenable interrupts
644 la %r2,SP_PTREGS(%r15) # load pt_regs
645 sr %r3,%r3 # clear *oldset
646 l %r1,BASED(.Ldo_signal)
647 basr %r14,%r1 # call do_signal
648 stnsm __SF_EMPTY(%r15),0xfc # disable I/O and ext. interrupts
649 b BASED(io_leave) # out of here, do NOT recheck
652 * External interrupt handler routine
655 .globl ext_int_handler
657 STORE_TIMER __LC_ASYNC_ENTER_TIMER
659 SAVE_ALL_BASE __LC_SAVE_AREA+16
660 SAVE_ALL __LC_EXT_OLD_PSW,__LC_SAVE_AREA+16,0
661 CREATE_STACK_FRAME __LC_EXT_OLD_PSW,__LC_SAVE_AREA+16
662 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
663 tm SP_PSW+1(%r15),0x01 # interrupting from user ?
664 bz BASED(ext_no_vtime)
665 UPDATE_VTIME __LC_EXIT_TIMER,__LC_ASYNC_ENTER_TIMER,__LC_USER_TIMER
666 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
667 mvc __LC_LAST_UPDATE_TIMER(8),__LC_ASYNC_ENTER_TIMER
670 l %r9,__LC_THREAD_INFO # load pointer to thread_info struct
671 la %r2,SP_PTREGS(%r15) # address of register-save area
672 lh %r3,__LC_EXT_INT_CODE # get interruption code
673 l %r1,BASED(.Ldo_extint)
678 * Machine check handler routines
681 .globl mcck_int_handler
683 spt __LC_CPU_TIMER_SAVE_AREA # revalidate cpu timer
684 lm %r0,%r15,__LC_GPREGS_SAVE_AREA # revalidate gprs
685 SAVE_ALL_BASE __LC_SAVE_AREA+32
686 la %r12,__LC_MCK_OLD_PSW
687 tm __LC_MCCK_CODE,0x80 # system damage?
688 bo BASED(mcck_int_main) # yes -> rest of mcck code invalid
689 tm __LC_MCCK_CODE+5,0x02 # stored cpu timer value valid?
691 spt __LC_LAST_UPDATE_TIMER # revalidate cpu timer
692 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
693 mvc __LC_ASYNC_ENTER_TIMER(8),__LC_LAST_UPDATE_TIMER
694 mvc __LC_SYNC_ENTER_TIMER(8),__LC_LAST_UPDATE_TIMER
695 mvc __LC_EXIT_TIMER(8),__LC_LAST_UPDATE_TIMER
696 0: tm __LC_MCCK_CODE+2,0x08 # mwp of old psw valid?
697 bno BASED(mcck_no_vtime) # no -> skip cleanup critical
698 tm __LC_MCK_OLD_PSW+1,0x01 # interrupting from user ?
699 bz BASED(mcck_no_vtime)
700 UPDATE_VTIME __LC_EXIT_TIMER,__LC_ASYNC_ENTER_TIMER,__LC_USER_TIMER
701 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
702 mvc __LC_LAST_UPDATE_TIMER(8),__LC_ASYNC_ENTER_TIMER
706 tm __LC_MCCK_CODE+2,0x09 # mwp + ia of old psw valid?
707 bno BASED(mcck_int_main) # no -> skip cleanup critical
708 tm __LC_MCK_OLD_PSW+1,0x01 # test problem state bit
709 bnz BASED(mcck_int_main) # from user -> load async stack
710 clc __LC_MCK_OLD_PSW+4(4),BASED(.Lcritical_end)
711 bhe BASED(mcck_int_main)
712 clc __LC_MCK_OLD_PSW+4(4),BASED(.Lcritical_start)
713 bl BASED(mcck_int_main)
714 l %r14,BASED(.Lcleanup_critical)
717 l %r14,__LC_PANIC_STACK # are we already on the panic stack?
721 l %r15,__LC_PANIC_STACK # load panic stack
722 0: CREATE_STACK_FRAME __LC_MCK_OLD_PSW,__LC_SAVE_AREA+32
723 l %r9,__LC_THREAD_INFO # load pointer to thread_info struct
724 la %r2,SP_PTREGS(%r15) # load pt_regs
725 l %r1,BASED(.Ls390_mcck)
726 basr %r14,%r1 # call machine check handler
727 tm SP_PSW+1(%r15),0x01 # returning to user ?
728 bno BASED(mcck_return)
729 l %r1,__LC_KERNEL_STACK # switch to kernel stack
730 s %r1,BASED(.Lc_spsize)
731 mvc SP_PTREGS(__PT_SIZE,%r1),SP_PTREGS(%r15)
732 xc __SF_BACKCHAIN(4,%r1),__SF_BACKCHAIN(%r1) # clear back chain
734 stosm __SF_EMPTY(%r15),0x04 # turn dat on
735 tm __TI_flags+3(%r9),_TIF_MCCK_PENDING
736 bno BASED(mcck_return)
737 l %r1,BASED(.Ls390_handle_mcck)
738 basr %r14,%r1 # call machine check handler
744 * Restart interruption handler, kick starter for additional CPUs
746 .globl restart_int_handler
748 l %r15,__LC_SAVE_AREA+60 # load ksp
749 lctl %c0,%c15,__LC_CREGS_SAVE_AREA # get new ctl regs
750 lam %a0,%a15,__LC_AREGS_SAVE_AREA
751 lm %r6,%r15,__SF_GPRS(%r15) # load registers from clone
752 stosm __SF_EMPTY(%r15),0x04 # now we can turn dat on
754 l %r14,restart_addr-.(%r14)
755 br %r14 # branch to start_secondary
757 .long start_secondary
760 * If we do not run with SMP enabled, let the new CPU crash ...
762 .globl restart_int_handler
766 lpsw restart_crash-restart_base(%r1)
769 .long 0x000a0000,0x00000000
773 #ifdef CONFIG_CHECK_STACK
775 * The synchronous or the asynchronous stack overflowed. We are dead.
776 * No need to properly save the registers, we are going to panic anyway.
777 * Setup a pt_regs so that show_trace can provide a good call trace.
780 l %r15,__LC_PANIC_STACK # change to panic stack
781 sl %r15,BASED(.Lc_spsize)
782 mvc SP_PSW(8,%r15),0(%r12) # move user PSW to stack
783 stm %r0,%r11,SP_R0(%r15) # store gprs %r0-%r11 to kernel stack
784 la %r1,__LC_SAVE_AREA
785 ch %r12,BASED(.L0x020) # old psw addr == __LC_SVC_OLD_PSW ?
787 ch %r12,BASED(.L0x028) # old psw addr == __LC_PGM_OLD_PSW ?
789 la %r1,__LC_SAVE_AREA+16
790 0: mvc SP_R12(16,%r15),0(%r1) # move %r12-%r15 to stack
791 xc __SF_BACKCHAIN(4,%r15),__SF_BACKCHAIN(%r15) # clear back chain
792 l %r1,BASED(1f) # branch to kernel_stack_overflow
793 la %r2,SP_PTREGS(%r15) # load pt_regs
795 1: .long kernel_stack_overflow
798 cleanup_table_system_call:
799 .long system_call + 0x80000000, sysc_do_svc + 0x80000000
800 cleanup_table_sysc_return:
801 .long sysc_return + 0x80000000, sysc_leave + 0x80000000
802 cleanup_table_sysc_leave:
803 .long sysc_leave + 0x80000000, sysc_work_loop + 0x80000000
804 cleanup_table_sysc_work_loop:
805 .long sysc_work_loop + 0x80000000, sysc_reschedule + 0x80000000
808 clc 4(4,%r12),BASED(cleanup_table_system_call)
810 clc 4(4,%r12),BASED(cleanup_table_system_call+4)
811 bl BASED(cleanup_system_call)
813 clc 4(4,%r12),BASED(cleanup_table_sysc_return)
815 clc 4(4,%r12),BASED(cleanup_table_sysc_return+4)
816 bl BASED(cleanup_sysc_return)
818 clc 4(4,%r12),BASED(cleanup_table_sysc_leave)
820 clc 4(4,%r12),BASED(cleanup_table_sysc_leave+4)
821 bl BASED(cleanup_sysc_leave)
823 clc 4(4,%r12),BASED(cleanup_table_sysc_work_loop)
825 clc 4(4,%r12),BASED(cleanup_table_sysc_work_loop+4)
826 bl BASED(cleanup_sysc_return)
831 mvc __LC_RETURN_PSW(8),0(%r12)
832 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
833 clc __LC_RETURN_PSW+4(4),BASED(cleanup_system_call_insn+4)
835 mvc __LC_SYNC_ENTER_TIMER(8),__LC_ASYNC_ENTER_TIMER
836 0: clc __LC_RETURN_PSW+4(4),BASED(cleanup_system_call_insn+8)
837 bhe BASED(cleanup_vtime)
839 clc __LC_RETURN_PSW+4(4),BASED(cleanup_system_call_insn)
841 mvc __LC_SAVE_AREA(16),__LC_SAVE_AREA+16
842 0: st %r13,__LC_SAVE_AREA+20
843 SAVE_ALL __LC_SVC_OLD_PSW,__LC_SAVE_AREA,1
844 CREATE_STACK_FRAME __LC_SVC_OLD_PSW,__LC_SAVE_AREA
845 st %r15,__LC_SAVE_AREA+28
847 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
849 clc __LC_RETURN_PSW+4(4),BASED(cleanup_system_call_insn+12)
850 bhe BASED(cleanup_stime)
851 tm SP_PSW+1(%r15),0x01 # interrupting from user ?
852 bz BASED(cleanup_novtime)
853 UPDATE_VTIME __LC_EXIT_TIMER,__LC_SYNC_ENTER_TIMER,__LC_USER_TIMER
855 clc __LC_RETURN_PSW+4(4),BASED(cleanup_system_call_insn+16)
856 bh BASED(cleanup_update)
857 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
859 mvc __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
862 mvc __LC_RETURN_PSW+4(4),BASED(cleanup_table_system_call+4)
863 la %r12,__LC_RETURN_PSW
865 cleanup_system_call_insn:
866 .long sysc_saveall + 0x80000000
867 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
868 .long system_call + 0x80000000
869 .long sysc_vtime + 0x80000000
870 .long sysc_stime + 0x80000000
871 .long sysc_update + 0x80000000
875 mvc __LC_RETURN_PSW(4),0(%r12)
876 mvc __LC_RETURN_PSW+4(4),BASED(cleanup_table_sysc_return)
877 la %r12,__LC_RETURN_PSW
881 clc 4(4,%r12),BASED(cleanup_sysc_leave_insn)
883 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
884 mvc __LC_EXIT_TIMER(8),__LC_ASYNC_ENTER_TIMER
885 clc 4(4,%r12),BASED(cleanup_sysc_leave_insn+4)
888 mvc __LC_RETURN_PSW(8),SP_PSW(%r15)
889 mvc __LC_SAVE_AREA+16(16),SP_R12(%r15)
890 lm %r0,%r11,SP_R0(%r15)
892 0: la %r12,__LC_RETURN_PSW
894 cleanup_sysc_leave_insn:
895 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
896 .long sysc_leave + 14 + 0x80000000
898 .long sysc_leave + 10 + 0x80000000
904 .Lc_spsize: .long SP_SIZE
905 .Lc_overhead: .long STACK_FRAME_OVERHEAD
906 .Lc_pactive: .long PREEMPT_ACTIVE
907 .Lnr_syscalls: .long NR_syscalls
908 .L0x018: .short 0x018
909 .L0x020: .short 0x020
910 .L0x028: .short 0x028
911 .L0x030: .short 0x030
912 .L0x038: .short 0x038
918 .Ls390_mcck: .long s390_do_machine_check
920 .long s390_handle_mcck
921 .Ldo_IRQ: .long do_IRQ
922 .Ldo_extint: .long do_extint
923 .Ldo_signal: .long do_signal
924 .Lhandle_per: .long do_single_step
925 .Ljump_table: .long pgm_check_table
926 .Lschedule: .long schedule
927 .Lclone: .long sys_clone
928 .Lexecve: .long sys_execve
929 .Lfork: .long sys_fork
930 .Lrt_sigreturn:.long sys_rt_sigreturn
932 .long sys_rt_sigsuspend
933 .Lsigreturn: .long sys_sigreturn
934 .Lsigsuspend: .long sys_sigsuspend
935 .Lsigaltstack: .long sys_sigaltstack
936 .Ltrace: .long syscall_trace
937 .Lvfork: .long sys_vfork
938 .Lschedtail: .long schedule_tail
941 .long __critical_start + 0x80000000
943 .long __critical_end + 0x80000000
945 .long cleanup_critical
947 #define SYSCALL(esa,esame,emu) .long esa
948 .globl sys_call_table
950 #include "syscalls.S"