Skip to content

Commit

Permalink
Merge pull request #357 from SWIM-ucf/stack-segment
Browse files Browse the repository at this point in the history
Stack Frame & Stack Segment Viewer
  • Loading branch information
cayb0rg authored Mar 27, 2024
2 parents c4d688a + c09941b commit c0fa1ed
Show file tree
Hide file tree
Showing 42 changed files with 1,209 additions and 627 deletions.
247 changes: 122 additions & 125 deletions Cargo.lock

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
name = "swim"
version = "0.1.0"
edition = "2021"
rust-version = "1.67"
rust-version = "1.77"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[toolchain]
channel = "1.67"
channel = "1.77"
components = [ "rustc", "cargo", "rustfmt", "rust-std", "rust-docs", "clippy" ]
targets = [ "wasm32-unknown-unknown" ]
profile = "default"
16 changes: 16 additions & 0 deletions src/agent.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ pub async fn emulation_core_agent(scope: ReactorScope<Command, DatapathUpdate>)
// Save the previous state of the emulator core's execution and initialization status
let is_executing = state.executing;
let is_initialized = state.initialized;
let curr_speed = state.speed;

// Part 1: Delay/Command Handling
if state.executing {
Expand Down Expand Up @@ -119,6 +120,11 @@ pub async fn emulation_core_agent(scope: ReactorScope<Command, DatapathUpdate>)
state.updates.changed_memory,
MipsStateUpdate::UpdateMemory(datapath.memory.clone())
);
send_update_mips!(
state.scope,
state.updates.changed_stack,
MipsStateUpdate::UpdateStack(datapath.stack.clone())
);
}
DatapathRef::RISCV(datapath) => {
// Stage always updates
Expand All @@ -144,6 +150,11 @@ pub async fn emulation_core_agent(scope: ReactorScope<Command, DatapathUpdate>)
state.updates.changed_memory,
RiscStateUpdate::UpdateMemory(datapath.memory.clone())
);
send_update_riscv!(
state.scope,
state.updates.changed_stack,
RiscStateUpdate::UpdateStack(datapath.stack.clone())
);
}
}
// Part 5: Sending Non-Syscall System Updates to UI
Expand All @@ -157,6 +168,11 @@ pub async fn emulation_core_agent(scope: ReactorScope<Command, DatapathUpdate>)
state.initialized != is_initialized,
DatapathUpdate::System(SystemUpdate::UpdateInitialized(state.initialized))
);
send_update!(
state.scope,
state.speed != curr_speed,
DatapathUpdate::System(SystemUpdate::UpdateSpeed(state.speed))
);
state.updates = Default::default();
}
}
Expand Down
38 changes: 36 additions & 2 deletions src/agent/datapath_reducer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ use crate::emulation_core::architectures::AvailableDatapaths::{MIPS, RISCV};
use crate::emulation_core::mips::coprocessor::FpuState;
use crate::emulation_core::mips::datapath::{DatapathState, Stage};
use crate::emulation_core::mips::fp_registers::FpRegisters;
use crate::emulation_core::mips::gp_registers::GpRegisters;
use crate::emulation_core::mips::gp_registers::{GpRegisterType, GpRegisters};
use crate::emulation_core::mips::memory::Memory;
use crate::emulation_core::register::{RegisterType, Registers};
use crate::emulation_core::riscv::datapath::{RiscDatapathState, RiscStage};
use crate::emulation_core::riscv::registers::RiscGpRegisters;
use crate::emulation_core::riscv::registers::{RiscGpRegisterType, RiscGpRegisters};
use crate::emulation_core::stack::Stack;
use gloo_console::log;
use std::rc::Rc;
use yew::Reducible;
Expand All @@ -32,6 +33,7 @@ pub struct MipsCoreState {
pub coprocessor_registers: FpRegisters,
pub memory: Memory,
pub current_stage: Stage,
pub stack: Stack,
}

#[derive(Default, PartialEq, Clone)]
Expand All @@ -40,6 +42,7 @@ pub struct RiscCoreState {
pub registers: RiscGpRegisters,
pub memory: Memory,
pub current_stage: RiscStage,
pub stack: Stack,
}

impl Default for DatapathReducer {
Expand Down Expand Up @@ -95,6 +98,10 @@ impl Reducible for DatapathReducer {
current_stage: stage,
..self.mips.clone()
},
MipsStateUpdate::UpdateStack(stack) => MipsCoreState {
stack,
..self.mips.clone()
},
},
..(*self).clone()
},
Expand All @@ -111,6 +118,15 @@ impl Reducible for DatapathReducer {
initialized,
..(*self).clone()
},
SystemUpdate::UpdateSpeed(speed) => Self {
current_architecture: self.current_architecture.clone(),
mips: self.mips.clone(),
messages: self.messages.clone(),
speed,
executing: self.executing,
initialized: self.initialized,
riscv: self.riscv.clone(),
},
},
DatapathUpdate::RISCV(update) => Self {
current_architecture: RISCV,
Expand All @@ -131,6 +147,10 @@ impl Reducible for DatapathReducer {
current_stage,
..self.riscv.clone()
},
RiscStateUpdate::UpdateStack(stack) => RiscCoreState {
stack,
..self.riscv.clone()
},
},
..(*self).clone()
},
Expand All @@ -146,6 +166,13 @@ impl DatapathReducer {
}
}

pub fn get_sp(&self) -> u64 {
match self.current_architecture {
MIPS => self.mips.registers[GpRegisterType::Sp],
RISCV => self.riscv.registers[RiscGpRegisterType::X1],
}
}

pub fn get_dyn_gp_registers(&self) -> Vec<(Rc<dyn RegisterType>, u64)> {
match self.current_architecture {
MIPS => self.mips.registers.get_dyn_register_list(),
Expand All @@ -159,4 +186,11 @@ impl DatapathReducer {
RISCV => &self.riscv.memory,
}
}

pub fn get_stack(&self) -> &Stack {
match self.current_architecture {
MIPS => &self.mips.stack,
RISCV => &self.riscv.stack,
}
}
}
4 changes: 4 additions & 0 deletions src/agent/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::emulation_core::mips::gp_registers::GpRegisters;
use crate::emulation_core::mips::memory::Memory;
use crate::emulation_core::riscv::datapath::{RiscDatapathState, RiscStage};
use crate::emulation_core::riscv::registers::RiscGpRegisters;
use crate::emulation_core::stack::Stack;
use crate::emulation_core::{architectures::AvailableDatapaths, mips::datapath::Stage};
use serde::{Deserialize, Serialize};

Expand Down Expand Up @@ -36,6 +37,7 @@ pub enum MipsStateUpdate {
UpdateCoprocessorRegisters(FpRegisters),
UpdateMemory(Memory),
UpdateStage(Stage),
UpdateStack(Stack),
}

#[derive(Clone, Debug, Serialize, Deserialize)]
Expand All @@ -44,6 +46,7 @@ pub enum RiscStateUpdate {
UpdateRegisters(RiscGpRegisters),
UpdateMemory(Memory),
UpdateStage(RiscStage),
UpdateStack(Stack),
}

/// Information about the effects of system calls sent from the worker thread to the UI thread.
Expand All @@ -52,6 +55,7 @@ pub enum SystemUpdate {
UpdateMessages(Vec<String>),
UpdateExecuting(bool),
UpdateInitialized(bool),
UpdateSpeed(u32),
}

/// Enum containing all types of updates sent from the worker thread to the UI thread.
Expand Down
Loading

0 comments on commit c0fa1ed

Please sign in to comment.