mbchk

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Whatever5k

mbchk

Post by Whatever5k »

I've created my kernel and tested it with mbchk, which said this:

kernel: The Multiboot header is found at the offset 0.
kernel: Page alignment is turned off.
kernel: Memory information is turned off.
kernel: Address fields is turned off.
kernel: All checks passed.

So everything seems fine. But when I want to load it with GRUB, it sais "unsupported or invalid executable format".
Why that?

My source files:
start.s:

;; start.s
       ;; The very beginning of GiPP. It creates the multiboot-header for GRUB
and then just loads the main C-function (kernel_main).



section .data

       MULTIBOOT_HEADER_MAGIC equ 0x1BADB002
       MULTIBOOT_HEADER_FLAGS equ 0x00000000
       MULTIBOOT_HEADER_CHKSUM equ 0xE4524FF

section .text

       global _start           ; where the compiler jumps to...
       extern kernel_main      ; the C-function to jump to

_start:
       ;; build the multiboot header for GRUB
       align 4
       dd MULTIBOOT_HEADER_MAGIC
       dd MULTIBOOT_HEADER_FLAGS
       dd MULTIBOOT_HEADER_CHKSUM

       CALL kernel_main
       jmp $ ;halt

So it creates the Multiboot-header and calls the C-function... .
Here's the main.c:

/*main.c*/

int kernel_main(void); /*prototype*/

void write_string (int colour, char *string)
{
char *video=(char*)0xB8000;
while(*string!=0)
{
*video=*string;
string++;
video++;
*video=colour;
video++;
}
}


int kernel_main(void)
{
write_string (5, "hello, world");
while(1);
return 0;
}

Somebody knows what I'm still doing wrong?
K.J.

Re: mbchk

Post by K.J. »

Did you output your kernel in ELF format?

K.J.
Whatever5k

Re: mbchk

Post by Whatever5k »

No, I linked it to a binary:

nasm -f elf start.s
gcc -c main.c
ld -Ttext 0x100000 --oformat binary start.o main.o
K.J.

Re: mbchk

Post by K.J. »

I'm not 100% sure about this, but I think that GRUB needs it to be and ELF.

K.J.
Chris Giese

Re: mbchk

Post by Chris Giese »

>kernel: Address fields is turned off.

This means that you are NOT using the aout kludge.
If the kernel is not ELF format, you must use the kludge.

'mbchk' doesn't check for this (:: sigh ::)

I am adding this to my GRUB ***** list (now up to 10 items)
User avatar
df
Member
Member
Posts: 1076
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

Re: mbchk

Post by df »

I am adding this to my GRUB ***** list (now up to 10 items)
now would be a good time to communicate that list to the grub guys. i know eric + yoshinori-san were going over doing a revised multiboot spec 0.7...

[email protected]
[email protected]
-- Stu --
Whatever5k

Re: mbchk

Post by Whatever5k »

Thanks, I linked it to elf and tried to boot it... .
Look at this, I've done the following steps:

root=(fd0)
kernel=(fd0)/kernel
boot

When I typed "kernel=(fd0)/kernel" GRUB said s.th. like this:

[Multiboot-elf] [0x0f244:3423] [0xa23d:3d] [start=0x100000]

The numbers are not right, but it looked s.th. like that.
Now I typed "boot" but GRUB said that the kernel has to be loaded before booting. But I just did it by typing "kernel=....".
So what's wrong?
Whatever5k

Re: mbchk

Post by Whatever5k »

I tried several things and that's what I found out. I build two slightly different kernels. They had the same asm file (start.s):

;; start.s
     ;; The very beginning of GiPP. It creates the multiboot-header for GRUB and then just loads the main C-function (kernel_main).

section .data

       MULTIBOOT_HEADER_MAGIC equ 0x1BADB002
     MULTIBOOT_HEADER_FLAGS equ 0x00000000
     MULTIBOOT_HEADER_CHKSUM equ -(MULTIBOOT_HEADER_MAGIC + MULTIBOOT_HEADER_FLAGS)

section .text

       global _start            ; where the compiler jumps to...
     extern kernel_main      ; the C-function to jump to

_start:
     ;; build the multiboot header for GRUB
     align 4
     dd MULTIBOOT_HEADER_MAGIC
     dd MULTIBOOT_HEADER_FLAGS
     dd MULTIBOOT_HEADER_CHKSUM

     jmp kernel_main

They differed in the C-file. Here's the version which works:

/*main.c*/

int kernel_main(void); /*prototype*/

int kernel_main(void)
{
char *video = (char*) 0xB8000;
*video = 'h';
*(video + 2) = 'i';
while(1); /*keep doing nothing*/
return 0;
}

If I compiled this C-file and linked it with the asm-file and booted it with GRUB, there was not this boot-error (it didn't put text on the screen, but this is not important for now). So this versions seems to work.

This is the version which did not work. It differs in the C-file:

/*main.c*/

int kernel_main(void); /*prototype*/

void write_string(int colour, char *string)
        {
                char *video=(char*)0xB8000;
                while(*string!=0)
                {
                        *video=*string;
                        string++;
                        video++;
                        *video=colour;
                        video++;
                }
        }

int kernel_main(void)
{
write_string(5, "hello, world");
while(1); /*keep doing nothing*/
return 0;
}

If I link this with the asm-file, GRUB cannot boot the kernel (it alway sais "kernel has to be loaded before booting", see above).

My question is: why can't GRUB load the version where there's a separate function for putting text on the screen?

Perhaps now somebody can help me.
regards,
A. Blessing
User avatar
df
Member
Member
Posts: 1076
Joined: Fri Oct 22, 2004 11:00 pm
Contact:

Re: mbchk

Post by df »

_start:
;; build the multiboot header for GRUB
align 4
dd MULTIBOOT_HEADER_MAGIC
dd MULTIBOOT_HEADER_FLAGS
dd MULTIBOOT_HEADER_CHKSUM

jmp kernel_main
err... you have DATA before CODE!

put the jmp kernel_main before the multiboot flags....
-- Stu --
Whatever5k

Re: mbchk

Post by Whatever5k »

Allright, it works... .
But why did the first version work (which also had the code before data)?
And my second question:

The kernel was supposed to ouput text. Well, after I typed "boot", my kernel started loading and did nothing but loop because of "while(1);". But it didn't ouput the "hello, world" text.
I wanted to halt my computer, but I clicked on the "save-energy-button" for pause. When I restarted the computer, the string "hello world" was put on the screen.
Why that?
Post Reply