Here is my source code


.386
.model flat,stdcall

.data
msg db "Here is data section"

.code
start:
dw msg
dw next
next:
end start


I compiled like this
ml /c /coff src.asm


and then I linked
link /subsystem:consol src.obj


What I've discovered in src.exe is that code section start at 0x200 and data section start at 0x400
What I want is code section starts at 0x1000 and data section starts at 0x2000
How can I do that?

The reason why I want that is 'dw msg' is assembled 0x00402000 and 'dw start' is assembled 0x00401008.
in my boot loader that src.exe will be loaded in 0x10000.
I'll jump to 0x11000 where code section start...

But the problem was in src.exe code section starts at 0x200
Can someone help me?
Posted on 2004-06-07 22:28:59 by johnny_d
Hrm, shouldn't you be using "dd offset msg" instead of "dw msg" ?

Anyway, with the microsoft linker you can't get 100% flexible control of the section ordering and such. You can, however, use /BASE: to set the imagebase, and use /FILEALIGN and /ALIGN.

However, you're better off writing a small piece of code in nasm or fasm that does proper PE loading - ie, a three-stage OS (bootloader, "osloader", kernel).
Posted on 2004-06-08 05:07:44 by f0dder
thanks f0dder...
I didn't know MS linker have /FILEALIGN option..
That might be helpful..

I strongly agree with you ..
"osloader" is good idea..
I also thought about that..

But I didn't want to give up linking with kernel....

Thanks anyway..
Posted on 2004-06-08 09:46:37 by johnny_d
I don't believe there's any point in using the PE format for this, since it is designed for 32-bit systems that use paging. Use a plain binary format instead (must use the old link.exe for this, or another linker which can output it)
Posted on 2004-06-08 11:13:29 by Sephiroth3
Sephiroth, no idea in using PE format for kernel? ;)
Posted on 2004-06-08 11:34:59 by f0dder
I think it would be better to get the basics running first, at least get a working memory management system. When Ntoskrnl.exe starts, a lot has already been set up by Ntldr, and we have 32-bit protected mode running.
Posted on 2004-06-08 11:52:24 by Sephiroth3
that's true enough, I certainly wouldn't load PE directly from the bootsector. ntldr sets up pmode, some temporary paging, and loads drivers (well, loads them into memory, can't remember if it activates them). But it doesn't do _all_ that much, does it?
Posted on 2004-06-08 13:08:06 by f0dder