mirror of
https://github.com/ipxe/ipxe
synced 2026-02-28 03:11:18 +03:00
[multiboot] Use memmap_describe() to construct Multiboot memory map
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -38,7 +38,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
|||||||
#include <multiboot.h>
|
#include <multiboot.h>
|
||||||
#include <ipxe/image.h>
|
#include <ipxe/image.h>
|
||||||
#include <ipxe/segment.h>
|
#include <ipxe/segment.h>
|
||||||
#include <ipxe/io.h>
|
#include <ipxe/memmap.h>
|
||||||
#include <ipxe/elf.h>
|
#include <ipxe/elf.h>
|
||||||
#include <ipxe/init.h>
|
#include <ipxe/init.h>
|
||||||
#include <ipxe/features.h>
|
#include <ipxe/features.h>
|
||||||
@@ -59,6 +59,9 @@ FEATURE ( FEATURE_IMAGE, "MBOOT", DHCP_EB_FEATURE_MULTIBOOT, 1 );
|
|||||||
*/
|
*/
|
||||||
#define MAX_MODULES 8
|
#define MAX_MODULES 8
|
||||||
|
|
||||||
|
/** Maximum number of memory map entries */
|
||||||
|
#define MAX_MEMMAP 8
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Maximum combined length of command lines
|
* Maximum combined length of command lines
|
||||||
*
|
*
|
||||||
@@ -106,32 +109,43 @@ static void multiboot_build_memmap ( struct image *image,
|
|||||||
struct multiboot_info *mbinfo,
|
struct multiboot_info *mbinfo,
|
||||||
struct multiboot_memory_map *mbmemmap,
|
struct multiboot_memory_map *mbmemmap,
|
||||||
unsigned int limit ) {
|
unsigned int limit ) {
|
||||||
struct memory_map memmap;
|
struct memmap_region region;
|
||||||
unsigned int i;
|
unsigned int remaining;
|
||||||
|
|
||||||
/* Get memory map */
|
|
||||||
get_memmap ( &memmap );
|
|
||||||
|
|
||||||
/* Translate into multiboot format */
|
/* Translate into multiboot format */
|
||||||
memset ( mbmemmap, 0, sizeof ( *mbmemmap ) );
|
memset ( mbmemmap, 0, sizeof ( *mbmemmap ) );
|
||||||
for ( i = 0 ; i < memmap.count ; i++ ) {
|
remaining = limit;
|
||||||
if ( i >= limit ) {
|
for_each_memmap ( ®ion, 0 ) {
|
||||||
|
|
||||||
|
/* Ignore any non-memory regions */
|
||||||
|
if ( ! ( region.flags & MEMMAP_FL_MEMORY ) )
|
||||||
|
continue;
|
||||||
|
memmap_dump ( ®ion );
|
||||||
|
|
||||||
|
/* Check Multiboot memory map limit */
|
||||||
|
if ( ! remaining ) {
|
||||||
DBGC ( image, "MULTIBOOT %s limit of %d memmap "
|
DBGC ( image, "MULTIBOOT %s limit of %d memmap "
|
||||||
"entries reached\n", image->name, limit );
|
"entries reached\n", image->name, limit );
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
mbmemmap[i].size = ( sizeof ( mbmemmap[i] ) -
|
|
||||||
sizeof ( mbmemmap[i].size ) );
|
/* Populate Multiboot memory map entry */
|
||||||
mbmemmap[i].base_addr = memmap.regions[i].start;
|
mbmemmap->size = ( sizeof ( *mbmemmap ) -
|
||||||
mbmemmap[i].length = ( memmap.regions[i].end -
|
sizeof ( mbmemmap->size ) );
|
||||||
memmap.regions[i].start );
|
mbmemmap->base_addr = region.addr;
|
||||||
mbmemmap[i].type = MBMEM_RAM;
|
mbmemmap->length = memmap_size ( ®ion );
|
||||||
mbinfo->mmap_length += sizeof ( mbmemmap[i] );
|
mbmemmap->type = MBMEM_RAM;
|
||||||
if ( memmap.regions[i].start == 0 )
|
|
||||||
mbinfo->mem_lower = ( memmap.regions[i].end / 1024 );
|
/* Update Multiboot information */
|
||||||
if ( memmap.regions[i].start == 0x100000 )
|
mbinfo->mmap_length += sizeof ( *mbmemmap );
|
||||||
mbinfo->mem_upper = ( ( memmap.regions[i].end -
|
if ( mbmemmap->base_addr == 0 )
|
||||||
0x100000 ) / 1024 );
|
mbinfo->mem_lower = ( mbmemmap->length / 1024 );
|
||||||
|
if ( mbmemmap->base_addr == 0x100000 )
|
||||||
|
mbinfo->mem_upper = ( mbmemmap->length / 1024 );
|
||||||
|
|
||||||
|
/* Move to next Multiboot memory map entry */
|
||||||
|
mbmemmap++;
|
||||||
|
remaining--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -247,8 +261,7 @@ static char __bss16_array ( mb_bootloader_name, [32] );
|
|||||||
#define mb_bootloader_name __use_data16 ( mb_bootloader_name )
|
#define mb_bootloader_name __use_data16 ( mb_bootloader_name )
|
||||||
|
|
||||||
/** The multiboot memory map */
|
/** The multiboot memory map */
|
||||||
static struct multiboot_memory_map
|
static struct multiboot_memory_map __bss16_array ( mbmemmap, [MAX_MEMMAP] );
|
||||||
__bss16_array ( mbmemmap, [MAX_MEMORY_REGIONS] );
|
|
||||||
#define mbmemmap __use_data16 ( mbmemmap )
|
#define mbmemmap __use_data16 ( mbmemmap )
|
||||||
|
|
||||||
/** The multiboot module list */
|
/** The multiboot module list */
|
||||||
|
|||||||
Reference in New Issue
Block a user