Commit b5b236c2 authored by Stefan Lankes's avatar Stefan Lankes
Browse files

use the orginal crate multiboot and x86 instead of a modified version

parent 9dc5d531
......@@ -17,7 +17,6 @@ exclude = ["/loader/*", "/examples/*", "/.travis.yml", "/.gitlab-ci.yml", ".giti
[badges]
travis-ci = { repository = "hermitcore/libhermit-rs" }
gitlab = { repository = "https://git.rwth-aachen.de/acs/public/hermitcore/libhermit-rs" }
[lib]
crate-type = ["staticlib"]
......@@ -41,17 +40,15 @@ default-features = false
[dependencies.smoltcp]
version = "0.5"
optional = true
#git = "https://github.com/hermitcore/smoltcp.git"
default-features = false
features = ["log", "verbose", "alloc", "socket-udp", "socket-tcp", "proto-ipv4"]
# for debugging: "log", "verbose"
[target.'cfg(target_arch = "x86_64")'.dependencies.hermit-multiboot]
git = "https://github.com/hermitcore/multiboot.git"
[target.'cfg(target_arch = "x86_64")'.dependencies.multiboot]
version = "0.*"
[target.'cfg(target_arch = "x86_64")'.dependencies.x86]
git = "https://github.com/hermitcore/rust-x86.git"
branch = "hermit"
version = "0.*"
default-features = false
[package.metadata.cargo-xbuild]
......
[package]
name = "hermit-loader"
version = "0.2.3"
version = "0.2.4"
authors = ["Stefan Lankes <slankes@eonerc.rwth-aachen.de>", "Colin Finck <colin.finck@rwth-aachen.de>"]
license = "MIT/Apache-2.0"
publish = false
[dependencies]
bitflags = "1.0.3"
bitflags = "1.0.*"
[target.'cfg(target_arch = "x86_64")'.dependencies.hermit-multiboot]
git = "https://github.com/hermitcore/multiboot.git"
[dependencies.lazy_static]
version = "1.0.1"
features = ["spin_no_std"]
[target.'cfg(target_arch = "x86_64")'.dependencies.multiboot]
version = "0.*"
[target.'cfg(target_arch = "x86_64")'.dependencies.x86]
git = "https://github.com/hermitcore/rust-x86.git"
branch = "hermit"
version = "0.*"
default-features = false
[package.metadata.cargo-xbuild]
......
......@@ -11,9 +11,9 @@ pub mod serial;
use arch::x86_64::paging::{BasePageSize, LargePageSize, PageSize, PageTableEntryFlags};
use arch::x86_64::serial::SerialPort;
use core::{mem, ptr};
use core::{mem, ptr, slice};
use elf::*;
use hermit_multiboot::Multiboot;
use multiboot::Multiboot;
use physicalmem;
extern "C" {
......@@ -56,10 +56,15 @@ struct KernelHeader {
// VARIABLES
static COM1: SerialPort = SerialPort::new(SERIAL_PORT_ADDRESS);
lazy_static! {
static ref MULTIBOOT: Multiboot = unsafe { Multiboot::new(mb_info) };
fn paddr_to_slice<'a>(p: multiboot::PAddr, sz: usize) -> Option<&'a [u8]> {
unsafe {
let ptr = mem::transmute(p);
Some(slice::from_raw_parts(ptr, sz))
}
}
//static mut MULTIBOOT: Multiboot<'static> = unsafe { Multiboot::new(mb_info, paddr_to_slice) };
// FUNCTIONS
pub fn message_output_init() {
COM1.init(SERIAL_PORT_BAUDRATE);
......@@ -77,15 +82,19 @@ pub unsafe fn find_kernel() -> usize {
paging::map::<BasePageSize>(page_address, page_address, 1, PageTableEntryFlags::empty());
// Load the Multiboot information and identity-map the modules information.
let modules_address = MULTIBOOT
.modules_address()
.expect("Could not find module information in the Multiboot information");
let multiboot = Multiboot::new(mb_info as u64, paddr_to_slice).unwrap();
let modules_address = multiboot
.modules()
.expect("Could not find a memory map in the Multiboot information")
.next()
.expect("Could not first map address")
.start as usize;
let page_address = align_down!(modules_address, BasePageSize::SIZE);
paging::map::<BasePageSize>(page_address, page_address, 1, PageTableEntryFlags::empty());
// Iterate through all modules.
// Collect the start address of the first module and the highest end address of all modules.
let modules = MULTIBOOT.modules().unwrap();
let modules = multiboot.modules().unwrap();
let mut found_module = false;
let mut start_address = 0;
let mut end_address = 0;
......@@ -94,11 +103,11 @@ pub unsafe fn find_kernel() -> usize {
found_module = true;
if start_address == 0 {
start_address = m.start_address();
start_address = m.start as usize;
}
if m.end_address() > end_address {
end_address = m.end_address();
if m.end as usize > end_address {
end_address = m.end as usize;
}
}
......@@ -182,12 +191,15 @@ pub unsafe fn boot_kernel(
ptr::write_volatile(&mut kernel_header.uartport, SERIAL_PORT_ADDRESS);
ptr::write_volatile(&mut kernel_header.uhyve, 0);
if let Some(address) = MULTIBOOT.command_line_address() {
let multiboot = Multiboot::new(mb_info as u64, paddr_to_slice).unwrap();
if let Some(cmdline) = multiboot.command_line() {
let address = cmdline.as_ptr();
// Identity-map the command line.
let page_address = align_down!(address, BasePageSize::SIZE);
let page_address = align_down!(address as usize, BasePageSize::SIZE);
paging::map::<BasePageSize>(page_address, page_address, 1, PageTableEntryFlags::empty());
let cmdline = MULTIBOOT.command_line().unwrap();
//let cmdline = multiboot.command_line().unwrap();
ptr::write_volatile(&mut kernel_header.cmdline, address as u64);
ptr::write_volatile(&mut kernel_header.cmdsize, cmdline.len() as u64);
}
......
......@@ -19,10 +19,7 @@
extern crate bitflags;
#[cfg(target_arch = "x86_64")]
extern crate hermit_multiboot;
#[macro_use]
extern crate lazy_static;
extern crate multiboot;
#[cfg(target_arch = "x86_64")]
extern crate x86;
......
......@@ -120,9 +120,9 @@ pub fn init() {
// Store the address to the PerCoreVariables structure allocated for this core in GS.
let address = ptr::read_volatile(&KERNEL_HEADER.current_percore_address);
if address == 0 {
wrmsr(IA32_KERNEL_GS_BASE, &PERCORE as *const _ as u64);
wrmsr(IA32_KERNEL_GSBASE, &PERCORE as *const _ as u64);
} else {
wrmsr(IA32_KERNEL_GS_BASE, address as u64);
wrmsr(IA32_KERNEL_GSBASE, address as u64);
}
}
}
......@@ -729,7 +729,7 @@ pub fn detect_frequency() {
pub fn print_information() {
infoheader!(" CPU INFORMATION ");
let cpuid = CpuId::new();
let extended_function_info = cpuid
.get_extended_function_info()
......
......@@ -10,6 +10,15 @@ pub mod physicalmem;
pub mod virtualmem;
pub use self::paging::init_page_tables;
use core::mem;
use core::slice;
fn paddr_to_slice<'a>(p: multiboot::PAddr, sz: usize) -> Option<&'a [u8]> {
unsafe {
let ptr = mem::transmute(p);
Some(slice::from_raw_parts(ptr, sz))
}
}
pub fn init() {
paging::init();
......
......@@ -12,13 +12,14 @@ use arch::x86_64::kernel::get_mbinfo;
use arch::x86_64::kernel::irq;
use arch::x86_64::kernel::is_uhyve;
use arch::x86_64::kernel::processor;
use arch::x86_64::mm::paddr_to_slice;
use arch::x86_64::mm::physicalmem;
use core::marker::PhantomData;
use core::mem;
use core::ptr;
use environment;
use hermit_multiboot::Multiboot;
use mm;
use multiboot::Multiboot;
use scheduler;
use x86::controlregs;
use x86::irq::PageFaultError;
......@@ -729,10 +730,13 @@ pub fn init_page_tables() {
identity_map(mb_info, mb_info);
// Map the "Memory Map" information too.
let mb = Multiboot::new(mb_info);
let mb = Multiboot::new(mb_info as u64, paddr_to_slice).unwrap();
let memory_map_address = mb
.memory_map_address()
.expect("Could not find a memory map in the Multiboot information");
.memory_regions()
.expect("Could not find a memory map in the Multiboot information")
.next()
.expect("Could not first map address")
.base_address() as usize;
identity_map(memory_map_address, memory_map_address);
}
......
......@@ -6,12 +6,13 @@
// copied, modified, or distributed except according to those terms.
use arch::x86_64::kernel::{get_limit, get_mbinfo};
use arch::x86_64::mm::paddr_to_slice;
use arch::x86_64::mm::paging::{BasePageSize, PageSize};
use collections::Node;
use core::sync::atomic::{AtomicUsize, Ordering};
use hermit_multiboot::Multiboot;
use mm;
use mm::freelist::{FreeList, FreeListEntry};
use multiboot::{MemoryType, Multiboot};
use synch::spinlock::*;
static PHYSICAL_FREE_LIST: SpinlockIrqSave<FreeList> = SpinlockIrqSave::new(FreeList::new());
......@@ -23,28 +24,30 @@ fn detect_from_multiboot_info() -> Result<(), ()> {
return Err(());
}
let mb = unsafe { Multiboot::new(mb_info) };
let mb = unsafe { Multiboot::new(mb_info as u64, paddr_to_slice).unwrap() };
let all_regions = mb
.memory_map()
.memory_regions()
.expect("Could not find a memory map in the Multiboot information");
let ram_regions = all_regions
.filter(|m| m.is_available() && m.base_address() + m.length() > mm::kernel_end_address());
let ram_regions = all_regions.filter(|m| {
m.memory_type() == MemoryType::Available
&& m.base_address() + m.length() > mm::kernel_end_address() as u64
});
let mut found_ram = false;
for m in ram_regions {
found_ram = true;
let start_address = if m.base_address() <= mm::kernel_start_address() {
let start_address = if m.base_address() <= mm::kernel_start_address() as u64 {
mm::kernel_end_address()
} else {
m.base_address()
m.base_address() as usize
};
let entry = Node::new(FreeListEntry {
start: start_address,
end: m.base_address() + m.length(),
end: (m.base_address() + m.length()) as usize,
});
let _ = TOTAL_MEMORY.fetch_add(m.base_address() + m.length(), Ordering::SeqCst);
let _ = TOTAL_MEMORY.fetch_add((m.base_address() + m.length()) as usize, Ordering::SeqCst);
PHYSICAL_FREE_LIST.lock().list.push(entry);
}
......
......@@ -46,7 +46,7 @@ extern crate alloc;
#[macro_use]
extern crate bitflags;
#[cfg(target_arch = "x86_64")]
extern crate hermit_multiboot;
extern crate multiboot;
#[cfg(target_arch = "x86_64")]
extern crate x86;
#[macro_use]
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment