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;
57 #define REG_FMT "%016lx"
59 #define REG_FMT "%08lx"
62 #define user_mode(regs) (((regs)->status & SR_PP) == 0)
64 #define MAX_REG_OFFSET offsetof(struct pt_regs, orig_a0)
66 /* Helpers for working with the instruction pointer */
67 static inline unsigned long instruction_pointer(struct pt_regs *regs)
71 static inline void instruction_pointer_set(struct pt_regs *regs,
77 #define profile_pc(regs) instruction_pointer(regs)
79 /* Helpers for working with the user stack pointer */
80 static inline unsigned long user_stack_pointer(struct pt_regs *regs)
84 static inline void user_stack_pointer_set(struct pt_regs *regs,
90 /* Valid only for Kernel mode traps. */
91 static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
96 /* Helpers for working with the frame pointer */
97 static inline unsigned long frame_pointer(struct pt_regs *regs)
101 static inline void frame_pointer_set(struct pt_regs *regs,
107 static inline unsigned long regs_return_value(struct pt_regs *regs)
112 extern int regs_query_register_offset(const char *name);
113 extern unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
117 * regs_get_register() - get register value from its offset
118 * @regs: pt_regs from which register value is gotten
119 * @offset: offset of the register.
121 * regs_get_register returns the value of a register whose offset from @regs.
122 * The @offset is the offset of the register in struct pt_regs.
123 * If @offset is bigger than MAX_REG_OFFSET, this returns 0.
125 static inline unsigned long regs_get_register(struct pt_regs *regs,
128 if (unlikely(offset > MAX_REG_OFFSET))
131 return *(unsigned long *)((unsigned long)regs + offset);
133 #endif /* __ASSEMBLY__ */
135 #endif /* _ASM_RISCV_PTRACE_H */