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