Page 1 of 1

problems of using GRUB as bootloader

Posted: Sun Jul 08, 2007 7:59 pm
by fei
I want to use GRUB as the bootloader for my kernel as suggested from BareBone Wiki page on http://www.osdev.org/wiki/Bare_bones.

My question is how I can acess the harware resources detected at the booting stage. For example, how much physical memory is available and what ata disks are available.

Another question is that I'm quite confused of which is the right way to use grub as the bootlaoder. Some examples use some multiboot macros (showb below). But the Barebone wiki page example doesn't use these macros. Can I get a berief explanation of why to use and how to use these macros??

Thanks in advance!

Code: Select all

; Multiboot constants
MULTIBOOT_PAGE_ALIGN	equ 1<<0
MULTIBOOT_MEMORY_INFO	equ 1<<1
MULTIBOOT_HEADER_MAGIC	equ 0x1BADB002
MULTIBOOT_HEADER_FLAGS	equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO
MULTIBOOT_CHECKSUM	equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)

Posted: Sun Jul 08, 2007 8:47 pm
by d4n1l0d
Yes, barebone uses macros.

this:
; setting up the Multiboot header - see GRUB docs for details
MODULEALIGN equ 1<<0 ; align loaded modules on page boundaries
MEMINFO equ 1<<1 ; provide memory map
FLAGS equ MODULEALIGN | MEMINFO ; this is the Multiboot 'flag' field
MAGIC equ 0x1BADB002 ; 'magic number' lets bootloader find the header
CHECKSUM equ -(MAGIC + FLAGS) ; checksum required
is the same of this
; Multiboot constants
MULTIBOOT_PAGE_ALIGN equ 1<<0
MULTIBOOT_MEMORY_INFO equ 1<<1
MULTIBOOT_HEADER_MAGIC equ 0x1BADB002
MULTIBOOT_HEADER_FLAGS equ MULTIBOOT_PAGE_ALIGN | MULTIBOOT_MEMORY_INFO
MULTIBOOT_CHECKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)
You can learn more about macros reading your asm compiler manual.

------------------
The way you can acess the hardware information stored by GRUB in the multboot header is sending its pointer to the stack ( as shown in bare bones )

Code: Select all


_loader:
   mov esp, stack+STACKSIZE           ; set up the stack
   push eax                           ; pass Multiboot magic number
   push ebx                           ; pass Multiboot info structure

   call  _main                        ; call kernel proper
               hlt                    ; halt machine should kernel return

now, you need to know the multboot structure ( check GRUB documentation for that ).

Write the structure in C code and get It into you kernel code:

Code: Select all

void _main( void* mbd, unsigned int magic )
{
   // write your kernel here
}
[/CODE]

Re:

Posted: Mon Jul 09, 2007 3:55 am
by fei
Thanks for the reply. Makes me clear now. GRUB has to find the header within the first 8K. I also find theses links: http://www.osdever.net/tutorials/grub.php and http://www.gnu.org/software/grub/manual ... t.html#Top. They are quite helpful.