From: Luke Kenneth Casson Leighton Date: Sat, 4 Apr 2020 19:39:54 +0000 (+0100) Subject: move GPR and Mem to isa caller X-Git-Tag: div_pipeline~1524 X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=c12a633ca9d67d2b470721d6b1c8e786a71b48d9;p=soc.git move GPR and Mem to isa caller --- diff --git a/src/soc/decoder/isa/caller.py b/src/soc/decoder/isa/caller.py index 89917d9c..b46310be 100644 --- a/src/soc/decoder/isa/caller.py +++ b/src/soc/decoder/isa/caller.py @@ -1,16 +1,71 @@ from functools import wraps +from soc.decoder.selectable_int import SelectableInt, selectconcat + + +class Mem: + + def __init__(self): + self.mem = [] + for i in range(128): + self.mem.append(i) + + def __call__(self, addr, sz): + res = [] + for s in range(sz): # TODO: big/little-end + res.append(SelectableInt(self.mem[addr.value + s], 8)) + print ("memread", addr, sz, res) + return selectconcat(*res) + + def memassign(self, addr, sz, val): + print ("memassign", addr, sz, val) + for s in range(sz): + byte = (val.value) >> (s*8) & 0xff # TODO: big/little-end + self.mem[addr.value + s] = byte + + +class GPR(dict): + def __init__(self, sd, regfile): + dict.__init__(self) + self.sd = sd + for i in range(32): + self[i] = SelectableInt(regfile[i], 64) + + def __call__(self, ridx): + return self[ridx] + + def set_form(self, form): + self.form = form + + def getz(self, rnum): + #rnum = rnum.value # only SelectableInt allowed + print("GPR getzero", rnum) + if rnum == 0: + return SelectableInt(0, 64) + return self[rnum] + + def _get_regnum(self, attr): + getform = self.sd.sigforms[self.form] + rnum = getattr(getform, attr) + return rnum + + def ___getitem__(self, attr): + print("GPR getitem", attr) + rnum = self._get_regnum(attr) + return self.regfile[rnum] + class ISACaller: def __init__(self): - self.gpr = {} # TODO - self.mem = {} # TODO + self.gpr = GPR() + self.mem = Mem() self.namespace = {'GPR': self.gpr, 'MEM': self.mem, 'memassign': self.memassign } def memassign(self, ea, sz, val): - pass + self.mem.memassign(ea, sz, val) + def inject(context): """ Decorator factory. """ diff --git a/src/soc/decoder/power_pseudo.py b/src/soc/decoder/power_pseudo.py index 37aa56fc..fc3f5410 100644 --- a/src/soc/decoder/power_pseudo.py +++ b/src/soc/decoder/power_pseudo.py @@ -21,6 +21,8 @@ from nmigen import Module, Signal from soc.decoder.pseudo.parser import GardenSnakeCompiler from soc.decoder.selectable_int import SelectableInt, selectconcat +from soc.decoder.isa.caller import GPR, Mem + ####### Test code ####### @@ -157,58 +159,6 @@ def tolist(num): def get_reg_hex(reg): return hex(reg.value) -class Mem: - - def __init__(self): - self.mem = [] - for i in range(128): - self.mem.append(i) - - def __call__(self, addr, sz): - res = [] - for s in range(sz): # TODO: big/little-end - res.append(SelectableInt(self.mem[addr.value + s], 8)) - print ("memread", addr, sz, res) - return selectconcat(*res) - - def memassign(self, addr, sz, val): - print ("memassign", addr, sz, val) - for s in range(sz): - byte = (val.value) >> (s*8) & 0xff # TODO: big/little-end - self.mem[addr.value + s] = byte - - -class GPR(dict): - def __init__(self, sd, regfile): - dict.__init__(self) - self.sd = sd - for i in range(32): - self[i] = SelectableInt(regfile[i], 64) - - def __call__(self, ridx): - return self[ridx] - - def set_form(self, form): - self.form = form - - def getz(self, rnum): - #rnum = rnum.value # only SelectableInt allowed - print("GPR getzero", rnum) - if rnum == 0: - return SelectableInt(0, 64) - return self[rnum] - - def _get_regnum(self, attr): - getform = self.sd.sigforms[self.form] - rnum = getattr(getform, attr) - return rnum - - def ___getitem__(self, attr): - print("GPR getitem", attr) - rnum = self._get_regnum(attr) - return self.regfile[rnum] - - def convert_to_python(pcode): gsc = GardenSnakeCompiler()