Skip to content

Instantly share code, notes, and snippets.

@gofer
Last active May 9, 2017 19:18
Show Gist options
  • Save gofer/d5a8b47b6b8a9946ad36cd039754d766 to your computer and use it in GitHub Desktop.
Save gofer/d5a8b47b6b8a9946ad36cd039754d766 to your computer and use it in GitHub Desktop.
BIOS hello world

How to build?

as -32 -o ./main.o ./main.s
ld -m elf_i386 -T ld.script -o ./a.out ./main.o
objcopy -j .text -j .data -O binary ./a.out ./boot.text.bin
SECTIONS
{
. = 0x00007C00;
.text : {
_text_start = .;
*(.text)
_text_end = .;
}
.data : {
_rodata_start = .;
*(.rodata)
_rodata_end = .;
_data_start = .;
*(.data)
_data_end = .;
}
}
.file "main.s"
.text
.code16
.globl _start
_start:
cli
cld
xor %ax, %ax
movw %ax, %ss
movw $_start + 0x400, %bp
movw %bp, %sp
movw %ax, %ds
movw %ax, %es
_main:
movb $0x00, %ah
movb $0x12, %al
int $0x10
movb $0x02, %ah
movb $0x00, %bh
movb $0x00, %dh
movb $0x00, %dl
int $0x10
movb $0x61, %al
call _putc
movb $0x62, %al
call _putc
movb $0x63, %al
call _putc
movb $0x0a, %al
call _putc
movb $0x0d, %al
call _putc
mov $_mesg, %si
call _puts
_finish:
hlt
jmp _finish
_puts:
pushw %bp
movw %sp, %bp
_puts.func:
lodsb
testb %al, %al
jz _puts.finish
call _putc
jmp _puts.func
_puts.finish:
leave
ret
_putc:
pushw %bp
movw %sp, %bp
movb $0x0e, %ah
movb $0x00, %bh
movb $0xd7, %bl
int $0x10
leave
ret
.section .rodata
_mesg:
.asciz "Hello, world.\r\n"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment