implement TRAP

trap routines not yet implemented
This commit is contained in:
dogeystamp 2024-01-06 13:46:11 -05:00
parent a76d194cc7
commit 7adac34b3e
Signed by: dogeystamp
GPG Key ID: 7225FE3592EFFA38
2 changed files with 21 additions and 1 deletions

View File

@ -84,7 +84,7 @@ pub fn execute_instruction(vm: &mut VM, instr: u16) {
OpCode::JMP => no_op(vm, instr),
OpCode::RES => no_op(vm, instr),
OpCode::LEA => op_lea(vm, instr),
OpCode::TRAP => no_op(vm, instr),
OpCode::TRAP => op_trap(vm, instr),
OpCode::NOOP => no_op(vm, instr),
}
}
@ -105,3 +105,20 @@ fn op_lea(vm: &mut VM, instr: u16) {
let offset = sign_extend(instr & 0xff, 9);
vm.registers.set_reg(dr, vm.registers.pc + offset);
}
fn op_trap(vm: &mut VM, instr: u16) {
// conform to spec
// (we don't actually need it in this implementation)
vm.registers.r7 = vm.registers.pc;
let trap_vector = instr & 0xff;
match trap_vector {
0x20 => todo!("GETC"),
0x21 => todo!("OUT"),
0x22 => todo!("PUTS"),
0x23 => todo!("IN"),
0x24 => todo!("PUTSP"),
0x25 => todo!("HALT"),
_ => unimplemented!(),
}
}

View File

@ -192,6 +192,9 @@ impl VM {
while running {
let instr = self.mem.get_mem(self.registers.pc);
// NOTE
// remember PC points to the *next* instruction at all times
// disallow reading past memory bounds
if self.registers.pc as usize == MEM_SIZE - 1 {
running = false