Skip to content

Commit

Permalink
Define a struct memory_map with a fixed number of entries, rather than
Browse files Browse the repository at this point in the history
requiring each caller to decide how many entries it wants to permit.
  • Loading branch information
Michael Brown committed May 24, 2006
1 parent edcf89e commit 986f6ff
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
24 changes: 12 additions & 12 deletions src/arch/i386/firmware/pcbios/memmap.c
Expand Up @@ -135,10 +135,9 @@ static unsigned int extmemsize ( void ) {
* Get e820 memory map
*
* @v memmap Memory map to fill in
* @v entries Maximum number of entries in memory map
* @ret rc Return status code
*/
static int meme820 ( struct memory_region *memmap, unsigned int entries ) {
static int meme820 ( struct memory_map *memmap ) {
unsigned int index = 0;
uint32_t next = 0;
uint32_t smap;
Expand Down Expand Up @@ -170,36 +169,37 @@ static int meme820 ( struct memory_region *memmap, unsigned int entries ) {
if ( e820buf.type != E820_TYPE_RAM )
continue;

memmap[index].start = e820buf.start;
memmap[index].end = e820buf.start + e820buf.len;
memmap->regions[index].start = e820buf.start;
memmap->regions[index].end = e820buf.start + e820buf.len;
index++;
} while ( ( index < entries ) && ( next != 0 ) );
} while ( ( next != 0 ) &&
( index < ( sizeof ( memmap->regions ) /
sizeof ( memmap->regions[0] ) ) ) );
return 0;
}

/**
* Get memory map
*
* @v memmap Memory map to fill in
* @v entries Maximum number of entries in memory map (minimum 2)
*/
void get_memmap ( struct memory_region *memmap, unsigned int entries ) {
void get_memmap ( struct memory_map *memmap ) {
unsigned int basemem, extmem;
int rc;

/* Clear memory map */
memset ( memmap, 0, ( entries * sizeof ( *memmap ) ) );
memset ( memmap, 0, sizeof ( *memmap ) );

/* Get base and extended memory sizes */
basemem = basememsize();
extmem = extmemsize();

/* Try INT 15,e820 first */
if ( ( rc = meme820 ( memmap, entries ) ) == 0 )
if ( ( rc = meme820 ( memmap ) ) == 0 )
return;

/* Fall back to constructing a map from basemem and extmem sizes */
memmap[0].end = ( basemem * 1024 );
memmap[1].start = 0x100000;
memmap[1].end = 0x100000 + ( extmem * 1024 );
memmap->regions[0].end = ( basemem * 1024 );
memmap->regions[1].start = 0x100000;
memmap->regions[1].end = 0x100000 + ( extmem * 1024 );
}
10 changes: 9 additions & 1 deletion src/arch/i386/include/memmap.h
Expand Up @@ -18,6 +18,14 @@ struct memory_region {
uint64_t end;
};

extern void get_memmap ( struct memory_region *memmap, unsigned int entries );
/** Maximum number of memory regions we expect to encounter */
#define MAX_MEMORY_REGIONS 8

/** A memory map */
struct memory_map {
struct memory_region regions[MAX_MEMORY_REGIONS];
};

extern void get_memmap ( struct memory_map *memmap );

#endif /* _MEMMAP_H */

0 comments on commit 986f6ff

Please sign in to comment.