Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; first_stage.asm
- [org 0x7C00]
- SECOND_STAGE_ADDRESS equ 0x7E00 ; Just after the first stage
- ; Basic setup
- cli
- xor ax, ax
- mov ds, ax
- mov es, ax
- mov ss, ax
- mov sp, 0x7C00
- ; Print debug message: "F" for First stage
- mov ah, 0x0E
- mov al, 'F'
- int 0x10
- ; Print newline
- mov al, 0x0D
- int 0x10
- mov al, 0x0A
- int 0x10
- ; Save boot drive number
- mov [0x7C1E], dl
- ; Print debug message: "L" for Loading second stage
- mov ah, 0x0E
- mov al, 'L'
- int 0x10
- ; Load the second stage
- mov ah, 0x02 ; BIOS read function
- mov al, 2 ; Number of sectors to read
- mov ch, 0 ; Cylinder 0
- mov cl, 2 ; Sector 2 (1-indexed)
- mov dh, 0 ; Head 0
- mov dl, [0x7C1E] ; Drive number
- mov bx, SECOND_STAGE_ADDRESS ; Where to load the second stage
- int 0x13 ; BIOS interrupt to read sectors
- jc error ; If carry flag was set, there was an error
- ; Print debug message: "S" for Switching to second stage
- mov ah, 0x0E
- mov al, 'S'
- int 0x10
- ; Jump to second stage
- jmp SECOND_STAGE_ADDRESS
- error:
- ; Print E for error
- mov ah, 0x0E
- mov al, 'E'
- int 0x10
- jmp $
- BOOT_DRIVE db 0
- times 510-($-$$) db 0
- dw 0xAA55
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement