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
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 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 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
236 5d/pop-to-EBP
237 c3/return
238
239 $lookup:abort:
240
241
242 68/push "lookup failed\n"/imm32
243 68/push 2/imm32/stderr
244
245 e8/call _write/disp32
246
247 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
248
249 bb/copy-to-EBX 1/imm32/exit-status
250 b8/copy-to-EAX 1/imm32/exit
251 cd/syscall 0x80/imm8
252
253 test-lookup-success:
254
255 55/push-EBP
256 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
257
258
259 68/push 0/imm32/limit
260 68/push 0/imm32/curr
261 89/copy 3/mod/direct 3/rm32/EBX . . . 4/r32/ESP . .
262
263
264 53/push-EBX
265 68/push 0x200/imm32
266
267 e8/call new-segment/disp32
268
269 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
270
271 68/push 0/imm32/address
272 68/push 0/imm32/alloc-id
273 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . .
274
275 8b/copy 0/mod/indirect 3/rm32/EBX . . . 2/r32/EDX . .
276
277
278 51/push-ECX
279 68/push 2/imm32/size
280 53/push-EBX
281
282 e8/call new/disp32
283
284 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
285
286
287 51/push-ECX
288
289 e8/call lookup/disp32
290
291 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
292
293
294
295 68/push "F - test-lookup-success"/imm32
296 81 0/subop/add 3/mod/direct 2/rm32/EDX . . . . . 4/imm32
297 52/push-EDX
298 50/push-EAX
299
300 e8/call check-ints-equal/disp32
301
302 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
303
304
305 c7 0/subop/copy 0/mod/indirect 5/rm32/.disp32 . . . Next-alloc-id/disp32 1/imm32
306
307
308 68/push "lookup succeeded\n"/imm32
309 68/push 2/imm32/stderr
310
311 e8/call write/disp32
312
313 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
314
315 5a/pop-to-EDX
316 59/pop-to-ECX
317
318 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
319 5d/pop-to-EBP
320 c3/return
321
322 test-lookup-failure:
323
324 55/push-EBP
325 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . .
326
327 68/push 0/imm32/limit
328 68/push 0/imm32/curr
329 89/copy 3/mod/direct 6/rm32/ESI . . . 4/r32/ESP . .
330
331
332 56/push-ESI
333 68/push 0x200/imm32
334
335 e8/call new-segment/disp32
336
337 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32
338
339 68/push 0/imm32/address
340 68/push 0/imm32/alloc-id
341 89/copy 3/mod/direct 1/rm32/ECX . . . 4/r32/ESP . .
342
343 8b/copy 0/mod/indirect 6/rm32/ESI . . . 3/r32/EBX . .
344
345
346
347 51/push-ECX
348 68/push 2/imm32/size
349 56/push-ESI
350
351 e8/call new/disp32
352
353 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
354
355 89/copy 0/mod/indirect 6/rm32/ESI . . . 3/r32/EBX . .
356
357
358 68/push 0/imm32/address
359 68/push 0/imm32/alloc-id
360 89/copy 3/mod/direct 2/rm32/EDX . . . 4/r32/ESP . .
361
362
363 52/push-EDX
364 68/push 2/imm32/size
365 56/push-ESI
366
367 e8/call new/disp32
368
369 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
370
371
372 68/push "F - test-lookup-failure"/imm32
373 ff 6/subop/push 1/mod/*+disp8 2/rm32/ECX . . . . 4/disp8 .
374 ff 6/subop/push 1/mod/*+disp8 1/rm32/ECX . . . . 4/disp8 .
375
376 e8/call check-ints-equal/disp32
377
378 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 0xc/imm32
379
380
381 51/push-ECX
382
383 e8/call lookup/disp32
384
385
386 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 4/imm32
387
388
389 c7 0/subop/copy 0/mod/indirect 5/rm32/.disp32 . . . Next-alloc-id/disp32 1/imm32
390
391 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . .
392 5d/pop-to-EBP
393 c3/return
394
395 == data
396
397
398 Next-alloc-id:
399 1/imm32
400
401