diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Makefile | 8 | ||||
-rw-r--r-- | cpu.ha | 13 | ||||
-rw-r--r-- | opc_impl.ha | 4 | ||||
-rw-r--r-- | sys0.r1a | 8 |
5 files changed, 27 insertions, 7 deletions
@@ -1,3 +1,4 @@ opcodes.ha *.py[cod] +*.r1b @@ -1,8 +1,12 @@ .POSIX: .SUFFIXES: +.SUFFIXES: .r1a .r1b -run: opcodes.ha - hare run +run: opcodes.ha sys0.r1b + hare run . sys0.r1b + +.r1a.r1b: + ./asm.py <$< >$@ opcodes.ha: mnems.py ./mnems.py >opcodes.ha @@ -110,15 +110,22 @@ fn mainloop(cpu: *cpu) void = { }; export fn main() void = { + if (len(os::args) != 2) + fmt::fatalf("usage: {} FILE.r1b", os::args[0]); + const fname = os::args[1]; + const cpu = cpu_new(); - const fp = match (os::open("sys0.r1b")) { + const fp = match (os::open(fname)) { case let i: io::file => yield i; - case let e: fs::error => fmt::fatalf("MISSING BOOT SECTOR: {}", + case let e: fs::error => fmt::fatalf("couldn't open boot sector {}", fs::strerror(e)); }; match (io::readall(fp, cpu.mem[0x0200..0x0300])) { - case let e: io::error => fmt::fatalf("BOOT SECTOR READ ERROR: {}", io::strerror(e)); + case let e: io::error => match (e) { + case io::underread => yield; + case let e: io::error => fmt::fatalf("couldn't read boot sector {}", io::strerror(e)); + }; case => yield; }; diff --git a/opc_impl.ha b/opc_impl.ha index f85be5f..c264ab4 100644 --- a/opc_impl.ha +++ b/opc_impl.ha @@ -80,8 +80,8 @@ fn do_opr(cpu: *cpu, op: u8) void = switch (op) { const y = pop(cpu); push(cpu, x + y); case op::SUB => - const x = pop(cpu); const y = pop(cpu); + const x = pop(cpu); push(cpu, x - y); case op::MUL => // TODO: better handling mul div @@ -89,8 +89,8 @@ fn do_opr(cpu: *cpu, op: u8) void = switch (op) { const y = pop(cpu); push(cpu, x * y); case op::DIV => - const x = pop(cpu); const y = pop(cpu); + const x = pop(cpu); push(cpu, x / y); case op::NEG => push(cpu, - pop(cpu)); diff --git a/sys0.r1a b/sys0.r1a new file mode 100644 index 0000000..4830cda --- /dev/null +++ b/sys0.r1a @@ -0,0 +1,8 @@ +l 10 +% start +i dup put +i lit1 sub +i dup lit0 +i equ +b start +i hlt |