2 * arch/s390/kernel/entry.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 + 4
32 SP_R2 = STACK_FRAME_OVERHEAD + __PT_GPRS + 8
33 SP_R3 = STACK_FRAME_OVERHEAD + __PT_GPRS + 12
34 SP_R4 = STACK_FRAME_OVERHEAD + __PT_GPRS + 16
35 SP_R5 = STACK_FRAME_OVERHEAD + __PT_GPRS + 20
36 SP_R6 = STACK_FRAME_OVERHEAD + __PT_GPRS + 24
37 SP_R7 = STACK_FRAME_OVERHEAD + __PT_GPRS + 28
38 SP_R8 = STACK_FRAME_OVERHEAD + __PT_GPRS + 32
39 SP_R9 = STACK_FRAME_OVERHEAD + __PT_GPRS + 36
40 SP_R10 = STACK_FRAME_OVERHEAD + __PT_GPRS + 40
41 SP_R11 = STACK_FRAME_OVERHEAD + __PT_GPRS + 44
42 SP_R12 = STACK_FRAME_OVERHEAD + __PT_GPRS + 48
43 SP_R13 = STACK_FRAME_OVERHEAD + __PT_GPRS + 52
44 SP_R14 = STACK_FRAME_OVERHEAD + __PT_GPRS + 56
45 SP_R15 = STACK_FRAME_OVERHEAD + __PT_GPRS + 60
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 _TIF_WORK_SVC = (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK | _TIF_NEED_RESCHED | \
52 _TIF_MCCK_PENDING | _TIF_RESTART_SVC | _TIF_SINGLE_STEP )
53 _TIF_WORK_INT = (_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK | _TIF_NEED_RESCHED | \
56 STACK_SHIFT = PAGE_SHIFT + THREAD_ORDER
57 STACK_SIZE = 1 << STACK_SHIFT
59 #define BASED(name) name-system_call(%r13)
62 * Register usage in interrupt handlers:
63 * R9 - pointer to current task structure
64 * R13 - pointer to literal pool
65 * R14 - return register for function calls
66 * R15 - kernel stack pointer
69 .macro STORE_TIMER lc_offset
70 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
75 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
76 .macro UPDATE_VTIME lc_from,lc_to,lc_sum
86 1: stm %r10,%r11,\lc_sum
90 .macro SAVE_ALL_BASE savearea
91 stm %r12,%r15,\savearea
92 l %r13,__LC_SVC_NEW_PSW+4 # load &system_call to %r13
95 .macro SAVE_ALL_SYNC psworg,savearea
97 tm \psworg+1,0x01 # test problem state bit
98 bz BASED(2f) # skip stack setup save
99 l %r15,__LC_KERNEL_STACK # problem state -> load ksp
100 #ifdef CONFIG_CHECK_STACK
102 2: tml %r15,STACK_SIZE - CONFIG_STACK_GUARD
103 bz BASED(stack_overflow)
109 .macro SAVE_ALL_ASYNC psworg,savearea
111 tm \psworg+1,0x01 # test problem state bit
112 bnz BASED(1f) # from user -> load async stack
113 clc \psworg+4(4),BASED(.Lcritical_end)
115 clc \psworg+4(4),BASED(.Lcritical_start)
117 l %r14,BASED(.Lcleanup_critical)
119 tm 1(%r12),0x01 # retest problem state after cleanup
121 0: l %r14,__LC_ASYNC_STACK # are we already on the async stack ?
125 1: l %r15,__LC_ASYNC_STACK
126 #ifdef CONFIG_CHECK_STACK
128 2: tml %r15,STACK_SIZE - CONFIG_STACK_GUARD
129 bz BASED(stack_overflow)
135 .macro CREATE_STACK_FRAME psworg,savearea
136 s %r15,BASED(.Lc_spsize) # make room for registers & psw
137 mvc SP_PSW(8,%r15),0(%r12) # move user PSW to stack
139 st %r2,SP_ORIG_R2(%r15) # store original content of gpr 2
140 icm %r12,12,__LC_SVC_ILC
141 stm %r0,%r11,SP_R0(%r15) # store gprs %r0-%r11 to kernel stack
143 mvc SP_R12(16,%r15),\savearea # move %r12-%r15 to stack
145 st %r12,__SF_BACKCHAIN(%r15) # clear back chain
148 .macro RESTORE_ALL psworg,sync
149 mvc \psworg(8),SP_PSW(%r15) # move user PSW to lowcore
151 ni \psworg+1,0xfd # clear wait state bit
153 lm %r0,%r15,SP_R0(%r15) # load gprs 0-15 of user
154 STORE_TIMER __LC_EXIT_TIMER
155 lpsw \psworg # back to caller
159 * Scheduler resume function, called by switch_to
160 * gpr2 = (task_struct *) prev
161 * gpr3 = (task_struct *) next
169 tm __THREAD_per(%r3),0xe8 # new process is using per ?
170 bz __switch_to_noper-__switch_to_base(%r1) # if not we're fine
171 stctl %c9,%c11,__SF_EMPTY(%r15) # We are using per stuff
172 clc __THREAD_per(12,%r3),__SF_EMPTY(%r15)
173 be __switch_to_noper-__switch_to_base(%r1) # we got away w/o bashing TLB's
174 lctl %c9,%c11,__THREAD_per(%r3) # Nope we didn't
176 l %r4,__THREAD_info(%r2) # get thread_info of prev
177 tm __TI_flags+3(%r4),_TIF_MCCK_PENDING # machine check pending?
178 bz __switch_to_no_mcck-__switch_to_base(%r1)
179 ni __TI_flags+3(%r4),255-_TIF_MCCK_PENDING # clear flag in prev
180 l %r4,__THREAD_info(%r3) # get thread_info of next
181 oi __TI_flags+3(%r4),_TIF_MCCK_PENDING # set it in next
183 stm %r6,%r15,__SF_GPRS(%r15)# store __switch_to registers of prev task
184 st %r15,__THREAD_ksp(%r2) # store kernel stack to prev->tss.ksp
185 l %r15,__THREAD_ksp(%r3) # load kernel stack from next->tss.ksp
186 lm %r6,%r15,__SF_GPRS(%r15)# load __switch_to registers of next task
187 st %r3,__LC_CURRENT # __LC_CURRENT = current task struct
188 lctl %c4,%c4,__TASK_pid(%r3) # load pid to control reg. 4
189 l %r3,__THREAD_info(%r3) # load thread_info from task struct
190 st %r3,__LC_THREAD_INFO
192 st %r3,__LC_KERNEL_STACK # __LC_KERNEL_STACK = new kernel stack
197 * SVC interrupt handler routine. System calls are synchronous events and
198 * are executed with interrupts enabled.
203 STORE_TIMER __LC_SYNC_ENTER_TIMER
205 SAVE_ALL_BASE __LC_SAVE_AREA
206 SAVE_ALL_SYNC __LC_SVC_OLD_PSW,__LC_SAVE_AREA
207 CREATE_STACK_FRAME __LC_SVC_OLD_PSW,__LC_SAVE_AREA
208 lh %r7,0x8a # get svc number from lowcore
209 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
211 tm SP_PSW+1(%r15),0x01 # interrupting from user ?
212 bz BASED(sysc_do_svc)
213 UPDATE_VTIME __LC_EXIT_TIMER,__LC_SYNC_ENTER_TIMER,__LC_USER_TIMER
215 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
217 mvc __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
220 l %r9,__LC_THREAD_INFO # load pointer to thread_info struct
221 sla %r7,2 # *4 and test for svc 0
222 bnz BASED(sysc_nr_ok) # svc number > 0
223 # svc 0: system call number in %r1
224 cl %r1,BASED(.Lnr_syscalls)
225 bnl BASED(sysc_nr_ok)
226 lr %r7,%r1 # copy svc number to %r7
229 mvc SP_ARGS(4,%r15),SP_R7(%r15)
231 l %r8,BASED(.Lsysc_table)
232 tm __TI_flags+3(%r9),(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT)
233 l %r8,0(%r7,%r8) # get system call addr.
234 bnz BASED(sysc_tracesys)
235 basr %r14,%r8 # call sys_xxxx
236 st %r2,SP_R2(%r15) # store return value (change R2 on stack)
237 # ATTENTION: check sys_execve_glue before
238 # changing anything here !!
241 tm SP_PSW+1(%r15),0x01 # returning to user ?
242 bno BASED(sysc_leave)
243 tm __TI_flags+3(%r9),_TIF_WORK_SVC
244 bnz BASED(sysc_work) # there is work to do (signals etc.)
246 RESTORE_ALL __LC_RETURN_PSW,1
249 # recheck if there is more work to do
252 tm __TI_flags+3(%r9),_TIF_WORK_SVC
253 bz BASED(sysc_leave) # there is no work to do
255 # One of the work bits is on. Find out which one.
258 tm __TI_flags+3(%r9),_TIF_MCCK_PENDING
259 bo BASED(sysc_mcck_pending)
260 tm __TI_flags+3(%r9),_TIF_NEED_RESCHED
261 bo BASED(sysc_reschedule)
262 tm __TI_flags+3(%r9),(_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK)
263 bnz BASED(sysc_sigpending)
264 tm __TI_flags+3(%r9),_TIF_RESTART_SVC
265 bo BASED(sysc_restart)
266 tm __TI_flags+3(%r9),_TIF_SINGLE_STEP
267 bo BASED(sysc_singlestep)
271 # _TIF_NEED_RESCHED is set, call schedule
274 l %r1,BASED(.Lschedule)
275 la %r14,BASED(sysc_work_loop)
276 br %r1 # call scheduler
279 # _TIF_MCCK_PENDING is set, call handler
282 l %r1,BASED(.Ls390_handle_mcck)
283 la %r14,BASED(sysc_work_loop)
284 br %r1 # TIF bit will be cleared by handler
287 # _TIF_SIGPENDING or _TIF_RESTORE_SIGMASK is set, call do_signal
290 ni __TI_flags+3(%r9),255-_TIF_SINGLE_STEP # clear TIF_SINGLE_STEP
291 la %r2,SP_PTREGS(%r15) # load pt_regs
292 l %r1,BASED(.Ldo_signal)
293 basr %r14,%r1 # call do_signal
294 tm __TI_flags+3(%r9),_TIF_RESTART_SVC
295 bo BASED(sysc_restart)
296 tm __TI_flags+3(%r9),_TIF_SINGLE_STEP
297 bo BASED(sysc_singlestep)
298 b BASED(sysc_work_loop)
301 # _TIF_RESTART_SVC is set, set up registers and restart svc
304 ni __TI_flags+3(%r9),255-_TIF_RESTART_SVC # clear TIF_RESTART_SVC
305 l %r7,SP_R2(%r15) # load new svc number
307 mvc SP_R2(4,%r15),SP_ORIG_R2(%r15) # restore first argument
308 lm %r2,%r6,SP_R2(%r15) # load svc arguments
309 b BASED(sysc_do_restart) # restart svc
312 # _TIF_SINGLE_STEP is set, call do_single_step
315 ni __TI_flags+3(%r9),255-_TIF_SINGLE_STEP # clear TIF_SINGLE_STEP
316 mvi SP_TRAP+1(%r15),0x28 # set trap indication to pgm check
317 la %r2,SP_PTREGS(%r15) # address of register-save area
318 l %r1,BASED(.Lhandle_per) # load adr. of per handler
319 la %r14,BASED(sysc_return) # load adr. of system return
320 br %r1 # branch to do_single_step
323 # call trace before and after sys_call
327 la %r2,SP_PTREGS(%r15) # load pt_regs
332 clc SP_R2(4,%r15),BASED(.Lnr_syscalls)
333 bnl BASED(sysc_tracenogo)
334 l %r8,BASED(.Lsysc_table)
335 l %r7,SP_R2(%r15) # strace might have changed the
336 sll %r7,2 # system call
339 lm %r3,%r6,SP_R3(%r15)
340 l %r2,SP_ORIG_R2(%r15)
341 basr %r14,%r8 # call sys_xxx
342 st %r2,SP_R2(%r15) # store return value
344 tm __TI_flags+3(%r9),(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT)
345 bz BASED(sysc_return)
347 la %r2,SP_PTREGS(%r15) # load pt_regs
349 la %r14,BASED(sysc_return)
353 # a new process exits the kernel with ret_from_fork
357 l %r13,__LC_SVC_NEW_PSW+4
358 l %r9,__LC_THREAD_INFO # load pointer to thread_info struct
359 tm SP_PSW+1(%r15),0x01 # forking a kernel thread ?
361 st %r15,SP_R15(%r15) # store stack pointer for new kthread
362 0: l %r1,BASED(.Lschedtail)
364 stosm __SF_EMPTY(%r15),0x03 # reenable interrupts
368 # clone, fork, vfork, exec and sigreturn need glue,
369 # because they all expect pt_regs as parameter,
370 # but are called with different parameter.
371 # return-address is set up above
374 la %r2,SP_PTREGS(%r15) # load pt_regs
376 br %r1 # branch to sys_clone
379 la %r2,SP_PTREGS(%r15) # load pt_regs
381 br %r1 # branch to sys_fork
384 la %r2,SP_PTREGS(%r15) # load pt_regs
386 br %r1 # branch to sys_vfork
389 la %r2,SP_PTREGS(%r15) # load pt_regs
390 l %r1,BASED(.Lexecve)
391 lr %r12,%r14 # save return address
392 basr %r14,%r1 # call sys_execve
393 ltr %r2,%r2 # check if execve failed
394 bnz 0(%r12) # it did fail -> store result in gpr2
395 b 4(%r12) # SKIP ST 2,SP_R2(15) after BASR 14,8
396 # in system_call/sysc_tracesys
399 la %r2,SP_PTREGS(%r15) # load pt_regs as parameter
400 l %r1,BASED(.Lsigreturn)
401 br %r1 # branch to sys_sigreturn
403 sys_rt_sigreturn_glue:
404 la %r2,SP_PTREGS(%r15) # load pt_regs as parameter
405 l %r1,BASED(.Lrt_sigreturn)
406 br %r1 # branch to sys_sigreturn
408 sys_sigaltstack_glue:
409 la %r4,SP_PTREGS(%r15) # load pt_regs as parameter
410 l %r1,BASED(.Lsigaltstack)
411 br %r1 # branch to sys_sigreturn
415 * Program check handler routine
418 .globl pgm_check_handler
421 * First we need to check for a special case:
422 * Single stepping an instruction that disables the PER event mask will
423 * cause a PER event AFTER the mask has been set. Example: SVC or LPSW.
424 * For a single stepped SVC the program check handler gets control after
425 * the SVC new PSW has been loaded. But we want to execute the SVC first and
426 * then handle the PER event. Therefore we update the SVC old PSW to point
427 * to the pgm_check_handler and branch to the SVC handler after we checked
428 * if we have to load the kernel stack register.
429 * For every other possible cause for PER event without the PER mask set
430 * we just ignore the PER event (FIXME: is there anything we have to do
433 STORE_TIMER __LC_SYNC_ENTER_TIMER
434 SAVE_ALL_BASE __LC_SAVE_AREA
435 tm __LC_PGM_INT_CODE+1,0x80 # check whether we got a per exception
436 bnz BASED(pgm_per) # got per exception -> special case
437 SAVE_ALL_SYNC __LC_PGM_OLD_PSW,__LC_SAVE_AREA
438 CREATE_STACK_FRAME __LC_PGM_OLD_PSW,__LC_SAVE_AREA
439 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
440 tm SP_PSW+1(%r15),0x01 # interrupting from user ?
441 bz BASED(pgm_no_vtime)
442 UPDATE_VTIME __LC_EXIT_TIMER,__LC_SYNC_ENTER_TIMER,__LC_USER_TIMER
443 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
444 mvc __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
447 l %r9,__LC_THREAD_INFO # load pointer to thread_info struct
448 l %r3,__LC_PGM_ILC # load program interruption code
452 l %r7,BASED(.Ljump_table)
454 l %r7,0(%r8,%r7) # load address of handler routine
455 la %r2,SP_PTREGS(%r15) # address of register-save area
456 la %r14,BASED(sysc_return)
457 br %r7 # branch to interrupt-handler
460 # handle per exception
463 tm __LC_PGM_OLD_PSW,0x40 # test if per event recording is on
464 bnz BASED(pgm_per_std) # ok, normal per event from user space
465 # ok its one of the special cases, now we need to find out which one
466 clc __LC_PGM_OLD_PSW(8),__LC_SVC_NEW_PSW
468 # no interesting special case, ignore PER event
469 lm %r12,%r15,__LC_SAVE_AREA
473 # Normal per exception
476 SAVE_ALL_SYNC __LC_PGM_OLD_PSW,__LC_SAVE_AREA
477 CREATE_STACK_FRAME __LC_PGM_OLD_PSW,__LC_SAVE_AREA
478 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
479 tm SP_PSW+1(%r15),0x01 # interrupting from user ?
480 bz BASED(pgm_no_vtime2)
481 UPDATE_VTIME __LC_EXIT_TIMER,__LC_SYNC_ENTER_TIMER,__LC_USER_TIMER
482 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
483 mvc __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
486 l %r9,__LC_THREAD_INFO # load pointer to thread_info struct
488 mvc __THREAD_per+__PER_atmid(2,%r1),__LC_PER_ATMID
489 mvc __THREAD_per+__PER_address(4,%r1),__LC_PER_ADDRESS
490 mvc __THREAD_per+__PER_access_id(1,%r1),__LC_PER_ACCESS_ID
491 oi __TI_flags+3(%r9),_TIF_SINGLE_STEP # set TIF_SINGLE_STEP
492 l %r3,__LC_PGM_ILC # load program interruption code
494 nr %r8,%r3 # clear per-event-bit and ilc
495 be BASED(sysc_return) # only per or per+check ?
499 # it was a single stepped SVC that is causing all the trouble
502 SAVE_ALL_SYNC __LC_SVC_OLD_PSW,__LC_SAVE_AREA
503 CREATE_STACK_FRAME __LC_SVC_OLD_PSW,__LC_SAVE_AREA
504 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
505 tm SP_PSW+1(%r15),0x01 # interrupting from user ?
506 bz BASED(pgm_no_vtime3)
507 UPDATE_VTIME __LC_EXIT_TIMER,__LC_SYNC_ENTER_TIMER,__LC_USER_TIMER
508 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
509 mvc __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
512 lh %r7,0x8a # get svc number from lowcore
513 l %r9,__LC_THREAD_INFO # load pointer to thread_info struct
515 mvc __THREAD_per+__PER_atmid(2,%r1),__LC_PER_ATMID
516 mvc __THREAD_per+__PER_address(4,%r1),__LC_PER_ADDRESS
517 mvc __THREAD_per+__PER_access_id(1,%r1),__LC_PER_ACCESS_ID
518 oi __TI_flags+3(%r9),_TIF_SINGLE_STEP # set TIF_SINGLE_STEP
519 stosm __SF_EMPTY(%r15),0x03 # reenable interrupts
523 * IO interrupt handler routine
526 .globl io_int_handler
528 STORE_TIMER __LC_ASYNC_ENTER_TIMER
530 SAVE_ALL_BASE __LC_SAVE_AREA+16
531 SAVE_ALL_ASYNC __LC_IO_OLD_PSW,__LC_SAVE_AREA+16
532 CREATE_STACK_FRAME __LC_IO_OLD_PSW,__LC_SAVE_AREA+16
533 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
534 tm SP_PSW+1(%r15),0x01 # interrupting from user ?
535 bz BASED(io_no_vtime)
536 UPDATE_VTIME __LC_EXIT_TIMER,__LC_ASYNC_ENTER_TIMER,__LC_USER_TIMER
537 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
538 mvc __LC_LAST_UPDATE_TIMER(8),__LC_ASYNC_ENTER_TIMER
541 l %r9,__LC_THREAD_INFO # load pointer to thread_info struct
542 l %r1,BASED(.Ldo_IRQ) # load address of do_IRQ
543 la %r2,SP_PTREGS(%r15) # address of register-save area
544 basr %r14,%r1 # branch to standard irq handler
547 tm SP_PSW+1(%r15),0x01 # returning to user ?
548 #ifdef CONFIG_PREEMPT
549 bno BASED(io_preempt) # no -> check for preemptive scheduling
551 bno BASED(io_leave) # no-> skip resched & signal
553 tm __TI_flags+3(%r9),_TIF_WORK_INT
554 bnz BASED(io_work) # there is work to do (signals etc.)
556 RESTORE_ALL __LC_RETURN_PSW,0
559 #ifdef CONFIG_PREEMPT
561 icm %r0,15,__TI_precount(%r9)
564 s %r1,BASED(.Lc_spsize)
565 mvc SP_PTREGS(__PT_SIZE,%r1),SP_PTREGS(%r15)
566 xc __SF_BACKCHAIN(4,%r1),__SF_BACKCHAIN(%r1) # clear back chain
569 tm __TI_flags+3(%r9),_TIF_NEED_RESCHED
571 mvc __TI_precount(4,%r9),BASED(.Lc_pactive)
572 stosm __SF_EMPTY(%r15),0x03 # reenable interrupts
573 l %r1,BASED(.Lschedule)
574 basr %r14,%r1 # call schedule
575 stnsm __SF_EMPTY(%r15),0xfc # disable I/O and ext. interrupts
576 xc __TI_precount(4,%r9),__TI_precount(%r9)
577 b BASED(io_resume_loop)
581 # switch to kernel stack, then check the TIF bits
584 l %r1,__LC_KERNEL_STACK
585 s %r1,BASED(.Lc_spsize)
586 mvc SP_PTREGS(__PT_SIZE,%r1),SP_PTREGS(%r15)
587 xc __SF_BACKCHAIN(4,%r1),__SF_BACKCHAIN(%r1) # clear back chain
590 # One of the work bits is on. Find out which one.
591 # Checked are: _TIF_SIGPENDING, _TIF_RESTORE_SIGMASK, _TIF_NEED_RESCHED
592 # and _TIF_MCCK_PENDING
595 tm __TI_flags+3(%r9),_TIF_MCCK_PENDING
596 bo BASED(io_mcck_pending)
597 tm __TI_flags+3(%r9),_TIF_NEED_RESCHED
598 bo BASED(io_reschedule)
599 tm __TI_flags+3(%r9),(_TIF_SIGPENDING | _TIF_RESTORE_SIGMASK)
600 bnz BASED(io_sigpending)
604 # _TIF_MCCK_PENDING is set, call handler
607 l %r1,BASED(.Ls390_handle_mcck)
608 la %r14,BASED(io_work_loop)
609 br %r1 # TIF bit will be cleared by handler
612 # _TIF_NEED_RESCHED is set, call schedule
615 l %r1,BASED(.Lschedule)
616 stosm __SF_EMPTY(%r15),0x03 # reenable interrupts
617 basr %r14,%r1 # call scheduler
618 stnsm __SF_EMPTY(%r15),0xfc # disable I/O and ext. interrupts
619 tm __TI_flags+3(%r9),_TIF_WORK_INT
620 bz BASED(io_leave) # there is no work to do
621 b BASED(io_work_loop)
624 # _TIF_SIGPENDING or _TIF_RESTORE_SIGMASK is set, call do_signal
627 stosm __SF_EMPTY(%r15),0x03 # reenable interrupts
628 la %r2,SP_PTREGS(%r15) # load pt_regs
629 l %r1,BASED(.Ldo_signal)
630 basr %r14,%r1 # call do_signal
631 stnsm __SF_EMPTY(%r15),0xfc # disable I/O and ext. interrupts
632 b BASED(io_work_loop)
635 * External interrupt handler routine
638 .globl ext_int_handler
640 STORE_TIMER __LC_ASYNC_ENTER_TIMER
642 SAVE_ALL_BASE __LC_SAVE_AREA+16
643 SAVE_ALL_ASYNC __LC_EXT_OLD_PSW,__LC_SAVE_AREA+16
644 CREATE_STACK_FRAME __LC_EXT_OLD_PSW,__LC_SAVE_AREA+16
645 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
646 tm SP_PSW+1(%r15),0x01 # interrupting from user ?
647 bz BASED(ext_no_vtime)
648 UPDATE_VTIME __LC_EXIT_TIMER,__LC_ASYNC_ENTER_TIMER,__LC_USER_TIMER
649 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
650 mvc __LC_LAST_UPDATE_TIMER(8),__LC_ASYNC_ENTER_TIMER
653 l %r9,__LC_THREAD_INFO # load pointer to thread_info struct
654 la %r2,SP_PTREGS(%r15) # address of register-save area
655 lh %r3,__LC_EXT_INT_CODE # get interruption code
656 l %r1,BASED(.Ldo_extint)
663 * Machine check handler routines
666 .globl mcck_int_handler
668 spt __LC_CPU_TIMER_SAVE_AREA # revalidate cpu timer
669 lm %r0,%r15,__LC_GPREGS_SAVE_AREA # revalidate gprs
670 SAVE_ALL_BASE __LC_SAVE_AREA+32
671 la %r12,__LC_MCK_OLD_PSW
672 tm __LC_MCCK_CODE,0x80 # system damage?
673 bo BASED(mcck_int_main) # yes -> rest of mcck code invalid
674 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
675 mvc __LC_SAVE_AREA+52(8),__LC_ASYNC_ENTER_TIMER
676 mvc __LC_ASYNC_ENTER_TIMER(8),__LC_CPU_TIMER_SAVE_AREA
677 tm __LC_MCCK_CODE+5,0x02 # stored cpu timer value valid?
679 la %r14,__LC_SYNC_ENTER_TIMER
680 clc 0(8,%r14),__LC_ASYNC_ENTER_TIMER
682 la %r14,__LC_ASYNC_ENTER_TIMER
683 0: clc 0(8,%r14),__LC_EXIT_TIMER
685 la %r14,__LC_EXIT_TIMER
686 0: clc 0(8,%r14),__LC_LAST_UPDATE_TIMER
688 la %r14,__LC_LAST_UPDATE_TIMER
690 mvc __LC_ASYNC_ENTER_TIMER(8),0(%r14)
693 tm __LC_MCCK_CODE+2,0x09 # mwp + ia of old psw valid?
694 bno BASED(mcck_int_main) # no -> skip cleanup critical
695 tm __LC_MCK_OLD_PSW+1,0x01 # test problem state bit
696 bnz BASED(mcck_int_main) # from user -> load async stack
697 clc __LC_MCK_OLD_PSW+4(4),BASED(.Lcritical_end)
698 bhe BASED(mcck_int_main)
699 clc __LC_MCK_OLD_PSW+4(4),BASED(.Lcritical_start)
700 bl BASED(mcck_int_main)
701 l %r14,BASED(.Lcleanup_critical)
704 l %r14,__LC_PANIC_STACK # are we already on the panic stack?
708 l %r15,__LC_PANIC_STACK # load panic stack
709 0: CREATE_STACK_FRAME __LC_MCK_OLD_PSW,__LC_SAVE_AREA+32
710 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
711 tm __LC_MCCK_CODE+2,0x08 # mwp of old psw valid?
712 bno BASED(mcck_no_vtime) # no -> skip cleanup critical
713 tm SP_PSW+1(%r15),0x01 # interrupting from user ?
714 bz BASED(mcck_no_vtime)
715 UPDATE_VTIME __LC_EXIT_TIMER,__LC_ASYNC_ENTER_TIMER,__LC_USER_TIMER
716 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
717 mvc __LC_LAST_UPDATE_TIMER(8),__LC_ASYNC_ENTER_TIMER
720 l %r9,__LC_THREAD_INFO # load pointer to thread_info struct
721 la %r2,SP_PTREGS(%r15) # load pt_regs
722 l %r1,BASED(.Ls390_mcck)
723 basr %r14,%r1 # call machine check handler
724 tm SP_PSW+1(%r15),0x01 # returning to user ?
725 bno BASED(mcck_return)
726 l %r1,__LC_KERNEL_STACK # switch to kernel stack
727 s %r1,BASED(.Lc_spsize)
728 mvc SP_PTREGS(__PT_SIZE,%r1),SP_PTREGS(%r15)
729 xc __SF_BACKCHAIN(4,%r1),__SF_BACKCHAIN(%r1) # clear back chain
731 stosm __SF_EMPTY(%r15),0x04 # turn dat on
732 tm __TI_flags+3(%r9),_TIF_MCCK_PENDING
733 bno BASED(mcck_return)
734 l %r1,BASED(.Ls390_handle_mcck)
735 basr %r14,%r1 # call machine check handler
737 mvc __LC_RETURN_MCCK_PSW(8),SP_PSW(%r15) # move return PSW
738 ni __LC_RETURN_MCCK_PSW+1,0xfd # clear wait state bit
739 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
740 mvc __LC_ASYNC_ENTER_TIMER(8),__LC_SAVE_AREA+52
741 tm __LC_RETURN_MCCK_PSW+1,0x01 # returning to user ?
743 lm %r0,%r15,SP_R0(%r15) # load gprs 0-15
745 lpsw __LC_RETURN_MCCK_PSW # back to caller
748 lm %r0,%r15,SP_R0(%r15) # load gprs 0-15
749 lpsw __LC_RETURN_MCCK_PSW # back to caller
751 RESTORE_ALL __LC_RETURN_MCCK_PSW,0
755 * Restart interruption handler, kick starter for additional CPUs
757 .globl restart_int_handler
759 l %r15,__LC_SAVE_AREA+60 # load ksp
760 lctl %c0,%c15,__LC_CREGS_SAVE_AREA # get new ctl regs
761 lam %a0,%a15,__LC_AREGS_SAVE_AREA
762 lm %r6,%r15,__SF_GPRS(%r15) # load registers from clone
763 stosm __SF_EMPTY(%r15),0x04 # now we can turn dat on
765 l %r14,restart_addr-.(%r14)
766 br %r14 # branch to start_secondary
768 .long start_secondary
771 * If we do not run with SMP enabled, let the new CPU crash ...
773 .globl restart_int_handler
777 lpsw restart_crash-restart_base(%r1)
780 .long 0x000a0000,0x00000000
784 #ifdef CONFIG_CHECK_STACK
786 * The synchronous or the asynchronous stack overflowed. We are dead.
787 * No need to properly save the registers, we are going to panic anyway.
788 * Setup a pt_regs so that show_trace can provide a good call trace.
791 l %r15,__LC_PANIC_STACK # change to panic stack
792 sl %r15,BASED(.Lc_spsize)
793 mvc SP_PSW(8,%r15),0(%r12) # move user PSW to stack
794 stm %r0,%r11,SP_R0(%r15) # store gprs %r0-%r11 to kernel stack
795 la %r1,__LC_SAVE_AREA
796 ch %r12,BASED(.L0x020) # old psw addr == __LC_SVC_OLD_PSW ?
798 ch %r12,BASED(.L0x028) # old psw addr == __LC_PGM_OLD_PSW ?
800 la %r1,__LC_SAVE_AREA+16
801 0: mvc SP_R12(16,%r15),0(%r1) # move %r12-%r15 to stack
802 xc __SF_BACKCHAIN(4,%r15),__SF_BACKCHAIN(%r15) # clear back chain
803 l %r1,BASED(1f) # branch to kernel_stack_overflow
804 la %r2,SP_PTREGS(%r15) # load pt_regs
806 1: .long kernel_stack_overflow
809 cleanup_table_system_call:
810 .long system_call + 0x80000000, sysc_do_svc + 0x80000000
811 cleanup_table_sysc_return:
812 .long sysc_return + 0x80000000, sysc_leave + 0x80000000
813 cleanup_table_sysc_leave:
814 .long sysc_leave + 0x80000000, sysc_work_loop + 0x80000000
815 cleanup_table_sysc_work_loop:
816 .long sysc_work_loop + 0x80000000, sysc_reschedule + 0x80000000
817 cleanup_table_io_return:
818 .long io_return + 0x80000000, io_leave + 0x80000000
819 cleanup_table_io_leave:
820 .long io_leave + 0x80000000, io_done + 0x80000000
821 cleanup_table_io_work_loop:
822 .long io_work_loop + 0x80000000, io_mcck_pending + 0x80000000
825 clc 4(4,%r12),BASED(cleanup_table_system_call)
827 clc 4(4,%r12),BASED(cleanup_table_system_call+4)
828 bl BASED(cleanup_system_call)
830 clc 4(4,%r12),BASED(cleanup_table_sysc_return)
832 clc 4(4,%r12),BASED(cleanup_table_sysc_return+4)
833 bl BASED(cleanup_sysc_return)
835 clc 4(4,%r12),BASED(cleanup_table_sysc_leave)
837 clc 4(4,%r12),BASED(cleanup_table_sysc_leave+4)
838 bl BASED(cleanup_sysc_leave)
840 clc 4(4,%r12),BASED(cleanup_table_sysc_work_loop)
842 clc 4(4,%r12),BASED(cleanup_table_sysc_work_loop+4)
843 bl BASED(cleanup_sysc_return)
845 clc 4(4,%r12),BASED(cleanup_table_io_return)
847 clc 4(4,%r12),BASED(cleanup_table_io_return+4)
848 bl BASED(cleanup_io_return)
850 clc 4(4,%r12),BASED(cleanup_table_io_leave)
852 clc 4(4,%r12),BASED(cleanup_table_io_leave+4)
853 bl BASED(cleanup_io_leave)
855 clc 4(4,%r12),BASED(cleanup_table_io_work_loop)
857 clc 4(4,%r12),BASED(cleanup_table_io_work_loop+4)
858 bl BASED(cleanup_io_return)
863 mvc __LC_RETURN_PSW(8),0(%r12)
864 c %r12,BASED(.Lmck_old_psw)
866 la %r12,__LC_SAVE_AREA+16
868 0: la %r12,__LC_SAVE_AREA+32
870 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
871 clc __LC_RETURN_PSW+4(4),BASED(cleanup_system_call_insn+4)
873 mvc __LC_SYNC_ENTER_TIMER(8),__LC_ASYNC_ENTER_TIMER
874 0: clc __LC_RETURN_PSW+4(4),BASED(cleanup_system_call_insn+8)
875 bhe BASED(cleanup_vtime)
877 clc __LC_RETURN_PSW+4(4),BASED(cleanup_system_call_insn)
879 mvc __LC_SAVE_AREA(16),0(%r12)
881 st %r12,__LC_SAVE_AREA+48 # argh
882 SAVE_ALL_SYNC __LC_SVC_OLD_PSW,__LC_SAVE_AREA
883 CREATE_STACK_FRAME __LC_SVC_OLD_PSW,__LC_SAVE_AREA
884 l %r12,__LC_SAVE_AREA+48 # argh
887 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
889 clc __LC_RETURN_PSW+4(4),BASED(cleanup_system_call_insn+12)
890 bhe BASED(cleanup_stime)
891 tm SP_PSW+1(%r15),0x01 # interrupting from user ?
892 bz BASED(cleanup_novtime)
893 UPDATE_VTIME __LC_EXIT_TIMER,__LC_SYNC_ENTER_TIMER,__LC_USER_TIMER
895 clc __LC_RETURN_PSW+4(4),BASED(cleanup_system_call_insn+16)
896 bh BASED(cleanup_update)
897 UPDATE_VTIME __LC_LAST_UPDATE_TIMER,__LC_EXIT_TIMER,__LC_SYSTEM_TIMER
899 mvc __LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
902 mvc __LC_RETURN_PSW+4(4),BASED(cleanup_table_system_call+4)
903 la %r12,__LC_RETURN_PSW
905 cleanup_system_call_insn:
906 .long sysc_saveall + 0x80000000
907 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
908 .long system_call + 0x80000000
909 .long sysc_vtime + 0x80000000
910 .long sysc_stime + 0x80000000
911 .long sysc_update + 0x80000000
915 mvc __LC_RETURN_PSW(4),0(%r12)
916 mvc __LC_RETURN_PSW+4(4),BASED(cleanup_table_sysc_return)
917 la %r12,__LC_RETURN_PSW
921 clc 4(4,%r12),BASED(cleanup_sysc_leave_insn)
923 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
924 mvc __LC_EXIT_TIMER(8),__LC_ASYNC_ENTER_TIMER
925 clc 4(4,%r12),BASED(cleanup_sysc_leave_insn+4)
928 mvc __LC_RETURN_PSW(8),SP_PSW(%r15)
929 c %r12,BASED(.Lmck_old_psw)
931 mvc __LC_SAVE_AREA+32(16),SP_R12(%r15)
933 0: mvc __LC_SAVE_AREA+16(16),SP_R12(%r15)
934 1: lm %r0,%r11,SP_R0(%r15)
936 2: la %r12,__LC_RETURN_PSW
938 cleanup_sysc_leave_insn:
939 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
940 .long sysc_leave + 14 + 0x80000000
942 .long sysc_leave + 10 + 0x80000000
945 mvc __LC_RETURN_PSW(4),0(%r12)
946 mvc __LC_RETURN_PSW+4(4),BASED(cleanup_table_io_work_loop)
947 la %r12,__LC_RETURN_PSW
951 clc 4(4,%r12),BASED(cleanup_io_leave_insn)
953 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
954 mvc __LC_EXIT_TIMER(8),__LC_ASYNC_ENTER_TIMER
955 clc 4(4,%r12),BASED(cleanup_io_leave_insn+4)
958 mvc __LC_RETURN_PSW(8),SP_PSW(%r15)
959 c %r12,BASED(.Lmck_old_psw)
961 mvc __LC_SAVE_AREA+32(16),SP_R12(%r15)
963 0: mvc __LC_SAVE_AREA+16(16),SP_R12(%r15)
964 1: lm %r0,%r11,SP_R0(%r15)
966 2: la %r12,__LC_RETURN_PSW
968 cleanup_io_leave_insn:
969 #ifdef CONFIG_VIRT_CPU_ACCOUNTING
970 .long io_leave + 18 + 0x80000000
972 .long io_leave + 14 + 0x80000000
978 .Lc_spsize: .long SP_SIZE
979 .Lc_overhead: .long STACK_FRAME_OVERHEAD
980 .Lc_pactive: .long PREEMPT_ACTIVE
981 .Lnr_syscalls: .long NR_syscalls
982 .L0x018: .short 0x018
983 .L0x020: .short 0x020
984 .L0x028: .short 0x028
985 .L0x030: .short 0x030
986 .L0x038: .short 0x038
992 .Ls390_mcck: .long s390_do_machine_check
994 .long s390_handle_mcck
995 .Lmck_old_psw: .long __LC_MCK_OLD_PSW
996 .Ldo_IRQ: .long do_IRQ
997 .Ldo_extint: .long do_extint
998 .Ldo_signal: .long do_signal
999 .Lhandle_per: .long do_single_step
1000 .Ljump_table: .long pgm_check_table
1001 .Lschedule: .long schedule
1002 .Lclone: .long sys_clone
1003 .Lexecve: .long sys_execve
1004 .Lfork: .long sys_fork
1005 .Lrt_sigreturn:.long sys_rt_sigreturn
1007 .long sys_rt_sigsuspend
1008 .Lsigreturn: .long sys_sigreturn
1009 .Lsigsuspend: .long sys_sigsuspend
1010 .Lsigaltstack: .long sys_sigaltstack
1011 .Ltrace: .long syscall_trace
1012 .Lvfork: .long sys_vfork
1013 .Lschedtail: .long schedule_tail
1014 .Lsysc_table: .long sys_call_table
1017 .long __critical_start + 0x80000000
1019 .long __critical_end + 0x80000000
1021 .long cleanup_critical
1023 .section .rodata, "a"
1024 #define SYSCALL(esa,esame,emu) .long esa
1026 #include "syscalls.S"