Fix RISCV_LD instructions
This commit is contained in:
parent
89cc9423bd
commit
1701e9b7d5
@ -179,27 +179,27 @@ impl Machine {
|
|||||||
RISCV_LD => {
|
RISCV_LD => {
|
||||||
match inst.funct3 {
|
match inst.funct3 {
|
||||||
RISCV_LD_LB => {
|
RISCV_LD_LB => {
|
||||||
machine.int_reg[inst.rd as usize] = Self::read_memory(machine, 1, (inst.rs1 as i16 + inst.imm12_I_signed) as usize) as i64;
|
machine.int_reg[inst.rd as usize] = Self::read_memory(machine, 1, (machine.int_reg[inst.rs1 as usize] + inst.imm12_I_signed as i64) as usize) as i64;
|
||||||
},
|
},
|
||||||
RISCV_LD_LH => {
|
RISCV_LD_LH => {
|
||||||
machine.int_reg[inst.rd as usize] = Self::read_memory(machine, 2, (inst.rs1 as i16 + inst.imm12_I_signed) as usize) as i64;
|
machine.int_reg[inst.rd as usize] = Self::read_memory(machine, 2, (machine.int_reg[inst.rs1 as usize] + inst.imm12_I_signed as i64) as usize) as i64;
|
||||||
},
|
},
|
||||||
RISCV_LD_LW => {
|
RISCV_LD_LW => {
|
||||||
machine.int_reg[inst.rd as usize] = Self::read_memory(machine, 4, (inst.rs1 as i16 + inst.imm12_I_signed) as usize) as i64;
|
machine.int_reg[inst.rd as usize] = Self::read_memory(machine, 4, (machine.int_reg[inst.rs1 as usize] + inst.imm12_I_signed as i64) as usize) as i64;
|
||||||
},
|
},
|
||||||
RISCV_LD_LD => {
|
RISCV_LD_LD => {
|
||||||
machine.int_reg[inst.rd as usize] = Self::read_memory(machine, 8, (inst.rs1 as i16 + inst.imm12_I_signed) as usize) as i64;
|
machine.int_reg[inst.rd as usize] = Self::read_memory(machine, 8, (machine.int_reg[inst.rs1 as usize] + inst.imm12_I_signed as i64) as usize) as i64;
|
||||||
},
|
},
|
||||||
|
|
||||||
// same thing three opration ?
|
// same thing three opration ?
|
||||||
RISCV_LD_LBU => {
|
RISCV_LD_LBU => {
|
||||||
machine.int_reg[inst.rd as usize] = Self::read_memory(machine, 1, (inst.rs1 as i16 + inst.imm12_I_signed) as usize) as i64;
|
machine.int_reg[inst.rd as usize] = Self::read_memory(machine, 1, (machine.int_reg[inst.rs1 as usize] + inst.imm12_I_signed as i64) as usize) as i64;
|
||||||
},
|
},
|
||||||
RISCV_LD_LHU => {
|
RISCV_LD_LHU => {
|
||||||
machine.int_reg[inst.rd as usize] = Self::read_memory(machine, 2, (inst.rs1 as i16 + inst.imm12_I_signed) as usize) as i64;
|
machine.int_reg[inst.rd as usize] = Self::read_memory(machine, 2, (machine.int_reg[inst.rs1 as usize] + inst.imm12_I_signed as i64) as usize) as i64;
|
||||||
},
|
},
|
||||||
RISCV_LD_LWU => {
|
RISCV_LD_LWU => {
|
||||||
machine.int_reg[inst.rd as usize] = Self::read_memory(machine, 4, (inst.rs1 as i16 + inst.imm12_I_signed) as usize) as i64;
|
machine.int_reg[inst.rd as usize] = Self::read_memory(machine, 4, (machine.int_reg[inst.rs1 as usize] + inst.imm12_I_signed as i64) as usize) as i64;
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
panic!("In LD switch case, this should never happen... Instr was {}", inst.value);
|
panic!("In LD switch case, this should never happen... Instr was {}", inst.value);
|
||||||
|
Loading…
Reference in New Issue
Block a user