[haiku-commits] BRANCH xyzzy-github.x86_64 - in src/system/kernel/arch/x86/paging: . src/system

  • From: xyzzy-github.x86_64 <community@xxxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Wed, 4 Jul 2012 21:49:09 +0200 (CEST)

added 3 changesets to branch 'refs/remotes/xyzzy-github/x86_64'
old head: e70dd7e0af671e37378d68c241a081ebeaf8f659
new head: d687d8ac70249aa14a983002e52b643836f76b2d

----------------------------------------------------------------------------

a8f85e6: Removed accidently left in debug message.

40aeaeb: Should enable CR4.PGE while switching to the kernel.

d687d8a: Implementation of VMPhysicalPageMapper for x86_64 using the permanent 
physical memory mapping.

                                      [ Alex Smith <alex@xxxxxxxxxxxxxxxx> ]

----------------------------------------------------------------------------

4 files changed, 231 insertions(+), 5 deletions(-)
src/system/boot/platform/bios_ia32/long.cpp        |    2 -
src/system/boot/platform/bios_ia32/long_asm.S      |    4 +-
src/system/kernel/arch/x86/Jamfile                 |    2 +-
.../x86/paging/x86_physical_page_mapper_mapped.cpp |  228 ++++++++++++++++

############################################################################

Commit:      a8f85e6e48ec38ad16d9e1289f031e696220367e

Author:      Alex Smith <alex@xxxxxxxxxxxxxxxx>
Date:        Wed Jul  4 17:33:21 2012 UTC

Removed accidently left in debug message.

----------------------------------------------------------------------------

diff --git a/src/system/boot/platform/bios_ia32/long.cpp 
b/src/system/boot/platform/bios_ia32/long.cpp
index 43230be..60bcdcf 100644
--- a/src/system/boot/platform/bios_ia32/long.cpp
+++ b/src/system/boot/platform/bios_ia32/long.cpp
@@ -137,8 +137,6 @@ long_mmu_init()
        pml4[0] = physicalAddress | kTableMappingFlags;
 
        for (uint64 i = 0; i < maxAddress; i += 0x40000000) {
-               dprintf("mapping %llu GB\n", i / 0x40000000);
-
                pageDir = (uint64*)mmu_allocate_page(&physicalAddress);
                memset(pageDir, 0, B_PAGE_SIZE);
                pdpt[i / 0x40000000] = physicalAddress | kTableMappingFlags;

############################################################################

Commit:      40aeaeb907f5390e3eeb2958aa5d8362652eca22

Author:      Alex Smith <alex@xxxxxxxxxxxxxxxx>
Date:        Wed Jul  4 17:39:23 2012 UTC

Should enable CR4.PGE while switching to the kernel.

----------------------------------------------------------------------------

diff --git a/src/system/boot/platform/bios_ia32/long_asm.S 
b/src/system/boot/platform/bios_ia32/long_asm.S
index c14889a..43be6af 100644
--- a/src/system/boot/platform/bios_ia32/long_asm.S
+++ b/src/system/boot/platform/bios_ia32/long_asm.S
@@ -25,9 +25,9 @@ FUNCTION(long_enter_kernel):
        andl    $~(1 << 31), %eax
        movl    %eax, %cr0
 
-       // Enable PAE.
+       // Enable PAE and PGE
        movl    %cr4, %eax
-       orl             $(1 << 5), %eax
+       orl             $(1 << 5) | (1 << 7), %eax
        movl    %eax, %cr4
 
        // Point CR3 to the kernel's PML4.

############################################################################

Commit:      d687d8ac70249aa14a983002e52b643836f76b2d

Author:      Alex Smith <alex@xxxxxxxxxxxxxxxx>
Date:        Wed Jul  4 18:57:48 2012 UTC

Implementation of VMPhysicalPageMapper for x86_64 using the permanent physical 
memory mapping.

----------------------------------------------------------------------------

diff --git a/src/system/kernel/arch/x86/Jamfile 
b/src/system/kernel/arch/x86/Jamfile
index a67e420..c45f2d1 100644
--- a/src/system/kernel/arch/x86/Jamfile
+++ b/src/system/kernel/arch/x86/Jamfile
@@ -26,7 +26,7 @@ if $(TARGET_ARCH) = x86_64 {
                stubs.cpp
 
                # paging
-               #x86_physical_page_mapper_mapped.cpp
+               x86_physical_page_mapper_mapped.cpp
 
                # paging/64bit
                X86PagingMethod64Bit.cpp
diff --git 
a/src/system/kernel/arch/x86/paging/x86_physical_page_mapper_mapped.cpp 
b/src/system/kernel/arch/x86/paging/x86_physical_page_mapper_mapped.cpp
index 45f270c..d74fb7c 100644
--- a/src/system/kernel/arch/x86/paging/x86_physical_page_mapper_mapped.cpp
+++ b/src/system/kernel/arch/x86/paging/x86_physical_page_mapper_mapped.cpp
@@ -18,6 +18,7 @@
 #include <new>
 
 #include <cpu.h>
+#include <kernel.h>
 #include <smp.h>
 #include <vm/vm.h>
 #include <vm/vm_types.h>
@@ -27,3 +28,230 @@
 #include "paging/X86PagingStructures.h"
 #include "paging/X86VMTranslationMap.h"
 
+
+// #pragma mark -
+
+
+class MappedTranslationMapPhysicalPageMapper
+       : public TranslationMapPhysicalPageMapper {
+public:
+       virtual void                            Delete();
+
+       virtual void*                           GetPageTableAt(phys_addr_t 
physicalAddress);
+};
+
+
+class MappedPhysicalPageMapper : public X86PhysicalPageMapper {
+public:
+       virtual status_t                        
CreateTranslationMapPhysicalPageMapper(
+                                                                       
TranslationMapPhysicalPageMapper** _mapper);
+
+       virtual void*                           InterruptGetPageTableAt(
+                                                                       
phys_addr_t physicalAddress);
+
+       virtual status_t                        GetPage(phys_addr_t 
physicalAddress,
+                                                                       addr_t* 
virtualAddress, void** handle);
+       virtual status_t                        PutPage(addr_t virtualAddress, 
void* handle);
+
+       virtual status_t                        GetPageCurrentCPU(phys_addr_t 
physicalAddress,
+                                                                       addr_t* 
virtualAddress, void** handle);
+       virtual status_t                        PutPageCurrentCPU(addr_t 
virtualAddress,
+                                                                       void* 
handle);
+
+       virtual status_t                        GetPageDebug(phys_addr_t 
physicalAddress,
+                                                                       addr_t* 
virtualAddress, void** handle);
+       virtual status_t                        PutPageDebug(addr_t 
virtualAddress,
+                                                                       void* 
handle);
+
+       virtual status_t                        MemsetPhysical(phys_addr_t 
address, int value,
+                                                                       
phys_size_t length);
+       virtual status_t                        MemcpyFromPhysical(void* to, 
phys_addr_t from,
+                                                                       size_t 
length, bool user);
+       virtual status_t                        MemcpyToPhysical(phys_addr_t to,
+                                                                       const 
void* from, size_t length, bool user);
+       virtual void                            MemcpyPhysicalPage(phys_addr_t 
to,
+                                                                       
phys_addr_t from);
+};
+
+
+static MappedPhysicalPageMapper sPhysicalPageMapper;
+static MappedTranslationMapPhysicalPageMapper sKernelPageMapper;
+
+
+// #pragma mark - MappedTranslationMapPhysicalPageMapper
+
+
+void
+MappedTranslationMapPhysicalPageMapper::Delete()
+{
+       delete this;
+}
+
+
+void*
+MappedTranslationMapPhysicalPageMapper::GetPageTableAt(
+       phys_addr_t physicalAddress)
+{
+       ASSERT(physicalAddress % B_PAGE_SIZE == 0);
+
+       return (void*)(physicalAddress + KERNEL_PMAP_BASE);
+}
+
+
+// #pragma mark - MappedPhysicalPageMapper
+
+
+status_t
+MappedPhysicalPageMapper::CreateTranslationMapPhysicalPageMapper(
+       TranslationMapPhysicalPageMapper** _mapper)
+{
+       MappedTranslationMapPhysicalPageMapper* mapper
+               = new(std::nothrow) MappedTranslationMapPhysicalPageMapper;
+       if (mapper == NULL)
+               return B_NO_MEMORY;
+
+       *_mapper = mapper;
+       return B_OK;
+}
+
+
+void*
+MappedPhysicalPageMapper::InterruptGetPageTableAt(
+       phys_addr_t physicalAddress)
+{
+       ASSERT(physicalAddress % B_PAGE_SIZE == 0);
+
+       return (void*)(physicalAddress + KERNEL_PMAP_BASE);
+}
+
+
+status_t
+MappedPhysicalPageMapper::GetPage(phys_addr_t physicalAddress,
+       addr_t* virtualAddress, void** handle)
+{
+       if (physicalAddress >= KERNEL_PMAP_BASE)
+               return B_BAD_ADDRESS;
+
+       *virtualAddress = physicalAddress + KERNEL_PMAP_BASE;
+       return B_OK;
+}
+
+
+status_t
+MappedPhysicalPageMapper::PutPage(addr_t virtualAddress, void* handle)
+{
+       return B_OK;
+}
+
+
+status_t
+MappedPhysicalPageMapper::GetPageCurrentCPU(phys_addr_t physicalAddress,
+       addr_t* virtualAddress, void** handle)
+{
+       if (physicalAddress >= KERNEL_PMAP_BASE)
+               return B_BAD_ADDRESS;
+
+       *virtualAddress = physicalAddress + KERNEL_PMAP_BASE;
+       return B_OK;
+}
+
+
+status_t
+MappedPhysicalPageMapper::PutPageCurrentCPU(addr_t virtualAddress,
+       void* handle)
+{
+       return B_OK;
+}
+
+
+status_t
+MappedPhysicalPageMapper::GetPageDebug(phys_addr_t physicalAddress,
+       addr_t* virtualAddress, void** handle)
+{
+       if (physicalAddress >= KERNEL_PMAP_BASE)
+               return B_BAD_ADDRESS;
+
+       *virtualAddress = physicalAddress + KERNEL_PMAP_BASE;
+       return B_OK;
+}
+
+
+status_t
+MappedPhysicalPageMapper::PutPageDebug(addr_t virtualAddress, void* handle)
+{
+       return B_OK;
+}
+
+
+status_t
+MappedPhysicalPageMapper::MemsetPhysical(phys_addr_t address, int value,
+       phys_size_t length)
+{
+       if (address >= KERNEL_PMAP_SIZE || address + length > KERNEL_PMAP_SIZE)
+               return B_BAD_ADDRESS;
+
+       memset((void*)(address + KERNEL_PMAP_BASE), value, length);
+       return B_OK;
+}
+
+
+status_t
+MappedPhysicalPageMapper::MemcpyFromPhysical(void* to, phys_addr_t _from,
+       size_t length, bool user)
+{
+       if (_from >= KERNEL_PMAP_SIZE || _from + length > KERNEL_PMAP_SIZE)
+               return B_BAD_ADDRESS;
+
+       void* from = (void*)(_from + KERNEL_PMAP_BASE);
+
+       if (user)
+               return user_memcpy(to, from, length);
+       else
+               memcpy(to, from, length);
+
+       return B_OK;
+}
+
+
+status_t
+MappedPhysicalPageMapper::MemcpyToPhysical(phys_addr_t _to, const void* from,
+       size_t length, bool user)
+{
+       if (_to >= KERNEL_PMAP_SIZE || _to + length > KERNEL_PMAP_SIZE)
+               return B_BAD_ADDRESS;
+
+       void* to = (void*)(_to + KERNEL_PMAP_BASE);
+
+       if (user)
+               return user_memcpy(to, from, length);
+       else
+               memcpy(to, from, length);
+
+       return B_OK;
+}
+
+
+void
+MappedPhysicalPageMapper::MemcpyPhysicalPage(phys_addr_t to,
+       phys_addr_t from)
+{
+       memcpy((void*)(to + KERNEL_PMAP_BASE), (void*)(from + KERNEL_PMAP_BASE),
+               B_PAGE_SIZE);
+}
+
+
+// #pragma mark - Initialization
+
+
+status_t
+mapped_physical_page_ops_init(kernel_args* args,
+       X86PhysicalPageMapper*& _pageMapper,
+       TranslationMapPhysicalPageMapper*& _kernelPageMapper)
+{
+       new(&sPhysicalPageMapper) MappedPhysicalPageMapper;
+       new(&sKernelPageMapper) MappedTranslationMapPhysicalPageMapper;
+
+       _pageMapper = &sPhysicalPageMapper;
+       _kernelPageMapper = &sKernelPageMapper;
+       return B_OK;
+}


Other related posts: