ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / arch / s390 / kernel / entry.S
1 /*
2  *  arch/s390/kernel/entry.S
3  *    S390 low-level entry points.
4  *
5  *  S390 version
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  */
11
12 #include <linux/sys.h>
13 #include <linux/linkage.h>
14 #include <linux/config.h>
15 #include <asm/cache.h>
16 #include <asm/lowcore.h>
17 #include <asm/errno.h>
18 #include <asm/ptrace.h>
19 #include <asm/thread_info.h>
20 #include <asm/offsets.h>
21 #include <asm/unistd.h>
22
23 /*
24  * Stack layout for the system_call stack entry.
25  * The first few entries are identical to the user_regs_struct.
26  */
27 SP_PTREGS    =  STACK_FRAME_OVERHEAD 
28 SP_PSW       =  STACK_FRAME_OVERHEAD + __PT_PSW
29 SP_R0        =  STACK_FRAME_OVERHEAD + __PT_GPRS
30 SP_R1        =  STACK_FRAME_OVERHEAD + __PT_GPRS + 4
31 SP_R2        =  STACK_FRAME_OVERHEAD + __PT_GPRS + 8
32 SP_R3        =  STACK_FRAME_OVERHEAD + __PT_GPRS + 12
33 SP_R4        =  STACK_FRAME_OVERHEAD + __PT_GPRS + 16
34 SP_R5        =  STACK_FRAME_OVERHEAD + __PT_GPRS + 20
35 SP_R6        =  STACK_FRAME_OVERHEAD + __PT_GPRS + 24
36 SP_R7        =  STACK_FRAME_OVERHEAD + __PT_GPRS + 28
37 SP_R8        =  STACK_FRAME_OVERHEAD + __PT_GPRS + 32
38 SP_R9        =  STACK_FRAME_OVERHEAD + __PT_GPRS + 36
39 SP_R10       =  STACK_FRAME_OVERHEAD + __PT_GPRS + 40
40 SP_R11       =  STACK_FRAME_OVERHEAD + __PT_GPRS + 44
41 SP_R12       =  STACK_FRAME_OVERHEAD + __PT_GPRS + 48
42 SP_R13       =  STACK_FRAME_OVERHEAD + __PT_GPRS + 52
43 SP_R14       =  STACK_FRAME_OVERHEAD + __PT_GPRS + 56
44 SP_R15       =  STACK_FRAME_OVERHEAD + __PT_GPRS + 60
45 SP_ORIG_R2   =  STACK_FRAME_OVERHEAD + __PT_ORIG_GPR2
46 SP_ILC       =  STACK_FRAME_OVERHEAD + __PT_ILC
47 SP_TRAP      =  STACK_FRAME_OVERHEAD + __PT_TRAP
48 SP_SIZE      =  STACK_FRAME_OVERHEAD + __PT_SIZE
49
50 _TIF_WORK_SVC = (_TIF_SIGPENDING | _TIF_NEED_RESCHED | _TIF_RESTART_SVC)
51 _TIF_WORK_INT = (_TIF_SIGPENDING | _TIF_NEED_RESCHED)
52
53 #define BASED(name) name-system_call(%r13)
54
55 /*
56  * Register usage in interrupt handlers:
57  *    R9  - pointer to current task structure
58  *    R13 - pointer to literal pool
59  *    R14 - return register for function calls
60  *    R15 - kernel stack pointer
61  */
62
63         .macro  SAVE_ALL_BASE psworg,savearea,sync
64         stm     %r12,%r15,\savearea
65         l       %r13,__LC_SVC_NEW_PSW+4   # load &system_call to %r13
66         .endm
67
68         .macro  CLEANUP_SAVE_ALL_BASE psworg,savearea,sync
69         l       %r1,SP_PSW+4(%r15)
70         cli     1(%r1),0xcf
71         jne     0f
72         mvc     \savearea(16),SP_R12(%r15)
73 0:      st      %r13,SP_R13(%r15)
74         .endm
75
76         .macro  SAVE_ALL psworg,savearea,sync
77         .if     \sync
78         tm      \psworg+1,0x01            # test problem state bit
79         bz      BASED(1f)                 # skip stack setup save
80         l       %r15,__LC_KERNEL_STACK    # problem state -> load ksp
81         .else
82         tm      \psworg+1,0x01            # test problem state bit
83         bnz     BASED(0f)                 # from user -> load async stack
84         l       %r14,__LC_ASYNC_STACK     # are we already on the async stack ?
85         slr     %r14,%r15
86         sra     %r14,13
87         be      BASED(1f)
88 0:      l       %r15,__LC_ASYNC_STACK
89         .endif
90 1:      s       %r15,BASED(.Lc_spsize)    # make room for registers & psw
91         l       %r14,BASED(.L\psworg)
92         slr     %r12,%r12
93         icm     %r14,12,__LC_SVC_ILC
94         stm     %r0,%r11,SP_R0(%r15)      # store gprs 0-12 to kernel stack
95         st      %r2,SP_ORIG_R2(%r15)      # store original content of gpr 2
96         mvc     SP_R12(16,%r15),\savearea # move R13-R15 to stack
97         mvc     SP_PSW(8,%r15),\psworg    # move user PSW to stack
98         st      %r14,SP_ILC(%r15)
99         st      %r12,0(%r15)              # clear back chain
100         .endm
101
102         .macro  CLEANUP_SAVE_ALL psworg,savearea,sync
103         l       %r1,\savearea+12
104         .if     \sync
105         tm      \psworg+1,0x01
106         bz      BASED(1f)
107         l       %r1,__LC_KERNEL_STACK
108         .else
109         tm      \psworg+1,0x01
110         bnz     BASED(0f)
111         l       %r0,__LC_ASYNC_STACK
112         slr     %r0,%r1
113         sra     %r0,13
114         bz      BASED(1f)
115 0:      l       %r1,__LC_ASYNC_STACK
116         .endif
117 1:      s       %r1,BASED(.Lc_spsize)
118         st      %r1,SP_R15(%r15)
119         l       %r0,BASED(.L\psworg)
120         xc      SP_R12(4,%r15),SP_R12(%r15)
121         icm     %r0,12,__LC_SVC_ILC
122         st      %r0,SP_R14(%r15)
123         mvc     SP_R0(48,%r1),SP_R0(%r15)
124         mvc     SP_ORIG_R2(4,%r1),SP_R2(%r15)
125         mvc     SP_R12(16,%r1),\savearea
126         mvc     SP_PSW(8,%r1),\psworg
127         st      %r0,SP_ILC(%r1)
128         xc      0(4,%r1),0(%r1)
129         .endm
130
131         .macro  RESTORE_ALL               # system exit macro
132         mvc     __LC_RETURN_PSW(8),SP_PSW(%r15)  # move user PSW to lowcore
133         ni      __LC_RETURN_PSW+1,0xfd    # clear wait state bit
134         lm      %r0,%r15,SP_R0(%r15)      # load gprs 0-15 of user
135         lpsw    __LC_RETURN_PSW           # back to caller
136         .endm
137
138         .macro  CLEANUP_RESTORE_ALL
139         l       %r1,SP_PSW+4(%r15)
140         cli     0(%r1),0x82
141         jne     0f
142         mvc     SP_PSW(8,%r15),__LC_RETURN_PSW
143         j       1f
144 0:      l       %r1,SP_R15(%r15)
145         mvc     SP_PSW(8,%r15),SP_PSW(%r1)
146         mvc     SP_R0(64,%r15),SP_R0(%r1)
147 1:
148         .endm
149
150         .macro  GET_THREAD_INFO
151         l       %r9,__LC_THREAD_INFO
152         .endm
153
154         .macro  CHECK_CRITICAL
155         tm      SP_PSW+1(%r15),0x01      # test problem state bit
156         bnz     BASED(0f)                # from user -> not critical
157         clc     SP_PSW+4(4,%r15),BASED(.Lcritical_end)
158         jnl     0f
159         clc     SP_PSW+4(4,%r15),BASED(.Lcritical_start)
160         jl      0f
161         l       %r1,BASED(.Lcleanup_critical)
162         basr    %r14,%r1
163 0:
164         .endm
165
166 /*
167  * Scheduler resume function, called by switch_to
168  *  gpr2 = (task_struct *) prev
169  *  gpr3 = (task_struct *) next
170  * Returns:
171  *  gpr2 = prev
172  */
173         .globl  __switch_to
174 __switch_to:
175         basr    %r1,0
176 __switch_to_base:
177         tm      __THREAD_per(%r3),0xe8          # new process is using per ?
178         bz      __switch_to_noper-__switch_to_base(%r1) # if not we're fine
179         stctl   %c9,%c11,24(%r15)               # We are using per stuff
180         clc     __THREAD_per(12,%r3),24(%r15)
181         be      __switch_to_noper-__switch_to_base(%r1) # we got away w/o bashing TLB's
182         lctl    %c9,%c11,__THREAD_per(%r3)      # Nope we didn't
183 __switch_to_noper:
184         stm     %r6,%r15,24(%r15)       # store __switch_to registers of prev task
185         st      %r15,__THREAD_ksp(%r2)  # store kernel stack to prev->tss.ksp
186         l       %r15,__THREAD_ksp(%r3)  # load kernel stack from next->tss.ksp
187         lm      %r6,%r15,24(%r15)       # load __switch_to registers of next task
188         st      %r3,__LC_CURRENT        # __LC_CURRENT = current task struct
189         l       %r3,__THREAD_info(%r3)  # load thread_info from task struct
190         st      %r3,__LC_THREAD_INFO
191         ahi     %r3,8192
192         st      %r3,__LC_KERNEL_STACK   # __LC_KERNEL_STACK = new kernel stack
193         br      %r14
194
195 /*
196  * do_softirq calling function. We want to run the softirq functions on the
197  * asynchronous interrupt stack.
198  */
199         .global do_call_softirq
200 do_call_softirq:
201         stnsm   24(%r15),0xfc
202         stm     %r12,%r15,28(%r15)
203         lr      %r12,%r15
204         basr    %r13,0
205 do_call_base:
206         l       %r0,__LC_ASYNC_STACK
207         slr     %r0,%r15
208         sra     %r0,13
209         be      0f-do_call_base(%r13)
210         l       %r15,__LC_ASYNC_STACK
211 0:      sl      %r15,.Lc_overhead-do_call_base(%r13)
212         st      %r12,0(%r15)    # store backchain
213         l       %r1,.Ldo_softirq-do_call_base(%r13)
214         basr    %r14,%r1
215         lm      %r12,%r15,28(%r12)
216         ssm     24(%r15)
217         br      %r14
218         
219 __critical_start:
220 /*
221  * SVC interrupt handler routine. System calls are synchronous events and
222  * are executed with interrupts enabled.
223  */
224
225         .globl  system_call
226 system_call:
227         SAVE_ALL_BASE __LC_SVC_OLD_PSW,__LC_SAVE_AREA,1
228         SAVE_ALL __LC_SVC_OLD_PSW,__LC_SAVE_AREA,1
229         lh      %r7,0x8a          # get svc number from lowcore
230 sysc_enter:
231         GET_THREAD_INFO           # load pointer to task_struct to R9
232         sla     %r7,2             # *4 and test for svc 0
233         bnz     BASED(sysc_do_restart)  # svc number > 0
234         # svc 0: system call number in %r1
235         cl      %r1,BASED(.Lnr_syscalls)
236         bnl     BASED(sysc_do_restart)
237         lr      %r7,%r1           # copy svc number to %r7
238         sla     %r7,2             # *4
239 sysc_do_restart:
240         tm      __TI_flags+3(%r9),(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT)
241         l       %r8,sys_call_table-system_call(%r7,%r13) # get system call addr.
242         bo      BASED(sysc_tracesys)
243         basr    %r14,%r8          # call sys_xxxx
244         st      %r2,SP_R2(%r15)   # store return value (change R2 on stack)
245                                   # ATTENTION: check sys_execve_glue before
246                                   # changing anything here !!
247
248 sysc_return:
249         tm      SP_PSW+1(%r15),0x01     # returning to user ?
250         bno     BASED(sysc_leave)
251         tm      __TI_flags+3(%r9),_TIF_WORK_SVC
252         bnz     BASED(sysc_work)  # there is work to do (signals etc.)
253 sysc_leave:
254         RESTORE_ALL
255
256 #
257 # recheck if there is more work to do
258 #
259 sysc_work_loop:
260         GET_THREAD_INFO           # load pointer to task_struct to R9
261         tm      __TI_flags+3(%r9),_TIF_WORK_SVC
262         bz      BASED(sysc_leave)      # there is no work to do
263 #
264 # One of the work bits is on. Find out which one.
265 # Checked are: _TIF_SIGPENDING and _TIF_NEED_RESCHED
266 #
267 sysc_work:
268         tm      __TI_flags+3(%r9),_TIF_NEED_RESCHED
269         bo      BASED(sysc_reschedule)
270         tm      __TI_flags+3(%r9),_TIF_SIGPENDING
271         bo      BASED(sysc_sigpending)
272         tm      __TI_flags+3(%r9),_TIF_RESTART_SVC
273         bo      BASED(sysc_restart)
274         b       BASED(sysc_leave)
275
276 #
277 # _TIF_NEED_RESCHED is set, call schedule
278 #       
279 sysc_reschedule:        
280         l       %r1,BASED(.Lschedule)
281         la      %r14,BASED(sysc_work_loop)
282         br      %r1                    # call scheduler
283
284 #
285 # _TIF_SIGPENDING is set, call do_signal
286 #
287 sysc_sigpending:     
288         la      %r2,SP_PTREGS(%r15)    # load pt_regs
289         sr      %r3,%r3                # clear *oldset
290         l       %r1,BASED(.Ldo_signal)
291         basr    %r14,%r1               # call do_signal
292         tm      __TI_flags+3(%r9),_TIF_RESTART_SVC
293         bo      BASED(sysc_restart)
294         b       BASED(sysc_leave)      # out of here, do NOT recheck
295
296 #
297 # _TIF_RESTART_SVC is set, set up registers and restart svc
298 #
299 sysc_restart:
300         ni      __TI_flags+3(%r9),255-_TIF_RESTART_SVC # clear TIF_RESTART_SVC
301         l       %r7,SP_R2(%r15)        # load new svc number
302         sla     %r7,2
303         mvc     SP_R2(4,%r15),SP_ORIG_R2(%r15) # restore first argument
304         lm      %r2,%r6,SP_R2(%r15)    # load svc arguments
305         b       BASED(sysc_do_restart) # restart svc
306
307 __critical_end:
308
309 #
310 # call trace before and after sys_call
311 #
312 sysc_tracesys:
313         l       %r1,BASED(.Ltrace)
314         la      %r2,SP_PTREGS(%r15)    # load pt_regs
315         la      %r3,0
316         srl     %r7,2
317         st      %r7,SP_R2(%r15)
318         basr    %r14,%r1
319         clc     SP_R2(4,%r15),BASED(.Lnr_syscalls)
320         bnl     BASED(sysc_tracenogo)
321         l       %r7,SP_R2(%r15)        # strace might have changed the 
322         sll     %r7,2                  #  system call
323         l       %r8,sys_call_table-system_call(%r7,%r13)
324 sysc_tracego:
325         lm      %r3,%r6,SP_R3(%r15)
326         l       %r2,SP_ORIG_R2(%r15)
327         basr    %r14,%r8          # call sys_xxx
328         st      %r2,SP_R2(%r15)   # store return value
329 sysc_tracenogo:
330         tm      __TI_flags+3(%r9),(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT)
331         bno     BASED(sysc_return)
332         l       %r1,BASED(.Ltrace)
333         la      %r2,SP_PTREGS(%r15)    # load pt_regs
334         la      %r3,1
335         la      %r14,BASED(sysc_return)
336         br      %r1
337
338 #
339 # a new process exits the kernel with ret_from_fork
340 #
341         .globl  ret_from_fork
342 ret_from_fork:
343         l       %r13,__LC_SVC_NEW_PSW+4
344         GET_THREAD_INFO           # load pointer to task_struct to R9
345         l       %r1,BASED(.Lschedtail)
346         basr    %r14,%r1
347         stosm   24(%r15),0x03     # reenable interrupts
348         b       BASED(sysc_return)
349
350 #
351 # clone, fork, vfork, exec and sigreturn need glue,
352 # because they all expect pt_regs as parameter,
353 # but are called with different parameter.
354 # return-address is set up above
355 #
356 sys_clone_glue: 
357         la      %r2,SP_PTREGS(%r15)    # load pt_regs
358         l       %r1,BASED(.Lclone)
359         br      %r1                   # branch to sys_clone
360
361 sys_fork_glue:  
362         la      %r2,SP_PTREGS(%r15)    # load pt_regs
363         l       %r1,BASED(.Lfork)
364         br      %r1                   # branch to sys_fork
365
366 sys_vfork_glue: 
367         la      %r2,SP_PTREGS(%r15)    # load pt_regs
368         l       %r1,BASED(.Lvfork)
369         br      %r1                   # branch to sys_vfork
370
371 sys_execve_glue:        
372         la      %r2,SP_PTREGS(%r15)   # load pt_regs
373         l       %r1,BASED(.Lexecve)
374         lr      %r12,%r14             # save return address
375         basr    %r14,%r1              # call sys_execve
376         ltr     %r2,%r2               # check if execve failed
377         bnz     0(%r12)               # it did fail -> store result in gpr2
378         b       4(%r12)               # SKIP ST 2,SP_R2(15) after BASR 14,8
379                                       # in system_call/sysc_tracesys
380
381 sys_sigreturn_glue:     
382         la      %r2,SP_PTREGS(%r15)   # load pt_regs as parameter
383         l       %r1,BASED(.Lsigreturn)
384         br      %r1                   # branch to sys_sigreturn
385
386 sys_rt_sigreturn_glue:     
387         la      %r2,SP_PTREGS(%r15)   # load pt_regs as parameter
388         l       %r1,BASED(.Lrt_sigreturn)
389         br      %r1                   # branch to sys_sigreturn
390
391 #
392 # sigsuspend and rt_sigsuspend need pt_regs as an additional
393 # parameter and they have to skip the store of %r2 into the
394 # user register %r2 because the return value was set in 
395 # sigsuspend and rt_sigsuspend already and must not be overwritten!
396 #
397
398 sys_sigsuspend_glue:    
399         lr      %r5,%r4               # move mask back
400         lr      %r4,%r3               # move history1 parameter
401         lr      %r3,%r2               # move history0 parameter
402         la      %r2,SP_PTREGS(%r15)   # load pt_regs as first parameter
403         l       %r1,BASED(.Lsigsuspend)
404         la      %r14,4(%r14)          # skip store of return value
405         br      %r1                   # branch to sys_sigsuspend
406
407 sys_rt_sigsuspend_glue: 
408         lr      %r4,%r3               # move sigsetsize parameter
409         lr      %r3,%r2               # move unewset parameter
410         la      %r2,SP_PTREGS(%r15)   # load pt_regs as first parameter
411         l       %r1,BASED(.Lrt_sigsuspend)
412         la      %r14,4(%r14)          # skip store of return value
413         br      %r1                   # branch to sys_rt_sigsuspend
414
415 sys_sigaltstack_glue:
416         la      %r4,SP_PTREGS(%r15)   # load pt_regs as parameter
417         l       %r1,BASED(.Lsigaltstack)
418         br      %r1                   # branch to sys_sigreturn
419
420
421 /*
422  * Program check handler routine
423  */
424
425         .globl  pgm_check_handler
426 pgm_check_handler:
427 /*
428  * First we need to check for a special case:
429  * Single stepping an instruction that disables the PER event mask will
430  * cause a PER event AFTER the mask has been set. Example: SVC or LPSW.
431  * For a single stepped SVC the program check handler gets control after
432  * the SVC new PSW has been loaded. But we want to execute the SVC first and
433  * then handle the PER event. Therefore we update the SVC old PSW to point
434  * to the pgm_check_handler and branch to the SVC handler after we checked
435  * if we have to load the kernel stack register.
436  * For every other possible cause for PER event without the PER mask set
437  * we just ignore the PER event (FIXME: is there anything we have to do
438  * for LPSW?).
439  */
440         SAVE_ALL_BASE __LC_PGM_OLD_PSW,__LC_SAVE_AREA,1
441         tm      __LC_PGM_INT_CODE+1,0x80 # check whether we got a per exception
442         bnz     BASED(pgm_per)           # got per exception -> special case
443         SAVE_ALL __LC_PGM_OLD_PSW,__LC_SAVE_AREA,1
444         l       %r3,__LC_PGM_ILC         # load program interruption code
445         la      %r8,0x7f
446         l       %r7,BASED(.Ljump_table)
447         nr      %r8,%r3
448         sll     %r8,2
449         GET_THREAD_INFO
450         l       %r7,0(%r8,%r7)           # load address of handler routine
451         la      %r2,SP_PTREGS(%r15)      # address of register-save area
452         la      %r14,BASED(sysc_return)
453         br      %r7                      # branch to interrupt-handler
454
455 #
456 # handle per exception
457 #
458 pgm_per:
459         tm      __LC_PGM_OLD_PSW,0x40    # test if per event recording is on
460         bnz     BASED(pgm_per_std)       # ok, normal per event from user space
461 # ok its one of the special cases, now we need to find out which one
462         clc     __LC_PGM_OLD_PSW(8),__LC_SVC_NEW_PSW
463         be      BASED(pgm_svcper)
464 # no interesting special case, ignore PER event
465         lm      %r13,%r15,__LC_SAVE_AREA
466         lpsw    0x28
467
468 #
469 # Normal per exception
470 #
471 pgm_per_std:
472         SAVE_ALL __LC_PGM_OLD_PSW,__LC_SAVE_AREA,1
473         GET_THREAD_INFO
474         mvc     __THREAD_per+__PER_atmid(2,%r9),__LC_PER_ATMID
475         mvc     __THREAD_per+__PER_address(4,%r9),__LC_PER_ADDRESS
476         mvc     __THREAD_per+__PER_access_id(1,%r9),__LC_PER_ACCESS_ID
477         la      %r4,0x7f
478         l       %r3,__LC_PGM_ILC         # load program interruption code
479         nr      %r4,%r3                  # clear per-event-bit and ilc
480         be      BASED(pgm_per_only)      # only per or per+check ?
481         l       %r1,BASED(.Ljump_table)
482         sll     %r4,2
483         l       %r1,0(%r4,%r1)           # load address of handler routine
484         la      %r2,SP_PTREGS(%r15)      # address of register-save area
485         basr    %r14,%r1                 # branch to interrupt-handler
486 pgm_per_only:
487         la      %r2,SP_PTREGS(15)        # address of register-save area
488         l       %r1,BASED(.Lhandle_per)  # load adr. of per handler
489         la      %r14,BASED(sysc_return)  # load adr. of system return
490         br      %r1                      # branch to do_debugger_trap
491
492 #
493 # it was a single stepped SVC that is causing all the trouble
494 #
495 pgm_svcper:
496         SAVE_ALL __LC_SVC_OLD_PSW,__LC_SAVE_AREA,1
497         lh      %r7,0x8a          # get svc number from lowcore
498         stosm   24(%r15),0x03     # reenable interrupts
499         GET_THREAD_INFO           # load pointer to task_struct to R9
500         mvc     __THREAD_per+__PER_atmid(2,%r9),__LC_PER_ATMID
501         mvc     __THREAD_per+__PER_address(4,%r9),__LC_PER_ADDRESS
502         mvc     __THREAD_per+__PER_access_id(1,%r9),__LC_PER_ACCESS_ID
503         sla     %r7,2             # *4 and test for svc 0
504         bnz     BASED(pgm_svcstd) # svc number > 0 ?
505         # svc 0: system call number in %r1
506         cl      %r1,BASED(.Lnr_syscalls)
507         bnl     BASED(pgm_svcstd)
508         lr      %r7,%r1           # copy svc number to %r7
509         sla     %r7,2             # *4
510 pgm_svcstd:
511         tm      __TI_flags+3(%r9),(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT)
512         l       %r8,sys_call_table-system_call(%r7,%r13) # get system call addr.
513         bo      BASED(pgm_tracesys)
514         basr    %r14,%r8          # call sys_xxxx
515         st      %r2,SP_R2(%r15)   # store return value (change R2 on stack)
516                                   # ATTENTION: check sys_execve_glue before
517                                   # changing anything here !!
518
519 pgm_svcret:
520         tm      __TI_flags+3(%r9),_TIF_SIGPENDING
521         bno     BASED(pgm_svcper_nosig)
522         la      %r2,SP_PTREGS(%r15) # load pt_regs
523         sr      %r3,%r3           # clear *oldset
524         l       %r1,BASED(.Ldo_signal)
525         basr    %r14,%r1          # call do_signal
526         
527 pgm_svcper_nosig:
528         mvi     SP_TRAP+3(%r15),0x28     # set trap indication to pgm check
529         la      %r2,SP_PTREGS(15)        # address of register-save area
530         l       %r1,BASED(.Lhandle_per)  # load adr. of per handler
531         la      %r14,BASED(sysc_return)  # load adr. of system return
532         br      %r1                      # branch to do_debugger_trap
533 #
534 # call trace before and after sys_call
535 #
536 pgm_tracesys:
537         l       %r1,BASED(.Ltrace)
538         la      %r2,SP_PTREGS(%r15)    # load pt_regs
539         la      %r3,0
540         srl     %r7,2
541         st      %r7,SP_R2(%r15)
542         basr    %r14,%r1
543         clc     SP_R2(4,%r15),BASED(.Lnr_syscalls)
544         bnl     BASED(pgm_svc_nogo)
545         l       %r7,SP_R2(%r15)   # strace changed the syscall
546         sll     %r7,2
547         l       %r8,sys_call_table-system_call(%r7,%r13)
548 pgm_svc_go:
549         lm      %r3,%r6,SP_R3(%r15)
550         l       %r2,SP_ORIG_R2(%r15)
551         basr    %r14,%r8          # call sys_xxx
552         st      %r2,SP_R2(%r15)   # store return value
553 pgm_svc_nogo:
554         tm      __TI_flags+3(%r9),(_TIF_SYSCALL_TRACE|_TIF_SYSCALL_AUDIT)
555         bno     BASED(pgm_svcret)
556         l       %r1,BASED(.Ltrace)
557         la      %r2,SP_PTREGS(%r15)    # load pt_regs
558         la      %r3,1
559         la      %r14,BASED(pgm_svcret)
560         br      %r1
561
562 /*
563  * IO interrupt handler routine
564  */
565
566         .globl io_int_handler
567 io_int_handler:
568         SAVE_ALL_BASE __LC_IO_OLD_PSW,__LC_SAVE_AREA+16,0
569         SAVE_ALL __LC_IO_OLD_PSW,__LC_SAVE_AREA+16,0
570         stck    __LC_INT_CLOCK
571         CHECK_CRITICAL
572         GET_THREAD_INFO           # load pointer to task_struct to R9
573         l       %r1,BASED(.Ldo_IRQ)        # load address of do_IRQ
574         la      %r2,SP_PTREGS(%r15) # address of register-save area
575         basr    %r14,%r1          # branch to standard irq handler
576
577 io_return:
578         tm      SP_PSW+1(%r15),0x01    # returning to user ?
579 #ifdef CONFIG_PREEMPT
580         bno     BASED(io_preempt)      # no -> check for preemptive scheduling
581 #else
582         bno     BASED(io_leave)        # no-> skip resched & signal
583 #endif
584         tm      __TI_flags+3(%r9),_TIF_WORK_INT
585         bnz     BASED(io_work)         # there is work to do (signals etc.)
586 io_leave:
587         RESTORE_ALL
588
589 #ifdef CONFIG_PREEMPT
590 io_preempt:
591         icm     %r0,15,__TI_precount(%r9)
592         bnz     BASED(io_leave)
593         l       %r1,SP_R15(%r15)
594         s       %r1,BASED(.Lc_spsize)
595         mvc     SP_PTREGS(__PT_SIZE,%r1),SP_PTREGS(%r15)
596         xc      0(4,%r1),0(%r1)        # clear back chain
597         lr      %r15,%r1
598 io_resume_loop:
599         tm      __TI_flags+3(%r9),_TIF_NEED_RESCHED
600         bno     BASED(io_leave)
601         mvc     __TI_precount(4,%r9),BASED(.Lc_pactive)
602         stosm   24(%r15),0x03          # reenable interrupts
603         l       %r1,BASED(.Lschedule)
604         basr    %r14,%r1               # call schedule
605         stnsm   24(%r15),0xfc          # disable I/O and ext. interrupts
606         GET_THREAD_INFO                # load pointer to task_struct to R9
607         xc      __TI_precount(4,%r9),__TI_precount(%r9)
608         b       BASED(io_resume_loop)
609 #endif
610
611 #
612 # switch to kernel stack, then check the TIF bits
613 #
614 io_work:
615         l       %r1,__LC_KERNEL_STACK
616         s       %r1,BASED(.Lc_spsize)
617         mvc     SP_PTREGS(__PT_SIZE,%r1),SP_PTREGS(%r15)
618         xc      0(4,%r1),0(%r1)        # clear back chain
619         lr      %r15,%r1
620 #
621 # One of the work bits is on. Find out which one.
622 # Checked are: _TIF_SIGPENDING and _TIF_NEED_RESCHED
623 #
624 io_work_loop:
625         tm      __TI_flags+3(%r9),_TIF_NEED_RESCHED
626         bo      BASED(io_reschedule)
627         tm      __TI_flags+3(%r9),_TIF_SIGPENDING
628         bo      BASED(io_sigpending)
629         b       BASED(io_leave)
630
631 #
632 # _TIF_NEED_RESCHED is set, call schedule
633 #       
634 io_reschedule:        
635         l       %r1,BASED(.Lschedule)
636         stosm   24(%r15),0x03          # reenable interrupts
637         basr    %r14,%r1               # call scheduler
638         stnsm   24(%r15),0xfc          # disable I/O and ext. interrupts
639         GET_THREAD_INFO                # load pointer to task_struct to R9
640         tm      __TI_flags+3(%r9),_TIF_WORK_INT
641         bz      BASED(io_leave)        # there is no work to do
642         b       BASED(io_work_loop)
643
644 #
645 # _TIF_SIGPENDING is set, call do_signal
646 #
647 io_sigpending:     
648         stosm   24(%r15),0x03          # reenable interrupts
649         la      %r2,SP_PTREGS(%r15)    # load pt_regs
650         sr      %r3,%r3                # clear *oldset
651         l       %r1,BASED(.Ldo_signal)
652         basr    %r14,%r1               # call do_signal
653         stnsm   24(%r15),0xfc          # disable I/O and ext. interrupts
654         b       BASED(io_leave)        # out of here, do NOT recheck
655
656 /*
657  * External interrupt handler routine
658  */
659
660         .globl  ext_int_handler
661 ext_int_handler:
662         SAVE_ALL_BASE __LC_EXT_OLD_PSW,__LC_SAVE_AREA+16,0
663         SAVE_ALL __LC_EXT_OLD_PSW,__LC_SAVE_AREA+16,0
664         stck    __LC_INT_CLOCK
665         CHECK_CRITICAL
666         GET_THREAD_INFO                # load pointer to task_struct to R9
667         la      %r2,SP_PTREGS(%r15)    # address of register-save area
668         lh      %r3,__LC_EXT_INT_CODE  # get interruption code
669         l       %r1,BASED(.Ldo_extint)
670         basr    %r14,%r1
671         b       BASED(io_return)
672
673 /*
674  * Machine check handler routines
675  */
676
677         .globl mcck_int_handler
678 mcck_int_handler:
679         SAVE_ALL_BASE __LC_MCK_OLD_PSW,__LC_SAVE_AREA+32,0
680         SAVE_ALL __LC_MCK_OLD_PSW,__LC_SAVE_AREA+32,0
681         l       %r1,BASED(.Ls390_mcck)
682         basr    %r14,%r1          # call machine check handler
683 mcck_return:
684         RESTORE_ALL
685
686 #ifdef CONFIG_SMP
687 /*
688  * Restart interruption handler, kick starter for additional CPUs
689  */
690         .globl restart_int_handler
691 restart_int_handler:
692         l       %r15,__LC_SAVE_AREA+60 # load ksp
693         lctl    %c0,%c15,__LC_CREGS_SAVE_AREA # get new ctl regs
694         lam     %a0,%a15,__LC_AREGS_SAVE_AREA
695         stosm   0(%r15),0x04           # now we can turn dat on
696         lm      %r6,%r15,24(%r15)      # load registers from clone
697         basr    %r14,0
698         l       %r14,restart_addr-.(%r14)
699         br      %r14                   # branch to start_secondary
700 restart_addr:
701         .long   start_secondary
702 #else
703 /*
704  * If we do not run with SMP enabled, let the new CPU crash ...
705  */
706         .globl restart_int_handler
707 restart_int_handler:
708         basr    %r1,0
709 restart_base:
710         lpsw    restart_crash-restart_base(%r1)
711         .align 8
712 restart_crash:
713         .long  0x000a0000,0x00000000
714 restart_go:
715 #endif
716
717 cleanup_table:
718         .long   system_call, sysc_enter, cleanup_sysc_enter
719         .long   sysc_return, sysc_leave, cleanup_sysc_return
720         .long   sysc_leave, sysc_work_loop, cleanup_sysc_leave
721         .long   sysc_work_loop, sysc_reschedule, cleanup_sysc_return
722 cleanup_table_entries=(.-cleanup_table) / 12
723
724 cleanup_critical:
725         lhi     %r0,cleanup_table_entries
726         la      %r1,BASED(cleanup_table)
727         l       %r2,SP_PSW+4(%r15)
728         la      %r2,0(%r2)
729 cleanup_loop:
730         cl      %r2,0(%r1)
731         bl      BASED(cleanup_cont)
732         cl      %r2,4(%r1)
733         bl      BASED(cleanup_found)
734 cleanup_cont:
735         la      %r1,12(%r1)
736         bct     %r0,BASED(cleanup_loop)
737         br      %r14
738 cleanup_found:
739         l       %r1,8(%r1)
740         br      %r1
741
742 cleanup_sysc_enter:
743         CLEANUP_SAVE_ALL_BASE __LC_SVC_OLD_PSW,__LC_SAVE_AREA,1
744         CLEANUP_SAVE_ALL __LC_SVC_OLD_PSW,__LC_SAVE_AREA,1
745         lh      %r0,0x8a
746         st      %r0,SP_R7(%r15)
747         la      %r1,BASED(sysc_enter)
748         o       %r1,BASED(.Lamode)
749         st      %r1,SP_PSW+4(%r15)
750         br      %r14
751
752 cleanup_sysc_return:
753         la      %r1,BASED(sysc_return)
754         o       %r1,BASED(.Lamode)
755         st      %r1,SP_PSW+4(%r15)
756         br      %r14
757
758 cleanup_sysc_leave:
759         CLEANUP_RESTORE_ALL
760         br      %r14
761
762 /*
763  * Integer constants
764  */
765                .align 4
766 .Lc_spsize:    .long  SP_SIZE
767 .Lc_overhead:  .long  STACK_FRAME_OVERHEAD
768 .Lc_pactive:   .long  PREEMPT_ACTIVE
769 .Lnr_syscalls: .long  NR_syscalls
770 .L0x018:       .long  0x018
771 .L0x020:       .long  0x020
772 .L0x028:       .long  0x028
773 .L0x030:       .long  0x030
774 .L0x038:       .long  0x038
775 .Lamode:       .long  0x80000000
776
777 /*
778  * Symbol constants
779  */
780 .Ls390_mcck:   .long  s390_do_machine_check
781 .Ldo_IRQ:      .long  do_IRQ
782 .Ldo_extint:   .long  do_extint
783 .Ldo_signal:   .long  do_signal
784 .Ldo_softirq:  .long  do_softirq
785 .Lhandle_per:  .long  do_debugger_trap
786 .Ljump_table:  .long  pgm_check_table
787 .Lschedule:    .long  schedule
788 .Lclone:       .long  sys_clone
789 .Lexecve:      .long  sys_execve
790 .Lfork:        .long  sys_fork
791 .Lrt_sigreturn:.long  sys_rt_sigreturn
792 .Lrt_sigsuspend:
793                .long  sys_rt_sigsuspend
794 .Lsigreturn:   .long  sys_sigreturn
795 .Lsigsuspend:  .long  sys_sigsuspend
796 .Lsigaltstack: .long  sys_sigaltstack
797 .Ltrace:       .long  syscall_trace
798 .Lvfork:       .long  sys_vfork
799 .Lschedtail:   .long  schedule_tail
800
801 .Lcritical_start:
802                .long  __critical_start + 0x80000000
803 .Lcritical_end:
804                .long  __critical_end + 0x80000000
805 .Lcleanup_critical:
806                .long  cleanup_critical
807
808 #define SYSCALL(esa,esame,emu)  .long esa
809         .globl  sys_call_table
810 sys_call_table:
811 #include "syscalls.S"
812 #undef SYSCALL
813