예제 #1
0
oskit_error_t init(void)
{
    phys_lmm_init();
    base_multiboot_init_mem();
    return 0;
}
void base_multiboot_init_mem(void)
{
	unsigned int min;
	extern char _start_of_kernel[], end[];

	/* Memory regions to skip.  */
	unsigned int cmdline_start_pa = boot_info.flags & MULTIBOOT_CMDLINE
		? boot_info.cmdline : 0;
	unsigned int cmdline_end_pa = cmdline_start_pa
		? cmdline_start_pa+strlen((char*)phystokv(cmdline_start_pa))+1
		: 0;

	/* Initialize the base memory allocator
	   according to the PC's physical memory regions.  */
	phys_lmm_init();

	/* Add to the free list all the memory the boot loader told us about,
	   carefully avoiding the areas occupied by boot information.
	   as well as our own executable code, data, and bss.
	   Start at the end of the BIOS data area.  */
	min = 0x500;
	do
	{
		unsigned int max = 0xffffffff;

		/* Skip the I/O and ROM area.  */
		skip(boot_info.mem_lower * 1024, 0x100000);

		/* Stop at the end of upper memory.  */
		skip(0x100000 + boot_info.mem_upper * 1024, 0xffffffff);

		/* Skip our own text, data, and bss.  */
		skip(kvtophys(_start_of_kernel), kvtophys(end));

		/* Skip the important stuff the bootloader passed to us.  */
		skip(cmdline_start_pa, cmdline_end_pa);
		if ((boot_info.flags & MULTIBOOT_MODS)
		    && (boot_info.mods_count > 0))
		{
			struct multiboot_module *m = (struct multiboot_module*)
				phystokv(boot_info.mods_addr);
			unsigned i;

			skip(boot_info.mods_addr,
			     boot_info.mods_addr +
			     boot_info.mods_count * sizeof(*m));
			for (i = 0; i < boot_info.mods_count; i++)
			{
				if (m[i].string != 0)
				{
					char *s = (char*)phystokv(m[i].string);
					unsigned len = strlen(s);
					skip(m[i].string, m[i].string+len+1);
				}
				skip(m[i].mod_start, m[i].mod_end);
			}
		}

		/* We actually found a contiguous memory block
		   that doesn't conflict with anything else!  Whew!
		   Add it to the free list.  */
		phys_lmm_add(min, max - min);

		/* Continue searching just past the end of this region.  */
		min = max;

		/* The skip() macro jumps to this label
		   to restart with a different (higher) min address.  */
		retry:
                min = min;
	}
	while (min < 0xffffffff);
}