From 781b7a0854ed3e37b7b1bb89bdfbed286102ac8c Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Mon, 11 Jan 2021 23:26:06 -0800 Subject: 7498 --- html/baremetal/108write.subx.html | 189 ++++++++++++++++++++++++---------- html/baremetal/112read-byte.subx.html | 72 +++++++------ html/baremetal/309stream.subx.html | 4 +- html/baremetal/400.mu.html | 2 +- html/baremetal/403unicode.mu.html | 4 +- html/baremetal/boot.hex.html | 4 +- 6 files changed, 181 insertions(+), 94 deletions(-) (limited to 'html/baremetal') diff --git a/html/baremetal/108write.subx.html b/html/baremetal/108write.subx.html index 68c65e6d..085efeff 100644 --- a/html/baremetal/108write.subx.html +++ b/html/baremetal/108write.subx.html @@ -21,6 +21,7 @@ a { color:inherit; } .subxFunction { color: #af5f00; text-decoration: underline; } .Normal { color: #000000; background-color: #c6c6c6; padding-bottom: 1px; } .Constant { color: #008787; } +.subxMinorFunction { color: #875f5f; } --> @@ -56,59 +57,141 @@ if ('onhashchange' in window) { https://github.com/akkartik/mu/blob/main/baremetal/108write.subx
- 1 #   instruction                     effective address                                                   register    displacement    immediate
- 2 # . op          subop               mod             rm32          base        index         scale       r32
- 3 # . 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
- 4 
- 5 write:  # f: (addr stream byte), s: (addr array byte)
- 6     # . prologue
- 7     55/push-ebp
- 8     89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
- 9     # if (s == 0) return
-10     81          7/subop/compare     1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0xc/disp8       0/imm32           # compare *(ebp+12)
-11     74/jump-if-=  $write:end/disp8
-12     # TODO: write to file
-13     # otherwise, treat 'f' as a stream to append to
-14     # . save registers
-15     50/push-eax
-16     51/push-ecx
-17     52/push-edx
-18     53/push-ebx
-19     # ecx = f
-20     8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .                         1/r32/ecx   8/disp8         .                 # copy *(ebp+8) to ecx
-21     # edx = f->write
-22     8b/copy                         0/mod/indirect  1/rm32/ecx    .           .             .           2/r32/edx   .               .                 # copy *ecx to edx
-23     # ebx = f->size
-24     8b/copy                         1/mod/*+disp8   1/rm32/ecx    .           .             .           3/r32/ebx   8/disp8         .                 # copy *(ecx+8) to ebx
-25     # eax = _append-3(&f->data[f->write], &f->data[f->size], s)
-26     # . . push s
-27     ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0xc/disp8       .                 # push *(ebp+12)
-28     # . . push &f->data[f->size]
-29     8d/copy-address                 1/mod/*+disp8   4/rm32/sib    1/base/ecx  3/index/ebx   .           3/r32/ebx   0xc/disp8       .                 # copy ecx+ebx+12 to ebx
-30     53/push-ebx
-31     # . . push &f->data[f->write]
-32     8d/copy-address                 1/mod/*+disp8   4/rm32/sib    1/base/ecx  2/index/edx   .           3/r32/ebx   0xc/disp8       .                 # copy ecx+edx+12 to ebx
-33     53/push-ebx
-34     # . . call
-35     e8/call  _append-3/disp32
-36     # . . discard args
-37     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
-38     # f->write += eax
-39     01/add                          0/mod/indirect  1/rm32/ecx    .           .             .           0/r32/eax   .               .                 # add eax to *ecx
-40     # . restore registers
-41     5b/pop-to-ebx
-42     5a/pop-to-edx
-43     59/pop-to-ecx
-44     58/pop-to-eax
-45 $write:end:
-46     # . epilogue
-47     89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
-48     5d/pop-to-ebp
-49     c3/return
-50 
-51 # TODO: bring in tests once we have check-ints-equal
-52 
-53 # . . vim:nowrap:textwidth=0
+  1 #   instruction                     effective address                                                   register    displacement    immediate
+  2 # . op          subop               mod             rm32          base        index         scale       r32
+  3 # . 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
+  4 
+  5 write:  # f: (addr stream byte), s: (addr array byte)
+  6     # . prologue
+  7     55/push-ebp
+  8     89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
+  9     # if (s == 0) return
+ 10     81          7/subop/compare     1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0xc/disp8       0/imm32           # compare *(ebp+12)
+ 11     74/jump-if-=  $write:end/disp8
+ 12     # TODO: write to file
+ 13     # otherwise, treat 'f' as a stream to append to
+ 14     # . save registers
+ 15     50/push-eax
+ 16     51/push-ecx
+ 17     52/push-edx
+ 18     53/push-ebx
+ 19     # ecx = f
+ 20     8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .                         1/r32/ecx   8/disp8         .                 # copy *(ebp+8) to ecx
+ 21     # edx = f->write
+ 22     8b/copy                         0/mod/indirect  1/rm32/ecx    .           .             .           2/r32/edx   .               .                 # copy *ecx to edx
+ 23     # ebx = f->size
+ 24     8b/copy                         1/mod/*+disp8   1/rm32/ecx    .           .             .           3/r32/ebx   8/disp8         .                 # copy *(ecx+8) to ebx
+ 25     # eax = _append-3(&f->data[f->write], &f->data[f->size], s)
+ 26     # . . push s
+ 27     ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0xc/disp8       .                 # push *(ebp+12)
+ 28     # . . push &f->data[f->size]
+ 29     8d/copy-address                 1/mod/*+disp8   4/rm32/sib    1/base/ecx  3/index/ebx   .           3/r32/ebx   0xc/disp8       .                 # copy ecx+ebx+12 to ebx
+ 30     53/push-ebx
+ 31     # . . push &f->data[f->write]
+ 32     8d/copy-address                 1/mod/*+disp8   4/rm32/sib    1/base/ecx  2/index/edx   .           3/r32/ebx   0xc/disp8       .                 # copy ecx+edx+12 to ebx
+ 33     53/push-ebx
+ 34     # . . call
+ 35     e8/call  _append-3/disp32
+ 36     # . . discard args
+ 37     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0xc/imm32         # add to esp
+ 38     # f->write += eax
+ 39     01/add                          0/mod/indirect  1/rm32/ecx    .           .             .           0/r32/eax   .               .                 # add eax to *ecx
+ 40     # . restore registers
+ 41     5b/pop-to-ebx
+ 42     5a/pop-to-edx
+ 43     59/pop-to-ecx
+ 44     58/pop-to-eax
+ 45 $write:end:
+ 46     # . epilogue
+ 47     89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
+ 48     5d/pop-to-ebp
+ 49     c3/return
+ 50 
+ 51 # TODO: bring in tests once we have check-ints-equal
+ 52 
+ 53 # 3-argument variant of _append
+ 54 _append-3:  # out: (addr byte), outend: (addr byte), s: (addr array byte) -> num_bytes_appended/eax
+ 55     # . prologue
+ 56     55/push-ebp
+ 57     89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
+ 58     # . save registers
+ 59     51/push-ecx
+ 60     # eax = _append-4(out, outend, &s->data[0], &s->data[s->size])
+ 61     # . . push &s->data[s->size]
+ 62     8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .                         0/r32/eax   0x10/disp8      .                 # copy *(ebp+16) to eax
+ 63     8b/copy                         0/mod/indirect  0/rm32/eax    .           .             .           1/r32/ecx   .               .                 # copy *eax to ecx
+ 64     8d/copy-address                 1/mod/*+disp8   4/rm32/sib    0/base/eax  1/index/ecx   .           1/r32/ecx   4/disp8         .                 # copy eax+ecx+4 to ecx
+ 65     51/push-ecx
+ 66     # . . push &s->data[0]
+ 67     8d/copy-address                 1/mod/*+disp8   0/rm32/eax    .           .             .           1/r32/ecx   4/disp8         .                 # copy eax+4 to ecx
+ 68     51/push-ecx
+ 69     # . . push outend
+ 70     ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0xc/disp8       .                 # push *(ebp+12)
+ 71     # . . push out
+ 72     ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           8/disp8         .                 # push *(ebp+8)
+ 73     # . . call
+ 74     e8/call  _append-4/disp32
+ 75     # . . discard args
+ 76     81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               0x10/imm32        # add to esp
+ 77 $_append-3:end:
+ 78     # . restore registers
+ 79     59/pop-to-ecx
+ 80     # . epilogue
+ 81     89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
+ 82     5d/pop-to-ebp
+ 83     c3/return
+ 84 
+ 85 # 4-argument variant of _append
+ 86 _append-4:  # out: (addr byte), outend: (addr byte), in: (addr byte), inend: (addr byte) -> num_bytes_appended/eax: int
+ 87     # . prologue
+ 88     55/push-ebp
+ 89     89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
+ 90     # . save registers
+ 91     51/push-ecx
+ 92     52/push-edx
+ 93     53/push-ebx
+ 94     56/push-esi
+ 95     57/push-edi
+ 96     # num_bytes_appended = 0
+ 97     b8/copy-to-eax  0/imm32
+ 98     # edi = out
+ 99     8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           7/r32/edi   8/disp8         .                 # copy *(ebp+8) to edi
+100     # edx = outend
+101     8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           2/r32/edx   0xc/disp8       .                 # copy *(ebp+12) to edx
+102     # esi = in
+103     8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           6/r32/esi   0x10/disp8      .                 # copy *(ebp+16) to esi
+104     # ecx = inend
+105     8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           1/r32/ecx   0x14/disp8      .                 # copy *(ebp+20) to ecx
+106 $_append-4:loop:
+107     # if (in >= inend) break
+108     39/compare                      3/mod/direct    6/rm32/esi    .           .             .           1/r32/ecx   .               .                 # compare esi with ecx
+109     73/jump-if-addr>=  $_append-4:end/disp8
+110     # if (out >= outend) abort  # just to catch test failures fast
+111     39/compare                      3/mod/direct    7/rm32/edi    .           .             .           2/r32/edx   .               .                 # compare edi with edx
+112     73/jump-if-addr>=  $_append-4:end/disp8  # TODO: abort
+113     # *out = *in
+114     8a/copy-byte                    0/mod/indirect  6/rm32/esi    .           .             .           3/r32/BL    .               .                 # copy byte at *esi to BL
+115     88/copy-byte                    0/mod/indirect  7/rm32/edi    .           .             .           3/r32/BL    .               .                 # copy byte at BL to *edi
+116     # ++num_bytes_appended
+117     40/increment-eax
+118     # ++in
+119     46/increment-esi
+120     # ++out
+121     47/increment-edi
+122     eb/jump  $_append-4:loop/disp8
+123 $_append-4:end:
+124     # . restore registers
+125     5f/pop-to-edi
+126     5e/pop-to-esi
+127     5b/pop-to-ebx
+128     5a/pop-to-edx
+129     59/pop-to-ecx
+130     # . epilogue
+131     89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
+132     5d/pop-to-ebp
+133     c3/return
+134 
+135 # . . vim:nowrap:textwidth=0
 
diff --git a/html/baremetal/112read-byte.subx.html b/html/baremetal/112read-byte.subx.html index 7673eab8..9fb89fd0 100644 --- a/html/baremetal/112read-byte.subx.html +++ b/html/baremetal/112read-byte.subx.html @@ -15,9 +15,9 @@ body { font-size:12pt; font-family: monospace; color: #000000; background-color: a { color:inherit; } * { font-size:12pt; font-size: 1em; } .subxComment { color: #005faf; } +.subxS1Comment { color: #0000af; } .subxS2Comment { color: #8a8a8a; } .LineNr { } -.subxS1Comment { color: #0000af; } .subxFunction { color: #af5f00; text-decoration: underline; } .Normal { color: #000000; background-color: #c6c6c6; padding-bottom: 1px; } .Constant { color: #008787; } @@ -56,39 +56,43 @@ if ('onhashchange' in window) { https://github.com/akkartik/mu/blob/main/baremetal/112read-byte.subx
- 1 # TODO: read-byte-buffered
- 2 
- 3 # Return next byte value in eax, with top 3 bytes cleared.
- 4 # Abort on reaching end of stream.
- 5 read-byte:  # s: (addr stream byte) -> result/eax: byte
- 6     # . prologue
- 7     55/push-ebp
- 8     89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
- 9     # . save registers
-10     51/push-ecx
-11     56/push-esi
-12     # esi = s
-13     8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           6/r32/esi   8/disp8         .                 # copy *(ebp+8) to esi
-14     # ecx = s->read
-15     8b/copy                         1/mod/*+disp8   6/rm32/esi    .           .             .           1/r32/ecx   4/disp8         .                 # copy *(esi+4) to ecx
-16     # if (f->read >= f->write) abort
-17     3b/compare                      0/mod/indirect  6/rm32/esi    .           .             .           1/r32/ecx   .               .                 # compare ecx with *esi
-18     0f 8d/jump-if->=  $read-byte:end/disp32  # TODO: abort
-19     # result = f->data[f->read]
-20     31/xor                          3/mod/direct    0/rm32/eax    .           .             .           0/r32/eax   .               .                 # clear eax
-21     8a/copy-byte                    1/mod/*+disp8   4/rm32/sib    6/base/esi  1/index/ecx   .           0/r32/AL    0xc/disp8       .                 # copy byte at *(esi+ecx+12) to AL
-22     # ++f->read
-23     ff          0/subop/increment   1/mod/*+disp8   6/rm32/esi    .           .             .           .           4/disp8         .                 # increment *(esi+4)
-24 $read-byte:end:
-25     # . restore registers
-26     5e/pop-to-esi
-27     59/pop-to-ecx
-28     # . epilogue
-29     89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
-30     5d/pop-to-ebp
-31     c3/return
-32 
-33 # . . vim:nowrap:textwidth=0
+ 1 #   instruction                     effective address                                                   register    displacement    immediate
+ 2 # . op          subop               mod             rm32          base        index         scale       r32
+ 3 # . 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
+ 4 
+ 5 # TODO: read-byte-buffered
+ 6 
+ 7 # Return next byte value in eax, with top 3 bytes cleared.
+ 8 # Abort on reaching end of stream.
+ 9 read-byte:  # s: (addr stream byte) -> result/eax: byte
+10     # . prologue
+11     55/push-ebp
+12     89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
+13     # . save registers
+14     51/push-ecx
+15     56/push-esi
+16     # esi = s
+17     8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           6/r32/esi   8/disp8         .                 # copy *(ebp+8) to esi
+18     # ecx = s->read
+19     8b/copy                         1/mod/*+disp8   6/rm32/esi    .           .             .           1/r32/ecx   4/disp8         .                 # copy *(esi+4) to ecx
+20     # if (f->read >= f->write) abort
+21     3b/compare                      0/mod/indirect  6/rm32/esi    .           .             .           1/r32/ecx   .               .                 # compare ecx with *esi
+22     0f 8d/jump-if->=  $read-byte:end/disp32  # TODO: abort
+23     # result = f->data[f->read]
+24     31/xor                          3/mod/direct    0/rm32/eax    .           .             .           0/r32/eax   .               .                 # clear eax
+25     8a/copy-byte                    1/mod/*+disp8   4/rm32/sib    6/base/esi  1/index/ecx   .           0/r32/AL    0xc/disp8       .                 # copy byte at *(esi+ecx+12) to AL
+26     # ++f->read
+27     ff          0/subop/increment   1/mod/*+disp8   6/rm32/esi    .           .             .           .           4/disp8         .                 # increment *(esi+4)
+28 $read-byte:end:
+29     # . restore registers
+30     5e/pop-to-esi
+31     59/pop-to-ecx
+32     # . epilogue
+33     89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
+34     5d/pop-to-ebp
+35     c3/return
+36 
+37 # . . vim:nowrap:textwidth=0
 
diff --git a/html/baremetal/309stream.subx.html b/html/baremetal/309stream.subx.html index db4e04e1..bbfd368b 100644 --- a/html/baremetal/309stream.subx.html +++ b/html/baremetal/309stream.subx.html @@ -137,7 +137,7 @@ if ('onhashchange' in window) { 81 8b/-> *(ebp+0x10) 1/r32/ecx 82 8d/copy-address *(eax+ecx) 1/r32/ecx 83 # - 84 (_append-4 %edx %ebx %eax %ecx) # => eax + 84 (_append-4 %edx %ebx %eax %ecx) # => eax 85 # s->write += n 86 8b/-> *(ebp+0x10) 1/r32/ecx 87 01/add-to *edi 1/r32/ecx @@ -183,7 +183,7 @@ if ('onhashchange' in window) { 127 8b/-> *(ebp+0x10) 1/r32/ecx 128 8d/copy-address *(eax+ecx) 1/r32/ecx 129 # -130 (_append-4 %eax %ecx %edx %ebx) # => eax +130 (_append-4 %eax %ecx %edx %ebx) # => eax 131 # s->read += n 132 8b/-> *(ebp+0x10) 1/r32/ecx 133 01/add-to *(esi+4) 1/r32/ecx diff --git a/html/baremetal/400.mu.html b/html/baremetal/400.mu.html index 713534af..715c8d09 100644 --- a/html/baremetal/400.mu.html +++ b/html/baremetal/400.mu.html @@ -58,7 +58,7 @@ if ('onhashchange' in window) { 4 5 sig write f: (addr stream byte), s: (addr array byte) 6 sig append-byte f: (addr stream byte), n: int -7 sig read-byte s: (addr stream byte) -> _/eax: byte +7 sig read-byte s: (addr stream byte) -> _/eax: byte 8 sig stream-empty? s: (addr stream _) -> _/eax: boolean diff --git a/html/baremetal/403unicode.mu.html b/html/baremetal/403unicode.mu.html index 35622877..8151f6d4 100644 --- a/html/baremetal/403unicode.mu.html +++ b/html/baremetal/403unicode.mu.html @@ -155,7 +155,7 @@ if ('onhashchange' in window) { 97 break-if-= 98 return 0xffffffff 99 } -100 var c/eax: byte <- read-byte in +100 var c/eax: byte <- read-byte in 101 var num-trailers/ecx: int <- copy 0 102 $read-grapheme:compute-length: { 103 # single byte: just return it @@ -201,7 +201,7 @@ if ('onhashchange' in window) { 143 { 144 compare num-trailers, 0 145 break-if-<= -146 var tmp/eax: byte <- read-byte in +146 var tmp/eax: byte <- read-byte in 147 var tmp2/eax: int <- copy tmp 148 tmp2 <- shift-left-bytes tmp2, num-byte-shifts 149 result <- or tmp2 diff --git a/html/baremetal/boot.hex.html b/html/baremetal/boot.hex.html index 4b696da1..5a3f3f43 100644 --- a/html/baremetal/boot.hex.html +++ b/html/baremetal/boot.hex.html @@ -486,10 +486,10 @@ if ('onhashchange' in window) { 431 ## the rest of this file has data 432 433 # offset 400 (address 0x8000): -434 +--158 lines: # translating keys to ASCII ----------------------------------------------------------------------------------------------------------------------------------------------- +434 +--158 lines: # translating keys to ASCII -------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 592 593 # offset c00 (address 0x8800) -594 +--236 lines: # Bitmaps for some ASCII characters (soon Unicode) ------------------------------------------------------------------------------------------------------------------------ +594 +--236 lines: # Bitmaps for some ASCII characters (soon Unicode) --------------------------------------------------------------------------------------------------------------------------------------------------- 830 831 # offset 1400 (address 0x9000) 832 -- cgit 1.4.1-2-gfad0