1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27#include <linux/ptrace.h>
28#include <linux/export.h>
29#include <linux/stacktrace.h>
30#include <linux/kallsyms.h>
31#include <asm/arcregs.h>
32#include <asm/unwind.h>
33#include <asm/switch_to.h>
34
35
36
37
38
39
40#ifdef CONFIG_ARC_DW2_UNWIND
41
42static void seed_unwind_frame_info(struct task_struct *tsk,
43 struct pt_regs *regs,
44 struct unwind_frame_info *frame_info)
45{
46
47
48
49
50 if (tsk == NULL && regs == NULL) {
51 unsigned long fp, sp, blink, ret;
52 frame_info->task = current;
53
54 __asm__ __volatile__(
55 "mov %0,r27\n\t"
56 "mov %1,r28\n\t"
57 "mov %2,r31\n\t"
58 "mov %3,r63\n\t"
59 : "=r"(fp), "=r"(sp), "=r"(blink), "=r"(ret)
60 );
61
62 frame_info->regs.r27 = fp;
63 frame_info->regs.r28 = sp;
64 frame_info->regs.r31 = blink;
65 frame_info->regs.r63 = ret;
66 frame_info->call_frame = 0;
67 } else if (regs == NULL) {
68
69
70
71
72
73
74 frame_info->task = tsk;
75
76 frame_info->regs.r27 = TSK_K_FP(tsk);
77 frame_info->regs.r28 = TSK_K_ESP(tsk);
78 frame_info->regs.r31 = TSK_K_BLINK(tsk);
79 frame_info->regs.r63 = (unsigned int)__switch_to;
80
81
82
83
84
85
86
87
88
89
90 frame_info->regs.r27 = 0;
91 frame_info->regs.r28 += 60;
92 frame_info->call_frame = 0;
93
94 } else {
95
96
97
98
99 frame_info->task = tsk;
100
101 frame_info->regs.r27 = regs->fp;
102 frame_info->regs.r28 = regs->sp;
103 frame_info->regs.r31 = regs->blink;
104 frame_info->regs.r63 = regs->ret;
105 frame_info->call_frame = 0;
106 }
107}
108
109#endif
110
111notrace noinline unsigned int
112arc_unwind_core(struct task_struct *tsk, struct pt_regs *regs,
113 int (*consumer_fn) (unsigned int, void *), void *arg)
114{
115#ifdef CONFIG_ARC_DW2_UNWIND
116 int ret = 0;
117 unsigned int address;
118 struct unwind_frame_info frame_info;
119
120 seed_unwind_frame_info(tsk, regs, &frame_info);
121
122 while (1) {
123 address = UNW_PC(&frame_info);
124
125 if (!address || !__kernel_text_address(address))
126 break;
127
128 if (consumer_fn(address, arg) == -1)
129 break;
130
131 ret = arc_unwind(&frame_info);
132 if (ret)
133 break;
134
135 frame_info.regs.r63 = frame_info.regs.r31;
136 }
137
138 return address;
139#else
140
141
142
143
144
145 pr_warn_once("CONFIG_ARC_DW2_UNWIND needs to be enabled\n");
146 return 0;
147
148#endif
149}
150
151
152
153
154
155
156
157
158
159
160
161
162static int __print_sym(unsigned int address, void *unused)
163{
164 __print_symbol(" %s\n", address);
165 return 0;
166}
167
168#ifdef CONFIG_STACKTRACE
169
170
171
172
173static int __collect_all(unsigned int address, void *arg)
174{
175 struct stack_trace *trace = arg;
176
177 if (trace->skip > 0)
178 trace->skip--;
179 else
180 trace->entries[trace->nr_entries++] = address;
181
182 if (trace->nr_entries >= trace->max_entries)
183 return -1;
184
185 return 0;
186}
187
188static int __collect_all_but_sched(unsigned int address, void *arg)
189{
190 struct stack_trace *trace = arg;
191
192 if (in_sched_functions(address))
193 return 0;
194
195 if (trace->skip > 0)
196 trace->skip--;
197 else
198 trace->entries[trace->nr_entries++] = address;
199
200 if (trace->nr_entries >= trace->max_entries)
201 return -1;
202
203 return 0;
204}
205
206#endif
207
208static int __get_first_nonsched(unsigned int address, void *unused)
209{
210 if (in_sched_functions(address))
211 return 0;
212
213 return -1;
214}
215
216
217
218
219
220
221noinline void show_stacktrace(struct task_struct *tsk, struct pt_regs *regs)
222{
223 pr_info("\nStack Trace:\n");
224 arc_unwind_core(tsk, regs, __print_sym, NULL);
225}
226EXPORT_SYMBOL(show_stacktrace);
227
228
229void show_stack(struct task_struct *tsk, unsigned long *sp)
230{
231 show_stacktrace(tsk, NULL);
232}
233
234
235
236
237
238unsigned int get_wchan(struct task_struct *tsk)
239{
240 return arc_unwind_core(tsk, NULL, __get_first_nonsched, NULL);
241}
242
243#ifdef CONFIG_STACKTRACE
244
245
246
247
248
249void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
250{
251
252 arc_unwind_core(tsk, NULL, __collect_all_but_sched, trace);
253}
254
255void save_stack_trace(struct stack_trace *trace)
256{
257
258 arc_unwind_core(NULL, NULL, __collect_all, trace);
259}
260EXPORT_SYMBOL_GPL(save_stack_trace);
261#endif
262