.githooks/
riscv/
test/
.clang-format
570 B
.gitignore
5 B
.gitsigners
112 B
AGENTS.md
227 B
LICENSE
1.1 KiB
Makefile
3.5 KiB
README
12.5 KiB
STYLE
781 B
abi_host.c
12.2 KiB
abi_linux.c
3.7 KiB
bitmanip.h
5.8 KiB
color.h
567 B
debug_map.c
5.1 KiB
debug_map.h
1.3 KiB
emulator.c
87.3 KiB
host.h
5.5 KiB
host_posix.c
11.2 KiB
hosted.h
5.7 KiB
image_native.c
4.6 KiB
image_rad0.c
2.7 KiB
image_raw.c
2.6 KiB
io.c
1.1 KiB
io.h
444 B
jit.c
99.2 KiB
jit.h
7.8 KiB
machine.c
4.4 KiB
machine.h
2.1 KiB
machine_cpu.c
13.6 KiB
machine_csr.c
4.6 KiB
machine_devices.c
10.8 KiB
machine_fdt.c
8.7 KiB
machine_internal.h
7.4 KiB
muldiv.h
1.0 KiB
profile.c
17.5 KiB
profile.h
1.4 KiB
riscv.c
755 B
riscv.h
4.3 KiB
types.h
1019 B
vector.c
54.0 KiB
vector.h
1.3 KiB
Makefile
raw
| 1 | # Builds the RISC-V emulator. |
| 2 | |
| 3 | PREFIX ?= $(HOME)/bin |
| 4 | CC := clang |
| 5 | CPPFLAGS := -iquote . |
| 6 | CFLAGS := -fvisibility=hidden -std=c99 -O3 -g \ |
| 7 | -Wall -Wextra -Wpedantic \ |
| 8 | -Wformat=2 -Wformat-security \ |
| 9 | -Wnull-dereference \ |
| 10 | -Wno-format-nonliteral \ |
| 11 | -Wcast-align \ |
| 12 | -Wunused -Wuninitialized \ |
| 13 | -Wmissing-field-initializers \ |
| 14 | -fno-common -fstack-protector-all \ |
| 15 | -mcmodel=medium \ |
| 16 | -march=native -flto |
| 17 | BLAKE3_CFLAGS := $(shell pkg-config --cflags libblake3) |
| 18 | BLAKE3_LIBS := $(shell pkg-config --libs libblake3) |
| 19 | LDFLAGS := -fuse-ld=lld -Wl,-z,stack-size=33554432 |
| 20 | EMULATOR_SRCS := emulator.c abi_host.c abi_linux.c image_native.c image_rad0.c \ |
| 21 | image_raw.c host_posix.c jit.c profile.c debug_map.c riscv/debug.c io.c riscv.c \ |
| 22 | vector.c machine.c machine_cpu.c machine_csr.c machine_devices.c machine_fdt.c |
| 23 | |
| 24 | default: bin/emulator |
| 25 | |
| 26 | bin/emulator: $(EMULATOR_SRCS) profile.h debug_map.h jit.h bitmanip.h vector.h muldiv.h color.h types.h io.h host.h hosted.h riscv.h riscv/debug.h machine.h machine_internal.h |
| 27 | @echo "cc emulator => $@" |
| 28 | @mkdir -p bin |
| 29 | @$(CC) $(CPPFLAGS) $(CFLAGS) $(BLAKE3_CFLAGS) $(LDFLAGS) $(EMULATOR_SRCS) $(BLAKE3_LIBS) -o $@ |
| 30 | |
| 31 | install: bin/emulator |
| 32 | @echo "copy bin/emulator => $(PREFIX)/emulator" |
| 33 | @mkdir -p $(PREFIX) |
| 34 | @cp bin/emulator $(PREFIX)/emulator |
| 35 | |
| 36 | fmt: |
| 37 | git ls-files "*.c" "*.h" | xargs clang-format -i |
| 38 | |
| 39 | clean: |
| 40 | @rm -f bin/emulator |
| 41 | |
| 42 | .PHONY: default clean install |
| 43 | .SUFFIXES: |
| 44 | .DELETE_ON_ERROR: |
| 45 | .SILENT: |
| 46 | |
| 47 | # Check integer vector execution with host memory diagnostics. |
| 48 | bin/vector-test: test/vector.c vector.c vector.h types.h |
| 49 | @mkdir -p bin |
| 50 | @$(CC) $(CPPFLAGS) -std=c99 -Wall -Wextra -g -fsanitize=address,undefined test/vector.c vector.c -o $@ |
| 51 | |
| 52 | bin/vector-machine-test: test/vector_machine.c vector.c vector.h machine_cpu.c machine_csr.c machine_devices.c machine.c machine_fdt.c machine_internal.h machine.h types.h bitmanip.h muldiv.h |
| 53 | @mkdir -p bin |
| 54 | @$(CC) $(CPPFLAGS) -std=c99 -Wall -Wextra -g -fsanitize=address,undefined test/vector_machine.c vector.c machine_cpu.c machine_csr.c machine_devices.c machine.c machine_fdt.c -o $@ |
| 55 | |
| 56 | test-vector: bin/vector-test bin/vector-machine-test test-jit |
| 57 | @ASAN_OPTIONS=detect_leaks=0 timeout 30 bin/vector-test |
| 58 | @ASAN_OPTIONS=detect_leaks=0 timeout 30 bin/vector-machine-test |
| 59 | |
| 60 | .PHONY: test-vector |
| 61 | |
| 62 | # Compare hosted vector translation with architectural interpreter state. |
| 63 | bin/jit-vector-test: test/jit_vector.c jit.c jit.h profile.h vector.c vector.h riscv.c riscv.h riscv/debug.c riscv/debug.h bitmanip.h color.h types.h |
| 64 | @mkdir -p bin |
| 65 | @$(CC) $(CPPFLAGS) -std=c99 -O2 -g -Wall -Wextra -fsanitize=address,undefined test/jit_vector.c jit.c vector.c riscv.c riscv/debug.c -o $@ |
| 66 | |
| 67 | test-jit: bin/jit-vector-test test-jit-calls |
| 68 | @ASAN_OPTIONS=detect_leaks=0 timeout 60 $< |
| 69 | |
| 70 | # Compare translated and interpreted runs of calls, returns and LR/SC. |
| 71 | bin/jit-calls-gen: test/jit_calls.c |
| 72 | @mkdir -p bin |
| 73 | @$(CC) $(CPPFLAGS) -std=c99 -Wall -Wextra -g $< -o $@ |
| 74 | |
| 75 | test-jit-calls: bin/emulator bin/jit-calls-gen |
| 76 | @bin/jit-calls-gen bin/jit-calls.bin |
| 77 | @jit=$$(bin/emulator -run -count-instructions bin/jit-calls.bin 2>&1; \ |
| 78 | echo "status $$?"); \ |
| 79 | int=$$(bin/emulator -run -count-instructions -no-jit bin/jit-calls.bin 2>&1; \ |
| 80 | echo "status $$?"); \ |
| 81 | if [ "$$jit" != "$$int" ]; then \ |
| 82 | echo "JIT call checks failed: '$$jit' != '$$int'"; exit 1; \ |
| 83 | fi; \ |
| 84 | echo "JIT call checks passed" |
| 85 | |
| 86 | .PHONY: test-jit test-jit-calls |