From 9a77780158842db6e4aa098f5027e030fc3bd878 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Fri, 22 May 2020 23:08:09 -0700 Subject: 6384 --- html/070new-stream.subx.html | 237 +++++++++++++++++++++++-------------------- 1 file changed, 128 insertions(+), 109 deletions(-) (limited to 'html/070new-stream.subx.html') diff --git a/html/070new-stream.subx.html b/html/070new-stream.subx.html index 1275b225..2eb35066 100644 --- a/html/070new-stream.subx.html +++ b/html/070new-stream.subx.html @@ -16,12 +16,12 @@ a { color:inherit; } * { font-size:12pt; font-size: 1em; } .subxComment { color: #005faf; } .subxS2Comment { color: #8a8a8a; } +.subxTest { color: #5f8700; } +.subxFunction { color: #af5f00; text-decoration: underline; } .LineNr { } .subxS1Comment { color: #0000af; } -.subxFunction { color: #af5f00; text-decoration: underline; } .Normal { color: #000000; background-color: #c6c6c6; padding-bottom: 1px; } .Constant { color: #008787; } -.subxTest { color: #5f8700; } --> @@ -64,117 +64,136 @@ if ('onhashchange' in window) { 5 # . op subop mod rm32 base index scale r32 6 # . 1-3 bytes 3 bits 2 bits 3 bits 3 bits 3 bits 2 bits 2 bits 0/1/2/4 bytes 0/1/2/4 bytes 7 - 8 new-stream: # ad: (addr allocation-descriptor), length: int, elemsize: int -> address/eax: (handle stream _) + 8 new-stream: # ad: (addr allocation-descriptor), length: int, elemsize: int, out: (addr handle stream _) 9 # . prologue 10 55/push-ebp 11 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp 12 # . save registers - 13 52/push-edx - 14 # var n/eax: int = elemsize * length + 12 (for read, write and length) - 15 # . eax = elemsize - 16 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 0/r32/eax 0x10/disp8 . # copy *(ebp+16) to eax - 17 # . eax *= length - 18 31/xor 3/mod/direct 2/rm32/edx . . . 2/r32/edx . . # clear edx - 19 f7 4/subop/multiply 1/mod/*+disp8 5/rm32/ebp . . 0xc/disp8 . # multiply *(ebp+12) into eax - 20 # . if overflow abort - 21 81 7/subop/compare 3/mod/direct 2/rm32/edx . . . . . 0/imm32 # compare edx - 22 75/jump-if-!= $new-stream:abort/disp8 - 23 # . edx = elemsize*length - 24 89/copy 3/mod/direct 2/rm32/edx . . . 0/r32/eax . . # copy eax to edx - 25 # . eax += 12 - 26 05/add-to-eax 0xc/imm32 - 27 # var eax: (handle stream _) = allocate(ad, n) - 28 # . . push args - 29 50/push-eax - 30 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 . # push *(ebp+8) - 31 # . . call - 32 e8/call allocate/disp32 - 33 # . . discard args - 34 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp - 35 # eax->length = elemsize*length - 36 89/copy 1/mod/*+disp8 0/rm32/eax . . . 2/r32/edx 8/disp8 . # copy edx to *(eax+8) - 37 # clear-stream(eax) - 38 # . . push args - 39 50/push-eax - 40 # . . call - 41 e8/call clear-stream/disp32 - 42 # . . discard args - 43 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp - 44 $new-stream:end: - 45 # . restore registers - 46 5a/pop-to-edx - 47 # . epilogue - 48 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp - 49 5d/pop-to-ebp - 50 c3/return - 51 - 52 $new-stream:abort: - 53 # . _write(2/stderr, error) - 54 # . . push args - 55 68/push "new-stream: size too large\n"/imm32 - 56 68/push 2/imm32/stderr - 57 # . . call - 58 e8/call _write/disp32 - 59 # . . discard args - 60 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp - 61 # . syscall(exit, 1) - 62 bb/copy-to-ebx 1/imm32 - 63 b8/copy-to-eax 1/imm32/exit - 64 cd/syscall 0x80/imm8 - 65 # never gets here - 66 - 67 test-new-stream: - 68 # . prologue - 69 55/push-ebp - 70 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp - 71 # var heap/ecx: allocation-descriptor - 72 68/push 0/imm32/limit - 73 68/push 0/imm32/curr - 74 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . . # copy esp to ecx - 75 # heap = new-segment(512) - 76 # . . push args - 77 51/push-ecx - 78 68/push 0x200/imm32 - 79 # . . call - 80 e8/call new-segment/disp32 - 81 # . . discard args - 82 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp - 83 # var start/edx = ad->curr - 84 8b/copy 0/mod/indirect 1/rm32/ecx . . . 2/r32/edx . . # copy *ecx to edx - 85 # var eax: (handle stream byte) = new-stream(heap, 3, 2) - 86 # . . push args - 87 68/push 2/imm32 - 88 68/push 3/imm32 - 89 51/push-ecx - 90 # . . call - 91 e8/call new-stream/disp32 - 92 # . . discard args - 93 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp - 94 # check-ints-equal(eax, edx, msg) - 95 # . . push args - 96 68/push "F - test-new-stream: returns current pointer of allocation descriptor"/imm32 - 97 52/push-edx - 98 50/push-eax - 99 # . . call -100 e8/call check-ints-equal/disp32 -101 # . . discard args -102 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp -103 # check-ints-equal(eax->length, 6, msg) -104 # . . push args -105 68/push "F - test-new-stream: sets length correctly"/imm32 -106 68/push 6/imm32 -107 ff 6/subop/push 1/mod/*+disp8 0/rm32/eax . . . . . 8/disp8 # push *(eax+8) -108 # . . call -109 e8/call check-ints-equal/disp32 -110 # . . discard args -111 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp -112 # the rest is delegated to clear-stream() so we won't bother checking it -113 # . epilogue -114 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp -115 5d/pop-to-ebp -116 c3/return -117 -118 # . . vim:nowrap:textwidth=0 + 13 50/push-eax + 14 52/push-edx + 15 # var size/edx: int = elemsize*length (clobbering eax) + 16 # . eax = elemsize + 17 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 0/r32/eax 0x10/disp8 . # copy *(ebp+16) to eax + 18 # . eax *= length + 19 31/xor 3/mod/direct 2/rm32/edx . . . 2/r32/edx . . # clear edx + 20 f7 4/subop/multiply 1/mod/*+disp8 5/rm32/ebp . . 0xc/disp8 . # multiply *(ebp+12) into eax + 21 # . if overflow abort + 22 81 7/subop/compare 3/mod/direct 2/rm32/edx . . . . . 0/imm32 # compare edx + 23 75/jump-if-!= $new-stream:abort/disp8 + 24 # . edx = elemsize*length + 25 89/copy 3/mod/direct 2/rm32/edx . . . 0/r32/eax . . # copy eax to edx + 26 # var n/eax: int = size + 12 (for read, write and size) + 27 05/add-to-eax 0xc/imm32 + 28 # allocate(ad, n, out) + 29 # . . push args + 30 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 0x14/disp8 . # push *(ebp+20) + 31 50/push-eax + 32 ff 6/subop/push 1/mod/*+disp8 5/rm32/ebp . . . . 8/disp8 . # push *(ebp+8) + 33 # . . call + 34 e8/call allocate/disp32 + 35 # . . discard args + 36 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp + 37 # eax = out->payload + 38 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 0/r32/eax 0x14/disp8 . # copy *(ebp+20) to eax + 39 8b/copy 1/mod/*+disp8 0/rm32/eax . . . 0/r32/eax 4/disp8 . # copy *(eax+4) to eax + 40 # skip payload->allocid + 41 05/add-to-eax 4/imm32 + 42 # eax->size = size + 43 89/copy 1/mod/*+disp8 0/rm32/eax . . . 2/r32/edx 8/disp8 . # copy edx to *(eax+8) + 44 # clear-stream(eax) + 45 # . . push args + 46 50/push-eax + 47 # . . call + 48 e8/call clear-stream/disp32 + 49 # . . discard args + 50 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp + 51 $new-stream:end: + 52 # . restore registers + 53 5a/pop-to-edx + 54 58/pop-to-eax + 55 # . epilogue + 56 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp + 57 5d/pop-to-ebp + 58 c3/return + 59 + 60 $new-stream:abort: + 61 # . _write(2/stderr, error) + 62 # . . push args + 63 68/push "new-stream: size too large\n"/imm32 + 64 68/push 2/imm32/stderr + 65 # . . call + 66 e8/call _write/disp32 + 67 # . . discard args + 68 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp + 69 # . syscall(exit, 1) + 70 bb/copy-to-ebx 1/imm32 + 71 b8/copy-to-eax 1/imm32/exit + 72 cd/syscall 0x80/imm8 + 73 # never gets here + 74 + 75 test-new-stream: + 76 # . prologue + 77 55/push-ebp + 78 89/copy 3/mod/direct 5/rm32/ebp . . . 4/r32/esp . . # copy esp to ebp + 79 # var heap/ecx: allocation-descriptor + 80 68/push 0/imm32/limit + 81 68/push 0/imm32/curr + 82 89/copy 3/mod/direct 1/rm32/ecx . . . 4/r32/esp . . # copy esp to ecx + 83 # heap = new-segment(512) + 84 # . . push args + 85 51/push-ecx + 86 68/push 0x200/imm32 + 87 # . . call + 88 e8/call new-segment/disp32 + 89 # . . discard args + 90 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 8/imm32 # add to esp + 91 # var start/edx = ad->curr + 92 8b/copy 0/mod/indirect 1/rm32/ecx . . . 2/r32/edx . . # copy *ecx to edx + 93 # var h/ebx: (handle stream byte) + 94 68/push 0/imm32 + 95 68/push 0/imm32 + 96 89/copy 3/mod/direct 3/rm32/ebx . . . 4/r32/esp . . # copy esp to ebx + 97 # new-stream(heap, 3, 2, h) + 98 # . . push args + 99 53/push-ebx +100 68/push 2/imm32 +101 68/push 3/imm32 +102 51/push-ecx +103 # . . call +104 e8/call new-stream/disp32 +105 # . . discard args +106 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32 # add to esp +107 # eax = out->payload +108 8b/copy 1/mod/*+disp8 3/rm32/ebx . . . 0/r32/eax 4/disp8 . # copy *(ebx+4) to eax +109 # check-ints-equal(eax, edx, msg) +110 # . . push args +111 68/push "F - test-new-stream: returns current pointer of allocation descriptor"/imm32 +112 52/push-edx +113 50/push-eax +114 # . . call +115 e8/call check-ints-equal/disp32 +116 # . . discard args +117 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp +118 # skip payload->allocid +119 05/add-to-eax 4/imm32 +120 # check-ints-equal(eax->size, 6, msg) +121 # . . push args +122 68/push "F - test-new-stream: sets size correctly"/imm32 +123 68/push 6/imm32 +124 ff 6/subop/push 1/mod/*+disp8 0/rm32/eax . . . . . 8/disp8 # push *(eax+8) +125 # . . call +126 e8/call check-ints-equal/disp32 +127 # . . discard args +128 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0xc/imm32 # add to esp +129 # the rest is delegated to clear-stream() so we won't bother checking it +130 # . reclaim locals +131 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 0x10/imm32 # add to esp +132 # . epilogue +133 89/copy 3/mod/direct 4/rm32/esp . . . 5/r32/ebp . . # copy ebp to esp +134 5d/pop-to-ebp +135 c3/return +136 +137 # . . vim:nowrap:textwidth=0 -- cgit 1.4.1-2-gfad0