I actually made a bootloader with two stages because I set the video mode to 1920px*1080px by using the VESA BIOS extensions (which requires more than 512 bytes.).
Right now I'm trying to call my own kernel to begin plotting pixels etc.. but it didn't work.
I based my bootloader on Michael Petch's code from the answer to this question
bootloader.asm:
%include "stage2info.inc"
STAGE2_LOAD_SEG equ STAGE2_ABS_ADDR >> 4
STAGE2_LBA_START equ 1
STAGE2_LBA_END equ STAGE2_LBA_START + NUM_STAGE2_SECTORS
[BITS 16]
[ORG 0x7c00]
%include "BPB.inc"
%include "error.asm"
bootloader_main:
xor ax, ax
mov ds, ax
mov ss, ax
mov sp, 0x7c00
cld
load_stage2:
mov [bootDevice], dl
mov di, STAGE2_LOAD_SEG
mov si, STAGE2_LBA_START
jmp check_for_last_lba
read_sector:
call lba_to_chs
mov es, di
xor bx, bx
retry:
mov ax, 0201h
int 13h
jc disk_error
success:
add di, 512>>4
inc si
check_for_last_lba:
cmp si, STAGE2_LBA_END
jl read_sector
stage2_loaded:
mov ax, STAGE2_RUN_SEG
mov ds, ax
mov es, ax
jmp STAGE2_RUN_SEG:STAGE2_RUN_OFS
lba_to_chs:
push ax
mov ax, si
xor dx, dx
div word[sectorsPerTrack]
mov cl, dl
inc cl
xor dx, dx
div word[numHeads]
mov dh, dl
mov dl, [bootDevice]
mov ch, al
shl ah, 6
or cl, ah
pop ax
ret
bootDevice: db 0x00
times 510 - ($-$$) db 0
DW 0xAA55
NUM_STAGE2_SECTORS equ (stage2_end - stage2_start + 511) / 512
stage2_start:
incbin "stage2.bin"
stage2_end:
stage2.asm:
%include "stage2info.inc"
[BITS 16]
[ORG STAGE2_RUN_OFS]
start:
;graphics stuff here...
call load_kernel
cli
lgdt[gdt_descriptor]
mov eax, cr0
or eax, 1
mov cr0, eax
jmp 0x8:kernel_entry
[BITS 32]
kernel_entry:
mov ax, 0x10
mov ss, ax
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ebp, 0x90000
mov esp, ebp
call KERNEL_OFFSET
jmp $
[BITS 16]
load_kernel:
mov bx, KERNEL_OFFSET
mov dh, 15
mov dl, 0
mov ah, 0x02
mov al, dh
mov ch, 0x00
mov dh, 0x00
mov cl, 0x02
int 0x13
ret
GDT:
dq 0
dw 0xFFFFF
dw 0x0
db 0x0
db 10011010b
db 11001111b
db 0x0
dw 0xFFFFF
dw 0x0
db 0x0
db 10010010b
db 11001111b
db 0x0
gdt_descriptor :
dw $ - GDT - 1
dd GDT
incbin "../kernel/kernel.bin"
VESAInfo db 'VBE3'
times 508 db 0
MODEInfo times 256 db 0
ModeInfoBlock times 256 db 0
KERNEL_OFFSET equ 0x1000
%include "error.asm"
stage2info.asm:
STAGE2_ABS_ADDR equ 0x07e00
STAGE2_RUN_SEG equ 0x0000
STAGE2_RUN_OFS equ STAGE2_ABS_ADDR
kernel.asm:
[bits 32]
jmp $
And I build the image like the following:
#!/bin/bash
nasm -f bin stage2.asm -o stage2.bin
nasm -f bin ../kernel/kernel.asm -o ../kernel/kernel.bin
nasm -f bin bootloader.asm -o bootloader.bin
dd if=/dev/zero of=disk.img bs=512 count=2880
dd if=bootloader.bin of=disk.img conv=notrunc
qemu-system-i386 -fda disk.img -boot a
Any idea why it didn't work?