How to build a binary with nasm

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
huxuelei
Member
Member
Posts: 35
Joined: Tue May 27, 2008 8:32 am

How to build a binary with nasm

Post 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.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post by pcmattman »

Your NASM command line is...?

Also, RTFM and STFW. You're most likely not the only person to find this problem.
huxuelei
Member
Member
Posts: 35
Joined: Tue May 27, 2008 8:32 am

Post by huxuelei »

My command line is :
nasm -f bin kernel.s -o kernel.bin
svdmeer
Member
Member
Posts: 87
Joined: Tue May 06, 2008 9:32 am
Location: The Netherlands

Post 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.
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Re: How to build a binary with nasm

Post 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
Post Reply