holey-bytes/hbbytecode/src/lib.rs

70 lines
2 KiB
Rust
Raw Normal View History

2023-06-07 08:07:37 -05:00
#![no_std]
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
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
NOT = 9, // RR; #0 ← !#1
// TODO: Add instruction for integer and float
// reg ← reg + imm instructions
2023-06-06 17:02:27 -05:00
ADDF = 10, // RRR; #0 ← #1 +. #2
SUBF = 11, // RRR; #0 ← #1 +. #2
MULF = 12, // RRR; #0 ← #1 +. #2
DIVF = 13, // RRR; #0 ← #1 +. #2
2023-06-06 17:02:27 -05:00
CP = 14, // RR; Copy #0 ← #1
LI = 15, // RI; Load immediate, #0 ← imm #1
LB = 16, // RRI; Load byte (8 bits), #0 ← [#1 + imm #2]
LD = 17, // RRI; Load doublet (16 bits)
LQ = 18, // RRI; Load quadlet (32 bits)
LO = 19, // RRI; Load octlet (64 bits)
SB = 20, // RRI; Store byte, [#1 + imm #2] ← #0
SD = 21, // RRI; Store doublet
SQ = 22, // RRI; Store quadlet
SO = 23, // RRI; Store octlet
2023-06-06 17:02:27 -05:00
PAGEMAP = 24, // ?; Map a page
PAGEUNMAP = 25, // ?; Unmap a page
PAGEMP = 26, // ?; Page modify protection flags
2023-06-07 17:52:24 -05:00
JMP = 27, // RI; Unconditional jump [#0 + imm #1]
2023-06-07 08:07:37 -05:00
JMPCOND = 28, // ?; Conditional jump
RET = 29, // N; Return
ECALL = 30, // N; Issue system call
});
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);
/// # Safety
/// TODO.
pub unsafe trait OpParam {}
unsafe impl OpParam for ParamRRR {}
2023-06-06 17:02:27 -05:00
unsafe impl OpParam for ParamRRI {}
unsafe impl OpParam for ParamRR {}
unsafe impl OpParam for ParamRI {}
unsafe impl OpParam for u64 {}
unsafe impl OpParam for () {}