-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathADTF_Debug.s
240 lines (178 loc) · 3.69 KB
/
ADTF_Debug.s
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
.include "ADTF_Debug_gen.s"
.file "ADTF_Debug.s"
.text
.global get_function_name
.global print_hex
print_tables:
frame
call_3 print_table, $function_table, function_table_size, $function_table_txt
print $newline
call_3 print_table, $event_table, event_table_size, $event_table_txt
print $newline
call_3 print_table, $option_table, option_table_size, $option_table_txt
leave
ret
print_table:
frame
#arg0 = table pointer
#arg1 = table size
#arg2 = table name char*
movl 12(%ebp), %ebx
movl $0, %esi
println 16(%ebp)
LD0_start:
cmpl %ebx, %esi
jge LD0_end
print $four_space
call_2 get_table_record, 8(%ebp), %esi
pushl %eax #save 1 - record ptr
call_2 get_member, %eax, $0
pushl %eax #save 2 - entry name
print %eax
popl %eax #restore 2
call_1 str_len, %eax
call_2 pad_spaces, %eax, $35
popl %eax #restore 1
call_2 get_member, %eax, $1
call_1 print_hex, %eax
print $newline
incl %esi
jmp LD0_start
LD0_end:
leave
ret
pad_spaces:
frame
#arg0 = number of spaces not to print
#arg1 = max spaces
pushl %esi #save esi, to restore later
movl 8(%ebp), %esi
LD1_start:
cmpl 12(%ebp), %esi
jge LD1_end
print $space
incl %esi
jmp LD1_start
LD1_end:
popl %esi
leave
ret
print_hex:
frame
#arg 0 = number
print $zero_x;
pushl %esi
pushl %ebx
movl $1, %esi
LD3_start:
cmpl $9, %esi
jge LD3_end
movl 8(%ebp), %eax
shift_by roll, %esi, %eax, $4, i
andl $0xF, %eax
movl $hex_table, %ebx
leal (%ebx,%eax,2), %eax
print %eax
incl %esi
jmp LD3_start
LD3_end:
popl %ebx
popl %esi
leave
ret
debug_out:
frame
#arg0 = pointer
#arg1 = char* to value
print $left_bracket
print 12(%ebp)
print $colon
call_1 print_hex, 8(%ebp)
print $right_bracket
leave
ret
get_function_name:
frame
#arg0 = function pointer
call_3 get_name_from_table, $function_table, function_table_size, 8(%ebp)
leave
ret
get_event_name:
frame
#arg0 = event pointer
call_3 get_name_from_table, $event_table, event_table_size, 8(%ebp)
leave
ret
get_option_name:
frame
#arg0 = option pointer
call_3 get_name_from_table, $option_table, option_table_size, 8(%ebp)
leave
ret
get_table_record:
frame
#arg0 = table pointer
#arg1 = index
pushl %esi
movl 12(%ebp), %esi
shll $1, %esi
movl 8(%ebp), %eax
leal (%eax,%esi,4), %eax
popl %esi
leave
ret
get_name_from_table:
frame
#arg0 = table pointer
#arg1 = table length
#arg2 = function pointer
#return = char* to function name, or to string "unknown"
pushl %ebx
pushl %esi
movl 12(%ebp), %ebx
pushl 8(%ebp)
movl $0, %esi
LD2_start:
cmpl %ebx, %esi
jge LD2_fail
call_2 get_table_record, 8(%ebp), %esi
movl %eax, %edx
call_2 get_member, %edx, $1
cmpl 16(%ebp), %eax
je LD2_return
incl %esi
jmp LD2_start
LD2_return:
call_2 get_member, %edx, $0
jmp LD2_final
LD2_fail:
movl $unknown, %eax
LD2_final:
addl $4, %esp
popl %esi
popl %ebx
leave
ret
print_iteration:
frame
#arg0 = iterator
#arg1 = bound
print $iteration
printNum 8(%ebp)
print $of
printNum 12(%ebp)
print $newline
call pause
leave
ret
.data
left_bracket: .string "["
right_bracket: .string "]"
colon: .string " @ "
of: .string " of "
zero_x: .string "0x"
unknown: .string "unknown"
function_table_txt: .string "Functions:"
event_table_txt: .string "Events:"
option_table_txt: .string "Options:"
hex_table: .string "0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"