#!/usr/bin/env ruby require 'open3' require 'fileutils' require 'pathname' TMP = Pathname.new 'build' CROSS_GCC = '../riscv32-ilp32d--glibc/bin/riscv32-linux-gcc' SYSROOT = '../riscv32-ilp32d--glibc/riscv32-buildroot-linux-gnu/sysroot' FileUtils.rm_rf TMP FileUtils.mkdir_p TMP FileUtils.cp 'asm-boot.s', TMP def stage(source_elna, stage_name, output) boot_exe = (TMP + stage_name).to_path stage_path = TMP + "#{stage_name}.s" system CROSS_GCC, '-nostdlib', '-o', boot_exe, stage_path.to_path, exception: true Open3.popen2 'qemu-riscv32', '-L', SYSROOT, boot_exe do |qemu_in, qemu_out| qemu_in.write source_elna qemu_in.close IO.copy_stream qemu_out, output qemu_out.close end end source_elna = File.read 'source.elna' next_stage = TMP + 'goto-boot.s' File.open next_stage, 'w' do |output| stage source_elna, 'asm-boot', output end stage(source_elna, 'goto-boot', $stdout)