levents.c
10 KB
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
28
29
30
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
/*
EVENTS.C
Utility routines for reading events sections.
*/
#include <elf_abi.h>
#include <elf_mips.h>
#include <sys/types.h>
#include <sys/syssgi.h>
#include "leb128.h"
#include "events.h"
/*
* just return 0 until we write the
* routine to return the raw compressed
* number.
*/
#define event_raw_leb(_ptr, _len) 0
/*******************************************************
Function: event_get_word64
Put the next 8 bytes of data into an unsigned
64 bit double word. This only works for big endian.
*******************************************************/
__uint64_t
event_get_word64(char *p)
{
__uint64_t i;
union {
__uint64_t u;
char a[8];
}x;
for (i = 0; i < 8; i++)
x.a[i] = p[i];
return(x.u);
}
/*******************************************************
Function: event_get_word32
Put the next 4 bytes of data into an unsigned
32 bit word. This only works for big endian.
*******************************************************/
__uint32_t
event_get_word32(char *p)
{
__uint32_t i;
union {
__uint32_t u;
char a[4];
}x;
for (i = 0; i<4; i++)
x.a[i] = p[i];
return(x.u);
}
/*******************************************************
Function: event_get_word16
Put the next 2 bytes of data into an unsigned
16 bit word. This only works for big endian.
*******************************************************/
unsigned short
event_get_word16(char *p)
{
__uint32_t i;
union {
unsigned short u;
char a[2];
}x;
for (i = 0; i<2; i++)
x.a[i] = p[i];
return(x.u);
}
/*******************************************************
Function: event_get_next_rec
Get information from the events section record
pointed to by p_event and return a pointer to the
next record.
*******************************************************/
char *
event_get_next_rec(
char *p_event, /* pointer into section */
__uint32_t offset, /* current offset into text section */
Full_Events *p_full) /* information from record */
{
int temp_offset; /* used for EK_FCALL_LOCAL */
unsigned char type, ubyte;
unsigned short ushort;
short sshort;
__uint32_t uword;
__int32_t incr;
char *p_last;
p_full->fevnt_arg1 = 0;
p_full->fevnt_arg2 = 0;
p_full->fevnt_arg3 = 0;
p_full->fevnt_pre_arg1 = 0;
p_full->fevnt_pre_arg2 = 0;
p_full->fevnt_pre_arg3 = 0;
type = *p_event++;
/*
* Increment the current offset by the lower 7 bits
* of the first byte multiplied by 4.
*/
if (type & EK_INCR_LOC) {
p_full->fevnt_pre_arg1 = (type & 0x7f);
p_full->fevnt_arg1 = (type & 0x7f) << 2;
offset += (type & 0x7f) << 2;
p_full->fevnt_type = EK_INCR_LOC;
p_full->fevnt_offset = offset;
return (p_event);
}
p_last = p_event;
switch((int)type) {
/*
* Resets the offset. The first argument is
* a 32 bit offset from the beginning of the
* text section this events section is representing.
* The second argument is a 16 bit offset to where
* the next EK_ADDR_RESET record is.
*/
case EK_ADDR_RESET:
offset = event_get_word32(p_event);
p_full->fevnt_arg1 = offset;
p_full->fevnt_pre_arg1 = offset;
p_event += 4;
ushort = event_get_word16(p_event);
p_full->fevnt_arg2 = ushort;
p_full->fevnt_pre_arg2 = ushort;
p_event += 2;
break;
/*
* Increment the current offset. The increment is
* an unsigned LEB128 value and is multiplied by 4
* after decompression.
*/
case EK_INCR_LOC_EXT:
p_event = uncompress_u4(p_event, &uword);
p_full->fevnt_arg1 = uword<<2;
offset += uword<<2;
p_full->fevnt_pre_arg1 = event_raw_leb(p_last, p_event-p_last);
break;
/*
* Increment the current offset. The increment is
* an unsigned LEB128 value.
*/
case EK_INCR_LOC_UNALIGNED:
p_event = uncompress_u4(p_event, &uword);
p_full->fevnt_arg1 = uword;
offset += uword;
p_full->fevnt_pre_arg1 = event_raw_leb(p_last, p_event-p_last);
break;
/*
* 16 bit argument is the lower half of the
* displacement from gp for a 2 part gp prolog.
*/
case EK_GP_PROLOG_HI: /* fall through */
/*
* 16 bit argument is the upper half of the
* displacement from gp for a 2 part gp prolog.
*/
case EK_GP_PROLOG_LO: /* fall through */
/*
* 16 bit argument is the offset from the
* base page for a 2 part gp page + offset.
*/
case EK_GOT_PAGE: /* fall through */
/*
* 16 bit argument is the displacement from the
* gp for a got page entry for a 2 part gp page + offset.
*/
case EK_GOT_OFST:
/*
* 16 bit argument is the LO part of the 32bit address.
*/
case EK_HI: /* fall through */
/*
* 16 bit argument is the HI part of the 32bit address.
*/
case EK_LO: /* fall through */
#if 0
case EK_CK_UNUSED_16BIT_0:
case EK_CK_UNUSED_16BIT_1:
case EK_CK_UNUSED_16BIT_2:
case EK_CK_UNUSED_16BIT_3:
case EK_CK_UNUSED_16BIT_4:
#endif
sshort = (short)event_get_word16(p_event);
p_full->fevnt_arg1 = sshort;
p_full->fevnt_pre_arg1 = sshort;
p_event += 2;
break;
/*
* For each of the following 4 cases, the argument is
* the full 64bit address.
*/
case EK_64_HIGHEST:
case EK_64_HIGHER:
case EK_64_HIGH:
case EK_64_LOW:
#if 0
case EK_CK_UNUSED_64BIT_0:
case EK_CK_UNUSED_64BIT_1:
case EK_CK_UNUSED_64BIT_2:
case EK_CK_UNUSED_64BIT_3:
case EK_CK_UNUSED_64BIT_4:
#endif
p_full->fevnt_arg1 = event_get_word64(p_event);
p_full->fevnt_pre_arg1 = p_full->fevnt_arg1;
p_event += 8;
break;
/*
* argument1 - 1 byte flag
* argument2 - 32bit address
* argument2 - ULEB128 value
*/
case EK_SWITCH_32:
p_full->fevnt_arg1 = *p_event++;
p_full->fevnt_arg2 = event_get_word32 (p_event);
p_event += 4;
p_event = uncompress_u4 (p_event, &uword);
p_full->fevnt_arg3 = uword;
break;
/*
* argument1 - 1 byte flag
* argument2 - 64bit address
* argument2 - ULEB128 value
*/
case EK_SWITCH_64:
p_full->fevnt_arg1 = *p_event++;
p_full->fevnt_arg2 = event_get_word64 (p_event);
p_event += 8;
p_event = uncompress_u4 (p_event, &uword);
p_full->fevnt_arg3 = uword;
break;
/*
* Specifies the alignment for the current location.
* The length is an unsigned LEB128 value.
* The alignment is a one byte field with a number in the
* range of 0 to 63.
*/
case CK_ALIGN:
p_event = uncompress_u4(p_event, &uword);
p_full->fevnt_arg1 = uword;
p_full->fevnt_pre_arg1 = event_raw_leb(p_last, p_event-p_last);
ubyte = *p_event++;
p_full->fevnt_arg2 = ubyte;
break;
case CK_DEFAULT: /* Default dat type for section. */
ubyte = *p_event++;
p_full->fevnt_arg2 = ubyte;
break;
case CK_INSTR: /* Executable instructions. */
case CK_DATA: /* Non-address data. */
case CK_SADDR_32: /* Simple 32-bit address data. */
case CK_GADDR_32: /* GP-relative 32-bit address data. */
case CK_CADDR_32: /* Complex 32-bit address data. */
case CK_SADDR_64: /* Simple 64-bit address data. */
case CK_GADDR_64: /* relative 64-bit address data. */
case CK_CADDR_64: /* Complex 64-bit address data. */
case CK_NO_XFORM: /* No transformations of instructions allowed. */
case CK_NO_REORDER: /* No reordering of instructions allowed. */
case EK_FCALL_MULT:
case EK_FCALL_MULT_PARTIAL:
#if 0
case EK_CK_UNUSED_ULEB128_0:
case EK_CK_UNUSED_ULEB128_1:
case EK_CK_UNUSED_ULEB128_2:
case EK_CK_UNUSED_ULEB128_3:
case EK_CK_UNUSED_ULEB128_4:
case EK_CK_UNUSED_ULEB128_5:
case EK_CK_UNUSED_ULEB128_6:
case EK_CK_UNUSED_ULEB128_7:
case EK_CK_UNUSED_ULEB128_8:
case EK_CK_UNUSED_ULEB128_9:
#endif
p_event = uncompress_u4(p_event, &uword);
p_full->fevnt_arg1 = uword;
p_full->fevnt_pre_arg1 = event_raw_leb(p_last, p_event-p_last);
break;
case EK_BB_START: /* hard to find basic block start */
case EK_NULL: /* padding record */
case EK_ENTRY: /* Marks an entry point into the subprogram. */
case EK_EXIT: /* Marks final exit points of a subprogram. */
case EK_PEND: /* Marks the last instruction of a subprogram. */
case EK_GPREL: /* Marks a GP-relative reference. */
#if 0
case EK_CK_UNUSED_NONE_0:
case EK_CK_UNUSED_NONE_1:
case EK_CK_UNUSED_NONE_2:
case EK_CK_UNUSED_NONE_3:
case EK_CK_UNUSED_NONE_4:
#endif
break;
/*
* argument1 - 4 byte unsigned
*/
case EK_IF_ENTRY:
case EK_FCALL_LOCAL:
#if 0
case EK_CK_UNUSED_32BIT_0:
case EK_CK_UNUSED_32BIT_1:
case EK_CK_UNUSED_32BIT_2:
#endif
temp_offset = event_get_word32(p_event);
p_full->fevnt_arg1 = temp_offset;
p_full->fevnt_pre_arg1 = temp_offset;
p_event += 4;
break;
case EK_FCALL_EXTERN_BIG:
ushort = event_get_word16(p_event);
p_full->fevnt_arg1 = ushort;
p_full->fevnt_pre_arg1 = ushort;
p_event += 2;
ushort = event_get_word16(p_event);
p_full->fevnt_arg2 = ushort;
p_full->fevnt_pre_arg2 = ushort;
p_event += 2;
break;
/*
* argument1 - 2 byte unsigned
*/
case EK_FCALL_EXTERN:
ushort = event_get_word16(p_event);
p_full->fevnt_arg1 = ushort;
p_full->fevnt_pre_arg1 = ushort;
p_event += 2;
break;
default:
/* TODO: Print an error message here. */
break;
}
p_full->fevnt_offset = offset;
p_full->fevnt_type = type;
return(p_event);
}
/*******************************************************
Function: event_find_record
starting at the given point in the section
pointed to by p_event, find the next events
section record of the given type.
It is assumed that the current offset comming
into this routine will be stored in p_full.
Returns EK_NULL if type not found.
*******************************************************/
__uint32_t
event_find_record(
char *p_event, /* pointer into the events section */
Full_Events *p_full, /* structure for events record info */
__uint32_t type, /* event section type */
char *p_end) /* end of the current events section */
{
while (p_event < p_end) {
p_event = event_get_next_rec(p_event, p_full->fevnt_offset, p_full);
if (p_full->fevnt_type == type)
return((__uint32_t)type);
}
return (EK_NULL);
}