I know nobody is answering these questions but I'm posting this to help out beginners that are on the same place I am.
Anyway I finally got to load the second stage and got it to display a simple '>'. Here's the code for the first stage:
Code: Select all
;-------------[stage1.asm]-------------;
; Author: Ricardo Diaz ;
; Description: A simple first stage ;
; bootloader. ;
;--------------------------------------;
org 0x7C00 ; We were loded at 0x7C00
bits 16 ; We're in real mode
start:
call print_reset_attempt ; Print "Attempting to reset..."
.reset:
mov ah, 0x0 ; Reset drive function
int 0x13 ; BIOS 'Low level disk services' interrupt
jc .reset ; Try again if carry flag was set
call print_successful ; Print "Succeeded"
mov ax, 0x1000 ; We'll load the second stage at 0x1000
mov es, ax
xor bx, bx
call print_read_attempt ; Print "Attempting to read..."
.read:
mov ah, 0x02 ; Read sector function
mov al, 1 ; Read one sector
mov ch, 0 ; Read from track one
mov cl, 2 ; Read sector two
mov dh, 0 ; Read from head zero
int 0x13 ; BIOS 'Low level disk services' interrupt
jc .read ; Try again if carry flag was set
call print_successful ; Print "Succeeded"
jmp 0x1000:0x0 ; Jump to the second stage
;------------------------------;
; All prints go here. ;
;------------------------------;
print_successful:
push cs
pop ds
mov si, succeeded_msg
mov bh, 0x00
mov bl, 0x00
mov ah, 0x0E
.print_loop:
lodsb
cmp al, 0
je .print_done
int 0x10
jmp .print_loop
.print_done:
ret
print_reset_attempt:
push cs
pop ds
mov si, attempting_reset_msg
mov bh, 0x00
mov bl, 0x00
mov ah, 0x0E
.print_loop:
lodsb
cmp al, 0
je .print_done
int 0x10
jmp .print_loop
.print_done:
ret
print_read_attempt:
push cs
pop ds
mov si, attempting_read_msg
mov bh, 0x00
mov bl, 0x00
mov ah, 0x0E
.print_loop:
lodsb
cmp al, 0
je .print_done
int 0x10
jmp .print_loop
.print_done:
ret
;------------------------------;
; ;
;------------------------------;
succeeded_msg db "Succeeded!", 13, 10, 0
attempting_reset_msg db "Attempting to reset the drive...", 13, 10, 0
attempting_read_msg db "Attempting to read sector 2...", 13, 10, 0
times 510 - ($-$$) db 0 ; Fill up with zeros
dw 0xAA55 ; Boot signature
And here's the code for the second stage:
Code: Select all
org 0x1000
bits 16
start:
mov ah, 0x0E
mov al, 13
xor bx, bx
int 0x10
mov al, 10
int 0x10
mov al, 62
int 0x10
jmp $
The way I added the files to the image was like this:
cat stage1.bin stage2.bin > bootloader
Then:
dd if=bootloader of=bootable_image.iso
Everything worked fine. I don't even know if this is the right way to do this but it did load it and that's pretty much what I want.
BTW I'm using a mac.