about summary refs log tree commit diff stats
path: root/113write-stream.subx
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-03-03 22:09:50 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-03-03 22:21:03 -0800
commit71e4f3812982dba2efb471283d310224e8db363e (patch)
treeea111a1acb8b8845dbda39c0e1b4bac1d198143b /113write-stream.subx
parentc6b928be29ac8cdb4e4d6e1eaa20420ff03e5a4c (diff)
downloadmu-71e4f3812982dba2efb471283d310224e8db363e.tar.gz
7842 - new directory organization
Baremetal is now the default build target and therefore has its sources
at the top-level. Baremetal programs build using the phase-2 Mu toolchain
that requires a Linux kernel. This phase-2 codebase which used to be at
the top-level is now under the linux/ directory. Finally, the phase-2 toolchain,
while self-hosting, has a way to bootstrap from a C implementation, which
is now stored in linux/bootstrap. The bootstrap C implementation uses some
literate programming tools that are now in linux/bootstrap/tools.

So the whole thing has gotten inverted. Each directory should build one
artifact and include the main sources (along with standard library). Tools
used for building it are relegated to sub-directories, even though those
tools are often useful in their own right, and have had lots of interesting
programs written using them.

A couple of things have gotten dropped in this process:
  - I had old ways to run on just a Linux kernel, or with a Soso kernel.
    No more.
  - I had some old tooling for running a single test at the cursor. I haven't
    used that lately. Maybe I'll bring it back one day.

The reorg isn't done yet. Still to do:
  - redo documentation everywhere. All the README files, all other markdown,
    particularly vocabulary.md.
  - clean up how-to-run comments at the start of programs everywhere
  - rethink what to do with the html/ directory. Do we even want to keep
    supporting it?

In spite of these shortcomings, all the scripts at the top-level, linux/
and linux/bootstrap are working. The names of the scripts also feel reasonable.
This is a good milestone to take stock at.
Diffstat (limited to '113write-stream.subx')
-rw-r--r--113write-stream.subx81
1 files changed, 1 insertions, 80 deletions
diff --git a/113write-stream.subx b/113write-stream.subx
index d7e975c0..7dd93fba 100644
--- a/113write-stream.subx
+++ b/113write-stream.subx
@@ -5,32 +5,10 @@
 # . op          subop               mod             rm32          base        index         scale       r32
 # . 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
 
-#? Entry:  # manual test
-#?     # write-stream(stdout, _test-stream2)
-#?     68/push  _test-stream2/imm32
-#?     68/push  1/imm32/stdout
-#?     e8/call write-stream/disp32
-#?     # syscall(exit, Num-test-failures)
-#?     8b/copy                         0/mod/indirect  5/rm32/.disp32            .             .           3/r32/ebx   Num-test-failures/disp32          # copy *Num-test-failures to ebx
-#?     e8/call  syscall_exit/disp32
-
-write-stream:  # f: fd or (addr stream byte), s: (addr stream byte)
+write-stream:  # f: (addr stream byte), s: (addr stream byte)
     # . prologue
     55/push-ebp
     89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
-    # if (f < 0x08000000) _write-stream(f, s), return  # f can't be a user-mode address, so treat it as a kernel file descriptor
-    81          7/subop/compare     1/mod/*+disp8   5/rm32/ebp    .           .             .           .           8/disp8         0x08000000/imm32  # compare *(ebp+8)
-    73/jump-if-addr>=  $write-stream:fake/disp8
-    # . . push args
-    ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           0xc/disp8       .                 # push *(ebp+12)
-    ff          6/subop/push        1/mod/*+disp8   5/rm32/ebp    .           .             .           .           8/disp8         .                 # push *(ebp+8)
-    # . . call
-    e8/call  _write-stream/disp32
-    # . . discard args
-    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
-    eb/jump  $write-stream:end/disp8
-$write-stream:fake:
-    # otherwise, treat 'f' as a stream to append to
     # . save registers
     50/push-eax
     56/push-esi
@@ -64,73 +42,16 @@ $write-stream:fake:
     01/add                          0/mod/indirect  7/rm32/edi    .           .             .           0/r32/eax   .               .                 # add eax to *edi
     # s->read += eax
     01/add                          1/mod/*+disp8   6/rm32/esi    .           .             .           0/r32/eax   4/disp8         .                 # add eax to *(esi+4)
-    # . restore registers
-    5f/pop-to-edi
-    5e/pop-to-esi
-    58/pop-to-eax
 $write-stream:end:
-    # . epilogue
-    89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
-    5d/pop-to-ebp
-    c3/return
-
-_write-stream:  # fd: int, s: (addr stream byte)
-    # . prologue
-    55/push-ebp
-    89/copy                         3/mod/direct    5/rm32/ebp    .           .             .           4/r32/esp   .               .                 # copy esp to ebp
-    # . save registers
-    50/push-eax
-    51/push-ecx
-    52/push-edx
-    53/push-ebx
-    56/push-esi
-    57/push-edi
-    # esi = s
-    8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           6/r32/esi   0xc/disp8       .                 # copy *(ebp+12) to esi
-    # edi = s->read
-    8b/copy                         1/mod/*+disp8   6/rm32/esi    .           .             .           7/r32/edi   4/disp8         .                 # copy *(esi+4) to edi
-    # edx = s->write
-    8b/copy                         0/mod/indirect  6/rm32/esi    .           .             .           2/r32/edx   .               .                 # copy *esi to edx
-    # syscall(write, fd, &s->data[s->read], s->write - s->read)
-    # . . fd: ebx
-    8b/copy                         1/mod/*+disp8   5/rm32/ebp    .           .             .           3/r32/ebx   8/disp8         .                 # copy *(ebp+8) to ebx
-    # . . data: ecx = &s->data[s->read]
-    8d/copy-address                 1/mod/*+disp8   4/rm32/sib    6/base/esi  7/index/edi   .           1/r32/ecx   0xc/disp8       .                 # copy esi+edi+12 to ecx
-    # . . size: edx = s->write - s->read
-    29/subtract                     3/mod/direct    2/rm32/edx    .           .             .           7/r32/edi   .               .                 # subtract edi from edx
-    # . . syscall
-    e8/call  syscall_write/disp32
-    # if (eax < 0) abort
-    3d/compare-eax-with  0/imm32
-    0f 8c/jump-if-<  $_write-stream:abort/disp32
-    # s->read += eax
-    01/add                          1/mod/*+disp8   6/rm32/esi    .           .             .           0/r32/eax   4/disp8         .                 # add eax to *(esi+4)
     # . restore registers
     5f/pop-to-edi
     5e/pop-to-esi
-    5b/pop-to-ebx
-    5a/pop-to-edx
-    59/pop-to-ecx
     58/pop-to-eax
     # . epilogue
     89/copy                         3/mod/direct    4/rm32/esp    .           .             .           5/r32/ebp   .               .                 # copy ebp to esp
     5d/pop-to-ebp
     c3/return
 
-$_write-stream:abort:
-    # . _write(2/stderr, error)
-    # . . push args
-    68/push  "_write-stream: failed to write to file\n"/imm32
-    68/push  2/imm32/stderr
-    # . . call
-    e8/call  _write/disp32
-    # . . discard args
-    81          0/subop/add         3/mod/direct    4/rm32/esp    .           .             .           .           .               8/imm32           # add to esp
-    # . syscall(exit, 1)
-    bb/copy-to-ebx  1/imm32
-    e8/call  syscall_exit/disp32
-    # never gets here
-
 test-write-stream-single:
     # setup
     # . clear-stream(_test-stream)