1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright (C) 2012 Regents of the University of California
6 #ifndef _ASM_RISCV_PTRACE_H
7 #define _ASM_RISCV_PTRACE_H
9 #include <uapi/asm/ptrace.h>
11 #include <linux/compiler.h>
48 /* Supervisor/Machine CSRs */
50 unsigned long badaddr
;
52 /* a0 value before the syscall */
53 unsigned long orig_a0
;
56 #define PTRACE_SYSEMU 0x1f
57 #define PTRACE_SYSEMU_SINGLESTEP 0x20
60 #define REG_FMT "%016lx"
62 #define REG_FMT "%08lx"
65 #define user_mode(regs) (((regs)->status & SR_PP) == 0)
67 #define MAX_REG_OFFSET offsetof(struct pt_regs, orig_a0)
69 /* Helpers for working with the instruction pointer */
70 static inline unsigned long instruction_pointer(struct pt_regs
*regs
)
74 static inline void instruction_pointer_set(struct pt_regs
*regs
,
80 #define profile_pc(regs) instruction_pointer(regs)
82 /* Helpers for working with the user stack pointer */
83 static inline unsigned long user_stack_pointer(struct pt_regs
*regs
)
87 static inline void user_stack_pointer_set(struct pt_regs
*regs
,
93 /* Valid only for Kernel mode traps. */
94 static inline unsigned long kernel_stack_pointer(struct pt_regs
*regs
)
99 /* Helpers for working with the frame pointer */
100 static inline unsigned long frame_pointer(struct pt_regs
*regs
)
104 static inline void frame_pointer_set(struct pt_regs
*regs
,
110 static inline unsigned long regs_return_value(struct pt_regs
*regs
)
115 static inline void regs_set_return_value(struct pt_regs
*regs
,
121 extern int regs_query_register_offset(const char *name
);
122 extern unsigned long regs_get_kernel_stack_nth(struct pt_regs
*regs
,
125 void prepare_ftrace_return(unsigned long *parent
, unsigned long self_addr
,
126 unsigned long frame_pointer
);
129 * regs_get_register() - get register value from its offset
130 * @regs: pt_regs from which register value is gotten
131 * @offset: offset of the register.
133 * regs_get_register returns the value of a register whose offset from @regs.
134 * The @offset is the offset of the register in struct pt_regs.
135 * If @offset is bigger than MAX_REG_OFFSET, this returns 0.
137 static inline unsigned long regs_get_register(struct pt_regs
*regs
,
140 if (unlikely(offset
> MAX_REG_OFFSET
))
143 return *(unsigned long *)((unsigned long)regs
+ offset
);
147 * regs_get_kernel_argument() - get Nth function argument in kernel
148 * @regs: pt_regs of that context
149 * @n: function argument number (start from 0)
151 * regs_get_argument() returns @n th argument of the function call.
153 * Note you can get the parameter correctly if the function has no
154 * more than eight arguments.
156 static inline unsigned long regs_get_kernel_argument(struct pt_regs
*regs
,
159 static const int nr_reg_arguments
= 8;
160 static const unsigned int argument_offs
[] = {
161 offsetof(struct pt_regs
, a0
),
162 offsetof(struct pt_regs
, a1
),
163 offsetof(struct pt_regs
, a2
),
164 offsetof(struct pt_regs
, a3
),
165 offsetof(struct pt_regs
, a4
),
166 offsetof(struct pt_regs
, a5
),
167 offsetof(struct pt_regs
, a6
),
168 offsetof(struct pt_regs
, a7
),
171 if (n
< nr_reg_arguments
)
172 return regs_get_register(regs
, argument_offs
[n
]);
176 static inline int regs_irqs_disabled(struct pt_regs
*regs
)
178 return !(regs
->status
& SR_PIE
);
181 #endif /* __ASSEMBLY__ */
183 #endif /* _ASM_RISCV_PTRACE_H */