How to request BIOS using GRUB?

I'm trying to make a small kernel for the 80386 processor mainly for training and I want to get a full memory card of available RAM.

I read that with GRUB this is possible and better to do than directly request the BIOS.

Can anyone tell me how to do this?

In particular, to use the bios functionality in real mode, we use bios interrupts and get the required values โ€‹โ€‹in some registers, what is the actual equivalent way when we want to use the functions provided by GRUB?

+5
source share
1 answer

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

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

Then GRUB loads the address of the multiboot information structure into ebx for you (this structure contains the address of the memory card). Then I call the C code to handle the actual iteration and process the memory card. I am doing something similar to iterate over a 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 defined as in the Gnu multiboot.h file. As Andrew Medico noted in the comments, here is a great link to get started with this.

+2
source

Source: https://habr.com/ru/post/1205975/


All Articles