Add int and iret instruction definitions to the VM backend

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-03-06 12:30:49 -05:00
parent 1fb2a1df44
commit 34b1147fe6
3 changed files with 49 additions and 29 deletions

View File

@@ -46,6 +46,8 @@ instructions! {
RET = 0x2001,
PUSH = 0x2002,
POP = 0x2003,
INT = 0x2004,
IRET = 0x2005,
MOV = 0x3000,
HALT = 0xF000,
NOP = 0xF001,
@@ -77,6 +79,8 @@ pub enum Inst {
Ret,
Push(Source),
Pop(Dest),
Int(Source, Source),
IRet,
Mov(Dest, Source),
Halt,
Nop,
@@ -110,6 +114,8 @@ impl Inst {
Inst::Ret => RET,
Inst::Push(_) => PUSH,
Inst::Pop(_) => POP,
Inst::Int(_, _) => INT,
Inst::IRet => IRET,
Inst::Halt => HALT,
Inst::Nop => NOP,
Inst::Dump => DUMP,
@@ -134,7 +140,8 @@ impl Inst {
| Inst::Not(dest, source)
| Inst::Mov(dest, source) => { 3 + dest.len() + source.len() }
Inst::CmpEq(s1, s2)
| Inst::CmpLt(s1, s2) => { 3 + s1.len() + s2.len() }
| Inst::CmpLt(s1, s2)
| Inst::Int(s1, s2) => { 3 + s1.len() + s2.len() }
Inst::Jmp(v)
| Inst::Jz(v)
| Inst::Jnz(v)
@@ -144,7 +151,8 @@ impl Inst {
Inst::Ret
| Inst::Halt
| Inst::Nop
| Inst::Dump => { 2 }
| Inst::Dump
| Inst::IRet => { 2 }
}
}
}

View File

@@ -121,6 +121,8 @@ impl<T> MemCursor<T>
RET => Ok(Inst::Ret),
PUSH => source!(Push),
POP => dest!(Pop),
INT => { todo!("INT decode") },
IRET => { todo!("IRET decode") },
MOV => dest_source!(Mov),
HALT => Ok(Inst::Halt),
NOP => Ok(Inst::Nop),

View File

@@ -356,6 +356,16 @@ impl State {
Inst::Pop(d) => {
self.pop(d)?;
}
Inst::Int(v, a) => {
let vector = self.load_source(v)?;
let aux = self.load_source(a)?;
// this method immediately jumps, so don't let the next_ip be set below
return self.interrupt(next_ip, vector as usize, aux);
}
Inst::IRet => {
// this method immediately jumps, so don't let the next_ip be set below
return self.exit_interrupt();
}
Inst::Mov(d, s) => {
let value = self.load_source(s)?;
self.store_dest(d, value)?;