xref: /kvm-unit-tests/lib/s390x/asm/arch_def.h (revision c08c320b20287d54c7699a8494619e450b0397b2) !
1cfb204f9SDavid Hildenbrand /*
2cfb204f9SDavid Hildenbrand  * Copyright (c) 2017 Red Hat Inc
3cfb204f9SDavid Hildenbrand  *
4cfb204f9SDavid Hildenbrand  * Authors:
5cfb204f9SDavid Hildenbrand  *  David Hildenbrand <david@redhat.com>
6cfb204f9SDavid Hildenbrand  *
7cfb204f9SDavid Hildenbrand  * This code is free software; you can redistribute it and/or modify it
8cfb204f9SDavid Hildenbrand  * under the terms of the GNU Library General Public License version 2.
9cfb204f9SDavid Hildenbrand  */
10cfb204f9SDavid Hildenbrand #ifndef _ASM_S390X_ARCH_DEF_H_
11cfb204f9SDavid Hildenbrand #define _ASM_S390X_ARCH_DEF_H_
12cfb204f9SDavid Hildenbrand 
13cfb204f9SDavid Hildenbrand struct psw {
14cfb204f9SDavid Hildenbrand 	uint64_t	mask;
15cfb204f9SDavid Hildenbrand 	uint64_t	addr;
16cfb204f9SDavid Hildenbrand };
17cfb204f9SDavid Hildenbrand 
18*c08c320bSDavid Hildenbrand #define PSW_MASK_DAT			0x0400000000000000UL
19*c08c320bSDavid Hildenbrand 
20cfb204f9SDavid Hildenbrand struct lowcore {
21cfb204f9SDavid Hildenbrand 	uint8_t		pad_0x0000[0x0080 - 0x0000];	/* 0x0000 */
22cfb204f9SDavid Hildenbrand 	uint32_t	ext_int_param;			/* 0x0080 */
23cfb204f9SDavid Hildenbrand 	uint16_t	cpu_addr;			/* 0x0084 */
24cfb204f9SDavid Hildenbrand 	uint16_t	ext_int_code;			/* 0x0086 */
25cfb204f9SDavid Hildenbrand 	uint16_t	svc_int_id;			/* 0x0088 */
26cfb204f9SDavid Hildenbrand 	uint16_t	svc_int_code;			/* 0x008a */
27cfb204f9SDavid Hildenbrand 	uint16_t	pgm_int_id;			/* 0x008c */
28cfb204f9SDavid Hildenbrand 	uint16_t	pgm_int_code;			/* 0x008e */
29cfb204f9SDavid Hildenbrand 	uint32_t	dxc_vxc;			/* 0x0090 */
30cfb204f9SDavid Hildenbrand 	uint16_t	mon_class_nb;			/* 0x0094 */
31cfb204f9SDavid Hildenbrand 	uint8_t		per_code;			/* 0x0096 */
32cfb204f9SDavid Hildenbrand 	uint8_t		per_atmid;			/* 0x0097 */
33cfb204f9SDavid Hildenbrand 	uint64_t	per_addr;			/* 0x0098 */
34cfb204f9SDavid Hildenbrand 	uint8_t		exc_acc_id;			/* 0x00a0 */
35cfb204f9SDavid Hildenbrand 	uint8_t		per_acc_id;			/* 0x00a1 */
36cfb204f9SDavid Hildenbrand 	uint8_t		op_acc_id;			/* 0x00a2 */
37cfb204f9SDavid Hildenbrand 	uint8_t		arch_mode_id;			/* 0x00a3 */
38cfb204f9SDavid Hildenbrand 	uint8_t		pad_0x00a4[0x00a8 - 0x00a4];	/* 0x00a4 */
39cfb204f9SDavid Hildenbrand 	uint64_t	trans_exc_id;			/* 0x00a8 */
40cfb204f9SDavid Hildenbrand 	uint64_t	mon_code;			/* 0x00b0 */
41cfb204f9SDavid Hildenbrand 	uint32_t	subsys_id_word;			/* 0x00b8 */
42cfb204f9SDavid Hildenbrand 	uint32_t	io_int_param;			/* 0x00bc */
43cfb204f9SDavid Hildenbrand 	uint32_t	io_int_word;			/* 0x00c0 */
44cfb204f9SDavid Hildenbrand 	uint8_t		pad_0x00c4[0x00c8 - 0x00c4];	/* 0x00c4 */
45cfb204f9SDavid Hildenbrand 	uint32_t	stfl;				/* 0x00c8 */
46cfb204f9SDavid Hildenbrand 	uint8_t		pad_0x00cc[0x00e8 - 0x00cc];	/* 0x00cc */
47cfb204f9SDavid Hildenbrand 	uint64_t	mcck_int_code;			/* 0x00e8 */
48cfb204f9SDavid Hildenbrand 	uint8_t		pad_0x00f0[0x00f4 - 0x00f0];	/* 0x00f0 */
49cfb204f9SDavid Hildenbrand 	uint32_t	ext_damage_code;		/* 0x00f4 */
50cfb204f9SDavid Hildenbrand 	uint64_t	failing_storage_addr;		/* 0x00f8 */
51cfb204f9SDavid Hildenbrand 	uint64_t	emon_ca_origin;			/* 0x0100 */
52cfb204f9SDavid Hildenbrand 	uint32_t	emon_ca_size;			/* 0x0108 */
53cfb204f9SDavid Hildenbrand 	uint32_t	emon_exc_count;			/* 0x010c */
54cfb204f9SDavid Hildenbrand 	uint64_t	breaking_event_addr;		/* 0x0110 */
55cfb204f9SDavid Hildenbrand 	uint8_t		pad_0x0118[0x0120 - 0x0118];	/* 0x0118 */
56cfb204f9SDavid Hildenbrand 	struct psw	restart_old_psw;		/* 0x0120 */
57cfb204f9SDavid Hildenbrand 	struct psw	ext_old_psw;			/* 0x0130 */
58cfb204f9SDavid Hildenbrand 	struct psw	svc_old_psw;			/* 0x0140 */
59cfb204f9SDavid Hildenbrand 	struct psw	pgm_old_psw;			/* 0x0150 */
60cfb204f9SDavid Hildenbrand 	struct psw	mcck_old_psw;			/* 0x0160 */
61cfb204f9SDavid Hildenbrand 	struct psw	io_old_psw;			/* 0x0170 */
62cfb204f9SDavid Hildenbrand 	uint8_t		pad_0x0180[0x01a0 - 0x0180];	/* 0x0180 */
63cfb204f9SDavid Hildenbrand 	struct psw	restart_new_psw;		/* 0x01a0 */
64cfb204f9SDavid Hildenbrand 	struct psw	ext_new_psw;			/* 0x01b0 */
65cfb204f9SDavid Hildenbrand 	struct psw	svc_new_psw;			/* 0x01c0 */
66cfb204f9SDavid Hildenbrand 	struct psw	pgm_new_psw;			/* 0x01d0 */
67cfb204f9SDavid Hildenbrand 	struct psw	mcck_new_psw;			/* 0x01e0 */
68cfb204f9SDavid Hildenbrand 	struct psw	io_new_psw;			/* 0x01f0 */
694da93626SDavid Hildenbrand 	/* sw definition: save area for registers in interrupt handlers */
704da93626SDavid Hildenbrand 	uint64_t	sw_int_grs[16];			/* 0x0200 */
714da93626SDavid Hildenbrand 	uint64_t	sw_int_fprs[16];		/* 0x0280 */
724da93626SDavid Hildenbrand 	uint32_t	sw_int_fpc;			/* 0x0300 */
734da93626SDavid Hildenbrand 	uint8_t		pad_0x0304[0x11b0 - 0x0304];	/* 0x0304 */
74cfb204f9SDavid Hildenbrand 	uint64_t	mcck_ext_sa_addr;		/* 0x11b0 */
75cfb204f9SDavid Hildenbrand 	uint8_t		pad_0x11b8[0x1200 - 0x11b8];	/* 0x11b8 */
76cfb204f9SDavid Hildenbrand 	uint64_t	fprs_sa[16];			/* 0x1200 */
77cfb204f9SDavid Hildenbrand 	uint64_t	grs_sa[16];			/* 0x1280 */
78cfb204f9SDavid Hildenbrand 	struct psw	psw_sa;				/* 0x1300 */
79cfb204f9SDavid Hildenbrand 	uint8_t		pad_0x1310[0x1318 - 0x1310];	/* 0x1310 */
80cfb204f9SDavid Hildenbrand 	uint32_t	prefix_sa;			/* 0x1318 */
81cfb204f9SDavid Hildenbrand 	uint32_t	fpc_sa;				/* 0x131c */
82cfb204f9SDavid Hildenbrand 	uint8_t		pad_0x1320[0x1324 - 0x1320];	/* 0x1320 */
83cfb204f9SDavid Hildenbrand 	uint32_t	tod_pr_sa;			/* 0x1324 */
84cfb204f9SDavid Hildenbrand 	uint64_t	cputm_sa;			/* 0x1328 */
85cfb204f9SDavid Hildenbrand 	uint64_t	cc_sa;				/* 0x1330 */
86cfb204f9SDavid Hildenbrand 	uint8_t		pad_0x1338[0x1340 - 0x1338];	/* 0x1338 */
87cfb204f9SDavid Hildenbrand 	uint32_t	ars_sa[16];			/* 0x1340 */
88cfb204f9SDavid Hildenbrand 	uint64_t	crs_sa[16];			/* 0x1380 */
89cfb204f9SDavid Hildenbrand 	uint8_t		pad_0x1400[0x1800 - 0x1400];	/* 0x1400 */
90cfb204f9SDavid Hildenbrand 	uint8_t		pgm_int_tdb[0x1900 - 0x1800];	/* 0x1800 */
91cfb204f9SDavid Hildenbrand } __attribute__ ((__packed__));
92cfb204f9SDavid Hildenbrand 
934da93626SDavid Hildenbrand #define PGM_INT_CODE_OPERATION			0x01
944da93626SDavid Hildenbrand #define PGM_INT_CODE_PRIVILEGED_OPERATION	0x02
954da93626SDavid Hildenbrand #define PGM_INT_CODE_EXECUTE			0x03
964da93626SDavid Hildenbrand #define PGM_INT_CODE_PROTECTION			0x04
974da93626SDavid Hildenbrand #define PGM_INT_CODE_ADDRESSING			0x05
984da93626SDavid Hildenbrand #define PGM_INT_CODE_SPECIFICATION		0x06
994da93626SDavid Hildenbrand #define PGM_INT_CODE_DATA			0x07
1004da93626SDavid Hildenbrand #define PGM_INT_CODE_FIXED_POINT_OVERFLOW	0x08
1014da93626SDavid Hildenbrand #define PGM_INT_CODE_FIXED_POINT_DIVIDE		0x09
1024da93626SDavid Hildenbrand #define PGM_INT_CODE_DECIMAL_OVERFLOW		0x0a
1034da93626SDavid Hildenbrand #define PGM_INT_CODE_DECIMAL_DIVIDE		0x0b
1044da93626SDavid Hildenbrand #define PGM_INT_CODE_HFP_EXPONENT_OVERFLOW	0x0c
1054da93626SDavid Hildenbrand #define PGM_INT_CODE_HFP_EXPONENT_UNDERFLOW	0x0d
1064da93626SDavid Hildenbrand #define PGM_INT_CODE_HFP_SIGNIFICANCE		0x0e
1074da93626SDavid Hildenbrand #define PGM_INT_CODE_HFP_DIVIDE			0x0f
1084da93626SDavid Hildenbrand #define PGM_INT_CODE_SEGMENT_TRANSLATION	0x10
1094da93626SDavid Hildenbrand #define PGM_INT_CODE_PAGE_TRANSLATION		0x11
1104da93626SDavid Hildenbrand #define PGM_INT_CODE_TRANSLATION_SPEC		0x12
1114da93626SDavid Hildenbrand #define PGM_INT_CODE_SPECIAL_OPERATION		0x13
1124da93626SDavid Hildenbrand #define PGM_INT_CODE_OPERAND			0x15
1134da93626SDavid Hildenbrand #define PGM_INT_CODE_TRACE_TABLE		0x16
1144da93626SDavid Hildenbrand #define PGM_INT_CODE_VECTOR_PROCESSING		0x1b
1154da93626SDavid Hildenbrand #define PGM_INT_CODE_SPACE_SWITCH_EVENT		0x1c
1164da93626SDavid Hildenbrand #define PGM_INT_CODE_HFP_SQUARE_ROOT		0x1d
1174da93626SDavid Hildenbrand #define PGM_INT_CODE_PC_TRANSLATION_SPEC	0x1f
1184da93626SDavid Hildenbrand #define PGM_INT_CODE_AFX_TRANSLATION		0x20
1194da93626SDavid Hildenbrand #define PGM_INT_CODE_ASX_TRANSLATION		0x21
1204da93626SDavid Hildenbrand #define PGM_INT_CODE_LX_TRANSLATION		0x22
1214da93626SDavid Hildenbrand #define PGM_INT_CODE_EX_TRANSLATION		0x23
1224da93626SDavid Hildenbrand #define PGM_INT_CODE_PRIMARY_AUTHORITY		0x24
1234da93626SDavid Hildenbrand #define PGM_INT_CODE_SECONDARY_AUTHORITY	0x25
1244da93626SDavid Hildenbrand #define PGM_INT_CODE_LFX_TRANSLATION		0x26
1254da93626SDavid Hildenbrand #define PGM_INT_CODE_LSX_TRANSLATION		0x27
1264da93626SDavid Hildenbrand #define PGM_INT_CODE_ALET_SPECIFICATION		0x28
1274da93626SDavid Hildenbrand #define PGM_INT_CODE_ALEN_TRANSLATION		0x29
1284da93626SDavid Hildenbrand #define PGM_INT_CODE_ALE_SEQUENCE		0x2a
1294da93626SDavid Hildenbrand #define PGM_INT_CODE_ASTE_VALIDITY		0x2b
1304da93626SDavid Hildenbrand #define PGM_INT_CODE_ASTE_SEQUENCE		0x2c
1314da93626SDavid Hildenbrand #define PGM_INT_CODE_EXTENDED_AUTHORITY		0x2d
1324da93626SDavid Hildenbrand #define PGM_INT_CODE_LSTE_SEQUENCE		0x2e
1334da93626SDavid Hildenbrand #define PGM_INT_CODE_ASTE_INSTANCE		0x2f
1344da93626SDavid Hildenbrand #define PGM_INT_CODE_STACK_FULL			0x30
1354da93626SDavid Hildenbrand #define PGM_INT_CODE_STACK_EMPTY		0x31
1364da93626SDavid Hildenbrand #define PGM_INT_CODE_STACK_SPECIFICATION	0x32
1374da93626SDavid Hildenbrand #define PGM_INT_CODE_STACK_TYPE			0x33
1384da93626SDavid Hildenbrand #define PGM_INT_CODE_STACK_OPERATION		0x34
1394da93626SDavid Hildenbrand #define PGM_INT_CODE_ASCE_TYPE			0x38
1404da93626SDavid Hildenbrand #define PGM_INT_CODE_REGION_FIRST_TRANS		0x39
1414da93626SDavid Hildenbrand #define PGM_INT_CODE_REGION_SECOND_TRANS	0x3a
1424da93626SDavid Hildenbrand #define PGM_INT_CODE_REGION_THIRD_TRANS		0x3b
1434da93626SDavid Hildenbrand #define PGM_INT_CODE_MONITOR_EVENT		0x40
1444da93626SDavid Hildenbrand #define PGM_INT_CODE_PER			0x80
1454da93626SDavid Hildenbrand #define PGM_INT_CODE_CRYPTO_OPERATION		0x119
1464da93626SDavid Hildenbrand #define PGM_INT_CODE_TX_ABORTED_EVENT		0x200
1474da93626SDavid Hildenbrand 
148484a3a57SDavid Hildenbrand struct cpuid {
149484a3a57SDavid Hildenbrand 	uint64_t version : 8;
150484a3a57SDavid Hildenbrand 	uint64_t id : 24;
151484a3a57SDavid Hildenbrand 	uint64_t type : 16;
152484a3a57SDavid Hildenbrand 	uint64_t format : 1;
153484a3a57SDavid Hildenbrand 	uint64_t reserved : 15;
154484a3a57SDavid Hildenbrand };
155484a3a57SDavid Hildenbrand 
1563db880b6SDavid Hildenbrand static inline int tprot(unsigned long addr)
1573db880b6SDavid Hildenbrand {
1583db880b6SDavid Hildenbrand 	int cc;
1593db880b6SDavid Hildenbrand 
1603db880b6SDavid Hildenbrand 	asm volatile(
1613db880b6SDavid Hildenbrand 		"	tprot	0(%1),0\n"
1623db880b6SDavid Hildenbrand 		"	ipm	%0\n"
1633db880b6SDavid Hildenbrand 		"	srl	%0,28\n"
1643db880b6SDavid Hildenbrand 		: "=d" (cc) : "a" (addr) : "cc");
1653db880b6SDavid Hildenbrand 	return cc;
1663db880b6SDavid Hildenbrand }
1673db880b6SDavid Hildenbrand 
168*c08c320bSDavid Hildenbrand static inline void lctlg(int cr, uint64_t value)
169*c08c320bSDavid Hildenbrand {
170*c08c320bSDavid Hildenbrand 	asm volatile(
171*c08c320bSDavid Hildenbrand 		"	lctlg	%1,%1,%0\n"
172*c08c320bSDavid Hildenbrand 		: : "Q" (value), "i" (cr));
173*c08c320bSDavid Hildenbrand }
174*c08c320bSDavid Hildenbrand 
175*c08c320bSDavid Hildenbrand static inline uint64_t stctg(int cr)
176*c08c320bSDavid Hildenbrand {
177*c08c320bSDavid Hildenbrand 	uint64_t value;
178*c08c320bSDavid Hildenbrand 
179*c08c320bSDavid Hildenbrand 	asm volatile(
180*c08c320bSDavid Hildenbrand 		"	stctg	%1,%1,%0\n"
181*c08c320bSDavid Hildenbrand 		: "=Q" (value) : "i" (cr) : "memory");
182*c08c320bSDavid Hildenbrand 	return value;
183*c08c320bSDavid Hildenbrand }
184*c08c320bSDavid Hildenbrand 
185*c08c320bSDavid Hildenbrand static inline uint64_t extract_psw_mask(void)
186*c08c320bSDavid Hildenbrand {
187*c08c320bSDavid Hildenbrand 	uint32_t mask_upper = 0, mask_lower = 0;
188*c08c320bSDavid Hildenbrand 
189*c08c320bSDavid Hildenbrand 	asm volatile(
190*c08c320bSDavid Hildenbrand 		"	epsw	%0,%1\n"
191*c08c320bSDavid Hildenbrand 		: "+r" (mask_upper), "+r" (mask_lower) : : );
192*c08c320bSDavid Hildenbrand 
193*c08c320bSDavid Hildenbrand 	return (uint64_t) mask_upper << 32 | mask_lower;
194*c08c320bSDavid Hildenbrand }
195*c08c320bSDavid Hildenbrand 
196*c08c320bSDavid Hildenbrand static inline void load_psw_mask(uint64_t mask)
197*c08c320bSDavid Hildenbrand {
198*c08c320bSDavid Hildenbrand 	struct psw psw = {
199*c08c320bSDavid Hildenbrand 		.mask = mask,
200*c08c320bSDavid Hildenbrand 		.addr = 0,
201*c08c320bSDavid Hildenbrand 	};
202*c08c320bSDavid Hildenbrand 	uint64_t tmp = 0;
203*c08c320bSDavid Hildenbrand 
204*c08c320bSDavid Hildenbrand 	asm volatile(
205*c08c320bSDavid Hildenbrand 		"	larl	%0,0f\n"
206*c08c320bSDavid Hildenbrand 		"	stg	%0,8(%1)\n"
207*c08c320bSDavid Hildenbrand 		"	lpswe	0(%1)\n"
208*c08c320bSDavid Hildenbrand 		"0:\n"
209*c08c320bSDavid Hildenbrand 		: "+r" (tmp) :  "a" (&psw) : "memory", "cc" );
210*c08c320bSDavid Hildenbrand }
211*c08c320bSDavid Hildenbrand 
212cfb204f9SDavid Hildenbrand #endif
213