Forget the kernel MemorySet (x86_64)

master
WangRunji 7 years ago
parent e12c4c1ddb
commit 548951abda

@ -9,13 +9,12 @@ use ucore_memory::paging::PageTable;
// BootInformation may trigger page fault after kernel remap // BootInformation may trigger page fault after kernel remap
// So just take its ownership // So just take its ownership
pub fn init(boot_info: BootInformation) -> MemorySet { pub fn init(boot_info: BootInformation) {
assert_has_not_been_called!("memory::init must be called only once"); assert_has_not_been_called!("memory::init must be called only once");
info!("{:?}", boot_info); info!("{:?}", boot_info);
init_frame_allocator(&boot_info); init_frame_allocator(&boot_info);
let ms = remap_the_kernel(&boot_info); remap_the_kernel(&boot_info);
init_heap(); init_heap();
ms
} }
fn init_frame_allocator(boot_info: &BootInformation) { fn init_frame_allocator(boot_info: &BootInformation) {
@ -52,7 +51,7 @@ fn init_frame_allocator(boot_info: &BootInformation) {
} }
} }
fn remap_the_kernel(boot_info: &BootInformation) -> MemorySet { fn remap_the_kernel(boot_info: &BootInformation) {
extern { fn stack_bottom(); } extern { fn stack_bottom(); }
extern { fn stack_top(); } extern { fn stack_top(); }
let kstack = Stack { let kstack = Stack {
@ -76,7 +75,8 @@ fn remap_the_kernel(boot_info: &BootInformation) -> MemorySet {
unsafe { memory_set.activate(); } unsafe { memory_set.activate(); }
info!("NEW TABLE!!!"); info!("NEW TABLE!!!");
memory_set use core::mem::forget;
forget(memory_set);
} }
fn memory_set_from(sections: ElfSectionsTag, kstack: Stack) -> MemorySet { fn memory_set_from(sections: ElfSectionsTag, kstack: Stack) -> MemorySet {

@ -10,16 +10,15 @@ pub mod idt;
pub mod smp; pub mod smp;
pub mod memory; pub mod memory;
pub fn init(multiboot_information_address: usize) -> MemorySet { pub fn init(multiboot_information_address: usize) {
idt::init(); idt::init();
let boot_info = unsafe { multiboot2::load(multiboot_information_address) }; let boot_info = unsafe { multiboot2::load(multiboot_information_address) };
let rsdt_addr = boot_info.rsdp_v1_tag().unwrap().rsdt_address(); let rsdt_addr = boot_info.rsdp_v1_tag().unwrap().rsdt_address();
let ms = memory::init(boot_info); memory::init(boot_info);
// Now heap is available // Now heap is available
gdt::init(); gdt::init();
let acpi = driver::init(rsdt_addr); let acpi = driver::init(rsdt_addr);
smp::start_other_cores(&acpi); smp::start_other_cores(&acpi);
ms
} }
/// The entry point for another processors /// The entry point for another processors

@ -107,9 +107,9 @@ pub extern "C" fn rust_main(multiboot_information_address: usize) -> ! {
println!("Hello World{}", "!"); println!("Hello World{}", "!");
io::init(); io::init();
let ms = arch::init(multiboot_information_address); arch::init(multiboot_information_address);
process::init(ms); process::init();
fs::load_sfs(); fs::load_sfs();

@ -10,10 +10,10 @@ mod processor;
mod scheduler; mod scheduler;
pub fn init(ms: MemorySet) { pub fn init() {
PROCESSOR.call_once(|| { PROCESSOR.call_once(|| {
SpinNoIrqLock::new({ SpinNoIrqLock::new({
let initproc = Process::new_init(ms); let initproc = Process::new_init();
let idleproc = Process::new("idle", idle_thread, 0); let idleproc = Process::new("idle", idle_thread, 0);
let mut processor = Processor::new(); let mut processor = Processor::new();
processor.add(initproc); processor.add(initproc);

@ -46,13 +46,13 @@ impl Process {
/// Make the first kernel thread `initproc` /// Make the first kernel thread `initproc`
/// Should be called only once /// Should be called only once
pub fn new_init(ms: MemorySet) -> Self { pub fn new_init() -> Self {
assert_has_not_been_called!(); assert_has_not_been_called!();
Process { Process {
pid: 0, pid: 0,
parent: 0, parent: 0,
name: String::from("init"), name: String::from("init"),
memory_set: ms, memory_set: MemorySet::new(),
status: Status::Running, status: Status::Running,
context: unsafe { Context::null() }, // will be set at first schedule context: unsafe { Context::null() }, // will be set at first schedule
is_user: false, is_user: false,

Loading…
Cancel
Save