Page 1 of 1

Multiboot

Posted: Wed Jul 08, 2009 11:58 am
by iskra
Hi everyone. I'm following JamesM's tutorial (found here http://www.jamesmolloy.co.uk/tutorial_html/index.html) to create my first 32-bit kernel. Tutorial uses GRUB as bootloader and GRUB passes a structure called multiboot_info. I've searched the GRUB documentations but couldn't find any information explaining what are those member variables of that struct. It says "if the flag's third bit is set then this information is correct" everywhere but i'm asking "what is that information about?"

I printed the information in multiboot_info struct to screen, so could anybody tell me what are they?

Thanks!

Image

Re: Multiboot

Posted: Wed Jul 08, 2009 3:05 pm
by f2

Re: Multiboot

Posted: Wed Jul 08, 2009 4:28 pm
by iskra
I should have posted that link in my original post since it doesn't contain the information i need. (At least, i couldn't find it in it). I'm asking, for example, what is the "cmdline" parameter?
Gnu.org wrote: If bit 2 of the `flags' longword is set, the `cmdline' field is valid, and contains the physical address of the command line to be passed to the kernel. The command line is a normal C-style zero-terminated string.
OK, but how in the world it got set "/kernel" in my bootloader?

Re: Multiboot

Posted: Wed Jul 08, 2009 4:54 pm
by iskra
I think i figured out what cmdline is about. I'm not much a linux-person and also i'm a newbie in OSDEV, so didn't realize that kernel itself is an application. I think this cmdline friend is something that linux understands.

And elf_sec. So my kernel binary is in ELF format? And elf_sec is just a struct about the header section?

Re: Multiboot

Posted: Wed Jul 08, 2009 5:51 pm
by JohnnyTheDon
In your menu.lst file, you must have written

Code: Select all

kernel /kernel
Everything on that line except the first 'kernel' is your command line. Its just a convenient way to pass some information to the kernel. Your kernel is NOT an application. The command line is completely static, not an input/output system.
And I would assume that your kernel is in ELF format. How are you compiling and linking it?

Re: Multiboot

Posted: Thu Jul 09, 2009 1:08 am
by iskra
JohnnyTheDon wrote:In your menu.lst file, you must have written

Code: Select all

kernel /kernel
Everything on that line except the first 'kernel' is your command line. Its just a convenient way to pass some information to the kernel. Your kernel is NOT an application. The command line is completely static, not an input/output system.
And I would assume that your kernel is in ELF format. How are you compiling and linking it?
Thanks for the reply. I don't know where "menu.lst" file is located actually. But here is my "link.ld", "boot.s" and Makefile.

Code: Select all

/* Link.ld -- Linker script for the kernel - ensure everything goes in the */

/*            Correct place.  */

/*            Original file taken from Bran's Kernel Development */

/*            tutorials: http://www.osdever.net/bkerndev/index.php. */



ENTRY(start)

SECTIONS

{



    .text 0x100000 :

    {

        code = .; _code = .; __code = .;

        *(.text)

        . = ALIGN(4096);

    }



    .data :

    {

        data = .; _data = .; __data = .;

        *(.data)

        *(.rodata)

        . = ALIGN(4096);

    }



    .bss :

    {

        bss = .; _bss = .; __bss = .;

        *(.bss)

        . = ALIGN(4096);

    }



    end = .; _end = .; __end = .;

}

Code: Select all

;

; boot.s -- Kernel start location. Also defines multiboot header.

;           Based on Bran's kernel development tutorial file start.asm

;



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]                       ; All instructions should be 32-bit.



[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]                  ; Kernel entry point.

[EXTERN main]                   ; This is the entry point of our C code



start:

    ; Load multiboot information:

    push    eax

    push    ebx



    ; Execute the kernel:

    cli                         ; Disable interrupts.

    call main                   ; call our main() function.

    jmp $                       ; Enter an infinite loop, to stop the processor

                                ; executing whatever rubbish is in the memory

                                ; after our kernel!

Code: Select all

# Makefile for JamesM's kernel tutorials.

# The C and C++ rules are already setup by default.

# The only one that needs changing is the assembler 

# rule, as we use nasm instead of GNU as.



SOURCES=boot.o main.o common.o monitor.o



CFLAGS=-nostdlib -nostdinc -fno-builtin -fno-stack-protector

LDFLAGS=-Tlink.ld

ASFLAGS=-felf



all: $(SOURCES) link



clean:

	-rm *.o kernel



link:

	ld $(LDFLAGS) -o kernel $(SOURCES)



.s.o:

	nasm $(ASFLAGS) $<

Re: Multiboot

Posted: Thu Jul 09, 2009 2:14 am
by salil_bhagurkar
menu.lst is in your floppy image that you use to boot into your OS. When you mount the floppy image, to put the kernel inside it, you can open this file by locating the directory boot/grub inside it.

Re: Multiboot

Posted: Thu Jul 09, 2009 3:08 am
by iskra
salil_bhagurkar wrote:menu.lst is in your floppy image that you use to boot into your OS. When you mount the floppy image, to put the kernel inside it, you can open this file by locating the directory boot/grub inside it.
Oh my... Got it, thank you very much!

Code: Select all

timeout 1



title	JamesM's Tutorial

	root (fd0)

	kernel /kernel

Re: Multiboot

Posted: Thu Jul 09, 2009 4:16 am
by jal
iskra wrote:Oh my... Got it, thank you very much!
You are well-advised to actually try to understand what you are doing, instead of just going step by step through a tutorial that you don't understand. All of your questions are the result of plain ignorance. You don't seem to know GRUB, you don't even know what you are compiling too, you don't understand the multiboot specification (and instead of blaming yourself you are blaiming the spec), etc. etc. There is some Required Knowledge(TM) before starting to develop an OS!


JAL

Re: Multiboot

Posted: Thu Jul 09, 2009 4:55 am
by iskra
jal wrote:
iskra wrote:Oh my... Got it, thank you very much!
You are well-advised to actually try to understand what you are doing, instead of just going step by step through a tutorial that you don't understand. All of your questions are the result of plain ignorance. You don't seem to know GRUB, you don't even know what you are compiling too, you don't understand the multiboot specification (and instead of blaming yourself you are blaiming the spec), etc. etc. There is some Required Knowledge(TM) before starting to develop an OS!

JAL
Well. In fact, I couldn't express myself clearly. I was following this tutorial and just finished the GDT and IDT part. But tutorial didn't describe some points clearly (it's a great tutorial as a whole, though) the ones i asked in this thread actually. So, i advanced to the GDT part but looked back and saw that i didn't learn how my kernel booted, so i decided to learn what is all about multiboot and GRUB. So i searched through internet, and gathered whatever i find. I know what i'm compiling. I just looked wrong place for certain information because i assumed members of a struct called "multiboot_info" should be in a document named "multiboot specification".

So my questions are not results of ignorance, instead they are results of curiosity. I could go on with tutorial but i didn't, so...

So, i agree with you, there is some required knowledge. But nobody borns with that information in brain.

Re: Multiboot

Posted: Thu Jul 09, 2009 5:56 am
by gravaera
I didn't understand the JamesM tutorial either at first. I couldn't read past the second part. Not because I couldn't follow, or didn't understand, but because I felt that I was allowing myself to be spoon fed. It took me about three weeks of reading from other sources, and searching, before I confidently continued up to the end, knowing that I definitely wasn't just taking what he said for granted, but I was able to do it myself, if necessary.

Reading is vital to OSDev.