www.digitalmars.com         C & C++   DMDScript  

c++ - Questions about DMC and Linking for 8086 real-mode

Hello everyone. I'm a little bit new with this compiler.
Well I'm trying to create a small application that would run on 
existing hardware (80C186 board, 16K ROM at top, 16K RAM at 
bottom), which was part of an embedded device.
I know that I'm insane for doing such task, but anyway!

First of all, I've tryied to write a small bootloader for 
standard x86 PCs to test the linking procedure; because it runs 
on real mode. The code uses an asm loader, and C. The result code 
must be loaded at 0x7c00.

Since the stack is assigned in the small ASM file (prior to the 
C), there is no need to define a "blank" stack segment.

That thing is working properly, but it is using a different 
memory map from the 80C186.

So, to build a correct binary, I should change the position of 
which some segments should be.

The stack doesn't need to be changed since it was pre-configured 
in ASM. Also the "code" segment is well placed (since i'm using 
the switch /BINARY:addr).

But what about Initialized data? In my "bootloader" test, there 
were no initialized data, since it's a simple "hello world".

I should add a code in ASM that loads the "initialized data" to 
the ram, but how can I change the behaivor of the Linker in that 
case? i.e. tell the code that initialized data is in "RAM" but 
the "initial" values are in the rom (which the loader will dump 
to ram on startup).

Here is my "build.bat" file, which first compiles the code, and 
then links it.
I've followed this tutorial 

Note: I'm using MSVC152 macro assembly compiler since the 
original code was written for that and not for DMC assembly (i'll 
change this later).
Also, I have to add manually a "signature" at 0x7DFE (0x1FE from 
the begin of the image) which I don't know how to add as a 
section (in gnu ld this was an easy task)

.\DM\BIN\DMC.exe main.cpp -g -0 -c -ms
.\DM\BIN\DMC.exe cdisplay.cpp -g -0 -c -cpp -ms
.\DM\BIN\DMC.exe cstring.cpp -g -0 -c -cpp -ms
.\MSVC152\ml.exe /AT /c *.asm
/BASE:0x7c00 /BINARY:0x7C00  loader.obj cstring.obj cdisplay.obj 
move loader.SYS output.bin
del *.obj

Thanks! (PS: Sorry for my bad english)
Dec 11 2014