From 96a6bac52d6f4a67932e54d25166bf7961718e9d Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Mon, 7 Jan 2019 13:36:15 -0800 Subject: 4914 --- html/subx/066allocate.subx.html | 57 ++++++++++++++++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) (limited to 'html/subx/066allocate.subx.html') diff --git a/html/subx/066allocate.subx.html b/html/subx/066allocate.subx.html index 9cae149f..74be6f73 100644 --- a/html/subx/066allocate.subx.html +++ b/html/subx/066allocate.subx.html @@ -209,7 +209,62 @@ if ('onhashchange' in window) { 149 5d/pop-to-EBP 150 c3/return 151 -152 # . . vim:nowrap:textwidth=0 +152 # helper: create a nested allocation descriptor (useful for tests) +153 allocate-region: # ad : (address allocation-descriptor), n : int -> new-ad : (address allocation-descriptor) +154 # . prolog +155 55/push-EBP +156 89/copy 3/mod/direct 5/rm32/EBP . . . 4/r32/ESP . . # copy ESP to EBP +157 # . save registers +158 51/push-ECX +159 # EAX = allocate(ad, n) +160 # . . push args +161 ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 0xc/disp8 . # push *(EBP+12) +162 ff 6/subop/push 1/mod/*+disp8 5/rm32/EBP . . . . 8/disp8 . # push *(EBP+8) +163 # . . call +164 e8/call allocate/disp32 +165 # . . discard args +166 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP +167 # if EAX == 0 abort +168 81 7/subop/compare 3/mod/direct 0/rm32/EAX . . . . . 0/imm32 # compare EAX +169 74/jump-if-equal $allocate-region:abort/disp8 +170 # earmark 8 bytes at the start for a new allocation descriptor +171 # . *EAX = EAX + 8 +172 89/copy 3/mod/direct 1/rm32/ECX . . . 0/r32/EAX . . # copy EAX to ECX +173 81 0/subop/add 3/mod/direct 1/rm32/ECX . . . . . 8/imm32 # add to ECX +174 89/copy 0/mod/indirect 0/rm32/EAX . . . 1/r32/ECX . . # copy ECX to *EAX +175 # . *(EAX+4) = EAX + n +176 89/copy 3/mod/direct 1/rm32/ECX . . . 0/r32/EAX . . # copy EAX to ECX +177 03/add 1/mod/*+disp8 5/rm32/EBP . . . 1/r32/ECX 0xc/disp8 . # add *(EBP+12) to ECX +178 89/copy 1/mod/*+disp8 0/rm32/EAX . . . 1/r32/ECX 4/disp8 . # copy ECX to *(EAX+4) +179 # . restore registers +180 59/pop-to-ECX +181 # . epilog +182 89/copy 3/mod/direct 4/rm32/ESP . . . 5/r32/EBP . . # copy EBP to ESP +183 5d/pop-to-EBP +184 c3/return +185 +186 # We could create a more general '$abort' jump target, but then we'd need to do +187 # a conditional jump followed by loading the error message and an unconditional +188 # jump. Or we'd need to unconditionally load the error message before a +189 # conditional jump, even if it's unused the vast majority of the time. This way +190 # we bloat a potentially cold segment in RAM so we can abort with a single +191 # instruction. +192 $allocate-region:abort: +193 # . _write(2/stderr, error) +194 # . . push args +195 68/push "allocate-region: failed to allocate"/imm32 +196 68/push 2/imm32/stderr +197 # . . call +198 e8/call _write/disp32 +199 # . . discard args +200 81 0/subop/add 3/mod/direct 4/rm32/ESP . . . . . 8/imm32 # add to ESP +201 # . syscall(exit, 1) +202 bb/copy-to-EBX 1/imm32 +203 b8/copy-to-EAX 1/imm32/exit +204 cd/syscall 0x80/imm8 +205 # never gets here +206 +207 # . . vim:nowrap:textwidth=0 -- cgit 1.4.1-2-gfad0