diff --git a/Makefile b/Makefile index 9edf71d..f3c31ae 100644 --- a/Makefile +++ b/Makefile @@ -14,7 +14,7 @@ user_object_files := $(wildcard user/*.o) qemu_opts := -cdrom $(iso) -smp 4 -serial mon:stdio features := use_apic -#link_user = 1 +link_user = 1 ifdef link_user features := $(features) link_user_program diff --git a/src/arch/x86_64/paging/mod.rs b/src/arch/x86_64/paging/mod.rs index 428eb01..e003fdc 100644 --- a/src/arch/x86_64/paging/mod.rs +++ b/src/arch/x86_64/paging/mod.rs @@ -103,15 +103,12 @@ impl ActivePageTable { } } - pub fn with(&mut self, - table: &mut InactivePageTable, - temporary_page: &mut temporary_page::TemporaryPage, // new - f: F) - where F: FnOnce(&mut Mapper) + pub fn with(&mut self, table: &mut InactivePageTable, f: impl FnOnce(&mut Mapper)) { use x86_64::instructions::tlb; use x86_64::registers::control_regs; + let mut temporary_page = TemporaryPage::new(Page::of_addr(0xcafebabe)); { let backup = Frame::of_addr( control_regs::cr3().0 as usize); @@ -155,10 +152,8 @@ pub struct InactivePageTable { } impl InactivePageTable { - pub fn new(frame: Frame, - active_table: &mut ActivePageTable, - temporary_page: &mut TemporaryPage) - -> InactivePageTable { + pub fn new(frame: Frame, active_table: &mut ActivePageTable) -> InactivePageTable { + let mut temporary_page = TemporaryPage::new(Page::of_addr(0xcafebabe)); { let table = temporary_page.map_table_frame(frame.clone(), active_table); diff --git a/src/memory/mod.rs b/src/memory/mod.rs index a08ea89..5ca7bda 100644 --- a/src/memory/mod.rs +++ b/src/memory/mod.rs @@ -88,13 +88,11 @@ pub fn init(boot_info: &BootInformation) -> MemoryController { pub fn remap_the_kernel(boot_info: &BootInformation) -> (ActivePageTable, Stack) { - let mut temporary_page = TemporaryPage::new(Page::of_addr(0xcafebabe)); - let mut active_table = unsafe { ActivePageTable::new() }; let mut new_table = - InactivePageTable::new(alloc_frame(), &mut active_table, &mut temporary_page); + InactivePageTable::new(alloc_frame(), &mut active_table); - active_table.with(&mut new_table, &mut temporary_page, |mapper| { + active_table.with(&mut new_table, |mapper| { let elf_sections_tag = boot_info.elf_sections_tag() .expect("Memory map tag required"); @@ -165,9 +163,8 @@ impl MemoryController { stack_allocator.alloc_stack(active_table, size_in_pages) } pub fn new_page_table(&mut self) -> InactivePageTable { - let mut temporary_page = TemporaryPage::new(Page::of_addr(0xcafebabe)); let frame = alloc_frame(); - let page_table = InactivePageTable::new(frame, &mut self.active_table, &mut temporary_page); + let page_table = InactivePageTable::new(frame, &mut self.active_table); page_table } pub fn map_page_identity(&mut self, addr: usize) { diff --git a/src/process/mod.rs b/src/process/mod.rs index 80e5f70..532a1ea 100644 --- a/src/process/mod.rs +++ b/src/process/mod.rs @@ -43,7 +43,7 @@ pub fn init(mc: &mut MemoryController) { let idleproc = Process::new("idle", idle_thread, mc); #[cfg(feature = "link_user_program")] let forktest = Process::new_user(_binary_user_forktest_start as usize, - _binary_user_forktest_end as usize); + _binary_user_forktest_end as usize, mc); processor.add(initproc); processor.add(idleproc); processor diff --git a/src/process/process.rs b/src/process/process.rs index ae5539d..eb43de8 100644 --- a/src/process/process.rs +++ b/src/process/process.rs @@ -50,15 +50,38 @@ impl Process { } } - pub fn new_user(begin: usize, end: usize) -> Self { + pub fn new_user(begin: usize, end: usize, mc: &mut MemoryController) -> Self { let slice = unsafe{ slice::from_raw_parts(begin as *const u8, end - begin) }; let elf = ElfFile::new(slice).expect("failed to read elf"); for program_header in elf.program_iter() { println!("{:?}", program_header); } -// for section in elf.section_iter() { -// println!("{:?}", section); -// } + for section in elf.section_iter() { + println!("{:?}", section); + } unimplemented!(); } +} + +use memory::{MemorySet, MemoryArea}; + +fn new_memory_set_from_elf(elf: ElfFile, mc: &mut MemoryController) -> MemorySet { + use xmas_elf::program::ProgramHeader; + + let mut set = MemorySet::new(mc); + for ph in elf.program_iter() { + match ph { + ProgramHeader::Ph32(ph) => unimplemented!(), + ProgramHeader::Ph64(ph) => { + set.push(MemoryArea { + start_addr: ph.virtual_addr as usize, + end_addr: (ph.virtual_addr + ph.mem_size) as usize, + flags: ph.flags.0, // TODO: handle it + name: "", + mapped: false, + }); + }, + } + } + set } \ No newline at end of file