xref: /openbmc/linux/arch/arc/include/asm/ptrace.h (revision a20eefae)
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 
12 #ifndef __ASSEMBLY__
13 
14 /* THE pt_regs: Defines how regs are saved during entry into kernel */
15 
16 #ifdef CONFIG_ISA_ARCOMPACT
17 struct pt_regs {
18 
19 #ifdef CONFIG_ARC_PLAT_EZNPS
20 	unsigned long eflags;	/* Extended FLAGS */
21 	unsigned long gpa1;	/* General Purpose Aux */
22 #endif
23 
24 	/* Real registers */
25 	unsigned long bta;	/* bta_l1, bta_l2, erbta */
26 
27 	unsigned long lp_start, lp_end, lp_count;
28 
29 	unsigned long status32;	/* status32_l1, status32_l2, erstatus */
30 	unsigned long ret;	/* ilink1, ilink2 or eret */
31 	unsigned long blink;
32 	unsigned long fp;
33 	unsigned long r26;	/* gp */
34 
35 	unsigned long r12, r11, r10, r9, r8, r7, r6, r5, r4, r3, r2, r1, r0;
36 
37 	unsigned long sp;	/* User/Kernel depending on where we came from */
38 	unsigned long orig_r0;
39 
40 	/*
41 	 * To distinguish bet excp, syscall, irq
42 	 * For traps and exceptions, Exception Cause Register.
43 	 * 	ECR: <00> <VV> <CC> <PP>
44 	 * 	Last word used by Linux for extra state mgmt (syscall-restart)
45 	 * For interrupts, use artificial ECR values to note current prio-level
46 	 */
47 	union {
48 		struct {
49 #ifdef CONFIG_CPU_BIG_ENDIAN
50 			unsigned long state:8, ecr_vec:8,
51 				      ecr_cause:8, ecr_param:8;
52 #else
53 			unsigned long ecr_param:8, ecr_cause:8,
54 				      ecr_vec:8, state:8;
55 #endif
56 		};
57 		unsigned long event;
58 	};
59 
60 	unsigned long user_r25;
61 };
62 #else
63 
64 struct pt_regs {
65 
66 	unsigned long orig_r0;
67 
68 	union {
69 		struct {
70 #ifdef CONFIG_CPU_BIG_ENDIAN
71 			unsigned long state:8, ecr_vec:8,
72 				      ecr_cause:8, ecr_param:8;
73 #else
74 			unsigned long ecr_param:8, ecr_cause:8,
75 				      ecr_vec:8, state:8;
76 #endif
77 		};
78 		unsigned long event;
79 	};
80 
81 	unsigned long bta;	/* bta_l1, bta_l2, erbta */
82 
83 	unsigned long user_r25;
84 
85 	unsigned long r26;	/* gp */
86 	unsigned long fp;
87 	unsigned long sp;	/* user/kernel sp depending on where we came from  */
88 
89 	unsigned long r12, r30;
90 
91 #ifdef CONFIG_ARC_HAS_ACCL_REGS
92 	unsigned long r58, r59;	/* ACCL/ACCH used by FPU / DSP MPY */
93 #endif
94 
95 	/*------- Below list auto saved by h/w -----------*/
96 	unsigned long r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11;
97 
98 	unsigned long blink;
99 	unsigned long lp_end, lp_start, lp_count;
100 
101 	unsigned long ei, ldi, jli;
102 
103 	unsigned long ret;
104 	unsigned long status32;
105 };
106 
107 #endif
108 
109 /* Callee saved registers - need to be saved only when you are scheduled out */
110 
111 struct callee_regs {
112 	unsigned long r25, r24, r23, r22, r21, r20, r19, r18, r17, r16, r15, r14, r13;
113 };
114 
115 #define instruction_pointer(regs)	((regs)->ret)
116 #define profile_pc(regs)		instruction_pointer(regs)
117 
118 /* return 1 if user mode or 0 if kernel mode */
119 #define user_mode(regs) (regs->status32 & STATUS_U_MASK)
120 
121 #define user_stack_pointer(regs)\
122 ({  unsigned int sp;		\
123 	if (user_mode(regs))	\
124 		sp = (regs)->sp;\
125 	else			\
126 		sp = -1;	\
127 	sp;			\
128 })
129 
130 /* return 1 if PC in delay slot */
131 #define delay_mode(regs) ((regs->status32 & STATUS_DE_MASK) == STATUS_DE_MASK)
132 
133 #define in_syscall(regs)    ((regs->ecr_vec == ECR_V_TRAP) && !regs->ecr_param)
134 #define in_brkpt_trap(regs) ((regs->ecr_vec == ECR_V_TRAP) && regs->ecr_param)
135 
136 #define STATE_SCALL_RESTARTED	0x01
137 
138 #define syscall_wont_restart(reg) (reg->state |= STATE_SCALL_RESTARTED)
139 #define syscall_restartable(reg) !(reg->state &  STATE_SCALL_RESTARTED)
140 
141 #define current_pt_regs()					\
142 ({								\
143 	/* open-coded current_thread_info() */			\
144 	register unsigned long sp asm ("sp");			\
145 	unsigned long pg_start = (sp & ~(THREAD_SIZE - 1));	\
146 	(struct pt_regs *)(pg_start + THREAD_SIZE) - 1;	\
147 })
148 
149 static inline long regs_return_value(struct pt_regs *regs)
150 {
151 	return (long)regs->r0;
152 }
153 
154 #endif /* !__ASSEMBLY__ */
155 
156 #endif /* __ASM_PTRACE_H */
157