xref: /openbmc/linux/arch/s390/kernel/entry.S (revision 3827ec3d8fd51aef8352b0282b14f0f3ab615930)
14bfc86ceSHeiko Carstens/*
24bfc86ceSHeiko Carstens *    S390 low-level entry points.
34bfc86ceSHeiko Carstens *
44bfc86ceSHeiko Carstens *    Copyright IBM Corp. 1999, 2012
54bfc86ceSHeiko Carstens *    Author(s): Martin Schwidefsky (schwidefsky@de.ibm.com),
64bfc86ceSHeiko Carstens *		 Hartmut Penner (hp@de.ibm.com),
74bfc86ceSHeiko Carstens *		 Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com),
84bfc86ceSHeiko Carstens *		 Heiko Carstens <heiko.carstens@de.ibm.com>
94bfc86ceSHeiko Carstens */
104bfc86ceSHeiko Carstens
114bfc86ceSHeiko Carstens#include <linux/init.h>
124bfc86ceSHeiko Carstens#include <linux/linkage.h>
134bfc86ceSHeiko Carstens#include <asm/processor.h>
144bfc86ceSHeiko Carstens#include <asm/cache.h>
154bfc86ceSHeiko Carstens#include <asm/errno.h>
164bfc86ceSHeiko Carstens#include <asm/ptrace.h>
174bfc86ceSHeiko Carstens#include <asm/thread_info.h>
184bfc86ceSHeiko Carstens#include <asm/asm-offsets.h>
194bfc86ceSHeiko Carstens#include <asm/unistd.h>
204bfc86ceSHeiko Carstens#include <asm/page.h>
214bfc86ceSHeiko Carstens#include <asm/sigp.h>
224bfc86ceSHeiko Carstens#include <asm/irq.h>
234bfc86ceSHeiko Carstens
244bfc86ceSHeiko Carstens__PT_R0      =	__PT_GPRS
254bfc86ceSHeiko Carstens__PT_R1      =	__PT_GPRS + 8
264bfc86ceSHeiko Carstens__PT_R2      =	__PT_GPRS + 16
274bfc86ceSHeiko Carstens__PT_R3      =	__PT_GPRS + 24
284bfc86ceSHeiko Carstens__PT_R4      =	__PT_GPRS + 32
294bfc86ceSHeiko Carstens__PT_R5      =	__PT_GPRS + 40
304bfc86ceSHeiko Carstens__PT_R6      =	__PT_GPRS + 48
314bfc86ceSHeiko Carstens__PT_R7      =	__PT_GPRS + 56
324bfc86ceSHeiko Carstens__PT_R8      =	__PT_GPRS + 64
334bfc86ceSHeiko Carstens__PT_R9      =	__PT_GPRS + 72
344bfc86ceSHeiko Carstens__PT_R10     =	__PT_GPRS + 80
354bfc86ceSHeiko Carstens__PT_R11     =	__PT_GPRS + 88
364bfc86ceSHeiko Carstens__PT_R12     =	__PT_GPRS + 96
374bfc86ceSHeiko Carstens__PT_R13     =	__PT_GPRS + 104
384bfc86ceSHeiko Carstens__PT_R14     =	__PT_GPRS + 112
394bfc86ceSHeiko Carstens__PT_R15     =	__PT_GPRS + 120
404bfc86ceSHeiko Carstens
414bfc86ceSHeiko CarstensSTACK_SHIFT = PAGE_SHIFT + THREAD_ORDER
424bfc86ceSHeiko CarstensSTACK_SIZE  = 1 << STACK_SHIFT
434bfc86ceSHeiko CarstensSTACK_INIT = STACK_SIZE - STACK_FRAME_OVERHEAD - __PT_SIZE
444bfc86ceSHeiko Carstens
454bfc86ceSHeiko Carstens_TIF_WORK	= (_TIF_SIGPENDING | _TIF_NOTIFY_RESUME | _TIF_NEED_RESCHED | \
464bfc86ceSHeiko Carstens		   _TIF_UPROBE)
474bfc86ceSHeiko Carstens_TIF_TRACE	= (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SECCOMP | \
484bfc86ceSHeiko Carstens		   _TIF_SYSCALL_TRACEPOINT)
494bfc86ceSHeiko Carstens_CIF_WORK	= (_CIF_MCCK_PENDING | _CIF_ASCE)
504bfc86ceSHeiko Carstens_PIF_WORK	= (_PIF_PER_TRAP)
514bfc86ceSHeiko Carstens
524bfc86ceSHeiko Carstens#define BASED(name) name-system_call(%r13)
534bfc86ceSHeiko Carstens
544bfc86ceSHeiko Carstens	.macro	TRACE_IRQS_ON
554bfc86ceSHeiko Carstens#ifdef CONFIG_TRACE_IRQFLAGS
564bfc86ceSHeiko Carstens	basr	%r2,%r0
574bfc86ceSHeiko Carstens	brasl	%r14,trace_hardirqs_on_caller
584bfc86ceSHeiko Carstens#endif
594bfc86ceSHeiko Carstens	.endm
604bfc86ceSHeiko Carstens
614bfc86ceSHeiko Carstens	.macro	TRACE_IRQS_OFF
624bfc86ceSHeiko Carstens#ifdef CONFIG_TRACE_IRQFLAGS
634bfc86ceSHeiko Carstens	basr	%r2,%r0
644bfc86ceSHeiko Carstens	brasl	%r14,trace_hardirqs_off_caller
654bfc86ceSHeiko Carstens#endif
664bfc86ceSHeiko Carstens	.endm
674bfc86ceSHeiko Carstens
684bfc86ceSHeiko Carstens	.macro	LOCKDEP_SYS_EXIT
694bfc86ceSHeiko Carstens#ifdef CONFIG_LOCKDEP
704bfc86ceSHeiko Carstens	tm	__PT_PSW+1(%r11),0x01	# returning to user ?
714bfc86ceSHeiko Carstens	jz	.+10
724bfc86ceSHeiko Carstens	brasl	%r14,lockdep_sys_exit
734bfc86ceSHeiko Carstens#endif
744bfc86ceSHeiko Carstens	.endm
754bfc86ceSHeiko Carstens
764bfc86ceSHeiko Carstens	.macro LPP newpp
774bfc86ceSHeiko Carstens#if IS_ENABLED(CONFIG_KVM)
784bfc86ceSHeiko Carstens	tm	__LC_MACHINE_FLAGS+6,0x20	# MACHINE_FLAG_LPP
794bfc86ceSHeiko Carstens	jz	.+8
804bfc86ceSHeiko Carstens	.insn	s,0xb2800000,\newpp
814bfc86ceSHeiko Carstens#endif
824bfc86ceSHeiko Carstens	.endm
834bfc86ceSHeiko Carstens
844bfc86ceSHeiko Carstens	.macro	HANDLE_SIE_INTERCEPT scratch,reason
854bfc86ceSHeiko Carstens#if IS_ENABLED(CONFIG_KVM)
864bfc86ceSHeiko Carstens	tmhh	%r8,0x0001		# interrupting from user ?
874bfc86ceSHeiko Carstens	jnz	.+62
884bfc86ceSHeiko Carstens	lgr	\scratch,%r9
894bfc86ceSHeiko Carstens	slg	\scratch,BASED(.Lsie_critical)
904bfc86ceSHeiko Carstens	clg	\scratch,BASED(.Lsie_critical_length)
914bfc86ceSHeiko Carstens	.if	\reason==1
924bfc86ceSHeiko Carstens	# Some program interrupts are suppressing (e.g. protection).
934bfc86ceSHeiko Carstens	# We must also check the instruction after SIE in that case.
944bfc86ceSHeiko Carstens	# do_protection_exception will rewind to .Lrewind_pad
954bfc86ceSHeiko Carstens	jh	.+42
964bfc86ceSHeiko Carstens	.else
974bfc86ceSHeiko Carstens	jhe	.+42
984bfc86ceSHeiko Carstens	.endif
994bfc86ceSHeiko Carstens	lg	%r14,__SF_EMPTY(%r15)		# get control block pointer
1004bfc86ceSHeiko Carstens	LPP	__SF_EMPTY+16(%r15)		# set host id
1014bfc86ceSHeiko Carstens	ni	__SIE_PROG0C+3(%r14),0xfe	# no longer in SIE
1024bfc86ceSHeiko Carstens	lctlg	%c1,%c1,__LC_USER_ASCE		# load primary asce
1034bfc86ceSHeiko Carstens	larl	%r9,sie_exit			# skip forward to sie_exit
1044bfc86ceSHeiko Carstens	mvi	__SF_EMPTY+31(%r15),\reason	# set exit reason
1054bfc86ceSHeiko Carstens#endif
1064bfc86ceSHeiko Carstens	.endm
1074bfc86ceSHeiko Carstens
1084bfc86ceSHeiko Carstens	.macro	CHECK_STACK stacksize,savearea
1094bfc86ceSHeiko Carstens#ifdef CONFIG_CHECK_STACK
1104bfc86ceSHeiko Carstens	tml	%r15,\stacksize - CONFIG_STACK_GUARD
1114bfc86ceSHeiko Carstens	lghi	%r14,\savearea
1124bfc86ceSHeiko Carstens	jz	stack_overflow
1134bfc86ceSHeiko Carstens#endif
1144bfc86ceSHeiko Carstens	.endm
1154bfc86ceSHeiko Carstens
1164bfc86ceSHeiko Carstens	.macro	SWITCH_ASYNC savearea,stack,shift
1174bfc86ceSHeiko Carstens	tmhh	%r8,0x0001		# interrupting from user ?
1184bfc86ceSHeiko Carstens	jnz	1f
1194bfc86ceSHeiko Carstens	lgr	%r14,%r9
1204bfc86ceSHeiko Carstens	slg	%r14,BASED(.Lcritical_start)
1214bfc86ceSHeiko Carstens	clg	%r14,BASED(.Lcritical_length)
1224bfc86ceSHeiko Carstens	jhe	0f
1234bfc86ceSHeiko Carstens	lghi	%r11,\savearea		# inside critical section, do cleanup
1244bfc86ceSHeiko Carstens	brasl	%r14,cleanup_critical
1254bfc86ceSHeiko Carstens	tmhh	%r8,0x0001		# retest problem state after cleanup
1264bfc86ceSHeiko Carstens	jnz	1f
1274bfc86ceSHeiko Carstens0:	lg	%r14,\stack		# are we already on the target stack?
1284bfc86ceSHeiko Carstens	slgr	%r14,%r15
1294bfc86ceSHeiko Carstens	srag	%r14,%r14,\shift
1304bfc86ceSHeiko Carstens	jnz	1f
1314bfc86ceSHeiko Carstens	CHECK_STACK 1<<\shift,\savearea
1324bfc86ceSHeiko Carstens	aghi	%r15,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
1334bfc86ceSHeiko Carstens	j	2f
1344bfc86ceSHeiko Carstens1:	lg	%r15,\stack		# load target stack
1354bfc86ceSHeiko Carstens2:	la	%r11,STACK_FRAME_OVERHEAD(%r15)
1364bfc86ceSHeiko Carstens	.endm
1374bfc86ceSHeiko Carstens
1384bfc86ceSHeiko Carstens	.macro UPDATE_VTIME scratch,enter_timer
1394bfc86ceSHeiko Carstens	lg	\scratch,__LC_EXIT_TIMER
1404bfc86ceSHeiko Carstens	slg	\scratch,\enter_timer
1414bfc86ceSHeiko Carstens	alg	\scratch,__LC_USER_TIMER
1424bfc86ceSHeiko Carstens	stg	\scratch,__LC_USER_TIMER
1434bfc86ceSHeiko Carstens	lg	\scratch,__LC_LAST_UPDATE_TIMER
1444bfc86ceSHeiko Carstens	slg	\scratch,__LC_EXIT_TIMER
1454bfc86ceSHeiko Carstens	alg	\scratch,__LC_SYSTEM_TIMER
1464bfc86ceSHeiko Carstens	stg	\scratch,__LC_SYSTEM_TIMER
1474bfc86ceSHeiko Carstens	mvc	__LC_LAST_UPDATE_TIMER(8),\enter_timer
1484bfc86ceSHeiko Carstens	.endm
1494bfc86ceSHeiko Carstens
1504bfc86ceSHeiko Carstens	.macro	LAST_BREAK scratch
1514bfc86ceSHeiko Carstens	srag	\scratch,%r10,23
1524bfc86ceSHeiko Carstens	jz	.+10
1534bfc86ceSHeiko Carstens	stg	%r10,__TI_last_break(%r12)
1544bfc86ceSHeiko Carstens	.endm
1554bfc86ceSHeiko Carstens
1564bfc86ceSHeiko Carstens	.macro REENABLE_IRQS
1574bfc86ceSHeiko Carstens	stg	%r8,__LC_RETURN_PSW
1584bfc86ceSHeiko Carstens	ni	__LC_RETURN_PSW,0xbf
1594bfc86ceSHeiko Carstens	ssm	__LC_RETURN_PSW
1604bfc86ceSHeiko Carstens	.endm
1614bfc86ceSHeiko Carstens
1624bfc86ceSHeiko Carstens	.macro STCK savearea
1634bfc86ceSHeiko Carstens#ifdef CONFIG_HAVE_MARCH_Z9_109_FEATURES
1644bfc86ceSHeiko Carstens	.insn	s,0xb27c0000,\savearea		# store clock fast
1654bfc86ceSHeiko Carstens#else
1664bfc86ceSHeiko Carstens	.insn	s,0xb2050000,\savearea		# store clock
1674bfc86ceSHeiko Carstens#endif
1684bfc86ceSHeiko Carstens	.endm
1694bfc86ceSHeiko Carstens
1704bfc86ceSHeiko Carstens	.section .kprobes.text, "ax"
1714bfc86ceSHeiko Carstens
1724bfc86ceSHeiko Carstens/*
1734bfc86ceSHeiko Carstens * Scheduler resume function, called by switch_to
1744bfc86ceSHeiko Carstens *  gpr2 = (task_struct *) prev
1754bfc86ceSHeiko Carstens *  gpr3 = (task_struct *) next
1764bfc86ceSHeiko Carstens * Returns:
1774bfc86ceSHeiko Carstens *  gpr2 = prev
1784bfc86ceSHeiko Carstens */
1794bfc86ceSHeiko CarstensENTRY(__switch_to)
1804bfc86ceSHeiko Carstens	stmg	%r6,%r15,__SF_GPRS(%r15)	# store gprs of prev task
181*3827ec3dSMartin Schwidefsky	lgr	%r1,%r2
182*3827ec3dSMartin Schwidefsky	aghi	%r1,__TASK_thread		# thread_struct of prev task
183*3827ec3dSMartin Schwidefsky	lg	%r4,__TASK_thread_info(%r2)	# get thread_info of prev
184*3827ec3dSMartin Schwidefsky	lg	%r5,__TASK_thread_info(%r3)	# get thread_info of next
185*3827ec3dSMartin Schwidefsky	stg	%r15,__THREAD_ksp(%r1)		# store kernel stack of prev
186*3827ec3dSMartin Schwidefsky	lgr	%r1,%r3
187*3827ec3dSMartin Schwidefsky	aghi	%r1,__TASK_thread		# thread_struct of next task
1884bfc86ceSHeiko Carstens	lgr	%r15,%r5
1894bfc86ceSHeiko Carstens	aghi	%r15,STACK_INIT			# end of kernel stack of next
1904bfc86ceSHeiko Carstens	stg	%r3,__LC_CURRENT		# store task struct of next
1914bfc86ceSHeiko Carstens	stg	%r5,__LC_THREAD_INFO		# store thread info of next
1924bfc86ceSHeiko Carstens	stg	%r15,__LC_KERNEL_STACK		# store end of kernel stack
193*3827ec3dSMartin Schwidefsky	lg	%r15,__THREAD_ksp(%r1)		# load kernel stack of next
1944bfc86ceSHeiko Carstens	lctl	%c4,%c4,__TASK_pid(%r3)		# load pid to control reg. 4
1954bfc86ceSHeiko Carstens	mvc	__LC_CURRENT_PID+4(4,%r0),__TASK_pid(%r3) # store pid of next
1964bfc86ceSHeiko Carstens	lmg	%r6,%r15,__SF_GPRS(%r15)	# load gprs of next task
1974bfc86ceSHeiko Carstens	br	%r14
1984bfc86ceSHeiko Carstens
1994bfc86ceSHeiko Carstens.L__critical_start:
2004bfc86ceSHeiko Carstens/*
2014bfc86ceSHeiko Carstens * SVC interrupt handler routine. System calls are synchronous events and
2024bfc86ceSHeiko Carstens * are executed with interrupts enabled.
2034bfc86ceSHeiko Carstens */
2044bfc86ceSHeiko Carstens
2054bfc86ceSHeiko CarstensENTRY(system_call)
2064bfc86ceSHeiko Carstens	stpt	__LC_SYNC_ENTER_TIMER
2074bfc86ceSHeiko Carstens.Lsysc_stmg:
2084bfc86ceSHeiko Carstens	stmg	%r8,%r15,__LC_SAVE_AREA_SYNC
2094bfc86ceSHeiko Carstens	lg	%r10,__LC_LAST_BREAK
2104bfc86ceSHeiko Carstens	lg	%r12,__LC_THREAD_INFO
2114bfc86ceSHeiko Carstens	lghi	%r14,_PIF_SYSCALL
2124bfc86ceSHeiko Carstens.Lsysc_per:
2134bfc86ceSHeiko Carstens	lg	%r15,__LC_KERNEL_STACK
2144bfc86ceSHeiko Carstens	la	%r11,STACK_FRAME_OVERHEAD(%r15)	# pointer to pt_regs
2154bfc86ceSHeiko Carstens.Lsysc_vtime:
2164bfc86ceSHeiko Carstens	UPDATE_VTIME %r13,__LC_SYNC_ENTER_TIMER
2174bfc86ceSHeiko Carstens	LAST_BREAK %r13
2184bfc86ceSHeiko Carstens	stmg	%r0,%r7,__PT_R0(%r11)
2194bfc86ceSHeiko Carstens	mvc	__PT_R8(64,%r11),__LC_SAVE_AREA_SYNC
2204bfc86ceSHeiko Carstens	mvc	__PT_PSW(16,%r11),__LC_SVC_OLD_PSW
2214bfc86ceSHeiko Carstens	mvc	__PT_INT_CODE(4,%r11),__LC_SVC_ILC
2224bfc86ceSHeiko Carstens	stg	%r14,__PT_FLAGS(%r11)
2234bfc86ceSHeiko Carstens.Lsysc_do_svc:
2244bfc86ceSHeiko Carstens	lg	%r10,__TI_sysc_table(%r12)	# address of system call table
2254bfc86ceSHeiko Carstens	llgh	%r8,__PT_INT_CODE+2(%r11)
2264bfc86ceSHeiko Carstens	slag	%r8,%r8,2			# shift and test for svc 0
2274bfc86ceSHeiko Carstens	jnz	.Lsysc_nr_ok
2284bfc86ceSHeiko Carstens	# svc 0: system call number in %r1
2294bfc86ceSHeiko Carstens	llgfr	%r1,%r1				# clear high word in r1
2304bfc86ceSHeiko Carstens	cghi	%r1,NR_syscalls
2314bfc86ceSHeiko Carstens	jnl	.Lsysc_nr_ok
2324bfc86ceSHeiko Carstens	sth	%r1,__PT_INT_CODE+2(%r11)
2334bfc86ceSHeiko Carstens	slag	%r8,%r1,2
2344bfc86ceSHeiko Carstens.Lsysc_nr_ok:
2354bfc86ceSHeiko Carstens	xc	__SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
2364bfc86ceSHeiko Carstens	stg	%r2,__PT_ORIG_GPR2(%r11)
2374bfc86ceSHeiko Carstens	stg	%r7,STACK_FRAME_OVERHEAD(%r15)
2384bfc86ceSHeiko Carstens	lgf	%r9,0(%r8,%r10)			# get system call add.
2394bfc86ceSHeiko Carstens	tm	__TI_flags+7(%r12),_TIF_TRACE
2404bfc86ceSHeiko Carstens	jnz	.Lsysc_tracesys
2414bfc86ceSHeiko Carstens	basr	%r14,%r9			# call sys_xxxx
2424bfc86ceSHeiko Carstens	stg	%r2,__PT_R2(%r11)		# store return value
2434bfc86ceSHeiko Carstens
2444bfc86ceSHeiko Carstens.Lsysc_return:
2454bfc86ceSHeiko Carstens	LOCKDEP_SYS_EXIT
2464bfc86ceSHeiko Carstens.Lsysc_tif:
2474bfc86ceSHeiko Carstens	tm	__PT_PSW+1(%r11),0x01		# returning to user ?
2484bfc86ceSHeiko Carstens	jno	.Lsysc_restore
2494bfc86ceSHeiko Carstens	tm	__PT_FLAGS+7(%r11),_PIF_WORK
2504bfc86ceSHeiko Carstens	jnz	.Lsysc_work
2514bfc86ceSHeiko Carstens	tm	__TI_flags+7(%r12),_TIF_WORK
2524bfc86ceSHeiko Carstens	jnz	.Lsysc_work			# check for work
2534bfc86ceSHeiko Carstens	tm	__LC_CPU_FLAGS+7,_CIF_WORK
2544bfc86ceSHeiko Carstens	jnz	.Lsysc_work
2554bfc86ceSHeiko Carstens.Lsysc_restore:
2564bfc86ceSHeiko Carstens	lg	%r14,__LC_VDSO_PER_CPU
2574bfc86ceSHeiko Carstens	lmg	%r0,%r10,__PT_R0(%r11)
2584bfc86ceSHeiko Carstens	mvc	__LC_RETURN_PSW(16),__PT_PSW(%r11)
2594bfc86ceSHeiko Carstens	stpt	__LC_EXIT_TIMER
2604bfc86ceSHeiko Carstens	mvc	__VDSO_ECTG_BASE(16,%r14),__LC_EXIT_TIMER
2614bfc86ceSHeiko Carstens	lmg	%r11,%r15,__PT_R11(%r11)
2624bfc86ceSHeiko Carstens	lpswe	__LC_RETURN_PSW
2634bfc86ceSHeiko Carstens.Lsysc_done:
2644bfc86ceSHeiko Carstens
2654bfc86ceSHeiko Carstens#
2664bfc86ceSHeiko Carstens# One of the work bits is on. Find out which one.
2674bfc86ceSHeiko Carstens#
2684bfc86ceSHeiko Carstens.Lsysc_work:
2694bfc86ceSHeiko Carstens	tm	__LC_CPU_FLAGS+7,_CIF_MCCK_PENDING
2704bfc86ceSHeiko Carstens	jo	.Lsysc_mcck_pending
2714bfc86ceSHeiko Carstens	tm	__TI_flags+7(%r12),_TIF_NEED_RESCHED
2724bfc86ceSHeiko Carstens	jo	.Lsysc_reschedule
2734bfc86ceSHeiko Carstens#ifdef CONFIG_UPROBES
2744bfc86ceSHeiko Carstens	tm	__TI_flags+7(%r12),_TIF_UPROBE
2754bfc86ceSHeiko Carstens	jo	.Lsysc_uprobe_notify
2764bfc86ceSHeiko Carstens#endif
2774bfc86ceSHeiko Carstens	tm	__PT_FLAGS+7(%r11),_PIF_PER_TRAP
2784bfc86ceSHeiko Carstens	jo	.Lsysc_singlestep
2794bfc86ceSHeiko Carstens	tm	__TI_flags+7(%r12),_TIF_SIGPENDING
2804bfc86ceSHeiko Carstens	jo	.Lsysc_sigpending
2814bfc86ceSHeiko Carstens	tm	__TI_flags+7(%r12),_TIF_NOTIFY_RESUME
2824bfc86ceSHeiko Carstens	jo	.Lsysc_notify_resume
2834bfc86ceSHeiko Carstens	tm	__LC_CPU_FLAGS+7,_CIF_ASCE
2844bfc86ceSHeiko Carstens	jo	.Lsysc_uaccess
2854bfc86ceSHeiko Carstens	j	.Lsysc_return		# beware of critical section cleanup
2864bfc86ceSHeiko Carstens
2874bfc86ceSHeiko Carstens#
2884bfc86ceSHeiko Carstens# _TIF_NEED_RESCHED is set, call schedule
2894bfc86ceSHeiko Carstens#
2904bfc86ceSHeiko Carstens.Lsysc_reschedule:
2914bfc86ceSHeiko Carstens	larl	%r14,.Lsysc_return
2924bfc86ceSHeiko Carstens	jg	schedule
2934bfc86ceSHeiko Carstens
2944bfc86ceSHeiko Carstens#
2954bfc86ceSHeiko Carstens# _CIF_MCCK_PENDING is set, call handler
2964bfc86ceSHeiko Carstens#
2974bfc86ceSHeiko Carstens.Lsysc_mcck_pending:
2984bfc86ceSHeiko Carstens	larl	%r14,.Lsysc_return
2994bfc86ceSHeiko Carstens	jg	s390_handle_mcck	# TIF bit will be cleared by handler
3004bfc86ceSHeiko Carstens
3014bfc86ceSHeiko Carstens#
3024bfc86ceSHeiko Carstens# _CIF_ASCE is set, load user space asce
3034bfc86ceSHeiko Carstens#
3044bfc86ceSHeiko Carstens.Lsysc_uaccess:
3054bfc86ceSHeiko Carstens	ni	__LC_CPU_FLAGS+7,255-_CIF_ASCE
3064bfc86ceSHeiko Carstens	lctlg	%c1,%c1,__LC_USER_ASCE		# load primary asce
3074bfc86ceSHeiko Carstens	j	.Lsysc_return
3084bfc86ceSHeiko Carstens
3094bfc86ceSHeiko Carstens#
3104bfc86ceSHeiko Carstens# _TIF_SIGPENDING is set, call do_signal
3114bfc86ceSHeiko Carstens#
3124bfc86ceSHeiko Carstens.Lsysc_sigpending:
3134bfc86ceSHeiko Carstens	lgr	%r2,%r11		# pass pointer to pt_regs
3144bfc86ceSHeiko Carstens	brasl	%r14,do_signal
3154bfc86ceSHeiko Carstens	tm	__PT_FLAGS+7(%r11),_PIF_SYSCALL
3164bfc86ceSHeiko Carstens	jno	.Lsysc_return
3174bfc86ceSHeiko Carstens	lmg	%r2,%r7,__PT_R2(%r11)	# load svc arguments
3184bfc86ceSHeiko Carstens	lg	%r10,__TI_sysc_table(%r12)	# address of system call table
3194bfc86ceSHeiko Carstens	lghi	%r8,0			# svc 0 returns -ENOSYS
3204bfc86ceSHeiko Carstens	llgh	%r1,__PT_INT_CODE+2(%r11)	# load new svc number
3214bfc86ceSHeiko Carstens	cghi	%r1,NR_syscalls
3224bfc86ceSHeiko Carstens	jnl	.Lsysc_nr_ok		# invalid svc number -> do svc 0
3234bfc86ceSHeiko Carstens	slag	%r8,%r1,2
3244bfc86ceSHeiko Carstens	j	.Lsysc_nr_ok		# restart svc
3254bfc86ceSHeiko Carstens
3264bfc86ceSHeiko Carstens#
3274bfc86ceSHeiko Carstens# _TIF_NOTIFY_RESUME is set, call do_notify_resume
3284bfc86ceSHeiko Carstens#
3294bfc86ceSHeiko Carstens.Lsysc_notify_resume:
3304bfc86ceSHeiko Carstens	lgr	%r2,%r11		# pass pointer to pt_regs
3314bfc86ceSHeiko Carstens	larl	%r14,.Lsysc_return
3324bfc86ceSHeiko Carstens	jg	do_notify_resume
3334bfc86ceSHeiko Carstens
3344bfc86ceSHeiko Carstens#
3354bfc86ceSHeiko Carstens# _TIF_UPROBE is set, call uprobe_notify_resume
3364bfc86ceSHeiko Carstens#
3374bfc86ceSHeiko Carstens#ifdef CONFIG_UPROBES
3384bfc86ceSHeiko Carstens.Lsysc_uprobe_notify:
3394bfc86ceSHeiko Carstens	lgr	%r2,%r11		# pass pointer to pt_regs
3404bfc86ceSHeiko Carstens	larl	%r14,.Lsysc_return
3414bfc86ceSHeiko Carstens	jg	uprobe_notify_resume
3424bfc86ceSHeiko Carstens#endif
3434bfc86ceSHeiko Carstens
3444bfc86ceSHeiko Carstens#
3454bfc86ceSHeiko Carstens# _PIF_PER_TRAP is set, call do_per_trap
3464bfc86ceSHeiko Carstens#
3474bfc86ceSHeiko Carstens.Lsysc_singlestep:
3484bfc86ceSHeiko Carstens	ni	__PT_FLAGS+7(%r11),255-_PIF_PER_TRAP
3494bfc86ceSHeiko Carstens	lgr	%r2,%r11		# pass pointer to pt_regs
3504bfc86ceSHeiko Carstens	larl	%r14,.Lsysc_return
3514bfc86ceSHeiko Carstens	jg	do_per_trap
3524bfc86ceSHeiko Carstens
3534bfc86ceSHeiko Carstens#
3544bfc86ceSHeiko Carstens# call tracehook_report_syscall_entry/tracehook_report_syscall_exit before
3554bfc86ceSHeiko Carstens# and after the system call
3564bfc86ceSHeiko Carstens#
3574bfc86ceSHeiko Carstens.Lsysc_tracesys:
3584bfc86ceSHeiko Carstens	lgr	%r2,%r11		# pass pointer to pt_regs
3594bfc86ceSHeiko Carstens	la	%r3,0
3604bfc86ceSHeiko Carstens	llgh	%r0,__PT_INT_CODE+2(%r11)
3614bfc86ceSHeiko Carstens	stg	%r0,__PT_R2(%r11)
3624bfc86ceSHeiko Carstens	brasl	%r14,do_syscall_trace_enter
3634bfc86ceSHeiko Carstens	lghi	%r0,NR_syscalls
3644bfc86ceSHeiko Carstens	clgr	%r0,%r2
3654bfc86ceSHeiko Carstens	jnh	.Lsysc_tracenogo
3664bfc86ceSHeiko Carstens	sllg	%r8,%r2,2
3674bfc86ceSHeiko Carstens	lgf	%r9,0(%r8,%r10)
3684bfc86ceSHeiko Carstens.Lsysc_tracego:
3694bfc86ceSHeiko Carstens	lmg	%r3,%r7,__PT_R3(%r11)
3704bfc86ceSHeiko Carstens	stg	%r7,STACK_FRAME_OVERHEAD(%r15)
3714bfc86ceSHeiko Carstens	lg	%r2,__PT_ORIG_GPR2(%r11)
3724bfc86ceSHeiko Carstens	basr	%r14,%r9		# call sys_xxx
3734bfc86ceSHeiko Carstens	stg	%r2,__PT_R2(%r11)	# store return value
3744bfc86ceSHeiko Carstens.Lsysc_tracenogo:
3754bfc86ceSHeiko Carstens	tm	__TI_flags+7(%r12),_TIF_TRACE
3764bfc86ceSHeiko Carstens	jz	.Lsysc_return
3774bfc86ceSHeiko Carstens	lgr	%r2,%r11		# pass pointer to pt_regs
3784bfc86ceSHeiko Carstens	larl	%r14,.Lsysc_return
3794bfc86ceSHeiko Carstens	jg	do_syscall_trace_exit
3804bfc86ceSHeiko Carstens
3814bfc86ceSHeiko Carstens#
3824bfc86ceSHeiko Carstens# a new process exits the kernel with ret_from_fork
3834bfc86ceSHeiko Carstens#
3844bfc86ceSHeiko CarstensENTRY(ret_from_fork)
3854bfc86ceSHeiko Carstens	la	%r11,STACK_FRAME_OVERHEAD(%r15)
3864bfc86ceSHeiko Carstens	lg	%r12,__LC_THREAD_INFO
3874bfc86ceSHeiko Carstens	brasl	%r14,schedule_tail
3884bfc86ceSHeiko Carstens	TRACE_IRQS_ON
3894bfc86ceSHeiko Carstens	ssm	__LC_SVC_NEW_PSW	# reenable interrupts
3904bfc86ceSHeiko Carstens	tm	__PT_PSW+1(%r11),0x01	# forking a kernel thread ?
3914bfc86ceSHeiko Carstens	jne	.Lsysc_tracenogo
3924bfc86ceSHeiko Carstens	# it's a kernel thread
3934bfc86ceSHeiko Carstens	lmg	%r9,%r10,__PT_R9(%r11)	# load gprs
3944bfc86ceSHeiko CarstensENTRY(kernel_thread_starter)
3954bfc86ceSHeiko Carstens	la	%r2,0(%r10)
3964bfc86ceSHeiko Carstens	basr	%r14,%r9
3974bfc86ceSHeiko Carstens	j	.Lsysc_tracenogo
3984bfc86ceSHeiko Carstens
3994bfc86ceSHeiko Carstens/*
4004bfc86ceSHeiko Carstens * Program check handler routine
4014bfc86ceSHeiko Carstens */
4024bfc86ceSHeiko Carstens
4034bfc86ceSHeiko CarstensENTRY(pgm_check_handler)
4044bfc86ceSHeiko Carstens	stpt	__LC_SYNC_ENTER_TIMER
4054bfc86ceSHeiko Carstens	stmg	%r8,%r15,__LC_SAVE_AREA_SYNC
4064bfc86ceSHeiko Carstens	lg	%r10,__LC_LAST_BREAK
4074bfc86ceSHeiko Carstens	lg	%r12,__LC_THREAD_INFO
4084bfc86ceSHeiko Carstens	larl	%r13,system_call
4094bfc86ceSHeiko Carstens	lmg	%r8,%r9,__LC_PGM_OLD_PSW
4104bfc86ceSHeiko Carstens	HANDLE_SIE_INTERCEPT %r14,1
4114bfc86ceSHeiko Carstens	tmhh	%r8,0x0001		# test problem state bit
4124bfc86ceSHeiko Carstens	jnz	1f			# -> fault in user space
4134bfc86ceSHeiko Carstens	tmhh	%r8,0x4000		# PER bit set in old PSW ?
4144bfc86ceSHeiko Carstens	jnz	0f			# -> enabled, can't be a double fault
4154bfc86ceSHeiko Carstens	tm	__LC_PGM_ILC+3,0x80	# check for per exception
4164bfc86ceSHeiko Carstens	jnz	.Lpgm_svcper		# -> single stepped svc
4174bfc86ceSHeiko Carstens0:	CHECK_STACK STACK_SIZE,__LC_SAVE_AREA_SYNC
4184bfc86ceSHeiko Carstens	aghi	%r15,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
4194bfc86ceSHeiko Carstens	j	2f
4204bfc86ceSHeiko Carstens1:	UPDATE_VTIME %r14,__LC_SYNC_ENTER_TIMER
4214bfc86ceSHeiko Carstens	LAST_BREAK %r14
4224bfc86ceSHeiko Carstens	lg	%r15,__LC_KERNEL_STACK
4234bfc86ceSHeiko Carstens	lg	%r14,__TI_task(%r12)
424*3827ec3dSMartin Schwidefsky	aghi	%r14,__TASK_thread	# pointer to thread_struct
4254bfc86ceSHeiko Carstens	lghi	%r13,__LC_PGM_TDB
4264bfc86ceSHeiko Carstens	tm	__LC_PGM_ILC+2,0x02	# check for transaction abort
4274bfc86ceSHeiko Carstens	jz	2f
4284bfc86ceSHeiko Carstens	mvc	__THREAD_trap_tdb(256,%r14),0(%r13)
4294bfc86ceSHeiko Carstens2:	la	%r11,STACK_FRAME_OVERHEAD(%r15)
4304bfc86ceSHeiko Carstens	stmg	%r0,%r7,__PT_R0(%r11)
4314bfc86ceSHeiko Carstens	mvc	__PT_R8(64,%r11),__LC_SAVE_AREA_SYNC
4324bfc86ceSHeiko Carstens	stmg	%r8,%r9,__PT_PSW(%r11)
4334bfc86ceSHeiko Carstens	mvc	__PT_INT_CODE(4,%r11),__LC_PGM_ILC
4344bfc86ceSHeiko Carstens	mvc	__PT_INT_PARM_LONG(8,%r11),__LC_TRANS_EXC_CODE
4354bfc86ceSHeiko Carstens	xc	__PT_FLAGS(8,%r11),__PT_FLAGS(%r11)
4364bfc86ceSHeiko Carstens	stg	%r10,__PT_ARGS(%r11)
4374bfc86ceSHeiko Carstens	tm	__LC_PGM_ILC+3,0x80	# check for per exception
4384bfc86ceSHeiko Carstens	jz	0f
4394bfc86ceSHeiko Carstens	tmhh	%r8,0x0001		# kernel per event ?
4404bfc86ceSHeiko Carstens	jz	.Lpgm_kprobe
4414bfc86ceSHeiko Carstens	oi	__PT_FLAGS+7(%r11),_PIF_PER_TRAP
4424bfc86ceSHeiko Carstens	mvc	__THREAD_per_address(8,%r14),__LC_PER_ADDRESS
4434bfc86ceSHeiko Carstens	mvc	__THREAD_per_cause(2,%r14),__LC_PER_CODE
4444bfc86ceSHeiko Carstens	mvc	__THREAD_per_paid(1,%r14),__LC_PER_ACCESS_ID
4454bfc86ceSHeiko Carstens0:	REENABLE_IRQS
4464bfc86ceSHeiko Carstens	xc	__SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
4474bfc86ceSHeiko Carstens	larl	%r1,pgm_check_table
4484bfc86ceSHeiko Carstens	llgh	%r10,__PT_INT_CODE+2(%r11)
4494bfc86ceSHeiko Carstens	nill	%r10,0x007f
4504bfc86ceSHeiko Carstens	sll	%r10,2
4514bfc86ceSHeiko Carstens	je	.Lsysc_return
4524bfc86ceSHeiko Carstens	lgf	%r1,0(%r10,%r1)		# load address of handler routine
4534bfc86ceSHeiko Carstens	lgr	%r2,%r11		# pass pointer to pt_regs
4544bfc86ceSHeiko Carstens	basr	%r14,%r1		# branch to interrupt-handler
4554bfc86ceSHeiko Carstens	j	.Lsysc_return
4564bfc86ceSHeiko Carstens
4574bfc86ceSHeiko Carstens#
4584bfc86ceSHeiko Carstens# PER event in supervisor state, must be kprobes
4594bfc86ceSHeiko Carstens#
4604bfc86ceSHeiko Carstens.Lpgm_kprobe:
4614bfc86ceSHeiko Carstens	REENABLE_IRQS
4624bfc86ceSHeiko Carstens	xc	__SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
4634bfc86ceSHeiko Carstens	lgr	%r2,%r11		# pass pointer to pt_regs
4644bfc86ceSHeiko Carstens	brasl	%r14,do_per_trap
4654bfc86ceSHeiko Carstens	j	.Lsysc_return
4664bfc86ceSHeiko Carstens
4674bfc86ceSHeiko Carstens#
4684bfc86ceSHeiko Carstens# single stepped system call
4694bfc86ceSHeiko Carstens#
4704bfc86ceSHeiko Carstens.Lpgm_svcper:
4714bfc86ceSHeiko Carstens	mvc	__LC_RETURN_PSW(8),__LC_SVC_NEW_PSW
4724bfc86ceSHeiko Carstens	larl	%r14,.Lsysc_per
4734bfc86ceSHeiko Carstens	stg	%r14,__LC_RETURN_PSW+8
4744bfc86ceSHeiko Carstens	lghi	%r14,_PIF_SYSCALL | _PIF_PER_TRAP
4754bfc86ceSHeiko Carstens	lpswe	__LC_RETURN_PSW		# branch to .Lsysc_per and enable irqs
4764bfc86ceSHeiko Carstens
4774bfc86ceSHeiko Carstens/*
4784bfc86ceSHeiko Carstens * IO interrupt handler routine
4794bfc86ceSHeiko Carstens */
4804bfc86ceSHeiko CarstensENTRY(io_int_handler)
4814bfc86ceSHeiko Carstens	STCK	__LC_INT_CLOCK
4824bfc86ceSHeiko Carstens	stpt	__LC_ASYNC_ENTER_TIMER
4834bfc86ceSHeiko Carstens	stmg	%r8,%r15,__LC_SAVE_AREA_ASYNC
4844bfc86ceSHeiko Carstens	lg	%r10,__LC_LAST_BREAK
4854bfc86ceSHeiko Carstens	lg	%r12,__LC_THREAD_INFO
4864bfc86ceSHeiko Carstens	larl	%r13,system_call
4874bfc86ceSHeiko Carstens	lmg	%r8,%r9,__LC_IO_OLD_PSW
4884bfc86ceSHeiko Carstens	HANDLE_SIE_INTERCEPT %r14,2
4894bfc86ceSHeiko Carstens	SWITCH_ASYNC __LC_SAVE_AREA_ASYNC,__LC_ASYNC_STACK,STACK_SHIFT
4904bfc86ceSHeiko Carstens	tmhh	%r8,0x0001		# interrupting from user?
4914bfc86ceSHeiko Carstens	jz	.Lio_skip
4924bfc86ceSHeiko Carstens	UPDATE_VTIME %r14,__LC_ASYNC_ENTER_TIMER
4934bfc86ceSHeiko Carstens	LAST_BREAK %r14
4944bfc86ceSHeiko Carstens.Lio_skip:
4954bfc86ceSHeiko Carstens	stmg	%r0,%r7,__PT_R0(%r11)
4964bfc86ceSHeiko Carstens	mvc	__PT_R8(64,%r11),__LC_SAVE_AREA_ASYNC
4974bfc86ceSHeiko Carstens	stmg	%r8,%r9,__PT_PSW(%r11)
4984bfc86ceSHeiko Carstens	mvc	__PT_INT_CODE(12,%r11),__LC_SUBCHANNEL_ID
4994bfc86ceSHeiko Carstens	xc	__PT_FLAGS(8,%r11),__PT_FLAGS(%r11)
5004bfc86ceSHeiko Carstens	TRACE_IRQS_OFF
5014bfc86ceSHeiko Carstens	xc	__SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
5024bfc86ceSHeiko Carstens.Lio_loop:
5034bfc86ceSHeiko Carstens	lgr	%r2,%r11		# pass pointer to pt_regs
5044bfc86ceSHeiko Carstens	lghi	%r3,IO_INTERRUPT
5054bfc86ceSHeiko Carstens	tm	__PT_INT_CODE+8(%r11),0x80	# adapter interrupt ?
5064bfc86ceSHeiko Carstens	jz	.Lio_call
5074bfc86ceSHeiko Carstens	lghi	%r3,THIN_INTERRUPT
5084bfc86ceSHeiko Carstens.Lio_call:
5094bfc86ceSHeiko Carstens	brasl	%r14,do_IRQ
5104bfc86ceSHeiko Carstens	tm	__LC_MACHINE_FLAGS+6,0x10	# MACHINE_FLAG_LPAR
5114bfc86ceSHeiko Carstens	jz	.Lio_return
5124bfc86ceSHeiko Carstens	tpi	0
5134bfc86ceSHeiko Carstens	jz	.Lio_return
5144bfc86ceSHeiko Carstens	mvc	__PT_INT_CODE(12,%r11),__LC_SUBCHANNEL_ID
5154bfc86ceSHeiko Carstens	j	.Lio_loop
5164bfc86ceSHeiko Carstens.Lio_return:
5174bfc86ceSHeiko Carstens	LOCKDEP_SYS_EXIT
5184bfc86ceSHeiko Carstens	TRACE_IRQS_ON
5194bfc86ceSHeiko Carstens.Lio_tif:
5204bfc86ceSHeiko Carstens	tm	__TI_flags+7(%r12),_TIF_WORK
5214bfc86ceSHeiko Carstens	jnz	.Lio_work		# there is work to do (signals etc.)
5224bfc86ceSHeiko Carstens	tm	__LC_CPU_FLAGS+7,_CIF_WORK
5234bfc86ceSHeiko Carstens	jnz	.Lio_work
5244bfc86ceSHeiko Carstens.Lio_restore:
5254bfc86ceSHeiko Carstens	lg	%r14,__LC_VDSO_PER_CPU
5264bfc86ceSHeiko Carstens	lmg	%r0,%r10,__PT_R0(%r11)
5274bfc86ceSHeiko Carstens	mvc	__LC_RETURN_PSW(16),__PT_PSW(%r11)
5284bfc86ceSHeiko Carstens	stpt	__LC_EXIT_TIMER
5294bfc86ceSHeiko Carstens	mvc	__VDSO_ECTG_BASE(16,%r14),__LC_EXIT_TIMER
5304bfc86ceSHeiko Carstens	lmg	%r11,%r15,__PT_R11(%r11)
5314bfc86ceSHeiko Carstens	lpswe	__LC_RETURN_PSW
5324bfc86ceSHeiko Carstens.Lio_done:
5334bfc86ceSHeiko Carstens
5344bfc86ceSHeiko Carstens#
5354bfc86ceSHeiko Carstens# There is work todo, find out in which context we have been interrupted:
5364bfc86ceSHeiko Carstens# 1) if we return to user space we can do all _TIF_WORK work
5374bfc86ceSHeiko Carstens# 2) if we return to kernel code and kvm is enabled check if we need to
5384bfc86ceSHeiko Carstens#    modify the psw to leave SIE
5394bfc86ceSHeiko Carstens# 3) if we return to kernel code and preemptive scheduling is enabled check
5404bfc86ceSHeiko Carstens#    the preemption counter and if it is zero call preempt_schedule_irq
5414bfc86ceSHeiko Carstens# Before any work can be done, a switch to the kernel stack is required.
5424bfc86ceSHeiko Carstens#
5434bfc86ceSHeiko Carstens.Lio_work:
5444bfc86ceSHeiko Carstens	tm	__PT_PSW+1(%r11),0x01	# returning to user ?
5454bfc86ceSHeiko Carstens	jo	.Lio_work_user		# yes -> do resched & signal
5464bfc86ceSHeiko Carstens#ifdef CONFIG_PREEMPT
5474bfc86ceSHeiko Carstens	# check for preemptive scheduling
5484bfc86ceSHeiko Carstens	icm	%r0,15,__TI_precount(%r12)
5494bfc86ceSHeiko Carstens	jnz	.Lio_restore		# preemption is disabled
5504bfc86ceSHeiko Carstens	tm	__TI_flags+7(%r12),_TIF_NEED_RESCHED
5514bfc86ceSHeiko Carstens	jno	.Lio_restore
5524bfc86ceSHeiko Carstens	# switch to kernel stack
5534bfc86ceSHeiko Carstens	lg	%r1,__PT_R15(%r11)
5544bfc86ceSHeiko Carstens	aghi	%r1,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
5554bfc86ceSHeiko Carstens	mvc	STACK_FRAME_OVERHEAD(__PT_SIZE,%r1),0(%r11)
5564bfc86ceSHeiko Carstens	xc	__SF_BACKCHAIN(8,%r1),__SF_BACKCHAIN(%r1)
5574bfc86ceSHeiko Carstens	la	%r11,STACK_FRAME_OVERHEAD(%r1)
5584bfc86ceSHeiko Carstens	lgr	%r15,%r1
5594bfc86ceSHeiko Carstens	# TRACE_IRQS_ON already done at .Lio_return, call
5604bfc86ceSHeiko Carstens	# TRACE_IRQS_OFF to keep things symmetrical
5614bfc86ceSHeiko Carstens	TRACE_IRQS_OFF
5624bfc86ceSHeiko Carstens	brasl	%r14,preempt_schedule_irq
5634bfc86ceSHeiko Carstens	j	.Lio_return
5644bfc86ceSHeiko Carstens#else
5654bfc86ceSHeiko Carstens	j	.Lio_restore
5664bfc86ceSHeiko Carstens#endif
5674bfc86ceSHeiko Carstens
5684bfc86ceSHeiko Carstens#
5694bfc86ceSHeiko Carstens# Need to do work before returning to userspace, switch to kernel stack
5704bfc86ceSHeiko Carstens#
5714bfc86ceSHeiko Carstens.Lio_work_user:
5724bfc86ceSHeiko Carstens	lg	%r1,__LC_KERNEL_STACK
5734bfc86ceSHeiko Carstens	mvc	STACK_FRAME_OVERHEAD(__PT_SIZE,%r1),0(%r11)
5744bfc86ceSHeiko Carstens	xc	__SF_BACKCHAIN(8,%r1),__SF_BACKCHAIN(%r1)
5754bfc86ceSHeiko Carstens	la	%r11,STACK_FRAME_OVERHEAD(%r1)
5764bfc86ceSHeiko Carstens	lgr	%r15,%r1
5774bfc86ceSHeiko Carstens
5784bfc86ceSHeiko Carstens#
5794bfc86ceSHeiko Carstens# One of the work bits is on. Find out which one.
5804bfc86ceSHeiko Carstens#
5814bfc86ceSHeiko Carstens.Lio_work_tif:
5824bfc86ceSHeiko Carstens	tm	__LC_CPU_FLAGS+7,_CIF_MCCK_PENDING
5834bfc86ceSHeiko Carstens	jo	.Lio_mcck_pending
5844bfc86ceSHeiko Carstens	tm	__TI_flags+7(%r12),_TIF_NEED_RESCHED
5854bfc86ceSHeiko Carstens	jo	.Lio_reschedule
5864bfc86ceSHeiko Carstens	tm	__TI_flags+7(%r12),_TIF_SIGPENDING
5874bfc86ceSHeiko Carstens	jo	.Lio_sigpending
5884bfc86ceSHeiko Carstens	tm	__TI_flags+7(%r12),_TIF_NOTIFY_RESUME
5894bfc86ceSHeiko Carstens	jo	.Lio_notify_resume
5904bfc86ceSHeiko Carstens	tm	__LC_CPU_FLAGS+7,_CIF_ASCE
5914bfc86ceSHeiko Carstens	jo	.Lio_uaccess
5924bfc86ceSHeiko Carstens	j	.Lio_return		# beware of critical section cleanup
5934bfc86ceSHeiko Carstens
5944bfc86ceSHeiko Carstens#
5954bfc86ceSHeiko Carstens# _CIF_MCCK_PENDING is set, call handler
5964bfc86ceSHeiko Carstens#
5974bfc86ceSHeiko Carstens.Lio_mcck_pending:
5984bfc86ceSHeiko Carstens	# TRACE_IRQS_ON already done at .Lio_return
5994bfc86ceSHeiko Carstens	brasl	%r14,s390_handle_mcck	# TIF bit will be cleared by handler
6004bfc86ceSHeiko Carstens	TRACE_IRQS_OFF
6014bfc86ceSHeiko Carstens	j	.Lio_return
6024bfc86ceSHeiko Carstens
6034bfc86ceSHeiko Carstens#
6044bfc86ceSHeiko Carstens# _CIF_ASCE is set, load user space asce
6054bfc86ceSHeiko Carstens#
6064bfc86ceSHeiko Carstens.Lio_uaccess:
6074bfc86ceSHeiko Carstens	ni	__LC_CPU_FLAGS+7,255-_CIF_ASCE
6084bfc86ceSHeiko Carstens	lctlg	%c1,%c1,__LC_USER_ASCE		# load primary asce
6094bfc86ceSHeiko Carstens	j	.Lio_return
6104bfc86ceSHeiko Carstens
6114bfc86ceSHeiko Carstens#
6124bfc86ceSHeiko Carstens# _TIF_NEED_RESCHED is set, call schedule
6134bfc86ceSHeiko Carstens#
6144bfc86ceSHeiko Carstens.Lio_reschedule:
6154bfc86ceSHeiko Carstens	# TRACE_IRQS_ON already done at .Lio_return
6164bfc86ceSHeiko Carstens	ssm	__LC_SVC_NEW_PSW	# reenable interrupts
6174bfc86ceSHeiko Carstens	brasl	%r14,schedule		# call scheduler
6184bfc86ceSHeiko Carstens	ssm	__LC_PGM_NEW_PSW	# disable I/O and ext. interrupts
6194bfc86ceSHeiko Carstens	TRACE_IRQS_OFF
6204bfc86ceSHeiko Carstens	j	.Lio_return
6214bfc86ceSHeiko Carstens
6224bfc86ceSHeiko Carstens#
6234bfc86ceSHeiko Carstens# _TIF_SIGPENDING or is set, call do_signal
6244bfc86ceSHeiko Carstens#
6254bfc86ceSHeiko Carstens.Lio_sigpending:
6264bfc86ceSHeiko Carstens	# TRACE_IRQS_ON already done at .Lio_return
6274bfc86ceSHeiko Carstens	ssm	__LC_SVC_NEW_PSW	# reenable interrupts
6284bfc86ceSHeiko Carstens	lgr	%r2,%r11		# pass pointer to pt_regs
6294bfc86ceSHeiko Carstens	brasl	%r14,do_signal
6304bfc86ceSHeiko Carstens	ssm	__LC_PGM_NEW_PSW	# disable I/O and ext. interrupts
6314bfc86ceSHeiko Carstens	TRACE_IRQS_OFF
6324bfc86ceSHeiko Carstens	j	.Lio_return
6334bfc86ceSHeiko Carstens
6344bfc86ceSHeiko Carstens#
6354bfc86ceSHeiko Carstens# _TIF_NOTIFY_RESUME or is set, call do_notify_resume
6364bfc86ceSHeiko Carstens#
6374bfc86ceSHeiko Carstens.Lio_notify_resume:
6384bfc86ceSHeiko Carstens	# TRACE_IRQS_ON already done at .Lio_return
6394bfc86ceSHeiko Carstens	ssm	__LC_SVC_NEW_PSW	# reenable interrupts
6404bfc86ceSHeiko Carstens	lgr	%r2,%r11		# pass pointer to pt_regs
6414bfc86ceSHeiko Carstens	brasl	%r14,do_notify_resume
6424bfc86ceSHeiko Carstens	ssm	__LC_PGM_NEW_PSW	# disable I/O and ext. interrupts
6434bfc86ceSHeiko Carstens	TRACE_IRQS_OFF
6444bfc86ceSHeiko Carstens	j	.Lio_return
6454bfc86ceSHeiko Carstens
6464bfc86ceSHeiko Carstens/*
6474bfc86ceSHeiko Carstens * External interrupt handler routine
6484bfc86ceSHeiko Carstens */
6494bfc86ceSHeiko CarstensENTRY(ext_int_handler)
6504bfc86ceSHeiko Carstens	STCK	__LC_INT_CLOCK
6514bfc86ceSHeiko Carstens	stpt	__LC_ASYNC_ENTER_TIMER
6524bfc86ceSHeiko Carstens	stmg	%r8,%r15,__LC_SAVE_AREA_ASYNC
6534bfc86ceSHeiko Carstens	lg	%r10,__LC_LAST_BREAK
6544bfc86ceSHeiko Carstens	lg	%r12,__LC_THREAD_INFO
6554bfc86ceSHeiko Carstens	larl	%r13,system_call
6564bfc86ceSHeiko Carstens	lmg	%r8,%r9,__LC_EXT_OLD_PSW
6574bfc86ceSHeiko Carstens	HANDLE_SIE_INTERCEPT %r14,3
6584bfc86ceSHeiko Carstens	SWITCH_ASYNC __LC_SAVE_AREA_ASYNC,__LC_ASYNC_STACK,STACK_SHIFT
6594bfc86ceSHeiko Carstens	tmhh	%r8,0x0001		# interrupting from user ?
6604bfc86ceSHeiko Carstens	jz	.Lext_skip
6614bfc86ceSHeiko Carstens	UPDATE_VTIME %r14,__LC_ASYNC_ENTER_TIMER
6624bfc86ceSHeiko Carstens	LAST_BREAK %r14
6634bfc86ceSHeiko Carstens.Lext_skip:
6644bfc86ceSHeiko Carstens	stmg	%r0,%r7,__PT_R0(%r11)
6654bfc86ceSHeiko Carstens	mvc	__PT_R8(64,%r11),__LC_SAVE_AREA_ASYNC
6664bfc86ceSHeiko Carstens	stmg	%r8,%r9,__PT_PSW(%r11)
6674bfc86ceSHeiko Carstens	lghi	%r1,__LC_EXT_PARAMS2
6684bfc86ceSHeiko Carstens	mvc	__PT_INT_CODE(4,%r11),__LC_EXT_CPU_ADDR
6694bfc86ceSHeiko Carstens	mvc	__PT_INT_PARM(4,%r11),__LC_EXT_PARAMS
6704bfc86ceSHeiko Carstens	mvc	__PT_INT_PARM_LONG(8,%r11),0(%r1)
6714bfc86ceSHeiko Carstens	xc	__PT_FLAGS(8,%r11),__PT_FLAGS(%r11)
6724bfc86ceSHeiko Carstens	TRACE_IRQS_OFF
6734bfc86ceSHeiko Carstens	xc	__SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
6744bfc86ceSHeiko Carstens	lgr	%r2,%r11		# pass pointer to pt_regs
6754bfc86ceSHeiko Carstens	lghi	%r3,EXT_INTERRUPT
6764bfc86ceSHeiko Carstens	brasl	%r14,do_IRQ
6774bfc86ceSHeiko Carstens	j	.Lio_return
6784bfc86ceSHeiko Carstens
6794bfc86ceSHeiko Carstens/*
6804bfc86ceSHeiko Carstens * Load idle PSW. The second "half" of this function is in .Lcleanup_idle.
6814bfc86ceSHeiko Carstens */
6824bfc86ceSHeiko CarstensENTRY(psw_idle)
6834bfc86ceSHeiko Carstens	stg	%r3,__SF_EMPTY(%r15)
6844bfc86ceSHeiko Carstens	larl	%r1,.Lpsw_idle_lpsw+4
6854bfc86ceSHeiko Carstens	stg	%r1,__SF_EMPTY+8(%r15)
6864bfc86ceSHeiko Carstens	STCK	__CLOCK_IDLE_ENTER(%r2)
6874bfc86ceSHeiko Carstens	stpt	__TIMER_IDLE_ENTER(%r2)
6884bfc86ceSHeiko Carstens.Lpsw_idle_lpsw:
6894bfc86ceSHeiko Carstens	lpswe	__SF_EMPTY(%r15)
6904bfc86ceSHeiko Carstens	br	%r14
6914bfc86ceSHeiko Carstens.Lpsw_idle_end:
6924bfc86ceSHeiko Carstens
6934bfc86ceSHeiko Carstens.L__critical_end:
6944bfc86ceSHeiko Carstens
6954bfc86ceSHeiko Carstens/*
6964bfc86ceSHeiko Carstens * Machine check handler routines
6974bfc86ceSHeiko Carstens */
6984bfc86ceSHeiko CarstensENTRY(mcck_int_handler)
6994bfc86ceSHeiko Carstens	STCK	__LC_MCCK_CLOCK
7004bfc86ceSHeiko Carstens	la	%r1,4095		# revalidate r1
7014bfc86ceSHeiko Carstens	spt	__LC_CPU_TIMER_SAVE_AREA-4095(%r1)	# revalidate cpu timer
7024bfc86ceSHeiko Carstens	lmg	%r0,%r15,__LC_GPREGS_SAVE_AREA-4095(%r1)# revalidate gprs
7034bfc86ceSHeiko Carstens	lg	%r10,__LC_LAST_BREAK
7044bfc86ceSHeiko Carstens	lg	%r12,__LC_THREAD_INFO
7054bfc86ceSHeiko Carstens	larl	%r13,system_call
7064bfc86ceSHeiko Carstens	lmg	%r8,%r9,__LC_MCK_OLD_PSW
7074bfc86ceSHeiko Carstens	HANDLE_SIE_INTERCEPT %r14,4
7084bfc86ceSHeiko Carstens	tm	__LC_MCCK_CODE,0x80	# system damage?
7094bfc86ceSHeiko Carstens	jo	.Lmcck_panic		# yes -> rest of mcck code invalid
7104bfc86ceSHeiko Carstens	lghi	%r14,__LC_CPU_TIMER_SAVE_AREA
7114bfc86ceSHeiko Carstens	mvc	__LC_MCCK_ENTER_TIMER(8),0(%r14)
7124bfc86ceSHeiko Carstens	tm	__LC_MCCK_CODE+5,0x02	# stored cpu timer value valid?
7134bfc86ceSHeiko Carstens	jo	3f
7144bfc86ceSHeiko Carstens	la	%r14,__LC_SYNC_ENTER_TIMER
7154bfc86ceSHeiko Carstens	clc	0(8,%r14),__LC_ASYNC_ENTER_TIMER
7164bfc86ceSHeiko Carstens	jl	0f
7174bfc86ceSHeiko Carstens	la	%r14,__LC_ASYNC_ENTER_TIMER
7184bfc86ceSHeiko Carstens0:	clc	0(8,%r14),__LC_EXIT_TIMER
7194bfc86ceSHeiko Carstens	jl	1f
7204bfc86ceSHeiko Carstens	la	%r14,__LC_EXIT_TIMER
7214bfc86ceSHeiko Carstens1:	clc	0(8,%r14),__LC_LAST_UPDATE_TIMER
7224bfc86ceSHeiko Carstens	jl	2f
7234bfc86ceSHeiko Carstens	la	%r14,__LC_LAST_UPDATE_TIMER
7244bfc86ceSHeiko Carstens2:	spt	0(%r14)
7254bfc86ceSHeiko Carstens	mvc	__LC_MCCK_ENTER_TIMER(8),0(%r14)
7264bfc86ceSHeiko Carstens3:	tm	__LC_MCCK_CODE+2,0x09	# mwp + ia of old psw valid?
7274bfc86ceSHeiko Carstens	jno	.Lmcck_panic		# no -> skip cleanup critical
7284bfc86ceSHeiko Carstens	SWITCH_ASYNC __LC_GPREGS_SAVE_AREA+64,__LC_PANIC_STACK,PAGE_SHIFT
7294bfc86ceSHeiko Carstens	tm	%r8,0x0001		# interrupting from user ?
7304bfc86ceSHeiko Carstens	jz	.Lmcck_skip
7314bfc86ceSHeiko Carstens	UPDATE_VTIME %r14,__LC_MCCK_ENTER_TIMER
7324bfc86ceSHeiko Carstens	LAST_BREAK %r14
7334bfc86ceSHeiko Carstens.Lmcck_skip:
7344bfc86ceSHeiko Carstens	lghi	%r14,__LC_GPREGS_SAVE_AREA+64
7354bfc86ceSHeiko Carstens	stmg	%r0,%r7,__PT_R0(%r11)
7364bfc86ceSHeiko Carstens	mvc	__PT_R8(64,%r11),0(%r14)
7374bfc86ceSHeiko Carstens	stmg	%r8,%r9,__PT_PSW(%r11)
7384bfc86ceSHeiko Carstens	xc	__PT_FLAGS(8,%r11),__PT_FLAGS(%r11)
7394bfc86ceSHeiko Carstens	xc	__SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
7404bfc86ceSHeiko Carstens	lgr	%r2,%r11		# pass pointer to pt_regs
7414bfc86ceSHeiko Carstens	brasl	%r14,s390_do_machine_check
7424bfc86ceSHeiko Carstens	tm	__PT_PSW+1(%r11),0x01	# returning to user ?
7434bfc86ceSHeiko Carstens	jno	.Lmcck_return
7444bfc86ceSHeiko Carstens	lg	%r1,__LC_KERNEL_STACK	# switch to kernel stack
7454bfc86ceSHeiko Carstens	mvc	STACK_FRAME_OVERHEAD(__PT_SIZE,%r1),0(%r11)
7464bfc86ceSHeiko Carstens	xc	__SF_BACKCHAIN(8,%r1),__SF_BACKCHAIN(%r1)
7474bfc86ceSHeiko Carstens	la	%r11,STACK_FRAME_OVERHEAD(%r1)
7484bfc86ceSHeiko Carstens	lgr	%r15,%r1
7494bfc86ceSHeiko Carstens	ssm	__LC_PGM_NEW_PSW	# turn dat on, keep irqs off
7504bfc86ceSHeiko Carstens	tm	__LC_CPU_FLAGS+7,_CIF_MCCK_PENDING
7514bfc86ceSHeiko Carstens	jno	.Lmcck_return
7524bfc86ceSHeiko Carstens	TRACE_IRQS_OFF
7534bfc86ceSHeiko Carstens	brasl	%r14,s390_handle_mcck
7544bfc86ceSHeiko Carstens	TRACE_IRQS_ON
7554bfc86ceSHeiko Carstens.Lmcck_return:
7564bfc86ceSHeiko Carstens	lg	%r14,__LC_VDSO_PER_CPU
7574bfc86ceSHeiko Carstens	lmg	%r0,%r10,__PT_R0(%r11)
7584bfc86ceSHeiko Carstens	mvc	__LC_RETURN_MCCK_PSW(16),__PT_PSW(%r11) # move return PSW
7594bfc86ceSHeiko Carstens	tm	__LC_RETURN_MCCK_PSW+1,0x01 # returning to user ?
7604bfc86ceSHeiko Carstens	jno	0f
7614bfc86ceSHeiko Carstens	stpt	__LC_EXIT_TIMER
7624bfc86ceSHeiko Carstens	mvc	__VDSO_ECTG_BASE(16,%r14),__LC_EXIT_TIMER
7634bfc86ceSHeiko Carstens0:	lmg	%r11,%r15,__PT_R11(%r11)
7644bfc86ceSHeiko Carstens	lpswe	__LC_RETURN_MCCK_PSW
7654bfc86ceSHeiko Carstens
7664bfc86ceSHeiko Carstens.Lmcck_panic:
7674bfc86ceSHeiko Carstens	lg	%r14,__LC_PANIC_STACK
7684bfc86ceSHeiko Carstens	slgr	%r14,%r15
7694bfc86ceSHeiko Carstens	srag	%r14,%r14,PAGE_SHIFT
7704bfc86ceSHeiko Carstens	jz	0f
7714bfc86ceSHeiko Carstens	lg	%r15,__LC_PANIC_STACK
7724bfc86ceSHeiko Carstens0:	aghi	%r15,-(STACK_FRAME_OVERHEAD + __PT_SIZE)
7734bfc86ceSHeiko Carstens	j	.Lmcck_skip
7744bfc86ceSHeiko Carstens
7754bfc86ceSHeiko Carstens#
7764bfc86ceSHeiko Carstens# PSW restart interrupt handler
7774bfc86ceSHeiko Carstens#
7784bfc86ceSHeiko CarstensENTRY(restart_int_handler)
7794bfc86ceSHeiko Carstens	stg	%r15,__LC_SAVE_AREA_RESTART
7804bfc86ceSHeiko Carstens	lg	%r15,__LC_RESTART_STACK
7814bfc86ceSHeiko Carstens	aghi	%r15,-__PT_SIZE			# create pt_regs on stack
7824bfc86ceSHeiko Carstens	xc	0(__PT_SIZE,%r15),0(%r15)
7834bfc86ceSHeiko Carstens	stmg	%r0,%r14,__PT_R0(%r15)
7844bfc86ceSHeiko Carstens	mvc	__PT_R15(8,%r15),__LC_SAVE_AREA_RESTART
7854bfc86ceSHeiko Carstens	mvc	__PT_PSW(16,%r15),__LC_RST_OLD_PSW # store restart old psw
7864bfc86ceSHeiko Carstens	aghi	%r15,-STACK_FRAME_OVERHEAD	# create stack frame on stack
7874bfc86ceSHeiko Carstens	xc	0(STACK_FRAME_OVERHEAD,%r15),0(%r15)
7884bfc86ceSHeiko Carstens	lg	%r1,__LC_RESTART_FN		# load fn, parm & source cpu
7894bfc86ceSHeiko Carstens	lg	%r2,__LC_RESTART_DATA
7904bfc86ceSHeiko Carstens	lg	%r3,__LC_RESTART_SOURCE
7914bfc86ceSHeiko Carstens	ltgr	%r3,%r3				# test source cpu address
7924bfc86ceSHeiko Carstens	jm	1f				# negative -> skip source stop
7934bfc86ceSHeiko Carstens0:	sigp	%r4,%r3,SIGP_SENSE		# sigp sense to source cpu
7944bfc86ceSHeiko Carstens	brc	10,0b				# wait for status stored
7954bfc86ceSHeiko Carstens1:	basr	%r14,%r1			# call function
7964bfc86ceSHeiko Carstens	stap	__SF_EMPTY(%r15)		# store cpu address
7974bfc86ceSHeiko Carstens	llgh	%r3,__SF_EMPTY(%r15)
7984bfc86ceSHeiko Carstens2:	sigp	%r4,%r3,SIGP_STOP		# sigp stop to current cpu
7994bfc86ceSHeiko Carstens	brc	2,2b
8004bfc86ceSHeiko Carstens3:	j	3b
8014bfc86ceSHeiko Carstens
8024bfc86ceSHeiko Carstens	.section .kprobes.text, "ax"
8034bfc86ceSHeiko Carstens
8044bfc86ceSHeiko Carstens#ifdef CONFIG_CHECK_STACK
8054bfc86ceSHeiko Carstens/*
8064bfc86ceSHeiko Carstens * The synchronous or the asynchronous stack overflowed. We are dead.
8074bfc86ceSHeiko Carstens * No need to properly save the registers, we are going to panic anyway.
8084bfc86ceSHeiko Carstens * Setup a pt_regs so that show_trace can provide a good call trace.
8094bfc86ceSHeiko Carstens */
8104bfc86ceSHeiko Carstensstack_overflow:
8114bfc86ceSHeiko Carstens	lg	%r15,__LC_PANIC_STACK	# change to panic stack
8124bfc86ceSHeiko Carstens	la	%r11,STACK_FRAME_OVERHEAD(%r15)
8134bfc86ceSHeiko Carstens	stmg	%r0,%r7,__PT_R0(%r11)
8144bfc86ceSHeiko Carstens	stmg	%r8,%r9,__PT_PSW(%r11)
8154bfc86ceSHeiko Carstens	mvc	__PT_R8(64,%r11),0(%r14)
8164bfc86ceSHeiko Carstens	stg	%r10,__PT_ORIG_GPR2(%r11) # store last break to orig_gpr2
8174bfc86ceSHeiko Carstens	xc	__SF_BACKCHAIN(8,%r15),__SF_BACKCHAIN(%r15)
8184bfc86ceSHeiko Carstens	lgr	%r2,%r11		# pass pointer to pt_regs
8194bfc86ceSHeiko Carstens	jg	kernel_stack_overflow
8204bfc86ceSHeiko Carstens#endif
8214bfc86ceSHeiko Carstens
8224bfc86ceSHeiko Carstens	.align	8
8234bfc86ceSHeiko Carstens.Lcleanup_table:
8244bfc86ceSHeiko Carstens	.quad	system_call
8254bfc86ceSHeiko Carstens	.quad	.Lsysc_do_svc
8264bfc86ceSHeiko Carstens	.quad	.Lsysc_tif
8274bfc86ceSHeiko Carstens	.quad	.Lsysc_restore
8284bfc86ceSHeiko Carstens	.quad	.Lsysc_done
8294bfc86ceSHeiko Carstens	.quad	.Lio_tif
8304bfc86ceSHeiko Carstens	.quad	.Lio_restore
8314bfc86ceSHeiko Carstens	.quad	.Lio_done
8324bfc86ceSHeiko Carstens	.quad	psw_idle
8334bfc86ceSHeiko Carstens	.quad	.Lpsw_idle_end
8344bfc86ceSHeiko Carstens
8354bfc86ceSHeiko Carstenscleanup_critical:
8364bfc86ceSHeiko Carstens	clg	%r9,BASED(.Lcleanup_table)	# system_call
8374bfc86ceSHeiko Carstens	jl	0f
8384bfc86ceSHeiko Carstens	clg	%r9,BASED(.Lcleanup_table+8)	# .Lsysc_do_svc
8394bfc86ceSHeiko Carstens	jl	.Lcleanup_system_call
8404bfc86ceSHeiko Carstens	clg	%r9,BASED(.Lcleanup_table+16)	# .Lsysc_tif
8414bfc86ceSHeiko Carstens	jl	0f
8424bfc86ceSHeiko Carstens	clg	%r9,BASED(.Lcleanup_table+24)	# .Lsysc_restore
8434bfc86ceSHeiko Carstens	jl	.Lcleanup_sysc_tif
8444bfc86ceSHeiko Carstens	clg	%r9,BASED(.Lcleanup_table+32)	# .Lsysc_done
8454bfc86ceSHeiko Carstens	jl	.Lcleanup_sysc_restore
8464bfc86ceSHeiko Carstens	clg	%r9,BASED(.Lcleanup_table+40)	# .Lio_tif
8474bfc86ceSHeiko Carstens	jl	0f
8484bfc86ceSHeiko Carstens	clg	%r9,BASED(.Lcleanup_table+48)	# .Lio_restore
8494bfc86ceSHeiko Carstens	jl	.Lcleanup_io_tif
8504bfc86ceSHeiko Carstens	clg	%r9,BASED(.Lcleanup_table+56)	# .Lio_done
8514bfc86ceSHeiko Carstens	jl	.Lcleanup_io_restore
8524bfc86ceSHeiko Carstens	clg	%r9,BASED(.Lcleanup_table+64)	# psw_idle
8534bfc86ceSHeiko Carstens	jl	0f
8544bfc86ceSHeiko Carstens	clg	%r9,BASED(.Lcleanup_table+72)	# .Lpsw_idle_end
8554bfc86ceSHeiko Carstens	jl	.Lcleanup_idle
8564bfc86ceSHeiko Carstens0:	br	%r14
8574bfc86ceSHeiko Carstens
8584bfc86ceSHeiko Carstens
8594bfc86ceSHeiko Carstens.Lcleanup_system_call:
8604bfc86ceSHeiko Carstens	# check if stpt has been executed
8614bfc86ceSHeiko Carstens	clg	%r9,BASED(.Lcleanup_system_call_insn)
8624bfc86ceSHeiko Carstens	jh	0f
8634bfc86ceSHeiko Carstens	mvc	__LC_SYNC_ENTER_TIMER(8),__LC_ASYNC_ENTER_TIMER
8644bfc86ceSHeiko Carstens	cghi	%r11,__LC_SAVE_AREA_ASYNC
8654bfc86ceSHeiko Carstens	je	0f
8664bfc86ceSHeiko Carstens	mvc	__LC_SYNC_ENTER_TIMER(8),__LC_MCCK_ENTER_TIMER
8674bfc86ceSHeiko Carstens0:	# check if stmg has been executed
8684bfc86ceSHeiko Carstens	clg	%r9,BASED(.Lcleanup_system_call_insn+8)
8694bfc86ceSHeiko Carstens	jh	0f
8704bfc86ceSHeiko Carstens	mvc	__LC_SAVE_AREA_SYNC(64),0(%r11)
8714bfc86ceSHeiko Carstens0:	# check if base register setup + TIF bit load has been done
8724bfc86ceSHeiko Carstens	clg	%r9,BASED(.Lcleanup_system_call_insn+16)
8734bfc86ceSHeiko Carstens	jhe	0f
8744bfc86ceSHeiko Carstens	# set up saved registers r10 and r12
8754bfc86ceSHeiko Carstens	stg	%r10,16(%r11)		# r10 last break
8764bfc86ceSHeiko Carstens	stg	%r12,32(%r11)		# r12 thread-info pointer
8774bfc86ceSHeiko Carstens0:	# check if the user time update has been done
8784bfc86ceSHeiko Carstens	clg	%r9,BASED(.Lcleanup_system_call_insn+24)
8794bfc86ceSHeiko Carstens	jh	0f
8804bfc86ceSHeiko Carstens	lg	%r15,__LC_EXIT_TIMER
8814bfc86ceSHeiko Carstens	slg	%r15,__LC_SYNC_ENTER_TIMER
8824bfc86ceSHeiko Carstens	alg	%r15,__LC_USER_TIMER
8834bfc86ceSHeiko Carstens	stg	%r15,__LC_USER_TIMER
8844bfc86ceSHeiko Carstens0:	# check if the system time update has been done
8854bfc86ceSHeiko Carstens	clg	%r9,BASED(.Lcleanup_system_call_insn+32)
8864bfc86ceSHeiko Carstens	jh	0f
8874bfc86ceSHeiko Carstens	lg	%r15,__LC_LAST_UPDATE_TIMER
8884bfc86ceSHeiko Carstens	slg	%r15,__LC_EXIT_TIMER
8894bfc86ceSHeiko Carstens	alg	%r15,__LC_SYSTEM_TIMER
8904bfc86ceSHeiko Carstens	stg	%r15,__LC_SYSTEM_TIMER
8914bfc86ceSHeiko Carstens0:	# update accounting time stamp
8924bfc86ceSHeiko Carstens	mvc	__LC_LAST_UPDATE_TIMER(8),__LC_SYNC_ENTER_TIMER
8934bfc86ceSHeiko Carstens	# do LAST_BREAK
8944bfc86ceSHeiko Carstens	lg	%r9,16(%r11)
8954bfc86ceSHeiko Carstens	srag	%r9,%r9,23
8964bfc86ceSHeiko Carstens	jz	0f
8974bfc86ceSHeiko Carstens	mvc	__TI_last_break(8,%r12),16(%r11)
8984bfc86ceSHeiko Carstens0:	# set up saved register r11
8994bfc86ceSHeiko Carstens	lg	%r15,__LC_KERNEL_STACK
9004bfc86ceSHeiko Carstens	la	%r9,STACK_FRAME_OVERHEAD(%r15)
9014bfc86ceSHeiko Carstens	stg	%r9,24(%r11)		# r11 pt_regs pointer
9024bfc86ceSHeiko Carstens	# fill pt_regs
9034bfc86ceSHeiko Carstens	mvc	__PT_R8(64,%r9),__LC_SAVE_AREA_SYNC
9044bfc86ceSHeiko Carstens	stmg	%r0,%r7,__PT_R0(%r9)
9054bfc86ceSHeiko Carstens	mvc	__PT_PSW(16,%r9),__LC_SVC_OLD_PSW
9064bfc86ceSHeiko Carstens	mvc	__PT_INT_CODE(4,%r9),__LC_SVC_ILC
9074bfc86ceSHeiko Carstens	xc	__PT_FLAGS(8,%r9),__PT_FLAGS(%r9)
9084bfc86ceSHeiko Carstens	mvi	__PT_FLAGS+7(%r9),_PIF_SYSCALL
9094bfc86ceSHeiko Carstens	# setup saved register r15
9104bfc86ceSHeiko Carstens	stg	%r15,56(%r11)		# r15 stack pointer
9114bfc86ceSHeiko Carstens	# set new psw address and exit
9124bfc86ceSHeiko Carstens	larl	%r9,.Lsysc_do_svc
9134bfc86ceSHeiko Carstens	br	%r14
9144bfc86ceSHeiko Carstens.Lcleanup_system_call_insn:
9154bfc86ceSHeiko Carstens	.quad	system_call
9164bfc86ceSHeiko Carstens	.quad	.Lsysc_stmg
9174bfc86ceSHeiko Carstens	.quad	.Lsysc_per
9184bfc86ceSHeiko Carstens	.quad	.Lsysc_vtime+18
9194bfc86ceSHeiko Carstens	.quad	.Lsysc_vtime+42
9204bfc86ceSHeiko Carstens
9214bfc86ceSHeiko Carstens.Lcleanup_sysc_tif:
9224bfc86ceSHeiko Carstens	larl	%r9,.Lsysc_tif
9234bfc86ceSHeiko Carstens	br	%r14
9244bfc86ceSHeiko Carstens
9254bfc86ceSHeiko Carstens.Lcleanup_sysc_restore:
9264bfc86ceSHeiko Carstens	clg	%r9,BASED(.Lcleanup_sysc_restore_insn)
9274bfc86ceSHeiko Carstens	je	0f
9284bfc86ceSHeiko Carstens	lg	%r9,24(%r11)		# get saved pointer to pt_regs
9294bfc86ceSHeiko Carstens	mvc	__LC_RETURN_PSW(16),__PT_PSW(%r9)
9304bfc86ceSHeiko Carstens	mvc	0(64,%r11),__PT_R8(%r9)
9314bfc86ceSHeiko Carstens	lmg	%r0,%r7,__PT_R0(%r9)
9324bfc86ceSHeiko Carstens0:	lmg	%r8,%r9,__LC_RETURN_PSW
9334bfc86ceSHeiko Carstens	br	%r14
9344bfc86ceSHeiko Carstens.Lcleanup_sysc_restore_insn:
9354bfc86ceSHeiko Carstens	.quad	.Lsysc_done - 4
9364bfc86ceSHeiko Carstens
9374bfc86ceSHeiko Carstens.Lcleanup_io_tif:
9384bfc86ceSHeiko Carstens	larl	%r9,.Lio_tif
9394bfc86ceSHeiko Carstens	br	%r14
9404bfc86ceSHeiko Carstens
9414bfc86ceSHeiko Carstens.Lcleanup_io_restore:
9424bfc86ceSHeiko Carstens	clg	%r9,BASED(.Lcleanup_io_restore_insn)
9434bfc86ceSHeiko Carstens	je	0f
9444bfc86ceSHeiko Carstens	lg	%r9,24(%r11)		# get saved r11 pointer to pt_regs
9454bfc86ceSHeiko Carstens	mvc	__LC_RETURN_PSW(16),__PT_PSW(%r9)
9464bfc86ceSHeiko Carstens	mvc	0(64,%r11),__PT_R8(%r9)
9474bfc86ceSHeiko Carstens	lmg	%r0,%r7,__PT_R0(%r9)
9484bfc86ceSHeiko Carstens0:	lmg	%r8,%r9,__LC_RETURN_PSW
9494bfc86ceSHeiko Carstens	br	%r14
9504bfc86ceSHeiko Carstens.Lcleanup_io_restore_insn:
9514bfc86ceSHeiko Carstens	.quad	.Lio_done - 4
9524bfc86ceSHeiko Carstens
9534bfc86ceSHeiko Carstens.Lcleanup_idle:
9544bfc86ceSHeiko Carstens	# copy interrupt clock & cpu timer
9554bfc86ceSHeiko Carstens	mvc	__CLOCK_IDLE_EXIT(8,%r2),__LC_INT_CLOCK
9564bfc86ceSHeiko Carstens	mvc	__TIMER_IDLE_EXIT(8,%r2),__LC_ASYNC_ENTER_TIMER
9574bfc86ceSHeiko Carstens	cghi	%r11,__LC_SAVE_AREA_ASYNC
9584bfc86ceSHeiko Carstens	je	0f
9594bfc86ceSHeiko Carstens	mvc	__CLOCK_IDLE_EXIT(8,%r2),__LC_MCCK_CLOCK
9604bfc86ceSHeiko Carstens	mvc	__TIMER_IDLE_EXIT(8,%r2),__LC_MCCK_ENTER_TIMER
9614bfc86ceSHeiko Carstens0:	# check if stck & stpt have been executed
9624bfc86ceSHeiko Carstens	clg	%r9,BASED(.Lcleanup_idle_insn)
9634bfc86ceSHeiko Carstens	jhe	1f
9644bfc86ceSHeiko Carstens	mvc	__CLOCK_IDLE_ENTER(8,%r2),__CLOCK_IDLE_EXIT(%r2)
9654bfc86ceSHeiko Carstens	mvc	__TIMER_IDLE_ENTER(8,%r2),__TIMER_IDLE_EXIT(%r2)
9664bfc86ceSHeiko Carstens1:	# account system time going idle
9674bfc86ceSHeiko Carstens	lg	%r9,__LC_STEAL_TIMER
9684bfc86ceSHeiko Carstens	alg	%r9,__CLOCK_IDLE_ENTER(%r2)
9694bfc86ceSHeiko Carstens	slg	%r9,__LC_LAST_UPDATE_CLOCK
9704bfc86ceSHeiko Carstens	stg	%r9,__LC_STEAL_TIMER
9714bfc86ceSHeiko Carstens	mvc	__LC_LAST_UPDATE_CLOCK(8),__CLOCK_IDLE_EXIT(%r2)
9724bfc86ceSHeiko Carstens	lg	%r9,__LC_SYSTEM_TIMER
9734bfc86ceSHeiko Carstens	alg	%r9,__LC_LAST_UPDATE_TIMER
9744bfc86ceSHeiko Carstens	slg	%r9,__TIMER_IDLE_ENTER(%r2)
9754bfc86ceSHeiko Carstens	stg	%r9,__LC_SYSTEM_TIMER
9764bfc86ceSHeiko Carstens	mvc	__LC_LAST_UPDATE_TIMER(8),__TIMER_IDLE_EXIT(%r2)
9774bfc86ceSHeiko Carstens	# prepare return psw
9784bfc86ceSHeiko Carstens	nihh	%r8,0xfcfd		# clear irq & wait state bits
9794bfc86ceSHeiko Carstens	lg	%r9,48(%r11)		# return from psw_idle
9804bfc86ceSHeiko Carstens	br	%r14
9814bfc86ceSHeiko Carstens.Lcleanup_idle_insn:
9824bfc86ceSHeiko Carstens	.quad	.Lpsw_idle_lpsw
9834bfc86ceSHeiko Carstens
9844bfc86ceSHeiko Carstens/*
9854bfc86ceSHeiko Carstens * Integer constants
9864bfc86ceSHeiko Carstens */
9874bfc86ceSHeiko Carstens	.align	8
9884bfc86ceSHeiko Carstens.Lcritical_start:
9894bfc86ceSHeiko Carstens	.quad	.L__critical_start
9904bfc86ceSHeiko Carstens.Lcritical_length:
9914bfc86ceSHeiko Carstens	.quad	.L__critical_end - .L__critical_start
9924bfc86ceSHeiko Carstens
9934bfc86ceSHeiko Carstens
9944bfc86ceSHeiko Carstens#if IS_ENABLED(CONFIG_KVM)
9954bfc86ceSHeiko Carstens/*
9964bfc86ceSHeiko Carstens * sie64a calling convention:
9974bfc86ceSHeiko Carstens * %r2 pointer to sie control block
9984bfc86ceSHeiko Carstens * %r3 guest register save area
9994bfc86ceSHeiko Carstens */
10004bfc86ceSHeiko CarstensENTRY(sie64a)
10014bfc86ceSHeiko Carstens	stmg	%r6,%r14,__SF_GPRS(%r15)	# save kernel registers
10024bfc86ceSHeiko Carstens	stg	%r2,__SF_EMPTY(%r15)		# save control block pointer
10034bfc86ceSHeiko Carstens	stg	%r3,__SF_EMPTY+8(%r15)		# save guest register save area
10044bfc86ceSHeiko Carstens	xc	__SF_EMPTY+16(16,%r15),__SF_EMPTY+16(%r15) # host id & reason
10054bfc86ceSHeiko Carstens	lmg	%r0,%r13,0(%r3)			# load guest gprs 0-13
10064bfc86ceSHeiko Carstens	lg	%r14,__LC_GMAP			# get gmap pointer
10074bfc86ceSHeiko Carstens	ltgr	%r14,%r14
10084bfc86ceSHeiko Carstens	jz	.Lsie_gmap
10094bfc86ceSHeiko Carstens	lctlg	%c1,%c1,__GMAP_ASCE(%r14)	# load primary asce
10104bfc86ceSHeiko Carstens.Lsie_gmap:
10114bfc86ceSHeiko Carstens	lg	%r14,__SF_EMPTY(%r15)		# get control block pointer
10124bfc86ceSHeiko Carstens	oi	__SIE_PROG0C+3(%r14),1		# we are going into SIE now
10138e236546SChristian Borntraeger	tm	__SIE_PROG20+3(%r14),3		# last exit...
10144bfc86ceSHeiko Carstens	jnz	.Lsie_done
10154bfc86ceSHeiko Carstens	LPP	__SF_EMPTY(%r15)		# set guest id
10164bfc86ceSHeiko Carstens	sie	0(%r14)
10174bfc86ceSHeiko Carstens.Lsie_done:
10184bfc86ceSHeiko Carstens	LPP	__SF_EMPTY+16(%r15)		# set host id
10194bfc86ceSHeiko Carstens	ni	__SIE_PROG0C+3(%r14),0xfe	# no longer in SIE
10204bfc86ceSHeiko Carstens	lctlg	%c1,%c1,__LC_USER_ASCE		# load primary asce
10214bfc86ceSHeiko Carstens# some program checks are suppressing. C code (e.g. do_protection_exception)
10224bfc86ceSHeiko Carstens# will rewind the PSW by the ILC, which is 4 bytes in case of SIE. Other
10234bfc86ceSHeiko Carstens# instructions between sie64a and .Lsie_done should not cause program
10244bfc86ceSHeiko Carstens# interrupts. So lets use a nop (47 00 00 00) as a landing pad.
10254bfc86ceSHeiko Carstens# See also HANDLE_SIE_INTERCEPT
10264bfc86ceSHeiko Carstens.Lrewind_pad:
10274bfc86ceSHeiko Carstens	nop	0
10284bfc86ceSHeiko Carstens	.globl sie_exit
10294bfc86ceSHeiko Carstenssie_exit:
10304bfc86ceSHeiko Carstens	lg	%r14,__SF_EMPTY+8(%r15)		# load guest register save area
10314bfc86ceSHeiko Carstens	stmg	%r0,%r13,0(%r14)		# save guest gprs 0-13
10324bfc86ceSHeiko Carstens	lmg	%r6,%r14,__SF_GPRS(%r15)	# restore kernel registers
10334bfc86ceSHeiko Carstens	lg	%r2,__SF_EMPTY+24(%r15)		# return exit reason code
10344bfc86ceSHeiko Carstens	br	%r14
10354bfc86ceSHeiko Carstens.Lsie_fault:
10364bfc86ceSHeiko Carstens	lghi	%r14,-EFAULT
10374bfc86ceSHeiko Carstens	stg	%r14,__SF_EMPTY+24(%r15)	# set exit reason code
10384bfc86ceSHeiko Carstens	j	sie_exit
10394bfc86ceSHeiko Carstens
10404bfc86ceSHeiko Carstens	.align	8
10414bfc86ceSHeiko Carstens.Lsie_critical:
10424bfc86ceSHeiko Carstens	.quad	.Lsie_gmap
10434bfc86ceSHeiko Carstens.Lsie_critical_length:
10444bfc86ceSHeiko Carstens	.quad	.Lsie_done - .Lsie_gmap
10454bfc86ceSHeiko Carstens
10464bfc86ceSHeiko Carstens	EX_TABLE(.Lrewind_pad,.Lsie_fault)
10474bfc86ceSHeiko Carstens	EX_TABLE(sie_exit,.Lsie_fault)
10484bfc86ceSHeiko Carstens#endif
10494bfc86ceSHeiko Carstens
10504bfc86ceSHeiko Carstens	.section .rodata, "a"
1051a876cb3fSHeiko Carstens#define SYSCALL(esame,emu)	.long esame
10524bfc86ceSHeiko Carstens	.globl	sys_call_table
10534bfc86ceSHeiko Carstenssys_call_table:
10544bfc86ceSHeiko Carstens#include "syscalls.S"
10554bfc86ceSHeiko Carstens#undef SYSCALL
10564bfc86ceSHeiko Carstens
10574bfc86ceSHeiko Carstens#ifdef CONFIG_COMPAT
10584bfc86ceSHeiko Carstens
1059a876cb3fSHeiko Carstens#define SYSCALL(esame,emu)	.long emu
10604bfc86ceSHeiko Carstens	.globl	sys_call_table_emu
10614bfc86ceSHeiko Carstenssys_call_table_emu:
10624bfc86ceSHeiko Carstens#include "syscalls.S"
10634bfc86ceSHeiko Carstens#undef SYSCALL
10644bfc86ceSHeiko Carstens#endif
1065