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