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