xref: /openbmc/linux/arch/arc/include/asm/ptrace.h (revision 85d616dd)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com)
4  *
5  * Amit Bhor, Sameer Dhavale: Codito Technologies 2004
6  */
7 #ifndef __ASM_ARC_PTRACE_H
8 #define __ASM_ARC_PTRACE_H
9 
10 #include <uapi/asm/ptrace.h>
11 #include <linux/compiler.h>
12 
13 #ifndef __ASSEMBLY__
14 
15 /* THE pt_regs: Defines how regs are saved during entry into kernel */
16 
17 #ifdef CONFIG_ISA_ARCOMPACT
18 struct pt_regs {
19 
20 	/* Real registers */
21 	unsigned long bta;	/* bta_l1, bta_l2, erbta */
22 
23 	unsigned long lp_start, lp_end, lp_count;
24 
25 	unsigned long status32;	/* status32_l1, status32_l2, erstatus */
26 	unsigned long ret;	/* ilink1, ilink2 or eret */
27 	unsigned long blink;
28 	unsigned long fp;
29 	unsigned long r26;	/* gp */
30 
31 	unsigned long r12, r11, r10, r9, r8, r7, r6, r5, r4, r3, r2, r1, r0;
32 
33 	unsigned long sp;	/* User/Kernel depending on where we came from */
34 	unsigned long orig_r0;
35 
36 	/*
37 	 * To distinguish bet excp, syscall, irq
38 	 * For traps and exceptions, Exception Cause Register.
39 	 * 	ECR: <00> <VV> <CC> <PP>
40 	 * 	Last word used by Linux for extra state mgmt (syscall-restart)
41 	 * For interrupts, use artificial ECR values to note current prio-level
42 	 */
43 	union {
44 		struct {
45 #ifdef CONFIG_CPU_BIG_ENDIAN
46 			unsigned long state:8, ecr_vec:8,
47 				      ecr_cause:8, ecr_param:8;
48 #else
49 			unsigned long ecr_param:8, ecr_cause:8,
50 				      ecr_vec:8, state:8;
51 #endif
52 		};
53 		unsigned long event;
54 	};
55 
56 	unsigned long user_r25;
57 };
58 
59 #define MAX_REG_OFFSET offsetof(struct pt_regs, user_r25)
60 
61 #else
62 
63 struct pt_regs {
64 
65 	unsigned long orig_r0;
66 
67 	union {
68 		struct {
69 #ifdef CONFIG_CPU_BIG_ENDIAN
70 			unsigned long state:8, ecr_vec:8,
71 				      ecr_cause:8, ecr_param:8;
72 #else
73 			unsigned long ecr_param:8, ecr_cause:8,
74 				      ecr_vec:8, state:8;
75 #endif
76 		};
77 		unsigned long event;
78 	};
79 
80 	unsigned long bta;	/* bta_l1, bta_l2, erbta */
81 
82 	unsigned long user_r25;
83 
84 	unsigned long r26;	/* gp */
85 	unsigned long fp;
86 	unsigned long sp;	/* user/kernel sp depending on where we came from  */
87 
88 	unsigned long r12, r30;
89 
90 #ifdef CONFIG_ARC_HAS_ACCL_REGS
91 	unsigned long r58, r59;	/* ACCL/ACCH used by FPU / DSP MPY */
92 #endif
93 #ifdef CONFIG_ARC_DSP_SAVE_RESTORE_REGS
94 	unsigned long DSP_CTRL;
95 #endif
96 
97 	/*------- Below list auto saved by h/w -----------*/
98 	unsigned long r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11;
99 
100 	unsigned long blink;
101 	unsigned long lp_end, lp_start, lp_count;
102 
103 	unsigned long ei, ldi, jli;
104 
105 	unsigned long ret;
106 	unsigned long status32;
107 };
108 
109 #define MAX_REG_OFFSET offsetof(struct pt_regs, status32)
110 
111 #endif
112 
113 /* Callee saved registers - need to be saved only when you are scheduled out */
114 
115 struct callee_regs {
116 	unsigned long r25, r24, r23, r22, r21, r20, r19, r18, r17, r16, r15, r14, r13;
117 };
118 
119 #define instruction_pointer(regs)	((regs)->ret)
120 #define profile_pc(regs)		instruction_pointer(regs)
121 
122 /* return 1 if user mode or 0 if kernel mode */
123 #define user_mode(regs) (regs->status32 & STATUS_U_MASK)
124 
125 #define user_stack_pointer(regs)\
126 ({  unsigned int sp;		\
127 	if (user_mode(regs))	\
128 		sp = (regs)->sp;\
129 	else			\
130 		sp = -1;	\
131 	sp;			\
132 })
133 
134 /* return 1 if PC in delay slot */
135 #define delay_mode(regs) ((regs->status32 & STATUS_DE_MASK) == STATUS_DE_MASK)
136 
137 #define in_syscall(regs)    ((regs->ecr_vec == ECR_V_TRAP) && !regs->ecr_param)
138 #define in_brkpt_trap(regs) ((regs->ecr_vec == ECR_V_TRAP) && regs->ecr_param)
139 
140 #define STATE_SCALL_RESTARTED	0x01
141 
142 #define syscall_wont_restart(reg) (reg->state |= STATE_SCALL_RESTARTED)
143 #define syscall_restartable(reg) !(reg->state &  STATE_SCALL_RESTARTED)
144 
145 #define current_pt_regs()					\
146 ({								\
147 	/* open-coded current_thread_info() */			\
148 	register unsigned long sp asm ("sp");			\
149 	unsigned long pg_start = (sp & ~(THREAD_SIZE - 1));	\
150 	(struct pt_regs *)(pg_start + THREAD_SIZE) - 1;	\
151 })
152 
153 static inline long regs_return_value(struct pt_regs *regs)
154 {
155 	return (long)regs->r0;
156 }
157 
158 static inline void instruction_pointer_set(struct pt_regs *regs,
159 					   unsigned long val)
160 {
161 	instruction_pointer(regs) = val;
162 }
163 
164 static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
165 {
166 	return regs->sp;
167 }
168 
169 extern int regs_query_register_offset(const char *name);
170 extern const char *regs_query_register_name(unsigned int offset);
171 extern bool regs_within_kernel_stack(struct pt_regs *regs, unsigned long addr);
172 extern unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
173 					       unsigned int n);
174 
175 static inline unsigned long regs_get_register(struct pt_regs *regs,
176 					      unsigned int offset)
177 {
178 	if (unlikely(offset > MAX_REG_OFFSET))
179 		return 0;
180 
181 	return *(unsigned long *)((unsigned long)regs + offset);
182 }
183 
184 #endif /* !__ASSEMBLY__ */
185 
186 #endif /* __ASM_PTRACE_H */
187