diff --git a/.idea/.gitignore b/.idea/.gitignore
new file mode 100644
index 0000000..13566b8
--- /dev/null
+++ b/.idea/.gitignore
@@ -0,0 +1,8 @@
+# Default ignored files
+/shelf/
+/workspace.xml
+# Editor-based HTTP Client requests
+/httpRequests/
+# Datasource local storage ignored files
+/dataSources/
+/dataSources.local.xml
diff --git a/.idea/dsa2.iml b/.idea/dsa2.iml
new file mode 100644
index 0000000..40aec87
--- /dev/null
+++ b/.idea/dsa2.iml
@@ -0,0 +1,16 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/modules.xml b/.idea/modules.xml
new file mode 100644
index 0000000..2190bf5
--- /dev/null
+++ b/.idea/modules.xml
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
new file mode 100644
index 0000000..35eb1dd
--- /dev/null
+++ b/.idea/vcs.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/dsa/common/src/asm/asm_opcode.rs b/dsa/common/src/asm/asm_opcode.rs
new file mode 100644
index 0000000..938e49d
--- /dev/null
+++ b/dsa/common/src/asm/asm_opcode.rs
@@ -0,0 +1,67 @@
+pub enum AsmOpcode {
+ Nop,
+
+ // move
+ Mov,
+ CMov,
+
+ // load
+ Ldb,
+ Ldbs,
+ Ldh,
+ Ldhs,
+ Ldw,
+
+ // store
+ Stb,
+ Sth,
+ Stw,
+
+ // load immediate
+ Lli,
+ Lui,
+ Lwi,
+
+ // comparison
+ Ieq,
+ Ine,
+ Ilt,
+ Ile,
+ Igt,
+ Ige,
+
+ // jump
+ Jmp,
+ Jez,
+ Jnz,
+ Jic,
+ Jnc,
+
+ // bitwise
+ And,
+ Nand,
+ Or,
+ Nor,
+ Xor,
+ Xnor,
+ Not,
+
+ // arithmetic
+ Add,
+ Sub,
+ Shl,
+ Shr,
+ Addi,
+ Subi,
+
+ // utility
+ Push,
+ Pop,
+ Call,
+ Ret,
+
+ // system
+ Int,
+ IRet,
+ Hlt,
+}
diff --git a/dsa/common/src/asm/mod.rs b/dsa/common/src/asm/mod.rs
new file mode 100644
index 0000000..75e82cd
--- /dev/null
+++ b/dsa/common/src/asm/mod.rs
@@ -0,0 +1,232 @@
+use crate::prelude::Register;
+
+pub struct Location {
+ offset: u16,
+ register: Option,
+ label: Option,
+}
+
+impl Location {
+ pub fn new(offset: u16, register: Option, label: Option) -> Self {
+ Location {
+ offset,
+ register,
+ label,
+ }
+ }
+
+ // need implementation to intelligently figure out if we need to load immediates
+ // so if the label is a const and > u16::max, we do Lui $label temp, then use temp as an offset
+ // if a register is being used already we have to add the offset to that.
+}
+
+pub enum ImmConst {
+ Label(String),
+ Imm16(u16),
+ Imm32(u32),
+}
+
+pub enum PseudoInstruction {
+ Nop,
+
+ // move
+ Mov {
+ src: Register,
+ dest: Register,
+ },
+ CMov {
+ src: Register,
+ dest: Register,
+ condition: Register,
+ },
+
+ // load
+ Ldb {
+ addr: Location,
+ dest: Register,
+ },
+ Ldbs {
+ addr: Location,
+ dest: Register,
+ },
+ Ldh {
+ addr: Location,
+ dest: Register,
+ },
+ Ldhs {
+ addr: Location,
+ dest: Register,
+ },
+ Ldw {
+ addr: Location,
+ dest: Register,
+ },
+
+ // store
+ Stb {
+ src: Register,
+ addr: Location,
+ },
+ Sth {
+ src: Register,
+ addr: Location,
+ },
+ Stw {
+ src: Register,
+ addr: Location,
+ },
+
+ // load immediate
+ Lli {
+ dest: Register,
+ value: ImmConst,
+ },
+ Lui {
+ dest: Register,
+ value: ImmConst,
+ },
+ Lwi {
+ dest: Register,
+ value: ImmConst,
+ },
+
+ // comparison
+ Ieq {
+ src1: Register,
+ src2: Register,
+ dest: Register,
+ },
+ Ine {
+ src1: Register,
+ src2: Register,
+ dest: Register,
+ },
+ Ilt {
+ src1: Register,
+ src2: Register,
+ dest: Register,
+ },
+ Ile {
+ src1: Register,
+ src2: Register,
+ dest: Register,
+ },
+ Igt {
+ src1: Register,
+ src2: Register,
+ dest: Register,
+ },
+ Ige {
+ src1: Register,
+ src2: Register,
+ dest: Register,
+ },
+
+ // jump
+ Jmp {
+ dest: Location,
+ },
+ Jez {
+ dest: Location,
+ cond: Register,
+ },
+ Jnz {
+ dest: Location,
+ cond: Register,
+ },
+ Jic {
+ dest: Location,
+ },
+ Jnc {
+ dest: Location,
+ },
+
+ // bitwise
+ And {
+ src1: Register,
+ src2: Register,
+ dest: Option,
+ },
+ Nand {
+ src1: Register,
+ src2: Register,
+ dest: Option,
+ },
+ Or {
+ src1: Register,
+ src2: Register,
+ dest: Option,
+ },
+ Nor {
+ src1: Register,
+ src2: Register,
+ dest: Register,
+ },
+ Xor {
+ src1: Register,
+ src2: Register,
+ dest: Option,
+ },
+ Xnor {
+ src1: Register,
+ src2: Register,
+ dest: Option,
+ },
+ Not {
+ src: Register,
+ dest: Option,
+ },
+
+ // arithmetic
+ Add {
+ src1: Register,
+ src2: Register,
+ dest: Option,
+ },
+ Sub {
+ src1: Register,
+ src2: Register,
+ dest: Option,
+ },
+ Shl {
+ src: Register,
+ shamt_r: Option,
+ shamt_i: Option,
+ dest: Option,
+ },
+ Shr {
+ src: Register,
+ shamt_r: Option,
+ shamt_i: Option,
+ dest: Option,
+ },
+ Addi {
+ src: Register,
+ value: ImmConst,
+ dest: Option,
+ },
+ Subi {
+ src: Register,
+ value: ImmConst,
+ dest: Option,
+ },
+
+ // utility
+ Push {
+ src: Register,
+ },
+ Pop {
+ dest: Register,
+ },
+ Call {
+ dest: Location,
+ },
+ Ret,
+
+ // system
+ Int {
+ code: ImmConst,
+ },
+ IRet,
+ Hlt,
+}
diff --git a/dsa/common/src/instructions/decode.rs b/dsa/common/src/isa/instructions/decode.rs
similarity index 95%
rename from dsa/common/src/instructions/decode.rs
rename to dsa/common/src/isa/instructions/decode.rs
index cfabe5d..1c14048 100644
--- a/dsa/common/src/instructions/decode.rs
+++ b/dsa/common/src/isa/instructions/decode.rs
@@ -1,4 +1,5 @@
-use crate::{instructions::Instruction, register::Register};
+use crate::isa::instructions::Instruction;
+use crate::isa::register::Register;
impl Instruction {
#[inline]
diff --git a/dsa/common/src/instructions/encode.rs b/dsa/common/src/isa/instructions/encode.rs
similarity index 99%
rename from dsa/common/src/instructions/encode.rs
rename to dsa/common/src/isa/instructions/encode.rs
index fd79163..e4f4c5e 100644
--- a/dsa/common/src/instructions/encode.rs
+++ b/dsa/common/src/isa/instructions/encode.rs
@@ -1,9 +1,7 @@
use std::ops::{Deref, DerefMut};
-use crate::{
- instructions::{Instruction, Opcode},
- register::Register,
-};
+use crate::isa::instructions::{Instruction, Opcode};
+use crate::isa::register::Register;
impl From for Instruction {
#[inline]
diff --git a/dsa/common/src/instructions/mod.rs b/dsa/common/src/isa/instructions/mod.rs
similarity index 100%
rename from dsa/common/src/instructions/mod.rs
rename to dsa/common/src/isa/instructions/mod.rs
diff --git a/dsa/common/src/isa/mod.rs b/dsa/common/src/isa/mod.rs
new file mode 100644
index 0000000..663b681
--- /dev/null
+++ b/dsa/common/src/isa/mod.rs
@@ -0,0 +1,2 @@
+pub mod register;
+pub mod instructions;
\ No newline at end of file
diff --git a/dsa/common/src/register.rs b/dsa/common/src/isa/register.rs
similarity index 100%
rename from dsa/common/src/register.rs
rename to dsa/common/src/isa/register.rs
diff --git a/dsa/common/src/lib.rs b/dsa/common/src/lib.rs
index 13ccda5..be900cf 100644
--- a/dsa/common/src/lib.rs
+++ b/dsa/common/src/lib.rs
@@ -1,7 +1,7 @@
-pub mod instructions;
-pub mod register;
+pub mod asm;
+pub mod isa;
pub mod prelude {
- pub use crate::instructions::Instruction;
- pub use crate::register::Register;
+ pub use crate::isa::instructions::Instruction;
+ pub use crate::isa::register::Register;
}
diff --git a/dsa/emulator/src/bin/bench_emu.rs b/dsa/emulator/src/bin/bench_emu.rs
index fd2e29e..9c8d9b8 100644
--- a/dsa/emulator/src/bin/bench_emu.rs
+++ b/dsa/emulator/src/bin/bench_emu.rs
@@ -1,4 +1,4 @@
-use common::instructions::Instruction;
+use common::isa::instructions::Instruction;
use dsa::{BulkAllocStore, Emulator, Page, RandomAccessMemory};
/// DSA Emulator Benchmark
///
diff --git a/dsa/emulator/src/main.rs b/dsa/emulator/src/main.rs
index 2842702..bed286f 100644
--- a/dsa/emulator/src/main.rs
+++ b/dsa/emulator/src/main.rs
@@ -1,18 +1,15 @@
use clap::Parser;
-use common::{instructions::Instruction, register::Register};
+use common::isa::instructions::Instruction;
use dsa::{
- BulkAllocStore, Emulator, Page, RandomAccessMemory, SharedState,
- args::DsaArgs,
- io::display::{DisplayDevice, DisplayHandle},
+ args::DsaArgs, io::display::{DisplayDevice, DisplayHandle}, BulkAllocStore, Emulator, Page,
+ RandomAccessMemory,
+ SharedState,
};
use std::{
- os::unix::thread::JoinHandleExt,
- process::exit,
- sync::{Arc, atomic::Ordering},
+ sync::{atomic::Ordering, Arc},
thread,
time::Duration,
};
-
fn main() {
let args = DsaArgs::parse();
diff --git a/dsa/emulator/src/processor/processor.rs b/dsa/emulator/src/processor/processor.rs
index d3c278c..74fbd7f 100644
--- a/dsa/emulator/src/processor/processor.rs
+++ b/dsa/emulator/src/processor/processor.rs
@@ -1,26 +1,23 @@
use std::{
hint::unlikely,
- ops::{Add, AddAssign},
+ ops::AddAssign,
sync::{
- Arc,
atomic::Ordering,
mpsc::{self, TryRecvError},
+ Arc,
},
thread,
time::{Duration, Instant},
};
-use common::{
- instructions::{Instruction, Opcode},
- register::Register,
-};
-
+use common::isa::instructions::{Instruction, Opcode};
+use common::isa::register::Register;
use crate::{
- Page,
config::{IoMapping, MemoryMap, RegionType},
- io::{IoAccess, IoDevice, MappedDevice},
+ io::{IoDevice, MappedDevice},
memory::{mmu::MMU, ram::RandomAccessMemory},
processor::{interrupts::Interrupt, state::SharedState},
+ Page,
};
pub struct Emulator {