Skip to content

Instantly share code, notes, and snippets.

@jtsiomb
Last active October 21, 2023 08:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtsiomb/ff4c13e353b568599cddbecaf403ecd3 to your computer and use it in GitHub Desktop.
Save jtsiomb/ff4c13e353b568599cddbecaf403ecd3 to your computer and use it in GitHub Desktop.
Bootable 16bit C program with gcc-ia16
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;
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); }
};
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