简体   繁体   中英

How I generate RAW BIN with declared segment offset using WatCom

I wrote a boot loader in NASM which is load a 64kb program data from the disk into the memory starts by address 0060:0000 [SEG:OFF]. I had tested this part of my project by Writing some code in Assembly (NASM) and put it into the disk. Works fine!

The full project it is a little bit complex for totally writing in Assembly. So I decide that I will use C with inline Assembly for further. For this I download an environment named open-watcom-c-win32-1.9. I have a simple C code for testing some WatCom compiler and linker directives to make RAW BIN file. The bin file are generated but not runs after my boot loader load it into the memory. I try a lot of wlink directives to set the segment and offset values but does not works.

void main()
{ 
 __asm 
      { 
       mov ah, 0x0E
       mov al, '!' 
       int 0x10 
      }
}

I think that the problem is that the compiler and linker uses wrong segment and offset addresses while the code generating. Because the Wlink drop the following error in any case.

Warning! W1023 no starting address found, using 0000:0000

I do not know that how I can set correctly the segment offset addresses but it would be necceserly for a working program. My questions that what kind of WatCom directives I use for generating 16 bit real mode RAW BIN file from a C source code with declared segment : offset? It is possible with WatCom or i need to use other stuff?

Since the order of the C functions is somewhat unpredictable some special init code is needed at the actual entry point. In this case the entry point always is in the very beginning of the file. The encoded offset of this initial code also dictates the offset of all other addresses (the segemnt doesn't matter and the compiler makes no assumptions about it). You will probably want to write your own very lean init code. The default init code is in the file cstart_t.obj, so you need to replace that. Exactly what you need to put in there depends on what you need, if the linker complains about some missing symbol you might need to throw it in there. A minimal one like this will work with your example code but might leave some C functions unusable (written in Nasm syntax):

global __STK
extern main_  ; The actual name of the main function depends on the memory model I think.

section _INIT class=CODE

resb 0        ; The expected offset of the code.
..start:
  jmp main_   ; Don't expect main() to return.

section _STACK stack class=STACK
__STK:

group DGROUP _INIT _STACK

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM