If you want to clone so you can test things, here is my github: boot32-barebones
UPDATE: Redone a few things and removed 'load_gdt' subroutine and now I have the debug and normal log files from bochs.
debug.log
normal.log
stage1.asm:
Code: Select all
; Stage 1 bootloader by Philip Simonson.
[org 0x7c00]
[bits 16]
[section .text]
global _start
_start:
jmp 0:main
nop
; put BPB here
main:
xor ax, ax
mov ds, ax
mov es, ax
mov ss, ax
mov sp, 0x7c00
cld
mov [iBootDrive], dl
call reset_disk
mov si, op_loading
call print
mov ax, 1
mov cl, 2
xor bx, bx
mov es, bx
mov bx, load_segment
call read_disk
jmp 0:load_segment
%include "common.inc"
%include "disk.inc"
op_loading db "Loading stage 2, please wait",0
op_ferror db 10,13,"Disk error!",13,10,0
op_fdone db "success!",13,10,0
op_progress db 0x2e,0
iBootDrive db 0
load_segment dw 0x07e0
; padding and magic number
times 510-($-$$) db 0
dw 0xaa55
Code: Select all
; stage 2 boot loader.
; by Philip Simonson.
; =======================
[org 0x7e00]
[bits 16]
start:
xor ax, ax
mov ds, ax
mov es, ax
call a20_bios
call check_a20
mov si, op_pmode
call print
; switch on protected mode
cli
lgdt [gdt.pointer]
mov eax, cr0
or eax, 1
mov cr0, eax
; hlt ; uncomment to test before jump instruction
jmp dword 0x08:INIT_PM
%include "common.inc"
%include "a20.inc"
%include "gdt.inc"
[bits 32]
INIT_PM:
mov ax, 0x10
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
mov ebp, 0x90000
mov esp, ebp
call BEGIN_PM
hlt
BEGIN_PM:
ret
op_pmode db "Entering protected mode...",0
op_pmode2 db "done!",13,10,0
op_a20yes db "A20 is enabled.",13,10,0
op_a20no db "A20 is disabled.",13,10,0
Code: Select all
; Global Descriptor Table
gdt:
.null: equ $-gdt
dd 0
dd 0
.code: equ $-gdt
dw 0xffff
dw 0
db 0
db 10011010b
db 11001111b
db 0
.data: equ $-gdt
dw 0xffff
dw 0
db 0
db 10010010b
db 11001111b
db 0
.pointer:
dw $-gdt-1
dd gdt