Skip to content

Commit

Permalink
gcc effort
Browse files Browse the repository at this point in the history
  • Loading branch information
bieganski committed Sep 28, 2023
1 parent 9f5448f commit 40e8fba
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
asm.o
asm.S
*.vcd
xpack-riscv-none-embed-gcc-*
riscv-none-*
*.swp
__pycache__/
**/__pycache__/
Expand Down
20 changes: 17 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
DOCKER_IMAGE_NAME := docker.io/library/mtkcpu:1.0.0

lint:
poetry run black .
poetry run isort .
Expand Down Expand Up @@ -26,11 +28,23 @@ build-docker:
bash ./build_docker_image.sh

test-docker:
docker run docker.io/library/mtkcpu:1.0.0 poetry run mtkcpu tests cpu
docker run $(DOCKER_IMAGE_NAME) poetry run mtkcpu tests cpu

run-docker-it:
docker run -it docker.io/library/mtkcpu:1.0.0 bash
docker run -it $(DOCKER_IMAGE_NAME) bash

fetch-gcc: export id := $(shell docker create $(DOCKER_IMAGE_NAME))
fetch-gcc: export temp := $(shell mktemp -p .)
fetch-gcc:
rm -r riscv-none-elf-gcc
docker cp $(id):/root/.local/xPacks/@xpack-dev-tools/riscv-none-elf-gcc/ - > $(temp)
docker rm -v $(id)
tar xvf $(temp)
rm $(temp)
chmod -R +wx riscv-none-elf-gcc
@echo "== GCC downloaded from docker to host - run the following command to have it in your PATH:"
@echo 'export PATH=$$PATH:$(shell realpath riscv-none-elf-gcc/13.2.0-1.2/.content/bin)'

test:
poetry run pytest -n 12

21 changes: 0 additions & 21 deletions install_toolchain.sh

This file was deleted.

18 changes: 6 additions & 12 deletions mtkcpu/utils/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def read_elf(elf_path, verbose=False):

if verbose:
import subprocess
p = subprocess.Popen(["riscv-none-embed-objdump", "--disassembler-options=no-aliases", "-M", "numeric", "-d", elf_path], stdout=subprocess.PIPE)
p = subprocess.Popen(["riscv-none-elf-objdump", "--disassembler-options=no-aliases", "-M", "numeric", "-d", elf_path], stdout=subprocess.PIPE)
out, _ = p.communicate()
out = str(out.decode("ascii"))
raise ValueError(out)
Expand All @@ -107,24 +107,18 @@ def read_elf(elf_path, verbose=False):
# TODO pass additional param
def compile_source(source_raw : str, output_elf : Path, mem_size_kb: int):

COMPILERS = ["riscv-none-embed-gcc", "riscv-none-elf-gcc"]
for candicate in COMPILERS:
if which(candicate) is not None:
break
else:
raise ValueError(f"Could not find a suitable compiler! Seeked for {COMPILERS}")

compiler = candicate
compiler = "riscv-none-elf-gcc"

if which(compiler) is not None:
raise ValueError(f"Could not find {compiler}")

with NamedTemporaryFile(suffix=".S", delete=False, mode="w+") as asm_file:
assert asm_file.write(source_raw)
with NamedTemporaryFile(suffix=".ld", delete=False) as ld_file:
from mtkcpu.utils.linker import write_linker_script
write_linker_script(Path(ld_file.name), mem_addr=CODE_START_ADDR, mem_size_kb=mem_size_kb)

march = "rv32i"
if "elf" in compiler:
march += "_zicsr"
march = "rv32i _zicsr"

cmd = [compiler, f"-march={march}", "-mabi=ilp32", "-nostartfiles", f"-T{ld_file.name}", asm_file.name, "-o", output_elf]
logging.critical(" ".join(cmd))
Expand Down
2 changes: 1 addition & 1 deletion run_jtag_test.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

pkill -f riscv-none-embed-gdb
pkill -f riscv-none-elf-gdb
pkill --signal SIGUSR1 -f openocd

# poetry run pytest mtkcpu/tests/test_jtag.py --verbose --capture=no
Expand Down

0 comments on commit 40e8fba

Please sign in to comment.