From d61ff5bf4b290f679790d817cf0529edf27baa91 Mon Sep 17 00:00:00 2001 From: mpernambuco Date: Wed, 12 Jul 2023 12:57:38 -0300 Subject: [PATCH 1/3] Align uarch-ram to 4 bytes. --- uarch/uarch-ram-entry.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/uarch/uarch-ram-entry.S b/uarch/uarch-ram-entry.S index 033dbc7a7..e1dfb36f8 100644 --- a/uarch/uarch-ram-entry.S +++ b/uarch/uarch-ram-entry.S @@ -18,7 +18,7 @@ #include .section .text.init; -.align 3; +.align 2; .global _start; _start: // Initialize stack From 6799c7c4bc843e76739280d9fda8ae8fe0b64e6c Mon Sep 17 00:00:00 2001 From: mpernambuco Date: Wed, 12 Jul 2023 12:58:45 -0300 Subject: [PATCH 2/3] Validate uarch instruction set after build --- uarch/.gitignore | 4 ++++ uarch/Makefile | 25 +++++++++++++++++++++---- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/uarch/.gitignore b/uarch/.gitignore index 2a673dc05..76e4808fb 100644 --- a/uarch/.gitignore +++ b/uarch/.gitignore @@ -5,3 +5,7 @@ *.bin .DS_Store .vscode +uarch-ram.elf.insn.txt +uarch-ram.elf.objdump + + diff --git a/uarch/Makefile b/uarch/Makefile index 2e24a66fb..645ede6ac 100644 --- a/uarch/Makefile +++ b/uarch/Makefile @@ -20,7 +20,11 @@ CXX := $(TOOLCHAIN_PREFIX)g++ OBJCOPY := $(TOOLCHAIN_PREFIX)objcopy OBJDUMP := $(TOOLCHAIN_PREFIX)objdump -# +# Instructions supported by the microarchitecture interpreter (rv64ui) +SUPPORTED_UARCH_INSN := add|addi|addiw|addw|and|andi|auipc|beq|bge|bgeu|blt|bltu|bne|ebreak|fence|jal|jalr|lb|lbu|ld|lh|$\ + lhu|lui|lw|lwu|or|ori|sb|sd|sh|sll|slli|slliw|sllw|slt|slti|sltiu|sltu|sra|srai|sraiw|sraw|srl|srli|srliw|srlw|sub|$\ + subw|sw|xor|xori + ifeq ($(relwithdebinfo),yes) OPTFLAGS+=-O2 -DNDEBUG -g else ifeq ($(release),yes) @@ -74,9 +78,9 @@ UARCH_OBJS = $(patsubst %.c,%.uarch_c.o,$(patsubst %.cpp,%.uarch_cpp.o,$(UARCH_S EMULATOR_OBJS = $(patsubst %.c,%.emulator_c.o,$(patsubst %.cpp,%.emulator_cpp.o,$(EMULATOR_SOURCES))) TARGETS=$(UARCH_OBJS) $(EMULATOR_OBJS) -.PHONY: all clean +.PHONY: all clean validate-instruction-set -all: $(TARGETS) uarch-ram.bin +all: $(TARGETS) uarch-ram.bin validate-instruction-set uarch-ram.bin: uarch-ram.elf $(OBJCOPY) -S -O binary $^ $@ @@ -100,5 +104,18 @@ uarch-ram-entry.o: uarch-ram-entry.S $(CC) -o $(@F).tmp -x c $(CFLAGS) -E $(^F) grep -v '^#' $@.tmp > $@ +uarch-ram.elf.insn.txt: uarch-ram.elf.objdump + grep -oP '^\s*[0-9a-f]{8}\:\s+[0-9a-f]{4,8}\s+\K[a-z]\S+' $(^F) | sort -u > $@ + +uarch-ram.elf.objdump: uarch-ram.elf + @$(OBJDUMP) -M no-aliases -d $(^F) > $@ + +validate-instruction-set: uarch-ram.elf.insn.txt + @grep -v -w -E "$(SUPPORTED_UARCH_INSN)" $( Date: Wed, 12 Jul 2023 13:02:28 -0300 Subject: [PATCH 3/3] Allow passing toolchain prefix as argument to makefile --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index a18ff47f0..e7bc55abd 100644 --- a/Makefile +++ b/Makefile @@ -183,6 +183,7 @@ toolchain-env: -e GROUP=$$(id -g -n) \ -e UID=$$(id -u) \ -e GID=$$(id -g) \ + $(if $(TOOLCHAIN_PREFIX), -e TOOLCHAIN_PREFIX=$(TOOLCHAIN_PREFIX), ) \ -v `pwd`:/opt/cartesi/machine-emulator \ -w /opt/cartesi/machine-emulator \ $(TOOLCHAIN_IMAGE):$(TOOLCHAIN_TAG) /bin/bash @@ -193,6 +194,7 @@ toolchain-exec: -e GROUP=$$(id -g -n) \ -e UID=$$(id -u) \ -e GID=$$(id -g) \ + $(if $(TOOLCHAIN_PREFIX), -e TOOLCHAIN_PREFIX=$(TOOLCHAIN_PREFIX), ) \ -v `pwd`:/opt/cartesi/machine-emulator \ -w /opt/cartesi/machine-emulator \ $(TOOLCHAIN_IMAGE):$(TOOLCHAIN_TAG) /bin/bash -c "$(CONTAINER_COMMAND)"