]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[bios] Describe umalloc() heap as an in-use memory area
authorMichael Brown <mcb30@ipxe.org>
Thu, 15 May 2025 14:35:27 +0000 (15:35 +0100)
committerMichael Brown <mcb30@ipxe.org>
Fri, 16 May 2025 15:18:36 +0000 (16:18 +0100)
Use the concept of an in-use memory region defined as part of the
system memory map API to describe the umalloc() heap.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/arch/x86/include/basemem.h
src/arch/x86/include/ipxe/int15.h
src/arch/x86/interface/pcbios/basemem.c
src/arch/x86/interface/pcbios/hidemem.c
src/arch/x86/interface/pcbios/memtop_umalloc.c
src/include/ipxe/hidemem.h [deleted file]
src/include/ipxe/memmap.h

index 01c2ea917d0e8d2dffc1961f27045075172f3062..9ac918ac0e236751543832be106f007aff562ee0 100644 (file)
@@ -27,9 +27,4 @@ static inline unsigned int get_fbms ( void ) {
 
 extern void set_fbms ( unsigned int new_fbms );
 
-/* Actually in hidemem.c, but putting it here avoids polluting the
- * architecture-independent include/hidemem.h.
- */
-extern void hide_basemem ( void );
-
 #endif /* _BASEMEM_H */
index fbd70f8d652d8e35a13eb0480298ef03d7c36834..e8aa9e2f58cc0965ce390c182c6b248bb6579af6 100644 (file)
@@ -16,5 +16,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 #endif
 
 extern void int15_intercept ( int intercept );
+extern void hide_basemem ( void );
 
 #endif /* _IPXE_INT15_H */
index 6a46081aa64d47816e4f20f1cd156cf26100164f..8f3a30e9202f561825eb68e84351ef900563491f 100644 (file)
@@ -27,7 +27,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 #include <realmode.h>
 #include <bios.h>
 #include <basemem.h>
-#include <ipxe/hidemem.h>
+#include <ipxe/memmap.h>
 
 /** @file
  *
index f201742cf6921f0951d17512489854e5d432481e..d00c02fb67ca24c30c538abca63270532a5cf2a6 100644 (file)
@@ -31,7 +31,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 #include <ipxe/init.h>
 #include <ipxe/io.h>
 #include <ipxe/memmap.h>
-#include <ipxe/hidemem.h>
 
 /** Set to true if you want to test a fake E820 map */
 #define FAKE_E820 0
@@ -119,21 +118,32 @@ void hide_basemem ( void ) {
 }
 
 /**
- * Hide umalloc() region
+ * Hide .text and .data
  *
  */
-void hide_umalloc ( physaddr_t start, physaddr_t end ) {
-       assert ( end <= virt_to_phys ( _textdata ) );
-       hide_region ( &hidemem_umalloc, start, end );
+void hide_textdata ( void ) {
+       hide_region ( &hidemem_textdata, virt_to_phys ( _textdata ),
+                     virt_to_phys ( _etextdata ) );
 }
 
 /**
- * Hide .text and .data
+ * Synchronise in-use regions with the externally visible system memory map
  *
  */
-void hide_textdata ( void ) {
-       hide_region ( &hidemem_textdata, virt_to_phys ( _textdata ),
-                     virt_to_phys ( _etextdata ) );
+static void int15_sync ( void ) {
+       physaddr_t start;
+       size_t size;
+
+       /* Besides our fixed base memory and textdata regions, we
+        * support hiding only a single in-use memory region (the
+        * umalloc region), which must be placed before the hidden
+        * textdata region (even if zero-length).
+        */
+       start = umalloc_used.start;
+       size = umalloc_used.size;
+       if ( ! size )
+               start = virt_to_phys ( _textdata );
+       hide_region ( &hidemem_umalloc, start, ( start + size ) );
 }
 
 /**
@@ -172,8 +182,8 @@ static void hide_etherboot ( void ) {
 
        /* Initialise the hidden regions */
        hide_basemem();
-       hide_umalloc ( virt_to_phys ( _textdata ), virt_to_phys ( _textdata ) );
        hide_textdata();
+       int15_sync();
 
        /* Some really moronic BIOSes bring up the PXE stack via the
         * UNDI loader entry point and then don't bother to unload it
@@ -250,3 +260,5 @@ struct startup_fn hide_etherboot_startup_fn __startup_fn ( STARTUP_EARLY ) = {
        .startup = hide_etherboot,
        .shutdown = unhide_etherboot,
 };
+
+PROVIDE_MEMMAP ( int15, memmap_sync, int15_sync );
index bfaffc4bb7c5ae110c8a463556b39bc1a0588c18..99d8f146078b4f0484691a6dc07264db4ad0bd90 100644 (file)
@@ -34,9 +34,9 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
 #include <string.h>
 #include <errno.h>
 #include <ipxe/uaccess.h>
-#include <ipxe/hidemem.h>
 #include <ipxe/io.h>
 #include <ipxe/memblock.h>
+#include <ipxe/memmap.h>
 #include <ipxe/umalloc.h>
 
 /** Maximum usable address for external allocated memory */
@@ -62,6 +62,22 @@ static void *bottom = NULL;
 /** Remaining space on heap */
 static size_t heap_size;
 
+/** In-use memory region */
+struct used_region umalloc_used __used_region = {
+       .name = "umalloc",
+};
+
+/**
+ * Hide umalloc() region
+ *
+ * @v start            Start of region
+ * @v end              End of region
+ */
+static void hide_umalloc ( physaddr_t start, physaddr_t end ) {
+
+       memmap_use ( &umalloc_used, start, ( end - start ) );
+}
+
 /**
  * Find largest usable memory region
  *
diff --git a/src/include/ipxe/hidemem.h b/src/include/ipxe/hidemem.h
deleted file mode 100644 (file)
index cc8d5ee..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-#ifndef _IPXE_HIDEMEM_H
-#define _IPXE_HIDEMEM_H
-
-/**
- * @file
- *
- * Hidden memory regions
- *
- */
-
-FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
-
-#include <stdint.h>
-
-extern void hide_umalloc ( physaddr_t start, physaddr_t end );
-
-#endif /* _IPXE_HIDEMEM_H */
index 0262c68da2f9d329742998895a2a507ac7467e5d..cfb9ac934d80ab39ef9a4eb592740a96aa17e528 100644 (file)
@@ -228,6 +228,8 @@ static inline void memmap_dump_all ( int hide ) {
                memmap_dump ( &region );
 }
 
+extern struct used_region umalloc_used __used_region;
+
 extern void memmap_update ( struct memmap_region *region, uint64_t start,
                            uint64_t size, unsigned int flags,
                            const char *name );