1

で16ビットの実行可能BINARYRAW形式を生成したいWatcom C compiler。リアルモードで実行されるヘッダーのない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.batWatcomコンパイラとリンカによって生成された次のメッセージを実行した後:

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値を指定する方法はありますか?

4

1 に答える 1

1

スタックセグメント情報は通常、最終的にmainを呼び出すcstartupモジュールで初期化されます。リンカは、リンクに含まれるモジュールのスタック要件を合計します。これは、cstartupがspに配置する値に反映されます。マルチスレッドフラグがない限り、スタックセグメントはdsとesのグループ化の一部になります(ssが分離される場合)。リンカコマンドファイルでスタックサイズを設定してみることもできます。

カーネルを呼び出す前に、大容量メモリモデルに必要なセグメントとグループを定義する.asmモジュールを作成することをお勧めします。多くの試行錯誤がありますが、学習した内容はほとんどの環境のスタートアップコードに適用できます。

Watcomが生成できる(逆アセンブリ).lstファイルを確認すると、.asmモジュールの記述方法に関する十分なガイダンスが得られるはずです。

于 2012-05-22T17:58:01.430 に答える