https://github.com/akkartik/mu/blob/master/subx/apps/handle.subx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 == code
24
25
26
27
28
29 e8/call run-tests/disp32
30
31 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/EBX Num-test-failures/disp32
32 b8/copy-to-EAX 1/imm32/exit
33 cd/syscall 0x80/imm8
34
35 new:
36
37 55/push-EBP
38 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
39
40 50/push-EAX
41 51/push-ECX
42 52/push-EDX
43
44 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 1/r32/ECX 0xc/disp8 .
45 81 0/subop/add 3/mod/direct 1/rm32/ECX . . . . . 4/imm32
46
47
48 51/push-ECX
49 ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 .
50
51 e8/call allocate/disp32
52
53 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
54
55 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 2/r32/EDX 0x10/disp8 .
56
57 89/copy 1/mod/*+disp8 2/rm32/EDX . . . 0/r32/EAX 4/disp8 .
58
59 81 7/subop/compare 3/mod/direct 0/rm32/EAX . . . . . 0/imm32
60 75/jump-if-not-equal $new:continue/disp8
61 c7 0/subop/copy 0/mod/indirect 2/rm32/EDX . . . . . 0/imm32
62 eb/jump $new:end/disp8
63 $new:continue:
64
65
66 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 1/r32/ECX Next-alloc-id/disp32
67
68 89/copy 0/mod/indirect 0/rm32/EAX . . . 1/r32/ECX . .
69
70 89/copy 0/mod/indirect 2/rm32/EDX . . . 1/r32/ECX . .
71
72 ff 0/subop/increment 0/mod/indirect 5/rm32/.disp32 . . . Next-alloc-id/disp32
73 $new:end:
74
75 5a/pop-to-EDX
76 59/pop-to-ECX
77 58/pop-to-EAX
78
79 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
80 5d/pop-to-EBP
81 c3/return
82
83 test-new:
84
85 55/push-EBP
86 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
87
88 c7 0/subop/copy 0/mod/indirect 5/rm32/.disp32 . . . Next-alloc-id/disp32 0x34/imm32
89
90 68/push 0/imm32/address
91 68/push 0/imm32/alloc-id
92 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . .
93
94
95 51/push-ECX
96 68/push 2/imm32/size
97 68/push Heap/imm32
98
99 e8/call new/disp32
100
101 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
102
103
104 68/push "F - test-new: alloc id of handle"/imm32
105 68/push 0x34/imm32
106 ff 6/subop/push 0/mod/indirect 1/rm32/ECX . . . . . .
107
108 e8/call check-ints-equal/disp32
109
110 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
111
112
113 68/push "F - test-new: alloc id of payload"/imm32
114 68/push 0x34/imm32
115 8b/copy 1/mod/*+disp8 1/rm32/ECX . . . 2/r32/EDX 4/disp8 .
116 ff 6/subop/push 0/mod/indirect 2/rm32/EDX . . . . . .
117
118 e8/call check-ints-equal/disp32
119
120 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
121
122
123 68/push "F - test-new: next alloc id"/imm32
124 68/push 0x35/imm32
125 ff 6/subop/push 0/mod/indirect 5/rm32/.disp32 . . . Next-alloc-id/disp32
126
127 e8/call check-ints-equal/disp32
128
129 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
130
131
132 c7 0/subop/copy 0/mod/indirect 5/rm32/.disp32 . . . Next-alloc-id/disp32 1/imm32
133
134 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
135 5d/pop-to-EBP
136 c3/return
137
138 test-new-failure:
139
140 55/push-EBP
141 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
142
143 c7 0/subop/copy 0/mod/indirect 5/rm32/.disp32 . . . Next-alloc-id/disp32 0x34/imm32
144
145
146 68/push 0x10/imm32/limit
147 68/push 0x10/imm32/curr
148 89/copy 3/mod/direct 0/rm32/EAX . . . 4/r32/ESP . .
149
150 68/push 1234/imm32/address
151 68/push 5678/imm32/alloc-id
152 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . .
153
154
155
156 51/push-ECX
157 68/push 2/imm32/size
158 50/push-EAX
159
160 e8/call new/disp32
161
162 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
163
164
165
166 68/push "F - test-new-failure: alloc id of handle"/imm32
167 68/push 0/imm32
168 ff 6/subop/push 0/mod/indirect 1/rm32/ECX . . . . . .
169
170 e8/call check-ints-equal/disp32
171
172 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
173
174
175 68/push "F - test-new-failure: address of handle"/imm32
176 68/push 0/imm32
177 ff 6/subop/push 1/mod/*+disp8 1/rm32/ECX . . . . 4/disp8 .
178
179 e8/call check-ints-equal/disp32
180
181 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
182
183
184
185 68/push "F - test-new-failure: next alloc id"/imm32
186 68/push 0x34/imm32
187 ff 6/subop/push 0/mod/indirect 5/rm32/.disp32 . . . Next-alloc-id/disp32
188
189 e8/call check-ints-equal/disp32
190
191 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
192
193
194 c7 0/subop/copy 0/mod/indirect 5/rm32/.disp32 . . . Next-alloc-id/disp32 1/imm32
195
196 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
197 5d/pop-to-EBP
198 c3/return
199
200 lookup:
201
202 55/push-EBP
203 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
204
205
206 8b/copy 1/mod/*+disp8 5/rm32/EBP . . . 0/r32/EAX 8/disp8 .
207
208
209 ff 6/subop/push 1/mod/*+disp8 1/rm32/ECX . . . . 4/disp8 .
210
211 8b/copy 0/mod/indirect 0/rm32/EAX . . . . . .
212
213 39/compare 0/mod/indirect 4/rm32/sib 4/base/ESP 4/index/none . 0/r32/EAX . .
214 75/jump-if-not-equal $lookup:fail/disp8
215
216 58/pop-to-EAX
217 05/add-to-EAX 4/imm32
218
219
220 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
221 5d/pop-to-EBP
222 c3/return
223 $lookup:fail:
224
225
226 68/push "lookup failed"/imm32
227 68/push 2/imm32/stderr
228
229 e8/call _write/disp32
230
231 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
232
233 bb/copy-to-EBX 1/imm32/exit-status
234 b8/copy-to-EAX 1/imm32/exit
235 cd/syscall 0x80/imm8
236
237 test-lookup-success:
238
239 55/push-EBP
240 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
241
242
243 68/push 0/imm32/address
244 68/push 0/imm32/alloc-id
245 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . .
246
247 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 2/r32/EDX Heap/disp32 .
248
249
250 51/push-ECX
251 68/push 2/imm32/size
252 68/push Heap/imm32
253
254 e8/call new/disp32
255
256 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
257
258
259 51/push-ECX
260
261 e8/call lookup/disp32
262
263 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
264
265
266
267 68/push "F - test-lookup-success"/imm32
268 81 0/subop/add 3/mod/direct 2/rm32/EDX . . . . . 4/imm32
269 52/push-EDX
270 50/push-EAX
271
272 e8/call check-ints-equal/disp32
273
274 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
275
276
277 c7 0/subop/copy 0/mod/indirect 5/rm32/.disp32 . . . Next-alloc-id/disp32 1/imm32
278
279 5a/pop-to-EDX
280 59/pop-to-ECX
281
282 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
283 5d/pop-to-EBP
284 c3/return
285
286 test-lookup-failure:
287
288 55/push-EBP
289 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
290
291 50/push-EAX
292 51/push-ECX
293 52/push-EDX
294
295 68/push 0/imm32/address
296 68/push 0/imm32/alloc-id
297 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . .
298
299 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/EBX Heap/disp32 .
300
301
302
303 51/push-ECX
304 68/push 2/imm32/size
305 68/push Heap/imm32
306
307 e8/call new/disp32
308
309 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
310
311 89/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/EBX Heap/disp32 .
312
313
314 68/push 0/imm32/address
315 68/push 0/imm32/alloc-id
316 89/copy 3/mod/direct 2/rm32/EDX . . . 4/r32/ESP . .
317
318
319 52/push-EDX
320 68/push 2/imm32/size
321 68/push Heap/imm32
322
323 e8/call new/disp32
324
325 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
326
327
328 68/push "F - test-lookup-failure"/imm32
329 ff 6/subop/push 1/mod/*+disp8 2/rm32/ECX . . . . 4/disp8 .
330 ff 6/subop/push 1/mod/*+disp8 1/rm32/ECX . . . . 4/disp8 .
331
332 e8/call check-ints-equal/disp32
333
334 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
335
336
337 51/push-ECX
338
339 e8/call lookup/disp32
340
341
342 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
343
344
345 c7 0/subop/copy 0/mod/indirect 5/rm32/.disp32 . . . Next-alloc-id/disp32 1/imm32
346
347 5a/pop-to-EDX
348 59/pop-to-ECX
349 58/pop-to-EAX
350
351 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
352 5d/pop-to-EBP
353 c3/return
354
355 == data
356
357
358 Next-alloc-id:
359 01 00 00 00
360
361