Example #1
0
void kmalloc_late_init(void)
{
	char *start;
	size_t size;

	TRACE();

	/*
	 * We want to grow the kernel heap to kheap_end. Thus we add a
	 * new lmm_region that starts at the end of the early heap, and
	 * extends to kheap_end.
	 */
	start = kheap_early_start + kheap_early_size;
	size = (size_t) kheap_end - (size_t) start;

	lmm_add_free(&kheap_lmm, start, size);
	ASSERT_LESSEQ(kmalloc_bytes_free(),
		      (size_t) kheap_end - (size_t) kheap_start);
}
Example #2
0
void kmalloc_early_init(void)
{
	TRACE();

	lmm_init(&kheap_lmm);
	lmm_add_region(&kheap_lmm, &global_region, (size_t) 0, (size_t) -1,
		       0, 0);

	/*
	 * Set up an initial heap starting at kheap_start.
	 */
	kheap_early_start = kheap_start;

	/*
	 * The early heap size is limited by the amount of memory statically
	 * mapped during boot.
	 */
	kheap_early_size = BOOT_PAGING_SIZE - (size_t) kheap_early_start;

	lmm_add_free(&kheap_lmm, kheap_early_start, kheap_early_size);
	ASSERT_LESSEQ(kmalloc_bytes_free(), kheap_early_size);

	kheap_used = 0;
}
Example #3
0
void mb_util_lmm (mbinfo_t *mbi, lmm_t *lmm)
{
	vm_offset_t min;
	extern char _start[], end[];

	/* Memory regions to skip.  */
	vm_offset_t cmdline_start_pa = mbi->flags & MULTIBOOT_CMDLINE
		? mbi->cmdline : 0;
	vm_offset_t 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.  */
	lmm_init(lmm);

    /* Do the x86 init dance to build our initial regions */
    lmm_add_region(&malloc_lmm, &reg1mb,
            (void*)phystokv(0x00000000), 0x00100000,
            LMMF_1MB | LMMF_16MB, LMM_PRI_1MB);
    lmm_add_region(&malloc_lmm, &reg16mb,
            (void*)phystokv(0x00100000), 0x00f00000,
            LMMF_16MB, LMM_PRI_16MB);
    lmm_add_region(&malloc_lmm, &reghigh,
            (void*)phystokv(0x01000000), 0xfeffffff,
            0, LMM_PRI_HIGH);

	/* 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
	{
		vm_offset_t max = 0xffffffff;

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

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

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

		/* FIXME: temporary state of affairs */
		extern char __kimg_start[];
		skip(kvtophys(__kimg_start), kvtophys(end));

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

			skip(mbi->mods_addr,
			     mbi->mods_addr +
			     mbi->mods_count * sizeof(*m));
			for (i = 0; i < mbi->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.  */
		lmm_add_free(&malloc_lmm, (void *) 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:;
	}
	while (min < 0xffffffff);
}