kit

kit
git clone https://git.ryansepassi.com/git/kit.git
Log | Files | Refs | README

entry.rv64.S (1382B)


      1 /* rv64 kernel entry: stack + kmain + SIFIVE_TEST exit.
      2  *
      3  * Booted by qemu-system-riscv64 -machine virt -bios none, which jumps
      4  * to the kernel image at 0x80000000 in M-mode with a0=hartid, a1=DTB.
      5  * We don't switch privilege levels (the test runs entirely in M-mode),
      6  * just set a stack and call kmain.
      7  *
      8  * Exit via the SIFIVE_TEST MMIO device at 0x100000:
      9  *   write 0x5555  → qemu exits with status 0 (pass)
     10  *   write 0x3333  → qemu exits with status 1 (fail), low bits encode
     11  *                   a 16-bit user code shifted into bits [16:1]; we
     12  *                   only need pass/fail here. */
     13 
     14     .section .text, "ax"
     15     .globl _start
     16 _start:
     17     /* Hart 0 only — qemu-virt boots a single hart by default, but
     18      * be defensive against smp>1 by parking other harts in WFI. */
     19     bnez    a0, .Lhang
     20 
     21     la      sp, kstack_top
     22 
     23     call    kmain
     24 
     25     bnez    a0, .Lfail
     26 
     27     /* Pass: write SIFIVE_TEST_PASS = 0x5555 to 0x100000. */
     28     li      t0, 0x100000
     29     li      t1, 0x5555
     30     sw      t1, 0(t0)
     31 .Lhang:
     32     wfi
     33     j       .Lhang
     34 
     35 .Lfail:
     36     /* Fail: write SIFIVE_TEST_FAIL = 0x3333 to 0x100000. The high
     37      * 16 bits would carry a user code; we leave them zero. */
     38     li      t0, 0x100000
     39     li      t1, 0x3333
     40     sw      t1, 0(t0)
     41     j       .Lhang
     42 
     43     .section .bss, "aw", %nobits
     44     .balign 16
     45 kstack_bottom:
     46     .skip   4096
     47 kstack_top: