xref: /openbmc/linux/arch/riscv/include/asm/ptrace.h (revision 5a1ea477)
1 /*
2  * Copyright (C) 2012 Regents of the University of California
3  *
4  *   This program is free software; you can redistribute it and/or
5  *   modify it under the terms of the GNU General Public License
6  *   as published by the Free Software Foundation, version 2.
7  *
8  *   This program is distributed in the hope that it will be useful,
9  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
10  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  *   GNU General Public License for more details.
12  */
13 
14 #ifndef _ASM_RISCV_PTRACE_H
15 #define _ASM_RISCV_PTRACE_H
16 
17 #include <uapi/asm/ptrace.h>
18 #include <asm/csr.h>
19 
20 #ifndef __ASSEMBLY__
21 
22 struct pt_regs {
23 	unsigned long sepc;
24 	unsigned long ra;
25 	unsigned long sp;
26 	unsigned long gp;
27 	unsigned long tp;
28 	unsigned long t0;
29 	unsigned long t1;
30 	unsigned long t2;
31 	unsigned long s0;
32 	unsigned long s1;
33 	unsigned long a0;
34 	unsigned long a1;
35 	unsigned long a2;
36 	unsigned long a3;
37 	unsigned long a4;
38 	unsigned long a5;
39 	unsigned long a6;
40 	unsigned long a7;
41 	unsigned long s2;
42 	unsigned long s3;
43 	unsigned long s4;
44 	unsigned long s5;
45 	unsigned long s6;
46 	unsigned long s7;
47 	unsigned long s8;
48 	unsigned long s9;
49 	unsigned long s10;
50 	unsigned long s11;
51 	unsigned long t3;
52 	unsigned long t4;
53 	unsigned long t5;
54 	unsigned long t6;
55 	/* Supervisor CSRs */
56 	unsigned long sstatus;
57 	unsigned long sbadaddr;
58 	unsigned long scause;
59 	/* a0 value before the syscall */
60 	unsigned long orig_a0;
61 };
62 
63 #ifdef CONFIG_64BIT
64 #define REG_FMT "%016lx"
65 #else
66 #define REG_FMT "%08lx"
67 #endif
68 
69 #define user_mode(regs) (((regs)->sstatus & SR_SPP) == 0)
70 
71 
72 /* Helpers for working with the instruction pointer */
73 static inline unsigned long instruction_pointer(struct pt_regs *regs)
74 {
75 	return regs->sepc;
76 }
77 static inline void instruction_pointer_set(struct pt_regs *regs,
78 					   unsigned long val)
79 {
80 	regs->sepc = val;
81 }
82 
83 #define profile_pc(regs) instruction_pointer(regs)
84 
85 /* Helpers for working with the user stack pointer */
86 static inline unsigned long user_stack_pointer(struct pt_regs *regs)
87 {
88 	return regs->sp;
89 }
90 static inline void user_stack_pointer_set(struct pt_regs *regs,
91 					  unsigned long val)
92 {
93 	regs->sp =  val;
94 }
95 
96 /* Helpers for working with the frame pointer */
97 static inline unsigned long frame_pointer(struct pt_regs *regs)
98 {
99 	return regs->s0;
100 }
101 static inline void frame_pointer_set(struct pt_regs *regs,
102 				     unsigned long val)
103 {
104 	regs->s0 = val;
105 }
106 
107 static inline unsigned long regs_return_value(struct pt_regs *regs)
108 {
109 	return regs->a0;
110 }
111 
112 #endif /* __ASSEMBLY__ */
113 
114 #endif /* _ASM_RISCV_PTRACE_H */
115