[haiku-commits] haiku: hrev47834 - src/system/boot/arch/arm src/system/boot/platform/u-boot src/system/kernel/arch/arm/paging/32bit src/system/boot/platform/raspberrypi_arm build/jam/board/beagle

  • From: ithamar@xxxxxxxxxxxxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 7 Sep 2014 20:56:16 +0200 (CEST)

hrev47834 adds 5 changesets to branch 'master'
old head: c53c1faf5615c8793f73fb71c9a0b696601a071a
new head: eea45d0a329d51c5fcf8bf904316e7761aaaa96f
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=eea45d0+%5Ec53c1fa

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

6fb65b9: ARM: remove section handling TODO; no need for it
  
  We will never use sections anyway..

0a163b6: ARM: define bootloader stack in linker script
  
  This removes the need for the whole HAIKU_BOARD_LOADER_STACK_BASE
  sing and dance, since it is always included in the bootloader binary
  itself.

e3020a5: ARM: remove initrd handling from mmu code
  
  Let the platform mmu_map_physical_memory the initrd region, and
  reserve it before calling mmu_init. This removes another hardcoded
  address, since e.g. U-Boot gets the address from the uImage file.

3e450da: ARM: remove the loader from the memory map table
  
  We have _start/_end symbols to mark our start and end, use those
  to determine where we are loaded. We're slowly getting closer to
  a fully dynamic handling of our memory map!

eea45d0: ARM: cleanup of bootloader memory mapping
  
  * Removes default mapping of a portion of the RAM (will be done
    as needed)
  * Passes on the page directory area to kernel, so on early vm init
    the kernel can use the area for pagetable allocation.
  * Leaves it to the platform to pass in physical memory range(s). This
    will ultimately come from FDT.
  * Fix long standing issue with allocation of the heap, potentially
    causing other part of the bootloader to overwrite the heap.
  * Implements pagetable allocator in kernel for early vm mapping.
  
  This fixes the first PANIC seen, we now just get the same one later
  on when the VM is up... more to come...

                          [ Ithamar R. Adema <ithamar@xxxxxxxxxxxxxxxxxxx> ]

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

12 files changed, 114 insertions(+), 150 deletions(-)
build/jam/board/beagle/BoardSetup                |   6 +-
build/jam/board/neo_freerunner/BoardSetup        |   2 -
build/jam/board/overo/BoardSetup                 |   3 -
build/jam/board/sam460ex/BoardSetup              |   2 -
build/jam/board/verdex/BoardSetup                |   2 -
.../private/kernel/arch/arm/arch_kernel_args.h   |   1 +
src/system/boot/arch/arm/arch_mmu.cpp            | 189 +++++++------------
.../boot/platform/raspberrypi_arm/start.cpp      |   7 +
src/system/boot/platform/u-boot/arch/arm/shell.S |   8 +-
src/system/boot/platform/u-boot/start.cpp        |  21 ++-
.../arm/paging/32bit/ARMPagingMethod32Bit.cpp    |  13 +-
src/system/ldscripts/arm/boot_loader_u-boot.ld   |  10 +

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

Commit:      6fb65b9dfe49b4e58c2ba331fd3bf286f64f1cf9
URL:         http://cgit.haiku-os.org/haiku/commit/?id=6fb65b9
Author:      Ithamar R. Adema <ithamar@xxxxxxxxxxxxxxxxxxx>
Date:        Sat Sep  6 15:21:17 2014 UTC

ARM: remove section handling TODO; no need for it

We will never use sections anyway..

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

diff --git a/src/system/boot/arch/arm/arch_mmu.cpp 
b/src/system/boot/arch/arm/arch_mmu.cpp
index 758a1f3..f44873e 100644
--- a/src/system/boot/arch/arm/arch_mmu.cpp
+++ b/src/system/boot/arch/arm/arch_mmu.cpp
@@ -273,10 +273,6 @@ get_next_page_table(uint32 type)
                        size = ARM_MMU_L2_FINE_TABLE_SIZE;
                        entryCount = ARM_MMU_L2_FINE_ENTRY_COUNT;
                        break;
-               case ARM_MMU_L1_TYPE_SECTION:
-                       // TODO: Figure out parameters for section types.
-                       size = 16384;
-                       break;
                default:
                        panic("asked for unknown page table type: %#" B_PRIx32 
"\n", type);
                        return NULL;

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

Commit:      0a163b65c71323e37490471c4933f2289e4e80e8
URL:         http://cgit.haiku-os.org/haiku/commit/?id=0a163b6
Author:      Ithamar R. Adema <ithamar@xxxxxxxxxxxxxxxxxxx>
Date:        Sat Sep  6 19:14:42 2014 UTC

ARM: define bootloader stack in linker script

This removes the need for the whole HAIKU_BOARD_LOADER_STACK_BASE
sing and dance, since it is always included in the bootloader binary
itself.

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

diff --git a/build/jam/board/beagle/BoardSetup 
b/build/jam/board/beagle/BoardSetup
index c4fe605..27eeea7 100644
--- a/build/jam/board/beagle/BoardSetup
+++ b/build/jam/board/beagle/BoardSetup
@@ -20,8 +20,6 @@ HAIKU_BOARD_LOADER_FAKE_OS = netbsd ;
 # (must be different than real load address)
 HAIKU_BOARD_LOADER_UIBASE = 0x82800000 ;
 
-HAIKU_BOARD_LOADER_STACK_BASE = 0x81a00000 ;
-
 #
 # Flash image
 #
@@ -64,7 +62,6 @@ HAIKU_BOARD_SDIMAGE_FILES =
 # gcc flags for the specific cpu
 
 local flags = -mcpu=cortex-a8 -mfpu=vfpv3 -mfloat-abi=hard
-          -DHAIKU_BOARD_LOADER_STACK_BASE=$(HAIKU_BOARD_LOADER_STACK_BASE)
           -DHAIKU_BOARD_LOADER_UIBASE=$(HAIKU_BOARD_LOADER_UIBASE) ;
 
 HAIKU_ASFLAGS_$(HAIKU_PACKAGING_ARCH) += $(flags) ;
diff --git a/build/jam/board/neo_freerunner/BoardSetup 
b/build/jam/board/neo_freerunner/BoardSetup
index 918cf53..f1f92ac 100644
--- a/build/jam/board/neo_freerunner/BoardSetup
+++ b/build/jam/board/neo_freerunner/BoardSetup
@@ -19,8 +19,6 @@ HAIKU_BOARD_LOADER_FAKE_OS = netbsd ;
 # (must be different than real load address)
 HAIKU_BOARD_LOADER_UIBASE = 0x34000000 ;
 
-HAIKU_BOARD_LOADER_STACK_BASE = 0x34000000 ;
-
 #
 # Flash image
 #
diff --git a/build/jam/board/overo/BoardSetup b/build/jam/board/overo/BoardSetup
index 5097afb..ae5b342 100644
--- a/build/jam/board/overo/BoardSetup
+++ b/build/jam/board/overo/BoardSetup
@@ -20,9 +20,6 @@ HAIKU_BOARD_LOADER_FAKE_OS = netbsd ;
 # (must be different than real load address)
 HAIKU_BOARD_LOADER_UIBASE = 0x84000000 ;
 
-HAIKU_BOARD_LOADER_STACK_BASE = 0x84000000 ;
-
-
 #
 # mmc/SD image
 #
diff --git a/build/jam/board/sam460ex/BoardSetup 
b/build/jam/board/sam460ex/BoardSetup
index 1ab1d3e..8142345 100644
--- a/build/jam/board/sam460ex/BoardSetup
+++ b/build/jam/board/sam460ex/BoardSetup
@@ -24,8 +24,6 @@ HAIKU_BOARD_LOADER_FAKE_OS = linux ;
 # (must be different than real load address)
 HAIKU_BOARD_LOADER_UIBASE = 0x02000000 ;
 
-HAIKU_BOARD_LOADER_STACK_BASE = 0x02000000 ;
-
 #
 # gcc flags for the specific cpu
 #
diff --git a/build/jam/board/verdex/BoardSetup 
b/build/jam/board/verdex/BoardSetup
index 90269f9..fb95faf 100644
--- a/build/jam/board/verdex/BoardSetup
+++ b/build/jam/board/verdex/BoardSetup
@@ -19,8 +19,6 @@ HAIKU_BOARD_LOADER_FAKE_OS = netbsd ;
 # (must be different than real load address)
 HAIKU_BOARD_LOADER_UIBASE = 0xa4000000 ;
 
-HAIKU_BOARD_LOADER_STACK_BASE = 0xa4000000 ;
-
 #
 # Flash image
 #
diff --git a/src/system/boot/arch/arm/arch_mmu.cpp 
b/src/system/boot/arch/arm/arch_mmu.cpp
index f44873e..81c75de 100644
--- a/src/system/boot/arch/arm/arch_mmu.cpp
+++ b/src/system/boot/arch/arm/arch_mmu.cpp
@@ -111,12 +111,6 @@ static struct memblock LOADER_MEMORYMAP[] = {
                ARM_MMU_L2_FLAG_C,
        },
        {
-               "RAM_stack", // stack
-               HAIKU_BOARD_LOADER_STACK_BASE,
-               HAIKU_BOARD_LOADER_STACK_BASE + 0xe00000,
-               ARM_MMU_L2_FLAG_C,
-       },
-       {
                "RAM_initrd", // initrd
                HAIKU_BOARD_LOADER_UIBASE,
                HAIKU_BOARD_LOADER_UIBASE + 0x500000,
diff --git a/src/system/boot/platform/u-boot/arch/arm/shell.S 
b/src/system/boot/platform/u-boot/arch/arm/shell.S
index ca945c9..aad2a96 100644
--- a/src/system/boot/platform/u-boot/arch/arm/shell.S
+++ b/src/system/boot/platform/u-boot/arch/arm/shell.S
@@ -2,8 +2,6 @@
 
 #include <asm_defs.h>
 
-#include <board_config.h>
-
        .text
 
 /*
@@ -59,10 +57,7 @@ SYMBOL(_start_common):
        mov     r4, r4
        mov     r4, r4
 
-
-
-
-       ldr     sp,=SDRAM_BASE + KSTACK_TOP
+       ldr     sp,=__stack_top
        ldrb    r4,gUBootOS
        cmp     r4,#0
        beq     start_raw
@@ -75,6 +70,7 @@ SYMBOL_END(_start_common)
 //XXX: doesn't seem to work
 //.data
 
+.global __stack_end, __stack_start
 
 SYMBOL(gUBootGlobalData):
        .long   0
diff --git a/src/system/boot/platform/u-boot/start.cpp 
b/src/system/boot/platform/u-boot/start.cpp
index 0a2fb10..d2e4203 100644
--- a/src/system/boot/platform/u-boot/start.cpp
+++ b/src/system/boot/platform/u-boot/start.cpp
@@ -50,7 +50,7 @@ typedef struct uboot_gd {
 // GCC defined globals
 extern void (*__ctor_list)(void);
 extern void (*__ctor_end)(void);
-extern uint8 __bss_start;
+extern uint8 __bss_start, __bss_end;
 extern uint8 _end;
 
 extern "C" int main(stage2_args *args);
@@ -72,7 +72,7 @@ static uint32 sBootOptions;
 static void
 clear_bss(void)
 {
-       memset(&__bss_start, 0, &_end - &__bss_start);
+       memset(&__bss_start, 0, &__bss_end - &__bss_start);
 }
 
 
diff --git a/src/system/ldscripts/arm/boot_loader_u-boot.ld 
b/src/system/ldscripts/arm/boot_loader_u-boot.ld
index 055c104..577ee75 100644
--- a/src/system/ldscripts/arm/boot_loader_u-boot.ld
+++ b/src/system/ldscripts/arm/boot_loader_u-boot.ld
@@ -1,6 +1,8 @@
 OUTPUT_FORMAT("elf32-littlearm", "elf32-littlearm", "elf32-littlearm")
 OUTPUT_ARCH(arm)
 
+STACK_SIZE = 16384;
+
 ENTRY(_start)
 SECTIONS
 {
@@ -29,6 +31,14 @@ SECTIONS
        /* uninitialized data (in same segment as writable data) */
        __bss_start = .;
        .bss : { *(.bss) }
+       __bss_end = .;
+
+       .stack : {
+               __stack_start = .;
+               . += STACK_SIZE;
+               . = ALIGN(0x8);
+               __stack_top = .;
+       }
 
        . = ALIGN(0x1000);
        _end = . ;

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

Commit:      e3020a50396a213352f70782904fa34546b6f2e4
URL:         http://cgit.haiku-os.org/haiku/commit/?id=e3020a5
Author:      Ithamar R. Adema <ithamar@xxxxxxxxxxxxxxxxxxx>
Date:        Sat Sep  6 20:25:31 2014 UTC

ARM: remove initrd handling from mmu code

Let the platform mmu_map_physical_memory the initrd region, and
reserve it before calling mmu_init. This removes another hardcoded
address, since e.g. U-Boot gets the address from the uImage file.

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

diff --git a/build/jam/board/beagle/BoardSetup 
b/build/jam/board/beagle/BoardSetup
index 27eeea7..10994d1 100644
--- a/build/jam/board/beagle/BoardSetup
+++ b/build/jam/board/beagle/BoardSetup
@@ -61,8 +61,7 @@ HAIKU_BOARD_SDIMAGE_FILES =
 #
 # gcc flags for the specific cpu
 
-local flags = -mcpu=cortex-a8 -mfpu=vfpv3 -mfloat-abi=hard
-          -DHAIKU_BOARD_LOADER_UIBASE=$(HAIKU_BOARD_LOADER_UIBASE) ;
+local flags = -mcpu=cortex-a8 -mfpu=vfpv3 -mfloat-abi=hard ;
 
 HAIKU_ASFLAGS_$(HAIKU_PACKAGING_ARCH) += $(flags) ;
 HAIKU_CCFLAGS_$(HAIKU_PACKAGING_ARCH) += $(flags) ;
diff --git a/src/system/boot/arch/arm/arch_mmu.cpp 
b/src/system/boot/arch/arm/arch_mmu.cpp
index 81c75de..3bd0ffd 100644
--- a/src/system/boot/arch/arm/arch_mmu.cpp
+++ b/src/system/boot/arch/arm/arch_mmu.cpp
@@ -110,12 +110,6 @@ static struct memblock LOADER_MEMORYMAP[] = {
                kLoaderBaseAddress + 0x11FFFFF,
                ARM_MMU_L2_FLAG_C,
        },
-       {
-               "RAM_initrd", // initrd
-               HAIKU_BOARD_LOADER_UIBASE,
-               HAIKU_BOARD_LOADER_UIBASE + 0x500000,
-               ARM_MMU_L2_FLAG_C,
-       },
 
 #ifdef FB_BASE
        {
@@ -548,8 +542,10 @@ mmu_init_for_kernel(void)
        TRACE(("mmu_init_for_kernel\n"));
 
        // save the memory we've physically allocated
-       gKernelArgs.physical_allocated_range[0].size
-               = sNextPhysicalAddress - 
gKernelArgs.physical_allocated_range[0].start;
+       int index = gKernelArgs.num_physical_allocated_ranges;
+       gKernelArgs.physical_allocated_range[index].start = SDRAM_BASE;
+       gKernelArgs.physical_allocated_range[index].size = sNextPhysicalAddress 
- SDRAM_BASE;
+       gKernelArgs.num_physical_allocated_ranges++;
 
        // Save the memory we've virtually allocated (for the kernel and other
        // stuff)
@@ -619,11 +615,6 @@ mmu_init(void)
        gKernelArgs.physical_memory_range[0].size = highestRAMAddress - 
SDRAM_BASE;
        gKernelArgs.num_physical_memory_ranges = 1;
 
-       gKernelArgs.physical_allocated_range[0].start = SDRAM_BASE;
-       gKernelArgs.physical_allocated_range[0].size = 0;
-       gKernelArgs.num_physical_allocated_ranges = 1;
-               // remember the start of the allocated physical pages
-
        init_page_directory();
 
        // map in a kernel stack
diff --git a/src/system/boot/platform/raspberrypi_arm/start.cpp 
b/src/system/boot/platform/raspberrypi_arm/start.cpp
index 46b0e8d..2d64bd7 100644
--- a/src/system/boot/platform/raspberrypi_arm/start.cpp
+++ b/src/system/boot/platform/raspberrypi_arm/start.cpp
@@ -134,6 +134,9 @@ _start(void)
        // Flick on "OK" led, use pre-mmu firmware base
        gpio_write(gPeripheralBase + GPIO_BASE, 16, 0);
 
+       // Reserve memory for boot archive before switching on MMU
+       insert_physical_allocated_range(BOOT_ARCHIVE_BASE, BOOT_ARCHIVE_SIZE);
+
        // To debug mmu, enable serial_init above me!
        mmu_init();
 
diff --git a/src/system/boot/platform/u-boot/start.cpp 
b/src/system/boot/platform/u-boot/start.cpp
index d2e4203..f50c896 100644
--- a/src/system/boot/platform/u-boot/start.cpp
+++ b/src/system/boot/platform/u-boot/start.cpp
@@ -267,8 +267,20 @@ start_raw(int argc, const char **argv)
                        dump_fdt(gFDT);
        }
        
+       if (args.platform.boot_tgz_size > 0) {
+               
insert_physical_allocated_range((addr_t)args.platform.boot_tgz_data,
+                       args.platform.boot_tgz_size);
+       }
+
        mmu_init();
 
+       // Handle our tarFS post-mmu
+       if (args.platform.boot_tgz_size > 0) {
+               args.platform.boot_tgz_data = 
(void*)mmu_map_physical_memory((addr_t)
+                       args.platform.boot_tgz_data, 
args.platform.boot_tgz_size,
+                       kDefaultPageFlags);
+       }
+
        // wait a bit to give the user the opportunity to press a key
 //     spin(750000);
 

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

Commit:      3e450daa1c856fb979541d9f5a8275ad25d6c0e4
URL:         http://cgit.haiku-os.org/haiku/commit/?id=3e450da
Author:      Ithamar R. Adema <ithamar@xxxxxxxxxxxxxxxxxxx>
Date:        Sat Sep  6 22:28:54 2014 UTC

ARM: remove the loader from the memory map table

We have _start/_end symbols to mark our start and end, use those
to determine where we are loaded. We're slowly getting closer to
a fully dynamic handling of our memory map!

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

diff --git a/src/system/boot/arch/arm/arch_mmu.cpp 
b/src/system/boot/arch/arm/arch_mmu.cpp
index 3bd0ffd..a0f1693 100644
--- a/src/system/boot/arch/arm/arch_mmu.cpp
+++ b/src/system/boot/arch/arm/arch_mmu.cpp
@@ -64,6 +64,9 @@ static const size_t kMaxKernelSize = 0x800000;
 // Base address for loader
 static const size_t kLoaderBaseAddress = KERNEL_LOAD_BASE + kMaxKernelSize;
 
+// Start and end of ourselfs
+extern int _start, _end;
+
 /*
 *defines a block in memory
 */
@@ -93,12 +96,6 @@ static struct memblock LOADER_MEMORYMAP[] = {
                ARM_MMU_L2_FLAG_C,
        },
        {
-               "RAM_loader", // 1MB loader
-               kLoaderBaseAddress + 0,
-               kLoaderBaseAddress + 0x0fffff,
-               ARM_MMU_L2_FLAG_C,
-       },
-       {
                "RAM_pt", // Page Table 1MB
                kLoaderBaseAddress + 0x100000,
                kLoaderBaseAddress + 0x1FFFFF,
@@ -126,12 +123,14 @@ static struct memblock LOADER_MEMORYMAP[] = {
        // not cached not buffered, R/W
 
 static addr_t sNextPhysicalAddress = 0; //will be set by mmu_init
-static addr_t sNextVirtualAddress = LOADER_MEMORYMAP[4].start;
+static addr_t sNextVirtualAddress = 0;
 
 static addr_t sNextPageTableAddress = 0;
 //the page directory is in front of the pagetable
 static uint32 kPageTableRegionEnd = 0;
 
+static uint32 sSmallPageType = ARM_MMU_L2_TYPE_SMALLEXT;
+
 // working page directory and page table
 static uint32 *sPageDirectory = 0 ;
 //page directory has to be on a multiple of 16MB for
@@ -309,17 +308,34 @@ get_or_create_page_table(addr_t address, uint32 type)
 }
 
 
+static void
+mmu_map_identity(addr_t start, size_t end, int flags)
+{
+       uint32 *pageTable = NULL;
+       uint32 pageTableIndex = 0;
+
+       start = ROUNDDOWN(start, B_PAGE_SIZE);
+       end = ROUNDUP(end, B_PAGE_SIZE);
+
+       TRACE(("mmu_map_identity: [ %" B_PRIxADDR " - %" B_PRIxADDR "]\n", 
start, end));
+
+       for (addr_t address = start; address < end; address += B_PAGE_SIZE) {
+               if (pageTable == NULL
+                       || pageTableIndex >= ARM_MMU_L2_COARSE_ENTRY_COUNT) {
+                       pageTable = get_or_create_page_table(address,
+                               ARM_MMU_L1_TYPE_COARSE);
+                       pageTableIndex = VADDR_TO_PTENT(address);
+               }
+
+               pageTable[pageTableIndex++]
+                       = address | flags | sSmallPageType;
+       }
+}
+
 void
 init_page_directory()
 {
        TRACE(("init_page_directory\n"));
-       uint32 smallType;
-
-       // see if subpages are disabled
-       if (mmu_read_C1() & (1 << 23))
-               smallType = ARM_MMU_L2_TYPE_SMALLNEW;
-       else
-               smallType = ARM_MMU_L2_TYPE_SMALLEXT;
 
        gKernelArgs.arch_args.phys_pgdir = (uint32)sPageDirectory;
 
@@ -327,6 +343,9 @@ init_page_directory()
        for (uint32 i = 0; i < ARM_MMU_L1_TABLE_ENTRY_COUNT; i++)
                sPageDirectory[i] = 0;
 
+       // map ourselfs first... just to make sure
+       mmu_map_identity((addr_t)&_start, (addr_t)&_end, ARM_MMU_L2_FLAG_C);
+
        for (uint32 i = 0; i < ARRAY_SIZE(LOADER_MEMORYMAP); i++) {
 
                TRACE(("BLOCK: %s START: %lx END %lx\n", 
LOADER_MEMORYMAP[i].name,
@@ -335,21 +354,8 @@ init_page_directory()
                addr_t address = LOADER_MEMORYMAP[i].start;
                ASSERT((address & ~ARM_PTE_ADDRESS_MASK) == 0);
 
-               uint32 *pageTable = NULL;
-               uint32 pageTableIndex = 0;
-
-               while (address < LOADER_MEMORYMAP[i].end) {
-                       if (pageTable == NULL
-                               || pageTableIndex >= 
ARM_MMU_L2_COARSE_ENTRY_COUNT) {
-                               pageTable = get_or_create_page_table(address,
-                                       ARM_MMU_L1_TYPE_COARSE);
-                               pageTableIndex = VADDR_TO_PTENT(address);
-                       }
-
-                       pageTable[pageTableIndex++]
-                               = address | LOADER_MEMORYMAP[i].flags | 
smallType;
-                       address += B_PAGE_SIZE;
-               }
+               mmu_map_identity(LOADER_MEMORYMAP[i].start, 
LOADER_MEMORYMAP[i].end,
+                       LOADER_MEMORYMAP[i].flags);
        }
 
        // Map the page directory itself.
@@ -588,6 +594,10 @@ mmu_init(void)
 {
        TRACE(("mmu_init\n"));
 
+       // see if subpages are disabled
+       if (mmu_read_C1() & (1 << 23))
+               sSmallPageType = ARM_MMU_L2_TYPE_SMALLNEW;
+
        mmu_write_C1(mmu_read_C1() & ~((1 << 29) | (1 << 28) | (1 << 0)));
                // access flag disabled, TEX remap disabled, mmu disabled
 
@@ -595,8 +605,10 @@ mmu_init(void)
 
        // calculate lowest RAM adress from MEMORYMAP
        for (uint32 i = 0; i < ARRAY_SIZE(LOADER_MEMORYMAP); i++) {
-               if (strcmp("RAM_free", LOADER_MEMORYMAP[i].name) == 0)
+               if (strcmp("RAM_free", LOADER_MEMORYMAP[i].name) == 0) {
                        sNextPhysicalAddress = LOADER_MEMORYMAP[i].start;
+                       sNextVirtualAddress = LOADER_MEMORYMAP[i].start;
+               }
 
                if (strcmp("RAM_pt", LOADER_MEMORYMAP[i].name) == 0) {
                        sNextPageTableAddress = LOADER_MEMORYMAP[i].start
@@ -611,9 +623,10 @@ mmu_init(void)
                }
        }
 
-       gKernelArgs.physical_memory_range[0].start = SDRAM_BASE;
-       gKernelArgs.physical_memory_range[0].size = highestRAMAddress - 
SDRAM_BASE;
-       gKernelArgs.num_physical_memory_ranges = 1;
+       insert_physical_memory_range(SDRAM_BASE, highestRAMAddress - 
SDRAM_BASE);
+
+       // mark ourselfs as allocated, so init_page_directory doesn't overwrite 
us
+       insert_physical_allocated_range((addr_t)&_start, (addr_t)&_end - 
(addr_t)&_start);
 
        init_page_directory();
 

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

Revision:    hrev47834
Commit:      eea45d0a329d51c5fcf8bf904316e7761aaaa96f
URL:         http://cgit.haiku-os.org/haiku/commit/?id=eea45d0
Author:      Ithamar R. Adema <ithamar@xxxxxxxxxxxxxxxxxxx>
Date:        Sun Sep  7 02:45:14 2014 UTC

ARM: cleanup of bootloader memory mapping

* Removes default mapping of a portion of the RAM (will be done
  as needed)
* Passes on the page directory area to kernel, so on early vm init
  the kernel can use the area for pagetable allocation.
* Leaves it to the platform to pass in physical memory range(s). This
  will ultimately come from FDT.
* Fix long standing issue with allocation of the heap, potentially
  causing other part of the bootloader to overwrite the heap.
* Implements pagetable allocator in kernel for early vm mapping.

This fixes the first PANIC seen, we now just get the same one later
on when the VM is up... more to come...

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

diff --git a/headers/private/kernel/arch/arm/arch_kernel_args.h 
b/headers/private/kernel/arch/arm/arch_kernel_args.h
index 3f39508..39a9316 100644
--- a/headers/private/kernel/arch/arm/arch_kernel_args.h
+++ b/headers/private/kernel/arch/arm/arch_kernel_args.h
@@ -20,6 +20,7 @@ typedef struct {
        // architecture specific
         uint32         phys_pgdir;
         uint32         vir_pgdir;
+       uint32          next_pagetable;
 } arch_kernel_args;
 
 #endif /* KERNEL_ARCH_ARM_KERNEL_ARGS_H */
diff --git a/src/system/boot/arch/arm/arch_mmu.cpp 
b/src/system/boot/arch/arm/arch_mmu.cpp
index a0f1693..715ffc6 100644
--- a/src/system/boot/arch/arm/arch_mmu.cpp
+++ b/src/system/boot/arch/arm/arch_mmu.cpp
@@ -61,10 +61,7 @@ TODO:
 // 8 MB for the kernel, kernel args, modules, driver settings, ...
 static const size_t kMaxKernelSize = 0x800000;
 
-// Base address for loader
-static const size_t kLoaderBaseAddress = KERNEL_LOAD_BASE + kMaxKernelSize;
-
-// Start and end of ourselfs
+// Start and end of ourselfs (from ld script)
 extern int _start, _end;
 
 /*
@@ -95,18 +92,6 @@ static struct memblock LOADER_MEMORYMAP[] = {
                KERNEL_LOAD_BASE + kMaxKernelSize - 1,
                ARM_MMU_L2_FLAG_C,
        },
-       {
-               "RAM_pt", // Page Table 1MB
-               kLoaderBaseAddress + 0x100000,
-               kLoaderBaseAddress + 0x1FFFFF,
-               ARM_MMU_L2_FLAG_C,
-       },
-       {
-               "RAM_free", // 16MB free RAM (more but we don't map it 
automaticaly)
-               kLoaderBaseAddress + 0x0200000,
-               kLoaderBaseAddress + 0x11FFFFF,
-               ARM_MMU_L2_FLAG_C,
-       },
 
 #ifdef FB_BASE
        {
@@ -127,7 +112,7 @@ static addr_t sNextVirtualAddress = 0;
 
 static addr_t sNextPageTableAddress = 0;
 //the page directory is in front of the pagetable
-static uint32 kPageTableRegionEnd = 0;
+static uint32 sPageTableRegionEnd = 0;
 
 static uint32 sSmallPageType = ARM_MMU_L2_TYPE_SMALLEXT;
 
@@ -138,16 +123,6 @@ static uint32 *sPageDirectory = 0 ;
 
 
 static addr_t
-get_next_virtual_address(size_t size)
-{
-       addr_t address = sNextVirtualAddress;
-       sNextVirtualAddress += size;
-
-       return address;
-}
-
-
-static addr_t
 get_next_virtual_address_aligned(size_t size, uint32 mask)
 {
        addr_t address = (sNextVirtualAddress) & mask;
@@ -158,16 +133,6 @@ get_next_virtual_address_aligned(size_t size, uint32 mask)
 
 
 static addr_t
-get_next_physical_address(size_t size)
-{
-       addr_t address = sNextPhysicalAddress;
-       sNextPhysicalAddress += size;
-
-       return address;
-}
-
-
-static addr_t
 get_next_physical_address_aligned(size_t size, uint32 mask)
 {
        addr_t address = sNextPhysicalAddress & mask;
@@ -246,8 +211,8 @@ static uint32 *
 get_next_page_table(uint32 type)
 {
        TRACE(("get_next_page_table, sNextPageTableAddress 0x%" B_PRIxADDR
-               ", kPageTableRegionEnd 0x%" B_PRIxADDR ", type 0x%" B_PRIx32 
"\n",
-               sNextPageTableAddress, kPageTableRegionEnd, type));
+               ", sPageTableRegionEnd 0x%" B_PRIxADDR ", type 0x%" B_PRIx32 
"\n",
+               sNextPageTableAddress, sPageTableRegionEnd, type));
 
        size_t size = 0;
        size_t entryCount = 0;
@@ -266,7 +231,7 @@ get_next_page_table(uint32 type)
        }
 
        addr_t address = sNextPageTableAddress;
-       if (address < kPageTableRegionEnd)
+       if (address < sPageTableRegionEnd)
                sNextPageTableAddress += size;
        else {
                TRACE(("page table allocation outside of pagetable region!\n"));
@@ -337,7 +302,8 @@ init_page_directory()
 {
        TRACE(("init_page_directory\n"));
 
-       gKernelArgs.arch_args.phys_pgdir = (uint32)sPageDirectory;
+       gKernelArgs.arch_args.phys_pgdir =
+       gKernelArgs.arch_args.vir_pgdir = (uint32)sPageDirectory;
 
        // clear out the page directory
        for (uint32 i = 0; i < ARM_MMU_L1_TABLE_ENTRY_COUNT; i++)
@@ -346,6 +312,9 @@ init_page_directory()
        // map ourselfs first... just to make sure
        mmu_map_identity((addr_t)&_start, (addr_t)&_end, ARM_MMU_L2_FLAG_C);
 
+       // map our page directory region (TODO should not be identity mapped)
+       mmu_map_identity((addr_t)sPageDirectory, sPageTableRegionEnd, 
ARM_MMU_L2_FLAG_C);
+
        for (uint32 i = 0; i < ARRAY_SIZE(LOADER_MEMORYMAP); i++) {
 
                TRACE(("BLOCK: %s START: %lx END %lx\n", 
LOADER_MEMORYMAP[i].name,
@@ -358,10 +327,6 @@ init_page_directory()
                        LOADER_MEMORYMAP[i].flags);
        }
 
-       // Map the page directory itself.
-       addr_t virtualPageDirectory = mmu_map_physical_memory(
-               (addr_t)sPageDirectory, ARM_MMU_L1_TABLE_SIZE, 
kDefaultPageFlags);
-
        mmu_flush_TLB();
 
        /* set up the translation table base */
@@ -374,10 +339,6 @@ init_page_directory()
 
        /* turn on the mmu */
        mmu_write_C1(mmu_read_C1() | 0x1);
-
-       // Use the mapped page directory from now on.
-       sPageDirectory = (uint32 *)virtualPageDirectory;
-       gKernelArgs.arch_args.vir_pgdir = virtualPageDirectory;
 }
 
 
@@ -547,18 +508,16 @@ mmu_init_for_kernel(void)
 {
        TRACE(("mmu_init_for_kernel\n"));
 
+       // store next available pagetable in our pagedir mapping, for
+       // the kernel to use in early vm setup
+       gKernelArgs.arch_args.next_pagetable = sNextPageTableAddress - 
(addr_t)sPageDirectory;
+
        // save the memory we've physically allocated
-       int index = gKernelArgs.num_physical_allocated_ranges;
-       gKernelArgs.physical_allocated_range[index].start = SDRAM_BASE;
-       gKernelArgs.physical_allocated_range[index].size = sNextPhysicalAddress 
- SDRAM_BASE;
-       gKernelArgs.num_physical_allocated_ranges++;
+       insert_physical_allocated_range((addr_t)sPageDirectory, 
sNextPhysicalAddress - (addr_t)sPageDirectory);
 
        // Save the memory we've virtually allocated (for the kernel and other
        // stuff)
-       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;
+       insert_virtual_allocated_range(KERNEL_LOAD_BASE, sNextVirtualAddress - 
KERNEL_LOAD_BASE);
 
 #ifdef TRACE_MEMORY_MAP
        {
@@ -601,32 +560,18 @@ mmu_init(void)
        mmu_write_C1(mmu_read_C1() & ~((1 << 29) | (1 << 28) | (1 << 0)));
                // access flag disabled, TEX remap disabled, mmu disabled
 
-       uint32 highestRAMAddress = SDRAM_BASE;
-
-       // calculate lowest RAM adress from MEMORYMAP
-       for (uint32 i = 0; i < ARRAY_SIZE(LOADER_MEMORYMAP); i++) {
-               if (strcmp("RAM_free", LOADER_MEMORYMAP[i].name) == 0) {
-                       sNextPhysicalAddress = LOADER_MEMORYMAP[i].start;
-                       sNextVirtualAddress = LOADER_MEMORYMAP[i].start;
-               }
-
-               if (strcmp("RAM_pt", LOADER_MEMORYMAP[i].name) == 0) {
-                       sNextPageTableAddress = LOADER_MEMORYMAP[i].start
-                               + ARM_MMU_L1_TABLE_SIZE;
-                       kPageTableRegionEnd = LOADER_MEMORYMAP[i].end;
-                       sPageDirectory = (uint32 *)LOADER_MEMORYMAP[i].start;
-               }
-
-               if (strncmp("RAM_", LOADER_MEMORYMAP[i].name, 4) == 0) {
-                       if (LOADER_MEMORYMAP[i].end > highestRAMAddress)
-                               highestRAMAddress = LOADER_MEMORYMAP[i].end;
-               }
-       }
+       // allocate page directory in memory after loader
+       sPageDirectory = (uint32 *)ROUNDUP((addr_t)&_end, 0x100000);
+       sNextPageTableAddress = (addr_t)sPageDirectory + ARM_MMU_L1_TABLE_SIZE;
+       sPageTableRegionEnd = (addr_t)sPageDirectory + 0x200000;
 
-       insert_physical_memory_range(SDRAM_BASE, highestRAMAddress - 
SDRAM_BASE);
+       // Mark start for dynamic allocation
+       sNextPhysicalAddress =
+       sNextVirtualAddress = sPageTableRegionEnd;
 
-       // mark ourselfs as allocated, so init_page_directory doesn't overwrite 
us
+       // mark allocated ranges, so they don't get overwritten
        insert_physical_allocated_range((addr_t)&_start, (addr_t)&_end - 
(addr_t)&_start);
+       insert_physical_allocated_range((addr_t)sPageDirectory, 0x200000);
 
        init_page_directory();
 
@@ -678,7 +623,7 @@ platform_release_heap(struct stage2_args *args, void *base)
 status_t
 platform_init_heap(struct stage2_args *args, void **_base, void **_top)
 {
-       void *heap = (void *)get_next_physical_address(args->heap_size);
+       void *heap = mmu_allocate(NULL, args->heap_size);
        if (heap == NULL)
                return B_NO_MEMORY;
 
diff --git a/src/system/boot/platform/raspberrypi_arm/start.cpp 
b/src/system/boot/platform/raspberrypi_arm/start.cpp
index 2d64bd7..4513b72 100644
--- a/src/system/boot/platform/raspberrypi_arm/start.cpp
+++ b/src/system/boot/platform/raspberrypi_arm/start.cpp
@@ -134,6 +134,10 @@ _start(void)
        // Flick on "OK" led, use pre-mmu firmware base
        gpio_write(gPeripheralBase + GPIO_BASE, 16, 0);
 
+       // specify available physical memory, using 128MB for now
+       // TODO: support CPU/GPU memory split options
+       insert_physical_memory_range(SDRAM_BASE, 128 * 1024 * 1024);
+
        // Reserve memory for boot archive before switching on MMU
        insert_physical_allocated_range(BOOT_ARCHIVE_BASE, BOOT_ARCHIVE_SIZE);
 
diff --git a/src/system/boot/platform/u-boot/start.cpp 
b/src/system/boot/platform/u-boot/start.cpp
index f50c896..8e698d4 100644
--- a/src/system/boot/platform/u-boot/start.cpp
+++ b/src/system/boot/platform/u-boot/start.cpp
@@ -19,6 +19,7 @@
 #include <arch/cpu.h>
 #include <platform_arch.h>
 #include <platform/openfirmware/openfirmware.h>
+#include <board_config.h>
 
 #include <string.h>
 
@@ -272,6 +273,10 @@ start_raw(int argc, const char **argv)
                        args.platform.boot_tgz_size);
        }
 
+       // specify available physical memory, using 32MB for now, since our
+       // ARMv5 targets have very little by default. TODO get from FDT!
+       insert_physical_memory_range(SDRAM_BASE, 32 * 1024 * 1024);
+
        mmu_init();
 
        // Handle our tarFS post-mmu
diff --git a/src/system/kernel/arch/arm/paging/32bit/ARMPagingMethod32Bit.cpp 
b/src/system/kernel/arch/arm/paging/32bit/ARMPagingMethod32Bit.cpp
index a973bb2..eb2cae6 100644
--- a/src/system/kernel/arch/arm/paging/32bit/ARMPagingMethod32Bit.cpp
+++ b/src/system/kernel/arch/arm/paging/32bit/ARMPagingMethod32Bit.cpp
@@ -346,6 +346,15 @@ ARMPagingMethod32Bit::CreateTranslationMap(bool kernel, 
VMTranslationMap** _map)
 }
 
 
+static phys_addr_t
+get_free_pgtable(kernel_args* args)
+{
+       phys_addr_t phys = args->arch_args.phys_pgdir + 
args->arch_args.next_pagetable;
+       //addr_t virt = args->arch_args.vir_pgdir + 
args->arch_args.next_pagetable;
+       args->arch_args.next_pagetable += ARM_MMU_L2_COARSE_TABLE_SIZE;
+       return phys;
+}
+
 status_t
 ARMPagingMethod32Bit::MapEarly(kernel_args* args, addr_t virtualAddress,
        phys_addr_t physicalAddress, uint8 attributes,
@@ -357,9 +366,7 @@ ARMPagingMethod32Bit::MapEarly(kernel_args* args, addr_t 
virtualAddress,
                phys_addr_t pgtable;
                page_directory_entry *e;
                // we need to allocate a pgtable
-               pgtable = get_free_page(args);
-               // pgtable is in pages, convert to physical address
-               pgtable *= B_PAGE_SIZE;
+               pgtable = get_free_pgtable(args);
 
                TRACE("ARMPagingMethod32Bit::MapEarly(): asked for free page 
for "
                        "pgtable. %#" B_PRIxPHYSADDR "\n", pgtable);


Other related posts:

  • » [haiku-commits] haiku: hrev47834 - src/system/boot/arch/arm src/system/boot/platform/u-boot src/system/kernel/arch/arm/paging/32bit src/system/boot/platform/raspberrypi_arm build/jam/board/beagle - ithamar