Starts adding rust in the toolchain

This commit is contained in:
2025-11-12 22:05:25 +01:00
parent 7bb8b993ae
commit 8326c1f169
11 changed files with 104 additions and 4 deletions

View File

@@ -67,7 +67,11 @@ compile: $(MEM)
$(MEM_DIR):
@mkdir -p $@/tests/op
@mkdir -p $@/programs
@mkdir -p $@/programs_rust
$(MEM_DIR)/programs_rust/%.elf: bench/programs_rust/% |$(MEM_DIR)
cd bench/programs_rust && cargo build --release --bin=$(basename $(notdir $@))
cp -f bench/programs_rust/target/riscv64i/release/$(basename $(notdir $@)) $@
$(MEM_DIR)/crt.o: $(BENCH_DIR)/crt.S |$(MEM_DIR)
$(CC) $(CFLAGS) -c $< -o $@
$(MEM_DIR)/%.elf: $(BENCH_DIR)/%.c $(MEM_DIR)/crt.o |$(MEM_DIR)
@@ -106,14 +110,16 @@ mill:
autotest: mill test-bench/mem/tests/$(PROG).mem ##! Lance la simulation automatique pour tous les tests ou juste celui fourni dans PROG
testall: mill compile
@# Limite le nombre de processeurs et la ram utilisée pour les tests parellèle
testall: mill compile ##! Lance la simulation automatique pour tous les tests en parallèle
@# Limite le nombre de processeurs et la ram utilisée pour les tests parallèle
@( \
ulimit -v $(TEST_MAX_RAM); \
PROOT=$(PWD) taskset -c 0-$(TEST_MAX_PROCS) ./mill TPchisel.test.testOnly $(TOP_REP).ZzTopAllSpec \
)
simulation: mill compile ##! Lance gtkwave sur le test fourni dans PROG
$(PROG): $(MEM_DIR)/$(PROG).mem
simulation: mill $(PROG) ##! Lance gtkwave sur le test fourni dans PROG
@$(call check_vars,PROG)
@PROOT=$(PWD) PROG=$(PROG) CYCLES=$(CYCLES) ./mill TPchisel.test.testOnly $(TOP_REP).$(TOP_TEST) -- -DemitVcd=1 -z "gtkwave"
@gtkwave -a common/config.gtkw ./build/chiselsim/ZzTopSpec/Simulation-pour-gtkwave/workdir-verilator/trace.vcd

View File

@@ -0,0 +1,14 @@
[build]
target = "riscv64i.json"
[target.riscv64i]
linker = "riscv64-unknown-elf-ld"
# linker = "rust-lld"
rustflags = [
# "-C", "link-arg=-nostartfiles",
"-C", "link-arg=-T../link.ld",
]
[unstable]
build-std = ["core", "compiler_builtins"]

3
bench/programs_rust/.gitignore vendored Normal file
View File

@@ -0,0 +1,3 @@
.helix/
target/
Cargo.lock

View File

@@ -0,0 +1,13 @@
[workspace]
resolver = "3"
members = ["fpga_lib", "hello_rust"]
[profile.release]
panic = "abort"
codegen-units = 1 # better optimizations
lto = true # better optimizations
strip = true
opt-level = "z"
[profile.dev]
panic = "abort"

View File

@@ -0,0 +1,6 @@
[package]
name = "fpga_lib"
version = "0.1.0"
edition = "2024"
[dependencies]

View File

@@ -0,0 +1,11 @@
#![no_std]
#[macro_export]
macro_rules! panic_handler {
() => {
#[panic_handler]
fn panic(_info: &core::panic::PanicInfo) -> ! {
loop {}
}
};
}

View File

@@ -0,0 +1,7 @@
[package]
name = "hello_rust"
version = "0.1.0"
edition = "2024"
[dependencies]
fpga_lib = { path = "../fpga_lib" }

View File

@@ -0,0 +1,18 @@
#![no_std]
#![no_main]
use core::arch::asm;
use fpga_lib::panic_handler;
panic_handler! {}
#[unsafe(no_mangle)]
pub extern "C" fn _start() -> ! {
unsafe {
asm! {
"li x31, 0xdead0"
}
}
loop {}
}

View File

@@ -0,0 +1,21 @@
{
"llvm-target": "riscv64",
"llvm-abiname": "lp64",
"abi": "lp64",
"data-layout": "e-m:e-p:64:64-i64:64-i128:128-n32:64-S128",
"target-endian": "little",
"target-pointer-width": 64,
"arch": "riscv64",
"os": "none",
"vendor": "unknown",
"env": "",
"features": "+i",
"linker-flavor": "ld.lld",
"linker": "riscv64-unknown-elf-ld",
"executables": true,
"panic-strategy": "abort",
"relocation-model": "static",
"disable-redzone": true,
"emit-debug-gdb-scripts": false,
"eh-frame-header": false
}

View File

@@ -0,0 +1,2 @@
[toolchain]
channel = "nightly"

View File

@@ -5,7 +5,6 @@ import chisel3.util.switch
import projet.CUInterface
import projet.AluOpCode
import chisel3.util.is
import projet.OpType
object OpRW {
// Implements functions for all instruction of the opImm, w kind