diff --git a/Cargo.toml b/Cargo.toml index 7308c8d21bd4eaee0471d92b5fe01cec78bf4e8e..56cd67222aabe2954ba41dca6234b456f7050892 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -9,8 +9,10 @@ path = "src/lib.rs" crate-type = ["staticlib"] [dependencies] +alloc_kernel = { path = "alloc_kernel" } bitflags = "0.7" spin = "0.4" +raw-cpuid = { git = "https://github.com/gz/rust-cpuid", branch = "master" } redox_syscall = "0.1" [dependencies.goblin] @@ -18,14 +20,9 @@ verion = "0.0.8" default-features = false features = ["elf32", "elf64"] -[dev-dependencies] -arch_test = { path = "arch/test" } - -[target.'cfg(target_arch = "arm")'.dependencies] -arch_arm = { path = "arch/arm" } - -[target.'cfg(target_arch = "x86_64")'.dependencies] -arch_x86_64 = { path = "arch/x86_64" } +[dependencies.x86] +version = "0.7" +default-features = false [features] default = [] diff --git a/arch/arm/Cargo.toml b/arch/arm/Cargo.toml deleted file mode 100644 index 3ad97bad1a3fffbdd37b5bdaa539ada9d2cbd652..0000000000000000000000000000000000000000 --- a/arch/arm/Cargo.toml +++ /dev/null @@ -1,8 +0,0 @@ -[package] -name = "arch_arm" -version = "0.1.0" - -[dependencies] -alloc_kernel = { path = "../../alloc_kernel" } -bitflags = "0.7" -spin = "0.4" diff --git a/arch/arm/src/context.rs b/arch/arm/src/context.rs deleted file mode 100644 index db711c30e28fc284a8d698514322763dd363649e..0000000000000000000000000000000000000000 --- a/arch/arm/src/context.rs +++ /dev/null @@ -1,9 +0,0 @@ -#[derive(Debug)] -pub struct Context; - -impl Context { - pub fn new() -> Self { - Context - } -} - diff --git a/arch/arm/src/externs.rs b/arch/arm/src/externs.rs deleted file mode 100644 index 3b87427fe812aa2891afca20afe019dc7c011286..0000000000000000000000000000000000000000 --- a/arch/arm/src/externs.rs +++ /dev/null @@ -1,70 +0,0 @@ -/// Memcpy -/// -/// Copy N bytes of memory from one location to another. -#[no_mangle] -pub unsafe extern fn memcpy(dest: *mut u8, src: *const u8, - n: usize) -> *mut u8 { - let mut i = 0; - while i < n { - *dest.offset(i as isize) = *src.offset(i as isize); - i += 1; - } - - dest -} - -/// Memmove -/// -/// Copy N bytes of memory from src to dest. The memory areas may overlap. -#[no_mangle] -pub unsafe extern fn memmove(dest: *mut u8, src: *const u8, - n: usize) -> *mut u8 { - if src < dest as *const u8 { - let mut i = n; - while i != 0 { - i -= 1; - *dest.offset(i as isize) = *src.offset(i as isize); - } - } else { - let mut i = 0; - while i < n { - *dest.offset(i as isize) = *src.offset(i as isize); - i += 1; - } - } - - dest -} - -/// Memset -/// -/// Fill a block of memory with a specified value. -#[no_mangle] -pub unsafe extern fn memset(s: *mut u8, c: i32, n: usize) -> *mut u8 { - let mut i = 0; - while i < n { - *s.offset(i as isize) = c as u8; - i += 1; - } - - s -} - -/// Memcmp -/// -/// Compare two blocks of memory. -#[no_mangle] -pub unsafe extern fn memcmp(s1: *const u8, s2: *const u8, n: usize) -> i32 { - let mut i = 0; - - while i < n { - let a = *s1.offset(i as isize); - let b = *s2.offset(i as isize); - if a != b { - return a as i32 - b as i32 - } - i += 1; - } - - 0 -} diff --git a/arch/arm/src/interrupt.rs b/arch/arm/src/interrupt.rs deleted file mode 100644 index 6d7d460cc9a9dda5ca81861def356b6fc7460cf7..0000000000000000000000000000000000000000 --- a/arch/arm/src/interrupt.rs +++ /dev/null @@ -1,30 +0,0 @@ -//! Interrupt instructions - -/// Clear interrupts -#[inline(always)] -pub unsafe fn disable() { -} - -/// Set interrupts -#[inline(always)] -pub unsafe fn enable() { -} - -/// Set interrupts and halt -#[inline(always)] -pub unsafe fn enable_and_halt() { - halt(); -} - -/// Halt instruction -#[inline(always)] -pub unsafe fn halt() { - //asm!("wfi" : : : : "volatile"); - asm!("nop" : : : : "volatile"); -} - -/// Get a stack trace -//TODO: Check for stack being mapped before dereferencing -#[inline(never)] -pub unsafe fn stack_trace() { -} diff --git a/arch/arm/src/lib.rs b/arch/arm/src/lib.rs deleted file mode 100644 index 60a14718298693346d9ce23ef676b4223dd53e91..0000000000000000000000000000000000000000 --- a/arch/arm/src/lib.rs +++ /dev/null @@ -1,39 +0,0 @@ -//! Architecture support for ARM - -#![feature(asm)] -#![feature(lang_items)] -#![feature(naked_functions)] -#![no_std] - -extern crate alloc_kernel as allocator; -#[macro_use] -extern crate bitflags; -extern crate spin; - -/// Print to console -#[macro_export] -macro_rules! print { - ($($arg:tt)*) => ({}); -} - -/// Print with new line to console -#[macro_export] -macro_rules! println { - ($fmt:expr) => (print!(concat!($fmt, "\n"))); - ($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*)); -} - -/// Context switching -pub mod context; - -/// Memset, memcpy, etc. -pub mod externs; - -/// Interrupt handling -pub mod interrupt; - -/// Panic support -pub mod panic; - -/// Initialization function -pub mod start; diff --git a/arch/arm/src/linker.ld b/arch/arm/src/linker.ld deleted file mode 100644 index 71fd23efaaee02018a0d22f86d30b30dc22bd505..0000000000000000000000000000000000000000 --- a/arch/arm/src/linker.ld +++ /dev/null @@ -1,60 +0,0 @@ -ENTRY(kstart) -OUTPUT_ARCH(arm) -OUTPUT_FORMAT(elf32-littlearm) - -KERNEL_OFFSET = 0; - -SECTIONS { - . = KERNEL_OFFSET; - - .text : AT(ADDR(.text) - KERNEL_OFFSET) { - __text_start = .; - *(.text*) - . = ALIGN(4096); - __text_end = .; - } - - .rodata : AT(ADDR(.rodata) - KERNEL_OFFSET) { - __rodata_start = .; - *(.rodata*) - . = ALIGN(4096); - __rodata_end = .; - } - - .data : AT(ADDR(.data) - KERNEL_OFFSET) { - __data_start = .; - *(.data*) - . = ALIGN(4096); - __data_end = .; - } - - .tdata : AT(ADDR(.tdata) - KERNEL_OFFSET) { - __tdata_start = .; - *(.tdata*) - . = ALIGN(4096); - __tdata_end = .; - __tbss_start = .; - *(.tbss*) - . += 8; - . = ALIGN(4096); - __tbss_end = .; - } - - .bss : AT(ADDR(.bss) - KERNEL_OFFSET) { - __bss_start = .; - *(.bss*) - . = ALIGN(4096); - __bss_end = .; - } - - __end = .; - - /DISCARD/ : { - *(.comment*) - *(.debug*) - *(.eh_frame*) - *(.gcc_except_table*) - *(.note*) - *(.rel.eh_frame*) - } -} diff --git a/arch/arm/src/panic.rs b/arch/arm/src/panic.rs deleted file mode 100644 index 2acb38ed8cfaf624cdeb4ddf1545971fb191930e..0000000000000000000000000000000000000000 --- a/arch/arm/src/panic.rs +++ /dev/null @@ -1,38 +0,0 @@ -//! Intrinsics for panic handling - -use interrupt; - -#[cfg(not(test))] -#[lang = "eh_personality"] -extern "C" fn eh_personality() {} - -#[cfg(not(test))] -/// Required to handle panics -#[lang = "panic_fmt"] -extern "C" fn panic_fmt(fmt: ::core::fmt::Arguments, file: &str, line: u32) -> ! { - println!("PANIC: {}", fmt); - println!("FILE: {}", file); - println!("LINE: {}", line); - - unsafe { interrupt::stack_trace(); } - - println!("HALT"); - loop { - unsafe { interrupt::halt(); } - } -} - -#[allow(non_snake_case)] -#[no_mangle] -/// Required to handle panics -pub extern "C" fn _Unwind_Resume() -> ! { - loop { - unsafe { interrupt::halt(); } - } -} - -/// Required for linker -#[no_mangle] -pub extern "C" fn __aeabi_unwind_cpp_pr0() { - loop {} -} diff --git a/arch/arm/src/start.rs b/arch/arm/src/start.rs deleted file mode 100644 index b9abbe67ad81675d5b7963f7036da44085bc58ff..0000000000000000000000000000000000000000 --- a/arch/arm/src/start.rs +++ /dev/null @@ -1,27 +0,0 @@ -const SERIAL_BASE: *mut u8 = 0x16000000 as *mut u8; -const SERIAL_FLAG_REGISTER: *const u8 = 0x16000018 as *const u8; -const SERIAL_BUFFER_FULL: u8 = (1 << 5); - -unsafe fn putc (c: u8) -{ - /* Wait until the serial buffer is empty */ - while *SERIAL_FLAG_REGISTER & SERIAL_BUFFER_FULL == SERIAL_BUFFER_FULL {} - - /* Put our character, c, into the serial buffer */ - *SERIAL_BASE = c; -} - -unsafe fn puts(string: &str) -{ - for b in string.bytes() { - putc(b); - } -} - -#[no_mangle] -#[naked] -pub unsafe extern fn kstart() -> ! { - asm!("mov sp, 0x18000" : : : : "volatile"); - puts("TEST\r\n"); - loop {} -} diff --git a/arch/test/Cargo.toml b/arch/test/Cargo.toml deleted file mode 100644 index 1900c7d558a89c41ca4844a7fe4b3a5dd35046ff..0000000000000000000000000000000000000000 --- a/arch/test/Cargo.toml +++ /dev/null @@ -1,3 +0,0 @@ -[package] -name = "arch_test" -version = "0.1.0" diff --git a/arch/test/src/interrupt.rs b/arch/test/src/interrupt.rs deleted file mode 100644 index 9e49020b6e9a0e394ff085711b8886183113a230..0000000000000000000000000000000000000000 --- a/arch/test/src/interrupt.rs +++ /dev/null @@ -1,43 +0,0 @@ -//! Interrupt instructions - -static mut INTERRUPTS_ENABLED: bool = false; - -/// Clear interrupts -#[inline(always)] -pub unsafe fn disable() { - println!("CLEAR INTERRUPTS"); - INTERRUPTS_ENABLED = false; -} - -/// Set interrupts -#[inline(always)] -pub unsafe fn enable() { - println!("SET INTERRUPTS"); - INTERRUPTS_ENABLED = true; -} - -/// Halt instruction -#[inline(always)] -pub unsafe fn halt() { - assert!(INTERRUPTS_ENABLED); - ::std::thread::yield_now(); -} - -/// Pause instruction -#[inline(always)] -pub unsafe fn pause() { - -} - -/// Set interrupts and nop -#[inline(always)] -pub unsafe fn enable_and_nop() { - enable(); -} - -/// Set interrupts and halt -#[inline(always)] -pub unsafe fn enable_and_halt() { - enable(); - halt(); -} diff --git a/arch/test/src/lib.rs b/arch/test/src/lib.rs deleted file mode 100644 index 8a155cd6185fc932179af9f4a6940aba550728a5..0000000000000000000000000000000000000000 --- a/arch/test/src/lib.rs +++ /dev/null @@ -1,43 +0,0 @@ -//! Architecture support for testing - -pub use std::io; - -/// Print to console -#[macro_export] -macro_rules! print { - ($($arg:tt)*) => ({ - use $crate::io::Write; - let _ = write!($crate::io::stdout(), $($arg)*); - }); -} - -/// Print with new line to console -#[macro_export] -macro_rules! println { - ($fmt:expr) => (print!(concat!($fmt, "\n"))); - ($fmt:expr, $($arg:tt)*) => (print!(concat!($fmt, "\n"), $($arg)*)); -} - -/// Create an interrupt function that can safely run rust code -#[macro_export] -macro_rules! interrupt { - ($name:ident, $func:block) => { - pub unsafe extern fn $name () { - unsafe fn inner() { - $func - } - - // Call inner rust function - inner(); - } - }; -} - -/// Interrupt instructions -pub mod interrupt; - -/// Initialization and main function -pub mod main; - -/// Time functions -pub mod time; diff --git a/arch/test/src/main.rs b/arch/test/src/main.rs deleted file mode 100644 index 3f93ffbbdd5411c52344efde8e01e14c50493b04..0000000000000000000000000000000000000000 --- a/arch/test/src/main.rs +++ /dev/null @@ -1,11 +0,0 @@ -/// This function is where the kernel sets up IRQ handlers -/// It is increcibly unsafe, and should be minimal in nature - -extern { - fn kmain() -> !; -} - -#[no_mangle] -pub unsafe extern fn kstart() -> ! { - kmain(); -} diff --git a/arch/test/src/time.rs b/arch/test/src/time.rs deleted file mode 100644 index 6f7889d7d51dff6f6122753188972a3aebf149ee..0000000000000000000000000000000000000000 --- a/arch/test/src/time.rs +++ /dev/null @@ -1,7 +0,0 @@ -pub fn monotonic() -> (u64, u64) { - (0, 0) -} - -pub fn realtime() -> (u64, u64) { - (0, 0) -} diff --git a/arch/x86_64/Cargo.toml b/arch/x86_64/Cargo.toml deleted file mode 100644 index dbd2c5c567d6fbdb69786735fe15b22123f66edf..0000000000000000000000000000000000000000 --- a/arch/x86_64/Cargo.toml +++ /dev/null @@ -1,14 +0,0 @@ -[package] -name = "arch_x86_64" -version = "0.1.0" - -[dependencies] -alloc_kernel = { path = "../../alloc_kernel/" } -bitflags = "0.7" -raw-cpuid = { git = "https://github.com/gz/rust-cpuid", branch = "master" } -spin = "0.4" -redox_syscall = "0.1" - -[dependencies.x86] -version = "0.7" -default-features = false diff --git a/arch/x86_64/src/lib.rs b/arch/x86_64/src/lib.rs deleted file mode 100644 index e9470516bec4327fefa3f24a2253a34972be6c1b..0000000000000000000000000000000000000000 --- a/arch/x86_64/src/lib.rs +++ /dev/null @@ -1,69 +0,0 @@ -//! Architecture support for x86_64 - -//#![deny(warnings)] -#![deny(unused_must_use)] -#![feature(asm)] -#![feature(concat_idents)] -#![feature(const_fn)] -#![feature(core_intrinsics)] -#![feature(drop_types_in_const)] -#![feature(lang_items)] -#![feature(naked_functions)] -#![feature(thread_local)] -#![feature(unique)] -#![no_std] - -extern crate alloc_kernel as allocator; -#[macro_use] -extern crate bitflags; -extern crate spin; -extern crate syscall; -pub extern crate x86; - -pub use consts::*; - -/// Macros like print, println, and interrupt -#[macro_use] -pub mod macros; - -/// Constants like memory locations -pub mod consts; - -/// ACPI table parsing -mod acpi; - -/// Console handling -pub mod console; - -/// Context switching -pub mod context; - -/// Devices -pub mod device; - -/// Global descriptor table -pub mod gdt; - -/// Interrupt descriptor table -mod idt; - -/// Interrupt instructions -pub mod interrupt; - -/// Memory management -pub mod memory; - -/// Paging -pub mod paging; - -/// Panic -pub mod panic; - -/// Initialization and start function -pub mod start; - -/// Shutdown function -pub mod stop; - -/// Time -pub mod time; diff --git a/arch/x86_64/src/linker.ld b/linkers/x86_64.ld similarity index 100% rename from arch/x86_64/src/linker.ld rename to linkers/x86_64.ld diff --git a/arch/x86_64/src/acpi/dmar/drhd.rs b/src/acpi/dmar/drhd.rs similarity index 100% rename from arch/x86_64/src/acpi/dmar/drhd.rs rename to src/acpi/dmar/drhd.rs diff --git a/arch/x86_64/src/acpi/dmar/mod.rs b/src/acpi/dmar/mod.rs similarity index 100% rename from arch/x86_64/src/acpi/dmar/mod.rs rename to src/acpi/dmar/mod.rs diff --git a/arch/x86_64/src/acpi/dsdt.rs b/src/acpi/dsdt.rs similarity index 92% rename from arch/x86_64/src/acpi/dsdt.rs rename to src/acpi/dsdt.rs index 0ed240846ad70c04c348df483618b512e08e1d40..67bcb7f96812b08992eee144b6bd08ec227d1b17 100644 --- a/arch/x86_64/src/acpi/dsdt.rs +++ b/src/acpi/dsdt.rs @@ -57,7 +57,7 @@ impl Dsdt { } } - let SLP_TYPa = (data[i] as u16) << 10; + let a = (data[i] as u16) << 10; i += 1; if i >= data.len() { return None; @@ -70,9 +70,9 @@ impl Dsdt { } } - let SLP_TYPb = (data[i] as u16) << 10; + let b = (data[i] as u16) << 10; - Some((SLP_TYPa, SLP_TYPb)) + Some((a, b)) } } diff --git a/arch/x86_64/src/acpi/fadt.rs b/src/acpi/fadt.rs similarity index 100% rename from arch/x86_64/src/acpi/fadt.rs rename to src/acpi/fadt.rs diff --git a/arch/x86_64/src/acpi/madt.rs b/src/acpi/madt.rs similarity index 100% rename from arch/x86_64/src/acpi/madt.rs rename to src/acpi/madt.rs diff --git a/arch/x86_64/src/acpi/mod.rs b/src/acpi/mod.rs similarity index 100% rename from arch/x86_64/src/acpi/mod.rs rename to src/acpi/mod.rs diff --git a/arch/x86_64/src/acpi/rsdt.rs b/src/acpi/rsdt.rs similarity index 100% rename from arch/x86_64/src/acpi/rsdt.rs rename to src/acpi/rsdt.rs diff --git a/arch/x86_64/src/acpi/sdt.rs b/src/acpi/sdt.rs similarity index 100% rename from arch/x86_64/src/acpi/sdt.rs rename to src/acpi/sdt.rs diff --git a/arch/x86_64/src/acpi/xsdt.rs b/src/acpi/xsdt.rs similarity index 100% rename from arch/x86_64/src/acpi/xsdt.rs rename to src/acpi/xsdt.rs diff --git a/arch/x86_64/src/console.rs b/src/console.rs similarity index 100% rename from arch/x86_64/src/console.rs rename to src/console.rs diff --git a/arch/x86_64/src/consts.rs b/src/consts.rs similarity index 100% rename from arch/x86_64/src/consts.rs rename to src/consts.rs diff --git a/arch/x86_64/src/context.rs b/src/context/arch/x86_64.rs similarity index 100% rename from arch/x86_64/src/context.rs rename to src/context/arch/x86_64.rs diff --git a/src/context/context.rs b/src/context/context.rs index 55af1ca0934538c3cad644401a2de65beaeaf184..51921216c1cada4c3aca99ac43991b23e8562050 100644 --- a/src/context/context.rs +++ b/src/context/context.rs @@ -3,9 +3,10 @@ use alloc::boxed::Box; use collections::{BTreeMap, Vec, VecDeque}; use spin::Mutex; -use arch; +use context::arch; use context::file::File; use context::memory::{Grant, Memory, SharedMemory, Tls}; +use device; use scheme::{SchemeNamespace, FileHandle}; use syscall::data::Event; use sync::{WaitMap, WaitQueue}; @@ -57,7 +58,7 @@ pub struct Context { /// Context should wake up at specified time pub wake: Option<(u64, u64)>, /// The architecture specific context - pub arch: arch::context::Context, + pub arch: arch::Context, /// Kernel FX - used to store SIMD and FPU registers on context switch pub kfx: Option<Box<[u8]>>, /// Kernel stack @@ -102,7 +103,7 @@ impl Context { waitpid: Arc::new(WaitMap::new()), pending: VecDeque::new(), wake: None, - arch: arch::context::Context::new(), + arch: arch::Context::new(), kfx: None, kstack: None, image: Vec::new(), @@ -206,7 +207,7 @@ impl Context { if cpu_id != ::cpu_id() { // Send IPI if not on current CPU // TODO: Make this more architecture independent - unsafe { arch::device::local_apic::LOCAL_APIC.ipi(cpu_id) }; + unsafe { device::local_apic::LOCAL_APIC.ipi(cpu_id) }; } } true diff --git a/src/context/list.rs b/src/context/list.rs index 11c25c221015b23169d596d41d5c901a3c947b78..1556e10c9bbd03acd49a4e695183f8801d6fbcee 100644 --- a/src/context/list.rs +++ b/src/context/list.rs @@ -3,9 +3,9 @@ use alloc::boxed::Box; use collections::BTreeMap; use core::mem; use core::sync::atomic::Ordering; +use paging; use spin::RwLock; -use arch; use syscall::error::{Result, Error, EAGAIN}; use super::context::{Context, ContextId}; @@ -76,7 +76,7 @@ impl ContextList { let func_ptr = stack.as_mut_ptr().offset(offset as isize); *(func_ptr as *mut usize) = func as usize; } - context.arch.set_page_table(unsafe { arch::paging::ActivePageTable::new().address() }); + context.arch.set_page_table(unsafe { paging::ActivePageTable::new().address() }); context.arch.set_fx(fx.as_ptr() as usize); context.arch.set_stack(stack.as_ptr() as usize + offset); context.kfx = Some(fx); diff --git a/src/context/memory.rs b/src/context/memory.rs index e12fbda067d5937373f127062e9be6e6bbdb8a32..111b54ebf017486597e4fd84568e22d37f6789f1 100644 --- a/src/context/memory.rs +++ b/src/context/memory.rs @@ -3,11 +3,11 @@ use collections::VecDeque; use core::intrinsics; use spin::Mutex; -use arch::memory::Frame; -use arch::paging::{ActivePageTable, InactivePageTable, Page, PageIter, PhysicalAddress, VirtualAddress}; -use arch::paging::entry::{self, EntryFlags}; -use arch::paging::mapper::MapperFlushAll; -use arch::paging::temporary_page::TemporaryPage; +use memory::Frame; +use paging::{ActivePageTable, InactivePageTable, Page, PageIter, PhysicalAddress, VirtualAddress}; +use paging::entry::{self, EntryFlags}; +use paging::mapper::MapperFlushAll; +use paging::temporary_page::TemporaryPage; #[derive(Debug)] pub struct Grant { diff --git a/src/context/mod.rs b/src/context/mod.rs index 2b1214c931d13d29e45e77e5b8463d18bb473e7c..05b7c580892ede93a39d0f676b63d51eb0f76a0e 100644 --- a/src/context/mod.rs +++ b/src/context/mod.rs @@ -8,6 +8,9 @@ pub use self::list::ContextList; pub use self::switch::switch; pub use context::context::ContextId; +#[path = "arch/x86_64.rs"] +mod arch; + /// Context struct mod context; diff --git a/src/context/switch.rs b/src/context/switch.rs index 60cd46bad6c5904402abf7eb0af87a37b0460881..2e67545ac1bc2794c48b6cdccf652f1db36165fa 100644 --- a/src/context/switch.rs +++ b/src/context/switch.rs @@ -1,8 +1,10 @@ use core::sync::atomic::Ordering; -use arch; -use context::{contexts, Context, Status, CONTEXT_ID}; +use context::{arch, contexts, Context, Status, CONTEXT_ID}; +use gdt; +use interrupt; use syscall; +use time; /// Switch to the next context /// @@ -13,8 +15,8 @@ pub unsafe fn switch() -> bool { use core::ops::DerefMut; // Set the global lock to avoid the unsafe operations below from causing issues - while arch::context::CONTEXT_SWITCH_LOCK.compare_and_swap(false, true, Ordering::SeqCst) { - arch::interrupt::pause(); + while arch::CONTEXT_SWITCH_LOCK.compare_and_swap(false, true, Ordering::SeqCst) { + interrupt::pause(); } let cpu_id = ::cpu_id(); @@ -43,7 +45,7 @@ pub unsafe fn switch() -> bool { if context.status == Status::Blocked && context.wake.is_some() { let wake = context.wake.expect("context::switch: wake not set"); - let current = arch::time::monotonic(); + let current = time::monotonic(); if current.0 > wake.0 || (current.0 == wake.0 && current.1 >= wake.1) { context.wake = None; context.unblock(); @@ -86,19 +88,19 @@ pub unsafe fn switch() -> bool { if to_ptr as usize == 0 { // Unset global lock if no context found - arch::context::CONTEXT_SWITCH_LOCK.store(false, Ordering::SeqCst); + arch::CONTEXT_SWITCH_LOCK.store(false, Ordering::SeqCst); return false; } (&mut *from_ptr).running = false; (&mut *to_ptr).running = true; if let Some(ref stack) = (*to_ptr).kstack { - arch::gdt::TSS.rsp[0] = (stack.as_ptr() as usize + stack.len() - 256) as u64; + gdt::TSS.rsp[0] = (stack.as_ptr() as usize + stack.len() - 256) as u64; } CONTEXT_ID.store((&mut *to_ptr).id, Ordering::SeqCst); // Unset global lock before switch, as arch is only usable by the current CPU at this time - arch::context::CONTEXT_SWITCH_LOCK.store(false, Ordering::SeqCst); + arch::CONTEXT_SWITCH_LOCK.store(false, Ordering::SeqCst); if let Some(sig) = to_sig { println!("Handle {}", sig); diff --git a/arch/x86_64/src/device/cpu.rs b/src/device/cpu.rs similarity index 100% rename from arch/x86_64/src/device/cpu.rs rename to src/device/cpu.rs diff --git a/arch/x86_64/src/device/local_apic.rs b/src/device/local_apic.rs similarity index 100% rename from arch/x86_64/src/device/local_apic.rs rename to src/device/local_apic.rs diff --git a/arch/x86_64/src/device/mod.rs b/src/device/mod.rs similarity index 100% rename from arch/x86_64/src/device/mod.rs rename to src/device/mod.rs diff --git a/arch/x86_64/src/device/pic.rs b/src/device/pic.rs similarity index 100% rename from arch/x86_64/src/device/pic.rs rename to src/device/pic.rs diff --git a/arch/x86_64/src/device/rtc.rs b/src/device/rtc.rs similarity index 100% rename from arch/x86_64/src/device/rtc.rs rename to src/device/rtc.rs diff --git a/arch/x86_64/src/device/serial.rs b/src/device/serial.rs similarity index 100% rename from arch/x86_64/src/device/serial.rs rename to src/device/serial.rs diff --git a/arch/x86_64/src/gdt.rs b/src/gdt.rs similarity index 100% rename from arch/x86_64/src/gdt.rs rename to src/gdt.rs diff --git a/arch/x86_64/src/idt.rs b/src/idt.rs similarity index 100% rename from arch/x86_64/src/idt.rs rename to src/idt.rs diff --git a/arch/x86_64/src/interrupt/exception.rs b/src/interrupt/exception.rs similarity index 100% rename from arch/x86_64/src/interrupt/exception.rs rename to src/interrupt/exception.rs diff --git a/arch/x86_64/src/interrupt/ipi.rs b/src/interrupt/ipi.rs similarity index 100% rename from arch/x86_64/src/interrupt/ipi.rs rename to src/interrupt/ipi.rs diff --git a/arch/x86_64/src/interrupt/irq.rs b/src/interrupt/irq.rs similarity index 100% rename from arch/x86_64/src/interrupt/irq.rs rename to src/interrupt/irq.rs diff --git a/arch/x86_64/src/interrupt/mod.rs b/src/interrupt/mod.rs similarity index 100% rename from arch/x86_64/src/interrupt/mod.rs rename to src/interrupt/mod.rs diff --git a/arch/x86_64/src/interrupt/syscall.rs b/src/interrupt/syscall.rs similarity index 100% rename from arch/x86_64/src/interrupt/syscall.rs rename to src/interrupt/syscall.rs diff --git a/src/lib.rs b/src/lib.rs index 4dec73fd9019319fec57a3b3314c663542efbea8..131afa037f303e328c27d7064e04548e3ef067e6 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,31 +12,21 @@ #![feature(drop_types_in_const)] #![feature(heap_api)] #![feature(integer_atomics)] +#![feature(lang_items)] +#![feature(naked_functions)] #![feature(never_type)] #![feature(thread_local)] +#![feature(unique)] #![no_std] -use arch::interrupt; - -/// Architecture specific items (test) -#[cfg(test)] -#[macro_use] -extern crate arch_test as arch; - -/// Architecture specific items (ARM) -#[cfg(all(not(test), target_arch = "arm"))] -#[macro_use] -extern crate arch_arm as arch; - -/// Architecture specific items (x86_64) -#[cfg(all(not(test), target_arch = "x86_64"))] -#[macro_use] -extern crate arch_x86_64 as arch; +extern crate alloc_kernel as allocator; +pub extern crate x86; extern crate alloc; #[macro_use] extern crate collections; +#[macro_use] extern crate bitflags; extern crate goblin; extern crate spin; @@ -44,28 +34,73 @@ extern crate spin; use core::sync::atomic::{AtomicUsize, ATOMIC_USIZE_INIT, Ordering}; use scheme::FileHandle; +pub use consts::*; + #[macro_use] /// Shared data structures pub mod common; +/// Macros like print, println, and interrupt +#[macro_use] +pub mod macros; + +/// Constants like memory locations +pub mod consts; + +/// ACPI table parsing +mod acpi; + +/// Console handling +pub mod console; + /// Context management pub mod context; +/// Devices +pub mod device; + /// ELF file parsing pub mod elf; /// External functions pub mod externs; +/// Global descriptor table +pub mod gdt; + +/// Interrupt descriptor table +mod idt; + +/// Interrupt instructions +pub mod interrupt; + +/// Memory management +pub mod memory; + +/// Paging +pub mod paging; + +/// Panic +pub mod panic; + /// Schemes, filesystem handlers pub mod scheme; +/// Initialization and start function +pub mod start; + +/// Shutdown function +pub mod stop; + /// Synchronization primitives pub mod sync; /// Syscall handlers pub mod syscall; +/// Time +pub mod time; + /// Tests #[cfg(test)] pub mod tests; @@ -103,20 +138,6 @@ pub extern fn userspace_init() { panic!("init returned"); } -/// Allow exception handlers to send signal to arch-independant kernel -#[no_mangle] -pub extern fn ksignal(signal: usize) { - println!("SIGNAL {}, CPU {}, PID {:?}", signal, cpu_id(), context::context_id()); - { - let contexts = context::contexts(); - if let Some(context_lock) = contexts.current() { - let context = context_lock.read(); - println!("NAME {}", unsafe { ::core::str::from_utf8_unchecked(&context.name.lock()) }); - } - } - syscall::exit(signal & 0x7F); -} - /// This is the kernel entry point for the primary CPU. The arch crate is responsible for calling this #[no_mangle] pub extern fn kmain(cpus: usize) { @@ -173,3 +194,17 @@ pub extern fn kmain_ap(id: usize) { } } } + +/// Allow exception handlers to send signal to arch-independant kernel +#[no_mangle] +pub extern fn ksignal(signal: usize) { + println!("SIGNAL {}, CPU {}, PID {:?}", signal, cpu_id(), context::context_id()); + { + let contexts = context::contexts(); + if let Some(context_lock) = contexts.current() { + let context = context_lock.read(); + println!("NAME {}", unsafe { ::core::str::from_utf8_unchecked(&context.name.lock()) }); + } + } + syscall::exit(signal & 0x7F); +} diff --git a/arch/x86_64/src/macros.rs b/src/macros.rs similarity index 100% rename from arch/x86_64/src/macros.rs rename to src/macros.rs diff --git a/arch/x86_64/src/memory/bump.rs b/src/memory/bump.rs similarity index 100% rename from arch/x86_64/src/memory/bump.rs rename to src/memory/bump.rs diff --git a/arch/x86_64/src/memory/mod.rs b/src/memory/mod.rs similarity index 100% rename from arch/x86_64/src/memory/mod.rs rename to src/memory/mod.rs diff --git a/arch/x86_64/src/paging/entry.rs b/src/paging/entry.rs similarity index 100% rename from arch/x86_64/src/paging/entry.rs rename to src/paging/entry.rs diff --git a/arch/x86_64/src/paging/mapper.rs b/src/paging/mapper.rs similarity index 100% rename from arch/x86_64/src/paging/mapper.rs rename to src/paging/mapper.rs diff --git a/arch/x86_64/src/paging/mod.rs b/src/paging/mod.rs similarity index 100% rename from arch/x86_64/src/paging/mod.rs rename to src/paging/mod.rs diff --git a/arch/x86_64/src/paging/table.rs b/src/paging/table.rs similarity index 100% rename from arch/x86_64/src/paging/table.rs rename to src/paging/table.rs diff --git a/arch/x86_64/src/paging/temporary_page.rs b/src/paging/temporary_page.rs similarity index 100% rename from arch/x86_64/src/paging/temporary_page.rs rename to src/paging/temporary_page.rs diff --git a/arch/x86_64/src/panic.rs b/src/panic.rs similarity index 100% rename from arch/x86_64/src/panic.rs rename to src/panic.rs diff --git a/src/scheme/irq.rs b/src/scheme/irq.rs index 4817df034dcc3ef778dff6feda8ce40635f85d61..5892cddef0200d0d51dbda3ee64ec5c3c97696bb 100644 --- a/src/scheme/irq.rs +++ b/src/scheme/irq.rs @@ -2,7 +2,7 @@ use core::{mem, str}; use core::sync::atomic::Ordering; use spin::Mutex; -use arch::interrupt::irq::acknowledge; +use interrupt::irq::acknowledge; use context; use scheme::{AtomicSchemeId, ATOMIC_SCHEMEID_INIT, SchemeId}; use syscall::error::*; diff --git a/src/scheme/memory.rs b/src/scheme/memory.rs index 9db0c48535b436afe5a4738485ff7e415b7023a2..c784f0b598262acada57e1def179f051c3224210 100644 --- a/src/scheme/memory.rs +++ b/src/scheme/memory.rs @@ -1,4 +1,4 @@ -use arch::memory::{free_frames, used_frames}; +use memory::{free_frames, used_frames}; use syscall::data::StatVfs; use syscall::error::*; diff --git a/src/scheme/sys/cpu.rs b/src/scheme/sys/cpu.rs index 70c1694ff661874287dd6a656aad819efb6306c5..d61205a73b82a45acfb5fc6a7c0707b813d5775f 100644 --- a/src/scheme/sys/cpu.rs +++ b/src/scheme/sys/cpu.rs @@ -1,6 +1,6 @@ use collections::Vec; -use arch::device::cpu::cpu_info; +use device::cpu::cpu_info; use syscall::error::{Error, EIO, Result}; pub fn resource() -> Result<Vec<u8>> { diff --git a/src/scheme/user.rs b/src/scheme/user.rs index 589a8c9789b7ecf8e3a25aa9cb4aa611a84d8841..93f51246bf7ca1544651ec034a9c6210b1e0a28c 100644 --- a/src/scheme/user.rs +++ b/src/scheme/user.rs @@ -4,9 +4,8 @@ use core::sync::atomic::{AtomicU64, Ordering}; use core::{mem, slice, usize}; use spin::{Mutex, RwLock}; -use arch; -use arch::paging::{InactivePageTable, Page, VirtualAddress, entry}; -use arch::paging::temporary_page::TemporaryPage; +use paging::{InactivePageTable, Page, VirtualAddress, entry}; +use paging::temporary_page::TemporaryPage; use context::{self, Context}; use context::memory::Grant; use scheme::{AtomicSchemeId, ATOMIC_SCHEMEID_INIT, SchemeId}; @@ -91,12 +90,12 @@ impl UserInner { let mut grants = context.grants.lock(); let mut new_table = unsafe { InactivePageTable::from_address(context.arch.get_page_table()) }; - let mut temporary_page = TemporaryPage::new(Page::containing_address(VirtualAddress::new(arch::USER_TMP_GRANT_OFFSET))); + let mut temporary_page = TemporaryPage::new(Page::containing_address(VirtualAddress::new(::USER_TMP_GRANT_OFFSET))); let from_address = (address/4096) * 4096; let offset = address - from_address; let full_size = ((offset + size + 4095)/4096) * 4096; - let mut to_address = arch::USER_GRANT_OFFSET; + let mut to_address = ::USER_GRANT_OFFSET; let mut flags = entry::PRESENT | entry::NO_EXECUTE | entry::USER_ACCESSIBLE; if writable { @@ -146,7 +145,7 @@ impl UserInner { let mut grants = context.grants.lock(); let mut new_table = unsafe { InactivePageTable::from_address(context.arch.get_page_table()) }; - let mut temporary_page = TemporaryPage::new(Page::containing_address(VirtualAddress::new(arch::USER_TMP_GRANT_OFFSET))); + let mut temporary_page = TemporaryPage::new(Page::containing_address(VirtualAddress::new(::USER_TMP_GRANT_OFFSET))); for i in 0 .. grants.len() { let start = grants[i].start_address().get(); diff --git a/arch/x86_64/src/start.rs b/src/start.rs similarity index 100% rename from arch/x86_64/src/start.rs rename to src/start.rs diff --git a/arch/x86_64/src/stop.rs b/src/stop.rs similarity index 100% rename from arch/x86_64/src/stop.rs rename to src/stop.rs diff --git a/src/syscall/driver.rs b/src/syscall/driver.rs index 9c3f3cd0b3658aa9e4ab980ab46df8fe1ca295ce..c28aa762436892382677a63c650042360079df9d 100644 --- a/src/syscall/driver.rs +++ b/src/syscall/driver.rs @@ -1,6 +1,5 @@ -use arch; -use arch::memory::{allocate_frames, deallocate_frames, Frame}; -use arch::paging::{entry, ActivePageTable, PhysicalAddress, VirtualAddress}; +use memory::{allocate_frames, deallocate_frames, Frame}; +use paging::{entry, ActivePageTable, PhysicalAddress, VirtualAddress}; use context; use context::memory::Grant; use syscall::error::{Error, EFAULT, ENOMEM, EPERM, ESRCH, Result}; @@ -54,7 +53,7 @@ pub fn physmap(physical_address: usize, size: usize, flags: usize) -> Result<usi let from_address = (physical_address/4096) * 4096; let offset = physical_address - from_address; let full_size = ((offset + size + 4095)/4096) * 4096; - let mut to_address = arch::USER_GRANT_OFFSET; + let mut to_address = ::USER_GRANT_OFFSET; let mut entry_flags = entry::PRESENT | entry::NO_EXECUTE | entry::USER_ACCESSIBLE; if flags & MAP_WRITE == MAP_WRITE { diff --git a/src/syscall/mod.rs b/src/syscall/mod.rs index d3030071a475c4782f0a352c55a0deba3d30d4ae..be0eef9c8f3632a952b698ede3325caa40ef1a9d 100644 --- a/src/syscall/mod.rs +++ b/src/syscall/mod.rs @@ -2,7 +2,7 @@ extern crate syscall; -pub use self::syscall::{data, error, flag, number, scheme}; +pub use self::syscall::{data, error, flag, io, number, scheme}; pub use self::driver::*; pub use self::fs::*; diff --git a/src/syscall/process.rs b/src/syscall/process.rs index bdbff75cefd37e047ce0141ed03fb509a9ab372d..abee4bc1305d5d5999bf845ed9d8b43d438ed010 100644 --- a/src/syscall/process.rs +++ b/src/syscall/process.rs @@ -6,11 +6,11 @@ use core::{intrinsics, mem, str}; use core::ops::DerefMut; use spin::Mutex; -use arch; -use arch::memory::allocate_frames; -use arch::paging::{ActivePageTable, InactivePageTable, Page, VirtualAddress, entry}; -use arch::paging::temporary_page::TemporaryPage; -use arch::start::usermode; +use memory::allocate_frames; +use paging::{ActivePageTable, InactivePageTable, Page, VirtualAddress, entry}; +use paging::temporary_page::TemporaryPage; +use start::usermode; +use interrupt; use context; use context::ContextId; use elf::{self, program_header}; @@ -40,11 +40,11 @@ pub fn brk(address: usize) -> Result<usize> { if address == 0 { //println!("Brk query {:X}", current); Ok(current) - } else if address >= arch::USER_HEAP_OFFSET { + } else if address >= ::USER_HEAP_OFFSET { //TODO: out of memory errors if let Some(ref heap_shared) = context.heap { heap_shared.with(|heap| { - heap.resize(address - arch::USER_HEAP_OFFSET, true); + heap.resize(address - ::USER_HEAP_OFFSET, true); }); } else { panic!("user heap not initialized"); @@ -118,7 +118,7 @@ pub fn clone(flags: usize, stack_base: usize) -> Result<ContextId> { unsafe { let func_ptr = new_stack.as_mut_ptr().offset(offset as isize); - *(func_ptr as *mut usize) = arch::interrupt::syscall::clone_ret as usize; + *(func_ptr as *mut usize) = interrupt::syscall::clone_ret as usize; } kstack_option = Some(new_stack); @@ -136,7 +136,7 @@ pub fn clone(flags: usize, stack_base: usize) -> Result<ContextId> { for memory_shared in context.image.iter() { memory_shared.with(|memory| { let mut new_memory = context::memory::Memory::new( - VirtualAddress::new(memory.start_address().get() + arch::USER_TMP_OFFSET), + VirtualAddress::new(memory.start_address().get() + ::USER_TMP_OFFSET), memory.size(), entry::PRESENT | entry::NO_EXECUTE | entry::WRITABLE, false @@ -156,7 +156,7 @@ pub fn clone(flags: usize, stack_base: usize) -> Result<ContextId> { if let Some(ref heap_shared) = context.heap { heap_shared.with(|heap| { let mut new_heap = context::memory::Memory::new( - VirtualAddress::new(arch::USER_TMP_HEAP_OFFSET), + VirtualAddress::new(::USER_TMP_HEAP_OFFSET), heap.size(), entry::PRESENT | entry::NO_EXECUTE | entry::WRITABLE, false @@ -176,7 +176,7 @@ pub fn clone(flags: usize, stack_base: usize) -> Result<ContextId> { if let Some(ref stack) = context.stack { let mut new_stack = context::memory::Memory::new( - VirtualAddress::new(arch::USER_TMP_STACK_OFFSET), + VirtualAddress::new(::USER_TMP_STACK_OFFSET), stack.size(), entry::PRESENT | entry::NO_EXECUTE | entry::WRITABLE, false @@ -197,7 +197,7 @@ pub fn clone(flags: usize, stack_base: usize) -> Result<ContextId> { master: tls.master, file_size: tls.file_size, mem: context::memory::Memory::new( - VirtualAddress::new(arch::USER_TMP_TLS_OFFSET), + VirtualAddress::new(::USER_TMP_TLS_OFFSET), tls.mem.size(), entry::PRESENT | entry::NO_EXECUTE | entry::WRITABLE, true @@ -321,7 +321,7 @@ pub fn clone(flags: usize, stack_base: usize) -> Result<ContextId> { let mut active_table = unsafe { ActivePageTable::new() }; - let mut temporary_page = TemporaryPage::new(Page::containing_address(VirtualAddress::new(arch::USER_TMP_MISC_OFFSET))); + let mut temporary_page = TemporaryPage::new(Page::containing_address(VirtualAddress::new(::USER_TMP_MISC_OFFSET))); let mut new_table = { let frame = allocate_frames(1).expect("no more frames in syscall::clone new_table"); @@ -393,7 +393,7 @@ pub fn clone(flags: usize, stack_base: usize) -> Result<ContextId> { let size = unsafe { & __tbss_end as *const _ as usize - & __tdata_start as *const _ as usize }; - let start = arch::KERNEL_PERCPU_OFFSET + arch::KERNEL_PERCPU_SIZE * cpu_id; + let start = ::KERNEL_PERCPU_OFFSET + ::KERNEL_PERCPU_SIZE * cpu_id; let end = start + size; let start_page = Page::containing_address(VirtualAddress::new(start)); @@ -411,7 +411,7 @@ pub fn clone(flags: usize, stack_base: usize) -> Result<ContextId> { // Move copy of image for memory_shared in image.iter_mut() { memory_shared.with(|memory| { - let start = VirtualAddress::new(memory.start_address().get() - arch::USER_TMP_OFFSET + arch::USER_OFFSET); + let start = VirtualAddress::new(memory.start_address().get() - ::USER_TMP_OFFSET + ::USER_OFFSET); memory.move_to(start, &mut new_table, &mut temporary_page); }); } @@ -420,7 +420,7 @@ pub fn clone(flags: usize, stack_base: usize) -> Result<ContextId> { // Move copy of heap if let Some(heap_shared) = heap_option { heap_shared.with(|heap| { - heap.move_to(VirtualAddress::new(arch::USER_HEAP_OFFSET), &mut new_table, &mut temporary_page); + heap.move_to(VirtualAddress::new(::USER_HEAP_OFFSET), &mut new_table, &mut temporary_page); }); context.heap = Some(heap_shared); } @@ -428,13 +428,13 @@ pub fn clone(flags: usize, stack_base: usize) -> Result<ContextId> { // Setup user stack if let Some(mut stack) = stack_option { - stack.move_to(VirtualAddress::new(arch::USER_STACK_OFFSET), &mut new_table, &mut temporary_page); + stack.move_to(VirtualAddress::new(::USER_STACK_OFFSET), &mut new_table, &mut temporary_page); context.stack = Some(stack); } // Setup user TLS if let Some(mut tls) = tls_option { - tls.mem.move_to(VirtualAddress::new(arch::USER_TLS_OFFSET), &mut new_table, &mut temporary_page); + tls.mem.move_to(VirtualAddress::new(::USER_TLS_OFFSET), &mut new_table, &mut temporary_page); context.tls = Some(tls); } @@ -478,7 +478,7 @@ fn empty(context: &mut context::Context, reaping: bool) { println!("{}: {}: Grant should not exist: {:?}", context.id.into(), unsafe { ::core::str::from_utf8_unchecked(&context.name.lock()) }, grant); let mut new_table = unsafe { InactivePageTable::from_address(context.arch.get_page_table()) }; - let mut temporary_page = TemporaryPage::new(Page::containing_address(VirtualAddress::new(arch::USER_TMP_GRANT_OFFSET))); + let mut temporary_page = TemporaryPage::new(Page::containing_address(VirtualAddress::new(::USER_TMP_GRANT_OFFSET))); grant.unmap_inactive(&mut new_table, &mut temporary_page); } else { @@ -490,7 +490,7 @@ fn empty(context: &mut context::Context, reaping: bool) { pub fn exec(path: &[u8], arg_ptrs: &[[usize; 2]]) -> Result<usize> { let entry; - let mut sp = arch::USER_STACK_OFFSET + arch::USER_STACK_SIZE - 256; + let mut sp = ::USER_STACK_OFFSET + ::USER_STACK_SIZE - 256; { let mut args = Vec::new(); @@ -592,13 +592,13 @@ pub fn exec(path: &[u8], arg_ptrs: &[[usize; 2]]) -> Result<usize> { context.image.push(memory.to_shared()); } else if segment.p_type == program_header::PT_TLS { let memory = context::memory::Memory::new( - VirtualAddress::new(arch::USER_TCB_OFFSET), + VirtualAddress::new(::USER_TCB_OFFSET), 4096, entry::NO_EXECUTE | entry::WRITABLE | entry::USER_ACCESSIBLE, true ); - unsafe { *(arch::USER_TCB_OFFSET as *mut usize) = arch::USER_TLS_OFFSET + segment.p_memsz as usize; } + unsafe { *(::USER_TCB_OFFSET as *mut usize) = ::USER_TLS_OFFSET + segment.p_memsz as usize; } context.image.push(memory.to_shared()); @@ -612,7 +612,7 @@ pub fn exec(path: &[u8], arg_ptrs: &[[usize; 2]]) -> Result<usize> { // Map heap context.heap = Some(context::memory::Memory::new( - VirtualAddress::new(arch::USER_HEAP_OFFSET), + VirtualAddress::new(::USER_HEAP_OFFSET), 0, entry::NO_EXECUTE | entry::WRITABLE | entry::USER_ACCESSIBLE, true @@ -620,8 +620,8 @@ pub fn exec(path: &[u8], arg_ptrs: &[[usize; 2]]) -> Result<usize> { // Map stack context.stack = Some(context::memory::Memory::new( - VirtualAddress::new(arch::USER_STACK_OFFSET), - arch::USER_STACK_SIZE, + VirtualAddress::new(::USER_STACK_OFFSET), + ::USER_STACK_SIZE, entry::NO_EXECUTE | entry::WRITABLE | entry::USER_ACCESSIBLE, true )); @@ -632,7 +632,7 @@ pub fn exec(path: &[u8], arg_ptrs: &[[usize; 2]]) -> Result<usize> { master: master, file_size: file_size, mem: context::memory::Memory::new( - VirtualAddress::new(arch::USER_TLS_OFFSET), + VirtualAddress::new(::USER_TLS_OFFSET), size, entry::NO_EXECUTE | entry::WRITABLE | entry::USER_ACCESSIBLE, true @@ -653,7 +653,7 @@ pub fn exec(path: &[u8], arg_ptrs: &[[usize; 2]]) -> Result<usize> { let mut arg_size = 0; for arg in args.iter().rev() { sp -= mem::size_of::<usize>(); - unsafe { *(sp as *mut usize) = arch::USER_ARG_OFFSET + arg_size; } + unsafe { *(sp as *mut usize) = ::USER_ARG_OFFSET + arg_size; } sp -= mem::size_of::<usize>(); unsafe { *(sp as *mut usize) = arg.len(); } @@ -665,7 +665,7 @@ pub fn exec(path: &[u8], arg_ptrs: &[[usize; 2]]) -> Result<usize> { if arg_size > 0 { let mut memory = context::memory::Memory::new( - VirtualAddress::new(arch::USER_ARG_OFFSET), + VirtualAddress::new(::USER_ARG_OFFSET), arg_size, entry::NO_EXECUTE | entry::WRITABLE, true @@ -675,7 +675,7 @@ pub fn exec(path: &[u8], arg_ptrs: &[[usize; 2]]) -> Result<usize> { for arg in args.iter().rev() { unsafe { intrinsics::copy(arg.as_ptr(), - (arch::USER_ARG_OFFSET + arg_offset) as *mut u8, + (::USER_ARG_OFFSET + arg_offset) as *mut u8, arg.len()); } @@ -916,7 +916,7 @@ fn reap(pid: ContextId) -> Result<ContextId> { running = context.running; } - arch::interrupt::pause(); + interrupt::pause(); } let mut contexts = context::contexts_mut(); diff --git a/src/syscall/time.rs b/src/syscall/time.rs index 448f31177eb61e2039fa3ad4563adb1875936f49..80c38c5f3f7f3aa00d09681622388b92d224a9e1 100644 --- a/src/syscall/time.rs +++ b/src/syscall/time.rs @@ -1,4 +1,4 @@ -use arch; +use time; use context; use syscall::data::TimeSpec; use syscall::error::*; @@ -7,13 +7,13 @@ use syscall::flag::{CLOCK_REALTIME, CLOCK_MONOTONIC}; pub fn clock_gettime(clock: usize, time: &mut TimeSpec) -> Result<usize> { match clock { CLOCK_REALTIME => { - let arch_time = arch::time::realtime(); + let arch_time = time::realtime(); time.tv_sec = arch_time.0 as i64; time.tv_nsec = arch_time.1 as i32; Ok(0) }, CLOCK_MONOTONIC => { - let arch_time = arch::time::monotonic(); + let arch_time = time::monotonic(); time.tv_sec = arch_time.0 as i64; time.tv_nsec = arch_time.1 as i32; Ok(0) @@ -23,7 +23,7 @@ pub fn clock_gettime(clock: usize, time: &mut TimeSpec) -> Result<usize> { } pub fn nanosleep(req: &TimeSpec, rem_opt: Option<&mut TimeSpec>) -> Result<usize> { - let start = arch::time::monotonic(); + let start = time::monotonic(); let sum = start.1 + req.tv_nsec as u64; let end = (start.0 + req.tv_sec as u64 + sum / 1000000000, sum % 1000000000); @@ -39,7 +39,7 @@ pub fn nanosleep(req: &TimeSpec, rem_opt: Option<&mut TimeSpec>) -> Result<usize unsafe { context::switch(); } if let Some(mut rem) = rem_opt { - //TODO let current = arch::time::monotonic(); + //TODO let current = time::monotonic(); rem.tv_sec = 0; rem.tv_nsec = 0; } diff --git a/src/syscall/validate.rs b/src/syscall/validate.rs index 0f5b03beb077b51995751cf951c83821ba548c9f..89747843baec7615ab02c1be207549dfa84bfa8c 100644 --- a/src/syscall/validate.rs +++ b/src/syscall/validate.rs @@ -1,6 +1,6 @@ use core::{mem, slice}; -use arch::paging::{ActivePageTable, Page, VirtualAddress, entry}; +use paging::{ActivePageTable, Page, VirtualAddress, entry}; use syscall::error::*; fn validate(address: usize, size: usize, flags: entry::EntryFlags) -> Result<()> { diff --git a/arch/x86_64/src/time.rs b/src/time.rs similarity index 100% rename from arch/x86_64/src/time.rs rename to src/time.rs