xref: /kvm-unit-tests/lib/arm64/asm/ptrace.h (revision 0cc3a351b925928827baa4b69cf0e46ff5837083)
1 #ifndef _ASMARM64_PTRACE_H_
2 #define _ASMARM64_PTRACE_H_
3 /*
4  * Adapted from Linux kernel headers
5  * arch/arm64/include/asm/ptrace.h
6  * arch/arm64/include/uapi/asm/ptrace.h
7  *
8  * Copyright (C) 2017, Red Hat Inc, Andrew Jones <drjones@redhat.com>
9  *
10  * This work is licensed under the terms of the GNU GPL, version 2.
11  */
12 
13 /* Current Exception Level values, as contained in CurrentEL */
14 #define CurrentEL_EL1	(1 << 2)
15 #define CurrentEL_EL2	(2 << 2)
16 
17 /*
18  * PSR bits
19  */
20 #define PSR_MODE_EL0t	0x00000000
21 #define PSR_MODE_EL1t	0x00000004
22 #define PSR_MODE_EL1h	0x00000005
23 #define PSR_MODE_EL2t	0x00000008
24 #define PSR_MODE_EL2h	0x00000009
25 #define PSR_MODE_EL3t	0x0000000c
26 #define PSR_MODE_EL3h	0x0000000d
27 #define PSR_MODE_MASK	0x0000000f
28 
29 /* AArch32 CPSR bits */
30 #define PSR_MODE32_BIT	0x00000010
31 
32 /* AArch64 SPSR bits */
33 #define PSR_F_BIT	0x00000040
34 #define PSR_I_BIT	0x00000080
35 #define PSR_A_BIT	0x00000100
36 #define PSR_D_BIT	0x00000200
37 #define PSR_Q_BIT	0x08000000
38 #define PSR_V_BIT	0x10000000
39 #define PSR_C_BIT	0x20000000
40 #define PSR_Z_BIT	0x40000000
41 #define PSR_N_BIT	0x80000000
42 
43 /*
44  * Groups of PSR bits
45  */
46 #define PSR_f		0xff000000	/* Flags                */
47 #define PSR_s		0x00ff0000	/* Status               */
48 #define PSR_x		0x0000ff00	/* Extension            */
49 #define PSR_c		0x000000ff	/* Control              */
50 
51 #ifndef __ASSEMBLER__
52 #include <libcflat.h>
53 
54 struct user_pt_regs {
55 	u64		regs[31];
56 	u64		sp;
57 	u64		pc;
58 	u64		pstate;
59 };
60 
61 struct user_fpsimd_state {
62 	__uint128_t	vregs[32];
63 	u32		fpsr;
64 	u32		fpcr;
65 };
66 
67 /*
68  * This struct defines the way the registers are stored on the stack during an
69  * exception. Note that sizeof(struct pt_regs) has to be a multiple of 16 (for
70  * stack alignment). struct user_pt_regs must form a prefix of struct pt_regs.
71  */
72 struct pt_regs {
73 	union {
74 		struct user_pt_regs user_regs;
75 		struct {
76 			u64 regs[31];
77 			u64 sp;
78 			u64 pc;
79 			u64 pstate;
80 		};
81 	};
82 	u64 orig_x0;
83 	u64 syscallno;
84 };
85 
86 #define user_mode(regs) \
87 	(((regs)->pstate & PSR_MODE_MASK) == PSR_MODE_EL0t)
88 
89 #define processor_mode(regs) \
90 	((regs)->pstate & PSR_MODE_MASK)
91 
92 #define interrupts_enabled(regs) \
93 	(!((regs)->pstate & PSR_I_BIT))
94 
95 #define fast_interrupts_enabled(regs) \
96 	(!((regs)->pstate & PSR_F_BIT))
97 
98 #endif /* !__ASSEMBLER__ */
99 #endif /* _ASMARM64_PTRACE_H_ */
100