1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
|
use crate::{
consts::{Addr, RegId, RegValue},
mem::MemConfig,
};
// placeholder - change when exception system is in place
pub(crate) type Exception = ();
pub(crate) enum InstructionResult {
Normal,
Exception(Exception),
Pause,
}
pub struct Core {
x_regs: [RegValue; 32],
pc: Addr,
mem: MemConfig,
}
impl Core {
pub fn new(mem: MemConfig) -> Self {
Self {
x_regs: [0; 32],
pc: 0,
mem,
}
}
pub fn reset(&mut self, pc: Addr) {
self.pc = pc;
}
fn reg_read(&self, id: RegId) -> RegValue {
self.x_regs[id as usize]
}
fn reg_write(&mut self, id: RegId, value: RegValue) {
if id == 0 {
return;
}
self.x_regs[id as usize] = value;
}
}
|