Remove `temporary_page` from function args

master
WangRunji 7 years ago
parent 5075abc5b0
commit 5714df7c39

@ -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

@ -103,15 +103,12 @@ impl ActivePageTable {
}
}
pub fn with<F>(&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);

@ -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) {

@ -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

@ -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
}
Loading…
Cancel
Save