https://github.com/akkartik/mu/blob/main/mu-init.subx

     1 # Initialize the minimal runtime for Mu programs.
     2 #
     3 # See translate for how this file is used.
     4 #
     5 # Mu programs start at a function called 'main' with this signature:
     6 #   fn main screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk)
     7 #
     8 # All tests must pass first (the "power-on unit test").
     9
    10 == code
    11
    12 Entry:
    13   # initialize stack
    14   bd/copy-to-ebp 0/imm32
    15   # Clear memory location 0 to ensure that uninitialized arrays run afoul of
    16   # the bounds checker.
    17   # TODO: This is utterly bonkers, and does not actually protect us against
    18   # all null pointer reads/writes. Create a real page table sometime.
    19   b8/copy-to-eax 0/imm32
    20   c7 0/subop/copy *eax 0/imm32
    21 #?   (main 0 0 Primary-bus-secondary-drive)
    22   # always first run tests
    23   (run-tests)
    24   (num-test-failures)  # => eax
    25   # call main if tests all passed
    26   {
    27     3d/compare-eax-and 0/imm32
    28     75/jump-if-!= break/disp8
    29     (clear-real-screen)
    30     c7 0/subop/copy *Real-screen-cursor-x 0/imm32
    31     c7 0/subop/copy *Real-screen-cursor-y 0/imm32
    32     (main 0 0 Primary-bus-secondary-drive)
    33   }
    34
    35   # hang indefinitely
    36   {
    37     eb/jump loop/disp8
    38   }