Debian Codegraph @

tapset/arm64/registers.stp

raw
1 /* Dwarfless register access for arm64 */
2 /* TODO: handle 32-bit access of registers */
3
4 @__private30 global _reg_offsets[37], _r32_offsets[31]
5
6 probe init {
7 /* Same order as pt_regs */
8 _reg_offsets["x0"] = 0
9 _reg_offsets["x1"] = 8
10 _reg_offsets["x2"] = 16
11 _reg_offsets["x3"] = 24
12 _reg_offsets["x4"] = 32
13 _reg_offsets["x5"] = 40
14 _reg_offsets["x6"] = 48
15 _reg_offsets["x7"] = 56
16 _reg_offsets["x8"] = 64
17 _reg_offsets["x9"] = 72
18 _reg_offsets["x10"] = 80
19 _reg_offsets["x11"] = 88
20 _reg_offsets["x12"] = 96
21 _reg_offsets["x13"] = 104
22 _reg_offsets["x14"] = 112
23 _reg_offsets["x15"] = 120
24 _reg_offsets["x16"] = 128
25 _reg_offsets["x17"] = 136
26 _reg_offsets["x18"] = 144
27 _reg_offsets["x19"] = 152
28 _reg_offsets["x20"] = 160
29 _reg_offsets["x21"] = 168
30 _reg_offsets["x22"] = 176
31 _reg_offsets["x23"] = 184
32 _reg_offsets["x24"] = 192
33 _reg_offsets["x25"] = 200
34 _reg_offsets["x26"] = 208
35 _reg_offsets["x27"] = 216
36 _reg_offsets["x28"] = 224
37 _reg_offsets["x29"] = 232 _reg_offsets["fp"] = 232
38 _reg_offsets["x30"] = 240 _reg_offsets["lr"] = 240
39 _reg_offsets["sp"] = 248
40 _reg_offsets["pc"] = 256
41 _reg_offsets["pstate"] = 264
42 _reg_offsets["orig_x0"] = 272
43
44 _r32_offsets["w0"] = 0
45 _r32_offsets["w1"] = 8
46 _r32_offsets["w2"] = 16
47 _r32_offsets["w3"] = 24
48 _r32_offsets["w4"] = 32
49 _r32_offsets["w5"] = 40
50 _r32_offsets["w6"] = 48
51 _r32_offsets["w7"] = 56
52 _r32_offsets["w8"] = 64
53 _r32_offsets["w9"] = 72
54 _r32_offsets["w10"] = 80
55 _r32_offsets["w11"] = 88
56 _r32_offsets["w12"] = 96
57 _r32_offsets["w13"] = 104
58 _r32_offsets["w14"] = 112
59 _r32_offsets["w15"] = 120
60 _r32_offsets["w16"] = 128
61 _r32_offsets["w17"] = 136
62 _r32_offsets["w18"] = 144
63 _r32_offsets["w19"] = 152
64 _r32_offsets["w20"] = 160
65 _r32_offsets["w21"] = 168
66 _r32_offsets["w22"] = 176
67 _r32_offsets["w23"] = 184
68 _r32_offsets["w24"] = 192
69 _r32_offsets["w25"] = 200
70 _r32_offsets["w26"] = 208
71 _r32_offsets["w27"] = 216
72 _r32_offsets["w28"] = 224
73 _r32_offsets["w29"] = 232
74 _r32_offsets["w30"] = 240
75 }
76
77 function probing_32bit_app:long() %{ /* pure */
78 STAP_RETVALUE = (CONTEXT->user_mode_p && _stp_is_compat_task());
79 %}
80
81 function arch_bytes:long() %{ /* pure */
82 STAP_RETVALUE = sizeof(long);
83 %}
84
85 function uarch_bytes:long() {
86 assert(user_mode(), "requires user mode")
87 return probing_32bit_app() ? 4 : 8
88 }
89
90 function _stp_get_register_by_offset:long (offset:long) %{ /* pure */
91 long value;
92 struct pt_regs *regs;
93 if (CONTEXT->sregs)
94 regs = CONTEXT->sregs;
95 else
96 regs = (CONTEXT->user_mode_p ? CONTEXT->uregs : CONTEXT->kregs);
97 if (!regs) {
98 CONTEXT->last_error = "No registers available in this context";
99 return;
100 }
101 if (STAP_ARG_offset < 0 || STAP_ARG_offset > sizeof(struct pt_regs) - sizeof(long)) {
102 snprintf(CONTEXT->error_buffer, sizeof(CONTEXT->error_buffer),
103 "Bad register offset: %lld",
104 (long long)STAP_ARG_offset);
105 CONTEXT->last_error = CONTEXT->error_buffer;
106 return;
107 }
108 memcpy(&value, ((char *)regs) + STAP_ARG_offset, sizeof(value));
109 STAP_RETVALUE = value;
110 %}
111
112 function _stp_sign_extend32:long (value:long) {
113 if (value & 0x80000000)
114 value |= (0xffffffff << 32)
115 return value
116 }
117
118 function _stp_register:long (name:string, sign_extend:long) {
119 reg32 = 0
120 assert(registers_valid(), "cannot access CPU registers in this context")
121 offset = _reg_offsets[name]
122 if (offset == 0 && !(name in _reg_offsets)) {
123 offset = _r32_offsets[name]
124 if (offset == 0 && !(name in _r32_offsets)) {
125 assert(0, "Unknown register: " . name)
126 }
127 reg32 = 1;
128 }
129 value = _stp_get_register_by_offset(offset)
130 if (reg32 || probing_32bit_app()) {
131 if (sign_extend)
132 value = _stp_sign_extend32(value)
133 else
134 value &= 0xffffffff
135 }
136 return value
137 }
138
139 /* Return the named register value as a signed value. */
140 function register:long (name:string) {
141 return _stp_register(name, 1)
142 }
143
144 /*
145 * Return the named register value as an unsigned value. Specifically,
146 * don't sign-extend the register value when promoting it to 64 bits.
147 */
148 function u_register:long (name:string) {
149 return _stp_register(name, 0)
150 }
151
152 /*
153 * Return the value of function arg #argnum (1=first arg).
154 * If truncate=1, mask off the top 32 bits.
155 * If sign_extend=1 and (truncate=1 or the probepoint we've hit is in a
156 * 32-bit app), sign-extend the 32-bit value.
157 * TODO: 32-bit arm code has different calling conventions than arm64
158 */
159 function _stp_arg:long (argnum:long, sign_extend:long, truncate:long) {
160 val = 0
161 assert(!(argnum < 1 || argnum > 8), sprintf("Cannot access arg(%d)", argnum))
162
163 if (argnum == 1)
164 val = u_register("x0")
165 else if (argnum == 2)
166 val = u_register("x1")
167 else if (argnum == 3)
168 val = u_register("x2")
169 else if (argnum == 4)
170 val = u_register("x3")
171 else if (argnum == 5)
172 val = u_register("x4")
173 else if (argnum == 6)
174 val = u_register("x5")
175 else if (argnum == 7)
176 val = u_register("x6")
177 else if (argnum == 8)
178 val = u_register("x7")
179
180 if (truncate) {
181 if (sign_extend)
182 val = _stp_sign_extend32(val)
183 else
184 /* High bits may be garbage. */
185 val = (val & 0xffffffff);
186 }
187 return val;
188 }
189
190 /*
191 * Return a pointer to an argument given its offset in pt_regs.
192 */
193 function _stp_offset_to_argptr:long (offset:long) %{
194 struct pt_regs *regs = CONTEXT->sregs;
195
196 if (!regs) {
197 snprintf(CONTEXT->error_buffer, sizeof(CONTEXT->error_buffer),
198 "cannot access function args in this context");
199 CONTEXT->last_error = CONTEXT->error_buffer;
200 return;
201 }
202 if (STAP_ARG_offset < 0
203 || STAP_ARG_offset > sizeof(struct pt_regs) - sizeof(long)) {
204 snprintf(CONTEXT->error_buffer, sizeof(CONTEXT->error_buffer),
205 "Bad register offset: %lld",
206 (long long)STAP_ARG_offset);
207 CONTEXT->last_error = CONTEXT->error_buffer;
208 return;
209 }
210 STAP_RETVALUE = (unsigned long)(((char *)regs) + STAP_ARG_offset);
211 %}
212
213 /*
214 * Return a pointer to function argument #argnum (1=first arg).
215 */
216 function _stp_get_argptr:long (argnum:long) {
217 off = 0
218 assert(!(argnum < 1 || argnum > 8), sprintf("Cannot access arg(%d)", argnum))
219
220 if (argnum == 1)
221 off = _reg_offsets["x0"]
222 else if (argnum == 2)
223 off = _reg_offsets["x1"]
224 else if (argnum == 3)
225 off = _reg_offsets["x2"]
226 else if (argnum == 4)
227 off = _reg_offsets["x3"]
228 else if (argnum == 5)
229 off = _reg_offsets["x4"]
230 else if (argnum == 6)
231 off = _reg_offsets["x5"]
232 else if (argnum == 7)
233 off = _reg_offsets["x6"]
234 else if (argnum == 8)
235 off = _reg_offsets["x7"]
236
237 return _stp_offset_to_argptr(off)
238 }
239
240 /* Return the value of function arg #argnum (1=first arg) as a signed int. */
241 function int_arg:long (argnum:long) {
242 return _stp_arg(argnum, 1, 1)
243 }
244
245 /* Return the value of function arg #argnum (1=first arg) as an unsigned int. */
246 function uint_arg:long (argnum:long) {
247 return _stp_arg(argnum, 0, 1)
248 }
249
250 function long_arg:long (argnum:long) {
251 return _stp_arg(argnum, 1, 0)
252 }
253
254 function ulong_arg:long (argnum:long) {
255 return _stp_arg(argnum, 0, 0)
256 }
257
258 function longlong_arg:long (argnum:long) {
259 if (probing_32bit_app()) {
260 lowbits = _stp_arg(argnum, 0, 1)
261 highbits = _stp_arg(argnum+1, 0, 1)
262 return ((highbits << 32) | lowbits)
263 } else
264 return _stp_arg(argnum, 0, 0)
265 }
266
267 function ulonglong_arg:long (argnum:long) {
268 return longlong_arg(argnum)
269 }
270
271 function pointer_arg:long (argnum:long) {
272 return _stp_arg(argnum, 0, 0)
273 }
274
275 function s32_arg:long (argnum:long) {
276 return int_arg(argnum)
277 }
278
279 function u32_arg:long (argnum:long) {
280 return uint_arg(argnum)
281 }
282
283 function s64_arg:long (argnum:long) {
284 return longlong_arg(argnum)
285 }
286
287 function u64_arg:long (argnum:long) {
288 return ulonglong_arg(argnum)
289 }
290
291 /* Set the value of function arg #argnum (1=first arg) as a signed int. */
292 function set_int_arg:long (argnum:long, value:long) {
293 return set_kernel_int(_stp_get_argptr(argnum), value)
294 }
295
296 /* Return the value of function arg #argnum (1=first arg) as an unsigned int. */
297 function set_uint_arg:long (argnum:long, value:long) {
298 return set_int_arg(argnum, value)
299 }
300
301 function set_long_arg:long (argnum:long, value:long) {
302 return set_kernel_long(_stp_get_argptr(argnum), value)
303 }
304
305 function set_ulong_arg:long (argnum:long, value:long) {
306 return set_long_arg(argnum, value)
307 }
308
309 function set_longlong_arg:long (argnum:long, value:long) {
310 if (probing_32bit_app()) {
311 highbits = value >> 32
312 lowbits = value & 0xffffffff
313 set_u32_arg(argnum, lowbits)
314 set_u32_arg(argnum+1, highbits)
315 } else
316 set_long_arg(argnum, value)
317 }
318
319 function set_ulonglong_arg:long (argnum:long, value:long) {
320 return set_longlong_arg(argnum, value)
321 }
322
323 function set_pointer_arg:long (argnum:long, value:long) {
324 return set_kernel_pointer(_stp_get_argptr(argnum), value)
325 }
326
327 function set_s32_arg:long (argnum:long, value:long) {
328 return set_int_arg(argnum, value)
329 }
330
331 function set_u32_arg:long (argnum:long, value:long) {
332 return set_uint_arg(argnum, value)
333 }
334
335 function set_s64_arg:long (argnum:long, value:long) {
336 return set_longlong_arg(argnum, value)
337 }
338
339 function set_u64_arg:long (argnum:long, value:long) {
340 return set_ulonglong_arg(argnum, value)
341 }
342 function asmlinkage() %{ /* pure */ %}
343
344 function fastcall() %{ /* pure */ %}
345
346 function regparm(n:long) %{
347 snprintf(CONTEXT->error_buffer, sizeof(CONTEXT->error_buffer),
348 "regparm is invalid on arm64.");
349 CONTEXT->last_error = CONTEXT->error_buffer;
350 %}