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