riscii

An emulator for the RISC II
Log | Files | Refs | LICENSE

commit e7aa518e36013753a72d3343b1b4c1c24840f6f6
parent 1b01ffcdd654ab25eb2da6f7a8eff5873ffb9b7f
Author: Ryan Jeffrey <ryan@ryanmj.xyz>
Date:   Tue,  7 Jun 2022 11:56:16 -0700

Register stub

Diffstat:
Asrc/register.rs | 65+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 65 insertions(+), 0 deletions(-)

diff --git a/src/register.rs b/src/register.rs @@ -0,0 +1,65 @@ +/// RISC II register system. +/// (C) Ryan Jeffrey <ryan@ryanmj.xyz>, 2022 +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU Affero General Public License as published by +// the Free Software Foundation, either version 3 of the License, or (at +// your option) any later version. + +// This program is distributed in the hope that it will be useful, but +// WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// General Public License for more details. + +// You should have received a copy of the GNU Affero General Public License +// along with this program. If not, see <https://www.gnu.org/licenses/>. + +/// The number of register windows the RISCII supports. +const NUM_WINDOWS: usize = 6; +/// The number of local registers per window. +const NUM_LOCALS: usize = 10; +/// The number of registers shared with the previous register window (input arguments). +const NUM_SHARED_PREV: usize = 6; +/// The number of registers shared with the next register window (output arguments). +const NUM_SHARED_NEXT: usize = 6; +/// The number of registers per window. +const WINDOW_SIZE: usize = NUM_LOCALS + NUM_SHARED_PREV + NUM_SHARED_NEXT; +/// Number of global registers. +const NUM_GLOBALS: usize = 10; + +// Struct definitions. + +/// A RISC II 32bit register. +struct Register(u32); + +/// The CPU's register state. +struct State { + /// Current window pointer, index of the currently active window. + cwp: Register, + /// Saved window pointer, the index of the youngest window saved in memory. + swp: Register, + /// Global registers. + globals: [Register; NUM_GLOBALS], + /// Register window stack. + locals: [Register; NUM_WINDOWS * (NUM_LOCALS + NUM_SHARED_NEXT)], +} + +// Struct implementations. + +impl State { + pub fn new() -> State { + State { + cwp: 0, + swp: 0, + globals: [0; NUM_GLOBALS], + locals: [0; NUM_WINDOWS * (NUM_LOCALS + NUM_SHARED_NEXT)], + } + } + + fn inc_cwp(&self) { + self.cwp += 1; + while self.cwp >= self.swp { + // TODO save the top window into memory. + self.swp += 1; + } + } +}