xref: /openbmc/u-boot/arch/riscv/include/asm/ptrace.h (revision ebca902a)
1 /*
2  * Copyright (c) 2017 Microsemi Corporation.
3  * Copyright (c) 2017 Padmarao Begari <Padmarao.Begari@microsemi.com>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation.
8  */
9 #ifndef __ASM_RISCV_PTRACE_H
10 #define __ASM_RISCV_PTRACE_H
11 
12 struct pt_regs {
13 	unsigned long sepc;
14 	unsigned long ra;
15 	unsigned long sp;
16 	unsigned long gp;
17 	unsigned long tp;
18 	unsigned long t0;
19 	unsigned long t1;
20 	unsigned long t2;
21 	unsigned long s0;
22 	unsigned long s1;
23 	unsigned long a0;
24 	unsigned long a1;
25 	unsigned long a2;
26 	unsigned long a3;
27 	unsigned long a4;
28 	unsigned long a5;
29 	unsigned long a6;
30 	unsigned long a7;
31 	unsigned long s2;
32 	unsigned long s3;
33 	unsigned long s4;
34 	unsigned long s5;
35 	unsigned long s6;
36 	unsigned long s7;
37 	unsigned long s8;
38 	unsigned long s9;
39 	unsigned long s10;
40 	unsigned long s11;
41 	unsigned long t3;
42 	unsigned long t4;
43 	unsigned long t5;
44 	unsigned long t6;
45 	/* Supervisor CSRs */
46 	unsigned long sstatus;
47 	unsigned long sbadaddr;
48 	unsigned long scause;
49 };
50 
51 #ifdef CONFIG_64BIT
52 #define REG_FMT "%016lx"
53 #else
54 #define REG_FMT "%08lx"
55 #endif
56 
57 #define user_mode(regs) (((regs)->sstatus & SR_PS) == 0)
58 
59 /* Helpers for working with the instruction pointer */
60 #define GET_IP(regs) ((regs)->sepc)
61 #define SET_IP(regs, val) (GET_IP(regs) = (val))
62 
instruction_pointer(struct pt_regs * regs)63 static inline unsigned long instruction_pointer(struct pt_regs *regs)
64 {
65 	return GET_IP(regs);
66 }
67 
instruction_pointer_set(struct pt_regs * regs,ulong val)68 static inline void instruction_pointer_set(struct pt_regs *regs, ulong val)
69 {
70 	SET_IP(regs, val);
71 }
72 
73 #define profile_pc(regs) instruction_pointer(regs)
74 
75 /* Helpers for working with the user stack pointer */
76 #define GET_USP(regs) ((regs)->sp)
77 #define SET_USP(regs, val) (GET_USP(regs) = (val))
78 
user_stack_pointer(struct pt_regs * regs)79 static inline unsigned long user_stack_pointer(struct pt_regs *regs)
80 {
81 	return GET_USP(regs);
82 }
83 
user_stack_pointer_set(struct pt_regs * regs,ulong val)84 static inline void user_stack_pointer_set(struct pt_regs *regs, ulong val)
85 {
86 	SET_USP(regs, val);
87 }
88 
89 /* Helpers for working with the frame pointer */
90 #define GET_FP(regs) ((regs)->s0)
91 #define SET_FP(regs, val) (GET_FP(regs) = (val))
92 
frame_pointer(struct pt_regs * regs)93 static inline unsigned long frame_pointer(struct pt_regs *regs)
94 {
95 	return GET_FP(regs);
96 }
97 
frame_pointer_set(struct pt_regs * regs,ulong val)98 static inline void frame_pointer_set(struct pt_regs *regs, ulong val)
99 {
100 	SET_FP(regs, val);
101 }
102 
103 #endif /* __ASM_RISCV_PTRACE_H */
104