This source file includes following definitions.
- get_frame_size
- find_frame_creation
- lookup_prev_stack_frame
- unwind_trap
- unwind_trap
- microblaze_unwind_inner
- microblaze_unwind
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 #include <linux/export.h>
17 #include <linux/kallsyms.h>
18 #include <linux/kernel.h>
19 #include <linux/sched.h>
20 #include <linux/sched/task_stack.h>
21 #include <linux/stacktrace.h>
22 #include <linux/types.h>
23 #include <linux/errno.h>
24 #include <linux/io.h>
25 #include <asm/sections.h>
26 #include <asm/exceptions.h>
27 #include <asm/unwind.h>
28 #include <asm/switch_to.h>
29
30 struct stack_trace;
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63 static inline long get_frame_size(unsigned long instr)
64 {
65 return abs((s16)(instr & 0xFFFF));
66 }
67
68
69
70
71
72
73
74
75
76
77 static unsigned long *find_frame_creation(unsigned long *pc)
78 {
79 int i;
80
81
82
83
84
85
86 for (i = 0; i < 1000; i++, pc--) {
87 unsigned long instr;
88 s16 frame_size;
89
90 if (!kernel_text_address((unsigned long) pc))
91 return NULL;
92
93 instr = *pc;
94
95
96 if ((instr & 0xFFFF0000) != 0x30210000)
97 continue;
98
99 frame_size = get_frame_size(instr);
100 if ((frame_size < 8) || (frame_size & 3)) {
101 pr_debug(" Invalid frame size %d at 0x%p\n",
102 frame_size, pc);
103 return NULL;
104 }
105
106 pr_debug(" Found frame creation at 0x%p, size %d\n", pc,
107 frame_size);
108 return pc;
109 }
110
111 return NULL;
112 }
113
114
115
116
117
118
119
120
121
122
123
124
125 static int lookup_prev_stack_frame(unsigned long fp, unsigned long pc,
126 unsigned long leaf_return,
127 unsigned long *pprev_fp,
128 unsigned long *pprev_pc)
129 {
130 unsigned long *prologue = NULL;
131
132
133 if (pc != (unsigned long) &_switch_to)
134 prologue = find_frame_creation((unsigned long *)pc);
135
136 if (prologue) {
137 long frame_size = get_frame_size(*prologue);
138
139 *pprev_fp = fp + frame_size;
140 *pprev_pc = *(unsigned long *)fp;
141 } else {
142 if (!leaf_return)
143 return -EINVAL;
144 *pprev_pc = leaf_return;
145 *pprev_fp = fp;
146 }
147
148
149
150
151 return (!*pprev_pc || (*pprev_pc & 3)) ? -EINVAL : 0;
152 }
153
154 static void microblaze_unwind_inner(struct task_struct *task,
155 unsigned long pc, unsigned long fp,
156 unsigned long leaf_return,
157 struct stack_trace *trace);
158
159
160
161
162
163 #ifdef CONFIG_MMU
164 static inline void unwind_trap(struct task_struct *task, unsigned long pc,
165 unsigned long fp, struct stack_trace *trace)
166 {
167
168 }
169 #else
170 static inline void unwind_trap(struct task_struct *task, unsigned long pc,
171 unsigned long fp, struct stack_trace *trace)
172 {
173 const struct pt_regs *regs = (const struct pt_regs *) fp;
174 microblaze_unwind_inner(task, regs->pc, regs->r1, regs->r15, trace);
175 }
176 #endif
177
178
179
180
181
182
183
184
185
186
187
188 static void microblaze_unwind_inner(struct task_struct *task,
189 unsigned long pc, unsigned long fp,
190 unsigned long leaf_return,
191 struct stack_trace *trace)
192 {
193 int ofs = 0;
194
195 pr_debug(" Unwinding with PC=%p, FP=%p\n", (void *)pc, (void *)fp);
196 if (!pc || !fp || (pc & 3) || (fp & 3)) {
197 pr_debug(" Invalid state for unwind, aborting\n");
198 return;
199 }
200 for (; pc != 0;) {
201 unsigned long next_fp, next_pc = 0;
202 unsigned long return_to = pc + 2 * sizeof(unsigned long);
203 const struct trap_handler_info *handler =
204 µblaze_trap_handlers;
205
206
207 if ((return_to >= (unsigned long)&_hw_exception_handler)
208 &&(return_to < (unsigned long)&ex_handler_unhandled)) {
209
210
211
212
213 #ifndef CONFIG_MMU
214 const struct pt_regs *regs =
215 (const struct pt_regs *) fp;
216 #endif
217 pr_info("HW EXCEPTION\n");
218 #ifndef CONFIG_MMU
219 microblaze_unwind_inner(task, regs->r17 - 4,
220 fp + EX_HANDLER_STACK_SIZ,
221 regs->r15, trace);
222 #endif
223 return;
224 }
225
226
227 for (; handler->start_addr; ++handler) {
228 if ((return_to >= handler->start_addr)
229 && (return_to <= handler->end_addr)) {
230 if (!trace)
231 pr_info("%s\n", handler->trap_name);
232 unwind_trap(task, pc, fp, trace);
233 return;
234 }
235 }
236 pc -= ofs;
237
238 if (trace) {
239 #ifdef CONFIG_STACKTRACE
240 if (trace->skip > 0)
241 trace->skip--;
242 else
243 trace->entries[trace->nr_entries++] = pc;
244
245 if (trace->nr_entries >= trace->max_entries)
246 break;
247 #endif
248 } else {
249
250 if (unlikely(pc == task_pt_regs(task)->pc)) {
251 pr_info("[<%p>] PID %lu [%s]\n",
252 (void *) pc,
253 (unsigned long) task->pid,
254 task->comm);
255 break;
256 } else
257 print_ip_sym(pc);
258 }
259
260
261 if (!kernel_text_address(pc))
262 break;
263
264 if (lookup_prev_stack_frame(fp, pc, leaf_return, &next_fp,
265 &next_pc) == 0) {
266 ofs = sizeof(unsigned long);
267 pc = next_pc & ~3;
268 fp = next_fp;
269 leaf_return = 0;
270 } else {
271 pr_debug(" Failed to find previous stack frame\n");
272 break;
273 }
274
275 pr_debug(" Next PC=%p, next FP=%p\n",
276 (void *)next_pc, (void *)next_fp);
277 }
278 }
279
280
281
282
283
284
285
286 void microblaze_unwind(struct task_struct *task, struct stack_trace *trace)
287 {
288 if (task) {
289 if (task == current) {
290 const struct pt_regs *regs = task_pt_regs(task);
291 microblaze_unwind_inner(task, regs->pc, regs->r1,
292 regs->r15, trace);
293 } else {
294 struct thread_info *thread_info =
295 (struct thread_info *)(task->stack);
296 const struct cpu_context *cpu_context =
297 &thread_info->cpu_context;
298
299 microblaze_unwind_inner(task,
300 (unsigned long) &_switch_to,
301 cpu_context->r1,
302 cpu_context->r15, trace);
303 }
304 } else {
305 unsigned long pc, fp;
306
307 __asm__ __volatile__ ("or %0, r1, r0" : "=r" (fp));
308
309 __asm__ __volatile__ (
310 "brlid %0, 0f;"
311 "nop;"
312 "0:"
313 : "=r" (pc)
314 );
315
316
317 microblaze_unwind_inner(current, pc, fp, 0, trace);
318 }
319 }
320