Skip to content

Instantly share code, notes, and snippets.

@unixzii
Created June 18, 2019 13:20
Show Gist options
  • Save unixzii/e2375421e760360c92615287cb31bb69 to your computer and use it in GitHub Desktop.
Save unixzii/e2375421e760360c92615287cb31bb69 to your computer and use it in GitHub Desktop.
A damn simple bootloader that prints "Hello, world!".
__asm__(
".code16gcc\n"
"jmpl $0, $main\n"
);
static const char * const msg = "Hello, world!";
void char_out(const char ch) {
__asm__(
"mov $0x0e, %%ah\n"
"mov %0, %%al\n"
"int $0x10\n"
: : "r"(ch) : "ax"
);
}
void main() {
const char *cur = msg;
for (;;) {
char ch = *(cur++);
if (!ch) break;
char_out(ch);
}
__asm__(
"hlt\n"
);
}
ENTRY(main);
SECTIONS
{
. = 0x7c00;
.text : AT(0x7c00)
{
*(.text);
}
.data :
{
*(.data);
*(.rodata*);
}
.magic : AT(0x7dfe)
{
SHORT(0xaa55);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment