:: commit 7394f84477874f28bd5759c2b5b2c87d2957ca5f

mintsuki <mintsuki@protonmail.com> — 2021-12-06 01:31

parents: c77d46986f

elf: Print out range addresses on allocation failure

diff --git a/stage23/lib/elf.c b/stage23/lib/elf.c
index 38203594..de76d1e2 100644
--- a/stage23/lib/elf.c
+++ b/stage23/lib/elf.c
@@ -372,7 +372,7 @@ static void elf64_get_ranges(uint8_t *elf, uint64_t slide, bool use_paddr, struc
     }
 
     if (ranges_count == 0) {
-        panic("elf: Attempted to use PMRs but no higher half PHDR exists");
+        panic("elf: Attempted to use PMRs but no higher half PHDRs exist");
     }
 
     struct elf_range *ranges = ext_mem_alloc(ranges_count * sizeof(struct elf_range));
@@ -471,7 +471,7 @@ int elf64_load(uint8_t *elf, uint64_t *entry_point, uint64_t *top, uint64_t *_sl
         }
 
         if (max_vaddr == 0 || min_vaddr == (uint64_t)-1) {
-            panic("elf: Attempted to use fully virtual mappings but no higher half PHDR exists");
+            panic("elf: Attempted to use fully virtual mappings but no higher half PHDRs exist");
         }
 
         image_size = max_vaddr - min_vaddr;
@@ -560,7 +560,7 @@ final:
             ((higher_half == true && this_top > 0x80000000)
           || !memmap_alloc_range((size_t)mem_base, (size_t)mem_size, alloc_type, true, false, simulation, false))) {
             if (++try_count == max_simulated_tries || simulation == false) {
-                panic("elf: Failed to allocate necessary memory ranges");
+                panic("elf: Failed to allocate necessary memory range (%p-%p)", mem_base, mem_base + mem_size);
             }
             if (!kaslr) {
                 slide += max_align;
diff --git a/stage23/lib/print.s2.c b/stage23/lib/print.s2.c
index 52bde60d..ca314e4a 100644
--- a/stage23/lib/print.s2.c
+++ b/stage23/lib/print.s2.c
@@ -173,6 +173,9 @@ void vprint(const char *fmt, va_list args) {
             case 'X':
                 prn_x(print_buf, &print_buf_i, va_arg(args, uint64_t));
                 break;
+            case 'p':
+                prn_x(print_buf, &print_buf_i, va_arg(args, uintptr_t));
+                break;
             case 'c': {
                 char c = (char)va_arg(args, int);
                 prn_char(print_buf, &print_buf_i, c); }
tab: 248 wrap: offon