Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Putting Two ORGs Together

I'm building a boot loader that boots the content that is located at the 1000h part of the floppy. I was doing that using Fasm(because my friend only uses Fasm, and he was helping me with this), but I prefer to use Nasm, and now I'm having problems with the syntax, then I want to know how could I do this in Nasm:

org 7C00h
    %include "boot.asm"

org 1000h
    %include "kernel.asm"

PS: I already put the %include directive using Nasm-syntax style, on Fasm it should be just include.

like image 476
Nathan Campos Avatar asked May 11 '26 01:05

Nathan Campos


2 Answers

See here for the description of your problem or what I think it is since it's a little hard to tell from the question. It's a good idea when posting questions with "I'm having problems with the syntax" to actually show what the syntax problem is :-)

See here for the solution (but it may not work, see below).

Basically, the org statement in NASM is meant to set the base address for the section and cannot be used to arbitrarily insert bytes into the stream. It suggests you use something like:

org 1000h
%include "kernel.asm"
times 7c00h-($-$$) db 0 ; pad it out with zero bytes
%include "boot.asm"

However, have you thought about what you're trying to do. If you're creating a flat binary file to load into memory, I don't think you want both the boot sector and kernel in a single file anyway.

The BIOS will want to load your boot sector as a single chunk at 7c00:0 and will almost certainly be confused when it has the kernel at the start of that chunk. I think what you will need to do is to create two totally separate flat binary files, one for the boot sector and another for the kernel. BIOS will load your boot sector, then your boot sector will load your kernel.

Then you can put the relevant org statement in the two source files and your problem should hopefully be solved.

like image 133
paxdiablo Avatar answered May 14 '26 17:05

paxdiablo


While org is only allowed once in NASM bin format source, you can use its multi-section support to create what I believe is the exact same as your FASM output with two org directives. Refer to https://www.nasm.us/xdoc/2.14.02/html/nasmdoc7.html#section-7.1.3

This is what a bootloader with such a second stage would look like:

        org 7C00h
        section BOOTSECTOR start=7C00h

        ; boot sector content here

        times 510 - ($ - $$) db 0
        dw 0AA55h


        section KERNEL follows=BOOTSECTOR vstart=1000h

        ; kernel content here
like image 33
ecm Avatar answered May 14 '26 15:05

ecm



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!