Added basic rust library for testing

feat/start
hheik 2024-04-29 22:42:59 +03:00
parent 61a7340ea8
commit f33ef06498
7 changed files with 40 additions and 2 deletions

5
.cargo/config.toml Normal file
View File

@ -0,0 +1,5 @@
[build]
target = "riscv64gc-unknown-none-elf"
[target.riscv64-unknown-elf]
linker = "/opt/riscv/bin/riscv64-unknown-elf-gcc"

1
.rustfmt.toml Normal file
View File

@ -0,0 +1 @@
hard_tabs = true

View File

@ -1,5 +1,9 @@
K=kernel K=kernel
U=user U=user
R=rust
RTARGET = riscv64gc-unknown-none-elf
RENV = debug
OBJS = \ OBJS = \
$K/entry.o \ $K/entry.o \
@ -30,6 +34,9 @@ OBJS = \
$K/plic.o \ $K/plic.o \
$K/virtio_disk.o $K/virtio_disk.o
RLIBS = \
$R/foo/target/$(RTARGET)/$(RENV)/libfoo.rlib
# riscv64-unknown-elf- or riscv64-linux-gnu- # riscv64-unknown-elf- or riscv64-linux-gnu-
# perhaps in /opt/riscv/bin # perhaps in /opt/riscv/bin
#TOOLPREFIX = #TOOLPREFIX =
@ -73,8 +80,8 @@ endif
LDFLAGS = -z max-page-size=4096 LDFLAGS = -z max-page-size=4096
$K/kernel: $(OBJS) $K/kernel.ld $U/initcode $K/kernel: $(OBJS) $K/kernel.ld $U/initcode rustlibs
$(LD) $(LDFLAGS) -T $K/kernel.ld -o $K/kernel $(OBJS) $(LD) $(LDFLAGS) -T $K/kernel.ld -o $K/kernel $(OBJS) $(RLIBS)
$(OBJDUMP) -S $K/kernel > $K/kernel.asm $(OBJDUMP) -S $K/kernel > $K/kernel.asm
$(OBJDUMP) -t $K/kernel | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > $K/kernel.sym $(OBJDUMP) -t $K/kernel | sed '1,/SYMBOL TABLE/d; s/ .* / /; /^$$/d' > $K/kernel.sym
@ -138,6 +145,9 @@ fs.img: mkfs/mkfs README $(UPROGS)
-include kernel/*.d user/*.d -include kernel/*.d user/*.d
rustlibs:
cargo build --manifest-path $R/foo/Cargo.toml
clean: clean:
rm -f *.tex *.dvi *.idx *.aux *.log *.ind *.ilg \ rm -f *.tex *.dvi *.idx *.aux *.log *.ind *.ilg \
*/*.o */*.d */*.asm */*.sym \ */*.o */*.d */*.asm */*.sym \
@ -145,6 +155,7 @@ clean:
mkfs/mkfs .gdbinit \ mkfs/mkfs .gdbinit \
$U/usys.S \ $U/usys.S \
$(UPROGS) $(UPROGS)
cargo clean --manifest-path $R/foo/Cargo.toml
# try to generate a unique GDB port # try to generate a unique GDB port
GDBPORT = $(shell expr `id -u` % 5000 + 25000) GDBPORT = $(shell expr `id -u` % 5000 + 25000)

1
rust/foo/.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target

7
rust/foo/Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "foo"
version = "0.1.0"

8
rust/foo/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "foo"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

5
rust/foo/src/lib.rs Normal file
View File

@ -0,0 +1,5 @@
#![no_std]
pub fn add(left: usize, right: usize) -> usize {
left + right + 5
}