[haiku-commits] BRANCH jessicah-github.efi.master [fc29aea9b31c] src/system/boot/platform/efi

  • From: jessicah-github.efi.master <community@xxxxxxxxxxxx>
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 13 Sep 2015 01:46:57 +0200 (CEST)

added 1 changeset to branch 'refs/remotes/jessicah-github/efi.master'
old head: 70e433808f7082477fbe63212108460802f822cb
new head: fc29aea9b31cb4617d978d4a6020d67e30184841
overview: https://github.com/jessicah/haiku/compare/70e433808f70...fc29aea9b31c

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

fc29aea9b31c: UEFI: fix up debug, trace MMU post-UEFI code.

[ Jessica Hamilton <jessica.l.hamilton@xxxxxxxxx> ]

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

Commit: fc29aea9b31cb4617d978d4a6020d67e30184841
Author: Jessica Hamilton <jessica.l.hamilton@xxxxxxxxx>
Date: Sat Sep 12 10:04:25 2015 UTC

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

3 files changed, 72 insertions(+), 11 deletions(-)
src/system/boot/platform/efi/debug.cpp | 3 --
src/system/boot/platform/efi/mmu.cpp | 69 ++++++++++++++++++++++++++++--
src/system/boot/platform/efi/start.cpp | 11 ++---

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

diff --git a/src/system/boot/platform/efi/debug.cpp
b/src/system/boot/platform/efi/debug.cpp
index 3b8ae99..23ae269 100644
--- a/src/system/boot/platform/efi/debug.cpp
+++ b/src/system/boot/platform/efi/debug.cpp
@@ -74,9 +74,6 @@ dprintf_args(const char *format, va_list args)

syslog_write(buffer, length);
serial_puts(buffer, length);
-
- if (platform_boot_options() & BOOT_OPTION_DEBUG_OUTPUT)
- puts(buffer);
}


diff --git a/src/system/boot/platform/efi/mmu.cpp
b/src/system/boot/platform/efi/mmu.cpp
index 7548f4e..0ae1d36 100644
--- a/src/system/boot/platform/efi/mmu.cpp
+++ b/src/system/boot/platform/efi/mmu.cpp
@@ -133,17 +133,46 @@ mmu_generate_post_efi_page_tables(UINTN memory_map_size,
EFI_MEMORY_DESCRIPTOR *
return (uint64)pml4;
}

+static const char* memory_types[] = {
+ "reserved",
+ "loader code",
+ "loader data",
+ "boot services code",
+ "boot services data",
+ "runtime services code",
+ "runtime services data",
+ "conventional",
+ "unusable",
+ "acpi reclaim",
+ "acpi nvs",
+ "mem-mapped io",
+ "mem-mapped io portspace",
+ "pal code",
+ NULL
+};
+
// Called after EFI boot services exit.
// Currently assumes that the memory map is sane... Sorted and no overlapping
regions.
void
mmu_post_efi_setup(UINTN memory_map_size, EFI_MEMORY_DESCRIPTOR *memory_map,
UINTN descriptor_size, UINTN descriptor_version)
{
// Add physical memory to the kernel args and update virtual addresses
for EFI regions..
+ dprintf("entering mmu_post_efi_setup...\n");
addr_t addr = (addr_t)memory_map;
gKernelArgs.num_physical_memory_ranges = 0;
+ dprintf("%-33s %8s %8s %4s %-24s %s\n",
+ "Start (P/V)", "# Pages", "Size", "Attr", "Type", "Action");
for (UINTN i = 0; i < memory_map_size / descriptor_size; ++i) {
EFI_MEMORY_DESCRIPTOR *entry = (EFI_MEMORY_DESCRIPTOR *)(addr +
i * descriptor_size);
+ const char* action = "";
+ UINTN magnitude = 0;
+ char unit = ' ';
switch (entry->Type) {
+ case EfiReservedMemoryType:
+ case EfiMemoryMappedIO:
+ case EfiMemoryMappedIOPortSpace:
+ action = "skipped";
+ break;
case EfiLoaderCode:
case EfiLoaderData:
case EfiBootServicesCode:
@@ -157,27 +186,57 @@ mmu_post_efi_setup(UINTN memory_map_size,
EFI_MEMORY_DESCRIPTOR *memory_map, UIN
base = 0x100000;
if (end > (512ull * 1024 * 1024 * 1024))
end = 512ull * 1024 * 1024 * 1024;
- if (base >= end)
+ if (base >= end) {
+ action = "ignored, <1MB or >512GB";
break;
+ }
uint64_t size = end - base;
+ magnitude = size;
+ while (magnitude > 1024) {
+ magnitude /= 1024;
+ switch (unit) {
+ case ' ': unit = 'k'; break;
+ case 'k': unit = 'M'; break;
+ case 'M': unit = 'G'; break;
+ }
+ }

insert_physical_memory_range(base, size);
+ action = "insert physical memory range";
// LoaderData memory is bootloader allocated memory,
possibly
// containing the kernel or loaded drivers.
- if (entry->Type == EfiLoaderData)
+ if (entry->Type == EfiLoaderData) {
insert_physical_allocated_range(base, size);
+ action = "insert allocated physical memory
range";
+ }
break;
}
case EfiACPIReclaimMemory:
// ACPI reclaim -- physical memory we could actually
use later
gKernelArgs.ignored_physical_memory +=
entry->NumberOfPages * 4096;
+ action = "ignored physical memory";
break;
case EfiRuntimeServicesCode:
case EfiRuntimeServicesData:
+ case EfiACPIMemoryNVS:
+ case EfiPalCode:
entry->VirtualStart = entry->PhysicalStart +
0xFFFFFF0000000000ull;
+ action = "created virtual mapping";
+ break;
+ default:
+ dprintf(" >>> unhandled entry type (%x) <<<\n",
entry->Type);
break;
}
+ if (unit == ' ')
+ dprintf("%016lx/%016lx %8ld %8s %01X %-24s
%s\n",
+ entry->PhysicalStart, entry->VirtualStart,
entry->NumberOfPages,
+ "", entry->Type, memory_types[entry->Type],
action);
+ else
+ dprintf("%016lx/%016lx %8ld %7ld%c %01X
%-24s %s\n",
+ entry->PhysicalStart, entry->VirtualStart,
entry->NumberOfPages,
+ magnitude, unit, entry->Type,
memory_types[entry->Type], action);
}
+ dprintf("memory ranges setup done\n");

// Sort the address ranges.
sort_address_ranges(gKernelArgs.physical_memory_range,
@@ -186,11 +245,15 @@ mmu_post_efi_setup(UINTN memory_map_size,
EFI_MEMORY_DESCRIPTOR *memory_map, UIN
gKernelArgs.num_physical_allocated_ranges);
sort_address_ranges(gKernelArgs.virtual_allocated_range,
gKernelArgs.num_virtual_allocated_ranges);
+ dprintf("sorted the address ranges...\n");

// Switch EFI to virtual mode, using the kernel pmap.
// Something involving ConvertPointer might need to be done after this?
//
http://wiki.phoenix.com/wiki/index.php/EFI_RUNTIME_SERVICES#SetVirtualAddressMap.28.29
- kRuntimeServices->SetVirtualAddressMap(memory_map_size,
descriptor_size, descriptor_version, memory_map);
+ dprintf("setting up the virtual address map...\n");
+ dprintf("address of dprintf: %p\n", (void*)&dprintf);
+ EFI_STATUS status =
kRuntimeServices->SetVirtualAddressMap(memory_map_size, descriptor_size,
descriptor_version, memory_map);
+ dprintf("status = %lx\n", status);
}

// As far as I know, EFI uses identity mapped memory, and we already have
paging enabled
diff --git a/src/system/boot/platform/efi/start.cpp
b/src/system/boot/platform/efi/start.cpp
index 58e049d..cc78c03 100644
--- a/src/system/boot/platform/efi/start.cpp
+++ b/src/system/boot/platform/efi/start.cpp
@@ -250,7 +250,6 @@ platform_start_kernel(void)
// A changing memory map shouldn't affect the generated page tables, as
// they only needed to know about the maximum address, not any specific
entry.
dprintf("Calling ExitBootServices. So long, EFI!\n");
-puts("Calling ExitBootServices");
while (1) {
if (kBootServices->ExitBootServices(kImage, map_key) ==
EFI_SUCCESS) {
break;
@@ -269,15 +268,17 @@ puts("Calling ExitBootServices");

// Switch to BIOS serial output
serial_switch_to_bios();
- dprintf("can we still serial debug?\n");
+ dprintf("welcome to legacy serial debugging! :p\n");

// Update EFI, generate final kernel physical memory map, etc.
+ dprintf("mmu_post_efi_setup...\n");
mmu_post_efi_setup(memory_map_size, memory_map, descriptor_size,
descriptor_version);

-puts("smp_boot_other cpus");
+ dprintf("smp_boot_other_cpus...\n");
smp_boot_other_cpus(final_pml4, (uint32_t)(uint64_t)&gLongGDTR,
gLongKernelEntry);
-puts("efi_enter_kernel");
+
// Enter the kernel!
+ dprintf("efi_enter_kernel...\n");
efi_enter_kernel(final_pml4,
gLongKernelEntry,
gKernelArgs.cpu_kstack[0].start +
gKernelArgs.cpu_kstack[0].size);
@@ -331,7 +332,7 @@ efi_main(EFI_HANDLE image, EFI_SYSTEM_TABLE *systemTable)
serial_enable();
// interrupts_init();
console_init();
- sBootOptions |= BOOT_OPTION_DEBUG_OUTPUT;
+ //sBootOptions |= BOOT_OPTION_DEBUG_OUTPUT;
cpu_init();
// mmu_init();
debug_init_post_mmu();


Other related posts:

  • » [haiku-commits] BRANCH jessicah-github.efi.master [fc29aea9b31c] src/system/boot/platform/efi - jessicah-github . efi . master