Commit 046daf63 authored by Christina Yu's avatar Christina Yu
Browse files

lab7

parent 54b91788
# filename: onestage_elf.py
import itertools
import sys
#from pydigital.memory import readmemh, MemorySegment
from pydigital.utils import sextend, as_twos_comp, twos_comp
from pydigital.elfloader import load_elf
from pydigital.register import Register
from pydigital.memory import Memory
#from riscv_isa.isa import regNumToName
from riscv_isa.decoder import control, enums
from riscv_isa import Instruction, decoder
from regfile import RegFile
......@@ -16,25 +14,15 @@ from branchpred import BHT, PHT
control = decoder.control
ALU = lambda op1, op2, alu_fun: alu(op1, op2, alu_fun)
#DM = Memory(MemorySegment(0xE0000, 0x4000)) #0xe0000, 0x10000
binFile = sys.argv[1]
elfMem, symbolTable = load_elf(binFile)
imem = elfMem
# the PC register
PC = Register()
RF = RegFile()
DM = Memory(elfMem)
# branch predictors
bht = BHT(8, 2, 4)
pht = PHT(4)
#RF.clock(2, 0xEFFFF, True)
#RF.regs[2] = 0xeffff #pointer
#RF.regs[0] = 0x00000
# construct a memory segment for instruction memory
# load the contents from the 32-bit fetch_test hex file (big endian)
# imem = readmemh(sys.argv[1], word_size = 4, byteorder = 'big')
def display():
print("--------------------------------------------------------------------------------")
if pc_val == None:
......@@ -242,10 +230,6 @@ for t in itertools.count():
break
###################################################################################
# check stopping conditions on NEXT instruction
# if PC.out() > 0x1100:
# print("STOP -- PC is large! Is something wrong?")
# break
if imem[PC.out()] == 0:
status = "TEST PASS" if RF.read(10) == 0 else "TEST FAIL"
print(status)
......@@ -255,7 +239,6 @@ for t in itertools.count():
exit(1)
if status == "TEST PASS":
exit(0)
#print("Done -- end of program.")
print("------------------------------< Final reg values >------------------------------")
RF.display()
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment