xref: /openbmc/linux/arch/riscv/include/asm/ptrace.h (revision e15a5365)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2012 Regents of the University of California
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>
11 
12 #ifndef __ASSEMBLY__
13 
14 struct pt_regs {
15 	unsigned long epc;
16 	unsigned long ra;
17 	unsigned long sp;
18 	unsigned long gp;
19 	unsigned long tp;
20 	unsigned long t0;
21 	unsigned long t1;
22 	unsigned long t2;
23 	unsigned long s0;
24 	unsigned long s1;
25 	unsigned long a0;
26 	unsigned long a1;
27 	unsigned long a2;
28 	unsigned long a3;
29 	unsigned long a4;
30 	unsigned long a5;
31 	unsigned long a6;
32 	unsigned long a7;
33 	unsigned long s2;
34 	unsigned long s3;
35 	unsigned long s4;
36 	unsigned long s5;
37 	unsigned long s6;
38 	unsigned long s7;
39 	unsigned long s8;
40 	unsigned long s9;
41 	unsigned long s10;
42 	unsigned long s11;
43 	unsigned long t3;
44 	unsigned long t4;
45 	unsigned long t5;
46 	unsigned long t6;
47 	/* Supervisor/Machine CSRs */
48 	unsigned long status;
49 	unsigned long badaddr;
50 	unsigned long cause;
51 	/* a0 value before the syscall */
52 	unsigned long orig_a0;
53 };
54 
55 #ifdef CONFIG_64BIT
56 #define REG_FMT "%016lx"
57 #else
58 #define REG_FMT "%08lx"
59 #endif
60 
61 #define user_mode(regs) (((regs)->status & SR_PP) == 0)
62 
63 
64 /* Helpers for working with the instruction pointer */
65 static inline unsigned long instruction_pointer(struct pt_regs *regs)
66 {
67 	return regs->epc;
68 }
69 static inline void instruction_pointer_set(struct pt_regs *regs,
70 					   unsigned long val)
71 {
72 	regs->epc = val;
73 }
74 
75 #define profile_pc(regs) instruction_pointer(regs)
76 
77 /* Helpers for working with the user stack pointer */
78 static inline unsigned long user_stack_pointer(struct pt_regs *regs)
79 {
80 	return regs->sp;
81 }
82 static inline void user_stack_pointer_set(struct pt_regs *regs,
83 					  unsigned long val)
84 {
85 	regs->sp =  val;
86 }
87 
88 /* Helpers for working with the frame pointer */
89 static inline unsigned long frame_pointer(struct pt_regs *regs)
90 {
91 	return regs->s0;
92 }
93 static inline void frame_pointer_set(struct pt_regs *regs,
94 				     unsigned long val)
95 {
96 	regs->s0 = val;
97 }
98 
99 static inline unsigned long regs_return_value(struct pt_regs *regs)
100 {
101 	return regs->a0;
102 }
103 
104 #endif /* __ASSEMBLY__ */
105 
106 #endif /* _ASM_RISCV_PTRACE_H */
107