davidv1992 wrote:The memory map you listed looks reasonable for a modern computer. As grub module loading is highly unlikely to have bugs that would cause it to load over reserved memory regions (there is quite a number of people here that use/have used it without issues), this suggests that you are parsing the module list given by the multiboot header incorrectly. There is a number of ways this can go wrong, the easiest way to figure out what is for you to compare what your code is doing to the data structures defined in the multiboot documentation provided by grub,
Seems that there is hard to do error in this part.
I do in next way:
1. Address of module is got in next way:
Code: Select all
int boot_main(uint32_t mboot_ptr)
{
multiboot_info_t *mbinfo = (multiboot_info_t *) mboot_ptr;
....
log_info("main", "mods_addr=%X\n", (multiboot_module_t *) mbinfo->mods_addr);
...
mboot_ptr is got by pushing ebx on the stack in next way:
Code: Select all
MBOOT_PAGE_ALIGN equ 1<<0 ; Load kernel and modules on a page boundary
MBOOT_MEM_INFO equ 1<<1 ; Provide your kernel with memory info
MBOOT_HEADER_MAGIC equ 0x1BADB002 ; Multiboot Magic value
; NOTE: We do not use MBOOT_AOUT_KLUDGE. It means that GRUB does not
; pass us a symbol table.
MBOOT_HEADER_FLAGS equ MBOOT_PAGE_ALIGN | MBOOT_MEM_INFO
MBOOT_CHECKSUM equ -(MBOOT_HEADER_MAGIC + MBOOT_HEADER_FLAGS)
[BITS 32]
[GLOBAL mboot] ; Make 'mboot' accessible from C.
[EXTERN code] ; Start of the '.text' section.
[EXTERN bss] ; Start of the .bss section.
[EXTERN end] ; End of the last loadable section.
mboot:
dd MBOOT_HEADER_MAGIC ; GRUB will search for this value on each
; 4-byte boundary in your kernel file
dd MBOOT_HEADER_FLAGS ; How GRUB should load your file / settings
dd MBOOT_CHECKSUM ; To ensure that the above values are correct
dd mboot ; Location of this descriptor
dd code ; Start of kernel '.text' (code) section.
dd bss ; End of kernel '.data' section.
dd end ; End of kernel.
dd start ; Kernel entry point (initial EIP).
[GLOBAL start]
[EXTERN boot_main]
start:
mov ecx, [ap_init_len]
mov esi, ap_init
mov edi, 0x1000
rep movsb
; Load multiboot information:
push ebx
cli
call boot_main
jmp $
2. Memory map I got in next way:
Code: Select all
void func(multiboot_info_t *mbinfo)
{
multiboot_memory_map_t *mmap = (multiboot_memory_map_t *)(mbinfo->mmap_addr);
while((uint32_t) mmap < mbinfo->mmap_addr + mbinfo->mmap_length) {
.....
mmap = (multiboot_memory_map_t*) ( (uint32_t)mmap + mmap->size + sizeof(mmap->size) );
}
}
Loading in next way:
Code: Select all
multiboot (hd0,1)/my_bootloader
module (hd0,1)/bzImage ...
3. I dont think that multiboot structure is changed but I am using next one:
Code: Select all
struct multiboot_info
{
/* Multiboot info version number */
multiboot_uint32_t flags;
/* Available memory from BIOS */
multiboot_uint32_t mem_lower;
multiboot_uint32_t mem_upper;
/* "root" partition */
multiboot_uint32_t boot_device;
/* Kernel command line */
multiboot_uint32_t cmdline;
/* Boot-Module list */
multiboot_uint32_t mods_count;
multiboot_uint32_t mods_addr;
union
{
multiboot_aout_symbol_table_t aout_sym;
multiboot_elf_section_header_table_t elf_sec;
} u;
/* Memory Mapping buffer */
multiboot_uint32_t mmap_length;
multiboot_uint32_t mmap_addr;
/* Drive Info buffer */
multiboot_uint32_t drives_length;
multiboot_uint32_t drives_addr;
/* ROM configuration table */
multiboot_uint32_t config_table;
/* Boot Loader Name */
multiboot_uint32_t boot_loader_name;
/* APM table */
multiboot_uint32_t apm_table;
/* Video */
multiboot_uint32_t vbe_control_info;
multiboot_uint32_t vbe_mode_info;
multiboot_uint16_t vbe_mode;
multiboot_uint16_t vbe_interface_seg;
multiboot_uint16_t vbe_interface_off;
multiboot_uint16_t vbe_interface_len;
};
typedef struct multiboot_info multiboot_info_t;