[haiku-commits] BRANCH mmu_man-github.rebasing-ppc-qemu-openbios [3087b7b98c89] src/system/boot/platform/openfirmware/arch/ppc src/system/boot/platform/openfirmware headers/private/kernel/arch/ppc src/system src/system/kernel/platform/openfirmware

  • From: mmu_man-github.rebasing-ppc-qemu-openbios <community@xxxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Fri, 26 Feb 2016 23:16:59 +0100 (CET)

added 1 changeset to branch 
'refs/remotes/mmu_man-github/rebasing-ppc-qemu-openbios'
old head: 7225b933f58a3309bb9b1648945e5262016b19b1
new head: 3087b7b98c8915d13dbf4af3d1e7b7149f15d87d
overview: https://github.com/mmuman/haiku/compare/7225b933f58a...3087b7b98c89

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

3087b7b98c89: WIP: PPC: Try to get QEMU to boot

                                          [ François Revol <revol@xxxxxxx> ]

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

Commit:      3087b7b98c8915d13dbf4af3d1e7b7149f15d87d
Author:      François Revol <revol@xxxxxxx>
Date:        Mon Nov  4 03:11:51 2013 UTC

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

8 files changed, 68 insertions(+), 6 deletions(-)
headers/private/kernel/arch/ppc/arch_kernel.h    |  3 ++
src/system/boot/loader/main.cpp                  |  2 +-
.../boot/platform/openfirmware/arch/ppc/cpu.cpp  |  2 +-
.../boot/platform/openfirmware/arch/ppc/mmu.cpp  | 55 ++++++++++++++++++--
.../platform/openfirmware/real_time_clock.cpp    |  5 ++
src/system/boot/platform/openfirmware/start.cpp  |  3 ++
src/system/kernel/main.cpp                       |  2 +-
.../platform/openfirmware/openfirmware.cpp       |  2 +

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

diff --git a/headers/private/kernel/arch/ppc/arch_kernel.h 
b/headers/private/kernel/arch/ppc/arch_kernel.h
index 803a9aa..92ab819 100644
--- a/headers/private/kernel/arch/ppc/arch_kernel.h
+++ b/headers/private/kernel/arch/ppc/arch_kernel.h
@@ -12,6 +12,9 @@
 #define KERNEL_SIZE 0x80000000
 #define KERNEL_TOP  (KERNEL_BASE + (KERNEL_SIZE - 1))
 
+// XXX: QEMU OpenBIOS maps IO at the default address...
+#define KERNEL_LOAD_BASE 0x82000000
+
 /*
 ** User space layout is a little special:
 ** The user space does not completely cover the space not covered by the 
kernel.
diff --git a/src/system/boot/loader/main.cpp b/src/system/boot/loader/main.cpp
index bb7a063..5b2e44f 100644
--- a/src/system/boot/loader/main.cpp
+++ b/src/system/boot/loader/main.cpp
@@ -18,7 +18,7 @@
 #include "file_systems/packagefs/packagefs.h"
 
 
-//#define TRACE_MAIN
+#define TRACE_MAIN
 #ifdef TRACE_MAIN
 #      define TRACE(x) dprintf x
 #else
diff --git a/src/system/boot/platform/openfirmware/arch/ppc/cpu.cpp 
b/src/system/boot/platform/openfirmware/arch/ppc/cpu.cpp
index a2a4b2a..df31e81 100644
--- a/src/system/boot/platform/openfirmware/arch/ppc/cpu.cpp
+++ b/src/system/boot/platform/openfirmware/arch/ppc/cpu.cpp
@@ -105,7 +105,7 @@ boot_arch_cpu_init(void)
 
        // allocate the kernel stacks (the memory stuff is already initialized
        // at this point)
-       addr_t stack = (addr_t)arch_mmu_allocate((void*)0x80000000,
+       addr_t stack = (addr_t)arch_mmu_allocate(NULL,
                cpuCount * (KERNEL_STACK_SIZE + KERNEL_STACK_GUARD_PAGES * 
B_PAGE_SIZE),
                B_READ_AREA | B_WRITE_AREA, false);
        if (!stack) {
diff --git a/src/system/boot/platform/openfirmware/arch/ppc/mmu.cpp 
b/src/system/boot/platform/openfirmware/arch/ppc/mmu.cpp
index a89fec7..d2004fa 100644
--- a/src/system/boot/platform/openfirmware/arch/ppc/mmu.cpp
+++ b/src/system/boot/platform/openfirmware/arch/ppc/mmu.cpp
@@ -37,7 +37,7 @@
 //#define PHYSINVAL ((void *)-1)
 #define PHYSINVAL NULL
 
-//#define TRACE_MMU
+#define TRACE_MMU
 #ifdef TRACE_MMU
 #   define TRACE(x...) dprintf(x)
 #else
@@ -49,6 +49,8 @@ segment_descriptor sSegments[16];
 page_table_entry_group *sPageTable;
 uint32 sPageTableHashMask;
 
+static const size_t kMaxKernelSize = 0x1000000;                // 16 MB for 
the kernel
+
 
 // begin and end of the boot loader
 extern "C" uint8 __text_begin;
@@ -485,6 +487,8 @@ extern "C" void *
 arch_mmu_allocate(void *_virtualAddress, size_t size, uint8 _protection,
        bool exactAddress)
 {
+       dprintf("arch_mmu_allocate(%p, size %" B_PRIuSIZE ", %08x)\n",
+               _virtualAddress, size, _protection);
        // we only know page sizes
        size = ROUNDUP(size, B_PAGE_SIZE);
 
@@ -498,7 +502,7 @@ arch_mmu_allocate(void *_virtualAddress, size_t size, uint8 
_protection,
        // that avoids trouble in the kernel, when we decide to keep the region.
        void *virtualAddress = _virtualAddress;
        if (!virtualAddress)
-               virtualAddress = (void*)KERNEL_BASE;
+               virtualAddress = (void*)(KERNEL_LOAD_BASE + kMaxKernelSize);
 
        // find free address large enough to hold "size"
        virtualAddress = find_free_virtual_range(virtualAddress, size);
@@ -575,6 +579,7 @@ map_callback(struct of_arguments *args)
        int length = args->Argument(2);
        int mode = args->Argument(3);
        int &error = args->ReturnValue(0);
+dprintf("map_callback(%p)\n", args);
 
        // insert range in physical allocated if needed
 
@@ -840,7 +845,7 @@ arch_mmu_init(void)
 
 #if 0
        block_address_translation bats[8];
-       getibats(bats);
+       getibats((int *)bats);
        for (int32 i = 0; i < 8; i++) {
                printf("page index %u, length %u, ppn %u\n", bats[i].page_index,
                        bats[i].length, bats[i].physical_block_number);
@@ -874,6 +879,21 @@ arch_mmu_init(void)
                physicalTable = table;
        }
 
+       // QEMU OpenBIOS
+/*
+       insert_physical_allocated_range(0xfff00000, 0x00100000);
+       insert_virtual_allocated_range(0xfff00000, 0x00100000);
+       map_range((void *)0xfff00000, (void *)0xfff00000,
+               0x00100000, PAGE_READ_WRITE);
+*/
+       // QEMU OpenBIOS PCI IO space
+
+       insert_physical_allocated_range(0x80000000, 0x04000000);
+       insert_virtual_allocated_range(0x80000000, 0x04000000);
+       map_range((void *)0x80000000, (void *)0x80000000,
+               0x04000000, PAGE_READ_WRITE);
+
+
        if (exceptionHandlers == (void *)-1) {
                // TODO: create mapping for the exception handlers
                dprintf("Error: no mapping for the exception handlers!\n");
@@ -882,17 +902,45 @@ arch_mmu_init(void)
        // Set the Open Firmware memory callback. From now on the Open Firmware
        // will ask us for memory.
        arch_set_callback();
+dprintf("<arch_set_callback\n");
+
+/*
+       if (!realMode) {
+               block_address_translation bat;
+
+               bat.length = BAT_LENGTH_256MB;
+               bat.kernel_valid = true;
+               bat.memory_coherent = true;
+               bat.protection = BAT_READ_WRITE;
+
+               set_ibat0(&bat);
+               set_dbat0(&bat);
+               isync();
+       }
+*/
+
+
+//     dprintf("set_msr(%08lx)\n", get_msr() &
+//             ~(MSR_INST_ADDRESS_TRANSLATION | MSR_DATA_ADDRESS_TRANSLATION));
+       set_msr(get_msr() &
+               ~(/*MSR_MACHINE_CHECK_ENABLED|*/MSR_INST_ADDRESS_TRANSLATION | 
MSR_DATA_ADDRESS_TRANSLATION));
 
        // set up new page table and turn on translation again
 
        for (int32 i = 0; i < 16; i++) {
+       //for (int32 i = 15/*XXX:0*/; i > -1; i--) {
+//dprintf("ppc_set_segment_register(%d, %lx)\n", i, sSegments[i]);
                ppc_set_segment_register((void *)(i * 0x10000000), 
sSegments[i]);
                        // one segment describes 256 MB of memory
        }
 
+//dprintf("ppc_set_page_table()\n");
        ppc_set_page_table(physicalTable, tableSize);
+//dprintf("invalidate_tlb()\n");
        invalidate_tlb();
 
+
+/*
        if (!realMode) {
                // clear BATs
                reset_ibats();
@@ -900,6 +948,7 @@ arch_mmu_init(void)
                ppc_sync();
                isync();
        }
+*/
 
        set_msr(MSR_MACHINE_CHECK_ENABLED | MSR_FP_AVAILABLE
                | MSR_INST_ADDRESS_TRANSLATION | MSR_DATA_ADDRESS_TRANSLATION);
diff --git a/src/system/boot/platform/openfirmware/real_time_clock.cpp 
b/src/system/boot/platform/openfirmware/real_time_clock.cpp
index 3ea8bf5..6204473 100644
--- a/src/system/boot/platform/openfirmware/real_time_clock.cpp
+++ b/src/system/boot/platform/openfirmware/real_time_clock.cpp
@@ -8,6 +8,7 @@
 #include "real_time_clock.h"
 
 #include <stdio.h>
+#include <KernelExport.h>
 
 #include <boot/kernel_args.h>
 #include <boot/stage2.h>
@@ -21,16 +22,20 @@ static int sHandle = OF_FAILED;
 status_t
 init_real_time_clock(void)
 {
+       return B_OK;
        // find RTC
        int rtcCookie = 0;
+dprintf("of_get_next_device(&(%d),'rtc')\n", rtcCookie);
        if (of_get_next_device(&rtcCookie, 0, "rtc",
                        gKernelArgs.platform_args.rtc_path,
                        sizeof(gKernelArgs.platform_args.rtc_path)) != B_OK) {
                printf("init_real_time_clock(): Found no RTC device!");
                return B_ERROR;
        }
+dprintf("of_get_next_device(rtc): '%s'\n", gKernelArgs.platform_args.rtc_path);
 
        sHandle = of_open(gKernelArgs.platform_args.rtc_path);
+dprintf("of_open(rtc): %d\n", sHandle);
        if (sHandle == OF_FAILED) {
                printf("%s(): Could not open RTC device!\n", __func__);
                return B_ERROR;
diff --git a/src/system/boot/platform/openfirmware/start.cpp 
b/src/system/boot/platform/openfirmware/start.cpp
index 2938db2..186135d 100644
--- a/src/system/boot/platform/openfirmware/start.cpp
+++ b/src/system/boot/platform/openfirmware/start.cpp
@@ -187,8 +187,10 @@ start(void *openFirmwareEntry)
        if (boot_arch_cpu_init() != B_OK)
                of_exit();
 
+dprintf("boot_arch_cpu_init done\n");
        if (init_real_time_clock() != B_OK)
                of_exit();
+dprintf("init_real_time_clock done\n");
 
        // check for key presses once
        sBootOptions = 0;
@@ -203,6 +205,7 @@ start(void *openFirmwareEntry)
 
        gKernelArgs.platform_args.openfirmware_entry = openFirmwareEntry;
 
+dprintf("call main()\n");
        main(&args);
                // if everything goes fine, main() never returns
 
diff --git a/src/system/kernel/main.cpp b/src/system/kernel/main.cpp
index f3a0a9b..361bedc 100644
--- a/src/system/kernel/main.cpp
+++ b/src/system/kernel/main.cpp
@@ -59,7 +59,7 @@
 #include "vm/VMAnonymousCache.h"
 
 
-//#define TRACE_BOOT
+#define TRACE_BOOT
 #ifdef TRACE_BOOT
 #      define TRACE(x...) dprintf("INIT: " x)
 #else
diff --git a/src/system/kernel/platform/openfirmware/openfirmware.cpp 
b/src/system/kernel/platform/openfirmware/openfirmware.cpp
index 1f1d997..3c2139f 100644
--- a/src/system/kernel/platform/openfirmware/openfirmware.cpp
+++ b/src/system/kernel/platform/openfirmware/openfirmware.cpp
@@ -6,6 +6,7 @@
 #include <platform/openfirmware/openfirmware.h>
 
 #include <stdarg.h>
+#include <KernelExport.h>
 
 
 // OpenFirmware entry function
@@ -505,6 +506,7 @@ of_release(void *virtualAddress, int size)
 void *
 of_claim(void *virtualAddress, int size, int align)
 {
+dprintf("OF at %p\n", gCallOpenFirmware);
        struct {
                const char      *name;
                int                     num_args;


Other related posts:

  • » [haiku-commits] BRANCH mmu_man-github.rebasing-ppc-qemu-openbios [3087b7b98c89] src/system/boot/platform/openfirmware/arch/ppc src/system/boot/platform/openfirmware headers/private/kernel/arch/ppc src/system src/system/kernel/platform/openfirmware - mmu_man-github . rebasing-ppc-qemu-openbios