简体   繁体   中英

How to query BIOS using GRUB?

I am trying to make a small kernel for 80386 processor mainly for learning purpose and want to get the full memory map of the available RAM.

I have read that it is possible and better to do so with the help of GRUB than directly querying the BIOS.

Can anybody tell me how do I do it ?

Particularly, for using bios functionality in real mode we use bios interrupts and get the desired values in some registers , what is the actual equivalent way when we want to use GRUB provided functions ?

Here is the process I use in my kernel (note that this is 32bit). In my bootstrap assembly file, I tell GRUB to provide me with a memory map:

.set MEMINFO,  1 << 1                   # Get memory map from GRUB

Then, GRUB loads the address of the multiboot info structure into ebx for you (this structure contains the address of the memory map). Then I call into C code to handle the actual iteration and processing of the memory map. I do something like this to iterate over the map:

/* Macro to get next entry in memory map */

#define MMAP_NEXT(m) \
            (multiboot_memory_map_t*)((uint32_t)m + m->size + sizeof(uint32_t))

void read_mmap(multiboot_info_t* mbt){

    multiboot_memory_map_t* mmap = (multiboot_memory_map_t*) mbt->mmap_addr;


    /* Iterate over memory map */

    while((uint32_t)mmap < mbt->mmap_addr + mbt->mmap_length) {

        // process the current memory map entry

        mmap = MMAP_NEXT(mmap);
    }
}

where multiboot_info_t and multiboot_memory_map_t are defined as in the Gnu multiboot.h file. As Andrew Medico posted in the comments, here is a great link for getting started with this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM