it compiles, update for rust 2018
This commit is contained in:
parent
911d9c8ae2
commit
3e49ec75d3
12 changed files with 46 additions and 90 deletions
|
|
@ -10,22 +10,19 @@ crate-type = ["staticlib"]
|
||||||
rlibc = "1.0"
|
rlibc = "1.0"
|
||||||
bitflags = "1.0.1"
|
bitflags = "1.0.1"
|
||||||
spin = "0.4"
|
spin = "0.4"
|
||||||
slab_allocator = "0.3.1"
|
slab_allocator = "0.3.5"
|
||||||
multiboot2 = { path = "multiboot2-elf64" } # added rsdp tag
|
x86 = { path = "x86" } # forked for IA-32 compat
|
||||||
|
multiboot2 = { path = "multiboot2-elf64" } # forked to add rsdp tag
|
||||||
|
|
||||||
[dependencies.raw-cpuid]
|
[dependencies.raw-cpuid]
|
||||||
# need to use github/master because of features not yet on crates.io
|
# need to use github/master because of features not yet on crates.io
|
||||||
git = "https://github.com/gz/rust-cpuid"
|
git = "https://github.com/gz/rust-cpuid"
|
||||||
features = ["nightly"]
|
features = ["nightly"]
|
||||||
|
|
||||||
[dependencies.x86]
|
|
||||||
# forked for IA32 compat
|
|
||||||
path = "x86"
|
|
||||||
|
|
||||||
[dependencies.lazy_static]
|
[dependencies.lazy_static]
|
||||||
version = "1.0.0"
|
version = "1.0.0"
|
||||||
features = ["spin_no_std"]
|
features = ["spin_no_std"]
|
||||||
|
|
||||||
[dependencies.compiler_builtins]
|
#[dependencies.compiler_builtins]
|
||||||
#I'm waiting for somebody to port i386/udivdi3.S ... :(((
|
##I'm waiting for somebody to port i386/udivdi3.S ... :(((
|
||||||
git = "https://github.com/rust-lang-nursery/compiler-builtins"
|
#git = "https://github.com/rust-lang-nursery/compiler-builtins"
|
||||||
|
|
|
||||||
|
|
@ -23,10 +23,10 @@ $(rust_os): $(TARGET).json Makefile
|
||||||
TERM=xterm RUST_TARGET_PATH="$(shell pwd)" xargo build --target $(TARGET)
|
TERM=xterm RUST_TARGET_PATH="$(shell pwd)" xargo build --target $(TARGET)
|
||||||
|
|
||||||
## LINKAGE
|
## LINKAGE
|
||||||
kernel := build/$(OS)-$(ARCH).bin
|
KERNEL := build/$(OS)-$(ARCH).bin
|
||||||
linker_script := src/arch/$(ARCH)/linker.ld
|
linker_script := src/arch/$(ARCH)/linker.ld
|
||||||
LD := /usr/bin/ld -m elf_i386 -L ./ -n --gc-sections
|
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)
|
$(LD) -o $@ -T $(linker_script) $(asm_object) $(rust_os)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
|
|
@ -36,11 +36,11 @@ clean:
|
||||||
.PHONY: clean kernel iso $(rust_os)
|
.PHONY: clean kernel iso $(rust_os)
|
||||||
|
|
||||||
# Bootloader recipes
|
# Bootloader recipes
|
||||||
ISO := $(kernel:.bin=.iso)
|
ISO := $(KERNEL:.bin=.iso)
|
||||||
iso: $(ISO)
|
iso: $(ISO)
|
||||||
include mk/grub.mk
|
include mk/grub.mk
|
||||||
|
|
||||||
# Emulation recipes
|
# Emulation recipes
|
||||||
include mk/qemu.mk
|
include mk/qemu.mk
|
||||||
|
|
||||||
kernel: $(kernel)
|
kernel: $(KERNEL)
|
||||||
|
|
|
||||||
|
|
@ -4,31 +4,40 @@ Kernel from scratch (KFS) series of projects at Ecole 42 !
|
||||||
|
|
||||||
# building
|
# building
|
||||||
|
|
||||||
|
`git submodule udpate --init`
|
||||||
|
|
||||||
- `nasm` compiles the bootcode
|
- `nasm` compiles the bootcode
|
||||||
- `ld` links the bootcode and rust binary
|
- `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
|
- `xargo` builds rust code
|
||||||
|
|
||||||
See `.travis.yml` to get an ubuntu environment ready
|
See `.travis.yml` to get an ubuntu environment ready
|
||||||
on archlinux `pacman -S rustup make grub xorriso mtools binutils gcc qemu`
|
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
|
#### 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 component add rust-src
|
||||||
|
rustup override add nightly
|
||||||
|
rustup default nightly
|
||||||
cargo install xargo
|
cargo install xargo
|
||||||
```
|
```
|
||||||
|
|
||||||
# running
|
# running
|
||||||
|
|
||||||
- `make iso` builds a bootable iso with grub
|
- `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
|
# todo
|
||||||
|
|
||||||
- remove assembly for a pure rust entry point
|
- 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
|
# inspiration
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
grub-cfg := src/arch/$(ARCH)/grub.cfg
|
grub-cfg := src/arch/$(ARCH)/grub.cfg
|
||||||
isodir := build/isofiles
|
isodir := build/isofiles
|
||||||
|
|
||||||
$(ISO): $(kernel) $(grub-cfg) Makefile
|
$(ISO): $(KERNEL) $(grub-cfg) Makefile
|
||||||
@mkdir -p $(isodir)/boot/grub
|
@mkdir -p $(isodir)/boot/grub
|
||||||
@cp $(grub-cfg) $(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
|
grub-mkrescue -o $@ $(isodir) 2>/dev/null
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,7 @@ qemu:
|
||||||
|
|
||||||
qemu-gdb:
|
qemu-gdb:
|
||||||
gdb -q\
|
gdb -q\
|
||||||
-symbols "$(kernel)" \
|
-symbols "$(KERNEL)" \
|
||||||
-ex "target remote :$(QEMU_GDB_PORT)"\
|
-ex "target remote :$(QEMU_GDB_PORT)"\
|
||||||
-ex "set arch i386"
|
-ex "set arch i386"
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,10 @@
|
||||||
pub use self::slab::Allocator;
|
// pub use self::ALLOCATOR;
|
||||||
mod slab;
|
|
||||||
|
|
||||||
use x86::*;
|
|
||||||
use x86::structures::paging::*;
|
use x86::structures::paging::*;
|
||||||
use arch::x86::paging::*;
|
use arch::x86::paging::*;
|
||||||
|
|
||||||
fn map_heap(active_table: &mut ActivePageTable) {
|
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 {
|
for page in ::KERNEL_HEAP_RANGE {
|
||||||
active_table.map(page, PageTableFlags::WRITABLE);
|
active_table.map(page, PageTableFlags::WRITABLE);
|
||||||
}
|
}
|
||||||
|
|
@ -20,5 +18,10 @@ pub unsafe fn init(active_table: &mut ActivePageTable) {
|
||||||
map_heap(active_table);
|
map_heap(active_table);
|
||||||
|
|
||||||
//slab allocator
|
//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!();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -54,7 +54,7 @@ pub unsafe extern "C" fn x86_rust_start(multiboot_info_addr: usize) {
|
||||||
// set up pic, pit
|
// set up pic, pit
|
||||||
devices::init();
|
devices::init();
|
||||||
|
|
||||||
// primary CPU entry point
|
// primary CPU entry point, architutecture independant now.
|
||||||
::kmain();
|
::kmain();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,8 @@
|
||||||
#![feature(thread_local)]
|
#![feature(thread_local)]
|
||||||
// home made heap
|
// home made heap
|
||||||
#![feature(alloc)]
|
#![feature(alloc)]
|
||||||
|
#![feature(alloc_error_handler)]
|
||||||
#![feature(allocator_api)]
|
#![feature(allocator_api)]
|
||||||
#![feature(global_allocator)]
|
|
||||||
// x86 specific
|
// x86 specific
|
||||||
#![feature(abi_x86_interrupt)]
|
#![feature(abi_x86_interrupt)]
|
||||||
|
|
||||||
|
|
@ -27,25 +27,16 @@ extern crate spin;
|
||||||
// used by arch/x86, need conditional compilation here
|
// used by arch/x86, need conditional compilation here
|
||||||
extern crate x86;
|
extern crate x86;
|
||||||
|
|
||||||
/// 80x25 terminal driver
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
pub mod vga;
|
pub mod vga;
|
||||||
/// PS/2 detection and processing
|
|
||||||
pub mod keyboard;
|
pub mod keyboard;
|
||||||
/// simplisitc kernel commands
|
|
||||||
pub mod console;
|
pub mod console;
|
||||||
/// ACPI self contained module
|
|
||||||
pub mod acpi;
|
pub mod acpi;
|
||||||
/// Heap allocators
|
|
||||||
pub mod allocator;
|
pub mod allocator;
|
||||||
/// Memory management
|
|
||||||
pub mod memory;
|
pub mod memory;
|
||||||
/// arch specific entry points
|
|
||||||
pub mod arch;
|
pub mod arch;
|
||||||
pub use arch::x86::consts::*;
|
pub use arch::x86::consts::*;
|
||||||
/// concurrency management
|
|
||||||
pub mod scheduling;
|
pub mod scheduling;
|
||||||
/// uptime counting
|
|
||||||
pub mod time;
|
pub mod time;
|
||||||
|
|
||||||
/// kernel entry point. arch module is responsible for
|
/// kernel entry point. arch module is responsible for
|
||||||
|
|
@ -66,15 +57,14 @@ pub fn kmain() -> ! {
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn eh_personality() {}
|
pub extern "C" fn eh_personality() {}
|
||||||
|
|
||||||
#[lang = "panic_fmt"]
|
#[panic_handler]
|
||||||
#[no_mangle]
|
#[no_mangle]
|
||||||
pub extern "C" fn panic_fmt(fmt: core::fmt::Arguments, file: &'static str, line: u32) -> ! {
|
pub extern "C" fn panic_fmt(info: &core::panic::PanicInfo) -> ! {
|
||||||
println!("PANIC: {}", fmt);
|
println!("{}", info);
|
||||||
println!("FILE: {}", file);
|
|
||||||
println!("LINE: {}", line);
|
|
||||||
flush!();
|
flush!();
|
||||||
loop {}
|
loop {}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[global_allocator]
|
#[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();
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
//! Recycle allocator
|
//! Recycle allocator
|
||||||
//! Uses freed frames if possible, then uses inner allocator
|
//! Uses freed frames if possible, then uses inner allocator
|
||||||
|
|
||||||
use alloc::Vec;
|
use alloc::vec::Vec;
|
||||||
use x86::*;
|
use x86::*;
|
||||||
use x86::structures::paging::*;
|
use x86::structures::paging::*;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
//! processes...
|
//! processes...
|
||||||
//! however it's stupid simple to implement!
|
//! however it's stupid simple to implement!
|
||||||
|
|
||||||
use alloc::VecDeque;
|
use alloc::collections::vec_deque::VecDeque;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
// use super::process::*;
|
// use super::process::*;
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
//!
|
//!
|
||||||
//! inspired from https://wiki.osdev.org/Blocking_Process
|
//! inspired from https://wiki.osdev.org/Blocking_Process
|
||||||
|
|
||||||
use alloc::VecDeque;
|
use alloc::collections::vec_deque::VecDeque;
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
struct Sleeper {
|
struct Sleeper {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue