Restructure and include basic Rust
This commit is contained in:
parent
f5b93ef12f
commit
79ecd97c76
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,6 +1,7 @@
|
|||||||
*~
|
*~
|
||||||
_*
|
_*
|
||||||
*.o
|
*.o
|
||||||
|
*.a
|
||||||
*.d
|
*.d
|
||||||
*.asm
|
*.asm
|
||||||
*.sym
|
*.sym
|
||||||
|
46
Makefile
46
Makefile
@ -1,5 +1,6 @@
|
|||||||
K=kernel
|
K=kernel
|
||||||
U=user
|
U=user
|
||||||
|
P=programs
|
||||||
|
|
||||||
OBJS = \
|
OBJS = \
|
||||||
$K/entry.o \
|
$K/entry.o \
|
||||||
@ -11,6 +12,7 @@ OBJS = \
|
|||||||
$K/spinlock.o \
|
$K/spinlock.o \
|
||||||
$K/string.o \
|
$K/string.o \
|
||||||
$K/main.o \
|
$K/main.o \
|
||||||
|
$K/rust.a \
|
||||||
$K/vm.o \
|
$K/vm.o \
|
||||||
$K/proc.o \
|
$K/proc.o \
|
||||||
$K/swtch.o \
|
$K/swtch.o \
|
||||||
@ -63,6 +65,10 @@ CFLAGS += -ffreestanding -fno-common -nostdlib -mno-relax
|
|||||||
CFLAGS += -I.
|
CFLAGS += -I.
|
||||||
CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector)
|
CFLAGS += $(shell $(CC) -fno-stack-protector -E -x c /dev/null >/dev/null 2>&1 && echo -fno-stack-protector)
|
||||||
|
|
||||||
|
RUSTC = rustc
|
||||||
|
TARGET_TRIPLE = riscv64gc-unknown-none-elf
|
||||||
|
RUSTFLAGS = -C soft-float=n --target $(TARGET_TRIPLE)
|
||||||
|
|
||||||
# Disable PIE when possible (for Ubuntu 16.10 toolchain)
|
# Disable PIE when possible (for Ubuntu 16.10 toolchain)
|
||||||
ifneq ($(shell $(CC) -dumpspecs 2>/dev/null | grep -e '[^f]no-pie'),)
|
ifneq ($(shell $(CC) -dumpspecs 2>/dev/null | grep -e '[^f]no-pie'),)
|
||||||
CFLAGS += -fno-pie -no-pie
|
CFLAGS += -fno-pie -no-pie
|
||||||
@ -89,6 +95,12 @@ tags: $(OBJS) _init
|
|||||||
|
|
||||||
ULIB = $U/ulib.o $U/usys.o $U/printf.o $U/umalloc.o
|
ULIB = $U/ulib.o $U/usys.o $U/printf.o $U/umalloc.o
|
||||||
|
|
||||||
|
%.a: %.rs
|
||||||
|
$(RUSTC) $(RUSTFLAGS) --crate-type staticlib -o $@ -L $K $^
|
||||||
|
|
||||||
|
%.o: %.c *.h
|
||||||
|
$(CC) $(CFLAGS) -c $^
|
||||||
|
|
||||||
_%: %.o $(ULIB)
|
_%: %.o $(ULIB)
|
||||||
$(LD) $(LDFLAGS) -T $U/user.ld -o $@ $^
|
$(LD) $(LDFLAGS) -T $U/user.ld -o $@ $^
|
||||||
$(OBJDUMP) -S $@ > $*.asm
|
$(OBJDUMP) -S $@ > $*.asm
|
||||||
@ -116,22 +128,22 @@ mkfs/mkfs: mkfs/mkfs.c $K/fs.h $K/param.h
|
|||||||
.PRECIOUS: %.o
|
.PRECIOUS: %.o
|
||||||
|
|
||||||
UPROGS=\
|
UPROGS=\
|
||||||
$U/_cat\
|
$P/_cat\
|
||||||
$U/_echo\
|
$P/_echo\
|
||||||
$U/_forktest\
|
$P/_forktest\
|
||||||
$U/_grep\
|
$P/_grep\
|
||||||
$U/_init\
|
$P/_grind\
|
||||||
$U/_kill\
|
$P/_init\
|
||||||
$U/_ln\
|
$P/_kill\
|
||||||
$U/_ls\
|
$P/_ln\
|
||||||
$U/_mkdir\
|
$P/_ls\
|
||||||
$U/_rm\
|
$P/_mkdir\
|
||||||
$U/_sh\
|
$P/_rm\
|
||||||
$U/_stressfs\
|
$P/_sh\
|
||||||
$U/_usertests\
|
$P/_stressfs\
|
||||||
$U/_grind\
|
$P/_usertests\
|
||||||
$U/_wc\
|
$P/_wc\
|
||||||
$U/_zombie\
|
$P/_zombie\
|
||||||
|
|
||||||
fs.img: mkfs/mkfs README $(UPROGS)
|
fs.img: mkfs/mkfs README $(UPROGS)
|
||||||
mkfs/mkfs fs.img README $(UPROGS)
|
mkfs/mkfs fs.img README $(UPROGS)
|
||||||
@ -140,7 +152,7 @@ fs.img: mkfs/mkfs README $(UPROGS)
|
|||||||
|
|
||||||
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 */*.a */*.d */*.asm */*.sym \
|
||||||
$U/initcode $U/initcode.out $K/kernel fs.img \
|
$U/initcode $U/initcode.out $K/kernel fs.img \
|
||||||
mkfs/mkfs .gdbinit \
|
mkfs/mkfs .gdbinit \
|
||||||
$U/usys.S \
|
$U/usys.S \
|
||||||
|
@ -6,6 +6,8 @@
|
|||||||
|
|
||||||
volatile static int started = 0;
|
volatile static int started = 0;
|
||||||
|
|
||||||
|
void rust_main();
|
||||||
|
|
||||||
// start() jumps here in supervisor mode on all CPUs.
|
// start() jumps here in supervisor mode on all CPUs.
|
||||||
void
|
void
|
||||||
main()
|
main()
|
||||||
@ -16,6 +18,7 @@ main()
|
|||||||
printf("\n");
|
printf("\n");
|
||||||
printf("xv6 kernel is booting\n");
|
printf("xv6 kernel is booting\n");
|
||||||
printf("\n");
|
printf("\n");
|
||||||
|
rust_main();
|
||||||
kinit(); // physical page allocator
|
kinit(); // physical page allocator
|
||||||
kvminit(); // create kernel page table
|
kvminit(); // create kernel page table
|
||||||
kvminithart(); // turn on paging
|
kvminithart(); // turn on paging
|
||||||
|
@ -59,6 +59,10 @@ printptr(uint64 x)
|
|||||||
consputc(digits[x >> (sizeof(uint64) * 8 - 4)]);
|
consputc(digits[x >> (sizeof(uint64) * 8 - 4)]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void print(char *raw) {
|
||||||
|
printf("%s", raw);
|
||||||
|
}
|
||||||
|
|
||||||
// Print to the console. only understands %d, %x, %p, %s.
|
// Print to the console. only understands %d, %x, %p, %s.
|
||||||
void
|
void
|
||||||
printf(char *fmt, ...)
|
printf(char *fmt, ...)
|
||||||
|
26
kernel/rust.rs
Normal file
26
kernel/rust.rs
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#![no_std]
|
||||||
|
#![no_main]
|
||||||
|
|
||||||
|
use core::ffi::{c_char, CStr};
|
||||||
|
|
||||||
|
extern "C" {
|
||||||
|
fn print(message: *const c_char);
|
||||||
|
fn panic(panic_message: *const c_char) -> !;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub extern "C" fn rust_main() {
|
||||||
|
unsafe {
|
||||||
|
print(
|
||||||
|
CStr::from_bytes_with_nul(b"Hello from Rust!\0")
|
||||||
|
.unwrap()
|
||||||
|
.as_ptr(),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#[panic_handler]
|
||||||
|
unsafe fn panic_wrapper(_panic_info: &core::panic::PanicInfo) -> ! {
|
||||||
|
panic(CStr::from_bytes_with_nul(b"panic from rust\0").unwrap_or_default().as_ptr())
|
||||||
|
}
|
@ -132,6 +132,8 @@ main(int argc, char *argv[])
|
|||||||
char *shortname;
|
char *shortname;
|
||||||
if(strncmp(argv[i], "user/", 5) == 0)
|
if(strncmp(argv[i], "user/", 5) == 0)
|
||||||
shortname = argv[i] + 5;
|
shortname = argv[i] + 5;
|
||||||
|
else if(strncmp(argv[i], "programs/", 9) == 0)
|
||||||
|
shortname = argv[i] + 9;
|
||||||
else
|
else
|
||||||
shortname = argv[i];
|
shortname = argv[i];
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user