From e0d71f95c7943f9c6aeaa5c84970c867b0cd6398 Mon Sep 17 00:00:00 2001 From: Kartik Agaram Date: Thu, 28 Jun 2018 16:12:33 -0700 Subject: 4284 - implement first syscall for subx Hopefully I won't need much more than exit, read and write. --- subx/019syscalls.cc | 19 +++++++++++++++++++ subx/020elf.cc | 1 + 2 files changed, 20 insertions(+) create mode 100644 subx/019syscalls.cc (limited to 'subx') diff --git a/subx/019syscalls.cc b/subx/019syscalls.cc new file mode 100644 index 00000000..96c11ee0 --- /dev/null +++ b/subx/019syscalls.cc @@ -0,0 +1,19 @@ +:(before "End Single-Byte Opcodes") +case 0xcd: { // int imm8 (software interrupt) + uint8_t code = next(); + if (code != 0x80) { + raise << "Unimplemented interrupt code " << HEXBYTE << code << '\n' << end(); + raise << " Only `int 80h` supported for now.\n" << end(); + break; + } + process_int80(); + break; +} + +:(code) +void process_int80() { + switch (Reg[EAX].u) { + case 1: + exit(Reg[EBX].u); + } +} diff --git a/subx/020elf.cc b/subx/020elf.cc index e217755f..3c9d6262 100644 --- a/subx/020elf.cc +++ b/subx/020elf.cc @@ -8,6 +8,7 @@ if (is_equal(argv[1], "run")) { load_elf(argv[2]); while (EIP < End_of_program) // weak final-gasp termination check run_one_instruction(); + raise << "executed past end of the world: " << EIP << " vs " << End_of_program << '\n' << end(); } :(code) -- cgit 1.4.1-2-gfad0