From 3522b3d0cdd47520eaf45187c6d1851dc15ff53b Mon Sep 17 00:00:00 2001 From: Alek Ratzloff Date: Mon, 9 Mar 2020 18:42:31 -0400 Subject: [PATCH] Update spec and register offset for interrupts Signed-off-by: Alek Ratzloff --- src/libvm/src/state.rs | 9 +++++++-- vm.md | 10 +++++----- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/libvm/src/state.rs b/src/libvm/src/state.rs index 8f11818..c2cd5e0 100644 --- a/src/libvm/src/state.rs +++ b/src/libvm/src/state.rs @@ -169,6 +169,10 @@ impl State { Ok(slice) } + // stack size of 288 - yowza + // Maybe we don't need 32 registers... this works out to 288 + const INTERRUPT_REG_SPACE: u64 = (R31 - R00 + 4) as u64 * 8; + /// Invoke an interrupt. pub fn interrupt(&mut self, return_ip: u64, index: usize, aux: u64) -> Result { assert!(index < IVT_LENGTH, "invalid interrupt index"); @@ -192,8 +196,9 @@ impl State { self.push(Source::Reg(reg))?; } + let sp = self.sp(); - self.set_reg_unchecked(FP, sp - 48); + self.set_reg_unchecked(FP, sp - Self::INTERRUPT_REG_SPACE); self.set_reg_unchecked(R00, index as u64); self.set_reg_unchecked(R01, aux); @@ -203,7 +208,7 @@ impl State { /// Exit/return from the current interrupt. pub fn exit_interrupt(&mut self) -> Result { let fp = self.fp(); - let sp = fp + 48; + let sp = fp + Self::INTERRUPT_REG_SPACE; self.set_reg_unchecked(SP, sp); diff --git a/vm.md b/vm.md index 50f5477..c1aa0fd 100644 --- a/vm.md +++ b/vm.md @@ -228,16 +228,15 @@ wrapping around to 0. * Push the IP of the next instruction to be called * Push the FLAGS register * Push the STATUS register - * Push the R0 register - * Push the R1 register + * Push the R0-R31 registers * Update the IP (i.e., jump) to the address of the given interrupt vector in the IVT * Update the R0 register to the value in the first parameter * Update the R1 register to the value in the second parameter - * Update the frame pointer to the current stack pointer - 48 + * Update the frame pointer to the current stack pointer - 288 * IRet * Opcode: 0x3005 * When this instruction is executed, these actions occur: - * Update the stack pointer to the current frame pointer + 48 + * Update the stack pointer to the current frame pointer + 288 * Pop the old R1 value * Pop the old R0 value * Pop the old STATUS value @@ -410,8 +409,9 @@ A VM must provide support for the following meta-values: # General TODO +* Memory permissions * MMIO regions -* Paging? +* Paging * Determine how address sizes are determined * source size <= dest size - zero extend source and copy * mov %r0, (label)u32