add memprobe
NOTE: print "%llx" "%lld" not working now
This commit is contained in:
parent
8336f11b2a
commit
c9c820840f
@ -5,7 +5,7 @@ PROG = boot
|
||||
SRCS = srt0.S gdt.S boot.c
|
||||
OBJS = srt0.o gdt.o boot.o
|
||||
|
||||
ESRCS = pccon.c sricon.c print.c a20.c time.c
|
||||
ESRCS = pccon.c sricon.c print.c a20.c time.c mem.c
|
||||
OBJS += $(ESRCS:.c=.o)
|
||||
|
||||
include $(SDIR)/Makefile.inc
|
||||
|
||||
@ -6,7 +6,7 @@ static void coninit(void);
|
||||
static void machdep(void);
|
||||
|
||||
void (*probe1[])(void) = {
|
||||
a20up, coninit,
|
||||
a20up, coninit, memprobe,
|
||||
};
|
||||
void (*probe2[])(void) = {
|
||||
};
|
||||
@ -31,7 +31,10 @@ ConDev contab[CON_END] = {
|
||||
.init = cominit,
|
||||
},
|
||||
};
|
||||
|
||||
ConDev *con = &contab[0];
|
||||
BIOSmmap biosmmap[64];
|
||||
uint cnvmem, extmem;
|
||||
|
||||
static void
|
||||
coninit(void)
|
||||
|
||||
@ -36,6 +36,11 @@ struct ConDev{
|
||||
uint dev;
|
||||
uchar pri; // the higher the better
|
||||
};
|
||||
typedef struct{
|
||||
u64 addr; /* Beginning of block */
|
||||
u64 size; /* Size of block */
|
||||
u32 type; /* Type of block */
|
||||
} __attribute__((packed)) BIOSmmap;
|
||||
|
||||
// gdt.S
|
||||
extern volatile struct BIOSreg BIOSreg;
|
||||
@ -44,5 +49,7 @@ extern volatile struct BIOSreg BIOSreg;
|
||||
extern void (*probe1[])(void);
|
||||
extern void (*probe2[])(void);
|
||||
extern BootProbe probes[];
|
||||
extern BIOSmmap biosmmap[64];
|
||||
extern ConDev contab[CON_END];
|
||||
extern ConDev *con;
|
||||
extern uint cnvmem, extmem;
|
||||
|
||||
@ -1,3 +1,6 @@
|
||||
#define MAX(x, y) ((x)>(y)?(x):(y))
|
||||
#define MIN(x, y) ((x)<(y)?(x):(y))
|
||||
|
||||
// console.c
|
||||
void cominit(ConDev *d);
|
||||
void pcinit(ConDev *d);
|
||||
@ -16,7 +19,10 @@ void print(const char *fmt, ...);
|
||||
// a20.c
|
||||
void a20up(void);
|
||||
|
||||
// long.c
|
||||
// mem.c
|
||||
void memprobe(void);
|
||||
|
||||
// time.c
|
||||
long getsecs(void);
|
||||
|
||||
static __inline int
|
||||
|
||||
@ -78,7 +78,7 @@
|
||||
.globl pmode_init
|
||||
.globl BIOSreg
|
||||
BIOSreg:
|
||||
.space 64
|
||||
.space 36, 0
|
||||
|
||||
// Table
|
||||
// IDTR offset + 0 : entry 0
|
||||
|
||||
82
boot/mem.c
Normal file
82
boot/mem.c
Normal file
@ -0,0 +1,82 @@
|
||||
#include <u.h>
|
||||
#include "dat.h"
|
||||
#include "fn.h"
|
||||
|
||||
#define IOMEM_BEGIN 0x0A0000
|
||||
#define IOMEM_END 0x100000
|
||||
|
||||
enum{
|
||||
MAP_END = 0x00,
|
||||
MAP_FREE = 0x01,
|
||||
MAP_RES = 0x02,
|
||||
MAP_ACPI_RECLAM = 0x03,
|
||||
MAP_ACPI_NVS = 0x04,
|
||||
};
|
||||
|
||||
static BIOSmmap*
|
||||
int15_E820(BIOSmmap *m)
|
||||
{
|
||||
int rc, sig, off = 0;
|
||||
do{
|
||||
BIOSreg.es = ((uint)(m) >> 4);
|
||||
__asm volatile("int $0x35; setc %b1"
|
||||
: "=a" (sig), "=d" (rc), "=b" (off)
|
||||
: "0" (0xE820), "1" (0x534d4150), "b" (off),
|
||||
"c" (sizeof(*m)), "D" (((uint)m) & 0xf)
|
||||
: "cc", "memory");
|
||||
|
||||
off = BIOSreg.bx;
|
||||
if(rc &0xff || sig !=0x534d4150){
|
||||
break;
|
||||
if(m->type == 0)
|
||||
m->type = MAP_RES;
|
||||
}
|
||||
m++;
|
||||
}while(off);
|
||||
return m;
|
||||
}
|
||||
|
||||
static void
|
||||
dumpmem(BIOSmmap *m)
|
||||
{
|
||||
ulong tot = 0;
|
||||
|
||||
for(BIOSmmap *p=m; p->type != MAP_END; ++p){
|
||||
print("MEM %u type %u size %lldKB at 0x%llx\n",
|
||||
p-m, p->type, p->size/1024, p->addr);
|
||||
if(p->type == MAP_FREE)
|
||||
tot += p->size/1024;
|
||||
}
|
||||
print("RAM low:%dKB high:%dKB\n", cnvmem, extmem);
|
||||
print("Total free memory: %dKB\n", tot);
|
||||
}
|
||||
|
||||
static int
|
||||
isa20done(void)
|
||||
{
|
||||
register char *a = (char *)0x100000;
|
||||
register char *b = (char *)0x000000;
|
||||
|
||||
return *a != *b;
|
||||
}
|
||||
|
||||
void
|
||||
memprobe(void)
|
||||
{
|
||||
BIOSmmap *m;
|
||||
|
||||
cnvmem = extmem = 0;
|
||||
m = int15_E820(biosmmap);
|
||||
m->type = MAP_END;
|
||||
for(m = biosmmap; m->type != MAP_END; ++m){
|
||||
if(m->type != MAP_FREE || m->size <= 0)
|
||||
continue;
|
||||
if(m->addr < IOMEM_BEGIN)
|
||||
cnvmem = MAX(cnvmem, m->addr + m->size)/1024;
|
||||
if(m->addr >= IOMEM_END)
|
||||
extmem += m->size/1024;
|
||||
}
|
||||
dumpmem(biosmmap);
|
||||
print("A20:%d", isa20done());
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user