[Solved] Problem stage 2 not loading kernel again.
Posted: Thu Jul 02, 2020 11:12 am
Hi guys, need your expertise again. I've implemented a way to not ever have to modify my stage 1 and stage 2 boot loaders anymore, but I have a problem with stage 2 not wanting to load the kernel. All I added to stage 2 was a way to load the kernel no matter how big it gets. But for some unknown reason, it doesn't load it. Below is all it says, then it hangs the system.
NOTE: It doesn't report, "File not found!" error. So I don't know why it hangs.
Here is what it displays on stage 2..
That's all it displays then hangs. Maybe the problem is in the load_file subroutine, I might be doing something wrong there. But I don't understand it because, it loads stage 1 absolutely fine. Below is the code for stage 2 and disk.inc (contains load_file and read_disk).
stage2.asm
disk.inc
Thanks in advance to any and all help you provide. It is much appreciated. After this I shouldn't have to ask for more help on the boot loader stuff, because then it will automatically gather whats required to load from my very basic file table. I'll be continuing to make a basic kernel with I/O. If you need to see more code here is the project github.com - boot32-barebones.
- Phil
NOTE: It doesn't report, "File not found!" error. So I don't know why it hangs.
Here is what it displays on stage 2..
Code: Select all
A20 is enabled.
Loading kernel, please wait
stage2.asm
Code: Select all
; stage 2 boot loader.
; by Philip Simonson.
; =======================
[org 0x7e00]
[bits 16]
start:
mov [iBootDrive], dl
; set text mode (80x25)
mov ax, 0x0003
int 0x10
call reset_disk
call a20_bios
call check_a20
mov si, op_loading
call print
call load_file
; switch on protected mode
cli
lgdt [gdt.pointer]
mov eax, cr0
or eax, 1
mov cr0, eax
jmp dword 0x08:INIT_PM
%include "common.inc"
%include "disk.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 run_offset
hlt
%include "common32.inc"
; data
op_loading db "Loading kernel, please wait",0
op_done db "done!",10,13,0
op_a20yes db "A20 is enabled.",10,13,0
op_a20no db "A20 is disabled.",10,13,0
op_progress db 0x2e,0
op_ferror db 10,13,"File not found!",10,13,0
op_filename db "kernel bin",0
; constants
root_segment equ 0x0ee0
root_offset equ 0x0000
load_segment equ 0x1000
load_offset equ 0x0000
run_offset equ 0x00010000
%include "bs.inc"
Code: Select all
; simple BIOS disk services
; ======================================
; reset disk drive
; ======================================
reset_disk:
push ax
xor ax, ax
mov dl, [iBootDrive]
int 0x13
pop ax
ret
; ==================================================
; Description: Load a file from my file table.
; No parameters.
; ==================================================
load_file:
mov bx, root_segment
mov es, bx
mov bx, root_offset
.loop:
mov al, [bx]
cmp al, 0x0
je .error
mov cx, 11
mov di, bx
mov si, op_filename
rep cmpsb
je .found
add bx, 16
jmp short .loop
.found:
mov ax, word [es:bx+0x0c]
mov cx, word [es:bx+0x0e]
mov bx, load_segment
mov es, bx
mov bx, load_offset
call read_disk
ret
.error:
mov si, op_ferror
call print
ret
; ==================================================
; Description: Load file from disk using LBA.
; ax - LBA (Logical Block Address)
; cx - Number of sectors to read.
; [es:bx] - Location to store at (in memory).
; ==================================================
read_disk:
mov di, 5
.loop:
push ax
push cx
push bx
; calculate sector
mov bx, word [iTrackSect]
xor dx, dx
div bx
inc dx
mov cl, dl
; calculate track/head
mov bx, word [iHeadCnt]
xor dx, dx
div bx
mov ch, al
xchg dl, dh
; read sector
mov ax, 0x0201
mov dl, byte [iBootDrive]
pop bx
int 0x13
jnc .success
xor ax, ax
int 0x13
dec di
pop cx
pop ax
cmp di, 0
jne .loop
mov si, op_ferror
call print
jmp $
.success:
mov si, op_progress
call print
pop cx
pop ax
inc ax
add bx, word [iSectSize]
loop read_disk
mov si, op_done
call print
ret
- Phil