Merge branch 'decode_print' of https://gitlab.istic.univ-rennes1.fr/simpleos/burritos into decode_print
This commit is contained in:
commit
a559bea039
@ -1,23 +1,42 @@
|
||||
use crate::decode::*;
|
||||
#[warn(unused_parens)]
|
||||
|
||||
use crate::decode::*;
|
||||
use crate::print::*;
|
||||
|
||||
pub struct Machine {
|
||||
pub _pc : u32,
|
||||
pub _int_reg : [u32 ; 32],
|
||||
pub _instructions : [u32 ; 100]
|
||||
pub pc : u32,
|
||||
pub int_reg : [u32 ; 32],
|
||||
pub instructions : [u32 ; 100]
|
||||
}
|
||||
|
||||
|
||||
impl Machine {
|
||||
|
||||
fn _init_machine() -> Machine {
|
||||
pub fn _init_machine() -> Machine {
|
||||
|
||||
Machine {
|
||||
_pc : 0,
|
||||
_instructions : [0 ; 100],
|
||||
_int_reg : [0 ; 32]
|
||||
pc : 0,
|
||||
instructions : [0 ; 100],
|
||||
int_reg : [0 ; 32]
|
||||
}
|
||||
}
|
||||
|
||||
pub fn oneInstruction(mut machine : Machine) -> Machine {
|
||||
if (machine.instructions.len() <= machine.pc as usize) {
|
||||
println!("ERROR : number max of instructions rushed");
|
||||
return machine;
|
||||
}
|
||||
let inst : Instruction = decode(machine.instructions[machine.pc as usize]);
|
||||
machine.pc += 1;
|
||||
match (inst.opcode) {
|
||||
RISCV_LUI => {
|
||||
machine.int_reg[inst.rd as usize] = inst.imm31_12;
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
machine
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -5,4 +5,8 @@ mod machine;
|
||||
fn main() {
|
||||
let instr = decode::decode(98);
|
||||
println!("{}", print::print(instr, 0));
|
||||
|
||||
let mut m = machine::Machine::_init_machine();
|
||||
m.instructions[0] = 0x37;
|
||||
machine::Machine::oneInstruction(m);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user