def do(self, src, expected_output, lang='c3'): base_filename = make_filename(self.id()) bsp_c3 = relpath('..', 'examples', 'or1k', 'bsp.c3') crt0 = relpath('..', 'examples', 'or1k', 'crt0.asm') mmap = relpath('..', 'examples', 'or1k', 'layout.mmp') build(base_filename, src, bsp_c3, crt0, self.march, self.opt_level, mmap, lang=lang, bin_format='bin', code_image='flash') binfile = base_filename + '.bin' # Create a uboot application file: with open(binfile, 'rb') as f: bindata = f.read() img_filename = base_filename + '.img' with open(img_filename, 'wb') as f: uboot_image.write_uboot_image( f, bindata, arch=uboot_image.Architecture.OPENRISC) if has_qemu(): output = qemu([ 'qemu-system-or1k', '-nographic', '-M', 'or1k-sim', '-m', '16', '-kernel', img_filename ]) self.assertEqual(expected_output, output)
def do(self, src, expected_output, lang="c3"): # Construct binary file from snippet: startercode = io.StringIO(self.startercode) base_filename = make_filename(self.id()) bsp_c3 = io.StringIO(self.bsp_c3_src) build( base_filename, src, bsp_c3, startercode, self.march, self.opt_level, io.StringIO(self.arch_mmap), lang=lang, elf_format="elf", ) base_filename = make_filename(self.id()) elf_filename = base_filename + ".elf" if has_qemu(): output = qemu([ "qemu-system-riscv32", "-nographic", "-M", "sifive_u", "-bios", elf_filename, ]) self.assertEqual(expected_output, output)
def do(self, src, expected_output, lang="c3"): base_filename = make_filename(self.id()) bsp_c3 = relpath("..", "examples", "microblaze", "bsp.c3") crt0 = relpath("..", "examples", "microblaze", "crt0.asm") mmap = relpath("..", "examples", "microblaze", "layout.mmp") build( base_filename, src, bsp_c3, crt0, self.march, self.opt_level, mmap, lang=lang, bin_format="bin", code_image="flash", ) bin_filename = base_filename + ".bin" if has_qemu(): output = qemu([ "qemu-system-microblaze", "-nographic", "-kernel", bin_filename, ]) self.assertEqual(expected_output, output)
def do(self, src, expected_output, lang="c3"): base_filename = make_filename(self.id()) bsp_c3 = relpath("..", "examples", "xtensa", "bsp.c3") crt0 = relpath("..", "examples", "xtensa", "glue.asm") mmap = relpath("..", "examples", "xtensa", "layout.mmp") build( base_filename, src, bsp_c3, crt0, self.march, self.opt_level, mmap, lang=lang, bin_format="elf", code_image="flash", ) elf_filename = base_filename + ".elf" if has_qemu(): output = qemu([ "qemu-system-xtensa", "-nographic", "-M", "lx60", "-m", "16", "-kernel", elf_filename, ]) self.assertEqual(expected_output, output)
def do(self, src, expected_output, lang='c3'): base_filename = make_filename(self.id()) bsp_c3 = relpath('..', 'examples', 'stm8', 'bsp.c3') crt0 = relpath('..', 'examples', 'stm8', 'start.asm') mmap = relpath('..', 'examples', 'avr', 'avr.mmap') build(base_filename, src, bsp_c3, crt0, self.march, self.opt_level, mmap, lang=lang, bin_format='hex', code_image='flash')
def do(self, src, expected_output, lang="c3"): base_filename = make_filename(self.id()) bsp_c3 = relpath("..", "examples", "msp430", "bsp.c3") startercode = io.StringIO(self.startercode) obj = build( base_filename, src, bsp_c3, startercode, "msp430", self.opt_level, io.StringIO(self.arch_mmap), lang=lang, ) flash = obj.get_image("flash") ivect = obj.get_image("vector16") rom = merge_memories(flash, ivect, "rom") rom_data = rom.data assert len(rom_data) % 2 == 0 with open(base_filename + ".bin", "wb") as f: f.write(rom_data) mem_file = base_filename + ".mem" with open(mem_file, "w") as f: for i in range(len(rom_data) // 2): w = rom_data[2 * i:2 * i + 2] print("%02x%02x" % (w[1], w[0]), file=f) if has_iverilog() and do_iverilog(): res = run_msp430(mem_file) self.assertEqual(expected_output, res)
def do(self, src, expected_output, lang='c3'): base_filename = make_filename(self.id()) bsp_c3 = relpath('..', 'examples', 'msp430', 'bsp.c3') startercode = io.StringIO(self.startercode) obj = build(base_filename, src, bsp_c3, startercode, "msp430", self.opt_level, io.StringIO(self.arch_mmap), lang=lang) flash = obj.get_image('flash') ivect = obj.get_image('vector16') rom = merge_memories(flash, ivect, 'rom') rom_data = rom.data assert len(rom_data) % 2 == 0 with open(base_filename + '.bin', 'wb') as f: f.write(rom_data) mem_file = base_filename + '.mem' with open(mem_file, 'w') as f: for i in range(len(rom_data) // 2): w = rom_data[2 * i:2 * i + 2] print('%02x%02x' % (w[1], w[0]), file=f) if has_iverilog() and do_iverilog(): res = run_msp430(mem_file) self.assertEqual(expected_output, res)
def do(self, src, expected_output, lang="c3"): # Construct binary file from snippet: bsp_c3 = relpath("..", "examples", "realview-pb-a8", "arch.c3") startercode = io.StringIO(self.startercode) base_filename = make_filename(self.id()) obj = build( base_filename, src, bsp_c3, startercode, self.march, self.opt_level, io.StringIO(self.arch_mmap), lang=lang, bin_format="bin", ) sample_filename = base_filename + ".bin" # Run bin file in emulator: if has_qemu(): res = qemu([ "qemu-system-arm", "--machine", "realview-pb-a8", "-m", "16M", "-nographic", "-kernel", sample_filename, ]) self.assertEqual(expected_output, res)
def do(self, src, expected_output, lang="c3"): base_filename = make_filename(self.id()) bsp_c3 = relpath("..", "examples", "stm8", "bsp.c3") crt0 = relpath("..", "examples", "stm8", "start.asm") mmap = relpath("..", "examples", "avr", "avr.mmap") build( base_filename, src, bsp_c3, crt0, self.march, self.opt_level, mmap, lang=lang, bin_format="hex", code_image="flash", )
def do(self, src, expected_output, lang="c3"): base_filename = make_filename(self.id()) bsp_c3 = relpath("..", "examples", "or1k", "bsp.c3") crt0 = relpath("..", "examples", "or1k", "crt0.asm") mmap = relpath("..", "examples", "or1k", "layout.mmp") build( base_filename, src, bsp_c3, crt0, self.march, self.opt_level, mmap, lang=lang, bin_format="bin", code_image="flash", ) binfile = base_filename + ".bin" # Create a uboot application file: with open(binfile, "rb") as f: bindata = f.read() img_filename = base_filename + ".img" with open(img_filename, "wb") as f: uboot_image.write_uboot_image( f, bindata, arch=uboot_image.Architecture.OPENRISC) qemu_cmd = [ "qemu-system-or1k", "-nographic", "-M", "or1k-sim", "-m", "16", "-kernel", img_filename, ] create_qemu_launch_script(base_filename + ".sh", qemu_cmd) if has_qemu(): output = qemu(qemu_cmd) self.assertEqual(expected_output, output)
def do(self, src, expected_output, lang='c3'): base_filename = make_filename(self.id()) bsp_c3 = relpath('..', 'examples', 'avr', 'bsp.c3') crt0 = relpath('..', 'examples', 'avr', 'glue.asm') mmap = relpath('..', 'examples', 'avr', 'avr.mmap') build(base_filename, src, bsp_c3, crt0, self.march, self.opt_level, mmap, lang=lang, bin_format='hex', code_image='flash') hexfile = base_filename + '.hex' print(hexfile) if has_avr_emulator() and do_iverilog(): res = run_avr(hexfile) self.assertEqual(expected_output, res)
def do(self, src, expected_output, lang="c3"): base_filename = make_filename(self.id()) bsp_c3 = relpath("..", "examples", "avr", "bsp.c3") crt0 = relpath("..", "examples", "avr", "glue.asm") mmap = relpath("..", "examples", "avr", "avr.mmap") build( base_filename, src, bsp_c3, crt0, self.march, self.opt_level, mmap, lang=lang, bin_format="hex", code_image="flash", ) hexfile = base_filename + ".hex" print(hexfile) if has_avr_emulator() and do_iverilog(): res = run_avr(hexfile) self.assertEqual(expected_output, res)
def do(self, src, expected_output, lang='c3'): base_filename = make_filename(self.id()) bsp_c3 = relpath('..', 'examples', 'microblaze', 'bsp.c3') crt0 = relpath('..', 'examples', 'microblaze', 'crt0.asm') mmap = relpath('..', 'examples', 'microblaze', 'layout.mmp') build(base_filename, src, bsp_c3, crt0, self.march, self.opt_level, mmap, lang=lang, bin_format='bin', code_image='flash') bin_filename = base_filename + '.bin' if has_qemu(): output = qemu([ 'qemu-system-microblaze', '-nographic', '-kernel', bin_filename ]) self.assertEqual(expected_output, output)
def do(self, src, expected_output, lang='c3'): base_filename = make_filename(self.id()) bsp_c3 = relpath('..', 'examples', 'xtensa', 'bsp.c3') crt0 = relpath('..', 'examples', 'xtensa', 'glue.asm') mmap = relpath('..', 'examples', 'xtensa', 'layout.mmp') build(base_filename, src, bsp_c3, crt0, self.march, self.opt_level, mmap, lang=lang, bin_format='elf', code_image='flash') elf_filename = base_filename + '.elf' if has_qemu(): output = qemu([ 'qemu-system-xtensa', '-nographic', '-M', 'lx60', '-m', '16', '-kernel', elf_filename ]) self.assertEqual(expected_output, output)
def do(self, src, expected_output, lang="c3"): bsp_c3 = io.StringIO(BSP_C3_SRC) base_filename = make_filename(self.id()) build( base_filename, src, bsp_c3, io.StringIO(STARTERCODE), self.march, self.opt_level, io.StringIO(ARCH_MMAP), lang=lang, bin_format="elf", ) exe = base_filename + ".elf" if has_linux(): if hasattr(subprocess, "TimeoutExpired"): res = subprocess.check_output(exe, timeout=10) else: res = subprocess.check_output(exe) res = res.decode("ascii") self.assertEqual(expected_output, res)
def do(self, src, expected_output, lang='c3'): base_filename = make_filename(self.id()) bsp_c3 = relpath('..', 'examples', 'xtensa', 'bsp.c3') crt0 = relpath('..', 'examples', 'xtensa', 'glue.asm') mmap = relpath('..', 'examples', 'xtensa', 'layout.mmp') build(base_filename, src, bsp_c3, crt0, self.march, self.opt_level, mmap, lang=lang, bin_format='bin', code_image='flash') binfile = base_filename + '.bin' img_filename = base_filename + '.img' self.make_image(binfile, img_filename) if has_qemu(): output = qemu([ 'qemu-system-xtensa', '-nographic', '-M', 'lx60', '-m', '16', '-drive', 'if=pflash,format=raw,file={}'.format(img_filename) ]) self.assertEqual(expected_output, output)
def do(self, src, expected_output, lang="c3"): # Construct binary file from snippet: startercode = io.StringIO(self.startercode) base_filename = make_filename(self.id()) bsp_c3 = io.StringIO(self.bsp_c3_src) obj = build( base_filename, src, bsp_c3, startercode, self.march, self.opt_level, io.StringIO(self.arch_mmap), lang=lang, bin_format="bin", elf_format="elf", code_image="flash", ) flash = obj.get_image("flash") data = obj.get_image("ram") rom = merge_memories(flash, data, "rom") rom_data = rom.data filewordsize = 0x8000 datawordlen = len(rom_data) // 4 mem_file = base_filename + ".mem" with open(mem_file, "w") as f: for i in range(filewordsize): if i < datawordlen: w = rom_data[4 * i:4 * i + 4] print("%02x%02x%02x%02x" % (w[3], w[2], w[1], w[0]), file=f) else: print("00000000", file=f) f.close() if has_iverilog() and do_iverilog(): res = run_picorv32(mem_file) self.assertEqual(expected_output, res)
def do(self, src, expected_output, lang="c3"): # Construct binary file from snippet: startercode = io.StringIO(self.startercode) base_filename = make_filename(self.id()) bsp_c3 = io.StringIO(self.bsp_c3_src) obj = build(base_filename, src, bsp_c3, startercode, self.march, self.opt_level, io.StringIO(self.arch_mmap), lang=lang, bin_format='bin', elf_format='elf', code_image='flash') flash = obj.get_image('flash') data = obj.get_image('ram') rom = merge_memories(flash, data, 'rom') rom_data = rom.data filewordsize = 0x8000 datawordlen = len(rom_data) // 4 mem_file = base_filename + '.mem' with open(mem_file, 'w') as f: for i in range(filewordsize): if (i < datawordlen): w = rom_data[4 * i:4 * i + 4] print('%02x%02x%02x%02x' % (w[3], w[2], w[1], w[0]), file=f) else: print('00000000', file=f) f.close() if has_iverilog() and do_iverilog(): res = run_picorv32(mem_file) self.assertEqual(expected_output, res)
def do(self, src, expected_output, lang='c3'): bsp_c3 = io.StringIO(self.bsp_c3_src) startercode = io.StringIO(self.startercode) base_filename = make_filename(self.id()) obj = build(base_filename, src, bsp_c3, startercode, self.march, self.opt_level, io.StringIO(self.arch_mmap), lang=lang, bin_format='elf') exe = base_filename + '.elf' if has_linux(): if hasattr(subprocess, 'TimeoutExpired'): res = subprocess.check_output(exe, timeout=10) else: res = subprocess.check_output(exe) res = res.decode('ascii') self.assertEqual(expected_output, res)
def do(self, src, expected_output, lang="c3"): # Construct binary file from snippet: bsp_c3 = relpath('..', 'examples', 'realview-pb-a8', 'arch.c3') startercode = io.StringIO(self.startercode) base_filename = make_filename(self.id()) obj = build(base_filename, src, bsp_c3, startercode, self.march, self.opt_level, io.StringIO(self.arch_mmap), lang=lang, bin_format='bin') sample_filename = base_filename + '.bin' # Run bin file in emulator: if has_qemu(): res = qemu([ 'qemu-system-arm', '--machine', 'realview-pb-a8', '-m', '16M', '-nographic', '-kernel', sample_filename ]) self.assertEqual(expected_output, res)