簡體   English   中英

Watcom編譯器如何從C生成16位可執行BINARY RAW格式?

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

我想通過Watcom C compiler生成16位可執行BINARY RAW格式。 像EXE文件一樣,沒有在實模式下運行的任何標頭。

我使用Large內存模型,因此代碼段和數據段可能不同,並且可能增加超過64K字節。

我喜歡這樣:

// 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;
}

為了編譯以上代碼,我在批處理文件下運行:

@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

運行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

輸出文件成功生成。

但是我的問題是:

如何解決W1014警告?

有什么方法可以指定初始CS值嗎?

堆棧段信息通常在cstartup模塊中初始化,該模塊最終將調用main。 鏈接器將匯總鏈接中包含的模塊的堆棧要求,這將反映在sp.cstartup中的值中。 除非您具有多線程標志(當ss分開時),否則堆棧段將是ds和es分組的一部分。 您也可以嘗試在鏈接器命令文件中設置堆棧大小。

我建議您編寫一個.asm模塊,該模塊定義大內存模型調用內核之前所需的段和組。 很多試驗和錯誤,但是您學到的知識將適用於大多數環境的啟動代碼。

檢出Watcom可以生成的(反匯編).lst文件,您應該獲得有關如何編寫.asm模塊的足夠指導。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM