class Boneless_v3(Elaboratable): def __init__(self, platform, asm_file="blink.asm"): self.memory = Memory(width=16, depth=2048) # max of 8*1024 on the 8k self.platform = platform self.asm_file = asm_file self.asm_text = open(self.asm_file).read() self.assem = Assembler() self.assem.parse_text(self.asm_text) self.prog = self.assem.assemble() print(self.prog) for i, j in enumerate(self.assem.disassemble(self.prog)): print("{:04X}".format(i), j) self.memory.init = self.prog def elaborate(self, platform): m = Module() # Add the platform clock clk16 = platform.request("clk16", 0) m.domains.sync = ClockDomain() m.d.comb += ClockSignal().eq(clk16.i) # Create the processor core = CoreFSM(alsru_cls=ALSRU_4LUT, memory=self.memory, reset_pc=8) m.submodules.core = core leds = platform.blinky() with m.If(core.o_bus_addr == 0): with m.If(core.o_ext_we == 1): m.d.sync += leds.eq(core.o_ext_data) return m
def __init__(self, platform, asm_file="blink.asm"): self.memory = Memory(width=16, depth=2048) # max of 8*1024 on the 8k self.platform = platform self.asm_file = asm_file self.asm_text = open(self.asm_file).read() self.assem = Assembler() self.assem.parse_text(self.asm_text) self.prog = self.assem.assemble() print(self.prog) for i, j in enumerate(self.assem.disassemble(self.prog)): print("{:04X}".format(i), j) self.memory.init = self.prog
def load(self, asm_file=""): self.assembler = Assembler() if asm_file != "": self.asm_file = asm_file # assemble the code txt = open(self.asm_file).read() self.assembler.parse(headers) self.assembler.parse(txt) self.out = self.assembler.assemble() # create memory and load the code self.mem = Memory(len(self.out), self) for i, j in enumerate(self.out): self.mem[i] = j self.pc = self.pc_reset
def prepare(self): # TODO , map registers bits and code fragments from gizmos # Prepare all the gizmos and map their addresses self.periph.prepare() # generate asm header address list # Code if self.asm_file is not None: header = self.periph.asm_header() #print(header) asm = Assembler() self.asm = asm txt = open(self.asm_file).read() asm.parse(header) asm.parse(txt) code = asm.assemble() self.code = code # Object list if self.debug: print("len :", len(self.code)) for i, j in enumerate(asm.disassemble(self.code)): print("{:04X}".format(i), j) else: print("FIRMWARE ", self.fw) io_map = self.periph.io_map() self.io_map = io_map l = firmware.show() if self.fw in l: f = firmware.available[self.fw](io_map) else: raise ValueError("Firmware does not exist") #f.show() self.fw = f self.code = f.assemble() self.memory.init = self.code self.devices = [] self._prepared = True
w.req("insp") w.req("xtp") w.req("tos") w.req("temp") return [ header("test"), header("hello"), header("fnord"), primitive("export", [ADDI(R0, R0, 2)]), variable("tib"), next(), # docol('fnord',[L('wot')]), # glob('state',0), # glob('>in',0), # glob('#tib',0), # glob('base',10), # glob('dp',0), # glob('stack',0,32), # glob('rstack',0,32) ] if __name__ == "__main__": bl = Forth() code = bl.code() pprint.pprint(code) asm = Assembler() asm.parse(code) bin = asm.assemble() print(bin)
def fw(): a = Assembler() f = firmware() print(f) a.parse(f) return a.assemble()
def boneload_fw(user_flash=0, uart_addr=0, spi_addr=16): a = Assembler() a.parse(_bfw_main(user_flash, uart_addr, spi_addr)) return a.assemble()
class Simulator: def __init__(self, size=200, reset=8, window=0, asm_file="../asm/echo.asm"): self.asm_file = asm_file self.size = size self.pc_reset = reset self.window_reset = window self.window = window self.pc = reset self.counter = 0 # flags self.z = 0 self.s = 0 self.c = 0 self.v = 0 self.has_exti = False self.exti_val = 0 # current instruction self.current = None self.debug = True self.load(asm_file) # external interface self.ext = External(20) # TODO bind gizmos to these values self.ext.mem[2] = on() def load(self, asm_file=""): self.assembler = Assembler() if asm_file != "": self.asm_file = asm_file # assemble the code txt = open(self.asm_file).read() self.assembler.parse(headers) self.assembler.parse(txt) self.out = self.assembler.assemble() # create memory and load the code self.mem = Memory(len(self.out), self) for i, j in enumerate(self.out): self.mem[i] = j self.pc = self.pc_reset def reset(self): self.pc = self.pc_reset self.window = self.window_reset def set_pc_off(self, pos): print("set pc", self.pc, pos) self.pc = self.pc + pos def set_pc_abs(self, pos): self.pc = pos def get_reg(self, pos): assert pos >= 0 & pos < 8 return self.mem[self.window + pos] def set_reg(self, pos, value): assert pos >= 0 & pos < 8 self.mem[self.window + pos] = value def step(self): val = self.mem[self.pc] # if it is an int , convert to an instruction if isinstance(val, int): instr = self.assembler.disassemble([val])[0] cls_name = instr.__class__.__name__ if cls_name in sim_dict: sim_instr = sim_dict[cls_name](instr, self) self.mem[self.pc] = sim_instr else: print(self.pc, "|", self.mem[0:8], ":", instr, "-", val, "|") print(cls_name, " does not exist") val = self.mem[self.pc] self.current = val if self.debug: print(self.pc, self.w, self.current, self.fl) if isinstance(val, SimInstr): val.call() self.pc += 1 self.counter += 1 @property def R0(self): pass @property def w(self): return self.mem[self.window : self.window + 8] @property def fl(self): return [self.z, self.c] def run(self, count=1000000): for i in range(count): self.step()
from boneless.arch.asm import Assembler from boneless.arch import opcode, mc, instr a = Assembler() a.parse(open("echo.asm").read()) print("---INPUT---") print(a.input) d = a.assemble() print("---MACHINE CODE---") print(d) e = a.disassemble(d) print("---DISASSEMBLE---") print(e)