mbchk
mbchk
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?
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?
Re: mbchk
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...I am adding this to my GRUB ***** list (now up to 10 items)
[email protected]
[email protected]
-- Stu --
Re: mbchk
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?
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?
Re: mbchk
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
;; 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
Re: mbchk
err... you have DATA before CODE!_start:
;; build the multiboot header for GRUB
align 4
dd MULTIBOOT_HEADER_MAGIC
dd MULTIBOOT_HEADER_FLAGS
dd MULTIBOOT_HEADER_CHKSUM
jmp kernel_main
put the jmp kernel_main before the multiboot flags....
-- Stu --
Re: mbchk
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?
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?