about summary refs log blame commit diff stats
path: root/mu-init.subx
blob: da22b2b353dade5ad18691c4ab244ad742c1dd83 (plain) (tree)
1
2
3
4
5
6
7
8

                                                 
                                          
 
                                                                    
                                                                                    
 
                                                       


       
      

                        





                                                                            
   












                                                 
 



                      
# Initialize the minimal runtime for Mu programs.
#
# See translate for how this file is used.
#
# Mu programs start at a function called 'main' with this signature:
#   fn main screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk)
#
# All tests must pass first (the "power-on unit test").

== code

Entry:
  # initialize stack
  bd/copy-to-ebp 0/imm32
  # Clear memory location 0 to ensure that uninitialized arrays run afoul of
  # the bounds checker.
  # TODO: This is utterly bonkers, and does not actually protect us against
  # all null pointer reads/writes. Create a real page table sometime.
  b8/copy-to-eax 0/imm32
  c7 0/subop/copy *eax 0/imm32
  #
#?   (main 0 0 Primary-bus-secondary-drive)
  # always first run tests
  (run-tests)
  (num-test-failures)  # => eax
  # call main if tests all passed
  {
    3d/compare-eax-and 0/imm32
    75/jump-if-!= break/disp8
    (clear-real-screen)
    c7 0/subop/copy *Real-screen-cursor-x 0/imm32
    c7 0/subop/copy *Real-screen-cursor-y 0/imm32
    (main 0 0 Primary-bus-secondary-drive)
  }

  # hang indefinitely
  {
    eb/jump loop/disp8
  }