Add IVT register and interrupt module

Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
2020-03-04 14:37:00 -05:00
parent bdd30274ed
commit ce352c000c
5 changed files with 59 additions and 34 deletions

View File

@@ -0,0 +1,19 @@
macro_rules! interrupts {
{
$($variant:ident = $value:expr),* $(,)?
} => {
pub type IntVec = u8;
$(
#[allow(dead_code)]
pub const $variant: IntVec = $value;
)*
};
}
interrupts! {
DIVIDE_BY_ZERO = 0,
INVALID_OPCODE = 1,
ILLEGAL_MEMORY_ADDRESS = 2,
HARDWARE_EVENT = 3,
}

View File

@@ -4,6 +4,7 @@ pub mod addr;
pub mod error;
pub mod flags;
pub mod inst;
pub mod interrupt;
pub mod mem;
pub mod obj;
pub mod reg;

View File

@@ -60,6 +60,7 @@ dump "DUMP"
%fp "REG_FP"
%flags "REG_FLAGS"
%null "REG_NULL"
%ivt "REG_IVT"
%status "REG_STATUS"
%r[0-9]{1,2} "REG_GENERAL"
[a-zA-Z_][a-zA-Z0-9_]* "NAME"

View File

@@ -137,6 +137,7 @@ Reg -> Reg:
| 'REG_FP' { FP }
| 'REG_FLAGS' { FLAGS }
| 'REG_NULL' { NULL }
| 'REG_IVT' { IVT }
| 'REG_STATUS' { STATUS }
| 'REG_GENERAL' {
let v = $1.expect("could not parse reg");

View File

@@ -36,41 +36,44 @@ registers! {
// Zero
NULL = 4,
// General status code
STATUS = 5,
// Interrupt vector table pointer
IVT = 5,
R00 = 6,
R01 = 7,
R02 = 8,
R03 = 9,
R04 = 10,
R05 = 11,
R06 = 12,
R07 = 13,
R08 = 14,
R09 = 15,
R10 = 16,
R11 = 17,
R12 = 18,
R13 = 19,
R14 = 20,
R15 = 21,
R16 = 22,
R17 = 23,
R18 = 24,
R19 = 25,
R20 = 26,
R21 = 27,
R22 = 28,
R23 = 29,
R24 = 30,
R25 = 31,
R26 = 32,
R27 = 33,
R28 = 34,
R29 = 35,
R30 = 36,
R31 = 37,
// General status code
STATUS = 6,
R00 = 7,
R01 = 8,
R02 = 9,
R03 = 10,
R04 = 11,
R05 = 12,
R06 = 13,
R07 = 14,
R08 = 15,
R09 = 16,
R10 = 17,
R11 = 18,
R12 = 19,
R13 = 20,
R14 = 21,
R15 = 22,
R16 = 23,
R17 = 24,
R18 = 25,
R19 = 26,
R20 = 27,
R21 = 28,
R22 = 29,
R23 = 30,
R24 = 31,
R25 = 32,
R26 = 33,
R27 = 34,
R28 = 35,
R29 = 36,
R30 = 37,
R31 = 38,
}
pub const LAST_REG: Reg = 63;