summaryrefslogtreecommitdiff
path: root/riscv/main.sail
diff options
context:
space:
mode:
Diffstat (limited to 'riscv/main.sail')
-rw-r--r--riscv/main.sail18
1 files changed, 16 insertions, 2 deletions
diff --git a/riscv/main.sail b/riscv/main.sail
index f7099398..994324bd 100644
--- a/riscv/main.sail
+++ b/riscv/main.sail
@@ -2,14 +2,28 @@ val fetch_and_execute : unit -> unit effect {barr, eamem, escape, exmem, rmem, r
function break () : unit -> unit = ()
-function fetch_and_execute () = while true do {
+val elf_tohost = "Elf_loader.elf_tohost" : unit -> int
+
+function fetch_and_execute () =
+ let tohost = __GetSlice_int(64, elf_tohost(), 0) in
+ while true do {
+ print_bits("PC: ", PC);
let instr = __RISCV_read(PC, 4);
nextPC = PC + 4;
let instr_ast = decode(instr);
break ();
match instr_ast {
Some(ast) => execute(ast),
- None => exit (())
+ None => {print("Decode failed"); exit (())}
+ };
+ let tohost_val = __RISCV_read(tohost, 4);
+ if unsigned(tohost_val) != 0 then {
+ let exit_val = unsigned(tohost_val >> 0b1) in
+ if exit_val == 0 then
+ print("SUCCESS")
+ else
+ print_int("FAILURE: ", exit_val);
+ exit (());
};
PC = nextPC
}