我想通过Watcom C compiler生成一个16位的可执行二进制原始格式。类似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值?
发布于 2012-05-22 17:58:01
堆栈段信息通常在cstartup模块中初始化,最终调用main。链接器将合并链接中包含的模块的堆栈需求,这将反映在sp中的值cstartup位置中。堆栈段将是ds和es分组的一部分,除非您有多线程标志(当ss将分开时)。您还可以尝试在链接器命令文件中设置堆栈大小。
我建议您编写一个.asm模块,它在调用内核之前定义大型内存模型所需的段和组。很多尝试和错误,但您所了解的将适用于大多数环境的启动代码。
查看Watcom可以生成的(反汇编) .lst文件,您应该得到关于如何编写.asm模块的足够指导。
https://stackoverflow.com/questions/10656717
复制相似问题