boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

p1-call.P1pp (868B)


      1 # tests/p1/p1-call.P1 -- exercise ENTER, ERET, CALL, RET, MOV, ADDI
      2 # across a nontrivial P1 program. Calls a `write_msg` subroutine twice
      3 # and returns argc + 1 as the exit status so we also verify the argv-
      4 # aware _start stub (argc is always >= 1).
      5 
      6 :p1_main
      7     # Build a frame and stash argc in s0 so write_msg can trash a0.
      8     %enter(0)
      9     %mov(s0, a0)
     10 
     11     # write_msg("A\n")
     12     %la(a0, &msg_a)
     13     %li(a1, 2)
     14     %call(&write_msg)
     15 
     16     # write_msg("BC\n")
     17     %la(a0, &msg_bc)
     18     %li(a1, 3)
     19     %call(&write_msg)
     20 
     21     # exit status = argc + 1 (so it's always >= 2).
     22     %addi(a0, s0, 1)
     23     %eret
     24 
     25 # write_msg(buf=a0, len=a1) -> void
     26 :write_msg
     27     %enter(0)
     28     # Shift (a0, a1) -> (a2, a3); fd goes in a1, number in a0.
     29     %mov(a2, a0)
     30     %mov(a3, a1)
     31     %li(a0, %sys_write)
     32     %li(a1, 1)
     33     %syscall
     34     %eret
     35 
     36 :msg_a
     37 "A
     38 "
     39 
     40 :msg_bc
     41 "BC
     42 "
     43 
     44 :ELF_end