From: Michael Brown Date: Sun, 25 May 2025 11:06:53 +0000 (+0100) Subject: [memmap] Allow explicit colour selection for memory map debug messages X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=09140ab2c1a14b77d1e8beb407e500cb4deeb0ae;p=thirdparty%2Fipxe.git [memmap] Allow explicit colour selection for memory map debug messages Provide DBGC_MEMMAP() as a replacement for memmap_dump(), allowing the colour used to match other messages within the same message group. Retain a dedicated colour for output from memmap_dump_all(), on the basis that it is generally most useful to visually compare full memory dumps against previous full memory dumps. Signed-off-by: Michael Brown --- diff --git a/src/arch/x86/core/relocate.c b/src/arch/x86/core/relocate.c index 0a8f0b8dc..3cdc53c2e 100644 --- a/src/arch/x86/core/relocate.c +++ b/src/arch/x86/core/relocate.c @@ -80,7 +80,7 @@ __asmcall void relocate ( struct i386_all_regs *ix86 ) { * away with using just 32-bit arithmetic after this * stage. */ - memmap_dump ( ®ion ); + DBGC_MEMMAP ( ®ion, ®ion ); if ( region.min > max ) { DBGC ( ®ion, "...starts after max=%#08lx\n", max ); break; diff --git a/src/arch/x86/image/multiboot.c b/src/arch/x86/image/multiboot.c index c6bc01d4c..40d6941da 100644 --- a/src/arch/x86/image/multiboot.c +++ b/src/arch/x86/image/multiboot.c @@ -120,7 +120,7 @@ static void multiboot_build_memmap ( struct image *image, /* Ignore any non-memory regions */ if ( ! ( region.flags & MEMMAP_FL_MEMORY ) ) continue; - memmap_dump ( ®ion ); + DBGC_MEMMAP ( image, ®ion ); /* Check Multiboot memory map limit */ if ( ! remaining ) { diff --git a/src/core/fdtmem.c b/src/core/fdtmem.c index bb8786d3c..fb44397af 100644 --- a/src/core/fdtmem.c +++ b/src/core/fdtmem.c @@ -273,7 +273,7 @@ physaddr_t fdtmem_relocate ( struct fdt_header *hdr, physaddr_t max ) { /* Parse FDT */ if ( ( rc = fdt_parse ( &fdt, hdr, -1UL ) ) != 0 ) { - DBGC ( ®ion, "FDTMEM could not parse FDT: %s\n", + DBGC ( hdr, "FDTMEM could not parse FDT: %s\n", strerror ( rc ) ); /* Refuse relocation if we have no FDT */ return old; @@ -282,7 +282,7 @@ physaddr_t fdtmem_relocate ( struct fdt_header *hdr, physaddr_t max ) { /* Determine required length */ len = fdtmem_len ( &fdt ); assert ( len > 0 ); - DBGC ( ®ion, "FDTMEM requires %#zx + %#zx => %#zx bytes for " + DBGC ( hdr, "FDTMEM requires %#zx + %#zx => %#zx bytes for " "relocation\n", memsz, fdt.len, len ); /* Construct memory map and choose a relocation address */ @@ -297,7 +297,7 @@ physaddr_t fdtmem_relocate ( struct fdt_header *hdr, physaddr_t max ) { next = ( region.max + 1 ); /* Dump region descriptor (for debugging) */ - memmap_dump ( ®ion ); + DBGC_MEMMAP ( hdr, ®ion ); assert ( region.max >= region.min ); /* Use highest possible region */ @@ -313,7 +313,7 @@ physaddr_t fdtmem_relocate ( struct fdt_header *hdr, physaddr_t max ) { } } - DBGC ( ®ion, "FDTMEM relocating %#08lx => [%#08lx,%#08lx]\n", + DBGC ( hdr, "FDTMEM relocating %#08lx => [%#08lx,%#08lx]\n", old, new, ( ( physaddr_t ) ( new + len - 1 ) ) ); return new; } diff --git a/src/core/memmap.c b/src/core/memmap.c index 2939e855b..4a96055e6 100644 --- a/src/core/memmap.c +++ b/src/core/memmap.c @@ -127,7 +127,7 @@ size_t memmap_largest ( physaddr_t *start ) { *start = 0; largest = 0; for_each_memmap ( ®ion, 1 ) { - memmap_dump ( ®ion ); + DBGC_MEMMAP ( ®ion, ®ion ); if ( ! memmap_is_usable ( ®ion ) ) continue; size = memmap_size ( ®ion ); diff --git a/src/image/lkrn.c b/src/image/lkrn.c index 8a7c577cd..a2044cb82 100644 --- a/src/image/lkrn.c +++ b/src/image/lkrn.c @@ -102,7 +102,7 @@ static int lkrn_ram ( struct image *image, struct lkrn_context *ctx ) { /* Locate start of RAM */ for_each_memmap ( ®ion, 0 ) { - memmap_dump ( ®ion ); + DBGC_MEMMAP ( image, ®ion ); if ( ! ( region.flags & MEMMAP_FL_MEMORY ) ) continue; ctx->ram = region.min; diff --git a/src/image/segment.c b/src/image/segment.c index 469a66321..d90da709c 100644 --- a/src/image/segment.c +++ b/src/image/segment.c @@ -65,11 +65,11 @@ int prep_segment ( void *segment, size_t filesz, size_t memsz ) { physaddr_t end = ( start + memsz ); physaddr_t max; - DBGC ( ®ion, "SEGMENT [%#08lx,%#08lx,%#08lx)\n", start, mid, end ); + DBGC ( segment, "SEGMENT [%#08lx,%#08lx,%#08lx)\n", start, mid, end ); /* Check for malformed lengths */ if ( filesz > memsz ) { - DBGC ( ®ion, "SEGMENT [%#08lx,%#08lx,%#08lx) is " + DBGC ( segment, "SEGMENT [%#08lx,%#08lx,%#08lx) is " "malformed\n", start, mid, end ); return -EINVAL; } @@ -81,18 +81,18 @@ int prep_segment ( void *segment, size_t filesz, size_t memsz ) { /* Check for address space overflow */ if ( max < start ) { - DBGC ( ®ion, "SEGMENT [%#08lx,%#08lx,%#08lx) wraps " + DBGC ( segment, "SEGMENT [%#08lx,%#08lx,%#08lx) wraps " "around\n", start, mid, end ); return -EINVAL; } /* Describe region containing this segment */ memmap_describe ( start, 1, ®ion ); - memmap_dump ( ®ion ); + DBGC_MEMMAP ( segment, ®ion ); /* Fail unless region is usable and sufficiently large */ if ( ( ! memmap_is_usable ( ®ion ) ) || ( region.max < max ) ) { - DBGC ( ®ion, "SEGMENT [%#08lx,%#08lx,%#08lx) does not fit " + DBGC ( segment, "SEGMENT [%#08lx,%#08lx,%#08lx) does not fit " "into available memory\n", start, mid, end ); return -ERANGE_SEGMENT; } diff --git a/src/include/ipxe/memmap.h b/src/include/ipxe/memmap.h index 405a74baf..c16e25daa 100644 --- a/src/include/ipxe/memmap.h +++ b/src/include/ipxe/memmap.h @@ -183,26 +183,29 @@ memmap_use ( struct used_region *used, physaddr_t start, size_t size ) { #define for_each_memmap( region, hide ) \ for_each_memmap_from ( (region), 0, (hide) ) - -/** - * Dump memory region descriptor (for debugging) - * - * @v region Region descriptor - */ -static inline void memmap_dump ( const struct memmap_region *region ) { - const char *name = region->name; - unsigned int flags = region->flags; - - /* Dump region information */ - DBGC ( region, "MEMMAP (%s%s%s%s) [%#08llx,%#08llx]%s%s\n", - ( ( flags & MEMMAP_FL_MEMORY ) ? "M" : "-" ), - ( ( flags & MEMMAP_FL_RESERVED ) ? "R" : "-" ), - ( ( flags & MEMMAP_FL_USED ) ? "U" : "-" ), - ( ( flags & MEMMAP_FL_INACCESSIBLE ) ? "X" : "-" ), - ( ( unsigned long long ) region->min ), - ( ( unsigned long long ) region->max ), - ( name ? " " : "" ), ( name ? name : "" ) ); -} +#define DBG_MEMMAP_IF( level, region ) do { \ + const char *name = (region)->name; \ + unsigned int flags = (region)->flags; \ + \ + DBG_IF ( level, "MEMMAP (%s%s%s%s) [%#08llx,%#08llx]%s%s\n", \ + ( ( flags & MEMMAP_FL_MEMORY ) ? "M" : "-" ), \ + ( ( flags & MEMMAP_FL_RESERVED ) ? "R" : "-" ), \ + ( ( flags & MEMMAP_FL_USED ) ? "U" : "-" ), \ + ( ( flags & MEMMAP_FL_INACCESSIBLE ) ? "X" : "-" ), \ + ( ( unsigned long long ) (region)->min ), \ + ( ( unsigned long long ) (region)->max ), \ + ( name ? " " : "" ), ( name ? name : "" ) ); \ + } while ( 0 ) + +#define DBGC_MEMMAP_IF( level, id, ... ) do { \ + DBG_AC_IF ( level, id ); \ + DBG_MEMMAP_IF ( level, __VA_ARGS__ ); \ + DBG_DC_IF ( level ); \ + } while ( 0 ) + +#define DBGC_MEMMAP( ... ) DBGC_MEMMAP_IF ( LOG, ##__VA_ARGS__ ) +#define DBGC2_MEMMAP( ... ) DBGC_MEMMAP_IF ( EXTRA, ##__VA_ARGS__ ) +#define DBGCP_MEMMAP( ... ) DBGC_MEMMAP_IF ( PROFILE, ##__VA_ARGS__ ) /** * Dump system memory map (for debugging) @@ -217,10 +220,10 @@ static inline void memmap_dump_all ( int hide ) { return; /* Describe all memory regions */ - DBGC ( ®ion, "MEMMAP with in-use regions %s:\n", + DBGC ( &memmap_describe, "MEMMAP with in-use regions %s:\n", ( hide ? "hidden" : "ignored" ) ); for_each_memmap ( ®ion, hide ) - memmap_dump ( ®ion ); + DBGC_MEMMAP ( &memmap_describe, ®ion ); } extern void memmap_update ( struct memmap_region *region, uint64_t start,