Beispiel #1
0
static void process_memorymap(struct multiboot *mboot)
{
	addr_t i = mboot->mmap_addr;
	unsigned long num_pages = 0;
	unsigned long unusable = 0;
	uint64_t j = 0;
	uint64_t address;
	uint64_t length;
	uint64_t highest_page = 0;
	uint64_t lowest_page = ~0;
	int found_contiguous = 0;
	pm_location = ((((addr_t)&kernel_end - MEMMAP_KERNEL_START) & ~(PAGE_SIZE - 1)) + PAGE_SIZE + 0x100000);
	while ((pm_location >= initrd_start_page && pm_location <= initrd_end_page))
		pm_location += PAGE_SIZE;

	while (i < (mboot->mmap_addr + mboot->mmap_length)) {
		mmap_entry_t *me = (mmap_entry_t *)(i + MEMMAP_KERNEL_START);
		address = ((uint64_t)me->base_addr_high << 32) | (uint64_t)me->base_addr_low;
		length = (((uint64_t)me->length_high << 32) | me->length_low);
		if (me->type == 1 && length > 0)
		{
			for (j = address; j < (address + length); j += PAGE_SIZE)
			{
				addr_t page;
				// 32 bit can only handle addresses up to 0xFFFFFFFF, above this == ignore.
				page = j;

				if (__is_actually_free(page)) {
					if (lowest_page > page)
						lowest_page = page;
					if (page > highest_page)
						highest_page = page;
					num_pages++;
					mm_physical_deallocate(page);
				}
			}
		}
		i += me->size + sizeof(uint32_t);
	}
	printk(1, "[MM]: Highest page = %x, Lowest page = %x, num_pages = %d\n", highest_page, lowest_page, num_pages);
	if (!j)
		PANIC(PANIC_MEM | PANIC_NOSYNC, "Memory map corrupted!", EFAULT);
	int gbs = 0;
	int mbs = ((num_pages * PAGE_SIZE)/1024)/1024;
	if (mbs < 4) {
		printk(KERN_PANIC, "%d MB, %d pages", mbs, num_pages);
		PANIC(PANIC_MEM | PANIC_NOSYNC, "Not enough memory, system wont work!", ENOMEM);
	}
	gbs = mbs/1024;
	if (gbs > 0)
	{
		printk(KERN_MILE, "%d GB", gbs);
		mbs = mbs % 1024;
	}
	printk(KERN_MILE, "%d MB available memory (page size = %d KB, kmalloc=slab: ok)\n", mbs, PAGE_SIZE/1024);
	printk(KERN_DEBUG, "[MM]: num pages = %d\n", num_pages);
	pm_num_pages = num_pages;
	maximum_page_number = highest_page / PAGE_SIZE;
	set_ksf(KSF_MEMMAPPED);
}
Beispiel #2
0
static void process_memorymap(struct multiboot *mboot)
{
	addr_t i = mboot->mmap_addr;
	unsigned long num_pages=0, unusable=0;
	uint64_t j=0, address, length, highest_page = 0, lowest_page = ~0;
	int found_contiguous=0;
	pm_location = ((((addr_t)&kernel_end - MEMMAP_KERNEL_START) & ~(PAGE_SIZE-1)) + PAGE_SIZE + 0x100000 /* HACK */);
	while((pm_location >= initrd_start_page && pm_location <= initrd_end_page))
		pm_location += PAGE_SIZE;

	while(i < (mboot->mmap_addr + mboot->mmap_length)){
		mmap_entry_t *me = (mmap_entry_t *)(i + MEMMAP_KERNEL_START);
		address = ((uint64_t)me->base_addr_high << 32) | (uint64_t)me->base_addr_low;
		length = (((uint64_t)me->length_high<<32) | me->length_low);
		if(me->type == 1 && length > 0)
		{
			for (j=address; 
				j < (address+length); j += PAGE_SIZE)
			{
				addr_t page;
#if ADDR_BITS == 32
				/* 32-bit can only handle the lower 32 bits of the address. If we're
				 * considering an address above 0xFFFFFFFF, we have to ignore it */
				page = (addr_t)(j & 0xFFFFFFFF);
				if((j >> 32) != 0)
					break;
#else
				page = j;
#endif
				if(__is_actually_free(page)) {
					if(lowest_page > page)
						lowest_page=page;
					if(page > highest_page)
						highest_page=page;
					num_pages++;
					mm_physical_deallocate(page);
				}
			}
		}
		i += me->size + sizeof (uint32_t);
	}
	printk(1, "[mm]: Highest page = %x, Lowest page = %x, num_pages = %d               \n", highest_page, lowest_page, num_pages);
	if(!j)
		panic(PANIC_MEM | PANIC_NOSYNC, "Memory map corrupted");
	int gbs=0;
	int mbs = ((num_pages * PAGE_SIZE)/1024)/1024;
	if(mbs < 4){
		panic(PANIC_MEM | PANIC_NOSYNC, 
				"Not enough memory, system wont work (%d MB, %d pages)", 
				mbs, num_pages);
	}
	gbs = mbs/1024;
	if(gbs > 0)
	{
		printk(KERN_MILE, "%d GB and ", gbs);
		mbs = mbs % 1024;
	}
	printk(KERN_MILE, "%d MB available memory (page size=%d KB, kmalloc=slab: ok)\n"
 			, mbs, PAGE_SIZE/1024);
	printk(1, "[mm]: num pages = %d\n", num_pages);
	pm_num_pages=num_pages;
	maximum_page_number = highest_page / PAGE_SIZE;
	set_ksf(KSF_MEMMAPPED);
}