xref: /openbmc/linux/arch/s390/kernel/entry.S (revision d3f468963cd6fd6d2aa5e26aed8b24232096d0e1)
1b2441318SGreg Kroah-Hartman/* SPDX-License-Identifier: GPL-2.0 */
24bfc86ceSHeiko Carstens/*
34bfc86ceSHeiko Carstens *    S390 low-level entry points.
44bfc86ceSHeiko Carstens *
54bfc86ceSHeiko Carstens *    Copyright IBM Corp. 1999, 2012
64bfc86ceSHeiko Carstens *    Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
74bfc86ceSHeiko Carstens *		 Hartmut Penner (hp@de.ibm.com),
84bfc86ceSHeiko Carstens *		 Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com),
94bfc86ceSHeiko Carstens *		 Heiko Carstens <heiko.carstens@de.ibm.com>
104bfc86ceSHeiko Carstens */
114bfc86ceSHeiko Carstens
124bfc86ceSHeiko Carstens#include <linux/init.h>
134bfc86ceSHeiko Carstens#include <linux/linkage.h>
144bfc86ceSHeiko Carstens#include <asm/processor.h>
154bfc86ceSHeiko Carstens#include <asm/cache.h>
163037a52fSMartin Schwidefsky#include <asm/ctl_reg.h>
17dc24b7b4SHendrik Brueckner#include <asm/dwarf.h>
184bfc86ceSHeiko Carstens#include <asm/errno.h>
194bfc86ceSHeiko Carstens#include <asm/ptrace.h>
204bfc86ceSHeiko Carstens#include <asm/thread_info.h>
214bfc86ceSHeiko Carstens#include <asm/asm-offsets.h>
224bfc86ceSHeiko Carstens#include <asm/unistd.h>
234bfc86ceSHeiko Carstens#include <asm/page.h>
244bfc86ceSHeiko Carstens#include <asm/sigp.h>
254bfc86ceSHeiko Carstens#include <asm/irq.h>
269977e886SHendrik Brueckner#include <asm/vx-insn.h>
2783abeffbSHendrik Brueckner#include <asm/setup.h>
2883abeffbSHendrik Brueckner#include <asm/nmi.h>
29711f5df7SAl Viro#include <asm/export.h>
304bfc86ceSHeiko Carstens
314bfc86ceSHeiko Carstens__PT_R0      =	__PT_GPRS
324bfc86ceSHeiko Carstens__PT_R1      =	__PT_GPRS + 8
334bfc86ceSHeiko Carstens__PT_R2      =	__PT_GPRS + 16
344bfc86ceSHeiko Carstens__PT_R3      =	__PT_GPRS + 24
354bfc86ceSHeiko Carstens__PT_R4      =	__PT_GPRS + 32
364bfc86ceSHeiko Carstens__PT_R5      =	__PT_GPRS + 40
374bfc86ceSHeiko Carstens__PT_R6      =	__PT_GPRS + 48
384bfc86ceSHeiko Carstens__PT_R7      =	__PT_GPRS + 56
394bfc86ceSHeiko Carstens__PT_R8      =	__PT_GPRS + 64
404bfc86ceSHeiko Carstens__PT_R9      =	__PT_GPRS + 72
414bfc86ceSHeiko Carstens__PT_R10     =	__PT_GPRS + 80
424bfc86ceSHeiko Carstens__PT_R11     =	__PT_GPRS + 88
434bfc86ceSHeiko Carstens__PT_R12     =	__PT_GPRS + 96
444bfc86ceSHeiko Carstens__PT_R13     =	__PT_GPRS + 104
454bfc86ceSHeiko Carstens__PT_R14     =	__PT_GPRS + 112
464bfc86ceSHeiko Carstens__PT_R15     =	__PT_GPRS + 120
474bfc86ceSHeiko Carstens
483a890380SHeiko CarstensSTACK_SHIFT = PAGE_SHIFT + THREAD_SIZE_ORDER
494bfc86ceSHeiko CarstensSTACK_SIZE  = 1 << STACK_SHIFT
504bfc86ceSHeiko CarstensSTACK_INIT = STACK_SIZE - STACK_FRAME_OVERHEAD - __PT_SIZE
514bfc86ceSHeiko Carstens
524bfc86ceSHeiko Carstens_TIF_WORK	= (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
5376f1948aSLinus Torvalds		   _TIF_UPROBE | _TIF_GUARDED_STORAGE | _TIF_PATCH_PENDING)
544bfc86ceSHeiko Carstens_TIF_TRACE	= (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SECCOMP | \
554bfc86ceSHeiko Carstens		   _TIF_SYSCALL_TRACEPOINT)
56b5a882fcSHeiko Carstens_CIF_WORK	= (_CIF_MCCK_PENDING | _CIF_ASCE_PRIMARY | \
57b5a882fcSHeiko Carstens		   _CIF_ASCE_SECONDARY | _CIF_FPU)
5823fefe11SMartin Schwidefsky_PIF_WORK	= (_PIF_PER_TRAP | _PIF_SYSCALL_RESTART)
594bfc86ceSHeiko Carstens
609977e886SHendrik Brueckner#define BASED(name) name-cleanup_critical(%r13)
614bfc86ceSHeiko Carstens
624bfc86ceSHeiko Carstens	.macro	TRACE_IRQS_ON
634bfc86ceSHeiko Carstens#ifdef CONFIG_TRACE_IRQFLAGS
644bfc86ceSHeiko Carstens	basr	%r2,%r0
654bfc86ceSHeiko Carstens	brasl	%r14,trace_hardirqs_on_caller
664bfc86ceSHeiko Carstens#endif
674bfc86ceSHeiko Carstens	.endm
684bfc86ceSHeiko Carstens
694bfc86ceSHeiko Carstens	.macro	TRACE_IRQS_OFF
704bfc86ceSHeiko Carstens#ifdef CONFIG_TRACE_IRQFLAGS
714bfc86ceSHeiko Carstens	basr	%r2,%r0
724bfc86ceSHeiko Carstens	brasl	%r14,trace_hardirqs_off_caller
734bfc86ceSHeiko Carstens#endif
744bfc86ceSHeiko Carstens	.endm
754bfc86ceSHeiko Carstens
764bfc86ceSHeiko Carstens	.macro	LOCKDEP_SYS_EXIT
774bfc86ceSHeiko Carstens#ifdef CONFIG_LOCKDEP
784bfc86ceSHeiko Carstens	tm	__PT_PSW+1(%r11),0x01	# returning to user ?
794bfc86ceSHeiko Carstens	jz	.+10
804bfc86ceSHeiko Carstens	brasl	%r14,lockdep_sys_exit
814bfc86ceSHeiko Carstens#endif
824bfc86ceSHeiko Carstens	.endm
834bfc86ceSHeiko Carstens
844bfc86ceSHeiko Carstens	.macro	CHECK_STACK stacksize,savearea
854bfc86ceSHeiko Carstens#ifdef CONFIG_CHECK_STACK
864bfc86ceSHeiko Carstens	tml	%r15,\stacksize - CONFIG_STACK_GUARD
874bfc86ceSHeiko Carstens	lghi	%r14,\savearea
884bfc86ceSHeiko Carstens	jz	stack_overflow
894bfc86ceSHeiko Carstens#endif
904bfc86ceSHeiko Carstens	.endm
914bfc86ceSHeiko Carstens
922acb94f4SMartin Schwidefsky	.macro	SWITCH_ASYNC savearea,timer
934bfc86ceSHeiko Carstens	tmhh	%r8,0x0001		# interrupting from user ?
944bfc86ceSHeiko Carstens	jnz	1f
954bfc86ceSHeiko Carstens	lgr	%r14,%r9
964bfc86ceSHeiko Carstens	slg	%r14,BASED(.Lcritical_start)
974bfc86ceSHeiko Carstens	clg	%r14,BASED(.Lcritical_length)
984bfc86ceSHeiko Carstens	jhe	0f
994bfc86ceSHeiko Carstens	lghi	%r11,\savearea		# inside critical section, do cleanup
1004bfc86ceSHeiko Carstens	brasl	%r14,cleanup_critical
1014bfc86ceSHeiko Carstens	tmhh	%r8,0x0001		# retest problem state after cleanup
1024bfc86ceSHeiko Carstens	jnz	1f
1032acb94f4SMartin Schwidefsky0:	lg	%r14,__LC_ASYNC_STACK	# are we already on the async stack?
1044bfc86ceSHeiko Carstens	slgr	%r14,%r15
1052acb94f4SMartin Schwidefsky	srag	%r14,%r14,STACK_SHIFT
106a359bb11SMartin Schwidefsky	jnz	2f
1072acb94f4SMartin Schwidefsky	CHECK_STACK 1<<STACK_SHIFT,\savearea
1084bfc86ceSHeiko Carstens	aghi	%r15,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
109a359bb11SMartin Schwidefsky	j	3f
11034525e1fSMartin Schwidefsky1:	UPDATE_VTIME %r14,%r15,\timer
1116b73044bSMartin Schwidefsky	BPENTER __TI_flags(%r12),_TIF_ISOLATE_BP
1122acb94f4SMartin Schwidefsky2:	lg	%r15,__LC_ASYNC_STACK	# load async stack
113a359bb11SMartin Schwidefsky3:	la	%r11,STACK_FRAME_OVERHEAD(%r15)
1144bfc86ceSHeiko Carstens	.endm
1154bfc86ceSHeiko Carstens
116a359bb11SMartin Schwidefsky	.macro UPDATE_VTIME w1,w2,enter_timer
117a359bb11SMartin Schwidefsky	lg	\w1,__LC_EXIT_TIMER
118a359bb11SMartin Schwidefsky	lg	\w2,__LC_LAST_UPDATE_TIMER
119a359bb11SMartin Schwidefsky	slg	\w1,\enter_timer
120a359bb11SMartin Schwidefsky	slg	\w2,__LC_EXIT_TIMER
121a359bb11SMartin Schwidefsky	alg	\w1,__LC_USER_TIMER
122a359bb11SMartin Schwidefsky	alg	\w2,__LC_SYSTEM_TIMER
123a359bb11SMartin Schwidefsky	stg	\w1,__LC_USER_TIMER
124a359bb11SMartin Schwidefsky	stg	\w2,__LC_SYSTEM_TIMER
1254bfc86ceSHeiko Carstens	mvc	__LC_LAST_UPDATE_TIMER(8),\enter_timer
1264bfc86ceSHeiko Carstens	.endm
1274bfc86ceSHeiko Carstens
1284bfc86ceSHeiko Carstens	.macro REENABLE_IRQS
1294bfc86ceSHeiko Carstens	stg	%r8,__LC_RETURN_PSW
1304bfc86ceSHeiko Carstens	ni	__LC_RETURN_PSW,0xbf
1314bfc86ceSHeiko Carstens	ssm	__LC_RETURN_PSW
1324bfc86ceSHeiko Carstens	.endm
1334bfc86ceSHeiko Carstens
1344bfc86ceSHeiko Carstens	.macro STCK savearea
1354bfc86ceSHeiko Carstens#ifdef CONFIG_HAVE_MARCH_Z9_109_FEATURES
1364bfc86ceSHeiko Carstens	.insn	s,0xb27c0000,\savearea		# store clock fast
1374bfc86ceSHeiko Carstens#else
1384bfc86ceSHeiko Carstens	.insn	s,0xb2050000,\savearea		# store clock
1394bfc86ceSHeiko Carstens#endif
1404bfc86ceSHeiko Carstens	.endm
1414bfc86ceSHeiko Carstens
14283abeffbSHendrik Brueckner	/*
14383abeffbSHendrik Brueckner	 * The TSTMSK macro generates a test-under-mask instruction by
14483abeffbSHendrik Brueckner	 * calculating the memory offset for the specified mask value.
14583abeffbSHendrik Brueckner	 * Mask value can be any constant.  The macro shifts the mask
14683abeffbSHendrik Brueckner	 * value to calculate the memory offset for the test-under-mask
14783abeffbSHendrik Brueckner	 * instruction.
14883abeffbSHendrik Brueckner	 */
14983abeffbSHendrik Brueckner	.macro TSTMSK addr, mask, size=8, bytepos=0
15083abeffbSHendrik Brueckner		.if (\bytepos < \size) && (\mask >> 8)
15183abeffbSHendrik Brueckner			.if (\mask & 0xff)
15283abeffbSHendrik Brueckner				.error "Mask exceeds byte boundary"
15383abeffbSHendrik Brueckner			.endif
15483abeffbSHendrik Brueckner			TSTMSK \addr, "(\mask >> 8)", \size, "(\bytepos + 1)"
15583abeffbSHendrik Brueckner			.exitm
15683abeffbSHendrik Brueckner		.endif
15783abeffbSHendrik Brueckner		.ifeq \mask
15883abeffbSHendrik Brueckner			.error "Mask must not be zero"
15983abeffbSHendrik Brueckner		.endif
16083abeffbSHendrik Brueckner		off = \size - \bytepos - 1
16183abeffbSHendrik Brueckner		tm	off+\addr, \mask
16283abeffbSHendrik Brueckner	.endm
16383abeffbSHendrik Brueckner
164d768bd89SMartin Schwidefsky	.macro BPOFF
165d768bd89SMartin Schwidefsky	.pushsection .altinstr_replacement, "ax"
166d768bd89SMartin Schwidefsky660:	.long	0xb2e8c000
167d768bd89SMartin Schwidefsky	.popsection
168d768bd89SMartin Schwidefsky661:	.long	0x47000000
169d768bd89SMartin Schwidefsky	.pushsection .altinstructions, "a"
170d768bd89SMartin Schwidefsky	.long 661b - .
171d768bd89SMartin Schwidefsky	.long 660b - .
172d768bd89SMartin Schwidefsky	.word 82
173d768bd89SMartin Schwidefsky	.byte 4
174d768bd89SMartin Schwidefsky	.byte 4
175d768bd89SMartin Schwidefsky	.popsection
176d768bd89SMartin Schwidefsky	.endm
177d768bd89SMartin Schwidefsky
178d768bd89SMartin Schwidefsky	.macro BPON
179d768bd89SMartin Schwidefsky	.pushsection .altinstr_replacement, "ax"
180d768bd89SMartin Schwidefsky662:	.long	0xb2e8d000
181d768bd89SMartin Schwidefsky	.popsection
182d768bd89SMartin Schwidefsky663:	.long	0x47000000
183d768bd89SMartin Schwidefsky	.pushsection .altinstructions, "a"
184d768bd89SMartin Schwidefsky	.long 663b - .
185d768bd89SMartin Schwidefsky	.long 662b - .
186d768bd89SMartin Schwidefsky	.word 82
187d768bd89SMartin Schwidefsky	.byte 4
188d768bd89SMartin Schwidefsky	.byte 4
189d768bd89SMartin Schwidefsky	.popsection
190d768bd89SMartin Schwidefsky	.endm
191d768bd89SMartin Schwidefsky
1926b73044bSMartin Schwidefsky	.macro BPENTER tif_ptr,tif_mask
1936b73044bSMartin Schwidefsky	.pushsection .altinstr_replacement, "ax"
1946b73044bSMartin Schwidefsky662:	.word	0xc004, 0x0000, 0x0000	# 6 byte nop
1956b73044bSMartin Schwidefsky	.word	0xc004, 0x0000, 0x0000	# 6 byte nop
1966b73044bSMartin Schwidefsky	.popsection
1976b73044bSMartin Schwidefsky664:	TSTMSK	\tif_ptr,\tif_mask
1986b73044bSMartin Schwidefsky	jz	. + 8
1996b73044bSMartin Schwidefsky	.long	0xb2e8d000
2006b73044bSMartin Schwidefsky	.pushsection .altinstructions, "a"
2016b73044bSMartin Schwidefsky	.long 664b - .
2026b73044bSMartin Schwidefsky	.long 662b - .
2036b73044bSMartin Schwidefsky	.word 82
2046b73044bSMartin Schwidefsky	.byte 12
2056b73044bSMartin Schwidefsky	.byte 12
2066b73044bSMartin Schwidefsky	.popsection
2076b73044bSMartin Schwidefsky	.endm
2086b73044bSMartin Schwidefsky
2096b73044bSMartin Schwidefsky	.macro BPEXIT tif_ptr,tif_mask
2106b73044bSMartin Schwidefsky	TSTMSK	\tif_ptr,\tif_mask
2116b73044bSMartin Schwidefsky	.pushsection .altinstr_replacement, "ax"
2126b73044bSMartin Schwidefsky662:	jnz	. + 8
2136b73044bSMartin Schwidefsky	.long	0xb2e8d000
2146b73044bSMartin Schwidefsky	.popsection
2156b73044bSMartin Schwidefsky664:	jz	. + 8
2166b73044bSMartin Schwidefsky	.long	0xb2e8c000
2176b73044bSMartin Schwidefsky	.pushsection .altinstructions, "a"
2186b73044bSMartin Schwidefsky	.long 664b - .
2196b73044bSMartin Schwidefsky	.long 662b - .
2206b73044bSMartin Schwidefsky	.word 82
2216b73044bSMartin Schwidefsky	.byte 8
2226b73044bSMartin Schwidefsky	.byte 8
2236b73044bSMartin Schwidefsky	.popsection
2246b73044bSMartin Schwidefsky	.endm
2256b73044bSMartin Schwidefsky
226f19fbd5eSMartin Schwidefsky#ifdef CONFIG_EXPOLINE
227f19fbd5eSMartin Schwidefsky
228f19fbd5eSMartin Schwidefsky	.macro GEN_BR_THUNK name,reg,tmp
229f19fbd5eSMartin Schwidefsky	.section .text.\name,"axG",@progbits,\name,comdat
230f19fbd5eSMartin Schwidefsky	.globl \name
231f19fbd5eSMartin Schwidefsky	.hidden \name
232f19fbd5eSMartin Schwidefsky	.type \name,@function
233f19fbd5eSMartin Schwidefsky\name:
234dc24b7b4SHendrik Brueckner	CFI_STARTPROC
235f19fbd5eSMartin Schwidefsky#ifdef CONFIG_HAVE_MARCH_Z10_FEATURES
236f19fbd5eSMartin Schwidefsky	exrl	0,0f
237f19fbd5eSMartin Schwidefsky#else
238f19fbd5eSMartin Schwidefsky	larl	\tmp,0f
239f19fbd5eSMartin Schwidefsky	ex	0,0(\tmp)
240f19fbd5eSMartin Schwidefsky#endif
241f19fbd5eSMartin Schwidefsky	j	.
242f19fbd5eSMartin Schwidefsky0:	br	\reg
243dc24b7b4SHendrik Brueckner	CFI_ENDPROC
244f19fbd5eSMartin Schwidefsky	.endm
245f19fbd5eSMartin Schwidefsky
246f19fbd5eSMartin Schwidefsky	GEN_BR_THUNK __s390x_indirect_jump_r1use_r9,%r9,%r1
247f19fbd5eSMartin Schwidefsky	GEN_BR_THUNK __s390x_indirect_jump_r1use_r14,%r14,%r1
248f19fbd5eSMartin Schwidefsky	GEN_BR_THUNK __s390x_indirect_jump_r11use_r14,%r14,%r11
249f19fbd5eSMartin Schwidefsky
250f19fbd5eSMartin Schwidefsky	.macro BASR_R14_R9
251f19fbd5eSMartin Schwidefsky0:	brasl	%r14,__s390x_indirect_jump_r1use_r9
252f19fbd5eSMartin Schwidefsky	.pushsection .s390_indirect_branches,"a",@progbits
253f19fbd5eSMartin Schwidefsky	.long	0b-.
254f19fbd5eSMartin Schwidefsky	.popsection
255f19fbd5eSMartin Schwidefsky	.endm
256f19fbd5eSMartin Schwidefsky
257f19fbd5eSMartin Schwidefsky	.macro BR_R1USE_R14
258f19fbd5eSMartin Schwidefsky0:	jg	__s390x_indirect_jump_r1use_r14
259f19fbd5eSMartin Schwidefsky	.pushsection .s390_indirect_branches,"a",@progbits
260f19fbd5eSMartin Schwidefsky	.long	0b-.
261f19fbd5eSMartin Schwidefsky	.popsection
262f19fbd5eSMartin Schwidefsky	.endm
263f19fbd5eSMartin Schwidefsky
264f19fbd5eSMartin Schwidefsky	.macro BR_R11USE_R14
265f19fbd5eSMartin Schwidefsky0:	jg	__s390x_indirect_jump_r11use_r14
266f19fbd5eSMartin Schwidefsky	.pushsection .s390_indirect_branches,"a",@progbits
267f19fbd5eSMartin Schwidefsky	.long	0b-.
268f19fbd5eSMartin Schwidefsky	.popsection
269f19fbd5eSMartin Schwidefsky	.endm
270f19fbd5eSMartin Schwidefsky
271f19fbd5eSMartin Schwidefsky#else	/* CONFIG_EXPOLINE */
272f19fbd5eSMartin Schwidefsky
273f19fbd5eSMartin Schwidefsky	.macro BASR_R14_R9
274f19fbd5eSMartin Schwidefsky	basr	%r14,%r9
275f19fbd5eSMartin Schwidefsky	.endm
276f19fbd5eSMartin Schwidefsky
277f19fbd5eSMartin Schwidefsky	.macro BR_R1USE_R14
278f19fbd5eSMartin Schwidefsky	br	%r14
279f19fbd5eSMartin Schwidefsky	.endm
280f19fbd5eSMartin Schwidefsky
281f19fbd5eSMartin Schwidefsky	.macro BR_R11USE_R14
282f19fbd5eSMartin Schwidefsky	br	%r14
283f19fbd5eSMartin Schwidefsky	.endm
284f19fbd5eSMartin Schwidefsky
285f19fbd5eSMartin Schwidefsky#endif /* CONFIG_EXPOLINE */
286f19fbd5eSMartin Schwidefsky
287f19fbd5eSMartin Schwidefsky
2884bfc86ceSHeiko Carstens	.section .kprobes.text, "ax"
28946210c44SHeiko Carstens.Ldummy:
29046210c44SHeiko Carstens	/*
29146210c44SHeiko Carstens	 * This nop exists only in order to avoid that __switch_to starts at
29246210c44SHeiko Carstens	 * the beginning of the kprobes text section. In that case we would
29346210c44SHeiko Carstens	 * have several symbols at the same address. E.g. objdump would take
29446210c44SHeiko Carstens	 * an arbitrary symbol name when disassembling this code.
29546210c44SHeiko Carstens	 * With the added nop in between the __switch_to symbol is unique
29646210c44SHeiko Carstens	 * again.
29746210c44SHeiko Carstens	 */
29846210c44SHeiko Carstens	nop	0
2994bfc86ceSHeiko Carstens
300d768bd89SMartin SchwidefskyENTRY(__bpon)
301d768bd89SMartin Schwidefsky	.globl __bpon
302d768bd89SMartin Schwidefsky	BPON
303f19fbd5eSMartin Schwidefsky	BR_R1USE_R14
304d768bd89SMartin Schwidefsky
3054bfc86ceSHeiko Carstens/*
3064bfc86ceSHeiko Carstens * Scheduler resume function, called by switch_to
3074bfc86ceSHeiko Carstens *  gpr2 = (task_struct *) prev
3084bfc86ceSHeiko Carstens *  gpr3 = (task_struct *) next
3094bfc86ceSHeiko Carstens * Returns:
3104bfc86ceSHeiko Carstens *  gpr2 = prev
3114bfc86ceSHeiko Carstens */
3124bfc86ceSHeiko CarstensENTRY(__switch_to)
3134bfc86ceSHeiko Carstens	stmg	%r6,%r15,__SF_GPRS(%r15)	# store gprs of prev task
3143241d3ebSHeiko Carstens	lghi	%r4,__TASK_stack
3153241d3ebSHeiko Carstens	lghi	%r1,__TASK_thread
3163241d3ebSHeiko Carstens	lg	%r5,0(%r4,%r3)			# start of kernel stack of next
3173241d3ebSHeiko Carstens	stg	%r15,__THREAD_ksp(%r1,%r2)	# store kernel stack of prev
3184bfc86ceSHeiko Carstens	lgr	%r15,%r5
3194bfc86ceSHeiko Carstens	aghi	%r15,STACK_INIT			# end of kernel stack of next
3204bfc86ceSHeiko Carstens	stg	%r3,__LC_CURRENT		# store task struct of next
3214bfc86ceSHeiko Carstens	stg	%r15,__LC_KERNEL_STACK		# store end of kernel stack
3223241d3ebSHeiko Carstens	lg	%r15,__THREAD_ksp(%r1,%r3)	# load kernel stack of next
3233241d3ebSHeiko Carstens	aghi	%r3,__TASK_pid
3243241d3ebSHeiko Carstens	mvc	__LC_CURRENT_PID(4,%r0),0(%r3)	# store pid of next
3254bfc86ceSHeiko Carstens	lmg	%r6,%r15,__SF_GPRS(%r15)	# load gprs of next task
326e22cf8caSChristian Borntraeger	TSTMSK	__LC_MACHINE_FLAGS,MACHINE_FLAG_LPP
327f19fbd5eSMartin Schwidefsky	jz	0f
328e22cf8caSChristian Borntraeger	.insn	s,0xb2800000,__LC_LPP		# set program parameter
329f19fbd5eSMartin Schwidefsky0:	BR_R1USE_R14
3304bfc86ceSHeiko Carstens
3314bfc86ceSHeiko Carstens.L__critical_start:
332d0fc4107SMartin Schwidefsky
333d0fc4107SMartin Schwidefsky#if IS_ENABLED(CONFIG_KVM)
334d0fc4107SMartin Schwidefsky/*
335d0fc4107SMartin Schwidefsky * sie64a calling convention:
336d0fc4107SMartin Schwidefsky * %r2 pointer to sie control block
337d0fc4107SMartin Schwidefsky * %r3 guest register save area
338d0fc4107SMartin Schwidefsky */
339d0fc4107SMartin SchwidefskyENTRY(sie64a)
340d0fc4107SMartin Schwidefsky	stmg	%r6,%r14,__SF_GPRS(%r15)	# save kernel registers
3416b73044bSMartin Schwidefsky	lg	%r12,__LC_CURRENT
342d0fc4107SMartin Schwidefsky	stg	%r2,__SF_EMPTY(%r15)		# save control block pointer
343d0fc4107SMartin Schwidefsky	stg	%r3,__SF_EMPTY+8(%r15)		# save guest register save area
344e22cf8caSChristian Borntraeger	xc	__SF_EMPTY+16(8,%r15),__SF_EMPTY+16(%r15) # reason code = 0
3456b73044bSMartin Schwidefsky	mvc	__SF_EMPTY+24(8,%r15),__TI_flags(%r12) # copy thread flags
34683abeffbSHendrik Brueckner	TSTMSK	__LC_CPU_FLAGS,_CIF_FPU		# load guest fp/vx registers ?
347d0fc4107SMartin Schwidefsky	jno	.Lsie_load_guest_gprs
348d0fc4107SMartin Schwidefsky	brasl	%r14,load_fpu_regs		# load guest fp/vx regs
349d0fc4107SMartin Schwidefsky.Lsie_load_guest_gprs:
350d0fc4107SMartin Schwidefsky	lmg	%r0,%r13,0(%r3)			# load guest gprs 0-13
351d0fc4107SMartin Schwidefsky	lg	%r14,__LC_GMAP			# get gmap pointer
352d0fc4107SMartin Schwidefsky	ltgr	%r14,%r14
353d0fc4107SMartin Schwidefsky	jz	.Lsie_gmap
354d0fc4107SMartin Schwidefsky	lctlg	%c1,%c1,__GMAP_ASCE(%r14)	# load primary asce
355d0fc4107SMartin Schwidefsky.Lsie_gmap:
356d0fc4107SMartin Schwidefsky	lg	%r14,__SF_EMPTY(%r15)		# get control block pointer
357d0fc4107SMartin Schwidefsky	oi	__SIE_PROG0C+3(%r14),1		# we are going into SIE now
358d0fc4107SMartin Schwidefsky	tm	__SIE_PROG20+3(%r14),3		# last exit...
359d0fc4107SMartin Schwidefsky	jnz	.Lsie_skip
36083abeffbSHendrik Brueckner	TSTMSK	__LC_CPU_FLAGS,_CIF_FPU
361d0fc4107SMartin Schwidefsky	jo	.Lsie_skip			# exit if fp/vx regs changed
3626b73044bSMartin Schwidefsky	BPEXIT	__SF_EMPTY+24(%r15),(_TIF_ISOLATE_BP|_TIF_ISOLATE_BP_GUEST)
363c929500dSQingFeng Hao.Lsie_entry:
364d0fc4107SMartin Schwidefsky	sie	0(%r14)
365d768bd89SMartin Schwidefsky.Lsie_exit:
366d768bd89SMartin Schwidefsky	BPOFF
3676b73044bSMartin Schwidefsky	BPENTER	__SF_EMPTY+24(%r15),(_TIF_ISOLATE_BP|_TIF_ISOLATE_BP_GUEST)
368d0fc4107SMartin Schwidefsky.Lsie_skip:
369d0fc4107SMartin Schwidefsky	ni	__SIE_PROG0C+3(%r14),0xfe	# no longer in SIE
370d0fc4107SMartin Schwidefsky	lctlg	%c1,%c1,__LC_USER_ASCE		# load primary asce
371d0fc4107SMartin Schwidefsky.Lsie_done:
372d0fc4107SMartin Schwidefsky# some program checks are suppressing. C code (e.g. do_protection_exception)
373c0e7bb38SChristian Borntraeger# will rewind the PSW by the ILC, which is often 4 bytes in case of SIE. There
374c0e7bb38SChristian Borntraeger# are some corner cases (e.g. runtime instrumentation) where ILC is unpredictable.
375c0e7bb38SChristian Borntraeger# Other instructions between sie64a and .Lsie_done should not cause program
376c0e7bb38SChristian Borntraeger# interrupts. So lets use 3 nops as a landing pad for all possible rewinds.
377d0fc4107SMartin Schwidefsky# See also .Lcleanup_sie
378c0e7bb38SChristian Borntraeger.Lrewind_pad6:
379c0e7bb38SChristian Borntraeger	nopr	7
380c0e7bb38SChristian Borntraeger.Lrewind_pad4:
381c0e7bb38SChristian Borntraeger	nopr	7
382c0e7bb38SChristian Borntraeger.Lrewind_pad2:
383c0e7bb38SChristian Borntraeger	nopr	7
384d0fc4107SMartin Schwidefsky	.globl sie_exit
385d0fc4107SMartin Schwidefskysie_exit:
386d0fc4107SMartin Schwidefsky	lg	%r14,__SF_EMPTY+8(%r15)		# load guest register save area
387d0fc4107SMartin Schwidefsky	stmg	%r0,%r13,0(%r14)		# save guest gprs 0-13
3887041d281SMartin Schwidefsky	xgr	%r0,%r0				# clear guest registers to
3897041d281SMartin Schwidefsky	xgr	%r1,%r1				# prevent speculative use
3907041d281SMartin Schwidefsky	xgr	%r2,%r2
3917041d281SMartin Schwidefsky	xgr	%r3,%r3
3927041d281SMartin Schwidefsky	xgr	%r4,%r4
3937041d281SMartin Schwidefsky	xgr	%r5,%r5
394d0fc4107SMartin Schwidefsky	lmg	%r6,%r14,__SF_GPRS(%r15)	# restore kernel registers
395e22cf8caSChristian Borntraeger	lg	%r2,__SF_EMPTY+16(%r15)		# return exit reason code
396f19fbd5eSMartin Schwidefsky	BR_R1USE_R14
397d0fc4107SMartin Schwidefsky.Lsie_fault:
398d0fc4107SMartin Schwidefsky	lghi	%r14,-EFAULT
399e22cf8caSChristian Borntraeger	stg	%r14,__SF_EMPTY+16(%r15)	# set exit reason code
400d0fc4107SMartin Schwidefsky	j	sie_exit
401d0fc4107SMartin Schwidefsky
402c0e7bb38SChristian Borntraeger	EX_TABLE(.Lrewind_pad6,.Lsie_fault)
403c0e7bb38SChristian Borntraeger	EX_TABLE(.Lrewind_pad4,.Lsie_fault)
404c0e7bb38SChristian Borntraeger	EX_TABLE(.Lrewind_pad2,.Lsie_fault)
405d0fc4107SMartin Schwidefsky	EX_TABLE(sie_exit,.Lsie_fault)
406711f5df7SAl ViroEXPORT_SYMBOL(sie64a)
407711f5df7SAl ViroEXPORT_SYMBOL(sie_exit)
408d0fc4107SMartin Schwidefsky#endif
409d0fc4107SMartin Schwidefsky
4104bfc86ceSHeiko Carstens/*
4114bfc86ceSHeiko Carstens * SVC interrupt handler routine. System calls are synchronous events and
4124bfc86ceSHeiko Carstens * are executed with interrupts enabled.
4134bfc86ceSHeiko Carstens */
4144bfc86ceSHeiko Carstens
4154bfc86ceSHeiko CarstensENTRY(system_call)
4164bfc86ceSHeiko Carstens	stpt	__LC_SYNC_ENTER_TIMER
4174bfc86ceSHeiko Carstens.Lsysc_stmg:
4184bfc86ceSHeiko Carstens	stmg	%r8,%r15,__LC_SAVE_AREA_SYNC
419d768bd89SMartin Schwidefsky	BPOFF
420d5c352cdSHeiko Carstens	lg	%r12,__LC_CURRENT
42134525e1fSMartin Schwidefsky	lghi	%r13,__TASK_thread
4224bfc86ceSHeiko Carstens	lghi	%r14,_PIF_SYSCALL
4234bfc86ceSHeiko Carstens.Lsysc_per:
4244bfc86ceSHeiko Carstens	lg	%r15,__LC_KERNEL_STACK
4254bfc86ceSHeiko Carstens	la	%r11,STACK_FRAME_OVERHEAD(%r15)	# pointer to pt_regs
426a359bb11SMartin Schwidefsky.Lsysc_vtime:
42734525e1fSMartin Schwidefsky	UPDATE_VTIME %r8,%r9,__LC_SYNC_ENTER_TIMER
4286b73044bSMartin Schwidefsky	BPENTER __TI_flags(%r12),_TIF_ISOLATE_BP
4294bfc86ceSHeiko Carstens	stmg	%r0,%r7,__PT_R0(%r11)
4304bfc86ceSHeiko Carstens	mvc	__PT_R8(64,%r11),__LC_SAVE_AREA_SYNC
4314bfc86ceSHeiko Carstens	mvc	__PT_PSW(16,%r11),__LC_SVC_OLD_PSW
4324bfc86ceSHeiko Carstens	mvc	__PT_INT_CODE(4,%r11),__LC_SVC_ILC
4334bfc86ceSHeiko Carstens	stg	%r14,__PT_FLAGS(%r11)
4344bfc86ceSHeiko Carstens.Lsysc_do_svc:
435*d3f46896SChristian Borntraeger	# clear user controlled register to prevent speculative use
436*d3f46896SChristian Borntraeger	xgr	%r0,%r0
437ef280c85SMartin Schwidefsky	# load address of system call table
438ef280c85SMartin Schwidefsky	lg	%r10,__THREAD_sysc_table(%r13,%r12)
4394bfc86ceSHeiko Carstens	llgh	%r8,__PT_INT_CODE+2(%r11)
4404bfc86ceSHeiko Carstens	slag	%r8,%r8,2			# shift and test for svc 0
4414bfc86ceSHeiko Carstens	jnz	.Lsysc_nr_ok
4424bfc86ceSHeiko Carstens	# svc 0: system call number in %r1
4434bfc86ceSHeiko Carstens	llgfr	%r1,%r1				# clear high word in r1
4444bfc86ceSHeiko Carstens	cghi	%r1,NR_syscalls
4454bfc86ceSHeiko Carstens	jnl	.Lsysc_nr_ok
4464bfc86ceSHeiko Carstens	sth	%r1,__PT_INT_CODE+2(%r11)
4474bfc86ceSHeiko Carstens	slag	%r8,%r1,2
4484bfc86ceSHeiko Carstens.Lsysc_nr_ok:
4494bfc86ceSHeiko Carstens	xc	__SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
4504bfc86ceSHeiko Carstens	stg	%r2,__PT_ORIG_GPR2(%r11)
4514bfc86ceSHeiko Carstens	stg	%r7,STACK_FRAME_OVERHEAD(%r15)
4524bfc86ceSHeiko Carstens	lgf	%r9,0(%r8,%r10)			# get system call add.
45383abeffbSHendrik Brueckner	TSTMSK	__TI_flags(%r12),_TIF_TRACE
4544bfc86ceSHeiko Carstens	jnz	.Lsysc_tracesys
455f19fbd5eSMartin Schwidefsky	BASR_R14_R9				# call sys_xxxx
4564bfc86ceSHeiko Carstens	stg	%r2,__PT_R2(%r11)		# store return value
4574bfc86ceSHeiko Carstens
4584bfc86ceSHeiko Carstens.Lsysc_return:
4594bfc86ceSHeiko Carstens	LOCKDEP_SYS_EXIT
4604bfc86ceSHeiko Carstens.Lsysc_tif:
46183abeffbSHendrik Brueckner	TSTMSK	__PT_FLAGS(%r11),_PIF_WORK
4624bfc86ceSHeiko Carstens	jnz	.Lsysc_work
46383abeffbSHendrik Brueckner	TSTMSK	__TI_flags(%r12),_TIF_WORK
4644bfc86ceSHeiko Carstens	jnz	.Lsysc_work			# check for work
46583abeffbSHendrik Brueckner	TSTMSK	__LC_CPU_FLAGS,_CIF_WORK
4664bfc86ceSHeiko Carstens	jnz	.Lsysc_work
4676b73044bSMartin Schwidefsky	BPEXIT	__TI_flags(%r12),_TIF_ISOLATE_BP
4684bfc86ceSHeiko Carstens.Lsysc_restore:
4694bfc86ceSHeiko Carstens	lg	%r14,__LC_VDSO_PER_CPU
4704bfc86ceSHeiko Carstens	lmg	%r0,%r10,__PT_R0(%r11)
4714bfc86ceSHeiko Carstens	mvc	__LC_RETURN_PSW(16),__PT_PSW(%r11)
47207a63cbeSMartin Schwidefsky.Lsysc_exit_timer:
4734bfc86ceSHeiko Carstens	stpt	__LC_EXIT_TIMER
4744bfc86ceSHeiko Carstens	mvc	__VDSO_ECTG_BASE(16,%r14),__LC_EXIT_TIMER
4754bfc86ceSHeiko Carstens	lmg	%r11,%r15,__PT_R11(%r11)
4764bfc86ceSHeiko Carstens	lpswe	__LC_RETURN_PSW
4774bfc86ceSHeiko Carstens.Lsysc_done:
4784bfc86ceSHeiko Carstens
4794bfc86ceSHeiko Carstens#
4804bfc86ceSHeiko Carstens# One of the work bits is on. Find out which one.
4814bfc86ceSHeiko Carstens#
4824bfc86ceSHeiko Carstens.Lsysc_work:
48383abeffbSHendrik Brueckner	TSTMSK	__LC_CPU_FLAGS,_CIF_MCCK_PENDING
4844bfc86ceSHeiko Carstens	jo	.Lsysc_mcck_pending
48583abeffbSHendrik Brueckner	TSTMSK	__TI_flags(%r12),_TIF_NEED_RESCHED
4864bfc86ceSHeiko Carstens	jo	.Lsysc_reschedule
48723fefe11SMartin Schwidefsky	TSTMSK	__PT_FLAGS(%r11),_PIF_SYSCALL_RESTART
48823fefe11SMartin Schwidefsky	jo	.Lsysc_syscall_restart
4894bfc86ceSHeiko Carstens#ifdef CONFIG_UPROBES
49083abeffbSHendrik Brueckner	TSTMSK	__TI_flags(%r12),_TIF_UPROBE
4914bfc86ceSHeiko Carstens	jo	.Lsysc_uprobe_notify
4924bfc86ceSHeiko Carstens#endif
493916cda1aSMartin Schwidefsky	TSTMSK	__TI_flags(%r12),_TIF_GUARDED_STORAGE
494916cda1aSMartin Schwidefsky	jo	.Lsysc_guarded_storage
49583abeffbSHendrik Brueckner	TSTMSK	__PT_FLAGS(%r11),_PIF_PER_TRAP
4964bfc86ceSHeiko Carstens	jo	.Lsysc_singlestep
4972f09ca60SMiroslav Benes#ifdef CONFIG_LIVEPATCH
4982f09ca60SMiroslav Benes	TSTMSK	__TI_flags(%r12),_TIF_PATCH_PENDING
4992f09ca60SMiroslav Benes	jo	.Lsysc_patch_pending	# handle live patching just before
5002f09ca60SMiroslav Benes					# signals and possible syscall restart
5012f09ca60SMiroslav Benes#endif
50223fefe11SMartin Schwidefsky	TSTMSK	__PT_FLAGS(%r11),_PIF_SYSCALL_RESTART
50323fefe11SMartin Schwidefsky	jo	.Lsysc_syscall_restart
50483abeffbSHendrik Brueckner	TSTMSK	__TI_flags(%r12),_TIF_SIGPENDING
5054bfc86ceSHeiko Carstens	jo	.Lsysc_sigpending
50683abeffbSHendrik Brueckner	TSTMSK	__TI_flags(%r12),_TIF_NOTIFY_RESUME
5074bfc86ceSHeiko Carstens	jo	.Lsysc_notify_resume
50883abeffbSHendrik Brueckner	TSTMSK	__LC_CPU_FLAGS,_CIF_FPU
5099977e886SHendrik Brueckner	jo	.Lsysc_vxrs
510b5a882fcSHeiko Carstens	TSTMSK	__LC_CPU_FLAGS,(_CIF_ASCE_PRIMARY|_CIF_ASCE_SECONDARY)
511b5a882fcSHeiko Carstens	jnz	.Lsysc_asce
5124bfc86ceSHeiko Carstens	j	.Lsysc_return		# beware of critical section cleanup
5134bfc86ceSHeiko Carstens
5144bfc86ceSHeiko Carstens#
5154bfc86ceSHeiko Carstens# _TIF_NEED_RESCHED is set, call schedule
5164bfc86ceSHeiko Carstens#
5174bfc86ceSHeiko Carstens.Lsysc_reschedule:
5184bfc86ceSHeiko Carstens	larl	%r14,.Lsysc_return
5194bfc86ceSHeiko Carstens	jg	schedule
5204bfc86ceSHeiko Carstens
5214bfc86ceSHeiko Carstens#
5224bfc86ceSHeiko Carstens# _CIF_MCCK_PENDING is set, call handler
5234bfc86ceSHeiko Carstens#
5244bfc86ceSHeiko Carstens.Lsysc_mcck_pending:
5254bfc86ceSHeiko Carstens	larl	%r14,.Lsysc_return
5264bfc86ceSHeiko Carstens	jg	s390_handle_mcck	# TIF bit will be cleared by handler
5274bfc86ceSHeiko Carstens
5284bfc86ceSHeiko Carstens#
5290aaba41bSMartin Schwidefsky# _CIF_ASCE_PRIMARY and/or _CIF_ASCE_SECONDARY set, load user space asce
5304bfc86ceSHeiko Carstens#
531b5a882fcSHeiko Carstens.Lsysc_asce:
5320aaba41bSMartin Schwidefsky	ni	__LC_CPU_FLAGS+7,255-_CIF_ASCE_SECONDARY
5330aaba41bSMartin Schwidefsky	lctlg	%c7,%c7,__LC_VDSO_ASCE		# load secondary asce
5340aaba41bSMartin Schwidefsky	TSTMSK	__LC_CPU_FLAGS,_CIF_ASCE_PRIMARY
5350aaba41bSMartin Schwidefsky	jz	.Lsysc_return
5360aaba41bSMartin Schwidefsky#ifndef CONFIG_HAVE_MARCH_Z10_FEATURES
5370aaba41bSMartin Schwidefsky	tm	__LC_STFLE_FAC_LIST+3,0x10	# has MVCOS ?
5380aaba41bSMartin Schwidefsky	jnz	.Lsysc_set_fs_fixup
539606aa4aaSHeiko Carstens	ni	__LC_CPU_FLAGS+7,255-_CIF_ASCE_PRIMARY
5404bfc86ceSHeiko Carstens	lctlg	%c1,%c1,__LC_USER_ASCE		# load primary asce
5410aaba41bSMartin Schwidefsky	j	.Lsysc_return
5420aaba41bSMartin Schwidefsky.Lsysc_set_fs_fixup:
5430aaba41bSMartin Schwidefsky#endif
544b5a882fcSHeiko Carstens	larl	%r14,.Lsysc_return
545b5a882fcSHeiko Carstens	jg	set_fs_fixup
5464bfc86ceSHeiko Carstens
5474bfc86ceSHeiko Carstens#
5489977e886SHendrik Brueckner# CIF_FPU is set, restore floating-point controls and floating-point registers.
5499977e886SHendrik Brueckner#
5509977e886SHendrik Brueckner.Lsysc_vxrs:
5519977e886SHendrik Brueckner	larl	%r14,.Lsysc_return
5529977e886SHendrik Brueckner	jg	load_fpu_regs
5539977e886SHendrik Brueckner
5549977e886SHendrik Brueckner#
5554bfc86ceSHeiko Carstens# _TIF_SIGPENDING is set, call do_signal
5564bfc86ceSHeiko Carstens#
5574bfc86ceSHeiko Carstens.Lsysc_sigpending:
5584bfc86ceSHeiko Carstens	lgr	%r2,%r11		# pass pointer to pt_regs
5594bfc86ceSHeiko Carstens	brasl	%r14,do_signal
56083abeffbSHendrik Brueckner	TSTMSK	__PT_FLAGS(%r11),_PIF_SYSCALL
5614bfc86ceSHeiko Carstens	jno	.Lsysc_return
56257d7f939SMartin Schwidefsky.Lsysc_do_syscall:
56357d7f939SMartin Schwidefsky	lghi	%r13,__TASK_thread
5644bfc86ceSHeiko Carstens	lmg	%r2,%r7,__PT_R2(%r11)	# load svc arguments
56557d7f939SMartin Schwidefsky	lghi	%r1,0			# svc 0 returns -ENOSYS
56657d7f939SMartin Schwidefsky	j	.Lsysc_do_svc
5674bfc86ceSHeiko Carstens
5684bfc86ceSHeiko Carstens#
5694bfc86ceSHeiko Carstens# _TIF_NOTIFY_RESUME is set, call do_notify_resume
5704bfc86ceSHeiko Carstens#
5714bfc86ceSHeiko Carstens.Lsysc_notify_resume:
5724bfc86ceSHeiko Carstens	lgr	%r2,%r11		# pass pointer to pt_regs
5734bfc86ceSHeiko Carstens	larl	%r14,.Lsysc_return
5744bfc86ceSHeiko Carstens	jg	do_notify_resume
5754bfc86ceSHeiko Carstens
5764bfc86ceSHeiko Carstens#
5774bfc86ceSHeiko Carstens# _TIF_UPROBE is set, call uprobe_notify_resume
5784bfc86ceSHeiko Carstens#
5794bfc86ceSHeiko Carstens#ifdef CONFIG_UPROBES
5804bfc86ceSHeiko Carstens.Lsysc_uprobe_notify:
5814bfc86ceSHeiko Carstens	lgr	%r2,%r11		# pass pointer to pt_regs
5824bfc86ceSHeiko Carstens	larl	%r14,.Lsysc_return
5834bfc86ceSHeiko Carstens	jg	uprobe_notify_resume
5844bfc86ceSHeiko Carstens#endif
5854bfc86ceSHeiko Carstens
5864bfc86ceSHeiko Carstens#
587916cda1aSMartin Schwidefsky# _TIF_GUARDED_STORAGE is set, call guarded_storage_load
588916cda1aSMartin Schwidefsky#
589916cda1aSMartin Schwidefsky.Lsysc_guarded_storage:
590916cda1aSMartin Schwidefsky	lgr	%r2,%r11		# pass pointer to pt_regs
591916cda1aSMartin Schwidefsky	larl	%r14,.Lsysc_return
592916cda1aSMartin Schwidefsky	jg	gs_load_bc_cb
59376f1948aSLinus Torvalds#
5942f09ca60SMiroslav Benes# _TIF_PATCH_PENDING is set, call klp_update_patch_state
5952f09ca60SMiroslav Benes#
5962f09ca60SMiroslav Benes#ifdef CONFIG_LIVEPATCH
5972f09ca60SMiroslav Benes.Lsysc_patch_pending:
5982f09ca60SMiroslav Benes	lg	%r2,__LC_CURRENT	# pass pointer to task struct
5992f09ca60SMiroslav Benes	larl	%r14,.Lsysc_return
6002f09ca60SMiroslav Benes	jg	klp_update_patch_state
6012f09ca60SMiroslav Benes#endif
602916cda1aSMartin Schwidefsky
603916cda1aSMartin Schwidefsky#
6044bfc86ceSHeiko Carstens# _PIF_PER_TRAP is set, call do_per_trap
6054bfc86ceSHeiko Carstens#
6064bfc86ceSHeiko Carstens.Lsysc_singlestep:
6074bfc86ceSHeiko Carstens	ni	__PT_FLAGS+7(%r11),255-_PIF_PER_TRAP
6084bfc86ceSHeiko Carstens	lgr	%r2,%r11		# pass pointer to pt_regs
6094bfc86ceSHeiko Carstens	larl	%r14,.Lsysc_return
6104bfc86ceSHeiko Carstens	jg	do_per_trap
6114bfc86ceSHeiko Carstens
6124bfc86ceSHeiko Carstens#
61323fefe11SMartin Schwidefsky# _PIF_SYSCALL_RESTART is set, repeat the current system call
61423fefe11SMartin Schwidefsky#
61523fefe11SMartin Schwidefsky.Lsysc_syscall_restart:
61623fefe11SMartin Schwidefsky	ni	__PT_FLAGS+7(%r11),255-_PIF_SYSCALL_RESTART
61723fefe11SMartin Schwidefsky	lmg	%r1,%r7,__PT_R1(%r11)	# load svc arguments
61823fefe11SMartin Schwidefsky	lg	%r2,__PT_ORIG_GPR2(%r11)
61923fefe11SMartin Schwidefsky	j	.Lsysc_do_svc
62023fefe11SMartin Schwidefsky
62123fefe11SMartin Schwidefsky#
6224bfc86ceSHeiko Carstens# call tracehook_report_syscall_entry/tracehook_report_syscall_exit before
6234bfc86ceSHeiko Carstens# and after the system call
6244bfc86ceSHeiko Carstens#
6254bfc86ceSHeiko Carstens.Lsysc_tracesys:
6264bfc86ceSHeiko Carstens	lgr	%r2,%r11		# pass pointer to pt_regs
6274bfc86ceSHeiko Carstens	la	%r3,0
6284bfc86ceSHeiko Carstens	llgh	%r0,__PT_INT_CODE+2(%r11)
6294bfc86ceSHeiko Carstens	stg	%r0,__PT_R2(%r11)
6304bfc86ceSHeiko Carstens	brasl	%r14,do_syscall_trace_enter
6314bfc86ceSHeiko Carstens	lghi	%r0,NR_syscalls
6324bfc86ceSHeiko Carstens	clgr	%r0,%r2
6334bfc86ceSHeiko Carstens	jnh	.Lsysc_tracenogo
6344bfc86ceSHeiko Carstens	sllg	%r8,%r2,2
6354bfc86ceSHeiko Carstens	lgf	%r9,0(%r8,%r10)
6364bfc86ceSHeiko Carstens.Lsysc_tracego:
6374bfc86ceSHeiko Carstens	lmg	%r3,%r7,__PT_R3(%r11)
6384bfc86ceSHeiko Carstens	stg	%r7,STACK_FRAME_OVERHEAD(%r15)
6394bfc86ceSHeiko Carstens	lg	%r2,__PT_ORIG_GPR2(%r11)
640f19fbd5eSMartin Schwidefsky	BASR_R14_R9			# call sys_xxx
6414bfc86ceSHeiko Carstens	stg	%r2,__PT_R2(%r11)	# store return value
6424bfc86ceSHeiko Carstens.Lsysc_tracenogo:
64383abeffbSHendrik Brueckner	TSTMSK	__TI_flags(%r12),_TIF_TRACE
6444bfc86ceSHeiko Carstens	jz	.Lsysc_return
6454bfc86ceSHeiko Carstens	lgr	%r2,%r11		# pass pointer to pt_regs
6464bfc86ceSHeiko Carstens	larl	%r14,.Lsysc_return
6474bfc86ceSHeiko Carstens	jg	do_syscall_trace_exit
6484bfc86ceSHeiko Carstens
6494bfc86ceSHeiko Carstens#
6504bfc86ceSHeiko Carstens# a new process exits the kernel with ret_from_fork
6514bfc86ceSHeiko Carstens#
6524bfc86ceSHeiko CarstensENTRY(ret_from_fork)
6534bfc86ceSHeiko Carstens	la	%r11,STACK_FRAME_OVERHEAD(%r15)
654d5c352cdSHeiko Carstens	lg	%r12,__LC_CURRENT
6554bfc86ceSHeiko Carstens	brasl	%r14,schedule_tail
6564bfc86ceSHeiko Carstens	TRACE_IRQS_ON
6574bfc86ceSHeiko Carstens	ssm	__LC_SVC_NEW_PSW	# reenable interrupts
6584bfc86ceSHeiko Carstens	tm	__PT_PSW+1(%r11),0x01	# forking a kernel thread ?
6594bfc86ceSHeiko Carstens	jne	.Lsysc_tracenogo
6604bfc86ceSHeiko Carstens	# it's a kernel thread
6614bfc86ceSHeiko Carstens	lmg	%r9,%r10,__PT_R9(%r11)	# load gprs
6624bfc86ceSHeiko CarstensENTRY(kernel_thread_starter)
6634bfc86ceSHeiko Carstens	la	%r2,0(%r10)
664f19fbd5eSMartin Schwidefsky	BASR_R14_R9
6654bfc86ceSHeiko Carstens	j	.Lsysc_tracenogo
6664bfc86ceSHeiko Carstens
6674bfc86ceSHeiko Carstens/*
6684bfc86ceSHeiko Carstens * Program check handler routine
6694bfc86ceSHeiko Carstens */
6704bfc86ceSHeiko Carstens
6714bfc86ceSHeiko CarstensENTRY(pgm_check_handler)
6724bfc86ceSHeiko Carstens	stpt	__LC_SYNC_ENTER_TIMER
673d768bd89SMartin Schwidefsky	BPOFF
6744bfc86ceSHeiko Carstens	stmg	%r8,%r15,__LC_SAVE_AREA_SYNC
6754bfc86ceSHeiko Carstens	lg	%r10,__LC_LAST_BREAK
676d5c352cdSHeiko Carstens	lg	%r12,__LC_CURRENT
677c771320eSMartin Schwidefsky	lghi	%r11,0
6789977e886SHendrik Brueckner	larl	%r13,cleanup_critical
6794bfc86ceSHeiko Carstens	lmg	%r8,%r9,__LC_PGM_OLD_PSW
6804bfc86ceSHeiko Carstens	tmhh	%r8,0x0001		# test problem state bit
681d0fc4107SMartin Schwidefsky	jnz	2f			# -> fault in user space
682d0fc4107SMartin Schwidefsky#if IS_ENABLED(CONFIG_KVM)
6830a5e2ec2SMartin Schwidefsky	# cleanup critical section for program checks in sie64a
684d0fc4107SMartin Schwidefsky	lgr	%r14,%r9
685d0fc4107SMartin Schwidefsky	slg	%r14,BASED(.Lsie_critical_start)
686d0fc4107SMartin Schwidefsky	clg	%r14,BASED(.Lsie_critical_length)
687d0fc4107SMartin Schwidefsky	jhe	0f
6880a5e2ec2SMartin Schwidefsky	lg	%r14,__SF_EMPTY(%r15)		# get control block pointer
6890a5e2ec2SMartin Schwidefsky	ni	__SIE_PROG0C+3(%r14),0xfe	# no longer in SIE
6900a5e2ec2SMartin Schwidefsky	lctlg	%c1,%c1,__LC_USER_ASCE		# load primary asce
6910a5e2ec2SMartin Schwidefsky	larl	%r9,sie_exit			# skip forward to sie_exit
692c771320eSMartin Schwidefsky	lghi	%r11,_PIF_GUEST_FAULT
693d0fc4107SMartin Schwidefsky#endif
694d0fc4107SMartin Schwidefsky0:	tmhh	%r8,0x4000		# PER bit set in old PSW ?
695d0fc4107SMartin Schwidefsky	jnz	1f			# -> enabled, can't be a double fault
6964bfc86ceSHeiko Carstens	tm	__LC_PGM_ILC+3,0x80	# check for per exception
6974bfc86ceSHeiko Carstens	jnz	.Lpgm_svcper		# -> single stepped svc
698d0fc4107SMartin Schwidefsky1:	CHECK_STACK STACK_SIZE,__LC_SAVE_AREA_SYNC
6994bfc86ceSHeiko Carstens	aghi	%r15,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
700d9fcf2a1SMartin Schwidefsky	j	4f
70134525e1fSMartin Schwidefsky2:	UPDATE_VTIME %r14,%r15,__LC_SYNC_ENTER_TIMER
7026b73044bSMartin Schwidefsky	BPENTER __TI_flags(%r12),_TIF_ISOLATE_BP
7034bfc86ceSHeiko Carstens	lg	%r15,__LC_KERNEL_STACK
704d5c352cdSHeiko Carstens	lgr	%r14,%r12
7053827ec3dSMartin Schwidefsky	aghi	%r14,__TASK_thread	# pointer to thread_struct
7064bfc86ceSHeiko Carstens	lghi	%r13,__LC_PGM_TDB
7074bfc86ceSHeiko Carstens	tm	__LC_PGM_ILC+2,0x02	# check for transaction abort
708d0fc4107SMartin Schwidefsky	jz	3f
7094bfc86ceSHeiko Carstens	mvc	__THREAD_trap_tdb(256,%r14),0(%r13)
710d9fcf2a1SMartin Schwidefsky3:	stg	%r10,__THREAD_last_break(%r14)
711c771320eSMartin Schwidefsky4:	lgr	%r13,%r11
712c771320eSMartin Schwidefsky	la	%r11,STACK_FRAME_OVERHEAD(%r15)
7134bfc86ceSHeiko Carstens	stmg	%r0,%r7,__PT_R0(%r11)
7147041d281SMartin Schwidefsky	# clear user controlled registers to prevent speculative use
7157041d281SMartin Schwidefsky	xgr	%r0,%r0
7167041d281SMartin Schwidefsky	xgr	%r1,%r1
7177041d281SMartin Schwidefsky	xgr	%r2,%r2
7187041d281SMartin Schwidefsky	xgr	%r3,%r3
7197041d281SMartin Schwidefsky	xgr	%r4,%r4
7207041d281SMartin Schwidefsky	xgr	%r5,%r5
7217041d281SMartin Schwidefsky	xgr	%r6,%r6
7227041d281SMartin Schwidefsky	xgr	%r7,%r7
7234bfc86ceSHeiko Carstens	mvc	__PT_R8(64,%r11),__LC_SAVE_AREA_SYNC
7244bfc86ceSHeiko Carstens	stmg	%r8,%r9,__PT_PSW(%r11)
7254bfc86ceSHeiko Carstens	mvc	__PT_INT_CODE(4,%r11),__LC_PGM_ILC
7264bfc86ceSHeiko Carstens	mvc	__PT_INT_PARM_LONG(8,%r11),__LC_TRANS_EXC_CODE
727c771320eSMartin Schwidefsky	stg	%r13,__PT_FLAGS(%r11)
7284bfc86ceSHeiko Carstens	stg	%r10,__PT_ARGS(%r11)
7294bfc86ceSHeiko Carstens	tm	__LC_PGM_ILC+3,0x80	# check for per exception
730d9fcf2a1SMartin Schwidefsky	jz	5f
7314bfc86ceSHeiko Carstens	tmhh	%r8,0x0001		# kernel per event ?
7324bfc86ceSHeiko Carstens	jz	.Lpgm_kprobe
7334bfc86ceSHeiko Carstens	oi	__PT_FLAGS+7(%r11),_PIF_PER_TRAP
7344bfc86ceSHeiko Carstens	mvc	__THREAD_per_address(8,%r14),__LC_PER_ADDRESS
7354bfc86ceSHeiko Carstens	mvc	__THREAD_per_cause(2,%r14),__LC_PER_CODE
7364bfc86ceSHeiko Carstens	mvc	__THREAD_per_paid(1,%r14),__LC_PER_ACCESS_ID
737d9fcf2a1SMartin Schwidefsky5:	REENABLE_IRQS
7384bfc86ceSHeiko Carstens	xc	__SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
7394bfc86ceSHeiko Carstens	larl	%r1,pgm_check_table
7404bfc86ceSHeiko Carstens	llgh	%r10,__PT_INT_CODE+2(%r11)
7414bfc86ceSHeiko Carstens	nill	%r10,0x007f
7424bfc86ceSHeiko Carstens	sll	%r10,2
743a359bb11SMartin Schwidefsky	je	.Lpgm_return
744f19fbd5eSMartin Schwidefsky	lgf	%r9,0(%r10,%r1)		# load address of handler routine
7454bfc86ceSHeiko Carstens	lgr	%r2,%r11		# pass pointer to pt_regs
746f19fbd5eSMartin Schwidefsky	BASR_R14_R9			# branch to interrupt-handler
747a359bb11SMartin Schwidefsky.Lpgm_return:
748a359bb11SMartin Schwidefsky	LOCKDEP_SYS_EXIT
749a359bb11SMartin Schwidefsky	tm	__PT_PSW+1(%r11),0x01	# returning to user ?
750a359bb11SMartin Schwidefsky	jno	.Lsysc_restore
75157d7f939SMartin Schwidefsky	TSTMSK	__PT_FLAGS(%r11),_PIF_SYSCALL
75257d7f939SMartin Schwidefsky	jo	.Lsysc_do_syscall
753a359bb11SMartin Schwidefsky	j	.Lsysc_tif
7544bfc86ceSHeiko Carstens
7554bfc86ceSHeiko Carstens#
7564bfc86ceSHeiko Carstens# PER event in supervisor state, must be kprobes
7574bfc86ceSHeiko Carstens#
7584bfc86ceSHeiko Carstens.Lpgm_kprobe:
7594bfc86ceSHeiko Carstens	REENABLE_IRQS
7604bfc86ceSHeiko Carstens	xc	__SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
7614bfc86ceSHeiko Carstens	lgr	%r2,%r11		# pass pointer to pt_regs
7624bfc86ceSHeiko Carstens	brasl	%r14,do_per_trap
763a359bb11SMartin Schwidefsky	j	.Lpgm_return
7644bfc86ceSHeiko Carstens
7654bfc86ceSHeiko Carstens#
7664bfc86ceSHeiko Carstens# single stepped system call
7674bfc86ceSHeiko Carstens#
7684bfc86ceSHeiko Carstens.Lpgm_svcper:
7694bfc86ceSHeiko Carstens	mvc	__LC_RETURN_PSW(8),__LC_SVC_NEW_PSW
770d24b98e3SMartin Schwidefsky	lghi	%r13,__TASK_thread
7714bfc86ceSHeiko Carstens	larl	%r14,.Lsysc_per
7724bfc86ceSHeiko Carstens	stg	%r14,__LC_RETURN_PSW+8
7734bfc86ceSHeiko Carstens	lghi	%r14,_PIF_SYSCALL | _PIF_PER_TRAP
7744bfc86ceSHeiko Carstens	lpswe	__LC_RETURN_PSW		# branch to .Lsysc_per and enable irqs
7754bfc86ceSHeiko Carstens
7764bfc86ceSHeiko Carstens/*
7774bfc86ceSHeiko Carstens * IO interrupt handler routine
7784bfc86ceSHeiko Carstens */
7794bfc86ceSHeiko CarstensENTRY(io_int_handler)
7804bfc86ceSHeiko Carstens	STCK	__LC_INT_CLOCK
7814bfc86ceSHeiko Carstens	stpt	__LC_ASYNC_ENTER_TIMER
782d768bd89SMartin Schwidefsky	BPOFF
7834bfc86ceSHeiko Carstens	stmg	%r8,%r15,__LC_SAVE_AREA_ASYNC
784d5c352cdSHeiko Carstens	lg	%r12,__LC_CURRENT
7859977e886SHendrik Brueckner	larl	%r13,cleanup_critical
7864bfc86ceSHeiko Carstens	lmg	%r8,%r9,__LC_IO_OLD_PSW
7872acb94f4SMartin Schwidefsky	SWITCH_ASYNC __LC_SAVE_AREA_ASYNC,__LC_ASYNC_ENTER_TIMER
7884bfc86ceSHeiko Carstens	stmg	%r0,%r7,__PT_R0(%r11)
7897041d281SMartin Schwidefsky	# clear user controlled registers to prevent speculative use
7907041d281SMartin Schwidefsky	xgr	%r0,%r0
7917041d281SMartin Schwidefsky	xgr	%r1,%r1
7927041d281SMartin Schwidefsky	xgr	%r2,%r2
7937041d281SMartin Schwidefsky	xgr	%r3,%r3
7947041d281SMartin Schwidefsky	xgr	%r4,%r4
7957041d281SMartin Schwidefsky	xgr	%r5,%r5
7967041d281SMartin Schwidefsky	xgr	%r6,%r6
7977041d281SMartin Schwidefsky	xgr	%r7,%r7
7987041d281SMartin Schwidefsky	xgr	%r10,%r10
7994bfc86ceSHeiko Carstens	mvc	__PT_R8(64,%r11),__LC_SAVE_AREA_ASYNC
8004bfc86ceSHeiko Carstens	stmg	%r8,%r9,__PT_PSW(%r11)
8014bfc86ceSHeiko Carstens	mvc	__PT_INT_CODE(12,%r11),__LC_SUBCHANNEL_ID
8024bfc86ceSHeiko Carstens	xc	__PT_FLAGS(8,%r11),__PT_FLAGS(%r11)
803db7e007fSHeiko Carstens	TSTMSK	__LC_CPU_FLAGS,_CIF_IGNORE_IRQ
804db7e007fSHeiko Carstens	jo	.Lio_restore
8054bfc86ceSHeiko Carstens	TRACE_IRQS_OFF
8064bfc86ceSHeiko Carstens	xc	__SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
8074bfc86ceSHeiko Carstens.Lio_loop:
8084bfc86ceSHeiko Carstens	lgr	%r2,%r11		# pass pointer to pt_regs
8094bfc86ceSHeiko Carstens	lghi	%r3,IO_INTERRUPT
8104bfc86ceSHeiko Carstens	tm	__PT_INT_CODE+8(%r11),0x80	# adapter interrupt ?
8114bfc86ceSHeiko Carstens	jz	.Lio_call
8124bfc86ceSHeiko Carstens	lghi	%r3,THIN_INTERRUPT
8134bfc86ceSHeiko Carstens.Lio_call:
8144bfc86ceSHeiko Carstens	brasl	%r14,do_IRQ
81583abeffbSHendrik Brueckner	TSTMSK	__LC_MACHINE_FLAGS,MACHINE_FLAG_LPAR
8164bfc86ceSHeiko Carstens	jz	.Lio_return
8174bfc86ceSHeiko Carstens	tpi	0
8184bfc86ceSHeiko Carstens	jz	.Lio_return
8194bfc86ceSHeiko Carstens	mvc	__PT_INT_CODE(12,%r11),__LC_SUBCHANNEL_ID
8204bfc86ceSHeiko Carstens	j	.Lio_loop
8214bfc86ceSHeiko Carstens.Lio_return:
8224bfc86ceSHeiko Carstens	LOCKDEP_SYS_EXIT
8234bfc86ceSHeiko Carstens	TRACE_IRQS_ON
8244bfc86ceSHeiko Carstens.Lio_tif:
82583abeffbSHendrik Brueckner	TSTMSK	__TI_flags(%r12),_TIF_WORK
8264bfc86ceSHeiko Carstens	jnz	.Lio_work		# there is work to do (signals etc.)
82783abeffbSHendrik Brueckner	TSTMSK	__LC_CPU_FLAGS,_CIF_WORK
8284bfc86ceSHeiko Carstens	jnz	.Lio_work
8294bfc86ceSHeiko Carstens.Lio_restore:
8304bfc86ceSHeiko Carstens	lg	%r14,__LC_VDSO_PER_CPU
8314bfc86ceSHeiko Carstens	lmg	%r0,%r10,__PT_R0(%r11)
8324bfc86ceSHeiko Carstens	mvc	__LC_RETURN_PSW(16),__PT_PSW(%r11)
833d768bd89SMartin Schwidefsky	tm	__PT_PSW+1(%r11),0x01	# returning to user ?
834d768bd89SMartin Schwidefsky	jno	.Lio_exit_kernel
8356b73044bSMartin Schwidefsky	BPEXIT	__TI_flags(%r12),_TIF_ISOLATE_BP
83607a63cbeSMartin Schwidefsky.Lio_exit_timer:
8374bfc86ceSHeiko Carstens	stpt	__LC_EXIT_TIMER
8384bfc86ceSHeiko Carstens	mvc	__VDSO_ECTG_BASE(16,%r14),__LC_EXIT_TIMER
839d768bd89SMartin Schwidefsky.Lio_exit_kernel:
8404bfc86ceSHeiko Carstens	lmg	%r11,%r15,__PT_R11(%r11)
8414bfc86ceSHeiko Carstens	lpswe	__LC_RETURN_PSW
8424bfc86ceSHeiko Carstens.Lio_done:
8434bfc86ceSHeiko Carstens
8444bfc86ceSHeiko Carstens#
8454bfc86ceSHeiko Carstens# There is work todo, find out in which context we have been interrupted:
8464bfc86ceSHeiko Carstens# 1) if we return to user space we can do all _TIF_WORK work
8474bfc86ceSHeiko Carstens# 2) if we return to kernel code and kvm is enabled check if we need to
8484bfc86ceSHeiko Carstens#    modify the psw to leave SIE
8494bfc86ceSHeiko Carstens# 3) if we return to kernel code and preemptive scheduling is enabled check
8504bfc86ceSHeiko Carstens#    the preemption counter and if it is zero call preempt_schedule_irq
8514bfc86ceSHeiko Carstens# Before any work can be done, a switch to the kernel stack is required.
8524bfc86ceSHeiko Carstens#
8534bfc86ceSHeiko Carstens.Lio_work:
8544bfc86ceSHeiko Carstens	tm	__PT_PSW+1(%r11),0x01	# returning to user ?
8554bfc86ceSHeiko Carstens	jo	.Lio_work_user		# yes -> do resched & signal
8564bfc86ceSHeiko Carstens#ifdef CONFIG_PREEMPT
8574bfc86ceSHeiko Carstens	# check for preemptive scheduling
858c360192bSMartin Schwidefsky	icm	%r0,15,__LC_PREEMPT_COUNT
8594bfc86ceSHeiko Carstens	jnz	.Lio_restore		# preemption is disabled
86083abeffbSHendrik Brueckner	TSTMSK	__TI_flags(%r12),_TIF_NEED_RESCHED
8614bfc86ceSHeiko Carstens	jno	.Lio_restore
8624bfc86ceSHeiko Carstens	# switch to kernel stack
8634bfc86ceSHeiko Carstens	lg	%r1,__PT_R15(%r11)
8644bfc86ceSHeiko Carstens	aghi	%r1,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
8654bfc86ceSHeiko Carstens	mvc	STACK_FRAME_OVERHEAD(__PT_SIZE,%r1),0(%r11)
8664bfc86ceSHeiko Carstens	xc	__SF_BACKCHAIN(8,%r1),__SF_BACKCHAIN(%r1)
8674bfc86ceSHeiko Carstens	la	%r11,STACK_FRAME_OVERHEAD(%r1)
8684bfc86ceSHeiko Carstens	lgr	%r15,%r1
8694bfc86ceSHeiko Carstens	# TRACE_IRQS_ON already done at .Lio_return, call
8704bfc86ceSHeiko Carstens	# TRACE_IRQS_OFF to keep things symmetrical
8714bfc86ceSHeiko Carstens	TRACE_IRQS_OFF
8724bfc86ceSHeiko Carstens	brasl	%r14,preempt_schedule_irq
8734bfc86ceSHeiko Carstens	j	.Lio_return
8744bfc86ceSHeiko Carstens#else
8754bfc86ceSHeiko Carstens	j	.Lio_restore
8764bfc86ceSHeiko Carstens#endif
8774bfc86ceSHeiko Carstens
8784bfc86ceSHeiko Carstens#
8794bfc86ceSHeiko Carstens# Need to do work before returning to userspace, switch to kernel stack
8804bfc86ceSHeiko Carstens#
8814bfc86ceSHeiko Carstens.Lio_work_user:
8824bfc86ceSHeiko Carstens	lg	%r1,__LC_KERNEL_STACK
8834bfc86ceSHeiko Carstens	mvc	STACK_FRAME_OVERHEAD(__PT_SIZE,%r1),0(%r11)
8844bfc86ceSHeiko Carstens	xc	__SF_BACKCHAIN(8,%r1),__SF_BACKCHAIN(%r1)
8854bfc86ceSHeiko Carstens	la	%r11,STACK_FRAME_OVERHEAD(%r1)
8864bfc86ceSHeiko Carstens	lgr	%r15,%r1
8874bfc86ceSHeiko Carstens
8884bfc86ceSHeiko Carstens#
8894bfc86ceSHeiko Carstens# One of the work bits is on. Find out which one.
8904bfc86ceSHeiko Carstens#
8914bfc86ceSHeiko Carstens.Lio_work_tif:
89283abeffbSHendrik Brueckner	TSTMSK	__LC_CPU_FLAGS,_CIF_MCCK_PENDING
8934bfc86ceSHeiko Carstens	jo	.Lio_mcck_pending
89483abeffbSHendrik Brueckner	TSTMSK	__TI_flags(%r12),_TIF_NEED_RESCHED
8954bfc86ceSHeiko Carstens	jo	.Lio_reschedule
8962f09ca60SMiroslav Benes#ifdef CONFIG_LIVEPATCH
8972f09ca60SMiroslav Benes	TSTMSK	__TI_flags(%r12),_TIF_PATCH_PENDING
8982f09ca60SMiroslav Benes	jo	.Lio_patch_pending
8992f09ca60SMiroslav Benes#endif
90083abeffbSHendrik Brueckner	TSTMSK	__TI_flags(%r12),_TIF_SIGPENDING
9014bfc86ceSHeiko Carstens	jo	.Lio_sigpending
90283abeffbSHendrik Brueckner	TSTMSK	__TI_flags(%r12),_TIF_NOTIFY_RESUME
9034bfc86ceSHeiko Carstens	jo	.Lio_notify_resume
904916cda1aSMartin Schwidefsky	TSTMSK	__TI_flags(%r12),_TIF_GUARDED_STORAGE
905916cda1aSMartin Schwidefsky	jo	.Lio_guarded_storage
90683abeffbSHendrik Brueckner	TSTMSK	__LC_CPU_FLAGS,_CIF_FPU
9079977e886SHendrik Brueckner	jo	.Lio_vxrs
908b5a882fcSHeiko Carstens	TSTMSK	__LC_CPU_FLAGS,(_CIF_ASCE_PRIMARY|_CIF_ASCE_SECONDARY)
909b5a882fcSHeiko Carstens	jnz	.Lio_asce
9104bfc86ceSHeiko Carstens	j	.Lio_return		# beware of critical section cleanup
9114bfc86ceSHeiko Carstens
9124bfc86ceSHeiko Carstens#
9134bfc86ceSHeiko Carstens# _CIF_MCCK_PENDING is set, call handler
9144bfc86ceSHeiko Carstens#
9154bfc86ceSHeiko Carstens.Lio_mcck_pending:
9164bfc86ceSHeiko Carstens	# TRACE_IRQS_ON already done at .Lio_return
9174bfc86ceSHeiko Carstens	brasl	%r14,s390_handle_mcck	# TIF bit will be cleared by handler
9184bfc86ceSHeiko Carstens	TRACE_IRQS_OFF
9194bfc86ceSHeiko Carstens	j	.Lio_return
9204bfc86ceSHeiko Carstens
9214bfc86ceSHeiko Carstens#
922b5a882fcSHeiko Carstens# _CIF_ASCE_PRIMARY and/or CIF_ASCE_SECONDARY set, load user space asce
9234bfc86ceSHeiko Carstens#
924b5a882fcSHeiko Carstens.Lio_asce:
9250aaba41bSMartin Schwidefsky	ni	__LC_CPU_FLAGS+7,255-_CIF_ASCE_SECONDARY
9260aaba41bSMartin Schwidefsky	lctlg	%c7,%c7,__LC_VDSO_ASCE		# load secondary asce
9270aaba41bSMartin Schwidefsky	TSTMSK	__LC_CPU_FLAGS,_CIF_ASCE_PRIMARY
9280aaba41bSMartin Schwidefsky	jz	.Lio_return
9290aaba41bSMartin Schwidefsky#ifndef CONFIG_HAVE_MARCH_Z10_FEATURES
9300aaba41bSMartin Schwidefsky	tm	__LC_STFLE_FAC_LIST+3,0x10	# has MVCOS ?
9310aaba41bSMartin Schwidefsky	jnz	.Lio_set_fs_fixup
932606aa4aaSHeiko Carstens	ni	__LC_CPU_FLAGS+7,255-_CIF_ASCE_PRIMARY
9334bfc86ceSHeiko Carstens	lctlg	%c1,%c1,__LC_USER_ASCE		# load primary asce
9340aaba41bSMartin Schwidefsky	j	.Lio_return
9350aaba41bSMartin Schwidefsky.Lio_set_fs_fixup:
9360aaba41bSMartin Schwidefsky#endif
937b5a882fcSHeiko Carstens	larl	%r14,.Lio_return
938b5a882fcSHeiko Carstens	jg	set_fs_fixup
9394bfc86ceSHeiko Carstens
9404bfc86ceSHeiko Carstens#
9419977e886SHendrik Brueckner# CIF_FPU is set, restore floating-point controls and floating-point registers.
9429977e886SHendrik Brueckner#
9439977e886SHendrik Brueckner.Lio_vxrs:
9449977e886SHendrik Brueckner	larl	%r14,.Lio_return
9459977e886SHendrik Brueckner	jg	load_fpu_regs
9469977e886SHendrik Brueckner
9479977e886SHendrik Brueckner#
948916cda1aSMartin Schwidefsky# _TIF_GUARDED_STORAGE is set, call guarded_storage_load
949916cda1aSMartin Schwidefsky#
950916cda1aSMartin Schwidefsky.Lio_guarded_storage:
951916cda1aSMartin Schwidefsky	# TRACE_IRQS_ON already done at .Lio_return
952916cda1aSMartin Schwidefsky	ssm	__LC_SVC_NEW_PSW	# reenable interrupts
953916cda1aSMartin Schwidefsky	lgr	%r2,%r11		# pass pointer to pt_regs
954916cda1aSMartin Schwidefsky	brasl	%r14,gs_load_bc_cb
955916cda1aSMartin Schwidefsky	ssm	__LC_PGM_NEW_PSW	# disable I/O and ext. interrupts
956916cda1aSMartin Schwidefsky	TRACE_IRQS_OFF
957916cda1aSMartin Schwidefsky	j	.Lio_return
958916cda1aSMartin Schwidefsky
959916cda1aSMartin Schwidefsky#
9604bfc86ceSHeiko Carstens# _TIF_NEED_RESCHED is set, call schedule
9614bfc86ceSHeiko Carstens#
9624bfc86ceSHeiko Carstens.Lio_reschedule:
9634bfc86ceSHeiko Carstens	# TRACE_IRQS_ON already done at .Lio_return
9644bfc86ceSHeiko Carstens	ssm	__LC_SVC_NEW_PSW	# reenable interrupts
9654bfc86ceSHeiko Carstens	brasl	%r14,schedule		# call scheduler
9664bfc86ceSHeiko Carstens	ssm	__LC_PGM_NEW_PSW	# disable I/O and ext. interrupts
9674bfc86ceSHeiko Carstens	TRACE_IRQS_OFF
9684bfc86ceSHeiko Carstens	j	.Lio_return
9694bfc86ceSHeiko Carstens
9704bfc86ceSHeiko Carstens#
9712f09ca60SMiroslav Benes# _TIF_PATCH_PENDING is set, call klp_update_patch_state
9722f09ca60SMiroslav Benes#
9732f09ca60SMiroslav Benes#ifdef CONFIG_LIVEPATCH
9742f09ca60SMiroslav Benes.Lio_patch_pending:
9752f09ca60SMiroslav Benes	lg	%r2,__LC_CURRENT	# pass pointer to task struct
9762f09ca60SMiroslav Benes	larl	%r14,.Lio_return
9772f09ca60SMiroslav Benes	jg	klp_update_patch_state
9782f09ca60SMiroslav Benes#endif
9792f09ca60SMiroslav Benes
9802f09ca60SMiroslav Benes#
9814bfc86ceSHeiko Carstens# _TIF_SIGPENDING or is set, call do_signal
9824bfc86ceSHeiko Carstens#
9834bfc86ceSHeiko Carstens.Lio_sigpending:
9844bfc86ceSHeiko Carstens	# TRACE_IRQS_ON already done at .Lio_return
9854bfc86ceSHeiko Carstens	ssm	__LC_SVC_NEW_PSW	# reenable interrupts
9864bfc86ceSHeiko Carstens	lgr	%r2,%r11		# pass pointer to pt_regs
9874bfc86ceSHeiko Carstens	brasl	%r14,do_signal
9884bfc86ceSHeiko Carstens	ssm	__LC_PGM_NEW_PSW	# disable I/O and ext. interrupts
9894bfc86ceSHeiko Carstens	TRACE_IRQS_OFF
9904bfc86ceSHeiko Carstens	j	.Lio_return
9914bfc86ceSHeiko Carstens
9924bfc86ceSHeiko Carstens#
9934bfc86ceSHeiko Carstens# _TIF_NOTIFY_RESUME or is set, call do_notify_resume
9944bfc86ceSHeiko Carstens#
9954bfc86ceSHeiko Carstens.Lio_notify_resume:
9964bfc86ceSHeiko Carstens	# TRACE_IRQS_ON already done at .Lio_return
9974bfc86ceSHeiko Carstens	ssm	__LC_SVC_NEW_PSW	# reenable interrupts
9984bfc86ceSHeiko Carstens	lgr	%r2,%r11		# pass pointer to pt_regs
9994bfc86ceSHeiko Carstens	brasl	%r14,do_notify_resume
10004bfc86ceSHeiko Carstens	ssm	__LC_PGM_NEW_PSW	# disable I/O and ext. interrupts
10014bfc86ceSHeiko Carstens	TRACE_IRQS_OFF
10024bfc86ceSHeiko Carstens	j	.Lio_return
10034bfc86ceSHeiko Carstens
10044bfc86ceSHeiko Carstens/*
10054bfc86ceSHeiko Carstens * External interrupt handler routine
10064bfc86ceSHeiko Carstens */
10074bfc86ceSHeiko CarstensENTRY(ext_int_handler)
10084bfc86ceSHeiko Carstens	STCK	__LC_INT_CLOCK
10094bfc86ceSHeiko Carstens	stpt	__LC_ASYNC_ENTER_TIMER
1010d768bd89SMartin Schwidefsky	BPOFF
10114bfc86ceSHeiko Carstens	stmg	%r8,%r15,__LC_SAVE_AREA_ASYNC
1012d5c352cdSHeiko Carstens	lg	%r12,__LC_CURRENT
10139977e886SHendrik Brueckner	larl	%r13,cleanup_critical
10144bfc86ceSHeiko Carstens	lmg	%r8,%r9,__LC_EXT_OLD_PSW
10152acb94f4SMartin Schwidefsky	SWITCH_ASYNC __LC_SAVE_AREA_ASYNC,__LC_ASYNC_ENTER_TIMER
10164bfc86ceSHeiko Carstens	stmg	%r0,%r7,__PT_R0(%r11)
10177041d281SMartin Schwidefsky	# clear user controlled registers to prevent speculative use
10187041d281SMartin Schwidefsky	xgr	%r0,%r0
10197041d281SMartin Schwidefsky	xgr	%r1,%r1
10207041d281SMartin Schwidefsky	xgr	%r2,%r2
10217041d281SMartin Schwidefsky	xgr	%r3,%r3
10227041d281SMartin Schwidefsky	xgr	%r4,%r4
10237041d281SMartin Schwidefsky	xgr	%r5,%r5
10247041d281SMartin Schwidefsky	xgr	%r6,%r6
10257041d281SMartin Schwidefsky	xgr	%r7,%r7
10267041d281SMartin Schwidefsky	xgr	%r10,%r10
10274bfc86ceSHeiko Carstens	mvc	__PT_R8(64,%r11),__LC_SAVE_AREA_ASYNC
10284bfc86ceSHeiko Carstens	stmg	%r8,%r9,__PT_PSW(%r11)
10294bfc86ceSHeiko Carstens	lghi	%r1,__LC_EXT_PARAMS2
10304bfc86ceSHeiko Carstens	mvc	__PT_INT_CODE(4,%r11),__LC_EXT_CPU_ADDR
10314bfc86ceSHeiko Carstens	mvc	__PT_INT_PARM(4,%r11),__LC_EXT_PARAMS
10324bfc86ceSHeiko Carstens	mvc	__PT_INT_PARM_LONG(8,%r11),0(%r1)
10334bfc86ceSHeiko Carstens	xc	__PT_FLAGS(8,%r11),__PT_FLAGS(%r11)
1034db7e007fSHeiko Carstens	TSTMSK	__LC_CPU_FLAGS,_CIF_IGNORE_IRQ
1035db7e007fSHeiko Carstens	jo	.Lio_restore
10364bfc86ceSHeiko Carstens	TRACE_IRQS_OFF
10374bfc86ceSHeiko Carstens	xc	__SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
10384bfc86ceSHeiko Carstens	lgr	%r2,%r11		# pass pointer to pt_regs
10394bfc86ceSHeiko Carstens	lghi	%r3,EXT_INTERRUPT
10404bfc86ceSHeiko Carstens	brasl	%r14,do_IRQ
10414bfc86ceSHeiko Carstens	j	.Lio_return
10424bfc86ceSHeiko Carstens
10434bfc86ceSHeiko Carstens/*
10444bfc86ceSHeiko Carstens * Load idle PSW. The second "half" of this function is in .Lcleanup_idle.
10454bfc86ceSHeiko Carstens */
10464bfc86ceSHeiko CarstensENTRY(psw_idle)
10474bfc86ceSHeiko Carstens	stg	%r3,__SF_EMPTY(%r15)
10484bfc86ceSHeiko Carstens	larl	%r1,.Lpsw_idle_lpsw+4
10494bfc86ceSHeiko Carstens	stg	%r1,__SF_EMPTY+8(%r15)
105072d38b19SMartin Schwidefsky#ifdef CONFIG_SMP
105172d38b19SMartin Schwidefsky	larl	%r1,smp_cpu_mtid
105272d38b19SMartin Schwidefsky	llgf	%r1,0(%r1)
105372d38b19SMartin Schwidefsky	ltgr	%r1,%r1
105472d38b19SMartin Schwidefsky	jz	.Lpsw_idle_stcctm
105572d38b19SMartin Schwidefsky	.insn	rsy,0xeb0000000017,%r1,5,__SF_EMPTY+16(%r15)
105672d38b19SMartin Schwidefsky.Lpsw_idle_stcctm:
105772d38b19SMartin Schwidefsky#endif
1058419123f9SMartin Schwidefsky	oi	__LC_CPU_FLAGS+7,_CIF_ENABLED_WAIT
1059d768bd89SMartin Schwidefsky	BPON
10604bfc86ceSHeiko Carstens	STCK	__CLOCK_IDLE_ENTER(%r2)
10614bfc86ceSHeiko Carstens	stpt	__TIMER_IDLE_ENTER(%r2)
10624bfc86ceSHeiko Carstens.Lpsw_idle_lpsw:
10634bfc86ceSHeiko Carstens	lpswe	__SF_EMPTY(%r15)
1064f19fbd5eSMartin Schwidefsky	BR_R1USE_R14
10654bfc86ceSHeiko Carstens.Lpsw_idle_end:
10664bfc86ceSHeiko Carstens
1067b5510d9bSHendrik Brueckner/*
1068b5510d9bSHendrik Brueckner * Store floating-point controls and floating-point or vector register
1069b5510d9bSHendrik Brueckner * depending whether the vector facility is available.	A critical section
1070b5510d9bSHendrik Brueckner * cleanup assures that the registers are stored even if interrupted for
1071b5510d9bSHendrik Brueckner * some other work.  The CIF_FPU flag is set to trigger a lazy restore
1072b5510d9bSHendrik Brueckner * of the register contents at return from io or a system call.
10739977e886SHendrik Brueckner */
10749977e886SHendrik BruecknerENTRY(save_fpu_regs)
1075d0164ee2SHendrik Brueckner	lg	%r2,__LC_CURRENT
1076d0164ee2SHendrik Brueckner	aghi	%r2,__TASK_thread
107783abeffbSHendrik Brueckner	TSTMSK	__LC_CPU_FLAGS,_CIF_FPU
1078f19fbd5eSMartin Schwidefsky	jo	.Lsave_fpu_regs_exit
1079d0164ee2SHendrik Brueckner	stfpc	__THREAD_FPU_fpc(%r2)
1080d0164ee2SHendrik Brueckner	lg	%r3,__THREAD_FPU_regs(%r2)
108183abeffbSHendrik Brueckner	TSTMSK	__LC_MACHINE_FLAGS,MACHINE_FLAG_VX
10829977e886SHendrik Brueckner	jz	.Lsave_fpu_regs_fp	  # no -> store FP regs
10839977e886SHendrik Brueckner	VSTM	%v0,%v15,0,%r3		  # vstm 0,15,0(3)
10849977e886SHendrik Brueckner	VSTM	%v16,%v31,256,%r3	  # vstm 16,31,256(3)
10859977e886SHendrik Brueckner	j	.Lsave_fpu_regs_done	  # -> set CIF_FPU flag
10869977e886SHendrik Brueckner.Lsave_fpu_regs_fp:
10879977e886SHendrik Brueckner	std	0,0(%r3)
10889977e886SHendrik Brueckner	std	1,8(%r3)
10899977e886SHendrik Brueckner	std	2,16(%r3)
10909977e886SHendrik Brueckner	std	3,24(%r3)
10919977e886SHendrik Brueckner	std	4,32(%r3)
10929977e886SHendrik Brueckner	std	5,40(%r3)
10939977e886SHendrik Brueckner	std	6,48(%r3)
10949977e886SHendrik Brueckner	std	7,56(%r3)
10959977e886SHendrik Brueckner	std	8,64(%r3)
10969977e886SHendrik Brueckner	std	9,72(%r3)
10979977e886SHendrik Brueckner	std	10,80(%r3)
10989977e886SHendrik Brueckner	std	11,88(%r3)
10999977e886SHendrik Brueckner	std	12,96(%r3)
11009977e886SHendrik Brueckner	std	13,104(%r3)
11019977e886SHendrik Brueckner	std	14,112(%r3)
11029977e886SHendrik Brueckner	std	15,120(%r3)
11039977e886SHendrik Brueckner.Lsave_fpu_regs_done:
11049977e886SHendrik Brueckner	oi	__LC_CPU_FLAGS+7,_CIF_FPU
1105f19fbd5eSMartin Schwidefsky.Lsave_fpu_regs_exit:
1106f19fbd5eSMartin Schwidefsky	BR_R1USE_R14
11079977e886SHendrik Brueckner.Lsave_fpu_regs_end:
1108711f5df7SAl ViroEXPORT_SYMBOL(save_fpu_regs)
11099977e886SHendrik Brueckner
1110b5510d9bSHendrik Brueckner/*
1111b5510d9bSHendrik Brueckner * Load floating-point controls and floating-point or vector registers.
1112b5510d9bSHendrik Brueckner * A critical section cleanup assures that the register contents are
1113b5510d9bSHendrik Brueckner * loaded even if interrupted for some other work.
11149977e886SHendrik Brueckner *
11159977e886SHendrik Brueckner * There are special calling conventions to fit into sysc and io return work:
11169977e886SHendrik Brueckner *	%r15:	<kernel stack>
11179977e886SHendrik Brueckner * The function requires:
1118b5510d9bSHendrik Brueckner *	%r4
11199977e886SHendrik Brueckner */
11209977e886SHendrik Bruecknerload_fpu_regs:
1121d0164ee2SHendrik Brueckner	lg	%r4,__LC_CURRENT
1122d0164ee2SHendrik Brueckner	aghi	%r4,__TASK_thread
112383abeffbSHendrik Brueckner	TSTMSK	__LC_CPU_FLAGS,_CIF_FPU
1124f19fbd5eSMartin Schwidefsky	jno	.Lload_fpu_regs_exit
1125d0164ee2SHendrik Brueckner	lfpc	__THREAD_FPU_fpc(%r4)
112683abeffbSHendrik Brueckner	TSTMSK	__LC_MACHINE_FLAGS,MACHINE_FLAG_VX
1127d0164ee2SHendrik Brueckner	lg	%r4,__THREAD_FPU_regs(%r4)	# %r4 <- reg save area
1128b5510d9bSHendrik Brueckner	jz	.Lload_fpu_regs_fp		# -> no VX, load FP regs
11299977e886SHendrik Brueckner	VLM	%v0,%v15,0,%r4
11309977e886SHendrik Brueckner	VLM	%v16,%v31,256,%r4
11319977e886SHendrik Brueckner	j	.Lload_fpu_regs_done
11329977e886SHendrik Brueckner.Lload_fpu_regs_fp:
11339977e886SHendrik Brueckner	ld	0,0(%r4)
11349977e886SHendrik Brueckner	ld	1,8(%r4)
11359977e886SHendrik Brueckner	ld	2,16(%r4)
11369977e886SHendrik Brueckner	ld	3,24(%r4)
11379977e886SHendrik Brueckner	ld	4,32(%r4)
11389977e886SHendrik Brueckner	ld	5,40(%r4)
11399977e886SHendrik Brueckner	ld	6,48(%r4)
11409977e886SHendrik Brueckner	ld	7,56(%r4)
11419977e886SHendrik Brueckner	ld	8,64(%r4)
11429977e886SHendrik Brueckner	ld	9,72(%r4)
11439977e886SHendrik Brueckner	ld	10,80(%r4)
11449977e886SHendrik Brueckner	ld	11,88(%r4)
11459977e886SHendrik Brueckner	ld	12,96(%r4)
11469977e886SHendrik Brueckner	ld	13,104(%r4)
11479977e886SHendrik Brueckner	ld	14,112(%r4)
11489977e886SHendrik Brueckner	ld	15,120(%r4)
11499977e886SHendrik Brueckner.Lload_fpu_regs_done:
11509977e886SHendrik Brueckner	ni	__LC_CPU_FLAGS+7,255-_CIF_FPU
1151f19fbd5eSMartin Schwidefsky.Lload_fpu_regs_exit:
1152f19fbd5eSMartin Schwidefsky	BR_R1USE_R14
11539977e886SHendrik Brueckner.Lload_fpu_regs_end:
11549977e886SHendrik Brueckner
11554bfc86ceSHeiko Carstens.L__critical_end:
11564bfc86ceSHeiko Carstens
11574bfc86ceSHeiko Carstens/*
11584bfc86ceSHeiko Carstens * Machine check handler routines
11594bfc86ceSHeiko Carstens */
11604bfc86ceSHeiko CarstensENTRY(mcck_int_handler)
11614bfc86ceSHeiko Carstens	STCK	__LC_MCCK_CLOCK
1162d768bd89SMartin Schwidefsky	BPOFF
11633037a52fSMartin Schwidefsky	la	%r1,4095		# validate r1
11643037a52fSMartin Schwidefsky	spt	__LC_CPU_TIMER_SAVE_AREA-4095(%r1)	# validate cpu timer
11653037a52fSMartin Schwidefsky	sckc	__LC_CLOCK_COMPARATOR			# validate comparator
11663037a52fSMartin Schwidefsky	lam	%a0,%a15,__LC_AREGS_SAVE_AREA-4095(%r1) # validate acrs
11673037a52fSMartin Schwidefsky	lmg	%r0,%r15,__LC_GPREGS_SAVE_AREA-4095(%r1)# validate gprs
1168d5c352cdSHeiko Carstens	lg	%r12,__LC_CURRENT
11699977e886SHendrik Brueckner	larl	%r13,cleanup_critical
11704bfc86ceSHeiko Carstens	lmg	%r8,%r9,__LC_MCK_OLD_PSW
117183abeffbSHendrik Brueckner	TSTMSK	__LC_MCCK_CODE,MCCK_CODE_SYSTEM_DAMAGE
11724bfc86ceSHeiko Carstens	jo	.Lmcck_panic		# yes -> rest of mcck code invalid
11733037a52fSMartin Schwidefsky	TSTMSK	__LC_MCCK_CODE,MCCK_CODE_CR_VALID
11743037a52fSMartin Schwidefsky	jno	.Lmcck_panic		# control registers invalid -> panic
11753037a52fSMartin Schwidefsky	la	%r14,4095
11763037a52fSMartin Schwidefsky	lctlg	%c0,%c15,__LC_CREGS_SAVE_AREA-4095(%r14) # validate ctl regs
11773037a52fSMartin Schwidefsky	ptlb
11782a2d7befSVasily Gorbik	lg	%r11,__LC_MCESAD-4095(%r14) # extended machine check save area
11793037a52fSMartin Schwidefsky	nill	%r11,0xfc00		# MCESA_ORIGIN_MASK
11803037a52fSMartin Schwidefsky	TSTMSK	__LC_CREGS_SAVE_AREA+16-4095(%r14),CR2_GUARDED_STORAGE
11813037a52fSMartin Schwidefsky	jno	0f
11823037a52fSMartin Schwidefsky	TSTMSK	__LC_MCCK_CODE,MCCK_CODE_GS_VALID
11833037a52fSMartin Schwidefsky	jno	0f
11843037a52fSMartin Schwidefsky	.insn	 rxy,0xe3000000004d,0,__MCESA_GS_SAVE_AREA(%r11) # LGSC
11853037a52fSMartin Schwidefsky0:	l	%r14,__LC_FP_CREG_SAVE_AREA-4095(%r14)
11863037a52fSMartin Schwidefsky	TSTMSK	__LC_MCCK_CODE,MCCK_CODE_FC_VALID
11873037a52fSMartin Schwidefsky	jo	0f
11883037a52fSMartin Schwidefsky	sr	%r14,%r14
11893037a52fSMartin Schwidefsky0:	sfpc	%r14
11903037a52fSMartin Schwidefsky	TSTMSK	__LC_MACHINE_FLAGS,MACHINE_FLAG_VX
11913037a52fSMartin Schwidefsky	jo	0f
11923037a52fSMartin Schwidefsky	lghi	%r14,__LC_FPREGS_SAVE_AREA
11933037a52fSMartin Schwidefsky	ld	%f0,0(%r14)
11943037a52fSMartin Schwidefsky	ld	%f1,8(%r14)
11953037a52fSMartin Schwidefsky	ld	%f2,16(%r14)
11963037a52fSMartin Schwidefsky	ld	%f3,24(%r14)
11973037a52fSMartin Schwidefsky	ld	%f4,32(%r14)
11983037a52fSMartin Schwidefsky	ld	%f5,40(%r14)
11993037a52fSMartin Schwidefsky	ld	%f6,48(%r14)
12003037a52fSMartin Schwidefsky	ld	%f7,56(%r14)
12013037a52fSMartin Schwidefsky	ld	%f8,64(%r14)
12023037a52fSMartin Schwidefsky	ld	%f9,72(%r14)
12033037a52fSMartin Schwidefsky	ld	%f10,80(%r14)
12043037a52fSMartin Schwidefsky	ld	%f11,88(%r14)
12053037a52fSMartin Schwidefsky	ld	%f12,96(%r14)
12063037a52fSMartin Schwidefsky	ld	%f13,104(%r14)
12073037a52fSMartin Schwidefsky	ld	%f14,112(%r14)
12083037a52fSMartin Schwidefsky	ld	%f15,120(%r14)
12093037a52fSMartin Schwidefsky	j	1f
12103037a52fSMartin Schwidefsky0:	VLM	%v0,%v15,0,%r11
12113037a52fSMartin Schwidefsky	VLM	%v16,%v31,256,%r11
12123037a52fSMartin Schwidefsky1:	lghi	%r14,__LC_CPU_TIMER_SAVE_AREA
12134bfc86ceSHeiko Carstens	mvc	__LC_MCCK_ENTER_TIMER(8),0(%r14)
121483abeffbSHendrik Brueckner	TSTMSK	__LC_MCCK_CODE,MCCK_CODE_CPU_TIMER_VALID
12154bfc86ceSHeiko Carstens	jo	3f
12164bfc86ceSHeiko Carstens	la	%r14,__LC_SYNC_ENTER_TIMER
12174bfc86ceSHeiko Carstens	clc	0(8,%r14),__LC_ASYNC_ENTER_TIMER
12184bfc86ceSHeiko Carstens	jl	0f
12194bfc86ceSHeiko Carstens	la	%r14,__LC_ASYNC_ENTER_TIMER
12204bfc86ceSHeiko Carstens0:	clc	0(8,%r14),__LC_EXIT_TIMER
12214bfc86ceSHeiko Carstens	jl	1f
12224bfc86ceSHeiko Carstens	la	%r14,__LC_EXIT_TIMER
12234bfc86ceSHeiko Carstens1:	clc	0(8,%r14),__LC_LAST_UPDATE_TIMER
12244bfc86ceSHeiko Carstens	jl	2f
12254bfc86ceSHeiko Carstens	la	%r14,__LC_LAST_UPDATE_TIMER
12264bfc86ceSHeiko Carstens2:	spt	0(%r14)
12274bfc86ceSHeiko Carstens	mvc	__LC_MCCK_ENTER_TIMER(8),0(%r14)
12283037a52fSMartin Schwidefsky3:	TSTMSK	__LC_MCCK_CODE,MCCK_CODE_PSW_MWP_VALID
12293037a52fSMartin Schwidefsky	jno	.Lmcck_panic
12303037a52fSMartin Schwidefsky	tmhh	%r8,0x0001		# interrupting from user ?
12313037a52fSMartin Schwidefsky	jnz	4f
12323037a52fSMartin Schwidefsky	TSTMSK	__LC_MCCK_CODE,MCCK_CODE_PSW_IA_VALID
12333037a52fSMartin Schwidefsky	jno	.Lmcck_panic
12343037a52fSMartin Schwidefsky4:	SWITCH_ASYNC __LC_GPREGS_SAVE_AREA+64,__LC_MCCK_ENTER_TIMER
12354bfc86ceSHeiko Carstens.Lmcck_skip:
12364bfc86ceSHeiko Carstens	lghi	%r14,__LC_GPREGS_SAVE_AREA+64
12374bfc86ceSHeiko Carstens	stmg	%r0,%r7,__PT_R0(%r11)
12387041d281SMartin Schwidefsky	# clear user controlled registers to prevent speculative use
12397041d281SMartin Schwidefsky	xgr	%r0,%r0
12407041d281SMartin Schwidefsky	xgr	%r1,%r1
12417041d281SMartin Schwidefsky	xgr	%r2,%r2
12427041d281SMartin Schwidefsky	xgr	%r3,%r3
12437041d281SMartin Schwidefsky	xgr	%r4,%r4
12447041d281SMartin Schwidefsky	xgr	%r5,%r5
12457041d281SMartin Schwidefsky	xgr	%r6,%r6
12467041d281SMartin Schwidefsky	xgr	%r7,%r7
12477041d281SMartin Schwidefsky	xgr	%r10,%r10
12484bfc86ceSHeiko Carstens	mvc	__PT_R8(64,%r11),0(%r14)
12494bfc86ceSHeiko Carstens	stmg	%r8,%r9,__PT_PSW(%r11)
12504bfc86ceSHeiko Carstens	xc	__PT_FLAGS(8,%r11),__PT_FLAGS(%r11)
12514bfc86ceSHeiko Carstens	xc	__SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
12524bfc86ceSHeiko Carstens	lgr	%r2,%r11		# pass pointer to pt_regs
12534bfc86ceSHeiko Carstens	brasl	%r14,s390_do_machine_check
12544bfc86ceSHeiko Carstens	tm	__PT_PSW+1(%r11),0x01	# returning to user ?
12554bfc86ceSHeiko Carstens	jno	.Lmcck_return
12564bfc86ceSHeiko Carstens	lg	%r1,__LC_KERNEL_STACK	# switch to kernel stack
12574bfc86ceSHeiko Carstens	mvc	STACK_FRAME_OVERHEAD(__PT_SIZE,%r1),0(%r11)
12584bfc86ceSHeiko Carstens	xc	__SF_BACKCHAIN(8,%r1),__SF_BACKCHAIN(%r1)
12594bfc86ceSHeiko Carstens	la	%r11,STACK_FRAME_OVERHEAD(%r1)
12604bfc86ceSHeiko Carstens	lgr	%r15,%r1
12614bfc86ceSHeiko Carstens	ssm	__LC_PGM_NEW_PSW	# turn dat on, keep irqs off
126283abeffbSHendrik Brueckner	TSTMSK	__LC_CPU_FLAGS,_CIF_MCCK_PENDING
12634bfc86ceSHeiko Carstens	jno	.Lmcck_return
12644bfc86ceSHeiko Carstens	TRACE_IRQS_OFF
12654bfc86ceSHeiko Carstens	brasl	%r14,s390_handle_mcck
12664bfc86ceSHeiko Carstens	TRACE_IRQS_ON
12674bfc86ceSHeiko Carstens.Lmcck_return:
12684bfc86ceSHeiko Carstens	lg	%r14,__LC_VDSO_PER_CPU
12694bfc86ceSHeiko Carstens	lmg	%r0,%r10,__PT_R0(%r11)
12704bfc86ceSHeiko Carstens	mvc	__LC_RETURN_MCCK_PSW(16),__PT_PSW(%r11) # move return PSW
12714bfc86ceSHeiko Carstens	tm	__LC_RETURN_MCCK_PSW+1,0x01 # returning to user ?
12724bfc86ceSHeiko Carstens	jno	0f
12736b73044bSMartin Schwidefsky	BPEXIT	__TI_flags(%r12),_TIF_ISOLATE_BP
12744bfc86ceSHeiko Carstens	stpt	__LC_EXIT_TIMER
12754bfc86ceSHeiko Carstens	mvc	__VDSO_ECTG_BASE(16,%r14),__LC_EXIT_TIMER
12764bfc86ceSHeiko Carstens0:	lmg	%r11,%r15,__PT_R11(%r11)
12774bfc86ceSHeiko Carstens	lpswe	__LC_RETURN_MCCK_PSW
12784bfc86ceSHeiko Carstens
12794bfc86ceSHeiko Carstens.Lmcck_panic:
12804bfc86ceSHeiko Carstens	lg	%r15,__LC_PANIC_STACK
1281ce4dda3fSMartin Schwidefsky	la	%r11,STACK_FRAME_OVERHEAD(%r15)
12824bfc86ceSHeiko Carstens	j	.Lmcck_skip
12834bfc86ceSHeiko Carstens
12844bfc86ceSHeiko Carstens#
12854bfc86ceSHeiko Carstens# PSW restart interrupt handler
12864bfc86ceSHeiko Carstens#
12874bfc86ceSHeiko CarstensENTRY(restart_int_handler)
1288e22cf8caSChristian Borntraeger	TSTMSK	__LC_MACHINE_FLAGS,MACHINE_FLAG_LPP
1289e22cf8caSChristian Borntraeger	jz	0f
1290e22cf8caSChristian Borntraeger	.insn	s,0xb2800000,__LC_LPP
1291e22cf8caSChristian Borntraeger0:	stg	%r15,__LC_SAVE_AREA_RESTART
12924bfc86ceSHeiko Carstens	lg	%r15,__LC_RESTART_STACK
12934bfc86ceSHeiko Carstens	aghi	%r15,-__PT_SIZE			# create pt_regs on stack
12944bfc86ceSHeiko Carstens	xc	0(__PT_SIZE,%r15),0(%r15)
12954bfc86ceSHeiko Carstens	stmg	%r0,%r14,__PT_R0(%r15)
12964bfc86ceSHeiko Carstens	mvc	__PT_R15(8,%r15),__LC_SAVE_AREA_RESTART
12974bfc86ceSHeiko Carstens	mvc	__PT_PSW(16,%r15),__LC_RST_OLD_PSW # store restart old psw
12984bfc86ceSHeiko Carstens	aghi	%r15,-STACK_FRAME_OVERHEAD	# create stack frame on stack
12994bfc86ceSHeiko Carstens	xc	0(STACK_FRAME_OVERHEAD,%r15),0(%r15)
13004bfc86ceSHeiko Carstens	lg	%r1,__LC_RESTART_FN		# load fn, parm & source cpu
13014bfc86ceSHeiko Carstens	lg	%r2,__LC_RESTART_DATA
13024bfc86ceSHeiko Carstens	lg	%r3,__LC_RESTART_SOURCE
13034bfc86ceSHeiko Carstens	ltgr	%r3,%r3				# test source cpu address
13044bfc86ceSHeiko Carstens	jm	1f				# negative -> skip source stop
13054bfc86ceSHeiko Carstens0:	sigp	%r4,%r3,SIGP_SENSE		# sigp sense to source cpu
13064bfc86ceSHeiko Carstens	brc	10,0b				# wait for status stored
13074bfc86ceSHeiko Carstens1:	basr	%r14,%r1			# call function
13084bfc86ceSHeiko Carstens	stap	__SF_EMPTY(%r15)		# store cpu address
13094bfc86ceSHeiko Carstens	llgh	%r3,__SF_EMPTY(%r15)
13104bfc86ceSHeiko Carstens2:	sigp	%r4,%r3,SIGP_STOP		# sigp stop to current cpu
13114bfc86ceSHeiko Carstens	brc	2,2b
13124bfc86ceSHeiko Carstens3:	j	3b
13134bfc86ceSHeiko Carstens
13144bfc86ceSHeiko Carstens	.section .kprobes.text, "ax"
13154bfc86ceSHeiko Carstens
13164bfc86ceSHeiko Carstens#ifdef CONFIG_CHECK_STACK
13174bfc86ceSHeiko Carstens/*
13184bfc86ceSHeiko Carstens * The synchronous or the asynchronous stack overflowed. We are dead.
13194bfc86ceSHeiko Carstens * No need to properly save the registers, we are going to panic anyway.
13204bfc86ceSHeiko Carstens * Setup a pt_regs so that show_trace can provide a good call trace.
13214bfc86ceSHeiko Carstens */
13224bfc86ceSHeiko Carstensstack_overflow:
13234bfc86ceSHeiko Carstens	lg	%r15,__LC_PANIC_STACK	# change to panic stack
13244bfc86ceSHeiko Carstens	la	%r11,STACK_FRAME_OVERHEAD(%r15)
13254bfc86ceSHeiko Carstens	stmg	%r0,%r7,__PT_R0(%r11)
13264bfc86ceSHeiko Carstens	stmg	%r8,%r9,__PT_PSW(%r11)
13274bfc86ceSHeiko Carstens	mvc	__PT_R8(64,%r11),0(%r14)
13284bfc86ceSHeiko Carstens	stg	%r10,__PT_ORIG_GPR2(%r11) # store last break to orig_gpr2
13294bfc86ceSHeiko Carstens	xc	__SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
13304bfc86ceSHeiko Carstens	lgr	%r2,%r11		# pass pointer to pt_regs
13314bfc86ceSHeiko Carstens	jg	kernel_stack_overflow
13324bfc86ceSHeiko Carstens#endif
13334bfc86ceSHeiko Carstens
13344bfc86ceSHeiko Carstenscleanup_critical:
1335d0fc4107SMartin Schwidefsky#if IS_ENABLED(CONFIG_KVM)
1336d0fc4107SMartin Schwidefsky	clg	%r9,BASED(.Lcleanup_table_sie)	# .Lsie_gmap
1337d0fc4107SMartin Schwidefsky	jl	0f
1338d0fc4107SMartin Schwidefsky	clg	%r9,BASED(.Lcleanup_table_sie+8)# .Lsie_done
1339d0fc4107SMartin Schwidefsky	jl	.Lcleanup_sie
1340d0fc4107SMartin Schwidefsky#endif
13414bfc86ceSHeiko Carstens	clg	%r9,BASED(.Lcleanup_table)	# system_call
13424bfc86ceSHeiko Carstens	jl	0f
13434bfc86ceSHeiko Carstens	clg	%r9,BASED(.Lcleanup_table+8)	# .Lsysc_do_svc
13444bfc86ceSHeiko Carstens	jl	.Lcleanup_system_call
13454bfc86ceSHeiko Carstens	clg	%r9,BASED(.Lcleanup_table+16)	# .Lsysc_tif
13464bfc86ceSHeiko Carstens	jl	0f
13474bfc86ceSHeiko Carstens	clg	%r9,BASED(.Lcleanup_table+24)	# .Lsysc_restore
13484bfc86ceSHeiko Carstens	jl	.Lcleanup_sysc_tif
13494bfc86ceSHeiko Carstens	clg	%r9,BASED(.Lcleanup_table+32)	# .Lsysc_done
13504bfc86ceSHeiko Carstens	jl	.Lcleanup_sysc_restore
13514bfc86ceSHeiko Carstens	clg	%r9,BASED(.Lcleanup_table+40)	# .Lio_tif
13524bfc86ceSHeiko Carstens	jl	0f
13534bfc86ceSHeiko Carstens	clg	%r9,BASED(.Lcleanup_table+48)	# .Lio_restore
13544bfc86ceSHeiko Carstens	jl	.Lcleanup_io_tif
13554bfc86ceSHeiko Carstens	clg	%r9,BASED(.Lcleanup_table+56)	# .Lio_done
13564bfc86ceSHeiko Carstens	jl	.Lcleanup_io_restore
13574bfc86ceSHeiko Carstens	clg	%r9,BASED(.Lcleanup_table+64)	# psw_idle
13584bfc86ceSHeiko Carstens	jl	0f
13594bfc86ceSHeiko Carstens	clg	%r9,BASED(.Lcleanup_table+72)	# .Lpsw_idle_end
13604bfc86ceSHeiko Carstens	jl	.Lcleanup_idle
13619977e886SHendrik Brueckner	clg	%r9,BASED(.Lcleanup_table+80)	# save_fpu_regs
13629977e886SHendrik Brueckner	jl	0f
13639977e886SHendrik Brueckner	clg	%r9,BASED(.Lcleanup_table+88)	# .Lsave_fpu_regs_end
13649977e886SHendrik Brueckner	jl	.Lcleanup_save_fpu_regs
13659977e886SHendrik Brueckner	clg	%r9,BASED(.Lcleanup_table+96)	# load_fpu_regs
13669977e886SHendrik Brueckner	jl	0f
13679977e886SHendrik Brueckner	clg	%r9,BASED(.Lcleanup_table+104)	# .Lload_fpu_regs_end
13689977e886SHendrik Brueckner	jl	.Lcleanup_load_fpu_regs
1369f19fbd5eSMartin Schwidefsky0:	BR_R11USE_R14
13704bfc86ceSHeiko Carstens
1371d0fc4107SMartin Schwidefsky	.align	8
1372d0fc4107SMartin Schwidefsky.Lcleanup_table:
1373d0fc4107SMartin Schwidefsky	.quad	system_call
1374d0fc4107SMartin Schwidefsky	.quad	.Lsysc_do_svc
1375d0fc4107SMartin Schwidefsky	.quad	.Lsysc_tif
1376d0fc4107SMartin Schwidefsky	.quad	.Lsysc_restore
1377d0fc4107SMartin Schwidefsky	.quad	.Lsysc_done
1378d0fc4107SMartin Schwidefsky	.quad	.Lio_tif
1379d0fc4107SMartin Schwidefsky	.quad	.Lio_restore
1380d0fc4107SMartin Schwidefsky	.quad	.Lio_done
1381d0fc4107SMartin Schwidefsky	.quad	psw_idle
1382d0fc4107SMartin Schwidefsky	.quad	.Lpsw_idle_end
1383d0fc4107SMartin Schwidefsky	.quad	save_fpu_regs
1384d0fc4107SMartin Schwidefsky	.quad	.Lsave_fpu_regs_end
1385d0fc4107SMartin Schwidefsky	.quad	load_fpu_regs
1386d0fc4107SMartin Schwidefsky	.quad	.Lload_fpu_regs_end
1387d0fc4107SMartin Schwidefsky
1388d0fc4107SMartin Schwidefsky#if IS_ENABLED(CONFIG_KVM)
1389d0fc4107SMartin Schwidefsky.Lcleanup_table_sie:
1390d0fc4107SMartin Schwidefsky	.quad	.Lsie_gmap
1391d0fc4107SMartin Schwidefsky	.quad	.Lsie_done
1392d0fc4107SMartin Schwidefsky
1393d0fc4107SMartin Schwidefsky.Lcleanup_sie:
1394c929500dSQingFeng Hao	cghi    %r11,__LC_SAVE_AREA_ASYNC 	#Is this in normal interrupt?
1395c929500dSQingFeng Hao	je      1f
1396c929500dSQingFeng Hao	slg     %r9,BASED(.Lsie_crit_mcck_start)
1397c929500dSQingFeng Hao	clg     %r9,BASED(.Lsie_crit_mcck_length)
1398c929500dSQingFeng Hao	jh      1f
1399c929500dSQingFeng Hao	oi      __LC_CPU_FLAGS+7, _CIF_MCCK_GUEST
14006b73044bSMartin Schwidefsky1:	BPENTER __SF_EMPTY+24(%r15),(_TIF_ISOLATE_BP|_TIF_ISOLATE_BP_GUEST)
14016b73044bSMartin Schwidefsky	lg	%r9,__SF_EMPTY(%r15)		# get control block pointer
1402e22cf8caSChristian Borntraeger	ni	__SIE_PROG0C+3(%r9),0xfe	# no longer in SIE
1403d0fc4107SMartin Schwidefsky	lctlg	%c1,%c1,__LC_USER_ASCE		# load primary asce
1404d0fc4107SMartin Schwidefsky	larl	%r9,sie_exit			# skip forward to sie_exit
1405f19fbd5eSMartin Schwidefsky	BR_R11USE_R14
1406d0fc4107SMartin Schwidefsky#endif
14074bfc86ceSHeiko Carstens
14084bfc86ceSHeiko Carstens.Lcleanup_system_call:
14094bfc86ceSHeiko Carstens	# check if stpt has been executed
14104bfc86ceSHeiko Carstens	clg	%r9,BASED(.Lcleanup_system_call_insn)
14114bfc86ceSHeiko Carstens	jh	0f
14124bfc86ceSHeiko Carstens	mvc	__LC_SYNC_ENTER_TIMER(8),__LC_ASYNC_ENTER_TIMER
14134bfc86ceSHeiko Carstens	cghi	%r11,__LC_SAVE_AREA_ASYNC
14144bfc86ceSHeiko Carstens	je	0f
14154bfc86ceSHeiko Carstens	mvc	__LC_SYNC_ENTER_TIMER(8),__LC_MCCK_ENTER_TIMER
14164bfc86ceSHeiko Carstens0:	# check if stmg has been executed
14174bfc86ceSHeiko Carstens	clg	%r9,BASED(.Lcleanup_system_call_insn+8)
14184bfc86ceSHeiko Carstens	jh	0f
14194bfc86ceSHeiko Carstens	mvc	__LC_SAVE_AREA_SYNC(64),0(%r11)
14204bfc86ceSHeiko Carstens0:	# check if base register setup + TIF bit load has been done
14214bfc86ceSHeiko Carstens	clg	%r9,BASED(.Lcleanup_system_call_insn+16)
14224bfc86ceSHeiko Carstens	jhe	0f
142334525e1fSMartin Schwidefsky	# set up saved register r12 task struct pointer
142434525e1fSMartin Schwidefsky	stg	%r12,32(%r11)
142534525e1fSMartin Schwidefsky	# set up saved register r13 __TASK_thread offset
142634525e1fSMartin Schwidefsky	mvc	40(8,%r11),BASED(.Lcleanup_system_call_const)
14274bfc86ceSHeiko Carstens0:	# check if the user time update has been done
14284bfc86ceSHeiko Carstens	clg	%r9,BASED(.Lcleanup_system_call_insn+24)
14294bfc86ceSHeiko Carstens	jh	0f
14304bfc86ceSHeiko Carstens	lg	%r15,__LC_EXIT_TIMER
14314bfc86ceSHeiko Carstens	slg	%r15,__LC_SYNC_ENTER_TIMER
14324bfc86ceSHeiko Carstens	alg	%r15,__LC_USER_TIMER
14334bfc86ceSHeiko Carstens	stg	%r15,__LC_USER_TIMER
14344bfc86ceSHeiko Carstens0:	# check if the system time update has been done
14354bfc86ceSHeiko Carstens	clg	%r9,BASED(.Lcleanup_system_call_insn+32)
14364bfc86ceSHeiko Carstens	jh	0f
14374bfc86ceSHeiko Carstens	lg	%r15,__LC_LAST_UPDATE_TIMER
14384bfc86ceSHeiko Carstens	slg	%r15,__LC_EXIT_TIMER
14394bfc86ceSHeiko Carstens	alg	%r15,__LC_SYSTEM_TIMER
14404bfc86ceSHeiko Carstens	stg	%r15,__LC_SYSTEM_TIMER
14414bfc86ceSHeiko Carstens0:	# update accounting time stamp
14424bfc86ceSHeiko Carstens	mvc	__LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
1443d5feec04SMartin Schwidefsky	BPENTER __TI_flags(%r12),_TIF_ISOLATE_BP
144434525e1fSMartin Schwidefsky	# set up saved register r11
14454bfc86ceSHeiko Carstens	lg	%r15,__LC_KERNEL_STACK
14464bfc86ceSHeiko Carstens	la	%r9,STACK_FRAME_OVERHEAD(%r15)
14474bfc86ceSHeiko Carstens	stg	%r9,24(%r11)		# r11 pt_regs pointer
14484bfc86ceSHeiko Carstens	# fill pt_regs
14494bfc86ceSHeiko Carstens	mvc	__PT_R8(64,%r9),__LC_SAVE_AREA_SYNC
14504bfc86ceSHeiko Carstens	stmg	%r0,%r7,__PT_R0(%r9)
14514bfc86ceSHeiko Carstens	mvc	__PT_PSW(16,%r9),__LC_SVC_OLD_PSW
14524bfc86ceSHeiko Carstens	mvc	__PT_INT_CODE(4,%r9),__LC_SVC_ILC
14534bfc86ceSHeiko Carstens	xc	__PT_FLAGS(8,%r9),__PT_FLAGS(%r9)
14544bfc86ceSHeiko Carstens	mvi	__PT_FLAGS+7(%r9),_PIF_SYSCALL
14554bfc86ceSHeiko Carstens	# setup saved register r15
14564bfc86ceSHeiko Carstens	stg	%r15,56(%r11)		# r15 stack pointer
14574bfc86ceSHeiko Carstens	# set new psw address and exit
14584bfc86ceSHeiko Carstens	larl	%r9,.Lsysc_do_svc
1459f19fbd5eSMartin Schwidefsky	BR_R11USE_R14
14604bfc86ceSHeiko Carstens.Lcleanup_system_call_insn:
14614bfc86ceSHeiko Carstens	.quad	system_call
14624bfc86ceSHeiko Carstens	.quad	.Lsysc_stmg
14634bfc86ceSHeiko Carstens	.quad	.Lsysc_per
1464a359bb11SMartin Schwidefsky	.quad	.Lsysc_vtime+36
14654bfc86ceSHeiko Carstens	.quad	.Lsysc_vtime+42
146634525e1fSMartin Schwidefsky.Lcleanup_system_call_const:
146734525e1fSMartin Schwidefsky	.quad	__TASK_thread
14684bfc86ceSHeiko Carstens
14694bfc86ceSHeiko Carstens.Lcleanup_sysc_tif:
14704bfc86ceSHeiko Carstens	larl	%r9,.Lsysc_tif
1471f19fbd5eSMartin Schwidefsky	BR_R11USE_R14
14724bfc86ceSHeiko Carstens
14734bfc86ceSHeiko Carstens.Lcleanup_sysc_restore:
147407a63cbeSMartin Schwidefsky	# check if stpt has been executed
14754bfc86ceSHeiko Carstens	clg	%r9,BASED(.Lcleanup_sysc_restore_insn)
147607a63cbeSMartin Schwidefsky	jh	0f
147707a63cbeSMartin Schwidefsky	mvc	__LC_EXIT_TIMER(8),__LC_ASYNC_ENTER_TIMER
147807a63cbeSMartin Schwidefsky	cghi	%r11,__LC_SAVE_AREA_ASYNC
14794bfc86ceSHeiko Carstens	je	0f
148007a63cbeSMartin Schwidefsky	mvc	__LC_EXIT_TIMER(8),__LC_MCCK_ENTER_TIMER
148107a63cbeSMartin Schwidefsky0:	clg	%r9,BASED(.Lcleanup_sysc_restore_insn+8)
148207a63cbeSMartin Schwidefsky	je	1f
14834bfc86ceSHeiko Carstens	lg	%r9,24(%r11)		# get saved pointer to pt_regs
14844bfc86ceSHeiko Carstens	mvc	__LC_RETURN_PSW(16),__PT_PSW(%r9)
14854bfc86ceSHeiko Carstens	mvc	0(64,%r11),__PT_R8(%r9)
14864bfc86ceSHeiko Carstens	lmg	%r0,%r7,__PT_R0(%r9)
148707a63cbeSMartin Schwidefsky1:	lmg	%r8,%r9,__LC_RETURN_PSW
1488f19fbd5eSMartin Schwidefsky	BR_R11USE_R14
14894bfc86ceSHeiko Carstens.Lcleanup_sysc_restore_insn:
149007a63cbeSMartin Schwidefsky	.quad	.Lsysc_exit_timer
14914bfc86ceSHeiko Carstens	.quad	.Lsysc_done - 4
14924bfc86ceSHeiko Carstens
14934bfc86ceSHeiko Carstens.Lcleanup_io_tif:
14944bfc86ceSHeiko Carstens	larl	%r9,.Lio_tif
1495f19fbd5eSMartin Schwidefsky	BR_R11USE_R14
14964bfc86ceSHeiko Carstens
14974bfc86ceSHeiko Carstens.Lcleanup_io_restore:
149807a63cbeSMartin Schwidefsky	# check if stpt has been executed
14994bfc86ceSHeiko Carstens	clg	%r9,BASED(.Lcleanup_io_restore_insn)
150007a63cbeSMartin Schwidefsky	jh	0f
150107a63cbeSMartin Schwidefsky	mvc	__LC_EXIT_TIMER(8),__LC_MCCK_ENTER_TIMER
150207a63cbeSMartin Schwidefsky0:	clg	%r9,BASED(.Lcleanup_io_restore_insn+8)
150307a63cbeSMartin Schwidefsky	je	1f
15044bfc86ceSHeiko Carstens	lg	%r9,24(%r11)		# get saved r11 pointer to pt_regs
15054bfc86ceSHeiko Carstens	mvc	__LC_RETURN_PSW(16),__PT_PSW(%r9)
15064bfc86ceSHeiko Carstens	mvc	0(64,%r11),__PT_R8(%r9)
15074bfc86ceSHeiko Carstens	lmg	%r0,%r7,__PT_R0(%r9)
150807a63cbeSMartin Schwidefsky1:	lmg	%r8,%r9,__LC_RETURN_PSW
1509f19fbd5eSMartin Schwidefsky	BR_R11USE_R14
15104bfc86ceSHeiko Carstens.Lcleanup_io_restore_insn:
151107a63cbeSMartin Schwidefsky	.quad	.Lio_exit_timer
15124bfc86ceSHeiko Carstens	.quad	.Lio_done - 4
15134bfc86ceSHeiko Carstens
15144bfc86ceSHeiko Carstens.Lcleanup_idle:
1515419123f9SMartin Schwidefsky	ni	__LC_CPU_FLAGS+7,255-_CIF_ENABLED_WAIT
15164bfc86ceSHeiko Carstens	# copy interrupt clock & cpu timer
15174bfc86ceSHeiko Carstens	mvc	__CLOCK_IDLE_EXIT(8,%r2),__LC_INT_CLOCK
15184bfc86ceSHeiko Carstens	mvc	__TIMER_IDLE_EXIT(8,%r2),__LC_ASYNC_ENTER_TIMER
15194bfc86ceSHeiko Carstens	cghi	%r11,__LC_SAVE_AREA_ASYNC
15204bfc86ceSHeiko Carstens	je	0f
15214bfc86ceSHeiko Carstens	mvc	__CLOCK_IDLE_EXIT(8,%r2),__LC_MCCK_CLOCK
15224bfc86ceSHeiko Carstens	mvc	__TIMER_IDLE_EXIT(8,%r2),__LC_MCCK_ENTER_TIMER
15234bfc86ceSHeiko Carstens0:	# check if stck & stpt have been executed
15244bfc86ceSHeiko Carstens	clg	%r9,BASED(.Lcleanup_idle_insn)
15254bfc86ceSHeiko Carstens	jhe	1f
15264bfc86ceSHeiko Carstens	mvc	__CLOCK_IDLE_ENTER(8,%r2),__CLOCK_IDLE_EXIT(%r2)
15274bfc86ceSHeiko Carstens	mvc	__TIMER_IDLE_ENTER(8,%r2),__TIMER_IDLE_EXIT(%r2)
152872d38b19SMartin Schwidefsky1:	# calculate idle cycles
152972d38b19SMartin Schwidefsky#ifdef CONFIG_SMP
153072d38b19SMartin Schwidefsky	clg	%r9,BASED(.Lcleanup_idle_insn)
153172d38b19SMartin Schwidefsky	jl	3f
153272d38b19SMartin Schwidefsky	larl	%r1,smp_cpu_mtid
153372d38b19SMartin Schwidefsky	llgf	%r1,0(%r1)
153472d38b19SMartin Schwidefsky	ltgr	%r1,%r1
153572d38b19SMartin Schwidefsky	jz	3f
153672d38b19SMartin Schwidefsky	.insn	rsy,0xeb0000000017,%r1,5,__SF_EMPTY+80(%r15)
153772d38b19SMartin Schwidefsky	larl	%r3,mt_cycles
153872d38b19SMartin Schwidefsky	ag	%r3,__LC_PERCPU_OFFSET
153972d38b19SMartin Schwidefsky	la	%r4,__SF_EMPTY+16(%r15)
154072d38b19SMartin Schwidefsky2:	lg	%r0,0(%r3)
154172d38b19SMartin Schwidefsky	slg	%r0,0(%r4)
154272d38b19SMartin Schwidefsky	alg	%r0,64(%r4)
154372d38b19SMartin Schwidefsky	stg	%r0,0(%r3)
154472d38b19SMartin Schwidefsky	la	%r3,8(%r3)
154572d38b19SMartin Schwidefsky	la	%r4,8(%r4)
154672d38b19SMartin Schwidefsky	brct	%r1,2b
154772d38b19SMartin Schwidefsky#endif
154872d38b19SMartin Schwidefsky3:	# account system time going idle
15494bfc86ceSHeiko Carstens	lg	%r9,__LC_STEAL_TIMER
15504bfc86ceSHeiko Carstens	alg	%r9,__CLOCK_IDLE_ENTER(%r2)
15514bfc86ceSHeiko Carstens	slg	%r9,__LC_LAST_UPDATE_CLOCK
15524bfc86ceSHeiko Carstens	stg	%r9,__LC_STEAL_TIMER
15534bfc86ceSHeiko Carstens	mvc	__LC_LAST_UPDATE_CLOCK(8),__CLOCK_IDLE_EXIT(%r2)
15544bfc86ceSHeiko Carstens	lg	%r9,__LC_SYSTEM_TIMER
15554bfc86ceSHeiko Carstens	alg	%r9,__LC_LAST_UPDATE_TIMER
15564bfc86ceSHeiko Carstens	slg	%r9,__TIMER_IDLE_ENTER(%r2)
15574bfc86ceSHeiko Carstens	stg	%r9,__LC_SYSTEM_TIMER
15584bfc86ceSHeiko Carstens	mvc	__LC_LAST_UPDATE_TIMER(8),__TIMER_IDLE_EXIT(%r2)
15594bfc86ceSHeiko Carstens	# prepare return psw
15604bfc86ceSHeiko Carstens	nihh	%r8,0xfcfd		# clear irq & wait state bits
15614bfc86ceSHeiko Carstens	lg	%r9,48(%r11)		# return from psw_idle
1562f19fbd5eSMartin Schwidefsky	BR_R11USE_R14
15634bfc86ceSHeiko Carstens.Lcleanup_idle_insn:
15644bfc86ceSHeiko Carstens	.quad	.Lpsw_idle_lpsw
15654bfc86ceSHeiko Carstens
15669977e886SHendrik Brueckner.Lcleanup_save_fpu_regs:
1567e370e476SMartin Schwidefsky	larl	%r9,save_fpu_regs
1568f19fbd5eSMartin Schwidefsky	BR_R11USE_R14
15699977e886SHendrik Brueckner
15709977e886SHendrik Brueckner.Lcleanup_load_fpu_regs:
1571e370e476SMartin Schwidefsky	larl	%r9,load_fpu_regs
1572f19fbd5eSMartin Schwidefsky	BR_R11USE_R14
15739977e886SHendrik Brueckner
15744bfc86ceSHeiko Carstens/*
15754bfc86ceSHeiko Carstens * Integer constants
15764bfc86ceSHeiko Carstens */
15774bfc86ceSHeiko Carstens	.align	8
15784bfc86ceSHeiko Carstens.Lcritical_start:
15794bfc86ceSHeiko Carstens	.quad	.L__critical_start
15804bfc86ceSHeiko Carstens.Lcritical_length:
15814bfc86ceSHeiko Carstens	.quad	.L__critical_end - .L__critical_start
15824bfc86ceSHeiko Carstens#if IS_ENABLED(CONFIG_KVM)
1583d0fc4107SMartin Schwidefsky.Lsie_critical_start:
15844bfc86ceSHeiko Carstens	.quad	.Lsie_gmap
15854bfc86ceSHeiko Carstens.Lsie_critical_length:
15864bfc86ceSHeiko Carstens	.quad	.Lsie_done - .Lsie_gmap
1587c929500dSQingFeng Hao.Lsie_crit_mcck_start:
1588c929500dSQingFeng Hao	.quad   .Lsie_entry
1589c929500dSQingFeng Hao.Lsie_crit_mcck_length:
1590c929500dSQingFeng Hao	.quad   .Lsie_skip - .Lsie_entry
15914bfc86ceSHeiko Carstens#endif
15924bfc86ceSHeiko Carstens	.section .rodata, "a"
1593a876cb3fSHeiko Carstens#define SYSCALL(esame,emu)	.long esame
15944bfc86ceSHeiko Carstens	.globl	sys_call_table
15954bfc86ceSHeiko Carstenssys_call_table:
15964381f9f1SHendrik Brueckner#include "asm/syscall_table.h"
15974bfc86ceSHeiko Carstens#undef SYSCALL
15984bfc86ceSHeiko Carstens
15994bfc86ceSHeiko Carstens#ifdef CONFIG_COMPAT
16004bfc86ceSHeiko Carstens
1601a876cb3fSHeiko Carstens#define SYSCALL(esame,emu)	.long emu
16024bfc86ceSHeiko Carstens	.globl	sys_call_table_emu
16034bfc86ceSHeiko Carstenssys_call_table_emu:
16044381f9f1SHendrik Brueckner#include "asm/syscall_table.h"
16054bfc86ceSHeiko Carstens#undef SYSCALL
16064bfc86ceSHeiko Carstens#endif
1607