[分享] How to build DOS COM files with GCC
之前意外看到的 gcc 特殊應用。
https://nullprogram.com/blog/2014/12/09/
"The most technically interesting part is that I didn’t need
any DOS development tools to create this!"
Compiler Options
Here are the essential compiler options.
-std=gnu99 -Os -nostdlib -m32 -march=i386 -ffreestanding
Linker Options
The -Wl option is used to pass arguments to the linker (ld).
We need it since we’re doing all this in one call to GCC.
-Wl,--nmagic,--script=com.ld
com.ld
OUTPUT_FORMAT(binary)
SECTIONS
{
. = 0x0100;
.text :
{
*(.text);
}
.data :
{
*(.data);
*(.bss);
*(.rodata);
}
_heap = ALIGN(4);
}
Program Startup
asm (".code16gcc\n"
"call dosmain\n"
"mov $0x4C, %ah\n"
"int $0x21\n");
static void print(char *string)
{
asm volatile ("mov $0x09, %%ah\n"
"int $0x21\n"
: /* no output */
: "d"(string)
: "ah");
}
int dosmain(void)
{
print("Hello, World!\n$");
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 114.45.139.241 (臺灣)
※ 文章網址: https://www.ptt.cc/bbs/CompilerDev/M.1603995735.A.91D.html
推
10/30 02:45,
5年前
, 1F
10/30 02:45, 1F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):