grub学习(4) 启动linux内核

 

grub_err_t
grub_linux_boot (void)
{
	struct linux_kernel_params *params;
	int e820_num;
	
	params = real_mode_mem;
	
	/* 获取内存分布 */
	int NESTED_FUNC_ATTR hook (grub_uint64_t addr, grub_uint64_t size, 
			     grub_memory_type_t type)
    {
      switch (type)
        {
        case GRUB_MEMORY_AVAILABLE:
	  grub_e820_add_region (params->e820_map, &e820_num,
				addr, size, GRUB_E820_RAM);
	  break;

        case GRUB_MEMORY_ACPI:
	  grub_e820_add_region (params->e820_map, &e820_num,
				addr, size, GRUB_E820_ACPI);
	  break;

        case GRUB_MEMORY_NVS:
	  grub_e820_add_region (params->e820_map, &e820_num,
				addr, size, GRUB_E820_NVS);
	  break;

        case GRUB_MEMORY_BADRAM:
	  grub_e820_add_region (params->e820_map, &e820_num,
				addr, size, GRUB_E820_BADRAM);
	  break;

        default:
          grub_e820_add_region (params->e820_map, &e820_num,
                                addr, size, GRUB_E820_RESERVED);
        }
      return 0;
    }

	e820_num = 0;
	grub_mmap_iterate (hook);
	params->mmap_size = e820_num;
	
	/* 跳转 */
	state.ebp = state.edi = state.ebx = 0;
	state.esi = real_mode_target;
	state.esp = real_mode_target;
	state.eip = params->code32_start;
	return grub_relocator32_boot (relocator, state);
}

 

你可能感兴趣的:(grub,bootloader)