简体   繁体   English

Watcom编译器如何从C生成16位可执行BINARY RAW格式?

[英]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 . 我想通过Watcom C compiler生成16位可执行BINARY RAW格式。 Something like an EXE file without any header that runs in Real Mode. 像EXE文件一样,没有在实模式下运行的任何标头。

I use Large memory model, Thus code segment and data segment may be different and can increase more than 64K bytes. 我使用Large内存模型,因此代码段和数据段可能不同,并且可能增加超过64K字节。

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: 运行build.bat之后,Watcom编译器和链接器生成以下消息:

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? 如何解决W1014警告?

And is there any way to specify initial CS value? 有什么方法可以指定初始CS值吗?

The stack segment information is usually initialized in the cstartup module which eventually calls main. 堆栈段信息通常在cstartup模块中初始化,该模块最终将调用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. 链接器将汇总链接中包含的模块的堆栈要求,这将反映在sp.cstartup中的值中。 The stack segment will be part of the ds and es grouping unless you have the multi-threading flag (when ss will be separate). 除非您具有多线程标志(当ss分开时),否则堆栈段将是ds和es分组的一部分。 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. 我建议您编写一个.asm模块,该模块定义大内存模型调用内核之前所需的段和组。 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. 检出Watcom可以生成的(反汇编).lst文件,您应该获得有关如何编写.asm模块的足够指导。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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