]>
Commit | Line | Data |
---|---|---|
50acfb2b | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
e2c0cdfb PD |
2 | /* |
3 | * Copyright (C) 2012 Regents of the University of California | |
e2c0cdfb PD |
4 | */ |
5 | ||
6 | #ifndef _ASM_RISCV_PTRACE_H | |
7 | #define _ASM_RISCV_PTRACE_H | |
8 | ||
9 | #include <uapi/asm/ptrace.h> | |
10 | #include <asm/csr.h> | |
dcdc7a53 | 11 | #include <linux/compiler.h> |
e2c0cdfb PD |
12 | |
13 | #ifndef __ASSEMBLY__ | |
14 | ||
15 | struct pt_regs { | |
a4c3733d | 16 | unsigned long epc; |
e2c0cdfb PD |
17 | unsigned long ra; |
18 | unsigned long sp; | |
19 | unsigned long gp; | |
20 | unsigned long tp; | |
21 | unsigned long t0; | |
22 | unsigned long t1; | |
23 | unsigned long t2; | |
24 | unsigned long s0; | |
25 | unsigned long s1; | |
26 | unsigned long a0; | |
27 | unsigned long a1; | |
28 | unsigned long a2; | |
29 | unsigned long a3; | |
30 | unsigned long a4; | |
31 | unsigned long a5; | |
32 | unsigned long a6; | |
33 | unsigned long a7; | |
34 | unsigned long s2; | |
35 | unsigned long s3; | |
36 | unsigned long s4; | |
37 | unsigned long s5; | |
38 | unsigned long s6; | |
39 | unsigned long s7; | |
40 | unsigned long s8; | |
41 | unsigned long s9; | |
42 | unsigned long s10; | |
43 | unsigned long s11; | |
44 | unsigned long t3; | |
45 | unsigned long t4; | |
46 | unsigned long t5; | |
47 | unsigned long t6; | |
a4c3733d CH |
48 | /* Supervisor/Machine CSRs */ |
49 | unsigned long status; | |
50 | unsigned long badaddr; | |
51 | unsigned long cause; | |
10febb3e DA |
52 | /* a0 value before the syscall */ |
53 | unsigned long orig_a0; | |
e2c0cdfb PD |
54 | }; |
55 | ||
56 | #ifdef CONFIG_64BIT | |
57 | #define REG_FMT "%016lx" | |
58 | #else | |
59 | #define REG_FMT "%08lx" | |
60 | #endif | |
61 | ||
a4c3733d | 62 | #define user_mode(regs) (((regs)->status & SR_PP) == 0) |
e2c0cdfb | 63 | |
dcdc7a53 | 64 | #define MAX_REG_OFFSET offsetof(struct pt_regs, orig_a0) |
e2c0cdfb PD |
65 | |
66 | /* Helpers for working with the instruction pointer */ | |
e2c0cdfb PD |
67 | static inline unsigned long instruction_pointer(struct pt_regs *regs) |
68 | { | |
a4c3733d | 69 | return regs->epc; |
e2c0cdfb PD |
70 | } |
71 | static inline void instruction_pointer_set(struct pt_regs *regs, | |
72 | unsigned long val) | |
73 | { | |
a4c3733d | 74 | regs->epc = val; |
e2c0cdfb PD |
75 | } |
76 | ||
77 | #define profile_pc(regs) instruction_pointer(regs) | |
78 | ||
79 | /* Helpers for working with the user stack pointer */ | |
e2c0cdfb PD |
80 | static inline unsigned long user_stack_pointer(struct pt_regs *regs) |
81 | { | |
6ab77af4 | 82 | return regs->sp; |
e2c0cdfb PD |
83 | } |
84 | static inline void user_stack_pointer_set(struct pt_regs *regs, | |
85 | unsigned long val) | |
86 | { | |
6ab77af4 | 87 | regs->sp = val; |
e2c0cdfb PD |
88 | } |
89 | ||
dcdc7a53 PS |
90 | /* Valid only for Kernel mode traps. */ |
91 | static inline unsigned long kernel_stack_pointer(struct pt_regs *regs) | |
92 | { | |
93 | return regs->sp; | |
94 | } | |
95 | ||
e2c0cdfb | 96 | /* Helpers for working with the frame pointer */ |
e2c0cdfb PD |
97 | static inline unsigned long frame_pointer(struct pt_regs *regs) |
98 | { | |
6ab77af4 | 99 | return regs->s0; |
e2c0cdfb PD |
100 | } |
101 | static inline void frame_pointer_set(struct pt_regs *regs, | |
102 | unsigned long val) | |
103 | { | |
6ab77af4 | 104 | regs->s0 = val; |
e2c0cdfb PD |
105 | } |
106 | ||
efe75c49 DA |
107 | static inline unsigned long regs_return_value(struct pt_regs *regs) |
108 | { | |
109 | return regs->a0; | |
110 | } | |
111 | ||
ee55ff80 GR |
112 | static inline void regs_set_return_value(struct pt_regs *regs, |
113 | unsigned long val) | |
114 | { | |
115 | regs->a0 = val; | |
116 | } | |
117 | ||
dcdc7a53 PS |
118 | extern int regs_query_register_offset(const char *name); |
119 | extern unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, | |
120 | unsigned int n); | |
121 | ||
122 | /** | |
123 | * regs_get_register() - get register value from its offset | |
124 | * @regs: pt_regs from which register value is gotten | |
125 | * @offset: offset of the register. | |
126 | * | |
127 | * regs_get_register returns the value of a register whose offset from @regs. | |
128 | * The @offset is the offset of the register in struct pt_regs. | |
129 | * If @offset is bigger than MAX_REG_OFFSET, this returns 0. | |
130 | */ | |
131 | static inline unsigned long regs_get_register(struct pt_regs *regs, | |
132 | unsigned int offset) | |
133 | { | |
134 | if (unlikely(offset > MAX_REG_OFFSET)) | |
135 | return 0; | |
136 | ||
137 | return *(unsigned long *)((unsigned long)regs + offset); | |
138 | } | |
e2c0cdfb PD |
139 | #endif /* __ASSEMBLY__ */ |
140 | ||
141 | #endif /* _ASM_RISCV_PTRACE_H */ |