First successful rust library call
parent
f33ef06498
commit
4cd2466900
5
Makefile
5
Makefile
|
|
@ -3,7 +3,6 @@ U=user
|
||||||
R=rust
|
R=rust
|
||||||
|
|
||||||
RTARGET = riscv64gc-unknown-none-elf
|
RTARGET = riscv64gc-unknown-none-elf
|
||||||
RENV = debug
|
|
||||||
|
|
||||||
OBJS = \
|
OBJS = \
|
||||||
$K/entry.o \
|
$K/entry.o \
|
||||||
|
|
@ -35,7 +34,7 @@ OBJS = \
|
||||||
$K/virtio_disk.o
|
$K/virtio_disk.o
|
||||||
|
|
||||||
RLIBS = \
|
RLIBS = \
|
||||||
$R/foo/target/$(RTARGET)/$(RENV)/libfoo.rlib
|
$R/foo/target/$(RTARGET)/release/libfoo.a
|
||||||
|
|
||||||
# riscv64-unknown-elf- or riscv64-linux-gnu-
|
# riscv64-unknown-elf- or riscv64-linux-gnu-
|
||||||
# perhaps in /opt/riscv/bin
|
# perhaps in /opt/riscv/bin
|
||||||
|
|
@ -146,7 +145,7 @@ fs.img: mkfs/mkfs README $(UPROGS)
|
||||||
-include kernel/*.d user/*.d
|
-include kernel/*.d user/*.d
|
||||||
|
|
||||||
rustlibs:
|
rustlibs:
|
||||||
cargo build --manifest-path $R/foo/Cargo.toml
|
cargo build -r --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 \
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,9 @@
|
||||||
#include "memlayout.h"
|
#include "memlayout.h"
|
||||||
#include "riscv.h"
|
#include "riscv.h"
|
||||||
#include "defs.h"
|
#include "defs.h"
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
extern int32_t add(int32_t right, int32_t left);
|
||||||
|
|
||||||
volatile static int started = 0;
|
volatile static int started = 0;
|
||||||
|
|
||||||
|
|
@ -13,7 +16,8 @@ void main() {
|
||||||
printfinit();
|
printfinit();
|
||||||
printf("\n");
|
printf("\n");
|
||||||
printf("xv6 kernel is booting\n");
|
printf("xv6 kernel is booting\n");
|
||||||
// printf("rustlib: add(1, 2) = %d\n", add(1, 2));
|
printf("\n");
|
||||||
|
printf("rust library call: add(1, 2) = %d\n", add(1, 2));
|
||||||
printf("\n");
|
printf("\n");
|
||||||
kinit(); // physical page allocator
|
kinit(); // physical page allocator
|
||||||
kvminit(); // create kernel page table
|
kvminit(); // create kernel page table
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,12 @@ name = "foo"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
crate-type = [ "staticlib" ]
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
panic = "abort"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,13 @@
|
||||||
#![no_std]
|
#![no_std]
|
||||||
|
#![crate_type = "staticlib"]
|
||||||
|
|
||||||
pub fn add(left: usize, right: usize) -> usize {
|
#[no_mangle]
|
||||||
left + right + 5
|
pub extern "C" fn add(left: i32, right: i32) -> i32 {
|
||||||
|
left + right
|
||||||
|
}
|
||||||
|
|
||||||
|
#[panic_handler]
|
||||||
|
#[no_mangle]
|
||||||
|
fn panic(_info: &core::panic::PanicInfo) -> ! {
|
||||||
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue