From ce4fd0c0fb1b9b8998e22b5aab044afffb14d40f Mon Sep 17 00:00:00 2001 From: Tomas Hruby Date: Wed, 15 Sep 2010 14:09:41 +0000 Subject: [PATCH] Enable paging - some more code reshuffling --- kernel/arch/i386/memory.c | 47 +++++++++++++++++++-------------------- kernel/proto.h | 1 - kernel/system/do_vmctl.c | 6 ++--- 3 files changed, 26 insertions(+), 28 deletions(-) diff --git a/kernel/arch/i386/memory.c b/kernel/arch/i386/memory.c index 6d1394cae..9875e9c05 100644 --- a/kernel/arch/i386/memory.c +++ b/kernel/arch/i386/memory.c @@ -38,32 +38,11 @@ FORWARD _PROTOTYPE( u32_t phys_get32, (phys_bytes v) ); FORWARD _PROTOTYPE( void vm_enable_paging, (void) ); -/* *** Internal VM Functions *** */ - -PUBLIC void vm_init(struct proc *newptproc) +PUBLIC void segmentation2paging(struct proc * current) { - if(vm_running) - panic("vm_init: vm_running"); - - /* switch_address_space() checks what is in cr3, and doesn't do - * anything if it's the same as the cr3 of its argument, newptproc. - * If MINIX was previously booted, this could very well be the case. - * - * The first time switch_address_space() is called, we want to - * force it to do something (load cr3 and set newptproc), so we - * zero cr3, and force paging off to make that a safe thing to do. - * - * After that, vm_enable_paging() enables paging with the page table - * of newptproc loaded. - */ - - vm_stop(); - write_cr3(0); - switch_address_space(newptproc); - assert(ptproc == newptproc); - catch_pagefaults = 0; + /* switch to the current process page tables before turning paging on */ + switch_address_space(current); vm_enable_paging(); - vm_running = 1; } /* This function sets up a mapping from within the kernel's address @@ -1042,6 +1021,26 @@ PUBLIC int arch_enable_paging(struct proc * caller, const message * m_ptr) struct vm_ep_data ep_data; int r; + /* switch_address_space() checks what is in cr3, and do nothing if it's + * the same as the cr3 of its argument, newptproc. If MINIX was + * previously booted, this could very well be the case. + * + * The first time switch_address_space() is called, we want to + * force it to do something (load cr3 and set newptproc), so we + * zero cr3, and force paging off to make that a safe thing to do. + * + * After that, segmentation2paging() enables paging with the page table + * of caller loaded. + */ + + vm_stop(); + write_cr3(0); + + /* switch from segmentation only to paging */ + segmentation2paging(caller); + + vm_running = 1; + /* * copy the extra data associated with the call from userspace */ diff --git a/kernel/proto.h b/kernel/proto.h index 4f71d7c94..fb84aa51c 100644 --- a/kernel/proto.h +++ b/kernel/proto.h @@ -152,7 +152,6 @@ _PROTOTYPE( int data_copy_vmcheck, (struct proc *, endpoint_t from, vir_bytes from_addr, endpoint_t to, vir_bytes to_addr, size_t bytes)); _PROTOTYPE( void alloc_segments, (struct proc *rp) ); -_PROTOTYPE( void vm_init, (struct proc *first) ); _PROTOTYPE( void vm_stop, (void) ); _PROTOTYPE( phys_bytes umap_local, (register struct proc *rp, int seg, vir_bytes vir_addr, vir_bytes bytes)); diff --git a/kernel/system/do_vmctl.c b/kernel/system/do_vmctl.c index c5fdbd865..82673deac 100644 --- a/kernel/system/do_vmctl.c +++ b/kernel/system/do_vmctl.c @@ -123,10 +123,10 @@ PUBLIC int do_vmctl(struct proc * caller, message * m_ptr) case VMCTL_ENABLE_PAGING: if(vm_running) panic("do_vmctl: paging already enabled"); - vm_init(p); - if(!vm_running) + if (arch_enable_paging(caller, m_ptr) != OK) panic("do_vmctl: paging enabling failed"); - return arch_enable_paging(caller, m_ptr); + return OK; + case VMCTL_KERN_PHYSMAP: { int i = m_ptr->SVMCTL_VALUE; -- 2.44.0