xref: /kvm-unit-tests/s390x/cpu-sie.S (revision f372d35fb1bea99e401cc6eafc798aecfce29a07)
1/* SPDX-License-Identifier: GPL-2.0-only */
2/*
3 * s390x SIE assembly library
4 *
5 * Copyright (c) 2019 IBM Corp.
6 *
7 * Authors:
8 *    Janosch Frank <frankja@linux.ibm.com>
9 */
10#include <asm/asm-offsets.h>
11
12/*
13 * sie64a calling convention:
14 * %r2 pointer to sie control block
15 * %r3 guest register save area
16 */
17.globl sie64a
18sie64a:
19	# Save host grs, fprs, fpc
20	stmg	%r0,%r14,SIE_SAVEAREA_HOST_GRS(%r3)	# save kernel registers
21	.irp i, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
22	std	\i, \i * 8  + SIE_SAVEAREA_HOST_FPRS(%r3)
23	.endr
24	stfpc	SIE_SAVEAREA_HOST_FPC(%r3)
25
26	stctg	%c1, %c1, SIE_SAVEAREA_HOST_ASCE(%r3)
27	lctlg	%c1, %c1, SIE_SAVEAREA_GUEST_ASCE(%r3)
28
29	# Store scb and save_area pointer into stack frame
30	stg	%r2,__SF_SIE_CONTROL(%r15)	# save control block pointer
31	stg	%r3,__SF_SIE_SAVEAREA(%r15)	# save guest register save area
32.globl sie_entry_gregs
33sie_entry_gregs:
34	# Load guest's gprs, fprs and fpc
35	.irp i, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
36	ld	\i, \i * 8 + SIE_SAVEAREA_GUEST_FPRS(%r3)
37	.endr
38	lfpc	SIE_SAVEAREA_GUEST_FPC(%r3)
39	lmg	%r0,%r13,SIE_SAVEAREA_GUEST_GRS(%r3)
40
41	# Move scb ptr into r14 for the sie instruction
42	lg	%r14,__SF_SIE_CONTROL(%r15)
43
44.globl sie_entry
45sie_entry:
46	sie	0(%r14)
47	nopr	7
48	nopr	7
49	nopr	7
50
51.globl sie_exit
52sie_exit:
53	# Load guest register save area
54	lg	%r14,__SF_SIE_SAVEAREA(%r15)
55
56	# Restore the host asce
57	lctlg	%c1, %c1, SIE_SAVEAREA_HOST_ASCE(%r14)
58
59	# Store guest's gprs, fprs and fpc
60	stmg	%r0,%r13,SIE_SAVEAREA_GUEST_GRS(%r14)	# save guest gprs 0-13
61	.irp i, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
62	std	\i, \i * 8  + SIE_SAVEAREA_GUEST_FPRS(%r14)
63	.endr
64	stfpc	SIE_SAVEAREA_GUEST_FPC(%r14)
65
66	# Restore host's gprs, fprs and fpc
67	.irp i, 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15
68	ld	\i, \i * 8 + SIE_SAVEAREA_HOST_FPRS(%r14)
69	.endr
70	lfpc	SIE_SAVEAREA_HOST_FPC(%r14)
71	lmg	%r0,%r14,SIE_SAVEAREA_HOST_GRS(%r14)	# restore kernel registers
72.globl sie_exit_gregs
73sie_exit_gregs:
74	br	%r14
75