Last active
October 21, 2023 08:46
-
-
Save jtsiomb/ff4c13e353b568599cddbecaf403ecd3 to your computer and use it in GitHub Desktop.
Bootable 16bit C program with gcc-ia16
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void _start(void) | |
{ | |
int i, j; | |
unsigned short __far *vmem = (void __far*)0xb8000000ul; | |
unsigned short c; | |
for(i=0; i<25; i++) { | |
c = ((i & 0xf) << 8) | '@'; | |
for(j=0; j<80; j++) { | |
*vmem++ = c; | |
} | |
} | |
for(;;); | |
} | |
unsigned short bootsig __attribute__((section(".bootsig"))) = 0xaa55; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
OUTPUT_FORMAT(binary) | |
ENTRY(_start) | |
SECTIONS { | |
. = 0x7c00; | |
.text : { | |
*(.text*); | |
} | |
.data : { | |
*(.rodata*); | |
*(.data*); | |
} | |
.bss ALIGN(4) (NOLOAD): { | |
_bss_start = .; | |
*(.bss*); | |
*(COMMON); | |
} | |
_bss_size = SIZEOF(.bss); | |
. = 0x7c00 + 510; | |
.bootsig : { *(.bootsig); } | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
bin = boot.img | |
CC = ia16-elf-gcc | |
LD = ia16-elf-ld | |
$(bin): boot.o | |
$(LD) -Tboot.ld -o $@ $^ | |
.PHONY: clean | |
clean: | |
rm -f boot.o $(bin) | |
.PHONY: run | |
run: $(bin) | |
qemu-system-i386 -hda $(bin) -serial file:serial.log | |
.PHONY: debug | |
debug: $(bin) | |
qemu-system-i386 -hda $(bin) -serial file:serial.log -s -S |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment