mem_init的代码很少,是纯c的。也比较容易理解,是内存初始化函数。
代码:
void mem_init(long start_mem, long end_mem)
{
int i;
HIGH_MEMORY = end_mem;
for (i=0 ; i
mem_map[i] = USED;
i = MAP_NR(start_mem);
end_mem -= start_mem;
end_mem >>= 12;
while (end_mem-->0)
mem_map[i++]=0;
}
end_mem和start_mem分别在主函数里设置了代码
memory_end = (1<<20) + (EXT_MEM_K<<10);
memory_end &= 0xfffff000;
if (memory_end > 16*1024*1024)
memory_end = 16*1024*1024;
if (memory_end > 12*1024*1024)
buffer_memory_end = 4*1024*1024;
else if (memory_end > 6*1024*1024)
buffer_memory_end = 2*1024*1024;
else
buffer_memory_end = 1*1024*1024;
根据内存具体大小设置设置。
其中MAP_NR(start_mem)调用宏#define MAP_NR(addr) (((addr)-LOW_MEM)>>12)获取第一页地址(按页计算)
接着 end_mem -= start_mem;
end_mem >>= 12;
计算页数
最后标记所有也空闲
while (end_mem-->0)
mem_map[i++]=0;
完毕
阅读(2718) | 评论(0) | 转发(0) |