#include "u.h"
#include "lib.h"
#include "dat.h"
#include "fns.h"
#include "mem.h"
typedef struct {
uvlong base;
uvlong len;
ulong type;
} Emap;
static char *etypes[] =
{
"type=0",
"memory",
"reserved",
"acpi reclaim",
"acpi nvs",
};
static int
emapcmp(const void *va, const void *vb)
{
Emap *a, *b;
a = (Emap*)va;
b = (Emap*)vb;
if(a->base < b->base)
return -1;
if(a->base > b->base)
return 1;
if(a->len < b->len)
return -1;
if(a->len > b->len)
return 1;
return a->type - b->type;
}
#define smap 0x534d4150
#define e820tab (CONFADDR + 0x20)
#define e820sz 20
#define e820end (16*e820sz+e820tab)
void
e820(void)
{
ulong i, nt, quiet;
Emap *e, **p, *tab[16];
MMap *m;
i = *(uchar*)e820end;
print("found %lud e820 entries\n", i);
if(i > 16)
return;
quiet = getconf("*e820print") == 0 && i>1;
e = (Emap*)e820tab;
for(nt = 0; nt < i; nt++){
if(e[nt].type == 0)
break;
for(p = tab+nt; p > tab && emapcmp(p[-1], e+nt) > 0; p--)
*p = p[-1];
*p = e+nt;
}
changeconf("e820", 0, "");
for(p = tab; p < tab+nt; p++){
e = *p;
if(e->type == 1)
changeconf("e820", 1, "%llux %llux ", e->base, e->base+e->len);
if(!quiet){
print("e820: %.8llux %.8llux ", e->base, e->base+e->len);
if(e->type < nelem(etypes))
print("%s\n", etypes[e->type]);
else
print("type=%lud\n", e->type);
}
if(e->type == 0)
break;
m = mmap + nmmap++;
m->size = 20;
m->base[0] = e->base;
m->base[1] = e->base>>32;
m->length[0] = e->len;
m->length[1] = e->len>>32;
m->type = e->type;
}
}
|