xref: /linux/arch/s390/kernel/entry.S (revision 08ec212c0f92cbf30e3ecc7349f18151714041d6)
1/*
2 *    S390 low-level entry points.
3 *
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>
9 */
10
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>
19#include <asm/page.h>
20#include <asm/sigp.h>
21
22__PT_R0      =	__PT_GPRS
23__PT_R1      =	__PT_GPRS + 4
24__PT_R2      =	__PT_GPRS + 8
25__PT_R3      =	__PT_GPRS + 12
26__PT_R4      =	__PT_GPRS + 16
27__PT_R5      =	__PT_GPRS + 20
28__PT_R6      =	__PT_GPRS + 24
29__PT_R7      =	__PT_GPRS + 28
30__PT_R8      =	__PT_GPRS + 32
31__PT_R9      =	__PT_GPRS + 36
32__PT_R10     =	__PT_GPRS + 40
33__PT_R11     =	__PT_GPRS + 44
34__PT_R12     =	__PT_GPRS + 48
35__PT_R13     =	__PT_GPRS + 524
36__PT_R14     =	__PT_GPRS + 56
37__PT_R15     =	__PT_GPRS + 60
38
39_TIF_WORK_SVC = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
40		 _TIF_MCCK_PENDING | _TIF_PER_TRAP )
41_TIF_WORK_INT = (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
42		 _TIF_MCCK_PENDING)
43_TIF_TRACE    = (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SECCOMP | \
44		 _TIF_SYSCALL_TRACEPOINT)
45
46STACK_SHIFT = PAGE_SHIFT + THREAD_ORDER
47STACK_SIZE  = 1 << STACK_SHIFT
48
49#define BASED(name) name-system_call(%r13)
50
51	.macro	TRACE_IRQS_ON
52#ifdef CONFIG_TRACE_IRQFLAGS
53	basr	%r2,%r0
54	l	%r1,BASED(.Lhardirqs_on)
55	basr	%r14,%r1		# call trace_hardirqs_on_caller
56#endif
57	.endm
58
59	.macro	TRACE_IRQS_OFF
60#ifdef CONFIG_TRACE_IRQFLAGS
61	basr	%r2,%r0
62	l	%r1,BASED(.Lhardirqs_off)
63	basr	%r14,%r1		# call trace_hardirqs_off_caller
64#endif
65	.endm
66
67	.macro	LOCKDEP_SYS_EXIT
68#ifdef CONFIG_LOCKDEP
69	tm	__PT_PSW+1(%r11),0x01	# returning to user ?
70	jz	.+10
71	l	%r1,BASED(.Llockdep_sys_exit)
72	basr	%r14,%r1		# call lockdep_sys_exit
73#endif
74	.endm
75
76	.macro	CHECK_STACK stacksize,savearea
77#ifdef CONFIG_CHECK_STACK
78	tml	%r15,\stacksize - CONFIG_STACK_GUARD
79	la	%r14,\savearea
80	jz	stack_overflow
81#endif
82	.endm
83
84	.macro	SWITCH_ASYNC savearea,stack,shift
85	tmh	%r8,0x0001		# interrupting from user ?
86	jnz	1f
87	lr	%r14,%r9
88	sl	%r14,BASED(.Lcritical_start)
89	cl	%r14,BASED(.Lcritical_length)
90	jhe	0f
91	la	%r11,\savearea		# inside critical section, do cleanup
92	bras	%r14,cleanup_critical
93	tmh	%r8,0x0001		# retest problem state after cleanup
94	jnz	1f
950:	l	%r14,\stack		# are we already on the target stack?
96	slr	%r14,%r15
97	sra	%r14,\shift
98	jnz	1f
99	CHECK_STACK 1<<\shift,\savearea
100	j	2f
1011:	l	%r15,\stack		# load target stack
1022:	ahi	%r15,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
103	la	%r11,STACK_FRAME_OVERHEAD(%r15)
104	.endm
105
106	.macro	ADD64 high,low,timer
107	al	\high,\timer
108	al	\low,4+\timer
109	brc	12,.+8
110	ahi	\high,1
111	.endm
112
113	.macro	SUB64 high,low,timer
114	sl	\high,\timer
115	sl	\low,4+\timer
116	brc	3,.+8
117	ahi	\high,-1
118	.endm
119
120	.macro	UPDATE_VTIME high,low,enter_timer
121	lm	\high,\low,__LC_EXIT_TIMER
122	SUB64	\high,\low,\enter_timer
123	ADD64	\high,\low,__LC_USER_TIMER
124	stm	\high,\low,__LC_USER_TIMER
125	lm	\high,\low,__LC_LAST_UPDATE_TIMER
126	SUB64	\high,\low,__LC_EXIT_TIMER
127	ADD64	\high,\low,__LC_SYSTEM_TIMER
128	stm	\high,\low,__LC_SYSTEM_TIMER
129	mvc	__LC_LAST_UPDATE_TIMER(8),\enter_timer
130	.endm
131
132	.macro REENABLE_IRQS
133	st	%r8,__LC_RETURN_PSW
134	ni	__LC_RETURN_PSW,0xbf
135	ssm	__LC_RETURN_PSW
136	.endm
137
138	.section .kprobes.text, "ax"
139
140/*
141 * Scheduler resume function, called by switch_to
142 *  gpr2 = (task_struct *) prev
143 *  gpr3 = (task_struct *) next
144 * Returns:
145 *  gpr2 = prev
146 */
147ENTRY(__switch_to)
148	stm	%r6,%r15,__SF_GPRS(%r15)	# store gprs of prev task
149	st	%r15,__THREAD_ksp(%r2)		# store kernel stack of prev
150	l	%r4,__THREAD_info(%r2)		# get thread_info of prev
151	l	%r5,__THREAD_info(%r3)		# get thread_info of next
152	lr	%r15,%r5
153	ahi	%r15,STACK_SIZE			# end of kernel stack of next
154	st	%r3,__LC_CURRENT		# store task struct of next
155	st	%r5,__LC_THREAD_INFO		# store thread info of next
156	st	%r15,__LC_KERNEL_STACK		# store end of kernel stack
157	lctl	%c4,%c4,__TASK_pid(%r3)		# load pid to control reg. 4
158	mvc	__LC_CURRENT_PID(4,%r0),__TASK_pid(%r3)	# store pid of next
159	l	%r15,__THREAD_ksp(%r3)		# load kernel stack of next
160	tm	__TI_flags+3(%r4),_TIF_MCCK_PENDING # machine check pending?
161	jz	0f
162	ni	__TI_flags+3(%r4),255-_TIF_MCCK_PENDING	# clear flag in prev
163	oi	__TI_flags+3(%r5),_TIF_MCCK_PENDING	# set it in next
1640:	lm	%r6,%r15,__SF_GPRS(%r15)	# load gprs of next task
165	br	%r14
166
167__critical_start:
168/*
169 * SVC interrupt handler routine. System calls are synchronous events and
170 * are executed with interrupts enabled.
171 */
172
173ENTRY(system_call)
174	stpt	__LC_SYNC_ENTER_TIMER
175sysc_stm:
176	stm	%r8,%r15,__LC_SAVE_AREA_SYNC
177	l	%r12,__LC_THREAD_INFO
178	l	%r13,__LC_SVC_NEW_PSW+4
179sysc_per:
180	l	%r15,__LC_KERNEL_STACK
181	ahi	%r15,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
182	la	%r11,STACK_FRAME_OVERHEAD(%r15)	# pointer to pt_regs
183sysc_vtime:
184	UPDATE_VTIME %r8,%r9,__LC_SYNC_ENTER_TIMER
185	stm	%r0,%r7,__PT_R0(%r11)
186	mvc	__PT_R8(32,%r11),__LC_SAVE_AREA_SYNC
187	mvc	__PT_PSW(8,%r11),__LC_SVC_OLD_PSW
188	mvc	__PT_INT_CODE(4,%r11),__LC_SVC_ILC
189sysc_do_svc:
190	oi	__TI_flags+3(%r12),_TIF_SYSCALL
191	lh	%r8,__PT_INT_CODE+2(%r11)
192	sla	%r8,2				# shift and test for svc0
193	jnz	sysc_nr_ok
194	# svc 0: system call number in %r1
195	cl	%r1,BASED(.Lnr_syscalls)
196	jnl	sysc_nr_ok
197	sth	%r1,__PT_INT_CODE+2(%r11)
198	lr	%r8,%r1
199	sla	%r8,2
200sysc_nr_ok:
201	l	%r10,BASED(.Lsys_call_table)	# 31 bit system call table
202	xc	__SF_BACKCHAIN(4,%r15),__SF_BACKCHAIN(%r15)
203	st	%r2,__PT_ORIG_GPR2(%r11)
204	st	%r7,STACK_FRAME_OVERHEAD(%r15)
205	l	%r9,0(%r8,%r10)			# get system call addr.
206	tm	__TI_flags+2(%r12),_TIF_TRACE >> 8
207	jnz	sysc_tracesys
208	basr	%r14,%r9			# call sys_xxxx
209	st	%r2,__PT_R2(%r11)		# store return value
210
211sysc_return:
212	LOCKDEP_SYS_EXIT
213sysc_tif:
214	tm	__PT_PSW+1(%r11),0x01		# returning to user ?
215	jno	sysc_restore
216	tm	__TI_flags+3(%r12),_TIF_WORK_SVC
217	jnz	sysc_work			# check for work
218	ni	__TI_flags+3(%r12),255-_TIF_SYSCALL
219sysc_restore:
220	mvc	__LC_RETURN_PSW(8),__PT_PSW(%r11)
221	stpt	__LC_EXIT_TIMER
222	lm	%r0,%r15,__PT_R0(%r11)
223	lpsw	__LC_RETURN_PSW
224sysc_done:
225
226#
227# One of the work bits is on. Find out which one.
228#
229sysc_work:
230	tm	__TI_flags+3(%r12),_TIF_MCCK_PENDING
231	jo	sysc_mcck_pending
232	tm	__TI_flags+3(%r12),_TIF_NEED_RESCHED
233	jo	sysc_reschedule
234	tm	__TI_flags+3(%r12),_TIF_SIGPENDING
235	jo	sysc_sigpending
236	tm	__TI_flags+3(%r12),_TIF_NOTIFY_RESUME
237	jo	sysc_notify_resume
238	tm	__TI_flags+3(%r12),_TIF_PER_TRAP
239	jo	sysc_singlestep
240	j	sysc_return		# beware of critical section cleanup
241
242#
243# _TIF_NEED_RESCHED is set, call schedule
244#
245sysc_reschedule:
246	l	%r1,BASED(.Lschedule)
247	la	%r14,BASED(sysc_return)
248	br	%r1			# call schedule
249
250#
251# _TIF_MCCK_PENDING is set, call handler
252#
253sysc_mcck_pending:
254	l	%r1,BASED(.Lhandle_mcck)
255	la	%r14,BASED(sysc_return)
256	br	%r1			# TIF bit will be cleared by handler
257
258#
259# _TIF_SIGPENDING is set, call do_signal
260#
261sysc_sigpending:
262	ni	__TI_flags+3(%r12),255-_TIF_PER_TRAP # clear TIF_PER_TRAP
263	lr	%r2,%r11		# pass pointer to pt_regs
264	l	%r1,BASED(.Ldo_signal)
265	basr	%r14,%r1		# call do_signal
266	tm	__TI_flags+3(%r12),_TIF_SYSCALL
267	jno	sysc_return
268	lm	%r2,%r7,__PT_R2(%r11)	# load svc arguments
269	xr	%r8,%r8			# svc 0 returns -ENOSYS
270	clc	__PT_INT_CODE+2(2,%r11),BASED(.Lnr_syscalls+2)
271	jnl	sysc_nr_ok		# invalid svc number -> do svc 0
272	lh	%r8,__PT_INT_CODE+2(%r11)	# load new svc number
273	sla	%r8,2
274	j	sysc_nr_ok		# restart svc
275
276#
277# _TIF_NOTIFY_RESUME is set, call do_notify_resume
278#
279sysc_notify_resume:
280	lr	%r2,%r11		# pass pointer to pt_regs
281	l	%r1,BASED(.Ldo_notify_resume)
282	la	%r14,BASED(sysc_return)
283	br	%r1			# call do_notify_resume
284
285#
286# _TIF_PER_TRAP is set, call do_per_trap
287#
288sysc_singlestep:
289	ni	__TI_flags+3(%r12),255-(_TIF_SYSCALL | _TIF_PER_TRAP)
290	lr	%r2,%r11		# pass pointer to pt_regs
291	l	%r1,BASED(.Ldo_per_trap)
292	la	%r14,BASED(sysc_return)
293	br	%r1			# call do_per_trap
294
295#
296# call tracehook_report_syscall_entry/tracehook_report_syscall_exit before
297# and after the system call
298#
299sysc_tracesys:
300	l	%r1,BASED(.Ltrace_enter)
301	lr	%r2,%r11		# pass pointer to pt_regs
302	la	%r3,0
303	xr	%r0,%r0
304	icm	%r0,3,__PT_INT_CODE+2(%r11)
305	st	%r0,__PT_R2(%r11)
306	basr	%r14,%r1		# call do_syscall_trace_enter
307	cl	%r2,BASED(.Lnr_syscalls)
308	jnl	sysc_tracenogo
309	lr	%r8,%r2
310	sll	%r8,2
311	l	%r9,0(%r8,%r10)
312sysc_tracego:
313	lm	%r3,%r7,__PT_R3(%r11)
314	st	%r7,STACK_FRAME_OVERHEAD(%r15)
315	l	%r2,__PT_ORIG_GPR2(%r11)
316	basr	%r14,%r9		# call sys_xxx
317	st	%r2,__PT_R2(%r11)	# store return value
318sysc_tracenogo:
319	tm	__TI_flags+2(%r12),_TIF_TRACE >> 8
320	jz	sysc_return
321	l	%r1,BASED(.Ltrace_exit)
322	lr	%r2,%r11		# pass pointer to pt_regs
323	la	%r14,BASED(sysc_return)
324	br	%r1			# call do_syscall_trace_exit
325
326#
327# a new process exits the kernel with ret_from_fork
328#
329ENTRY(ret_from_fork)
330	la	%r11,STACK_FRAME_OVERHEAD(%r15)
331	l	%r12,__LC_THREAD_INFO
332	l	%r13,__LC_SVC_NEW_PSW+4
333	tm	__PT_PSW+1(%r11),0x01	# forking a kernel thread ?
334	je	1f
335	l	%r1,BASED(.Lschedule_tail)
336	basr	%r14,%r1		# call schedule_tail
337	TRACE_IRQS_ON
338	ssm	__LC_SVC_NEW_PSW	# reenable interrupts
339	j	sysc_tracenogo
340
3411:	# it's a kernel thread
342	st	%r15,__PT_R15(%r11)	# store stack pointer for new kthread
343	l	%r1,BASED(.Lschedule_tail)
344	basr	%r14,%r1		# call schedule_tail
345	TRACE_IRQS_ON
346	ssm	__LC_SVC_NEW_PSW	# reenable interrupts
347	lm	%r9,%r11,__PT_R9(%r11)	# load gprs
348ENTRY(kernel_thread_starter)
349	la	%r2,0(%r10)
350	basr	%r14,%r9
351	la	%r2,0
352	br	%r11			# do_exit
353
354#
355# kernel_execve function needs to deal with pt_regs that is not
356# at the usual place
357#
358ENTRY(ret_from_kernel_execve)
359	ssm	__LC_PGM_NEW_PSW	# disable I/O and ext. interrupts
360	lr	%r15,%r2
361	lr	%r11,%r2
362	ahi	%r15,-STACK_FRAME_OVERHEAD
363	xc	__SF_BACKCHAIN(4,%r15),__SF_BACKCHAIN(%r15)
364	l	%r12,__LC_THREAD_INFO
365	ssm	__LC_SVC_NEW_PSW	# reenable interrupts
366	j	sysc_return
367
368/*
369 * Program check handler routine
370 */
371
372ENTRY(pgm_check_handler)
373	stpt	__LC_SYNC_ENTER_TIMER
374	stm	%r8,%r15,__LC_SAVE_AREA_SYNC
375	l	%r12,__LC_THREAD_INFO
376	l	%r13,__LC_SVC_NEW_PSW+4
377	lm	%r8,%r9,__LC_PGM_OLD_PSW
378	tmh	%r8,0x0001		# test problem state bit
379	jnz	1f			# -> fault in user space
380	tmh	%r8,0x4000		# PER bit set in old PSW ?
381	jnz	0f			# -> enabled, can't be a double fault
382	tm	__LC_PGM_ILC+3,0x80	# check for per exception
383	jnz	pgm_svcper		# -> single stepped svc
3840:	CHECK_STACK STACK_SIZE,__LC_SAVE_AREA_SYNC
385	j	2f
3861:	UPDATE_VTIME %r14,%r15,__LC_SYNC_ENTER_TIMER
387	l	%r15,__LC_KERNEL_STACK
3882:	ahi	%r15,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
389	la	%r11,STACK_FRAME_OVERHEAD(%r15)
390	stm	%r0,%r7,__PT_R0(%r11)
391	mvc	__PT_R8(32,%r11),__LC_SAVE_AREA_SYNC
392	stm	%r8,%r9,__PT_PSW(%r11)
393	mvc	__PT_INT_CODE(4,%r11),__LC_PGM_ILC
394	mvc	__PT_INT_PARM_LONG(4,%r11),__LC_TRANS_EXC_CODE
395	tm	__LC_PGM_ILC+3,0x80	# check for per exception
396	jz	0f
397	l	%r1,__TI_task(%r12)
398	tmh	%r8,0x0001		# kernel per event ?
399	jz	pgm_kprobe
400	oi	__TI_flags+3(%r12),_TIF_PER_TRAP
401	mvc	__THREAD_per_address(4,%r1),__LC_PER_ADDRESS
402	mvc	__THREAD_per_cause(2,%r1),__LC_PER_CAUSE
403	mvc	__THREAD_per_paid(1,%r1),__LC_PER_PAID
4040:	REENABLE_IRQS
405	xc	__SF_BACKCHAIN(4,%r15),__SF_BACKCHAIN(%r15)
406	l	%r1,BASED(.Ljump_table)
407	la	%r10,0x7f
408	n	%r10,__PT_INT_CODE(%r11)
409	je	sysc_return
410	sll	%r10,2
411	l	%r1,0(%r10,%r1)		# load address of handler routine
412	lr	%r2,%r11		# pass pointer to pt_regs
413	basr	%r14,%r1		# branch to interrupt-handler
414	j	sysc_return
415
416#
417# PER event in supervisor state, must be kprobes
418#
419pgm_kprobe:
420	REENABLE_IRQS
421	xc	__SF_BACKCHAIN(4,%r15),__SF_BACKCHAIN(%r15)
422	l	%r1,BASED(.Ldo_per_trap)
423	lr	%r2,%r11		# pass pointer to pt_regs
424	basr	%r14,%r1		# call do_per_trap
425	j	sysc_return
426
427#
428# single stepped system call
429#
430pgm_svcper:
431	oi	__TI_flags+3(%r12),_TIF_PER_TRAP
432	mvc	__LC_RETURN_PSW(4),__LC_SVC_NEW_PSW
433	mvc	__LC_RETURN_PSW+4(4),BASED(.Lsysc_per)
434	lpsw	__LC_RETURN_PSW		# branch to sysc_per and enable irqs
435
436/*
437 * IO interrupt handler routine
438 */
439
440ENTRY(io_int_handler)
441	stck	__LC_INT_CLOCK
442	stpt	__LC_ASYNC_ENTER_TIMER
443	stm	%r8,%r15,__LC_SAVE_AREA_ASYNC
444	l	%r12,__LC_THREAD_INFO
445	l	%r13,__LC_SVC_NEW_PSW+4
446	lm	%r8,%r9,__LC_IO_OLD_PSW
447	tmh	%r8,0x0001		# interrupting from user ?
448	jz	io_skip
449	UPDATE_VTIME %r14,%r15,__LC_ASYNC_ENTER_TIMER
450io_skip:
451	SWITCH_ASYNC __LC_SAVE_AREA_ASYNC,__LC_ASYNC_STACK,STACK_SHIFT
452	stm	%r0,%r7,__PT_R0(%r11)
453	mvc	__PT_R8(32,%r11),__LC_SAVE_AREA_ASYNC
454	stm	%r8,%r9,__PT_PSW(%r11)
455	TRACE_IRQS_OFF
456	xc	__SF_BACKCHAIN(4,%r15),__SF_BACKCHAIN(%r15)
457	l	%r1,BASED(.Ldo_IRQ)
458	lr	%r2,%r11		# pass pointer to pt_regs
459	basr	%r14,%r1		# call do_IRQ
460io_return:
461	LOCKDEP_SYS_EXIT
462	TRACE_IRQS_ON
463io_tif:
464	tm	__TI_flags+3(%r12),_TIF_WORK_INT
465	jnz	io_work			# there is work to do (signals etc.)
466io_restore:
467	mvc	__LC_RETURN_PSW(8),__PT_PSW(%r11)
468	stpt	__LC_EXIT_TIMER
469	lm	%r0,%r15,__PT_R0(%r11)
470	lpsw	__LC_RETURN_PSW
471io_done:
472
473#
474# There is work todo, find out in which context we have been interrupted:
475# 1) if we return to user space we can do all _TIF_WORK_INT work
476# 2) if we return to kernel code and preemptive scheduling is enabled check
477#    the preemption counter and if it is zero call preempt_schedule_irq
478# Before any work can be done, a switch to the kernel stack is required.
479#
480io_work:
481	tm	__PT_PSW+1(%r11),0x01	# returning to user ?
482	jo	io_work_user		# yes -> do resched & signal
483#ifdef CONFIG_PREEMPT
484	# check for preemptive scheduling
485	icm	%r0,15,__TI_precount(%r12)
486	jnz	io_restore		# preemption disabled
487	tm	__TI_flags+3(%r12),_TIF_NEED_RESCHED
488	jno	io_restore
489	# switch to kernel stack
490	l	%r1,__PT_R15(%r11)
491	ahi	%r1,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
492	mvc	STACK_FRAME_OVERHEAD(__PT_SIZE,%r1),0(%r11)
493	xc	__SF_BACKCHAIN(4,%r1),__SF_BACKCHAIN(%r1)
494	la	%r11,STACK_FRAME_OVERHEAD(%r1)
495	lr	%r15,%r1
496	# TRACE_IRQS_ON already done at io_return, call
497	# TRACE_IRQS_OFF to keep things symmetrical
498	TRACE_IRQS_OFF
499	l	%r1,BASED(.Lpreempt_irq)
500	basr	%r14,%r1		# call preempt_schedule_irq
501	j	io_return
502#else
503	j	io_restore
504#endif
505
506#
507# Need to do work before returning to userspace, switch to kernel stack
508#
509io_work_user:
510	l	%r1,__LC_KERNEL_STACK
511	ahi	%r1,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
512	mvc	STACK_FRAME_OVERHEAD(__PT_SIZE,%r1),0(%r11)
513	xc	__SF_BACKCHAIN(4,%r1),__SF_BACKCHAIN(%r1)
514	la	%r11,STACK_FRAME_OVERHEAD(%r1)
515	lr	%r15,%r1
516
517#
518# One of the work bits is on. Find out which one.
519# Checked are: _TIF_SIGPENDING, _TIF_NOTIFY_RESUME, _TIF_NEED_RESCHED
520#		and _TIF_MCCK_PENDING
521#
522io_work_tif:
523	tm	__TI_flags+3(%r12),_TIF_MCCK_PENDING
524	jo	io_mcck_pending
525	tm	__TI_flags+3(%r12),_TIF_NEED_RESCHED
526	jo	io_reschedule
527	tm	__TI_flags+3(%r12),_TIF_SIGPENDING
528	jo	io_sigpending
529	tm	__TI_flags+3(%r12),_TIF_NOTIFY_RESUME
530	jo	io_notify_resume
531	j	io_return		# beware of critical section cleanup
532
533#
534# _TIF_MCCK_PENDING is set, call handler
535#
536io_mcck_pending:
537	# TRACE_IRQS_ON already done at io_return
538	l	%r1,BASED(.Lhandle_mcck)
539	basr	%r14,%r1		# TIF bit will be cleared by handler
540	TRACE_IRQS_OFF
541	j	io_return
542
543#
544# _TIF_NEED_RESCHED is set, call schedule
545#
546io_reschedule:
547	# TRACE_IRQS_ON already done at io_return
548	l	%r1,BASED(.Lschedule)
549	ssm	__LC_SVC_NEW_PSW	# reenable interrupts
550	basr	%r14,%r1		# call scheduler
551	ssm	__LC_PGM_NEW_PSW	# disable I/O and ext. interrupts
552	TRACE_IRQS_OFF
553	j	io_return
554
555#
556# _TIF_SIGPENDING is set, call do_signal
557#
558io_sigpending:
559	# TRACE_IRQS_ON already done at io_return
560	l	%r1,BASED(.Ldo_signal)
561	ssm	__LC_SVC_NEW_PSW	# reenable interrupts
562	lr	%r2,%r11		# pass pointer to pt_regs
563	basr	%r14,%r1		# call do_signal
564	ssm	__LC_PGM_NEW_PSW	# disable I/O and ext. interrupts
565	TRACE_IRQS_OFF
566	j	io_return
567
568#
569# _TIF_SIGPENDING is set, call do_signal
570#
571io_notify_resume:
572	# TRACE_IRQS_ON already done at io_return
573	l	%r1,BASED(.Ldo_notify_resume)
574	ssm	__LC_SVC_NEW_PSW	# reenable interrupts
575	lr	%r2,%r11		# pass pointer to pt_regs
576	basr	%r14,%r1		# call do_notify_resume
577	ssm	__LC_PGM_NEW_PSW	# disable I/O and ext. interrupts
578	TRACE_IRQS_OFF
579	j	io_return
580
581/*
582 * External interrupt handler routine
583 */
584
585ENTRY(ext_int_handler)
586	stck	__LC_INT_CLOCK
587	stpt	__LC_ASYNC_ENTER_TIMER
588	stm	%r8,%r15,__LC_SAVE_AREA_ASYNC
589	l	%r12,__LC_THREAD_INFO
590	l	%r13,__LC_SVC_NEW_PSW+4
591	lm	%r8,%r9,__LC_EXT_OLD_PSW
592	tmh	%r8,0x0001		# interrupting from user ?
593	jz	ext_skip
594	UPDATE_VTIME %r14,%r15,__LC_ASYNC_ENTER_TIMER
595ext_skip:
596	SWITCH_ASYNC __LC_SAVE_AREA_ASYNC,__LC_ASYNC_STACK,STACK_SHIFT
597	stm	%r0,%r7,__PT_R0(%r11)
598	mvc	__PT_R8(32,%r11),__LC_SAVE_AREA_ASYNC
599	stm	%r8,%r9,__PT_PSW(%r11)
600	TRACE_IRQS_OFF
601	lr	%r2,%r11		# pass pointer to pt_regs
602	l	%r3,__LC_EXT_CPU_ADDR	# get cpu address + interruption code
603	l	%r4,__LC_EXT_PARAMS	# get external parameters
604	l	%r1,BASED(.Ldo_extint)
605	basr	%r14,%r1		# call do_extint
606	j	io_return
607
608/*
609 * Load idle PSW. The second "half" of this function is in cleanup_idle.
610 */
611ENTRY(psw_idle)
612	st	%r3,__SF_EMPTY(%r15)
613	basr	%r1,0
614	la	%r1,psw_idle_lpsw+4-.(%r1)
615	st	%r1,__SF_EMPTY+4(%r15)
616	oi	__SF_EMPTY+4(%r15),0x80
617	stck	__CLOCK_IDLE_ENTER(%r2)
618	stpt	__TIMER_IDLE_ENTER(%r2)
619psw_idle_lpsw:
620	lpsw	__SF_EMPTY(%r15)
621	br	%r14
622psw_idle_end:
623
624__critical_end:
625
626/*
627 * Machine check handler routines
628 */
629
630ENTRY(mcck_int_handler)
631	stck	__LC_MCCK_CLOCK
632	spt	__LC_CPU_TIMER_SAVE_AREA	# revalidate cpu timer
633	lm	%r0,%r15,__LC_GPREGS_SAVE_AREA	# revalidate gprs
634	l	%r12,__LC_THREAD_INFO
635	l	%r13,__LC_SVC_NEW_PSW+4
636	lm	%r8,%r9,__LC_MCK_OLD_PSW
637	tm	__LC_MCCK_CODE,0x80	# system damage?
638	jo	mcck_panic		# yes -> rest of mcck code invalid
639	la	%r14,__LC_CPU_TIMER_SAVE_AREA
640	mvc	__LC_MCCK_ENTER_TIMER(8),0(%r14)
641	tm	__LC_MCCK_CODE+5,0x02	# stored cpu timer value valid?
642	jo	3f
643	la	%r14,__LC_SYNC_ENTER_TIMER
644	clc	0(8,%r14),__LC_ASYNC_ENTER_TIMER
645	jl	0f
646	la	%r14,__LC_ASYNC_ENTER_TIMER
6470:	clc	0(8,%r14),__LC_EXIT_TIMER
648	jl	1f
649	la	%r14,__LC_EXIT_TIMER
6501:	clc	0(8,%r14),__LC_LAST_UPDATE_TIMER
651	jl	2f
652	la	%r14,__LC_LAST_UPDATE_TIMER
6532:	spt	0(%r14)
654	mvc	__LC_MCCK_ENTER_TIMER(8),0(%r14)
6553:	tm	__LC_MCCK_CODE+2,0x09	# mwp + ia of old psw valid?
656	jno	mcck_panic		# no -> skip cleanup critical
657	tm	%r8,0x0001		# interrupting from user ?
658	jz	mcck_skip
659	UPDATE_VTIME %r14,%r15,__LC_MCCK_ENTER_TIMER
660mcck_skip:
661	SWITCH_ASYNC __LC_GPREGS_SAVE_AREA+32,__LC_PANIC_STACK,PAGE_SHIFT
662	mvc	__PT_R0(64,%r11),__LC_GPREGS_SAVE_AREA
663	stm	%r8,%r9,__PT_PSW(%r11)
664	xc	__SF_BACKCHAIN(4,%r15),__SF_BACKCHAIN(%r15)
665	l	%r1,BASED(.Ldo_machine_check)
666	lr	%r2,%r11		# pass pointer to pt_regs
667	basr	%r14,%r1		# call s390_do_machine_check
668	tm	__PT_PSW+1(%r11),0x01	# returning to user ?
669	jno	mcck_return
670	l	%r1,__LC_KERNEL_STACK	# switch to kernel stack
671	ahi	%r1,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
672	mvc	STACK_FRAME_OVERHEAD(__PT_SIZE,%r1),0(%r11)
673	xc	__SF_BACKCHAIN(4,%r1),__SF_BACKCHAIN(%r1)
674	la	%r11,STACK_FRAME_OVERHEAD(%r15)
675	lr	%r15,%r1
676	ssm	__LC_PGM_NEW_PSW	# turn dat on, keep irqs off
677	tm	__TI_flags+3(%r12),_TIF_MCCK_PENDING
678	jno	mcck_return
679	TRACE_IRQS_OFF
680	l	%r1,BASED(.Lhandle_mcck)
681	basr	%r14,%r1		# call s390_handle_mcck
682	TRACE_IRQS_ON
683mcck_return:
684	mvc	__LC_RETURN_MCCK_PSW(8),__PT_PSW(%r11) # move return PSW
685	tm	__LC_RETURN_MCCK_PSW+1,0x01 # returning to user ?
686	jno	0f
687	lm	%r0,%r15,__PT_R0(%r11)
688	stpt	__LC_EXIT_TIMER
689	lpsw	__LC_RETURN_MCCK_PSW
6900:	lm	%r0,%r15,__PT_R0(%r11)
691	lpsw	__LC_RETURN_MCCK_PSW
692
693mcck_panic:
694	l	%r14,__LC_PANIC_STACK
695	slr	%r14,%r15
696	sra	%r14,PAGE_SHIFT
697	jz	0f
698	l	%r15,__LC_PANIC_STACK
6990:	ahi	%r15,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
700	j	mcck_skip
701
702#
703# PSW restart interrupt handler
704#
705ENTRY(restart_int_handler)
706	st	%r15,__LC_SAVE_AREA_RESTART
707	l	%r15,__LC_RESTART_STACK
708	ahi	%r15,-__PT_SIZE			# create pt_regs on stack
709	xc	0(__PT_SIZE,%r15),0(%r15)
710	stm	%r0,%r14,__PT_R0(%r15)
711	mvc	__PT_R15(4,%r15),__LC_SAVE_AREA_RESTART
712	mvc	__PT_PSW(8,%r15),__LC_RST_OLD_PSW # store restart old psw
713	ahi	%r15,-STACK_FRAME_OVERHEAD	# create stack frame on stack
714	xc	0(STACK_FRAME_OVERHEAD,%r15),0(%r15)
715	l	%r1,__LC_RESTART_FN		# load fn, parm & source cpu
716	l	%r2,__LC_RESTART_DATA
717	l	%r3,__LC_RESTART_SOURCE
718	ltr	%r3,%r3				# test source cpu address
719	jm	1f				# negative -> skip source stop
7200:	sigp	%r4,%r3,SIGP_SENSE		# sigp sense to source cpu
721	brc	10,0b				# wait for status stored
7221:	basr	%r14,%r1			# call function
723	stap	__SF_EMPTY(%r15)		# store cpu address
724	lh	%r3,__SF_EMPTY(%r15)
7252:	sigp	%r4,%r3,SIGP_STOP		# sigp stop to current cpu
726	brc	2,2b
7273:	j	3b
728
729	.section .kprobes.text, "ax"
730
731#ifdef CONFIG_CHECK_STACK
732/*
733 * The synchronous or the asynchronous stack overflowed. We are dead.
734 * No need to properly save the registers, we are going to panic anyway.
735 * Setup a pt_regs so that show_trace can provide a good call trace.
736 */
737stack_overflow:
738	l	%r15,__LC_PANIC_STACK	# change to panic stack
739	ahi	%r15,-__PT_SIZE		# create pt_regs
740	stm	%r0,%r7,__PT_R0(%r15)
741	stm	%r8,%r9,__PT_PSW(%r15)
742	mvc	__PT_R8(32,%r11),0(%r14)
743	lr	%r15,%r11
744	ahi	%r15,-STACK_FRAME_OVERHEAD
745	l	%r1,BASED(1f)
746	xc	__SF_BACKCHAIN(4,%r15),__SF_BACKCHAIN(%r15)
747	lr	%r2,%r11		# pass pointer to pt_regs
748	br	%r1			# branch to kernel_stack_overflow
7491:	.long	kernel_stack_overflow
750#endif
751
752cleanup_table:
753	.long	system_call + 0x80000000
754	.long	sysc_do_svc + 0x80000000
755	.long	sysc_tif + 0x80000000
756	.long	sysc_restore + 0x80000000
757	.long	sysc_done + 0x80000000
758	.long	io_tif + 0x80000000
759	.long	io_restore + 0x80000000
760	.long	io_done + 0x80000000
761	.long	psw_idle + 0x80000000
762	.long	psw_idle_end + 0x80000000
763
764cleanup_critical:
765	cl	%r9,BASED(cleanup_table)	# system_call
766	jl	0f
767	cl	%r9,BASED(cleanup_table+4)	# sysc_do_svc
768	jl	cleanup_system_call
769	cl	%r9,BASED(cleanup_table+8)	# sysc_tif
770	jl	0f
771	cl	%r9,BASED(cleanup_table+12)	# sysc_restore
772	jl	cleanup_sysc_tif
773	cl	%r9,BASED(cleanup_table+16)	# sysc_done
774	jl	cleanup_sysc_restore
775	cl	%r9,BASED(cleanup_table+20)	# io_tif
776	jl	0f
777	cl	%r9,BASED(cleanup_table+24)	# io_restore
778	jl	cleanup_io_tif
779	cl	%r9,BASED(cleanup_table+28)	# io_done
780	jl	cleanup_io_restore
781	cl	%r9,BASED(cleanup_table+32)	# psw_idle
782	jl	0f
783	cl	%r9,BASED(cleanup_table+36)	# psw_idle_end
784	jl	cleanup_idle
7850:	br	%r14
786
787cleanup_system_call:
788	# check if stpt has been executed
789	cl	%r9,BASED(cleanup_system_call_insn)
790	jh	0f
791	mvc	__LC_SYNC_ENTER_TIMER(8),__LC_ASYNC_ENTER_TIMER
792	chi	%r11,__LC_SAVE_AREA_ASYNC
793	je	0f
794	mvc	__LC_SYNC_ENTER_TIMER(8),__LC_MCCK_ENTER_TIMER
7950:	# check if stm has been executed
796	cl	%r9,BASED(cleanup_system_call_insn+4)
797	jh	0f
798	mvc	__LC_SAVE_AREA_SYNC(32),0(%r11)
7990:	# set up saved registers r12, and r13
800	st	%r12,16(%r11)		# r12 thread-info pointer
801	st	%r13,20(%r11)		# r13 literal-pool pointer
802	# check if the user time calculation has been done
803	cl	%r9,BASED(cleanup_system_call_insn+8)
804	jh	0f
805	l	%r10,__LC_EXIT_TIMER
806	l	%r15,__LC_EXIT_TIMER+4
807	SUB64	%r10,%r15,__LC_SYNC_ENTER_TIMER
808	ADD64	%r10,%r15,__LC_USER_TIMER
809	st	%r10,__LC_USER_TIMER
810	st	%r15,__LC_USER_TIMER+4
8110:	# check if the system time calculation has been done
812	cl	%r9,BASED(cleanup_system_call_insn+12)
813	jh	0f
814	l	%r10,__LC_LAST_UPDATE_TIMER
815	l	%r15,__LC_LAST_UPDATE_TIMER+4
816	SUB64	%r10,%r15,__LC_EXIT_TIMER
817	ADD64	%r10,%r15,__LC_SYSTEM_TIMER
818	st	%r10,__LC_SYSTEM_TIMER
819	st	%r15,__LC_SYSTEM_TIMER+4
8200:	# update accounting time stamp
821	mvc	__LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
822	# set up saved register 11
823	l	%r15,__LC_KERNEL_STACK
824	ahi	%r15,-__PT_SIZE
825	st	%r15,12(%r11)		# r11 pt_regs pointer
826	# fill pt_regs
827	mvc	__PT_R8(32,%r15),__LC_SAVE_AREA_SYNC
828	stm	%r0,%r7,__PT_R0(%r15)
829	mvc	__PT_PSW(8,%r15),__LC_SVC_OLD_PSW
830	mvc	__PT_INT_CODE(4,%r15),__LC_SVC_ILC
831	# setup saved register 15
832	ahi	%r15,-STACK_FRAME_OVERHEAD
833	st	%r15,28(%r11)		# r15 stack pointer
834	# set new psw address and exit
835	l	%r9,BASED(cleanup_table+4)	# sysc_do_svc + 0x80000000
836	br	%r14
837cleanup_system_call_insn:
838	.long	system_call + 0x80000000
839	.long	sysc_stm + 0x80000000
840	.long	sysc_vtime + 0x80000000 + 36
841	.long	sysc_vtime + 0x80000000 + 76
842
843cleanup_sysc_tif:
844	l	%r9,BASED(cleanup_table+8)	# sysc_tif + 0x80000000
845	br	%r14
846
847cleanup_sysc_restore:
848	cl	%r9,BASED(cleanup_sysc_restore_insn)
849	jhe	0f
850	l	%r9,12(%r11)		# get saved pointer to pt_regs
851	mvc	__LC_RETURN_PSW(8),__PT_PSW(%r9)
852	mvc	0(32,%r11),__PT_R8(%r9)
853	lm	%r0,%r7,__PT_R0(%r9)
8540:	lm	%r8,%r9,__LC_RETURN_PSW
855	br	%r14
856cleanup_sysc_restore_insn:
857	.long	sysc_done - 4 + 0x80000000
858
859cleanup_io_tif:
860	l	%r9,BASED(cleanup_table+20)	# io_tif + 0x80000000
861	br	%r14
862
863cleanup_io_restore:
864	cl	%r9,BASED(cleanup_io_restore_insn)
865	jhe	0f
866	l	%r9,12(%r11)		# get saved r11 pointer to pt_regs
867	mvc	__LC_RETURN_PSW(8),__PT_PSW(%r9)
868	mvc	0(32,%r11),__PT_R8(%r9)
869	lm	%r0,%r7,__PT_R0(%r9)
8700:	lm	%r8,%r9,__LC_RETURN_PSW
871	br	%r14
872cleanup_io_restore_insn:
873	.long	io_done - 4 + 0x80000000
874
875cleanup_idle:
876	# copy interrupt clock & cpu timer
877	mvc	__CLOCK_IDLE_EXIT(8,%r2),__LC_INT_CLOCK
878	mvc	__TIMER_IDLE_EXIT(8,%r2),__LC_ASYNC_ENTER_TIMER
879	chi	%r11,__LC_SAVE_AREA_ASYNC
880	je	0f
881	mvc	__CLOCK_IDLE_EXIT(8,%r2),__LC_MCCK_CLOCK
882	mvc	__TIMER_IDLE_EXIT(8,%r2),__LC_MCCK_ENTER_TIMER
8830:	# check if stck has been executed
884	cl	%r9,BASED(cleanup_idle_insn)
885	jhe	1f
886	mvc	__CLOCK_IDLE_ENTER(8,%r2),__CLOCK_IDLE_EXIT(%r2)
887	mvc	__TIMER_IDLE_ENTER(8,%r2),__TIMER_IDLE_EXIT(%r3)
8881:	# account system time going idle
889	lm	%r9,%r10,__LC_STEAL_TIMER
890	ADD64	%r9,%r10,__CLOCK_IDLE_ENTER(%r2)
891	SUB64	%r9,%r10,__LC_LAST_UPDATE_CLOCK
892	stm	%r9,%r10,__LC_STEAL_TIMER
893	mvc	__LC_LAST_UPDATE_CLOCK(8),__CLOCK_IDLE_EXIT(%r2)
894	lm	%r9,%r10,__LC_SYSTEM_TIMER
895	ADD64	%r9,%r10,__LC_LAST_UPDATE_TIMER
896	SUB64	%r9,%r10,__TIMER_IDLE_ENTER(%r2)
897	stm	%r9,%r10,__LC_SYSTEM_TIMER
898	mvc	__LC_LAST_UPDATE_TIMER(8),__TIMER_IDLE_EXIT(%r2)
899	# prepare return psw
900	n	%r8,BASED(cleanup_idle_wait)	# clear wait state bit
901	l	%r9,24(%r11)			# return from psw_idle
902	br	%r14
903cleanup_idle_insn:
904	.long	psw_idle_lpsw + 0x80000000
905cleanup_idle_wait:
906	.long	0xfffdffff
907
908/*
909 * Integer constants
910 */
911	.align	4
912.Lnr_syscalls:
913	.long	NR_syscalls
914.Lvtimer_max:
915	.quad	0x7fffffffffffffff
916
917/*
918 * Symbol constants
919 */
920.Ldo_machine_check:	.long	s390_do_machine_check
921.Lhandle_mcck:		.long	s390_handle_mcck
922.Ldo_IRQ:		.long	do_IRQ
923.Ldo_extint:		.long	do_extint
924.Ldo_signal:		.long	do_signal
925.Ldo_notify_resume:	.long	do_notify_resume
926.Ldo_per_trap:		.long	do_per_trap
927.Ljump_table:		.long	pgm_check_table
928.Lschedule:		.long	schedule
929#ifdef CONFIG_PREEMPT
930.Lpreempt_irq:		.long	preempt_schedule_irq
931#endif
932.Ltrace_enter:		.long	do_syscall_trace_enter
933.Ltrace_exit:		.long	do_syscall_trace_exit
934.Lschedule_tail:	.long	schedule_tail
935.Lsys_call_table:	.long	sys_call_table
936.Lsysc_per:		.long	sysc_per + 0x80000000
937#ifdef CONFIG_TRACE_IRQFLAGS
938.Lhardirqs_on:		.long	trace_hardirqs_on_caller
939.Lhardirqs_off:		.long	trace_hardirqs_off_caller
940#endif
941#ifdef CONFIG_LOCKDEP
942.Llockdep_sys_exit:	.long	lockdep_sys_exit
943#endif
944.Lcritical_start:	.long	__critical_start + 0x80000000
945.Lcritical_length:	.long	__critical_end - __critical_start
946
947		.section .rodata, "a"
948#define SYSCALL(esa,esame,emu)	.long esa
949	.globl	sys_call_table
950sys_call_table:
951#include "syscalls.S"
952#undef SYSCALL
953