. made memory parsing function into a library call

(moved 'struct memory' to <minix/type.h> for this library call)
 . removed some debugging messages from pci library
This commit is contained in:
Ben Gras
2007-02-16 15:54:28 +00:00
parent a47531cc97
commit 3275602598
5 changed files with 58 additions and 10 deletions

View File

@@ -1,5 +1,6 @@
#include "sysutil.h"
#include <stdlib.h>
#include <env.h>
#include <string.h>
@@ -88,4 +89,53 @@ badenv:
return -1;
}
/*=========================================================================*
* env_memory_parse *
*=========================================================================*/
PUBLIC int env_memory_parse(mem_chunks, maxchunks)
struct memory *mem_chunks; /* where to store the memory bits */
int maxchunks; /* how many were found */
{
int i, done = 0;
char *s;
struct memory *memp;
char memstr[100], *end;
/* Initialize everything to zero. */
for (i = 0; i < maxchunks; i++) {
memp = &mem_chunks[i]; /* next mem chunk is stored here */
memp->base = memp->size = 0;
}
/* The available memory is determined by MINIX' boot loader as a list of
* (base:size)-pairs in boothead.s. The 'memory' boot variable is set in
* in boot.s. The format is "b0:s0,b1:s1,b2:s2", where b0:s0 is low mem,
* b1:s1 is mem between 1M and 16M, b2:s2 is mem above 16M. Pairs b1:s1
* and b2:s2 are combined if the memory is adjacent.
*/
if(env_get_param("memory", memstr, sizeof(memstr)-1) != OK)
return -1;
s = memstr;
for (i = 0; i < maxchunks && !done; i++) {
phys_bytes base = 0, size = 0, limit;
memp = &mem_chunks[i]; /* next mem chunk is stored here */
if (*s != 0) { /* get fresh data, unless at end */
/* Read fresh base and expect colon as next char. */
base = strtoul(s, &end, 0x10); /* get number */
if (end != s && *end == ':') s = ++end; /* skip ':' */
else *s=0; /* terminate, should not happen */
/* Read fresh size and expect comma or assume end. */
size = strtoul(s, &end, 0x10); /* get number */
if (end != s && *end == ',') s = ++end; /* skip ',' */
else done = 1;
}
if (base + size <= base) continue;
memp->base = base;
memp->size = size;
}
return OK;
}