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