it compiles, update for rust 2018

This commit is contained in:
Jack Halford 2019-01-15 23:16:36 +01:00
parent 911d9c8ae2
commit 3e49ec75d3
12 changed files with 46 additions and 90 deletions

View file

@ -10,22 +10,19 @@ crate-type = ["staticlib"]
rlibc = "1.0"
bitflags = "1.0.1"
spin = "0.4"
slab_allocator = "0.3.1"
multiboot2 = { path = "multiboot2-elf64" } # added rsdp tag
slab_allocator = "0.3.5"
x86 = { path = "x86" } # forked for IA-32 compat
multiboot2 = { path = "multiboot2-elf64" } # forked to add rsdp tag
[dependencies.raw-cpuid]
# need to use github/master because of features not yet on crates.io
git = "https://github.com/gz/rust-cpuid"
features = ["nightly"]
[dependencies.x86]
# forked for IA32 compat
path = "x86"
[dependencies.lazy_static]
version = "1.0.0"
features = ["spin_no_std"]
[dependencies.compiler_builtins]
#I'm waiting for somebody to port i386/udivdi3.S ... :(((
git = "https://github.com/rust-lang-nursery/compiler-builtins"
#[dependencies.compiler_builtins]
##I'm waiting for somebody to port i386/udivdi3.S ... :(((
#git = "https://github.com/rust-lang-nursery/compiler-builtins"

View file

@ -23,10 +23,10 @@ $(rust_os): $(TARGET).json Makefile
TERM=xterm RUST_TARGET_PATH="$(shell pwd)" xargo build --target $(TARGET)
## LINKAGE
kernel := build/$(OS)-$(ARCH).bin
KERNEL := build/$(OS)-$(ARCH).bin
linker_script := src/arch/$(ARCH)/linker.ld
LD := /usr/bin/ld -m elf_i386 -L ./ -n --gc-sections
$(kernel): $(rust_os) $(asm_object) $(linker_script) Makefile
$(KERNEL): $(rust_os) $(asm_object) $(linker_script) Makefile
$(LD) -o $@ -T $(linker_script) $(asm_object) $(rust_os)
clean:
@ -36,11 +36,11 @@ clean:
.PHONY: clean kernel iso $(rust_os)
# Bootloader recipes
ISO := $(kernel:.bin=.iso)
ISO := $(KERNEL:.bin=.iso)
iso: $(ISO)
include mk/grub.mk
# Emulation recipes
include mk/qemu.mk
kernel: $(kernel)
kernel: $(KERNEL)

View file

@ -4,31 +4,40 @@ Kernel from scratch (KFS) series of projects at Ecole 42 !
# building
`git submodule udpate --init`
- `nasm` compiles the bootcode
- `ld` links the bootcode and rust binary
- `grub-mkrescue` builds the iso
- `grub-mkrescue` builds the iso (need xorriso and mtools)
- `xargo` builds rust code
See `.travis.yml` to get an ubuntu environment ready
on archlinux `pacman -S rustup make grub xorriso mtools binutils gcc qemu`
on voidlinux `xbps-install -S rustup make grub xorriso mtools binutils gcc qemu nasm`
#### rust setup
We build on nightly channel because of some cool features not yet in stable.
We need the rust sources to build with xargo for cross-compiling to custom platform.
```
rustup override add nightly
rustup component add rust-src
rustup override add nightly
rustup default nightly
cargo install xargo
```
# running
- `make iso` builds a bootable iso with grub
- `make qemu` runs the iso, `make qemu-reload` after a re-build
- `make qemu` runs the iso,
- `make qemu-reload` reloads the CD
# todo
- remove assembly for a pure rust entry point
- replace grub with something lighter
- replace grub with something lighter (no bootloader at all with `qemu -kernel` ?)
# inspiration

View file

@ -1,8 +1,8 @@
grub-cfg := src/arch/$(ARCH)/grub.cfg
isodir := build/isofiles
$(ISO): $(kernel) $(grub-cfg) Makefile
$(ISO): $(KERNEL) $(grub-cfg) Makefile
@mkdir -p $(isodir)/boot/grub
@cp $(grub-cfg) $(isodir)/boot/grub
@cp $(kernel) $(isodir)/boot/$(OS)
@cp $(KERNEL) $(isodir)/boot/$(OS)
grub-mkrescue -o $@ $(isodir) 2>/dev/null

View file

@ -13,7 +13,7 @@ qemu:
qemu-gdb:
gdb -q\
-symbols "$(kernel)" \
-symbols "$(KERNEL)" \
-ex "target remote :$(QEMU_GDB_PORT)"\
-ex "set arch i386"

View file

@ -1,12 +1,10 @@
pub use self::slab::Allocator;
mod slab;
// pub use self::ALLOCATOR;
use x86::*;
use x86::structures::paging::*;
use arch::x86::paging::*;
fn map_heap(active_table: &mut ActivePageTable) {
//zone for heap is predefines in `consts.rs`
//zone for heap is predefined in `consts.rs`
for page in ::KERNEL_HEAP_RANGE {
active_table.map(page, PageTableFlags::WRITABLE);
}
@ -20,5 +18,10 @@ pub unsafe fn init(active_table: &mut ActivePageTable) {
map_heap(active_table);
//slab allocator
Allocator::init(offset.as_u32() as usize, size as usize);
super::ALLOCATOR.init(offset.as_u32() as usize, size as usize);
}
#[alloc_error_handler]
fn foo(_: core::alloc::Layout) -> ! {
panic!();
}

View file

@ -1,43 +0,0 @@
use alloc::heap::{Alloc, AllocErr, Layout};
use spin::Mutex;
use slab_allocator::Heap;
static HEAP: Mutex<Option<Heap>> = Mutex::new(None);
pub struct Allocator;
impl Allocator {
pub unsafe fn init(offset: usize, size: usize) {
*HEAP.lock() = Some(Heap::new(offset, size));
}
}
unsafe impl<'a> Alloc for &'a Allocator {
unsafe fn alloc(&mut self, layout: Layout) -> Result<*mut u8, AllocErr> {
if let Some(ref mut heap) = *HEAP.lock() {
heap.allocate(layout)
} else {
panic!("__rust_allocate: heap not initialized");
}
}
unsafe fn dealloc(&mut self, ptr: *mut u8, layout: Layout) {
if let Some(ref mut heap) = *HEAP.lock() {
heap.deallocate(ptr, layout)
} else {
panic!("__rust_deallocate: heap not initialized");
}
}
fn oom(&mut self, error: AllocErr) -> ! {
panic!("Out of memory: {:?}", error);
}
fn usable_size(&self, layout: &Layout) -> (usize, usize) {
if let Some(ref mut heap) = *HEAP.lock() {
heap.usable_size(layout)
} else {
panic!("__rust_usable_size: heap not initialized");
}
}
}

View file

@ -54,7 +54,7 @@ pub unsafe extern "C" fn x86_rust_start(multiboot_info_addr: usize) {
// set up pic, pit
devices::init();
// primary CPU entry point
// primary CPU entry point, architutecture independant now.
::kmain();
}

View file

@ -10,8 +10,8 @@
#![feature(thread_local)]
// home made heap
#![feature(alloc)]
#![feature(alloc_error_handler)]
#![feature(allocator_api)]
#![feature(global_allocator)]
// x86 specific
#![feature(abi_x86_interrupt)]
@ -27,25 +27,16 @@ extern crate spin;
// used by arch/x86, need conditional compilation here
extern crate x86;
/// 80x25 terminal driver
#[macro_use]
pub mod vga;
/// PS/2 detection and processing
pub mod keyboard;
/// simplisitc kernel commands
pub mod console;
/// ACPI self contained module
pub mod acpi;
/// Heap allocators
pub mod allocator;
/// Memory management
pub mod memory;
/// arch specific entry points
pub mod arch;
pub use arch::x86::consts::*;
/// concurrency management
pub mod scheduling;
/// uptime counting
pub mod time;
/// kernel entry point. arch module is responsible for
@ -66,15 +57,14 @@ pub fn kmain() -> ! {
#[no_mangle]
pub extern "C" fn eh_personality() {}
#[lang = "panic_fmt"]
#[panic_handler]
#[no_mangle]
pub extern "C" fn panic_fmt(fmt: core::fmt::Arguments, file: &'static str, line: u32) -> ! {
println!("PANIC: {}", fmt);
println!("FILE: {}", file);
println!("LINE: {}", line);
pub extern "C" fn panic_fmt(info: &core::panic::PanicInfo) -> ! {
println!("{}", info);
flush!();
loop {}
}
#[global_allocator]
static HEAP_ALLOCATOR: allocator::Allocator = allocator::Allocator;
// pub static ALLOCATOR: slab_allocator::LockedHeap = allocator::ALLOCATOR;
pub static ALLOCATOR: slab_allocator::LockedHeap = slab_allocator::LockedHeap::empty();

View file

@ -1,7 +1,7 @@
//! Recycle allocator
//! Uses freed frames if possible, then uses inner allocator
use alloc::Vec;
use alloc::vec::Vec;
use x86::*;
use x86::structures::paging::*;
use super::*;

View file

@ -4,7 +4,7 @@
//! processes...
//! however it's stupid simple to implement!
use alloc::VecDeque;
use alloc::collections::vec_deque::VecDeque;
use super::*;
// use super::process::*;

View file

@ -5,7 +5,7 @@
//!
//! inspired from https://wiki.osdev.org/Blocking_Process
use alloc::VecDeque;
use alloc::collections::vec_deque::VecDeque;
use super::*;
struct Sleeper {