; TODO: Check which MBR partition is bootable and it's type cld ; clear the direction flag so that sto* and lod* increment di ; Test for EDD mov ah, 0x41 mov bx, 0x55AA ; boot signature word, why ? mov dl, 0x80 ; drive index (HDD 1) int 0x13 jc exit cmp bx, 0xAA55 jne exit ; Read sector 1 ; fill disk address packet (read 1 sector at offset 1) mov ax, 0 mov es, ax mov di, 0x200 mov ax, 16 ; size of packet stosb mov ax, 0 ; always 0 stosb mov ax, 1 ; number of sectors stosb mov ax, 0 ; always 0 stosb mov ax, 0x200 ; offset stosw mov ax, 0x7c0 ; segment stosw mov ax, 0x1 ; lower 4 bytes of LBA stosd mov ax, 0x0 ; upper 2 bytes of LBA stosd mov ax, 0 mov ds, ax mov si, 0x200 mov ah, 0x42 mov dl, 0x80 ; drive index (HDD 1) int 0x13 main_continuation: mov ax, 0xb800 ; protected mode video memory segment (seg / 16 + off) mov es, ax mov ax, 0x7c0 mov ds, ax mov si, 0x22b ; mov si, msg call print cli jmp hang ; print using BIOS functions ; print_loop: ; lodsb ; load byte from DS:SI into al ; or al, al ; jz hang ; mov ah, 0x0E ; int 0x10 ; jmp print_loop ; print without using BIOS functions print: lodsb cmp al, 0 jz exit_print mov ah, 0x0F mov cx, ax movzx bx, byte [xpos] shl bx, 1 movzx ax, byte [ypos] mov dx, 160 mul dx mov di, bx add di, ax mov ax, cx stosw add byte[xpos], 1 jmp print exit_print: add byte[ypos], 1 mov byte[xpos], 0 ret hang: jmp hang ; vars msg db 'Hello world', 13, 10, 0 ; Hello world CR LF \0 xpos db 0 ypos db 0 ; fill times 0x1b8 -($-$$) db 0 ; fill MBR boostrap dd 0 ; fill unique disk ID dw 0 ; reserved ; write first partition table entry CHS for start and end are set to 0 db 0x80 ; mark the partition as bootable db 0x0 ; partition start head dw 0x0 ; partition start sector and cylinder (sector = 1, cylinder = 0) db 0x06 ; system ID (partition type, 07 = exFAT) db 0x0 ; partition end head dw 0x0 ; partition end sector and cylinder (sector = 5, cylinder = 455) dd 0x1 ; partition start LBA dd 0x3fff ; partition end LBA times 0x10 db 0 ; fill second partition table entry times 0x10 db 0 ; fill third partition table entry times 0x10 db 0 ; fill fourth partition table entry dw 0xAA55 ; valid boot sector signature ; db 'TEST' ; times 0x800000 - ($-$$) db 0 exit: