2023-06-07 08:07:37 -05:00
|
|
|
|
#![no_std]
|
2023-06-06 15:03:37 -05:00
|
|
|
|
|
|
|
|
|
macro_rules! constmod {
|
|
|
|
|
($vis:vis $mname:ident($repr:ty) { $($cname:ident = $val:expr),* $(,)? }) => {
|
|
|
|
|
$vis mod $mname {
|
|
|
|
|
$(pub const $cname: $repr = $val;)*
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
constmod!(pub opcode(u8) {
|
2023-06-06 17:02:27 -05:00
|
|
|
|
NOP = 0, // N; Do nothing
|
2023-06-06 15:03:37 -05:00
|
|
|
|
|
2023-06-08 17:10:46 -05:00
|
|
|
|
ADD = 1, // RRR; #0 ← #1 + #2
|
|
|
|
|
SUB = 2, // RRR; #0 ← #1 - #2
|
|
|
|
|
MUL = 3, // RRR; #0 ← #1 × #2
|
|
|
|
|
DIV = 4, // RRR; #0 ← #1 ÷ #2
|
|
|
|
|
REM = 5, // RRR; #0 ← #1 % #2
|
|
|
|
|
AND = 6, // RRR; #0 ← #1 & #2
|
|
|
|
|
OR = 7, // RRR; #0 ← #1 | #2
|
|
|
|
|
XOR = 8, // RRR; #0 ← #1 ^ #2
|
|
|
|
|
SL = 9, // RRR; #0 ← #1 « #2
|
|
|
|
|
SR = 10, // RRR; #0 ← #1 » #2
|
|
|
|
|
SRS = 11, // RRR; #0 ← #1 » #2 (signed)
|
|
|
|
|
NOT = 12, // RR; #0 ← !#1
|
2023-06-06 15:03:37 -05:00
|
|
|
|
|
2023-06-08 17:10:46 -05:00
|
|
|
|
ADDF = 13, // RRR; #0 ← #1 +. #2
|
|
|
|
|
SUBF = 14, // RRR; #0 ← #1 +. #2
|
|
|
|
|
MULF = 15, // RRR; #0 ← #1 +. #2
|
|
|
|
|
DIVF = 16, // RRR; #0 ← #1 +. #2
|
2023-06-06 15:03:37 -05:00
|
|
|
|
|
2023-06-08 17:10:46 -05:00
|
|
|
|
ADDI = 17, // RRI; #0 ← #1 + imm #2
|
|
|
|
|
MULI = 18, // RRI; #0 ← #1 × imm #2
|
|
|
|
|
REMI = 19, // RRI; #0 ← #1 % imm #2
|
|
|
|
|
ANDI = 20, // RRI; #0 ← #1 & imm #2
|
|
|
|
|
ORI = 21, // RRI; #0 ← #1 | imm #2
|
|
|
|
|
XORI = 22, // RRI; #0 ← #1 ^ imm #2
|
2023-06-06 15:03:37 -05:00
|
|
|
|
|
2023-06-08 17:10:46 -05:00
|
|
|
|
SLI = 23, // RRI; #0 ← #1 « imm #2
|
|
|
|
|
SRI = 24, // RRI; #0 ← #1 » imm #2
|
|
|
|
|
SRSI = 25, // RRI; #0 ← #1 » imm #2 (signed)
|
2023-06-06 15:03:37 -05:00
|
|
|
|
|
2023-06-08 17:10:46 -05:00
|
|
|
|
ADDFI = 26, // RRI; #0 ← #1 +. imm #2
|
|
|
|
|
MULFI = 27, // RRI; #0 ← #1 *. imm #2
|
|
|
|
|
|
|
|
|
|
CP = 28, // RR; Copy #0 ← #1
|
|
|
|
|
LI = 29, // RI; Load immediate, #0 ← imm #1
|
|
|
|
|
LB = 30, // RRI; Load byte (8 bits), #0 ← [#1 + imm #2]
|
|
|
|
|
LD = 31, // RRI; Load doublet (16 bits)
|
|
|
|
|
LQ = 32, // RRI; Load quadlet (32 bits)
|
|
|
|
|
LO = 33, // RRI; Load octlet (64 bits)
|
|
|
|
|
SB = 34, // RRI; Store byte, [#1 + imm #2] ← #0
|
|
|
|
|
SD = 35, // RRI; Store doublet
|
|
|
|
|
SQ = 36, // RRI; Store quadlet
|
|
|
|
|
SO = 37, // RRI; Store octlet
|
|
|
|
|
|
2023-06-08 18:55:09 -05:00
|
|
|
|
JMP = 38, // RI; Unconditional jump [#0 + imm #1]
|
|
|
|
|
JEQ = 39, // RRI; if #0 = #1 → jump imm #2
|
|
|
|
|
JNE = 40, // RRI; if #0 ≠ #1 → jump imm #2
|
|
|
|
|
JLT = 41, // RRI; if #0 < #1 → jump imm #2
|
|
|
|
|
JGT = 52, // RRI; if #0 > #1 → jump imm #2
|
|
|
|
|
JLTU = 53, // RRI; if #0 < #1 → jump imm #2 (unsigned)
|
|
|
|
|
JGTU = 54, // RRI; if #0 > #1 → jump imm #2 (unsigned)
|
|
|
|
|
RET = 55, // N; Return
|
|
|
|
|
ECALL = 56, // N; Issue system call
|
2023-06-06 15:03:37 -05:00
|
|
|
|
});
|
|
|
|
|
|
2023-06-08 16:23:23 -05:00
|
|
|
|
#[repr(packed)]
|
|
|
|
|
pub struct ParamRRR(pub u8, pub u8, pub u8);
|
|
|
|
|
#[repr(packed)]
|
|
|
|
|
pub struct ParamRRI(pub u8, pub u8, pub u64);
|
|
|
|
|
#[repr(packed)]
|
|
|
|
|
pub struct ParamRR(pub u8, pub u8);
|
|
|
|
|
#[repr(packed)]
|
|
|
|
|
pub struct ParamRI(pub u8, pub u64);
|
2023-06-06 15:03:37 -05:00
|
|
|
|
|
|
|
|
|
/// # Safety
|
|
|
|
|
/// TODO.
|
|
|
|
|
pub unsafe trait OpParam {}
|
|
|
|
|
unsafe impl OpParam for ParamRRR {}
|
2023-06-06 17:02:27 -05:00
|
|
|
|
unsafe impl OpParam for ParamRRI {}
|
2023-06-06 15:03:37 -05:00
|
|
|
|
unsafe impl OpParam for ParamRR {}
|
|
|
|
|
unsafe impl OpParam for ParamRI {}
|
|
|
|
|
unsafe impl OpParam for u64 {}
|
|
|
|
|
unsafe impl OpParam for () {}
|