[WIP] rv32 can enter userland now

master
Jiajie Chen 6 years ago
parent cf6a7746f4
commit f6a54c398d

@ -19,7 +19,7 @@ pub const MEMORY_END: usize = 0x8060_0000;
pub const MEMORY_END: usize = 0x8800_0000;
// FIXME: rv64 `sh` and `ls` will crash if stack top > 0x80000000 ???
pub const USER_STACK_OFFSET: usize = 0x80000000 - USER_STACK_SIZE;
pub const USER_STACK_OFFSET: usize = 0x40000000 - USER_STACK_SIZE;
pub const USER_STACK_SIZE: usize = 0x10000;
pub const MAX_DTB_SIZE: usize = 0x2000;

@ -99,9 +99,9 @@ impl VgaBuffer {
}
lazy_static! {
pub static ref VGA_WRITER: Mutex<VgaWriter> = Mutex::new(
VgaWriter::new(unsafe{ &mut *((phys_to_virt(0xb8000)) as *mut VgaBuffer) })
);
pub static ref VGA_WRITER: Mutex<VgaWriter> = Mutex::new(VgaWriter::new(unsafe {
&mut *((phys_to_virt(0xb8000)) as *mut VgaBuffer)
}));
}
pub struct VgaWriter {

@ -48,10 +48,7 @@ impl Cpu {
}
pub fn iter() -> impl Iterator<Item = &'static Self> {
unsafe {
CPUS.iter()
.filter_map(|x| x.as_ref())
}
unsafe { CPUS.iter().filter_map(|x| x.as_ref()) }
}
pub fn id(&self) -> usize {
self.id
@ -114,7 +111,7 @@ const KCODE: Descriptor = Descriptor::UserSegment(0x0020980000000000); // EXECUT
const UCODE: Descriptor = Descriptor::UserSegment(0x0020F80000000000); // EXECUTABLE | USER_SEGMENT | USER_MODE | PRESENT | LONG_MODE
const KDATA: Descriptor = Descriptor::UserSegment(0x0000920000000000); // DATA_WRITABLE | USER_SEGMENT | PRESENT
const UDATA: Descriptor = Descriptor::UserSegment(0x0000F20000000000); // DATA_WRITABLE | USER_SEGMENT | USER_MODE | PRESENT
// Copied from xv6
// Copied from xv6
const UCODE32: Descriptor = Descriptor::UserSegment(0x00cffa00_0000ffff); // EXECUTABLE | USER_SEGMENT | USER_MODE | PRESENT
const UDATA32: Descriptor = Descriptor::UserSegment(0x00cff200_0000ffff); // EXECUTABLE | USER_SEGMENT | USER_MODE | PRESENT

@ -6,8 +6,8 @@ mod trapframe;
pub use self::handler::*;
pub use self::trapframe::*;
use crate::consts::KERNEL_OFFSET;
use apic::*;
use crate::memory::phys_to_virt;
use apic::*;
#[inline(always)]
pub unsafe fn enable() {

@ -1,6 +1,5 @@
/// Interface for inter-processor interrupt.
/// This module wraps inter-processor interrupt into a broadcast-calling style.
use crate::consts::KERNEL_OFFSET;
use alloc::boxed::{Box, FnBox};
use alloc::sync::Arc;

@ -9,12 +9,12 @@ pub mod gdt;
pub mod idt;
pub mod interrupt;
pub mod io;
pub mod ipi;
pub mod memory;
pub mod paging;
pub mod rand;
pub mod syscall;
pub mod timer;
pub mod ipi;
static AP_CAN_INIT: AtomicBool = AtomicBool::new(false);
@ -34,7 +34,10 @@ pub extern "C" fn _start(boot_info: &'static BootInfo) -> ! {
// First init log mod, so that we can print log info.
crate::logging::init();
info!("{:#x?}", boot_info);
assert_eq!(boot_info.physical_memory_offset as usize, consts::PHYSICAL_MEMORY_OFFSET);
assert_eq!(
boot_info.physical_memory_offset as usize,
consts::PHYSICAL_MEMORY_OFFSET
);
// Init trap handling.
idt::init();

@ -286,8 +286,5 @@ fn flush_tlb_all(vaddr: usize) {
if !super::AP_CAN_INIT.load(Ordering::Relaxed) {
return;
}
super::ipi::invoke_on_allcpu(
move || tlb::flush(VirtAddr::new(vaddr as u64)),
false,
);
super::ipi::invoke_on_allcpu(move || tlb::flush(VirtAddr::new(vaddr as u64)), false);
}

@ -1,9 +1,9 @@
use alloc::alloc::{alloc_zeroed, dealloc, Layout};
pub use crate::arch::paging::PageTableImpl;
use isomorphic_drivers::provider;
use rcore_memory::paging::PageTable;
use rcore_memory::PAGE_SIZE;
pub use crate::arch::paging::PageTableImpl;
pub struct Provider;

@ -16,7 +16,7 @@ use super::HEAP_ALLOCATOR;
pub use crate::arch::paging::*;
use crate::consts::{KERNEL_OFFSET, MEMORY_OFFSET, PHYSICAL_MEMORY_OFFSET};
use crate::process::current_thread;
use crate::sync::{SpinNoIrqLock, MutexGuard, SpinNoIrq};
use crate::sync::{MutexGuard, SpinNoIrq, SpinNoIrqLock};
use alloc::boxed::Box;
use bitmap_allocator::BitAlloc;
use buddy_system_allocator::Heap;

@ -20,9 +20,9 @@ use crate::memory::{
use crate::sync::{Condvar, SpinNoIrqLock as Mutex};
use super::abi::{self, ProcInitInfo};
use crate::processor;
use core::mem::uninitialized;
use rcore_fs::vfs::INode;
use crate::processor;
pub struct Thread {
context: Context,

Loading…
Cancel
Save