Debian Codegraph @

tapset/mips/registers.stp

raw
1 /* Dwarfless register access for mips */
2
3 global _reg_offsets, _stp_regs_registered
4
5 function _stp_register_regs() {
6 offset_acx = 0
7 %( CONFIG_64BIT == "y" %?
8 /* n32/n64 registers naming scheme */
9 /* Same order as struct pt_regs */
10 _reg_offsets["zero"] = 0
11 _reg_offsets["at"] = 8
12 _reg_offsets["v0"] = 16
13 _reg_offsets["v1"] = 24
14 _reg_offsets["a0"] = 32
15 _reg_offsets["a1"] = 40
16 _reg_offsets["a2"] = 48
17 _reg_offsets["a3"] = 56
18 _reg_offsets["a4"] = 64
19 _reg_offsets["a5"] = 72
20 _reg_offsets["a6"] = 80
21 _reg_offsets["a7"] = 88
22 _reg_offsets["t0"] = 96
23 _reg_offsets["t1"] = 104
24 _reg_offsets["t2"] = 112
25 _reg_offsets["t3"] = 120
26 _reg_offsets["s0"] = 128
27 _reg_offsets["s1"] = 136
28 _reg_offsets["s2"] = 144
29 _reg_offsets["s3"] = 152
30 _reg_offsets["s4"] = 160
31 _reg_offsets["s5"] = 168
32 _reg_offsets["s6"] = 176
33 _reg_offsets["s7"] = 184
34 _reg_offsets["t8"] = 192
35 _reg_offsets["t9"] = 200
36 _reg_offsets["k0"] = 208
37 _reg_offsets["k1"] = 216
38 _reg_offsets["gp"] = 224
39 _reg_offsets["sp"] = 232
40 _reg_offsets["s8"] = 240 _reg_offsets["fp"] = 240
41 _reg_offsets["ra"] = 248
42
43 _reg_offsets["status"] = 256
44 _reg_offsets["hi"] = 264
45 _reg_offsets["lo"] = 272
46
47 %( CONFIG_CPU_HAS_SMARTMIPS == "y" %?
48 _reg_offsets["acx"] = 280
49 offset_acx = 8
50 %)
51 _reg_offsets["badvaddr"] = 280 + offset_acx
52 _reg_offsets["cause"] = 288 + offset_acx
53 _reg_offsets["epc"] = 296 + offset_acx
54
55 /* no cp0_tcstatus register for now */
56 %( CONFIG_CPU_CAVIUM_OCTEON == "y" %?
57 _reg_offsets["mpl0"] = 304 + offset_acx
58 _reg_offsets["mpl1"] = 310 + offset_acx
59 _reg_offsets["mpl2"] = 318 + offset_acx
60 _reg_offsets["mtp0"] = 316 + offset_acx
61 _reg_offsets["mtp1"] = 324 + offset_acx
62 _reg_offsets["mtp2"] = 330 + offset_acx
63 %)
64
65 %:
66 /* o32 registers naming scheme */
67 /* Same order as struct pt_regs */
68 _reg_offsets["zero"] = 24
69 _reg_offsets["at"] = 28
70 _reg_offsets["v0"] = 32
71 _reg_offsets["v1"] = 36
72 _reg_offsets["a0"] = 40
73 _reg_offsets["a1"] = 44
74 _reg_offsets["a2"] = 48
75 _reg_offsets["a3"] = 52
76 _reg_offsets["t0"] = 56
77 _reg_offsets["t1"] = 60
78 _reg_offsets["t2"] = 64
79 _reg_offsets["t3"] = 68
80 _reg_offsets["t4"] = 72
81 _reg_offsets["t5"] = 76
82 _reg_offsets["t6"] = 80
83 _reg_offsets["t7"] = 84
84 _reg_offsets["s0"] = 88
85 _reg_offsets["s1"] = 92
86 _reg_offsets["s2"] = 96
87 _reg_offsets["s3"] = 100
88 _reg_offsets["s4"] = 104
89 _reg_offsets["s5"] = 108
90 _reg_offsets["s6"] = 112
91 _reg_offsets["s7"] = 116
92 _reg_offsets["t8"] = 120
93 _reg_offsets["t9"] = 124
94 _reg_offsets["k0"] = 128
95 _reg_offsets["k1"] = 132
96 _reg_offsets["gp"] = 136
97 _reg_offsets["sp"] = 140
98 _reg_offsets["s8"] = 144 _reg_offsets["fp"] = 144
99 _reg_offsets["ra"] = 148
100
101 _reg_offsets["status"] = 152
102 _reg_offsets["hi"] = 156
103 _reg_offsets["lo"] = 160
104
105 %( CONFIG_CPU_HAS_SMARTMIPS == "y" %?
106 _reg_offsets["acx"] = 164
107 offset_acx = 4
108 %)
109 _reg_offsets["badvaddr"] = 164 + offset_acx
110 _reg_offsets["cause"] = 168 + offset_acx
111 _reg_offsets["epc"] = 172 + offset_acx
112
113 /* no cp0_tcstatus register for now */
114 /* no mpl and mtp registers for now */
115 %)
116 _stp_regs_registered = 1
117 }
118
119 function probing_app_with_32bit_regs() %{ /* pure */
120 struct pt_regs *regs;
121 regs = (CONTEXT->user_mode_p ? CONTEXT->uregs : NULL );
122 STAP_RETVALUE = _stp_probing_app_with_32bit_regs(regs);
123 %}
124
125 function _stp_get_register_by_offset:long (offset:long) %{ /* pure */
126 long value;
127 struct pt_regs *regs;
128 regs = (CONTEXT->user_mode_p ? CONTEXT->uregs : CONTEXT->kregs);
129
130 if (!regs) {
131 CONTEXT->last_error = "No registers available in this context";
132 return;
133 }
134 if (STAP_ARG_offset < 0 || STAP_ARG_offset > sizeof(struct pt_regs) - sizeof(long)) {
135 snprintf(CONTEXT->error_buffer, sizeof(CONTEXT->error_buffer),
136 "Bad register offset: %lld", STAP_ARG_offset);
137 CONTEXT->last_error = CONTEXT->error_buffer;
138 return;
139 }
140 memcpy(&value, ((char *)regs) + STAP_ARG_offset, sizeof(value));
141 STAP_RETVALUE = value;
142 %}
143
144 function _stp_sign_extend32:long (value:long) {
145 if (value & 0x80000000)
146 value |= (0xffffffff << 32)
147 return value
148 }
149
150 function _stp_register:long (name:string, sign_extend:long) {
151 if (!registers_valid()) {
152 error("cannot access CPU registers in this context")
153 return 0
154 }
155 if (!_stp_regs_registered)
156 _stp_register_regs()
157 offset = _reg_offsets[name]
158 if (offset == 0 && !(name in _reg_offsets)) {
159 error("Unknown register: " . name)
160 return 0
161 }
162 value = _stp_get_register_by_offset(offset)
163 %( CONFIG_64BIT == "y" %?
164 if (probing_app_with_32bit_regs()) {
165 %)
166 if (sign_extend)
167 value = _stp_sign_extend32(value)
168 else
169 value &= 0xffffffff
170 %( CONFIG_64BIT == "y" %?
171 }
172 %)
173 return value
174 }
175
176 /* Return the named register value as a signed value. */
177 function register:long (name:string) {
178 return _stp_register(name, 1)
179 }
180
181 /*
182 * Return the named register value as an unsigned value. Specifically,
183 * don't sign-extend the register value when promoting it to 64 bits.
184 */
185 function u_register:long (name:string) {
186 return _stp_register(name, 0)
187 }
188
189
190 /* Dwarfless register access for mips */
191
192 %{
193 // These functions are largely lifted from arch/mips/include/ptrace.h.
194
195 static inline unsigned long _stp_kernel_stack_pointer(struct pt_regs *regs)
196 {
197 return regs->regs[31];
198 }
199
200 /**
201 * _stp_regs_within_kernel_stack() - check the address in the stack
202 * @regs: pt_regs which contains kernel stack pointer.
203 * @addr: address which is checked.
204 *
205 * _stp_regs_within_kernel_stack() checks @addr is within the kernel stack page(s).
206 * If @addr is within the kernel stack, it returns true. If not, returns false.
207 */
208 static inline int _stp_regs_within_kernel_stack(struct pt_regs *regs, unsigned long addr)
209 {
210 return ((addr & ~(THREAD_SIZE - 1)) ==
211 (_stp_kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1)));
212 }
213
214 /*
215 * _stp_regs_get_kernel_stack_nth_addr() - get address of the Nth entry of the stack
216 * @regs: pt_regs which contains kernel stack pointer.
217 * @n: stack entry number.
218 *
219 * _stp_regs_get_kernel_stack_nth_addr() returns the address of the @n
220 * th entry of the kernel stack which is specified by @regs. If the @n
221 * th entry is NOT in the kernel stack, this returns 0.
222 */
223 long *
224 _stp_regs_get_kernel_stack_nth_addr(struct pt_regs *regs, unsigned int n)
225 {
226 long *addr = (unsigned long *)_stp_kernel_stack_pointer(regs);
227 addr += n;
228 if (_stp_regs_within_kernel_stack(regs, (unsigned long)addr))
229 return addr;
230 else
231 return 0;
232 }
233
234 %}
235
236 function _stp_get_stack_nth:long (n:long)
237 %{ /* pure */
238 __label__ deref_fault;
239 unsigned int n = (unsigned int)STAP_ARG_n;
240 struct pt_regs *regs;
241 long *addr;
242
243 STAP_RETVALUE = 0;
244 if (CONTEXT->user_mode_p) {
245 // This function only handles kernel arguments off the stack.
246 snprintf(CONTEXT->error_buffer, sizeof(CONTEXT->error_buffer),
247 "cannot access function args in this context");
248 CONTEXT->last_error = CONTEXT->error_buffer;
249 return;
250 }
251 regs = CONTEXT->kregs;
252 if (!regs) {
253 snprintf(CONTEXT->error_buffer, sizeof(CONTEXT->error_buffer),
254 "cannot access function args in this context");
255 CONTEXT->last_error = CONTEXT->error_buffer;
256 return;
257 }
258
259 /* Get the address of the nth item on the stack. */
260 addr = _stp_regs_get_kernel_stack_nth_addr(regs, n);
261 if (addr == NULL) {
262 snprintf(CONTEXT->error_buffer, sizeof(CONTEXT->error_buffer),
263 "cannot access stack arg(%d)", n);
264 CONTEXT->last_error = CONTEXT->error_buffer;
265 return;
266 }
267 STAP_RETVALUE = kread(addr);
268 return;
269
270 deref_fault: /* branched to from kread() */
271 snprintf(CONTEXT->error_buffer, sizeof(CONTEXT->error_buffer),
272 "kernel fault at %#lx accessing stack arg(%d)",
273 (unsigned long)addr, n);
274 CONTEXT->last_error = CONTEXT->error_buffer;
275 %}
276
277 /*
278 * Return the value of function arg #argnum (1=first arg).
279 * If truncate=1, mask off the top 32 bits.
280 * If sign_extend=1 and (truncate=1 or the probepoint we've hit is in a
281 * 32-bit app), sign-extend the 32-bit value.
282 */
283 function _stp_arg:long (argnum:long, sign_extend:long, truncate:long) {
284 val = 0
285 if (argnum < 1 || argnum > 8) {
286 error(sprintf("Cannot access arg(%d)", argnum))
287 return 0
288 }
289
290 if (argnum == 1)
291 val = u_register("a0")
292 else if (argnum == 2)
293 val = u_register("a1")
294 else if (argnum == 3)
295 val = u_register("a2")
296 else if (argnum == 4)
297 val = u_register("a3")
298 %( CONFIG_64BIT == "y" %?
299 else if (argnum == 5)
300 val = u_register("a4")
301 else if (argnum == 6)
302 val = u_register("a5")
303 else if (argnum == 7)
304 val = u_register("a6")
305 else if (argnum == 8)
306 val = u_register("a7")
307 %:
308 else
309 val = _stp_get_stack_nth(argnum - 5)
310 %)
311
312 if (truncate) {
313 if (sign_extend)
314 val = _stp_sign_extend32(val)
315 else
316 /* High bits may be garbage. */
317 val = (val & 0xffffffff);
318 }
319 return val;
320 }
321
322 function probing_32bit_app:long() %{ /* pure */
323 STAP_RETVALUE = (CONTEXT->user_mode_p && _stp_is_compat_task());
324 %}
325
326 function arch_bytes:long() %{ /* pure */
327 STAP_RETVALUE = sizeof(long);
328 %}
329
330 function uarch_bytes:long() {
331 assert(user_mode(), "requires user mode")
332 return probing_32bit_app() ? 4 : 8
333 }
334
335 /* Return the value of function arg #argnum (1=first arg) as a signed int. */
336 function int_arg:long (argnum:long) {
337 return _stp_arg(argnum, 1, 1)
338 }
339
340 /* Return the value of function arg #argnum (1=first arg) as an unsigned int. */
341 function uint_arg:long (argnum:long) {
342 return _stp_arg(argnum, 0, 1)
343 }
344
345 function long_arg:long (argnum:long) {
346 return _stp_arg(argnum, 1, 0)
347 }
348
349 function ulong_arg:long (argnum:long) {
350 return _stp_arg(argnum, 0, 0)
351 }
352
353 function longlong_arg:long (argnum:long) {
354 if (probing_app_with_32bit_regs()) {
355 lowbits = _stp_arg(argnum, 0, 1)
356 highbits = _stp_arg(argnum+1, 0, 1)
357 return ((highbits << 32) | lowbits)
358 } else
359 return _stp_arg(argnum, 0, 0)
360 }
361
362 function ulonglong_arg:long (argnum:long) {
363 return longlong_arg(argnum)
364 }
365
366 function pointer_arg:long (argnum:long) {
367 return _stp_arg(argnum, 0, 0)
368 }
369
370 function s32_arg:long (argnum:long) {
371 return int_arg(argnum)
372 }
373
374 function u32_arg:long (argnum:long) {
375 return uint_arg(argnum)
376 }
377
378 function s64_arg:long (argnum:long) {
379 return longlong_arg(argnum)
380 }
381
382 function u64_arg:long (argnum:long) {
383 return ulonglong_arg(argnum)
384 }
385
386 function asmlinkage() %{ /* pure */ %}
387
388 function fastcall() %{ /* pure */ %}
389
390 function regparm() %{
391 snprintf(CONTEXT->error_buffer, sizeof(CONTEXT->error_buffer),
392 "regparm is invalid on mips.");
393 CONTEXT->last_error = CONTEXT->error_buffer;
394 %}