Refactor to move alloc_kernel in tree, and move io into syscall

This commit is contained in:
Jeremy Soller
2017-01-09 20:35:54 -07:00
parent 1c7b5680a4
commit e20135575c
9 changed files with 78 additions and 11 deletions

8
alloc_kernel/Cargo.toml Normal file
View File

@@ -0,0 +1,8 @@
[package]
authors = ["Philipp Oppermann <dev@phil-opp.com>"]
name = "alloc_kernel"
version = "0.1.0"
[dependencies]
linked_list_allocator = { git = "https://github.com/phil-opp/linked-list-allocator.git" }
spin = "*"

62
alloc_kernel/src/lib.rs Normal file
View File

@@ -0,0 +1,62 @@
#![feature(allocator)]
#![feature(const_fn)]
#![allocator]
#![no_std]
use spin::Mutex;
use linked_list_allocator::Heap;
extern crate spin;
extern crate linked_list_allocator;
static HEAP: Mutex<Option<Heap>> = Mutex::new(None);
pub unsafe fn init(offset: usize, size: usize) {
*HEAP.lock() = Some(Heap::new(offset, size));
}
#[no_mangle]
pub extern fn __rust_allocate(size: usize, align: usize) -> *mut u8 {
if let Some(ref mut heap) = *HEAP.lock() {
heap.allocate_first_fit(size, align).expect("out of memory")
} else {
panic!("__rust_allocate: heap not initialized");
}
}
#[no_mangle]
pub extern fn __rust_deallocate(ptr: *mut u8, size: usize, align: usize) {
if let Some(ref mut heap) = *HEAP.lock() {
unsafe { heap.deallocate(ptr, size, align) };
} else {
panic!("__rust_deallocate: heap not initialized");
}
}
#[no_mangle]
pub extern fn __rust_usable_size(size: usize, _align: usize) -> usize {
size
}
#[no_mangle]
pub extern fn __rust_reallocate_inplace(_ptr: *mut u8, size: usize,
_new_size: usize, _align: usize) -> usize
{
size
}
#[no_mangle]
pub extern fn __rust_reallocate(ptr: *mut u8, size: usize, new_size: usize,
align: usize) -> *mut u8 {
use core::{ptr, cmp};
// from: https://github.com/rust-lang/rust/blob/
// c66d2380a810c9a2b3dbb4f93a830b101ee49cc2/
// src/liballoc_system/lib.rs#L98-L101
let new_ptr = __rust_allocate(new_size, align);
unsafe { ptr::copy(ptr, new_ptr, cmp::min(size, new_size)) };
__rust_deallocate(ptr, size, align);
new_ptr
}

View File

@@ -3,6 +3,6 @@ name = "arch_arm"
version = "0.1.0"
[dependencies]
alloc_kernel = { path = "../../alloc_kernel" }
bitflags = "*"
hole_list_allocator = { path = "../../../crates/hole_list_allocator"}
spin = "*"

View File

@@ -5,7 +5,7 @@
#![feature(naked_functions)]
#![no_std]
extern crate hole_list_allocator as allocator;
extern crate alloc_kernel as allocator;
#[macro_use]
extern crate bitflags;
extern crate spin;

View File

@@ -3,12 +3,11 @@ name = "arch_x86_64"
version = "0.1.0"
[dependencies]
alloc_kernel = { path = "../../alloc_kernel/" }
bitflags = "*"
hole_list_allocator = { path = "../../../crates/hole_list_allocator/" }
io = { path = "../../../crates/io/" }
raw-cpuid = { git = "https://github.com/gz/rust-cpuid" }
spin = "*"
redox_syscall = { path = "../../../syscall/" }
redox_syscall = { git = "https://github.com/redox-os/syscall" }
[dependencies.x86]
version = "0.7"

View File

@@ -1,4 +1,4 @@
use io::{Io, Pio};
use syscall::io::{Io, Pio};
use time;
pub fn init() {

View File

@@ -1,7 +1,7 @@
use core::fmt::{self, Write};
use spin::Mutex;
use io::{Io, Pio, ReadOnly};
use syscall::io::{Io, Pio, ReadOnly};
pub static COM1: Mutex<SerialPort> = Mutex::new(SerialPort::new(0x3F8));
pub static COM2: Mutex<SerialPort> = Mutex::new(SerialPort::new(0x2F8));

View File

@@ -12,11 +12,9 @@
#![feature(unique)]
#![no_std]
extern crate hole_list_allocator as allocator;
extern crate alloc_kernel as allocator;
#[macro_use]
extern crate bitflags;
extern crate io;
extern crate spin;
extern crate syscall;
pub extern crate x86;

View File

@@ -1,4 +1,4 @@
use io::{Io, Pio};
use syscall::io::{Io, Pio};
#[no_mangle]
pub unsafe extern fn kstop() -> ! {