简体   繁体   中英

How to generate 16-bit executable BINARY RAW format from C by Watcom compiler?

I want to generate a 16-bit executable BINARY RAW format by Watcom C compiler . Something like an EXE file without any header that runs in Real Mode.

I use Large memory model, Thus code segment and data segment may be different and can increase more than 64K bytes.

I do like this:

// kernel.c
void kernel(void)
{
    /* Print Hello! */
    __asm
    {
        mov ah, 0x0E;
        mov bl, 7

        mov al, 'H'
        int 0x10

        mov al, 'e'
        int 0x10

        mov al, 'l'
        int 0x10

        mov al, 'l'
        int 0x10

        mov al, 'o'
        int 0x10

        mov al, '!'
        int 0x10
    }
    return;
}

For compiling above code I run below batch file:

@rem build.bat

@rem Cleaning.
del *.obj
del *.bin

cls

@rem Compiling.
@rem 0:     8088 and 8086 instructions.
@rem d0:    No debugging information.
@rem ml:    The "large" memory model (big code, big data) is selected.
@rem s:     Remove stack overflow checks.
@rem wx:    Set the warning level to its maximum setting.
@rem zl:    Suppress generation of library file names and references in object file.
wcc -0 -d0 -ml -s -wx -zl kernel.c

@rem Linking.
@rem FILE:      Specify the object files.
@rem FORMAT:    Specify the format of the executable file.
@rem NAME:      Name for the executable file.
@rem OPTION:    Specify options.
@rem Note startup function (kernel_) implemented in kernel.c.
wlink FILE kernel.obj FORMAT RAW BIN NAME kernel.bin OPTION NODEFAULTLIBS, START=kernel_

del *.obj

After running build.bat the following message generated by Watcom compiler and linker:

D:\Amir-OS\ckernel>wcc -0 -d0 -ml -s -wx -zl kernel.c
Open Watcom C16 Optimizing Compiler Version 1.9
Portions Copyright (c) 1984-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See http://www.openwatcom.org/ for details.
kernel.c: 28 lines, included 35, 0 warnings, 0 errors
Code size: 39

D:\Amir-OS\ckernel>wlink FILE kernel.obj FORMAT RAW BIN NAME kernel.bin OPTION N
ODEFAULTLIBS, START=kernel_
Open Watcom Linker Version 1.9
Portions Copyright (c) 1985-2002 Sybase, Inc. All Rights Reserved.
Source code is available under the Sybase Open Watcom Public License.
See http://www.openwatcom.org/ for details.
loading object files
Warning! W1014: stack segment not found
creating a RAW Binary Image executable

Output files successfully generated.

But my question is:

How can I resolve W1014 warning?

And is there any way to specify initial CS value?

The stack segment information is usually initialized in the cstartup module which eventually calls main. The linker will sum stack requirements for the modules included in the link and this will be reflected in the value cstartup places in sp. The stack segment will be part of the ds and es grouping unless you have the multi-threading flag (when ss will be separate). You can also experiment with setting the stack size in the linker command file.

I suggest you write a .asm module which defines the segments and groups required by the large memory model before it calls kernel. A lot of trial and error but what you learn will be applicable to the startup code for most environments.

Check out the (disassembly) .lst file that Watcom can generate and you should get enough guidance on how the .asm module should be written.

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