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