summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEkaitz Zarraga <ekaitz@elenq.tech>2021-05-25 18:37:40 +0200
committerEkaitz Zarraga <ekaitz@elenq.tech>2021-05-25 18:37:40 +0200
commitd4426ef4435be0b033af16e60e74e73ce700a6a0 (patch)
treea08f255c38a116804b00843e94f29a759fed72d2
parent423bee4496736d47d939b361fcd2035b7a66feac (diff)
Fix instruction set bugs
-rw-r--r--pysc-v/InstructionSets/RV32I.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/pysc-v/InstructionSets/RV32I.py b/pysc-v/InstructionSets/RV32I.py
index 8e1c1b8..f2929f3 100644
--- a/pysc-v/InstructionSets/RV32I.py
+++ b/pysc-v/InstructionSets/RV32I.py
@@ -55,8 +55,8 @@ class S(Instruction):
imm_5_11 = (self.imm & 0xFE0)>>5
return c_uint32(
(imm_5_11 << 25) +\
- (self.rs2 << 20) +\
- (self.rs1 << 15) +\
+ (self.rs1 << 20) +\
+ (self.rs2 << 15) +\
(self.funct3 << 12) +\
(imm_0_4 << 7) +\
self.opcode
@@ -75,12 +75,12 @@ class B(Instruction):
# NOTE: The lowest bit of the imm is always 0 because instructions
# are at least 16 bits wide, so it's not used, that's why this
# instruction looks that weird
- imm_11 = (self.imm & 0b0100000000000)>>11
imm_12 = (self.imm & 0b1000000000000)>>12
- imm_1_4 = (self.imm & 0b0000000011110)>>1
+ imm_11 = (self.imm & 0b0100000000000)>>11
imm_5_10 = (self.imm & 0b0011111100000)>>5
+ imm_1_4 = (self.imm & 0b0000000011110)>>1
return c_uint32(
- (imm_12 << 30) +\
+ (imm_12 << 31) +\
(imm_5_10 << 25) +\
(self.rs2 << 20) +\
(self.rs1 << 15) +\
@@ -118,7 +118,7 @@ class J(Instruction):
# NOTE: Jumps are also weird
imm_20 = (self.imm & 0x100000)>>20
imm_12_19 = (self.imm & 0x0FF000)>>12
- imm_11 = (self.imm & 0x000800)>>8
+ imm_11 = (self.imm & 0x000800)>>11
imm_1_10 = (self.imm & 0x0007FE)>>1
return c_uint32(
(imm_20 << 31) +\