Page 1 of 1

How to build a binary with nasm

Posted: Tue May 27, 2008 11:03 pm
by huxuelei
Hi, I have written a program with NASM . It can run in DOS.
I want to use GRUB4DOS to load that program into memory.
Here is my command in GRUB:

root (fd0) (1)
kernel /mykernel.bin (2)

After line (2) execute, the grub told me this information:
Error 14: Invalid or unsupported executable format.

The head of my program is like this:

org 0100h
jmp START_REALMODE

As you see, I build this program to COM format.Is there anything should change when I want to build a binary file?


I don't know how to solve this problem. Please help me.

Posted: Tue May 27, 2008 11:10 pm
by pcmattman
Your NASM command line is...?

Also, RTFM and STFW. You're most likely not the only person to find this problem.

Posted: Tue May 27, 2008 11:37 pm
by huxuelei
My command line is :
nasm -f bin kernel.s -o kernel.bin

Posted: Wed May 28, 2008 1:00 am
by svdmeer
There is nothing wrong with the COM-format, as long as your bootloader supports it. But I Grub doesn't support it. Grub needs additional info where to load it in memory. In most cases this information is included in the executable format, many Grub-users use ELF-format.

This topic is imho not needed when you read the manuals of Grub and Nasm.

Re: How to build a binary with nasm

Posted: Wed May 28, 2008 1:36 am
by JamesM
Hi,
huxuelei wrote:Hi, I have written a program with NASM . It can run in DOS.
I want to use GRUB4DOS to load that program into memory.
Here is my command in GRUB:

root (fd0) (1)
kernel /mykernel.bin (2)

After line (2) execute, the grub told me this information:
Error 14: Invalid or unsupported executable format.

The head of my program is like this:

org 0100h
jmp START_REALMODE

As you see, I build this program to COM format.Is there anything should change when I want to build a binary file?


I don't know how to solve this problem. Please help me.
I think you're slightly mistaken about a few things. You say that your program can run in DOS - does that mean that it relies on DOS functionality? if so, you won't be able to run it without DOS loaded first, and grub4dos doesn't do that (I've just looked at its wiki page).

All grub4dos is, apparently, is a slightly different implementation of GNU GRUB, with a few tweaks here and there. If you wish to use the 'kernel' command, you must provide a kernel which is either in ELF format (because GRUB can read ELF executables itself) or have a multiboot header, more information on which can be found here and here.

It's the lack of multiboot header that causes grub to fail.

Hope this helps,

James