Code: Select all
.code16
.include "source/constants.S"
.global _start0
.global PRINT_STRING
.global HALT
.section .text
.global _start0
_start0:
ljmp $0, $L0 # Canonicalize (%CS):%IP.
L0:
xorw %ax, %ax
movw %ax, %ds # Load Segment Registers.
movw %ax, %es
movw %ax, %ss
movw %ax, %fs
movw %ax, %gs
movw $STACK_TOP, %sp # Prepare stack.
sti # Set interrupt flag.
movw $BOOT0SEQ_STR, %si
movb $0x07, %dh
call PRINT_STRING
INIT_ATTEMPT1:
movb $0, %ah # Reset drive controller.
int $0x13
jnc INIT_SUCCESS
INIT_ATTEMPT2:
movb $0, %ah # Try again.
int $0x13
jc FAILURE
INIT_SUCCESS:
cmpb $0x80, %dl # Check whether we boot from hard drive or floppy.
jl LBA_FAILURE_OR_FLOPPY
HARDDRIVE: # We boot from a hard-drive.
movb $0x41, %ah # Check whether we support Disk Address Packet.
movw $0x55AA, %bx
int $0x13
jc LBA_FAILURE_OR_FLOPPY
cmpw $0xAA55, %bx
jne LBA_FAILURE_OR_FLOPPY
test $1, %cx
jz LBA_FAILURE_OR_FLOPPY
LBA_SUCCESS: # We can read from a disk using Disk Address Packet.
movb $0x42, %ah
movw $DAP, %si # %ds is arleady set to zero.
int $0x13
jc FAILURE # Test whether read was successful.
jmp SUCCESS
LBA_FAILURE_OR_FLOPPY: # We boot from a floppy disk or the extension check failed.
FLOPPY_ATTEMPT1:
movw $0x0210, %ax
movw $0x0001, %cx
movb $0, %dh
movw $BOOT1_START, %bx # %es is arleady set to zero.
int $0x13
jnc FLOPPY_SUCCESS
FLOPPY_ATTEMPT2: # Try reading for a second time!
movw $0x0210, %ax
movw $0x0001, %cx
movw $BOOT1_START, %bx
int $0x13
jc FAILURE
FLOPPY_SUCCESS:
jmp SUCCESS
SUCCESS:
movw $BOOT0_SUCCESS_STR, %si
movb $0x0A, %dh # 0x0A -- Light Green.
call PRINT_STRING
jmp BOOT1_START
FAILURE: # Something went wrong!
movw $ERROR_MESSAGE, %si
movb $0x04, %dh # 0x04 -- Red.
call PRINT_STRING
jmp HALT
HALT:
cli
1: hlt
jmp 1b
PRINT_STRING: # PRINT_STRING(string : %si, color : %dh)
movb (%si), %al
inc %si
orb %al, %al
jz PRINT_RET
call PRINT_CHAR
jmp PRINT_STRING
PRINT_RET:
ret
PRINT_CHAR:
movb $0x0E, %ah
movb $0x00, %bh
movb %dh, %bl
int $0x10
ret
.balign 4
DAP: # Disk Adress Packet structure.
DAP_packet_size: .byte 0x10
DAP_zero: .byte 0x00
DAP_Nsectors: .word 0x01
DAP_buffer: .long BOOT1_START
DAP_lower_bits: .long 0x01
DAP_upper_bits: .long 0x00
.byte 0x00
BOOT0SEQ_STR: .asciz "[[ BootSeq0 ]]: "
BOOT0_SUCCESS_STR: .asciz "Succes!\n\r"
ERROR_MESSAGE: .asciz "Error: Could not find Boot1!\n\r"
.space 510 - (. - _start0)
.word 0xAA55 # Boot Signature.
Code: Select all
eax 0x4200 16896
ecx 0x7 7
edx 0x780 1920
ebx 0xaa55 43605
esp 0x9000 0x9000
ebp 0x0 0x0
esi 0x7c9c 31900
edi 0x0 0
eip 0x7c48 0x7c48
eflags 0x202 [ IOPL=0 IF ]
cs 0x0 0
ss 0x0 0
ds 0x0 0
es 0x0 0
fs 0x0 0
gs 0x0 0
