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