-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvobj Object File.tcl
106 lines (86 loc) · 2.01 KB
/
vobj Object File.tcl
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
# http://sun.hasenbraten.de/vlink/
requires 0 "56 4F 42 4A"
proc read_number { name } {
global BYTESPERTADDR
set p [pos]
set n 0
set size 0
set n [uint8]
if { $n <= 0x7f} {
entry $name $n 1 $p
return $n
} else {
if {$n >= 0xc0} {
set n [expr $n - 0xc0]
# missing bytes are filled w/ $ff
set val [expr (1 << ($BYTESPERTADDR << 3)) - 1]
} else {
set n [expr $n - 0x80]
set val 0
}
for { set j 0 } {$j < $n} { incr j} {
set x [uint8]
set val [expr $val | ($x << ($j << 3))]
}
# 1 for the header byte
entry $name $val [expr $n + 1] $p
return $val
}
}
section "Header" {
uint32 -hex Magic
set flags [uint8 -hex flags]
if { $flags & 3 == 2 } { little_endian } else { big_endian }
read_number bitsperbyte
set BYTESPERTADDR [read_number bytespertaddr]
cstr "ascii" cpu
set nsections [read_number nsections]
set nsymbols [read_number nsymbols]
}
# 0... nsections sections
section "Symbols" {
for {set i 0} {$i < $nsymbols} {incr i} {
section -collapsed ""
set name [cstr "ascii" name]
sectionname $name
read_number type
read_number flags
read_number index
read_number value
read_number size
endsection
}
}
section "Sections" {
for {set i 0} {$i < $nsections} {incr i} {
section ""
set name [cstr "ascii" name]
sectionname $name
cstr "ascii" attr
read_number flags
read_number align
read_number size
set nrelocs [read_number nrelocs]
set ndata [read_number databytes]
if {$ndata > 0} { bytes $ndata data }
# relocs
for {set r 0} {$r < $nrelocs} {incr r} {
section -collapsed "Reloc ${r}"
set type [read_number "type"]
if {$type >= 0x80} {
# cpu-specific/special type
set size [read_number "size"]
bytes size "data"
} else {
read_number "byte offset"
read_number "bit offset"
read_number "size"
read_number "mask"
read_number "addend"
read_number "symbol index"
}
endsection
}
endsection
}
}