/* e820_map.c
*I don't mean to write the whole OS kernel.I just want to put what I have
*already learned into practice.But what will it be end up looking like.
*I don't know.ALA I have some free time,I will write something.Just like
*linus once said,"Just for fun".I don't care what this small ugly codes
*will be capable of,or does it worth something.I just write it for fun,
*and for practice.
* 10 / 12 / 2010 liangtao
* E-mail:liangtao90s@gmail.com
*/
/* used only for test currently */
#include
#include
#include
struct e820_map e820_map_table[E820_MAP_NR_MAX];
unsigned short e820_map_nr;
void setup_e820_map(void)
{
int i = 0;
e820_map_nr = *(unsigned short *)((E820_MAP_SEG << 4) + E820_MAP_NR);
struct e820_map *base = (struct e820_map *)E820_MAP_BASE;
if(e820_map_nr > E820_MAP_NR_MAX) {
printf("!!!!!!BUG!!!!!!got %hd e820 map!!!!!!!!\n", e820_map_nr);
while(1);
}
while(i < e820_map_nr ) {
memncpy((void *)(e820_map_table + i),(base + i), 20);
i++;
}
}
static void end(void)
{
int i = 1;
while(i--);
}
void show_mem_info(void)
{
int i;
unsigned char e801_flag = *(unsigned char *)((E820_MAP_SEG << 4) + E801_FLAG);
unsigned char mem88_flag = *(unsigned char *)((E820_MAP_SEG << 4) + MEM88_FLAG);
struct e820_map *map_base = e820_map_table + 0;
putstr("!!!!memory map info got from e820 bios call:\n");
for(i = 0; i < e820_map_nr; i++) {
printf("map %dth:\t\n", i);
printf("\tbase addr low32 :\t %#x\n", map_base->base_addr_low32);
printf("\tbase addr high32 :\t %#x\n", map_base->base_addr_high32);
printf("\tlength low32 :\t %#x\n", map_base->len_low32);
printf("\tlength high32 :\t %#x\n", map_base->len_high32);
if(map_base->type == E820_TYPE_AVAIL)
putstr("\tthis memory region is available and can be used by the OS!\n");
else if(map_base->type == E820_TYPE_RESERVED)
putstr("\tthis memory region is reserved and cannot be used by the OS!\n");
else if(map_base->type == E820_TYPE_UNDEF)
putstr("\tthis memory region is undefined and cannot be used by the OS!\n");
else
putstr("!!!!!!!!!!!UNKNOW MEMORY REGION TYPE!!!!!!!!!!!!!!\n");
map_base++;
end();
}
if(e801_flag == 1) {
unsigned long e801_part1 = *(unsigned long *)((E820_MAP_SEG << 4) + E801_PART1);
unsigned long e801_part2 = *(unsigned long *)((E820_MAP_SEG << 4) + E801_PART2);
e801_part2 <<= 6;
printf("E801 way. EXT 1 is:\t %ld KB\n", e801_part1);
printf("E801 way. EXT 2 is:\t %ld KB\n", e801_part2);
}
else
putstr("!!!!!!!e801 way failed!\n");
if(mem88_flag != 0) {
unsigned short mem_88 = *(unsigned long *)((E820_MAP_SEG << 4) + MEM88_EXT);
printf("88 way. EXT is:\t %hd KB\n", mem_88);
}
}
阅读(3024) | 评论(0) | 转发(0) |