Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Christina Yu
pyriscv
Commits
9b3329a1
Commit
9b3329a1
authored
Dec 01, 2021
by
Christina Yu
Browse files
lab6
parent
17e6ac1f
Changes
5
Hide whitespace changes
Inline
Side-by-side
__pycache__/regfile.cpython-37.pyc
View file @
9b3329a1
No preview for this file type
onestage_elf.py
View file @
9b3329a1
...
...
@@ -96,7 +96,7 @@ for t in itertools.count():
print
(
f
"
{
t
:
20
d
}
:"
,
display
())
PC
.
clock
(
pc_val
+
4
)
continue
print
(
instr
.
name
)
alu_fun
=
control
[
instr
.
name
].
ALU_fun
alu_str
=
control
[
instr
.
name
].
renums
[
"ALU_fun"
][
getattr
(
control
[
instr
.
name
],
"ALU_fun"
)]
op1_sel
=
control
[
instr
.
name
].
op1_sel
...
...
@@ -115,7 +115,7 @@ for t in itertools.count():
aluVal
=
ALU
(
op1
,
op2
,
alu_fun
)
aluValUnsigned
=
as_twos_comp
(
aluVal
)
#
if rs1Val == None: rs1Val = 0
if
rs1Val
==
None
:
rs1Val
=
0
jalr
=
lambda
i_imm
,
rs1Val
:
as_twos_comp
(
rs1Val
)
+
i_imm
branch
=
lambda
pc
,
imm
:
pc
+
imm
jump
=
lambda
pc
,
imm
:
pc
+
imm
...
...
riscv_isa/__pycache__/decoder.cpython-37.pyc
View file @
9b3329a1
No preview for this file type
riscv_isa/__pycache__/isa.cpython-37.pyc
View file @
9b3329a1
No preview for this file type
riscv_isa/isa.py
View file @
9b3329a1
...
...
@@ -20,30 +20,32 @@ def regNumToName(num):
instrDict
=
{
"I"
:
[
"lw"
,
"addi"
,
"slti"
,
"ori"
,
"andi"
,
"slli"
,
"sltiu"
,
"xori"
,
"srli"
,
"srai"
,
"ecall"
],
"srai"
,
"ecall"
,
"jalr"
,
"lbu"
,
"fence"
],
"R"
:
[
"sub"
,
"add"
,
"sll"
,
"slt"
,
"sltu"
,
"xor"
,
"srl"
,
"sra"
,
"or"
,
"and"
],
"U"
:
[
"lui"
],
"U"
:
[
"lui"
,
"auipc"
],
"S"
:
[
"sw"
],
"SB"
:
[
"beq"
,
"bne"
,
"blt"
,
"bge"
,
"bltu"
,
"bgeu"
],
"UJ"
:
[
"jal"
],
"UJ"
:
[
"jal"
]
}
"sltiu"
,
"xori"
,
"srli"
,
"srai"
opcodeDict
=
{
#opcode, funct3, funct7/imm, inst
"0000011"
:
{
"010"
:
"lw"
},
"1100111"
:{
"000"
:
"jalr"
},
"0000011"
:
{
"010"
:
"lw"
,
"100"
:
"lbu"
},
"0001111"
:
"fence"
,
"0100011"
:
{
"010"
:
"sw"
},
"1100011"
:
{
"000"
:
"beq"
,
"001"
:
"bne"
,
"100"
:
"blt"
,
"101"
:
"bge"
,
"110"
:
"bltu"
,
"111"
:
"bgeu"
},
"0010011"
:
{
"000"
:
"addi"
,
"010"
:
"slti"
,
"110"
:
"ori"
,
"111"
:
"andi"
,
"001"
:
"slli"
,
"011"
:
"sltiu"
,
"100"
:
"xori"
,
"101"
:
{
"0000000"
:
"srli"
,
"0100000"
:
"srai"
}},
"0110111"
:
"lui"
,
"0010111"
:
"auipc"
,
"1101111"
:
"jal"
,
"0110011"
:
{
"000"
:
{
"0100000"
:
"sub"
,
"0000000"
:
"add"
},
"001"
:
"sll"
,
"100"
:
"xor"
,
"110"
:
"or"
},
"1110011"
:
{
"000"
:
{
"000000000001"
:
"ebreak"
,
"000000000000"
:
"ecall"
}}}
"000000000000"
:
"ecall"
}
,
"001"
:
"CSRRW"
,
"010"
:
"CSRRS"
,
"011"
:
"CSRRC"
,
"101"
:
"CSRRW1"
,
"110"
:
"CSRRS1"
,
"111"
:
"CSRRC1"
}}
INST_TYPE_MASK
=
0b00000000000000000000000001111111
INST_FUNC3_MASK
=
0b00000000000000000111000000000000
...
...
@@ -84,9 +86,9 @@ class Instruction():
if
self
.
opcode
in
opcodeDict
:
if
self
.
opcode
==
"0110011"
:
return
"R"
if
(
self
.
opcode
==
"0010011"
)
or
(
self
.
opcode
==
"1110011"
)
or
(
self
.
opcode
==
"0000011"
):
if
(
self
.
opcode
==
"0010011"
)
or
(
self
.
opcode
==
"1110011"
)
or
(
self
.
opcode
==
"0000011"
)
or
(
self
.
opcode
==
"1100111"
)
or
(
self
.
opcode
==
"0001111"
)
:
return
"I"
if
self
.
opcode
==
"0110111"
:
if
self
.
opcode
==
"0110111"
or
self
.
opcode
==
"0010111"
:
return
"U"
if
self
.
opcode
==
"0100011"
:
return
"S"
...
...
@@ -101,6 +103,7 @@ class Instruction():
if
self
.
type
==
"I"
:
#selfç.funct7 = "0"
self
.
funct7
=
self
.
binVal
[:
7
]
#funct7 in binary
self
.
rdb
=
self
.
binVal
[
20
:
25
]
#rd reg in binary
self
.
rd
=
regNumToName
(
int
(
self
.
rdb
,
2
))
#rd reg
self
.
immb
=
self
.
binVal
[:
12
]
#immediate in binary
...
...
@@ -108,9 +111,26 @@ class Instruction():
self
.
rs1b
=
self
.
binVal
[
12
:
17
]
#reg rs1 in binary
self
.
rs1
=
regNumToName
(
int
(
self
.
rs1b
,
2
))
#reg rs1
self
.
funct3
=
self
.
binVal
[
17
:
20
]
#funct3 in binary
print
(
self
.
opcode
,
self
.
funct3
,
self
.
funct7
)
#self.imm = str(int(self.immb, 2)) #convert integer binary to string
if
(
self
.
opcode
==
"1110011"
)
and
(
self
.
funct3
==
"000"
):
if
self
.
opcode
==
"1100111"
:
return
"jalr"
elif
self
.
opcode
==
"1110011"
:
if
self
.
funct3
==
"000"
:
return
"ecall"
elif
self
.
funct3
==
"001"
:
return
"CSRRW"
elif
self
.
funct3
==
"010"
:
return
"CSRRS"
elif
self
.
funct3
==
"011"
:
return
"CSRRC"
elif
self
.
funct3
==
"101"
:
return
"CSRRW1"
elif
self
.
funct3
==
"110"
:
return
"CSRRS1"
elif
self
.
funct3
==
"111"
:
return
"CSRRC1"
elif
self
.
opcode
==
"0010011"
:
if
self
.
funct3
==
"010"
:
return
"slti"
...
...
@@ -137,6 +157,10 @@ class Instruction():
elif
self
.
opcode
==
"0000011"
:
if
self
.
funct3
==
"010"
:
return
"lw"
elif
self
.
funct3
==
"100"
:
return
"lbu"
elif
self
.
opcode
==
"0001111"
:
return
"fence"
elif
self
.
type
==
"R"
:
self
.
funct7
=
self
.
binVal
[:
7
]
#funct7 in binary
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment