progress on serial and added editor
This commit is contained in:
@@ -7,3 +7,4 @@ edition = "2024"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
strum = { version = "0.28.0", features = ["derive"] }
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
use strum::{Display, EnumString};
|
||||
|
||||
use crate::prelude::Register;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub struct Location {
|
||||
offset: u16,
|
||||
register: Option<Register>,
|
||||
@@ -20,13 +23,95 @@ impl Location {
|
||||
// if a register is being used already we have to add the offset to that.
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum ImmConst {
|
||||
Label(String),
|
||||
Imm16(u16),
|
||||
Imm32(u32),
|
||||
}
|
||||
|
||||
pub enum PseudoInstruction {
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, EnumString, Display)]
|
||||
#[strum(ascii_case_insensitive)]
|
||||
pub enum AsmOpcode {
|
||||
Nop,
|
||||
|
||||
Mov,
|
||||
CMov,
|
||||
|
||||
Ldb,
|
||||
Ldbs,
|
||||
Ldh,
|
||||
Ldhs,
|
||||
Ldw,
|
||||
|
||||
Stb,
|
||||
Sth,
|
||||
Stw,
|
||||
|
||||
Lli,
|
||||
Lui,
|
||||
Lwi,
|
||||
|
||||
Jmp,
|
||||
Jez,
|
||||
Jnz,
|
||||
Jic,
|
||||
Jnc,
|
||||
|
||||
Ieq,
|
||||
Ine,
|
||||
Igt,
|
||||
Ige,
|
||||
Ilt,
|
||||
Ile,
|
||||
|
||||
Shl,
|
||||
Shr,
|
||||
Add,
|
||||
Sub,
|
||||
AddI,
|
||||
SubI,
|
||||
|
||||
And,
|
||||
Or,
|
||||
Not,
|
||||
Xor,
|
||||
Nand,
|
||||
Nor,
|
||||
Xnor,
|
||||
|
||||
Int,
|
||||
IRet,
|
||||
Hlt,
|
||||
|
||||
// Function instructions
|
||||
Call,
|
||||
Ret,
|
||||
|
||||
// Stack ops
|
||||
Push,
|
||||
Pop,
|
||||
|
||||
// data directives
|
||||
Db,
|
||||
Dh,
|
||||
Dw,
|
||||
|
||||
// data reservations
|
||||
Resb,
|
||||
Resh,
|
||||
Resw,
|
||||
|
||||
// Function pseudo-instructions
|
||||
Func,
|
||||
Return,
|
||||
|
||||
// include directive
|
||||
Include,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
pub enum AsmInstruction {
|
||||
Nop,
|
||||
|
||||
// move
|
||||
|
||||
@@ -222,7 +222,7 @@ impl fmt::Debug for Instruction {
|
||||
Some(op @ (Opcode::Shl | Opcode::Shr)) => {
|
||||
write!(
|
||||
f,
|
||||
"{op:?} {src:?}, {dest:?}, r:{rshamt:?} + i:{ishamt}",
|
||||
"{op:?} {src:?}, {dest:?}, {rshamt:?} + {ishamt}",
|
||||
op = op,
|
||||
src = self.src1_checked(),
|
||||
dest = self.dest_checked(),
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Default)]
|
||||
use strum::{Display, EnumString};
|
||||
|
||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Default, EnumString)]
|
||||
#[repr(u8)]
|
||||
#[non_exhaustive]
|
||||
#[strum(ascii_case_insensitive)]
|
||||
pub enum Register {
|
||||
// general purpose
|
||||
Rg0 = 0,
|
||||
@@ -22,24 +25,35 @@ pub enum Register {
|
||||
Rge = 14,
|
||||
Rgf = 15,
|
||||
|
||||
// special purpose
|
||||
Acc = 16,
|
||||
Acc = 16, // temp/scratch register
|
||||
|
||||
// stack registers
|
||||
Spr = 17,
|
||||
Bpr = 18,
|
||||
Ret = 19,
|
||||
Idr = 20,
|
||||
Mmr = 21,
|
||||
|
||||
Idr = 20, // points to interrupt descriptor table
|
||||
Mmr = 21, // points to page tables
|
||||
|
||||
// system - read only
|
||||
Zero = 22,
|
||||
Sts = 23,
|
||||
Cir = 24,
|
||||
Pcx = 25,
|
||||
Zero = 22, // always reads as zero.
|
||||
Sts = 23, // status register for flags
|
||||
Cir = 24, // current instruction register
|
||||
Pcx = 25, // program counter
|
||||
|
||||
#[strum(disabled, to_string = "Ret")]
|
||||
Ret = 19, // used under the hood by call/ret instructions but not used directly in asm.
|
||||
|
||||
#[default]
|
||||
#[strum(disabled, to_string = "Null")] // don't include this in FromStr impl
|
||||
Null = 26,
|
||||
}
|
||||
|
||||
impl std::fmt::Display for Register {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{:?}", self)
|
||||
}
|
||||
}
|
||||
|
||||
impl Register {
|
||||
/// Total number of registers, not counting Null as it's not a real register.
|
||||
/// reading or writing to Null is undefined behaviour.
|
||||
@@ -66,90 +80,3 @@ impl Register {
|
||||
Ok(unsafe { Self::from_u8_unchecked(idx) })
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Register {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(
|
||||
f,
|
||||
"{}",
|
||||
match self {
|
||||
// general purpose
|
||||
Self::Rg0 => "Rg0",
|
||||
Self::Rg1 => "Rg1",
|
||||
Self::Rg2 => "Rg2",
|
||||
Self::Rg3 => "Rg3",
|
||||
Self::Rg4 => "Rg4",
|
||||
Self::Rg5 => "Rg5",
|
||||
Self::Rg6 => "Rg6",
|
||||
Self::Rg7 => "Rg7",
|
||||
Self::Rg8 => "Rg8",
|
||||
Self::Rg9 => "Rg9",
|
||||
Self::Rga => "Rga",
|
||||
Self::Rgb => "Rgb",
|
||||
Self::Rgc => "Rgc",
|
||||
Self::Rgd => "Rgd",
|
||||
Self::Rge => "Rge",
|
||||
Self::Rgf => "Rgf",
|
||||
|
||||
// special purpose
|
||||
Self::Acc => "Acc",
|
||||
Self::Spr => "Spr",
|
||||
Self::Bpr => "Bpr",
|
||||
Self::Ret => "Ret",
|
||||
Self::Idr => "Idr",
|
||||
Self::Mmr => "Mmr",
|
||||
|
||||
// system - read only
|
||||
Self::Zero => "Zero",
|
||||
Self::Sts => "Sts",
|
||||
Self::Cir => "Cir",
|
||||
Self::Pcx => "Pcx",
|
||||
|
||||
Self::Null => "Null",
|
||||
}
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl std::str::FromStr for Register {
|
||||
type Err = ();
|
||||
|
||||
fn from_str(s: &str) -> Result<Self, Self::Err> {
|
||||
match s.to_ascii_lowercase().as_str() {
|
||||
// general purpose
|
||||
"rg0" => Ok(Self::Rg0),
|
||||
"rg1" => Ok(Self::Rg1),
|
||||
"rg2" => Ok(Self::Rg2),
|
||||
"rg3" => Ok(Self::Rg3),
|
||||
"rg4" => Ok(Self::Rg4),
|
||||
"rg5" => Ok(Self::Rg5),
|
||||
"rg6" => Ok(Self::Rg6),
|
||||
"rg7" => Ok(Self::Rg7),
|
||||
"rg8" => Ok(Self::Rg8),
|
||||
"rg9" => Ok(Self::Rg9),
|
||||
"rga" => Ok(Self::Rga),
|
||||
"rgb" => Ok(Self::Rgb),
|
||||
"rgc" => Ok(Self::Rgc),
|
||||
"rgd" => Ok(Self::Rgd),
|
||||
"rge" => Ok(Self::Rge),
|
||||
"rgf" => Ok(Self::Rgf),
|
||||
|
||||
// special purpose
|
||||
"acc" => Ok(Self::Acc),
|
||||
"spr" => Ok(Self::Spr),
|
||||
"bpr" => Ok(Self::Bpr),
|
||||
// "ret" => Ok(Self::Ret),
|
||||
"idr" => Ok(Self::Idr),
|
||||
"mmr" => Ok(Self::Mmr),
|
||||
|
||||
// system - read only
|
||||
"zero" => Ok(Self::Zero),
|
||||
"sts" => Ok(Self::Sts),
|
||||
"cir" => Ok(Self::Cir),
|
||||
"pcx" => Ok(Self::Pcx),
|
||||
|
||||
"null" => Ok(Self::Null),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user