GRUB PROB

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
codemastersnake

GRUB PROB

Post by codemastersnake »

Hello every one....

I have created a kernel ... but when i try to load it through grub I get error
-------
Booting 'Magneto ver 0.1'

root (fd0)
Filesystem type is fat, using whole disk
kernel /kernel.bin

Error 13: Invalid or unsupported executable format

Press any key to continue...

------

I created that kernel by following :

tlink /x /t obj obj, kernel,bin

/t is for .com file....

how can i make my kernel so that it loads with grub...
GLneo

Re:GRUB PROB

Post by GLneo »

make it a ".elf" kernel
nick8325
Member
Member
Posts: 200
Joined: Wed Oct 18, 2006 5:49 am

Re:GRUB PROB

Post by nick8325 »

Codemaster Snake wrote: I created that kernel by following :

tlink /x /t obj obj, kernel,bin

/t is for .com file....

how can i make my kernel so that it loads with grub...
This is a bit strange...are you using Turbo C? I think that can only generate real mode code, and GRUB boots into 32-bit protected mode.

If your code is 32-bit, you should look at the hex values at the start of your kernel binary, and compare them with the multiboot header at http://www.gnu.org/software/grub/manual/multiboot/multiboot.html#OS%20image%20format.

If your code is real mode, you can either:
1) Use a different compiler (e.g. GCC, Watcom) and write 32-bit protected mode code
or
2) Use a different bootloader. Alexei Frounze has written one at http://alexfru.chat.ru/epm.html#bootprog, which can load DOS COM and EXE programs. He also has some information about 16-bit code at http://alexfru.narod.ru/os/c16/c16.html.
codemastersnake

Re:GRUB PROB

Post by codemastersnake »

Yeah I know! Many people find it very strange that I use Turbo C++ for development.... They are always curious that how can I use that....

Well I am pretty confortable with turbo c++ and have created 4 versions of my OS with that....

I am presently using own modified bootloader to load raw .com image to memory and then jump to it.

Now I wanted to use grub for my kernel... and have faced the problem where it says: unsupprotd executable file format.

I would still like to stay with Turbo C++. IS there any way by which I could modify the outputted kernel.bin file to be compatible with grub....

Also Turbo C++ does produce 32 bit protected mode code.
and what is the .elf file/foemat mentioned above
nick8325
Member
Member
Posts: 200
Joined: Wed Oct 18, 2006 5:49 am

Re:GRUB PROB

Post by nick8325 »

OK, that's fine. I just wanted to make sure :)

Do you know that for GRUB to load your kernel you need to add a multiboot header? The first link I posted earlier shows what you need to put in it - that data needs to be near the start of the .com file.

Also, GRUB doesn't set ESP. If you're not doing it already, you'll need to reserve some space for a stack (like char stack[4096]) and then set ESP to point at the top of that.

If you do have the multiboot header, get a hex dump of the first few (128 or so) bytes of the .com file, and then check that the header is in there and looks like it should. Post it here if you're not sure.

Also, check that the load_end_addr - load_addr in the multiboot header is the same size as the .com file. If it's bigger than the file, GRUB won't load it.
nick8325
Member
Member
Posts: 200
Joined: Wed Oct 18, 2006 5:49 am

Re:GRUB PROB

Post by nick8325 »

Sorry, I forgot to mention: ELF is an executable file format used by Unix and very popular for OSDev. GRUB can load ELF files without much change to them.
codemastersnake

Re:GRUB PROB

Post by codemastersnake »

nick8325 wrote: OK, that's fine. I just wanted to make sure :)

Do you know that for GRUB to load your kernel you need to add a multiboot header? The first link I posted earlier shows what you need to put in it - that data needs to be near the start of the .com file.

Also, GRUB doesn't set ESP. If you're not doing it already, you'll need to reserve some space for a stack (like char stack[4096]) and then set ESP to point at the top of that.

If you do have the multiboot header, get a hex dump of the first few (128 or so) bytes of the .com file, and then check that the header is in there and looks like it should. Post it here if you're not sure.

Also, check that the load_end_addr - load_addr in the multiboot header is the same size as the .com file. If it's bigger than the file, GRUB won't load it.
I didn't knew that...
I forgot to mention that my os is a 16bit RM os....
OK I am bit lazy now can you tell me quickly how to add multiboot header...
nick8325
Member
Member
Posts: 200
Joined: Wed Oct 18, 2006 5:49 am

Re:GRUB PROB

Post by nick8325 »

Oh, by:
Codemaster Snake wrote: Also Turbo C++ does produce 32 bit protected mode code.
I thought that you meant that you were using Turbo C++ to make 32 bit code.

GRUB can only load 32-bit kernels, so you will have to use something else.

Like I said in my first post, you should be able to use Alexei Frounze's bootloader instead. That will load your kernel from a .EXE or .COM file on a disk and then jump to it.
codemastersnake

Re:GRUB PROB

Post by codemastersnake »

K that means that I'll have to make my kernel 32 bit to be able to make it bootable from GRUB.....
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:GRUB PROB

Post by Solar »

nick8325 wrote:GRUB can only load 32-bit kernels, so you will have to use something else.
Incorrect. GRUB can chainload just about everything. It's only when you're loading a multiboot kernel that this must be a 32bit kernel (since the multiboot procedure activates Protected Mode).
Every good solution is obvious once you've found it.
nick8325
Member
Member
Posts: 200
Joined: Wed Oct 18, 2006 5:49 am

Re:GRUB PROB

Post by nick8325 »

Solar wrote:
nick8325 wrote:GRUB can only load 32-bit kernels, so you will have to use something else.
Incorrect. GRUB can chainload just about everything. It's only when you're loading a multiboot kernel that this must be a 32bit kernel (since the multiboot procedure activates Protected Mode).
But AFAIK (and according to grub/stage2/builtins.c:chainloader_func) it will only load one sector, so it only does what the BIOS would do anyway. As such it's not really useful as a bootloader for real mode code.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:GRUB PROB

Post by Solar »

nick8325 wrote: But AFAIK (and according to grub/stage2/builtins.c:chainloader_func) it will only load one sector, so it only does what the BIOS would do anyway. As such it's not really useful as a bootloader for real mode code.
With the small difference that it can load that one sector from a wide variety of file systems, by name (it doesn't have to reside in the boot sector), provides a comfortable multiple-choice menu to select whether to chainload your sector or start Windows or Linux or whatever, provides network and CD-ROM booting...

;)
Every good solution is obvious once you've found it.
Post Reply