https://github.com/akkartik/mu/blob/master/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
24 == code
25
26
27
28
29 Entry:
30
31
32
33 68/push Heap/imm32
34 ff 6/subop/push 0/mod/indirect 5/rm32/.disp32 . . . Heap-size/disp32
35
36 e8/call new-segment/disp32
37
38 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
39
40 e8/call run-tests/disp32
41 $handle-main:end:
42
43 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 3/r32/ebx Num-test-failures/disp32
44 b8/copy-to-eax 1/imm32/exit
45 cd/syscall 0x80/imm8
46
47 new:
48
49 55/push-ebp
50 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
51
52 50/push-eax
53 51/push-ecx
54 52/push-edx
55
56 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 1/r32/ecx 0xc/disp8 .
57 81 0/subop/add 3/mod/direct 1/rm32/ecx . . . . . 4/imm32
58
59
60 51/push-ecx
61 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 .
62
63 e8/call allocate/disp32
64
65 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
66
67 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 2/r32/edx 0x10/disp8 .
68
69 89/copy 1/mod/*+disp8 2/rm32/edx . . . 0/r32/eax 4/disp8 .
70
71 3d/compare-eax-and 0/imm32
72 75/jump-if-not-equal $new:continue/disp8
73 c7 0/subop/copy 0/mod/indirect 2/rm32/edx . . . . . 0/imm32
74 eb/jump $new:end/disp8
75 $new:continue:
76
77
78 8b/copy 0/mod/indirect 5/rm32/.disp32 . . 1/r32/ecx Next-alloc-id/disp32
79
80 89/copy 0/mod/indirect 0/rm32/eax . . . 1/r32/ecx . .
81
82 89/copy 0/mod/indirect 2/rm32/edx . . . 1/r32/ecx . .
83
84 ff 0/subop/increment 0/mod/indirect 5/rm32/.disp32 . . . Next-alloc-id/disp32
85 $new:end:
86
87 5a/pop-to-edx
88 59/pop-to-ecx
89 58/pop-to-eax
90
91 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
92 5d/pop-to-ebp
93 c3/return
94
95 test-new:
96
97 55/push-ebp
98 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
99
100 68/push 0/imm32/limit
101 68/push 0/imm32/curr
102 89/copy 3/mod/direct 2/rm32/edx . . . 4/r32/esp . .
103
104
105 52/push-edx
106 68/push 0x200/imm32
107
108 e8/call new-segment/disp32
109
110 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
111
112 c7 0/subop/copy 0/mod/indirect 5/rm32/.disp32 . . . Next-alloc-id/disp32 0x34/imm32
113
114 68/push 0/imm32/address
115 68/push 0/imm32/alloc-id
116 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . .
117
118
119 51/push-ecx
120 68/push 2/imm32/size
121 52/push-edx
122
123 e8/call new/disp32
124
125 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
126
127
128 68/push "F - test-new: alloc id of handle"/imm32
129 68/push 0x34/imm32
130 ff 6/subop/push 0/mod/indirect 1/rm32/ecx . . . . . .
131
132 e8/call check-ints-equal/disp32
133
134 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
135
136
137 68/push "F - test-new: alloc id of payload"/imm32
138 68/push 0x34/imm32
139 8b/copy 1/mod/*+disp8 1/rm32/ecx . . . 2/r32/edx 4/disp8 .
140 ff 6/subop/push 0/mod/indirect 2/rm32/edx . . . . . .
141
142 e8/call check-ints-equal/disp32
143
144 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
145
146
147 68/push "F - test-new: next alloc id"/imm32
148 68/push 0x35/imm32
149 ff 6/subop/push 0/mod/indirect 5/rm32/.disp32 . . . Next-alloc-id/disp32
150
151 e8/call check-ints-equal/disp32
152
153 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
154
155
156 c7 0/subop/copy 0/mod/indirect 5/rm32/.disp32 . . . Next-alloc-id/disp32 1/imm32
157
158 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
159 5d/pop-to-ebp
160 c3/return
161
162 _pending-test-new-failure:
163
164 55/push-ebp
165 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
166
167 c7 0/subop/copy 0/mod/indirect 5/rm32/.disp32 . . . Next-alloc-id/disp32 0x34/imm32
168
169
170 68/push 0x10/imm32/limit
171 68/push 0x10/imm32/curr
172 89/copy 3/mod/direct 0/rm32/eax . . . 4/r32/esp . .
173
174 68/push 1234/imm32/address
175 68/push 5678/imm32/alloc-id
176 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . .
177
178
179
180 51/push-ecx
181 68/push 2/imm32/size
182 50/push-eax
183
184 e8/call new/disp32
185
186 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
187
188
189
190 68/push "F - test-new-failure: alloc id of handle"/imm32
191 68/push 0/imm32
192 ff 6/subop/push 0/mod/indirect 1/rm32/ecx . . . . . .
193
194 e8/call check-ints-equal/disp32
195
196 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
197
198
199 68/push "F - test-new-failure: address of handle"/imm32
200 68/push 0/imm32
201 ff 6/subop/push 1/mod/*+disp8 1/rm32/ecx . . . . 4/disp8 .
202
203 e8/call check-ints-equal/disp32
204
205 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
206
207
208
209 68/push "F - test-new-failure: next alloc id"/imm32
210 68/push 0x34/imm32
211 ff 6/subop/push 0/mod/indirect 5/rm32/.disp32 . . . Next-alloc-id/disp32
212
213 e8/call check-ints-equal/disp32
214
215 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
216
217
218 c7 0/subop/copy 0/mod/indirect 5/rm32/.disp32 . . . Next-alloc-id/disp32 1/imm32
219
220 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
221 5d/pop-to-ebp
222 c3/return
223
224 lookup:
225
226 55/push-ebp
227 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
228
229
230 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 0/r32/eax 8/disp8 .
231
232
233 ff 6/subop/push 0/mod/indirect 0/rm32/eax . . . . . .
234
235 8b/copy 1/mod/*+disp8 0/rm32/eax . . . . 4/disp8 .
236
237 50/push-eax
238
239 8b/copy 0/mod/indirect 0/rm32/eax . . . . . .
240
241 39/compare 1/mod/*+disp8 4/rm32/sib 4/base/esp 4/index/none . 0/r32/eax 4/disp8 .
242 75/jump-if-not-equal $lookup:abort/disp8
243
244 58/pop-to-eax
245
246 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
247
248 05/add-to-eax 4/imm32
249
250
251
252
253
254
255
256
257
258
259
260
261
262 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
263 5d/pop-to-ebp
264 c3/return
265
266 $lookup:abort:
267
268
269 68/push "lookup failed\n"/imm32
270 68/push 2/imm32/stderr
271
272 e8/call _write/disp32
273
274 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
275
276 bb/copy-to-ebx 1/imm32/exit-status
277 b8/copy-to-eax 1/imm32/exit
278 cd/syscall 0x80/imm8
279
280 test-lookup-success:
281
282 55/push-ebp
283 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
284
285
286 68/push 0/imm32/limit
287 68/push 0/imm32/curr
288 89/copy 3/mod/direct 3/rm32/ebx . . . 4/r32/esp . .
289
290
291 53/push-ebx
292 68/push 0x200/imm32
293
294 e8/call new-segment/disp32
295
296 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
297
298 68/push 0/imm32/address
299 68/push 0/imm32/alloc-id
300 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . .
301
302 8b/copy 0/mod/indirect 3/rm32/ebx . . . 2/r32/edx . .
303
304
305 51/push-ecx
306 68/push 2/imm32/size
307 53/push-ebx
308
309 e8/call new/disp32
310
311 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
312
313
314 51/push-ecx
315
316 e8/call lookup/disp32
317
318 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
319
320
321
322 68/push "F - test-lookup-success"/imm32
323 81 0/subop/add 3/mod/direct 2/rm32/edx . . . . . 4/imm32
324 52/push-edx
325 50/push-eax
326
327 e8/call check-ints-equal/disp32
328
329 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
330
331
332 c7 0/subop/copy 0/mod/indirect 5/rm32/.disp32 . . . Next-alloc-id/disp32 1/imm32
333
334
335 68/push "lookup succeeded\n"/imm32
336 68/push 2/imm32/stderr
337
338 e8/call write/disp32
339
340 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
341
342 5a/pop-to-edx
343 59/pop-to-ecx
344
345 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
346 5d/pop-to-ebp
347 c3/return
348
349 test-lookup-failure:
350
351 55/push-ebp
352 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . .
353
354 68/push 0/imm32/limit
355 68/push 0/imm32/curr
356 89/copy 3/mod/direct 6/rm32/esi . . . 4/r32/esp . .
357
358
359 56/push-esi
360 68/push 0x200/imm32
361
362 e8/call new-segment/disp32
363
364 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32
365
366 68/push 0/imm32/address
367 68/push 0/imm32/alloc-id
368 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . .
369
370 8b/copy 0/mod/indirect 6/rm32/esi . . . 3/r32/ebx . .
371
372
373
374 51/push-ecx
375 68/push 2/imm32/size
376 56/push-esi
377
378 e8/call new/disp32
379
380 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
381
382 89/copy 0/mod/indirect 6/rm32/esi . . . 3/r32/ebx . .
383
384
385 68/push 0/imm32/address
386 68/push 0/imm32/alloc-id
387 89/copy 3/mod/direct 2/rm32/edx . . . 4/r32/esp . .
388
389
390 52/push-edx
391 68/push 2/imm32/size
392 56/push-esi
393
394 e8/call new/disp32
395
396 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
397
398
399 68/push "F - test-lookup-failure"/imm32
400 ff 6/subop/push 1/mod/*+disp8 2/rm32/ecx . . . . 4/disp8 .
401 ff 6/subop/push 1/mod/*+disp8 1/rm32/ecx . . . . 4/disp8 .
402
403 e8/call check-ints-equal/disp32
404
405 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32
406
407
408 51/push-ecx
409
410 e8/call lookup/disp32
411
412
413 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32
414
415
416 c7 0/subop/copy 0/mod/indirect 5/rm32/.disp32 . . . Next-alloc-id/disp32 1/imm32
417
418 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . .
419 5d/pop-to-ebp
420 c3/return
421
422 == data
423
424
425 Next-alloc-id:
426 1/imm32
427
428