armv8: try to print things.
authorSimon Gerber <simon.gerber@inf.ethz.ch>
Thu, 18 Jun 2015 08:56:23 +0000 (10:56 +0200)
committerSimon Gerber <simon.gerber@inf.ethz.ch>
Thu, 18 Jun 2015 11:54:18 +0000 (13:54 +0200)
Signed-off-by: Simon Gerber <simon.gerber@inf.ethz.ch>

kernel/arch/apm88xxxx/boot.S
kernel/arch/apm88xxxx/init.c
kernel/include/uefi_mmap.h [new file with mode: 0644]

index 03c5d53..498e5cd 100644 (file)
@@ -1,23 +1,22 @@
 /**
  * \file
- * \brief Bootstrap the kernel for ARMv7 processors.  This code is
+ * \brief Bootstrap the kernel for UEFI/ARMv8 platforms.  This code is
  *      entered from the bootloader (typically arm_molly, RedBoot,
  *      etc.).
  */
 /*
- * Copyright (c) 2009 ETH Zurich.
+ * Copyright (c) 2015 ETH Zurich.
  * All rights reserved.
  *
  * This file is distributed under the terms in the attached LICENSE file.
  * If you do not find this file, copies can be found by writing to:
- * ETH Zurich D-INFK, Haldeneggsteig 4, CH-8092 Zurich. Attn: Systems Group.
+ * ETH Zurich D-INFK, Universitaetstr 6, CH-8092 Zurich. Attn: Systems Group.
  */
 
 #ifndef __ASSEMBLER__
 #define __ASSEMBLER__   1
 #endif
 
-#include <barrelfish_kpi/flags_arch.h> // ARM_MODE_MASK
 #include <offsets.h> // BOOT_STACK_PHYS
 
         .text
 start:
         // On entry:
         //
-        // MMU disabled
-        // Caches in unknown state, but no lockdown
-        // No TLB lockdown.
-        // CPU is in a priviledged mode.
+        // Single core running (not guaranteed to be core 0)
+        // CPU is in highest non-secure privilege mode: EL2 or EL1
+        // MMU enabled, 4k translation granule, 1:1 mapping of all RAM, using
+        // TTBR0.
+        // Little-endian mode
+        // Core caches (L1&L2) and TLB enabled
+        // Non-architectural caches disabled
+        // Interrupts enabled
+        // Generic timer initialized and enabled
+        // >= 128KiB stack
+        // ACPI tables available
+        // Register x0 contains handle to ACPI root table
+        // Register x1 contains a pointer to the UEFI memory map
         //
-        // TODO: ensure mode
 
         //init stack
-        ldr     x1, =kernel_stack
-        mov     sp, x1
+        ldr     x15, =kernel_stack
+        mov     sp, x15
         add     sp, sp, #KERNEL_STACK_SIZE
 
         ldr     PIC_REGISTER, got_base
 
-        //prepare argument
-        mov     x0, x2
+        // maybe prepare arguments
         b       arch_init
         b       halt
 
index f35e58b..c077d3d 100644 (file)
@@ -1,5 +1,6 @@
 #include <kernel.h>
 #include <serial.h>
+#include <uefi_mmap.h>
 
 /**
  * \brief Kernel stack.
@@ -8,20 +9,52 @@
  */
 uintptr_t kernel_stack[KERNEL_STACK_SIZE / sizeof(uintptr_t)] __attribute__ ((aligned(16)));
 
+
 __attribute__((noreturn))
-void arch_init(void *arg);
-void arch_init(void *arg)
+void arch_init(void *arg1, EFI_MEMORY_DESCRIPTOR *uefi_mmap);
+// Currently
+void arch_init(void *arg1, EFI_MEMORY_DESCRIPTOR *uefi_mmap)
 {
-    // set console port: XXX which?
+    // set console port: UART0 is the one that's connected to the DB9
+    // connector on the back of the mustang boxes.
     serial_console_port = 0;
 
-    // init serial console, skip hwinit for now
+    // init serial console, skip hwinit, as the port is guaranteed to be
+    // initialized by UEFI.
     serial_console_init(false);
 
     // print something
     printf("Barrelfish APM88xxxx CPU driver starting at addr 0x%"
-            PRIxLVADDR" on core %"PRIuCOREID"\n",
+            PRIxLVADDR" on core %"PRIuCOREID" xxxxxxxxxx\n",
             local_phys_to_mem((lpaddr_t)&kernel_first_byte), my_core_id);
 
-    while(1);
+    printf("ACPI root table (RSDP):  %p\n", arg1);
+    printf("UEFI memory map pointer: %p\n", uefi_mmap);
+
+    uint32_t *mmap_ptr = (uint32_t *)uefi_mmap;
+
+    printf("Test 1: %p\n", mmap_ptr);
+    printf("Test 2: %p\n", mmap_ptr+1);
+    printf("Test 3: %p\n", mmap_ptr+2);
+    printf("Test 4: %p\n", mmap_ptr+3);
+    printf("Test 5: %p\n", mmap_ptr+4);
+#if 0
+    for (int i = 0; i < 8; i++) {
+        printf("%016lx: 0x%08x\n", (uint64_t)(mmap_ptr+i), mmap_ptr[i]);
+    }
+
+    printf("First memory map entry:\n");
+    printf(" Type:      %x\n", uefi_mmap->Type);
+    printf(" PhysStart: 0x%lx\n", uefi_mmap->PhysicalStart);
+    printf(" VirtStart: 0x%lx\n", uefi_mmap->VirtualStart);
+    printf(" #pages:    %lu\n", uefi_mmap->NumberOfPages);
+    printf(" Attrs:     %lx\n", uefi_mmap->Attribute);
+
+#endif
+
+    *(uint32_t*)0x1c020000 = 'a';
+
+    while(1) {
+        __asm volatile ("nop":::);
+    }
 }
diff --git a/kernel/include/uefi_mmap.h b/kernel/include/uefi_mmap.h
new file mode 100644 (file)
index 0000000..25b0fb2
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * Copyright (c) 2015 ETH Zurich.
+ * All rights reserved.
+ *
+ * This file is distributed under the terms in the attached LICENSE file.
+ * If you do not find this file, copies can be found by writing to:
+ * ETH Zurich D-INFK, Universitaetstr 6, CH-8092 Zurich. Attn: Systems Group.
+ */
+
+#ifndef UEFI_MMAP_H
+#define UEFI_MMAP_H
+
+//*******************************************************
+//EFI_VIRTUAL_ADDRESS
+// UEFI Spec v2.5, p.158
+//*******************************************************
+typedef uint64_t EFI_VIRTUAL_ADDRESS;
+
+//*******************************************************
+//EFI_PHYSICAL_ADDRESS
+// UEFI Spec v2.5, p.153
+//*******************************************************
+typedef uint64_t EFI_PHYSICAL_ADDRESS;
+
+
+//*******************************************************
+//EFI_MEMORY_TYPE
+// UEFI Spec v2.5, p.153
+//*******************************************************
+// These type values are discussed in Table 25 and Table 26
+typedef enum {
+    EfiReservedMemoryType,
+    EfiLoaderCode,
+    EfiLoaderData,
+    EfiBootServicesCode,
+    EfiBootServicesData,
+    EfiRuntimeServicesCode,
+    EfiRuntimeServicesData,
+    EfiConventionalMemory,
+    EfiUnusableMemory,
+    EfiACPIReclaimMemory,
+    EfiACPIMemoryNVS,
+    EfiMemoryMappedIO,
+    EfiMemoryMappedIOPortSpace,
+    EfiPalCode,
+    EfiPersistentMemory,
+    EfiMaxMemoryType
+} EFI_MEMORY_TYPE;
+
+//*******************************************************
+// Memory Attribute Definitions
+// from UEFI Spec v2.5, p.157
+//*******************************************************
+// These types can be “ORed” together as needed.
+typedef enum {
+    EFI_MEMORY_UC            = 0x0000000000000001,
+    EFI_MEMORY_WC            = 0x0000000000000002,
+    EFI_MEMORY_WT            = 0x0000000000000004,
+    EFI_MEMORY_WB            = 0x0000000000000008,
+    EFI_MEMORY_UCE           = 0x0000000000000010,
+    EFI_MEMORY_WP            = 0x0000000000001000,
+    EFI_MEMORY_RP            = 0x0000000000002000,
+    EFI_MEMORY_XP            = 0x0000000000004000,
+    EFI_MEMORY_NV            = 0x0000000000008000,
+    EFI_MEMORY_MORE_RELIABLE = 0x0000000000010000,
+    EFI_MEMORY_RO            = 0x0000000000020000,
+    EFI_MEMORY_RUNTIME       = 0x8000000000000000,
+} EFI_MEMORY_ATTR;
+
+//*******************************************************
+// Memory Descriptor Version Number
+//*******************************************************
+#define EFI_MEMORY_DESCRIPTOR_VERSION  1
+
+//*******************************************************
+//EFI_MEMORY_DESCRIPTOR
+//*******************************************************
+typedef struct {
+    uint32_t              Type;
+    EFI_PHYSICAL_ADDRESS  PhysicalStart;
+    EFI_VIRTUAL_ADDRESS   VirtualStart;
+    uint64_t              NumberOfPages;
+    uint64_t              Attribute;
+} EFI_MEMORY_DESCRIPTOR;
+
+#endif // UEFI_MMAP_H