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" |