Add registers in rust
This commit is contained in:
11
.gitignore
vendored
11
.gitignore
vendored
@@ -6,7 +6,12 @@ mill*
|
|||||||
bench/mem
|
bench/mem
|
||||||
.metals
|
.metals
|
||||||
.bloop
|
.bloop
|
||||||
.rpt
|
*.rpt
|
||||||
.Xil
|
*.jou
|
||||||
|
*.log
|
||||||
|
*.mmi
|
||||||
|
*.Xil
|
||||||
clockInfo.txt
|
clockInfo.txt
|
||||||
.csv
|
*.csv
|
||||||
|
*.bit
|
||||||
|
*.dcp
|
||||||
|
|||||||
5
Makefile
5
Makefile
@@ -61,7 +61,8 @@ TEST_MAX_PROCS := $$(($$(nproc) - 2)) ## Garde un processeur libre
|
|||||||
|
|
||||||
.PRECIOUS: $(MEM_DIR)/%.elf
|
.PRECIOUS: $(MEM_DIR)/%.elf
|
||||||
|
|
||||||
.PHONY: synthese fpga clean compile autotest simulation
|
.PHONY: synthese fpga clean compile autotest simulation force
|
||||||
|
force:
|
||||||
|
|
||||||
compile: $(MEM)
|
compile: $(MEM)
|
||||||
$(MEM_DIR):
|
$(MEM_DIR):
|
||||||
@@ -69,7 +70,7 @@ $(MEM_DIR):
|
|||||||
@mkdir -p $@/programs
|
@mkdir -p $@/programs
|
||||||
@mkdir -p $@/programs_rust
|
@mkdir -p $@/programs_rust
|
||||||
|
|
||||||
$(MEM_DIR)/programs_rust/%.elf: bench/programs_rust/% |$(MEM_DIR)
|
$(MEM_DIR)/programs_rust/%.elf: bench/programs_rust/% force |$(MEM_DIR)
|
||||||
cd bench/programs_rust && cargo build --release --bin=$(basename $(notdir $@))
|
cd bench/programs_rust && cargo build --release --bin=$(basename $(notdir $@))
|
||||||
cp -f bench/programs_rust/target/riscv64i/release/$(basename $(notdir $@)) $@
|
cp -f bench/programs_rust/target/riscv64i/release/$(basename $(notdir $@)) $@
|
||||||
$(MEM_DIR)/crt.o: $(BENCH_DIR)/crt.S |$(MEM_DIR)
|
$(MEM_DIR)/crt.o: $(BENCH_DIR)/crt.S |$(MEM_DIR)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
resolver = "3"
|
resolver = "3"
|
||||||
members = ["fpga_lib", "hello_rust"]
|
members = ["fpga-lib", "fpga-lib-macros", "hello-rust"]
|
||||||
|
|
||||||
[profile.release]
|
[profile.release]
|
||||||
panic = "abort"
|
panic = "abort"
|
||||||
|
|||||||
12
bench/programs_rust/fpga-lib-macros/Cargo.toml
Normal file
12
bench/programs_rust/fpga-lib-macros/Cargo.toml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
[package]
|
||||||
|
name = "fpga-lib-macros"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
proc-macro = true
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
proc-macro2 = "1.0"
|
||||||
|
quote = "1.0"
|
||||||
|
syn = { version = "2.0", features = ["full"] }
|
||||||
34
bench/programs_rust/fpga-lib-macros/src/lib.rs
Normal file
34
bench/programs_rust/fpga-lib-macros/src/lib.rs
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
extern crate proc_macro;
|
||||||
|
use proc_macro::TokenStream;
|
||||||
|
use quote::{format_ident, quote};
|
||||||
|
|
||||||
|
#[proc_macro]
|
||||||
|
pub fn define_regs(_input: TokenStream) -> TokenStream {
|
||||||
|
let mut tokens = proc_macro2::TokenStream::new();
|
||||||
|
|
||||||
|
for n in 0..32usize {
|
||||||
|
let load = format!("li x{}, {{}}", n);
|
||||||
|
let store = format!("mv {{}}, x{}", n);
|
||||||
|
let ident = format_ident!("X{}", n);
|
||||||
|
let t = quote! {
|
||||||
|
impl Reg<#n> {
|
||||||
|
pub fn write_const<const X: u64>() {
|
||||||
|
unsafe {
|
||||||
|
core::arch::asm!(#load, const X)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub fn read() -> u64 {
|
||||||
|
let out: u64;
|
||||||
|
unsafe {
|
||||||
|
core::arch::asm!(#store, out(reg) out)
|
||||||
|
}
|
||||||
|
out
|
||||||
|
}
|
||||||
|
}
|
||||||
|
pub type #ident = Reg<#n>;
|
||||||
|
};
|
||||||
|
tokens.extend(t);
|
||||||
|
}
|
||||||
|
|
||||||
|
tokens.into()
|
||||||
|
}
|
||||||
7
bench/programs_rust/fpga-lib/Cargo.toml
Normal file
7
bench/programs_rust/fpga-lib/Cargo.toml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
[package]
|
||||||
|
name = "fpga-lib"
|
||||||
|
version = "0.1.0"
|
||||||
|
edition = "2024"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
fpga-lib-macros = { path = "../fpga-lib-macros" }
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
#![no_std]
|
#![no_std]
|
||||||
|
|
||||||
|
pub mod register;
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! panic_handler {
|
macro_rules! panic_handler {
|
||||||
() => {
|
() => {
|
||||||
3
bench/programs_rust/fpga-lib/src/register.rs
Normal file
3
bench/programs_rust/fpga-lib/src/register.rs
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
pub struct Reg<const N: usize> {}
|
||||||
|
|
||||||
|
fpga_lib_macros::define_regs! {}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "fpga_lib"
|
name = "hello-rust"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
fpga-lib = { path = "../fpga-lib" }
|
||||||
26
bench/programs_rust/hello-rust/src/main.rs
Normal file
26
bench/programs_rust/hello-rust/src/main.rs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
#![no_std]
|
||||||
|
#![no_main]
|
||||||
|
|
||||||
|
use core::arch::asm;
|
||||||
|
|
||||||
|
use fpga_lib::{panic_handler, register::X31};
|
||||||
|
|
||||||
|
panic_handler! {}
|
||||||
|
|
||||||
|
#[unsafe(no_mangle)]
|
||||||
|
pub extern "C" fn _start() -> ! {
|
||||||
|
X31::write_const::<0xdead1ffffffff>();
|
||||||
|
let test = X31::read() + 10;
|
||||||
|
unsafe {
|
||||||
|
asm!(
|
||||||
|
"add x31, x0, x0",
|
||||||
|
"add x31, x0, {}", in(reg) test
|
||||||
|
);
|
||||||
|
|
||||||
|
const VGA: *mut u8 = 0x80000000 as *mut u8;
|
||||||
|
VGA.write_volatile(255);
|
||||||
|
// VGA.add(1).write_volatile(255);
|
||||||
|
}
|
||||||
|
|
||||||
|
loop {}
|
||||||
|
}
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "hello_rust"
|
|
||||||
version = "0.1.0"
|
|
||||||
edition = "2024"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
fpga_lib = { path = "../fpga_lib" }
|
|
||||||
@@ -1,18 +0,0 @@
|
|||||||
#![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 {}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user