Commit | Line | Data |
---|---|---|
d2912cb1 | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
3be80aae VG |
2 | /* |
3 | * Copyright (C) 2004, 2007-2010, 2011-2012 Synopsys, Inc. (www.synopsys.com) | |
4 | * | |
3be80aae VG |
5 | * Amit Bhor, Sameer Dhavale: Codito Technologies 2004 |
6 | */ | |
3be80aae VG |
7 | #ifndef __ASM_ARC_PTRACE_H |
8 | #define __ASM_ARC_PTRACE_H | |
9 | ||
8c2f4a8d | 10 | #include <uapi/asm/ptrace.h> |
b3bbf6a7 | 11 | #include <linux/compiler.h> |
3be80aae VG |
12 | |
13 | #ifndef __ASSEMBLY__ | |
14 | ||
58d9ceb7 VG |
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 | ||
3be80aae VG |
26 | /* THE pt_regs: Defines how regs are saved during entry into kernel */ |
27 | ||
1f6ccfff | 28 | #ifdef CONFIG_ISA_ARCOMPACT |
3be80aae | 29 | struct pt_regs { |
3be80aae VG |
30 | |
31 | /* Real registers */ | |
87ce6280 | 32 | unsigned long bta; /* bta_l1, bta_l2, erbta */ |
4b06ff35 | 33 | |
87ce6280 | 34 | unsigned long lp_start, lp_end, lp_count; |
4b06ff35 | 35 | |
87ce6280 VG |
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 */ | |
4b06ff35 | 41 | |
87ce6280 | 42 | unsigned long r12, r11, r10, r9, r8, r7, r6, r5, r4, r3, r2, r1, r0; |
4b06ff35 | 43 | |
87ce6280 VG |
44 | unsigned long sp; /* User/Kernel depending on where we came from */ |
45 | unsigned long orig_r0; | |
5c39c0ab | 46 | |
502a0c77 VG |
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 | */ | |
58d9ceb7 | 54 | ecr_reg ecr; |
3be80aae | 55 | }; |
b3bbf6a7 | 56 | |
9de7fc30 VG |
57 | struct callee_regs { |
58 | unsigned long r25, r24, r23, r22, r21, r20, r19, r18, r17, r16, r15, r14, r13; | |
59 | }; | |
60 | ||
58d9ceb7 | 61 | #define MAX_REG_OFFSET offsetof(struct pt_regs, ecr) |
b3bbf6a7 | 62 | |
1f6ccfff VG |
63 | #else |
64 | ||
65 | struct pt_regs { | |
66 | ||
87ce6280 | 67 | unsigned long orig_r0; |
1f6ccfff | 68 | |
58d9ceb7 | 69 | ecr_reg ecr; /* Exception Cause Reg */ |
1f6ccfff | 70 | |
c505b0da | 71 | unsigned long bta; /* erbta */ |
1f6ccfff | 72 | |
87ce6280 | 73 | unsigned long fp; |
d4624bf6 VG |
74 | unsigned long r30; |
75 | unsigned long r12; | |
76 | unsigned long r26; /* gp */ | |
1f6ccfff | 77 | |
3d5e8012 VG |
78 | #ifdef CONFIG_ARC_HAS_ACCL_REGS |
79 | unsigned long r58, r59; /* ACCL/ACCH used by FPU / DSP MPY */ | |
80 | #endif | |
7321e2ea EP |
81 | #ifdef CONFIG_ARC_DSP_SAVE_RESTORE_REGS |
82 | unsigned long DSP_CTRL; | |
83 | #endif | |
3d5e8012 | 84 | |
d4624bf6 VG |
85 | unsigned long sp; /* user/kernel sp depending on entry */ |
86 | ||
1f6ccfff | 87 | /*------- Below list auto saved by h/w -----------*/ |
87ce6280 | 88 | unsigned long r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, r10, r11; |
1f6ccfff | 89 | |
87ce6280 VG |
90 | unsigned long blink; |
91 | unsigned long lp_end, lp_start, lp_count; | |
1f6ccfff | 92 | |
87ce6280 | 93 | unsigned long ei, ldi, jli; |
1f6ccfff | 94 | |
87ce6280 VG |
95 | unsigned long ret; |
96 | unsigned long status32; | |
1f6ccfff VG |
97 | }; |
98 | ||
3be80aae | 99 | struct callee_regs { |
87ce6280 | 100 | unsigned long r25, r24, r23, r22, r21, r20, r19, r18, r17, r16, r15, r14, r13; |
3be80aae VG |
101 | }; |
102 | ||
9de7fc30 VG |
103 | #define MAX_REG_OFFSET offsetof(struct pt_regs, status32) |
104 | ||
105 | #endif | |
106 | ||
87ce6280 | 107 | #define instruction_pointer(regs) ((regs)->ret) |
3be80aae VG |
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 | }) | |
4adeefe1 | 121 | |
2e651ea1 VG |
122 | /* return 1 if PC in delay slot */ |
123 | #define delay_mode(regs) ((regs->status32 & STATUS_DE_MASK) == STATUS_DE_MASK) | |
124 | ||
58d9ceb7 VG |
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) | |
4adeefe1 | 127 | |
502a0c77 VG |
128 | #define STATE_SCALL_RESTARTED 0x01 |
129 | ||
58d9ceb7 VG |
130 | #define syscall_wont_restart(regs) (regs->ecr.state |= STATE_SCALL_RESTARTED) |
131 | #define syscall_restartable(regs) !(regs->ecr.state & STATE_SCALL_RESTARTED) | |
55bb9480 | 132 | |
bf90e1ea VG |
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)); \ | |
283237a0 | 138 | (struct pt_regs *)(pg_start + THREAD_SIZE) - 1; \ |
bf90e1ea VG |
139 | }) |
140 | ||
4d86dfbb VG |
141 | static inline long regs_return_value(struct pt_regs *regs) |
142 | { | |
87ce6280 | 143 | return (long)regs->r0; |
4d86dfbb VG |
144 | } |
145 | ||
bb6121b1 MH |
146 | static inline void instruction_pointer_set(struct pt_regs *regs, |
147 | unsigned long val) | |
148 | { | |
149 | instruction_pointer(regs) = val; | |
150 | } | |
b3bbf6a7 SM |
151 | |
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 | ||
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 | ||
db70d9f9 | 172 | extern int syscall_trace_enter(struct pt_regs *); |
4d369680 VG |
173 | extern void syscall_trace_exit(struct pt_regs *); |
174 | ||
3be80aae VG |
175 | #endif /* !__ASSEMBLY__ */ |
176 | ||
3be80aae | 177 | #endif /* __ASM_PTRACE_H */ |