[haiku-commits] haiku: hrev46291 - in src/system/boot: arch/arm arch/m68k platform/amiga_m68k platform/atari_m68k loader

  • From: revol@xxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 26 Oct 2013 20:55:00 +0200 (CEST)

hrev46291 adds 5 changesets to branch 'master'
old head: 057c8708f216514c6874b7c49f6ca170760b3cf0
new head: b3025a8642645f026efef25e5302e5183113aa59
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=b3025a8+%5E057c870

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

9703c9c: bootloader: Add tracing to malloc_large()

1804178: bootloader: ARM: Fix mmu_free()
  
  Allocation size was mixed up with page counts...
  Allow freeing up to sNextVirtualAddress.

b086b8a: bootloader: ARM: Replace KERNEL_BASE with KERNEL_LOAD_BASE

585830a: bootloader: M68K: s/KERNEL_BASE/KERNEL_LOAD_BASE/

b3025a8: bootloader: M68K: Fix mmu_free()
  
  Same bug as in ARM code...

                                          [ François Revol <revol@xxxxxxx> ]

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

5 files changed, 66 insertions(+), 60 deletions(-)
src/system/boot/arch/arm/arch_mmu.cpp       | 33 +++++++++++++------------
src/system/boot/arch/m68k/mmu.cpp           | 30 +++++++++++-----------
src/system/boot/loader/heap.cpp             |  6 ++++-
src/system/boot/platform/amiga_m68k/mmu.cpp | 28 ++++++++++-----------
src/system/boot/platform/atari_m68k/mmu.cpp | 29 +++++++++++-----------

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

Commit:      9703c9cc30cc47c2488a190a93b9603c08f368ca
URL:         http://cgit.haiku-os.org/haiku/commit/?id=9703c9c
Author:      François Revol <revol@xxxxxxx>
Date:        Sat Oct 26 16:41:57 2013 UTC

bootloader: Add tracing to malloc_large()

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

diff --git a/src/system/boot/loader/heap.cpp b/src/system/boot/loader/heap.cpp
index 7fc9e40..dcf3269 100644
--- a/src/system/boot/loader/heap.cpp
+++ b/src/system/boot/loader/heap.cpp
@@ -261,15 +261,19 @@ static void*
 malloc_large(size_t size)
 {
        LargeAllocation* allocation = new(std::nothrow) LargeAllocation;
-       if (allocation == NULL)
+       if (allocation == NULL) {
+               dprintf("malloc_large(): Out of memory!\n");
                return NULL;
+       }
 
        if (allocation->Allocate(size) != B_OK) {
+               dprintf("malloc_large(): Out of memory!\n");
                delete allocation;
                return NULL;
        }
 
        sLargeAllocations.InsertUnchecked(allocation);
+       TRACE("malloc_large(%lu) -> %p\n", size, allocation->Address());
        return allocation->Address();
 }
 

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

Commit:      18041782fdc356a02ddf7384141657cd2a616b58
URL:         http://cgit.haiku-os.org/haiku/commit/?id=1804178
Author:      François Revol <revol@xxxxxxx>
Date:        Sat Oct 26 17:15:30 2013 UTC

bootloader: ARM: Fix mmu_free()

Allocation size was mixed up with page counts...
Allow freeing up to sNextVirtualAddress.

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

diff --git a/src/system/boot/arch/arm/arch_mmu.cpp 
b/src/system/boot/arch/arm/arch_mmu.cpp
index 8867f7f..d4078f9 100644
--- a/src/system/boot/arch/arm/arch_mmu.cpp
+++ b/src/system/boot/arch/arm/arch_mmu.cpp
@@ -513,18 +513,18 @@ mmu_free(void *virtualAddress, size_t size)
        TRACE(("mmu_free(virtualAddress = %p, size: %ld)\n", virtualAddress, 
size));
 
        addr_t address = (addr_t)virtualAddress;
-       size = (size + B_PAGE_SIZE - 1) / B_PAGE_SIZE;
-               // get number of pages to map
+       addr_t pageOffset = address % B_PAGE_SIZE;
+       address -= pageOffset;
+       size = (size + pageOffset + B_PAGE_SIZE - 1) / B_PAGE_SIZE * 
B_PAGE_SIZE;
 
        // is the address within the valid range?
-       if (address < KERNEL_BASE
-               || address + size >= KERNEL_BASE + kMaxKernelSize) {
+       if (address < KERNEL_LOAD_BASE || address + size > sNextVirtualAddress) 
{
                panic("mmu_free: asked to unmap out of range region (%p, size 
%lx)\n",
                        (void *)address, size);
        }
 
        // unmap all pages within the range
-       for (uint32 i = 0; i < size; i++) {
+       for (size_t i = 0; i < size; i += B_PAGE_SIZE) {
                unmap_page(address);
                address += B_PAGE_SIZE;
        }

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

Commit:      b086b8ad2d38cda47c2dea8fc18922bc7023db90
URL:         http://cgit.haiku-os.org/haiku/commit/?id=b086b8a
Author:      François Revol <revol@xxxxxxx>
Date:        Sat Oct 26 17:23:20 2013 UTC

bootloader: ARM: Replace KERNEL_BASE with KERNEL_LOAD_BASE

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

diff --git a/src/system/boot/arch/arm/arch_mmu.cpp 
b/src/system/boot/arch/arm/arch_mmu.cpp
index d4078f9..22dc535 100644
--- a/src/system/boot/arch/arm/arch_mmu.cpp
+++ b/src/system/boot/arch/arm/arch_mmu.cpp
@@ -51,7 +51,7 @@ TODO:
         0xa2000000 - ?                 code (up to 1MB)
         0xa2100000                     boot loader heap / free physical memory
 
-       The kernel is mapped at KERNEL_BASE, all other stuff mapped by the
+       The kernel is mapped at KERNEL_LOAD_BASE, all other stuff mapped by the
        loader (kernel args, modules, driver settings, ...) comes after
        0x80020000 which means that there is currently only 2 MB reserved for
        the kernel itself (see kMaxKernelSize).
@@ -127,7 +127,7 @@ static struct memblock LOADER_MEMORYMAP[] = {
 static const size_t kMaxKernelSize = 0x200000;         // 2 MB for the kernel
 
 static addr_t sNextPhysicalAddress = 0; //will be set by mmu_init
-static addr_t sNextVirtualAddress = KERNEL_BASE + kMaxKernelSize;
+static addr_t sNextVirtualAddress = KERNEL_LOAD_BASE + kMaxKernelSize;
 
 static addr_t sNextPageTableAddress = 0;
 //the page directory is in front of the pagetable
@@ -391,7 +391,7 @@ map_page(addr_t virtualAddress, addr_t physicalAddress, 
uint32 flags)
        TRACE(("map_page: vaddr 0x%lx, paddr 0x%lx\n", virtualAddress,
                physicalAddress));
 
-       if (virtualAddress < KERNEL_BASE) {
+       if (virtualAddress < KERNEL_LOAD_BASE) {
                panic("map_page: asked to map invalid page %p!\n",
                        (void *)virtualAddress);
        }
@@ -440,7 +440,7 @@ unmap_page(addr_t virtualAddress)
 {
        TRACE(("unmap_page(virtualAddress = %p)\n", (void *)virtualAddress));
 
-       if (virtualAddress < KERNEL_BASE) {
+       if (virtualAddress < KERNEL_LOAD_BASE) {
                panic("unmap_page: asked to unmap invalid page %p!\n",
                        (void *)virtualAddress);
        }
@@ -474,12 +474,13 @@ mmu_allocate(void *virtualAddress, size_t size)
                addr_t address = (addr_t)virtualAddress;
 
                // is the address within the valid range?
-               if (address < KERNEL_BASE || address + size * B_PAGE_SIZE
-                       >= KERNEL_BASE + kMaxKernelSize) {
+               if (address < KERNEL_LOAD_BASE || address + size * B_PAGE_SIZE
+                       >= KERNEL_LOAD_BASE + kMaxKernelSize) {
                        TRACE(("mmu_allocate in illegal range\n address: %" 
B_PRIx32
-                               "  KERNELBASE: %" B_PRIx32 " KERNEL_BASE + 
kMaxKernelSize: %"
-                               B_PRIx32 "  address + size : %" B_PRIx32 "\n", 
(uint32)address,
-                               (uint32)KERNEL_BASE, (uint32)KERNEL_BASE + 
kMaxKernelSize,
+                               "  KERNELBASE: %" B_PRIx32 " KERNEL_LOAD_BASE + 
kMaxKernelSize:"
+                               " %" B_PRIx32 "  address + size : %" B_PRIx32 
"\n",
+                               (uint32)address, (uint32)KERNEL_LOAD_BASE,
+                               (uint32)KERNEL_LOAD_BASE + kMaxKernelSize,
                                (uint32)(address + size)));
                        return NULL;
                }
@@ -551,9 +552,9 @@ mmu_init_for_kernel(void)
 
        // Save the memory we've virtually allocated (for the kernel and other
        // stuff)
-       gKernelArgs.virtual_allocated_range[0].start = KERNEL_BASE;
+       gKernelArgs.virtual_allocated_range[0].start = KERNEL_LOAD_BASE;
        gKernelArgs.virtual_allocated_range[0].size
-               = sNextVirtualAddress - KERNEL_BASE;
+               = sNextVirtualAddress - KERNEL_LOAD_BASE;
        gKernelArgs.num_virtual_allocated_ranges = 1;
 
 #ifdef TRACE_MEMORY_MAP

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

Commit:      585830a55ef4f6bbbd1559a47a8395b5597906fe
URL:         http://cgit.haiku-os.org/haiku/commit/?id=585830a
Author:      François Revol <revol@xxxxxxx>
Date:        Sat Oct 26 18:33:55 2013 UTC

bootloader: M68K: s/KERNEL_BASE/KERNEL_LOAD_BASE/

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

diff --git a/src/system/boot/arch/m68k/mmu.cpp 
b/src/system/boot/arch/m68k/mmu.cpp
index 1a44790..79ea943 100644
--- a/src/system/boot/arch/m68k/mmu.cpp
+++ b/src/system/boot/arch/m68k/mmu.cpp
@@ -70,7 +70,7 @@
  */
 #warning M68K: check for Physbase() < ST_RAM_TOP
 
-//#define TRACE_MMU
+#define TRACE_MMU
 #ifdef TRACE_MMU
 #      define TRACE(x) dprintf x
 #else
@@ -89,8 +89,8 @@ static const size_t kMaxKernelSize = 0x100000;                
// 1 MB for the kernel
 addr_t gPageRoot = 0;
 
 static addr_t sNextPhysicalAddress = 0x100000;
-static addr_t sNextVirtualAddress = KERNEL_BASE + kMaxKernelSize;
-static addr_t sMaxVirtualAddress = KERNEL_BASE /*+ 0x400000*/;
+static addr_t sNextVirtualAddress = KERNEL_LOAD_BASE + kMaxKernelSize;
+static addr_t sMaxVirtualAddress = KERNEL_LOAD_BASE /*+ 0x400000*/;
 
 #if 0
 static addr_t sNextPageTableAddress = 0x90000;
@@ -212,7 +212,7 @@ map_page(addr_t virtualAddress, addr_t physicalAddress, 
uint32 flags)
 {
        TRACE(("map_page: vaddr 0x%lx, paddr 0x%lx\n", virtualAddress, 
physicalAddress));
 
-       if (virtualAddress < KERNEL_BASE)
+       if (virtualAddress < KERNEL_LOAD_BASE)
                panic("map_page: asked to map invalid page %p!\n", (void 
*)virtualAddress);
 
        // slow but I'm too lazy to fix the code below
@@ -257,7 +257,7 @@ init_page_directory(void)
        //XXX: check for errors
 
        //gKernelArgs.arch_args.num_pgtables = 0;
-       gMMUOps->add_page_table(KERNEL_BASE);
+       gMMUOps->add_page_table(KERNEL_LOAD_BASE);
 
 #if 0
 
@@ -290,7 +290,7 @@ init_page_directory(void)
        gPageRoot[1] = (uint32)pageTable | kDefaultPageFlags;
 
        gKernelArgs.arch_args.num_pgtables = 0;
-       add_page_table(KERNEL_BASE);
+       add_page_table(KERNEL_LOAD_BASE);
 
        // switch to the new pgdir and enable paging
        asm("movl %0, %%eax;"
@@ -338,8 +338,8 @@ mmu_allocate(void *virtualAddress, size_t size)
                addr_t address = (addr_t)virtualAddress;
 
                // is the address within the valid range?
-               if (address < KERNEL_BASE || address + size * B_PAGE_SIZE
-                       >= KERNEL_BASE + kMaxKernelSize)
+               if (address < KERNEL_LOAD_BASE || address + size * B_PAGE_SIZE
+                       >= KERNEL_LOAD_BASE + kMaxKernelSize)
                        return NULL;
 
                for (uint32 i = 0; i < size; i++) {
@@ -377,8 +377,8 @@ mmu_free(void *virtualAddress, size_t size)
                // get number of pages to map
 
        // is the address within the valid range?
-       if (address < KERNEL_BASE
-               || address + size >= KERNEL_BASE + kMaxKernelSize) {
+       if (address < KERNEL_LOAD_BASE
+               || address + size >= KERNEL_LOAD_BASE + kMaxKernelSize) {
                panic("mmu_free: asked to unmap out of range region (%p, size 
%lx)\n",
                        (void *)address, size);
        }
@@ -499,8 +499,8 @@ mmu_init_for_kernel(void)
        gKernelArgs.physical_allocated_range[0].size = sNextPhysicalAddress - 
gKernelArgs.physical_allocated_range[0].start;
 
        // save the memory we've virtually allocated (for the kernel and other 
stuff)
-       gKernelArgs.virtual_allocated_range[0].start = KERNEL_BASE;
-       gKernelArgs.virtual_allocated_range[0].size = sNextVirtualAddress - 
KERNEL_BASE;
+       gKernelArgs.virtual_allocated_range[0].start = KERNEL_LOAD_BASE;
+       gKernelArgs.virtual_allocated_range[0].size = sNextVirtualAddress - 
KERNEL_LOAD_BASE;
        gKernelArgs.num_virtual_allocated_ranges = 1;
 
        // sort the address ranges
diff --git a/src/system/boot/platform/amiga_m68k/mmu.cpp 
b/src/system/boot/platform/amiga_m68k/mmu.cpp
index 1dde414..eb5d17b 100644
--- a/src/system/boot/platform/amiga_m68k/mmu.cpp
+++ b/src/system/boot/platform/amiga_m68k/mmu.cpp
@@ -89,8 +89,8 @@ static const size_t kMaxKernelSize = 0x100000;                
// 1 MB for the kernel
 addr_t gPageRoot = 0;
 
 static addr_t sNextPhysicalAddress = 0x100000;
-static addr_t sNextVirtualAddress = KERNEL_BASE + kMaxKernelSize;
-static addr_t sMaxVirtualAddress = KERNEL_BASE /*+ 0x400000*/;
+static addr_t sNextVirtualAddress = KERNEL_LOAD_BASE + kMaxKernelSize;
+static addr_t sMaxVirtualAddress = KERNEL_LOAD_BASE /*+ 0x400000*/;
 
 #if 0
 static addr_t sNextPageTableAddress = 0x90000;
@@ -212,7 +212,7 @@ map_page(addr_t virtualAddress, addr_t physicalAddress, 
uint32 flags)
 {
        TRACE(("map_page: vaddr 0x%lx, paddr 0x%lx\n", virtualAddress, 
physicalAddress));
 
-       if (virtualAddress < KERNEL_BASE)
+       if (virtualAddress < KERNEL_LOAD_BASE)
                panic("map_page: asked to map invalid page %p!\n", (void 
*)virtualAddress);
 
        // slow but I'm too lazy to fix the code below
@@ -257,7 +257,7 @@ init_page_directory(void)
        //XXX: check for errors
 
        //gKernelArgs.arch_args.num_pgtables = 0;
-       gMMUOps->add_page_table(KERNEL_BASE);
+       gMMUOps->add_page_table(KERNEL_LOAD_BASE);
 
 #if 0
 
@@ -290,7 +290,7 @@ init_page_directory(void)
        gPageRoot[1] = (uint32)pageTable | kDefaultPageFlags;
 
        gKernelArgs.arch_args.num_pgtables = 0;
-       add_page_table(KERNEL_BASE);
+       add_page_table(KERNEL_LOAD_BASE);
 
        // switch to the new pgdir and enable paging
        asm("movl %0, %%eax;"
@@ -338,8 +338,8 @@ mmu_allocate(void *virtualAddress, size_t size)
                addr_t address = (addr_t)virtualAddress;
 
                // is the address within the valid range?
-               if (address < KERNEL_BASE || address + size * B_PAGE_SIZE
-                       >= KERNEL_BASE + kMaxKernelSize)
+               if (address < KERNEL_LOAD_BASE || address + size * B_PAGE_SIZE
+                       >= KERNEL_LOAD_BASE + kMaxKernelSize)
                        return NULL;
 
                for (uint32 i = 0; i < size; i++) {
@@ -377,8 +377,8 @@ mmu_free(void *virtualAddress, size_t size)
                // get number of pages to map
 
        // is the address within the valid range?
-       if (address < KERNEL_BASE
-               || address + size >= KERNEL_BASE + kMaxKernelSize) {
+       if (address < KERNEL_LOAD_BASE
+               || address + size >= KERNEL_LOAD_BASE + kMaxKernelSize) {
                panic("mmu_free: asked to unmap out of range region (%p, size 
%lx)\n",
                        (void *)address, size);
        }
@@ -499,8 +499,8 @@ mmu_init_for_kernel(void)
        gKernelArgs.physical_allocated_range[0].size = sNextPhysicalAddress - 
gKernelArgs.physical_allocated_range[0].start;
 
        // save the memory we've virtually allocated (for the kernel and other 
stuff)
-       gKernelArgs.virtual_allocated_range[0].start = KERNEL_BASE;
-       gKernelArgs.virtual_allocated_range[0].size = sNextVirtualAddress - 
KERNEL_BASE;
+       gKernelArgs.virtual_allocated_range[0].start = KERNEL_LOAD_BASE;
+       gKernelArgs.virtual_allocated_range[0].size = sNextVirtualAddress - 
KERNEL_LOAD_BASE;
        gKernelArgs.num_virtual_allocated_ranges = 1;
 
        // sort the address ranges
diff --git a/src/system/boot/platform/atari_m68k/mmu.cpp 
b/src/system/boot/platform/atari_m68k/mmu.cpp
index 548d6d5..300e160 100644
--- a/src/system/boot/platform/atari_m68k/mmu.cpp
+++ b/src/system/boot/platform/atari_m68k/mmu.cpp
@@ -71,7 +71,7 @@
  */
 #warning M68K: check for Physbase() < ST_RAM_TOP
 
-//#define TRACE_MMU
+#define TRACE_MMU
 #ifdef TRACE_MMU
 #      define TRACE(x) dprintf x
 #else
@@ -90,8 +90,8 @@ static const size_t kMaxKernelSize = 0x200000;                
// 2 MB for the kernel
 addr_t gPageRoot = 0;
 
 static addr_t sNextPhysicalAddress = 0x100000;
-static addr_t sNextVirtualAddress = KERNEL_BASE + kMaxKernelSize;
-static addr_t sMaxVirtualAddress = KERNEL_BASE /*+ 0x400000*/;
+static addr_t sNextVirtualAddress = KERNEL_LOAD_BASE + kMaxKernelSize;
+static addr_t sMaxVirtualAddress = KERNEL_LOAD_BASE /*+ 0x400000*/;
 
 #if 0
 static addr_t sNextPageTableAddress = 0x90000;
@@ -213,7 +213,7 @@ map_page(addr_t virtualAddress, addr_t physicalAddress, 
uint32 flags)
 {
        TRACE(("map_page: vaddr 0x%lx, paddr 0x%lx\n", virtualAddress, 
physicalAddress));
 
-       if (virtualAddress < KERNEL_BASE)
+       if (virtualAddress < KERNEL_LOAD_BASE)
                panic("map_page: asked to map invalid page %p!\n", (void 
*)virtualAddress);
 
        // slow but I'm too lazy to fix the code below
@@ -258,7 +258,7 @@ init_page_directory(void)
        //XXX: check for errors
 
        //gKernelArgs.arch_args.num_pgtables = 0;
-       gMMUOps->add_page_table(KERNEL_BASE);
+       gMMUOps->add_page_table(KERNEL_LOAD_BASE);
 
 #if 0
 
@@ -291,7 +291,7 @@ init_page_directory(void)
        gPageRoot[1] = (uint32)pageTable | kDefaultPageFlags;
 
        gKernelArgs.arch_args.num_pgtables = 0;
-       add_page_table(KERNEL_BASE);
+       add_page_table(KERNEL_LOAD_BASE);
 
        // switch to the new pgdir and enable paging
        asm("movl %0, %%eax;"
@@ -339,8 +339,8 @@ mmu_allocate(void *virtualAddress, size_t size)
                addr_t address = (addr_t)virtualAddress;
 
                // is the address within the valid range?
-               if (address < KERNEL_BASE || address + size * B_PAGE_SIZE
-                       >= KERNEL_BASE + kMaxKernelSize)
+               if (address < KERNEL_LOAD_BASE || address + size * B_PAGE_SIZE
+                       >= KERNEL_LOAD_BASE + kMaxKernelSize)
                        return NULL;
 
                for (uint32 i = 0; i < size; i++) {
@@ -378,7 +378,7 @@ mmu_free(void *virtualAddress, size_t size)
                // get number of pages to map
 
        // is the address within the valid range?
-       if (address < KERNEL_BASE) {
+       if (address < KERNEL_LOAD_BASE) {
                panic("mmu_free: asked to unmap out of range region (%p, size 
%lx)\n",
                        (void *)address, size);
        }
@@ -499,8 +499,8 @@ mmu_init_for_kernel(void)
        gKernelArgs.physical_allocated_range[0].size = sNextPhysicalAddress - 
gKernelArgs.physical_allocated_range[0].start;
 
        // save the memory we've virtually allocated (for the kernel and other 
stuff)
-       gKernelArgs.virtual_allocated_range[0].start = KERNEL_BASE;
-       gKernelArgs.virtual_allocated_range[0].size = sNextVirtualAddress - 
KERNEL_BASE;
+       gKernelArgs.virtual_allocated_range[0].start = KERNEL_LOAD_BASE;
+       gKernelArgs.virtual_allocated_range[0].size = sNextVirtualAddress - 
KERNEL_LOAD_BASE;
        gKernelArgs.num_virtual_allocated_ranges = 1;
 
        // sort the address ranges

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

Revision:    hrev46291
Commit:      b3025a8642645f026efef25e5302e5183113aa59
URL:         http://cgit.haiku-os.org/haiku/commit/?id=b3025a8
Author:      François Revol <revol@xxxxxxx>
Date:        Sat Oct 26 18:49:48 2013 UTC

bootloader: M68K: Fix mmu_free()

Same bug as in ARM code...

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

diff --git a/src/system/boot/arch/m68k/mmu.cpp 
b/src/system/boot/arch/m68k/mmu.cpp
index 79ea943..8f7495c 100644
--- a/src/system/boot/arch/m68k/mmu.cpp
+++ b/src/system/boot/arch/m68k/mmu.cpp
@@ -373,18 +373,18 @@ mmu_free(void *virtualAddress, size_t size)
        TRACE(("mmu_free(virtualAddress = %p, size: %ld)\n", virtualAddress, 
size));
 
        addr_t address = (addr_t)virtualAddress;
-       size = (size + B_PAGE_SIZE - 1) / B_PAGE_SIZE;
-               // get number of pages to map
+       addr_t pageOffset = address % B_PAGE_SIZE;
+       address -= pageOffset;
+       size = (size + pageOffset + B_PAGE_SIZE - 1) / B_PAGE_SIZE * 
B_PAGE_SIZE;
 
        // is the address within the valid range?
-       if (address < KERNEL_LOAD_BASE
-               || address + size >= KERNEL_LOAD_BASE + kMaxKernelSize) {
+       if (address < KERNEL_LOAD_BASE || address + size > sNextVirtualAddress) 
{
                panic("mmu_free: asked to unmap out of range region (%p, size 
%lx)\n",
                        (void *)address, size);
        }
 
        // unmap all pages within the range
-       for (uint32 i = 0; i < size; i++) {
+       for (size_t i = 0; i < size; i += B_PAGE_SIZE) {
                unmap_page(address);
                address += B_PAGE_SIZE;
        }
diff --git a/src/system/boot/platform/amiga_m68k/mmu.cpp 
b/src/system/boot/platform/amiga_m68k/mmu.cpp
index eb5d17b..bbc02c6 100644
--- a/src/system/boot/platform/amiga_m68k/mmu.cpp
+++ b/src/system/boot/platform/amiga_m68k/mmu.cpp
@@ -373,18 +373,18 @@ mmu_free(void *virtualAddress, size_t size)
        TRACE(("mmu_free(virtualAddress = %p, size: %ld)\n", virtualAddress, 
size));
 
        addr_t address = (addr_t)virtualAddress;
-       size = (size + B_PAGE_SIZE - 1) / B_PAGE_SIZE;
-               // get number of pages to map
+       addr_t pageOffset = address % B_PAGE_SIZE;
+       address -= pageOffset;
+       size = (size + pageOffset + B_PAGE_SIZE - 1) / B_PAGE_SIZE * 
B_PAGE_SIZE;
 
        // is the address within the valid range?
-       if (address < KERNEL_LOAD_BASE
-               || address + size >= KERNEL_LOAD_BASE + kMaxKernelSize) {
+       if (address < KERNEL_LOAD_BASE || address + size > sNextVirtualAddress) 
{
                panic("mmu_free: asked to unmap out of range region (%p, size 
%lx)\n",
                        (void *)address, size);
        }
 
        // unmap all pages within the range
-       for (uint32 i = 0; i < size; i++) {
+       for (size_t i = 0; i < size; i += B_PAGE_SIZE) {
                unmap_page(address);
                address += B_PAGE_SIZE;
        }
diff --git a/src/system/boot/platform/atari_m68k/mmu.cpp 
b/src/system/boot/platform/atari_m68k/mmu.cpp
index 300e160..4a858ec 100644
--- a/src/system/boot/platform/atari_m68k/mmu.cpp
+++ b/src/system/boot/platform/atari_m68k/mmu.cpp
@@ -374,17 +374,18 @@ mmu_free(void *virtualAddress, size_t size)
        TRACE(("mmu_free(virtualAddress = %p, size: %ld)\n", virtualAddress, 
size));
 
        addr_t address = (addr_t)virtualAddress;
-       size = (size + B_PAGE_SIZE - 1) / B_PAGE_SIZE;
-               // get number of pages to map
+       addr_t pageOffset = address % B_PAGE_SIZE;
+       address -= pageOffset;
+       size = (size + pageOffset + B_PAGE_SIZE - 1) / B_PAGE_SIZE * 
B_PAGE_SIZE;
 
        // is the address within the valid range?
-       if (address < KERNEL_LOAD_BASE) {
+       if (address < KERNEL_LOAD_BASE || address + size > sNextVirtualAddress) 
{
                panic("mmu_free: asked to unmap out of range region (%p, size 
%lx)\n",
                        (void *)address, size);
        }
 
        // unmap all pages within the range
-       for (uint32 i = 0; i < size; i++) {
+       for (size_t i = 0; i < size; i += B_PAGE_SIZE) {
                unmap_page(address);
                address += B_PAGE_SIZE;
        }


Other related posts:

  • » [haiku-commits] haiku: hrev46291 - in src/system/boot: arch/arm arch/m68k platform/amiga_m68k platform/atari_m68k loader - revol