xref: /openbmc/linux/arch/arc/include/asm/ptrace.h (revision 3ddc8b84)
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 #define MAX_REG_OFFSET offsetof(struct pt_regs, ecr)
58 
59 #else
60 
61 struct pt_regs {
62 
63 	unsigned long orig_r0;
64 
65 	ecr_reg ecr;		/* Exception Cause Reg */
66 
67 	unsigned long bta;	/* erbta */
68 
69 	unsigned long fp;
70 	unsigned long r30;
71 	unsigned long r12;
72 	unsigned long r26;	/* gp */
73 
74 #ifdef CONFIG_ARC_HAS_ACCL_REGS
75 	unsigned long r58, r59;	/* ACCL/ACCH used by FPU / DSP MPY */
76 #endif
77 #ifdef CONFIG_ARC_DSP_SAVE_RESTORE_REGS
78 	unsigned long DSP_CTRL;
79 #endif
80 
81 	unsigned long sp;	/* user/kernel sp depending on entry  */
82 
83 	/*------- Below list auto saved by h/w -----------*/
84 	unsigned long r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11;
85 
86 	unsigned long blink;
87 	unsigned long lp_end, lp_start, lp_count;
88 
89 	unsigned long ei, ldi, jli;
90 
91 	unsigned long ret;
92 	unsigned long status32;
93 };
94 
95 #define MAX_REG_OFFSET offsetof(struct pt_regs, status32)
96 
97 #endif
98 
99 /* Callee saved registers - need to be saved only when you are scheduled out */
100 
101 struct callee_regs {
102 	unsigned long r25, r24, r23, r22, r21, r20, r19, r18, r17, r16, r15, r14, r13;
103 };
104 
105 #define instruction_pointer(regs)	((regs)->ret)
106 #define profile_pc(regs)		instruction_pointer(regs)
107 
108 /* return 1 if user mode or 0 if kernel mode */
109 #define user_mode(regs) (regs->status32 & STATUS_U_MASK)
110 
111 #define user_stack_pointer(regs)\
112 ({  unsigned int sp;		\
113 	if (user_mode(regs))	\
114 		sp = (regs)->sp;\
115 	else			\
116 		sp = -1;	\
117 	sp;			\
118 })
119 
120 /* return 1 if PC in delay slot */
121 #define delay_mode(regs) ((regs->status32 & STATUS_DE_MASK) == STATUS_DE_MASK)
122 
123 #define in_syscall(regs)    ((regs->ecr.vec == ECR_V_TRAP) && !regs->ecr.param)
124 #define in_brkpt_trap(regs) ((regs->ecr.vec == ECR_V_TRAP) && regs->ecr.param)
125 
126 #define STATE_SCALL_RESTARTED	0x01
127 
128 #define syscall_wont_restart(regs) (regs->ecr.state |= STATE_SCALL_RESTARTED)
129 #define syscall_restartable(regs) !(regs->ecr.state &  STATE_SCALL_RESTARTED)
130 
131 #define current_pt_regs()					\
132 ({								\
133 	/* open-coded current_thread_info() */			\
134 	register unsigned long sp asm ("sp");			\
135 	unsigned long pg_start = (sp & ~(THREAD_SIZE - 1));	\
136 	(struct pt_regs *)(pg_start + THREAD_SIZE) - 1;	\
137 })
138 
139 static inline long regs_return_value(struct pt_regs *regs)
140 {
141 	return (long)regs->r0;
142 }
143 
144 static inline void instruction_pointer_set(struct pt_regs *regs,
145 					   unsigned long val)
146 {
147 	instruction_pointer(regs) = val;
148 }
149 
150 static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
151 {
152 	return regs->sp;
153 }
154 
155 extern int regs_query_register_offset(const char *name);
156 extern const char *regs_query_register_name(unsigned int offset);
157 extern bool regs_within_kernel_stack(struct pt_regs *regs, unsigned long addr);
158 extern unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
159 					       unsigned int n);
160 
161 static inline unsigned long regs_get_register(struct pt_regs *regs,
162 					      unsigned int offset)
163 {
164 	if (unlikely(offset > MAX_REG_OFFSET))
165 		return 0;
166 
167 	return *(unsigned long *)((unsigned long)regs + offset);
168 }
169 
170 extern int syscall_trace_entry(struct pt_regs *);
171 extern void syscall_trace_exit(struct pt_regs *);
172 
173 #endif /* !__ASSEMBLY__ */
174 
175 #endif /* __ASM_PTRACE_H */
176