Skip to content

Commit 4ab63ac

Browse files
committed
Add Rust support
1 parent 7c0bde6 commit 4ab63ac

File tree

6 files changed

+56
-2
lines changed

6 files changed

+56
-2
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
*~
22
_*
33
*.o
4+
*.a
45
*.d
56
*.asm
67
*.sym

Makefile

+10-2
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,15 @@ tags: $(OBJS) entryother.S _init
146146
vectors.S: vectors.pl
147147
./vectors.pl > vectors.S
148148

149-
ULIB = ulib.o usys.o printf.o umalloc.o
149+
# Rust library.
150+
libxv6.a: $(shell find rust -type f -not -path "*/target/*")
151+
cd rust && \
152+
cargo build --release && \
153+
cd ../ && \
154+
cp rust/target/i686-unknown-linux-gnu/release/libxv6.a libxv6.a
155+
156+
# User space libraries.
157+
ULIB = ulib.o usys.o printf.o umalloc.o libxv6.a
150158

151159
_%: %.o $(ULIB)
152160
$(LD) $(LDFLAGS) -N -e main -Ttext 0 -o $@ $^
@@ -170,7 +178,6 @@ mkfs: mkfs.c fs.h
170178

171179
UPROGS=\
172180
_cat\
173-
_nc\
174181
_echo\
175182
_forktest\
176183
_grep\
@@ -179,6 +186,7 @@ UPROGS=\
179186
_ln\
180187
_ls\
181188
_mkdir\
189+
_nc\
182190
_rm\
183191
_sh\
184192
_stressfs\

rust/.cargo/config.toml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build]
2+
target = ["i686-unknown-linux-gnu"]
3+

rust/.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
debug/
2+
target/
3+
Cargo.lock
4+
**/*.rs.bk
5+

rust/Cargo.toml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[lib]
2+
crate-type = [ "staticlib" ]
3+
4+
[package]
5+
name = "xv6"
6+
version = "0.1.0"
7+
edition = "2021"
8+
9+
[profile.dev]
10+
panic = "abort"
11+
12+
[profile.release]
13+
panic = "abort"

rust/src/lib.rs

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#![no_std]
2+
#![feature(c_variadic)]
3+
4+
use core::panic::PanicInfo;
5+
6+
#[panic_handler]
7+
fn panic(_: &PanicInfo) -> ! {
8+
unsafe {
9+
printf(1, "panic!".as_ptr());
10+
}
11+
loop {}
12+
}
13+
14+
extern "C" {
15+
// printf.c
16+
pub fn printf(fd: i32, c: *const u8, args: ...);
17+
}
18+
19+
#[no_mangle]
20+
fn hello_world() {
21+
unsafe {
22+
printf(1, "hello from Rust!\n".as_bytes().as_ptr());
23+
}
24+
}

0 commit comments

Comments
 (0)