[Solved] Problem stage 2 not loading kernel again.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
psimonson1988
Member
Member
Posts: 40
Joined: Tue Jul 16, 2019 8:40 pm

[Solved] Problem stage 2 not loading kernel again.

Post by psimonson1988 »

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..

Code: Select all

A20 is enabled.
Loading kernel, please wait
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

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"
disk.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
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
Last edited by psimonson1988 on Fri Jul 03, 2020 12:18 pm, edited 1 time in total.
PeterX
Member
Member
Posts: 590
Joined: Fri Nov 22, 2019 5:46 am

Re: Problem stage 2 not loading kernel again.

Post by PeterX »

I can't find a bug that would be obvious to me. But I would suggest debugging in one form or another.
Like
- dumping out a '.' for each loaded sector
- putting a character on the video memory directly after entering pmode.
- dumping out register contents
- etc.
Or using a debugger.

Greetings
Peter
Octocontrabass
Member
Member
Posts: 5885
Joined: Mon Mar 25, 2013 7:01 pm

Re: Problem stage 2 not loading kernel again.

Post by Octocontrabass »

I've found the Bochs debugger to be quite useful for debugging bootloaders, especially with its magic breakpoint.

Is there any particular reason why you have to write your own bootloader instead of using an existing one like GRUB?
User avatar
iansjack
Member
Member
Posts: 4834
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Problem stage 2 not loading kernel again.

Post by iansjack »

Either using Bochs, or QEMU + gdb (my favourite), single-step through the code until you see where it's going wrong. You'll learn far more that way than waiting for someone to tell you the answer.
psimonson1988
Member
Member
Posts: 40
Joined: Tue Jul 16, 2019 8:40 pm

Re: Problem stage 2 not loading kernel again.

Post by psimonson1988 »

Octocontrabass wrote:I've found the Bochs debugger to be quite useful for debugging bootloaders, especially with its magic breakpoint.

Is there any particular reason why you have to write your own bootloader instead of using an existing one like GRUB?
How exactly do I debug a bootloader? Also to answer your question. It's good practice, and a great learning opportunity for getting as close to the baremetal as possible. There is also another reason for doing this project that is I want to give beginners a chance to look at good code rather than all those bad tutorials that I was following. That is why I writing this. Because when I get done with the code... I may start on making a good tutorial explaining all of this stuff so other people can understand it as well, it's incredibly fascinating.

By the way, thanks again for all help so far.
User avatar
iansjack
Member
Member
Posts: 4834
Joined: Sat Mar 31, 2012 3:07 am
Location: Chichester, UK

Re: Problem stage 2 not loading kernel again.

Post by iansjack »

psimonson1988 wrote:How exactly do I debug a bootloader?
The same way that you debug any other code. Set breakpoints, single-step through potentially buggy regions, examine variables, memory, and registers. Pay particular attention to the stack.
Octocontrabass
Member
Member
Posts: 5885
Joined: Mon Mar 25, 2013 7:01 pm

Re: Problem stage 2 not loading kernel again.

Post by Octocontrabass »

psimonson1988 wrote:How exactly do I debug a bootloader?
Using a debugger. :wink:

Personally, I'd set a breakpoint close to where I think things are going wrong, and step through it one instruction at a time to see where it stops working correctly. The Bochs magic breakpoint is especially useful for this since you don't have to figure out the correct address to set the breakpoint.
psimonson1988 wrote:Also to answer your question. It's good practice, and a great learning opportunity for getting as close to the baremetal as possible.
It certainly is good practice for debugging, but that's about it. The BIOS routines abstract the hardware away from you, so you're not all that close to bare metal. Real mode is significantly different both from the other modes and from other CPUs, so a lot of what you learn there won't be useful once you start writing your OS.
psimonson1988
Member
Member
Posts: 40
Joined: Tue Jul 16, 2019 8:40 pm

Re: Problem stage 2 not loading kernel again.

Post by psimonson1988 »

Okay I've debugged it for awhile now, and it keeps getting stuck inside the read_disk subroutine. In an infinite loop, can you help with that please? Not sure what I did wrong when making the read_disk function but something is way wrong for it to be doing that... below is the debug.log and normal.log files from bochs.

debug.log:

Code: Select all

Next at t=0
(0) [0x0000fffffff0] f000:fff0 (unk. ctxt): jmpf 0xf000:e05b          ; ea5be000f0
c
(0) Magic breakpoint
Next at t=15030884
(0) [0x000000007e1a] 0000:7e1a (unk. ctxt): call .+111 (0x00007e8c)   ; e86f00
s
Next at t=15030885
(0) [0x000000007e8c] 0000:7e8c (unk. ctxt): mov bx, 0x0ee0            ; bbe00e
s
Next at t=15030886
(0) [0x000000007e8f] 0000:7e8f (unk. ctxt): mov es, bx                ; 8ec3
s
Next at t=15030887
(0) [0x000000007e91] 0000:7e91 (unk. ctxt): mov bx, 0x0000            ; bb0000
s
Next at t=15030888
(0) [0x000000007e94] 0000:7e94 (unk. ctxt): mov al, byte ptr ds:[bx]  ; 8a07
s
Next at t=15030889
(0) [0x000000007e96] 0000:7e96 (unk. ctxt): cmp al, 0x00              ; 3c00
s
Next at t=15030890
(0) [0x000000007e98] 0000:7e98 (unk. ctxt): jz .+37 (0x00007ebf)      ; 7425
s
Next at t=15030891
(0) [0x000000007e9a] 0000:7e9a (unk. ctxt): mov cx, 0x000b            ; b90b00
s
Next at t=15030892
(0) [0x000000007e9d] 0000:7e9d (unk. ctxt): mov di, bx                ; 89df
s
Next at t=15030893
(0) [0x000000007e9f] 0000:7e9f (unk. ctxt): mov si, 0x8007            ; be0780
s
Next at t=15030894
(0) [0x000000007ea2] 0000:7ea2 (unk. ctxt): rep cmpsb byte ptr ds:[si], byte ptr es:[di] ; f3a6
s
Next at t=15030895
(0) [0x000000007ea4] 0000:7ea4 (unk. ctxt): jz .+5 (0x00007eab)       ; 7405
s
Next at t=15030896
(0) [0x000000007ea6] 0000:7ea6 (unk. ctxt): add bx, 0x0010            ; 83c310
s
Next at t=15030897
(0) [0x000000007ea9] 0000:7ea9 (unk. ctxt): jmp .-23 (0x00007e94)     ; ebe9
s
Next at t=15030898
(0) [0x000000007e94] 0000:7e94 (unk. ctxt): mov al, byte ptr ds:[bx]  ; 8a07
s
Next at t=15030899
(0) [0x000000007e96] 0000:7e96 (unk. ctxt): cmp al, 0x00              ; 3c00
s
Next at t=15030900
(0) [0x000000007e98] 0000:7e98 (unk. ctxt): jz .+37 (0x00007ebf)      ; 7425
s
Next at t=15030901
(0) [0x000000007e9a] 0000:7e9a (unk. ctxt): mov cx, 0x000b            ; b90b00
s
Next at t=15030902
(0) [0x000000007e9d] 0000:7e9d (unk. ctxt): mov di, bx                ; 89df
s
Next at t=15030903
(0) [0x000000007e9f] 0000:7e9f (unk. ctxt): mov si, 0x8007            ; be0780
s
Next at t=15030904
(0) [0x000000007ea2] 0000:7ea2 (unk. ctxt): rep cmpsb byte ptr ds:[si], byte ptr es:[di] ; f3a6
s
Next at t=15030905
(0) [0x000000007ea4] 0000:7ea4 (unk. ctxt): jz .+5 (0x00007eab)       ; 7405
s
Next at t=15030906
(0) [0x000000007ea6] 0000:7ea6 (unk. ctxt): add bx, 0x0010            ; 83c310
s
Next at t=15030907
(0) [0x000000007ea9] 0000:7ea9 (unk. ctxt): jmp .-23 (0x00007e94)     ; ebe9
s
Next at t=15030908
(0) [0x000000007e94] 0000:7e94 (unk. ctxt): mov al, byte ptr ds:[bx]  ; 8a07
s
Next at t=15030909
(0) [0x000000007e96] 0000:7e96 (unk. ctxt): cmp al, 0x00              ; 3c00
s
Next at t=15030910
(0) [0x000000007e98] 0000:7e98 (unk. ctxt): jz .+37 (0x00007ebf)      ; 7425
s
Next at t=15030911
(0) [0x000000007e9a] 0000:7e9a (unk. ctxt): mov cx, 0x000b            ; b90b00
s
Next at t=15030912
(0) [0x000000007e9d] 0000:7e9d (unk. ctxt): mov di, bx                ; 89df
s
Next at t=15030913
(0) [0x000000007e9f] 0000:7e9f (unk. ctxt): mov si, 0x8007            ; be0780
s
Next at t=15030914
(0) [0x000000007ea2] 0000:7ea2 (unk. ctxt): rep cmpsb byte ptr ds:[si], byte ptr es:[di] ; f3a6
s
Next at t=15030915
(0) [0x000000007ea2] 0000:7ea2 (unk. ctxt): rep cmpsb byte ptr ds:[si], byte ptr es:[di] ; f3a6
s
Next at t=15030916
(0) [0x000000007ea2] 0000:7ea2 (unk. ctxt): rep cmpsb byte ptr ds:[si], byte ptr es:[di] ; f3a6
s
Next at t=15030917
(0) [0x000000007ea2] 0000:7ea2 (unk. ctxt): rep cmpsb byte ptr ds:[si], byte ptr es:[di] ; f3a6
s
Next at t=15030918
(0) [0x000000007ea2] 0000:7ea2 (unk. ctxt): rep cmpsb byte ptr ds:[si], byte ptr es:[di] ; f3a6
s
Next at t=15030919
(0) [0x000000007ea2] 0000:7ea2 (unk. ctxt): rep cmpsb byte ptr ds:[si], byte ptr es:[di] ; f3a6
s
Next at t=15030920
(0) [0x000000007ea2] 0000:7ea2 (unk. ctxt): rep cmpsb byte ptr ds:[si], byte ptr es:[di] ; f3a6
s
Next at t=15030921
(0) [0x000000007ea2] 0000:7ea2 (unk. ctxt): rep cmpsb byte ptr ds:[si], byte ptr es:[di] ; f3a6
s
Next at t=15030922
(0) [0x000000007ea2] 0000:7ea2 (unk. ctxt): rep cmpsb byte ptr ds:[si], byte ptr es:[di] ; f3a6
s
Next at t=15030923
(0) [0x000000007ea2] 0000:7ea2 (unk. ctxt): rep cmpsb byte ptr ds:[si], byte ptr es:[di] ; f3a6
s
Next at t=15030924
(0) [0x000000007ea2] 0000:7ea2 (unk. ctxt): rep cmpsb byte ptr ds:[si], byte ptr es:[di] ; f3a6
s
Next at t=15030925
(0) [0x000000007ea4] 0000:7ea4 (unk. ctxt): jz .+5 (0x00007eab)       ; 7405
s
Next at t=15030926
(0) [0x000000007eab] 0000:7eab (unk. ctxt): mov ax, word ptr es:[bx+12] ; 268b470c
s
Next at t=15030927
(0) [0x000000007eaf] 0000:7eaf (unk. ctxt): mov cx, word ptr es:[bx+14] ; 268b4f0e
s
Next at t=15030928
(0) [0x000000007eb3] 0000:7eb3 (unk. ctxt): mov bx, 0x1000            ; bb0010
s
Next at t=15030929
(0) [0x000000007eb6] 0000:7eb6 (unk. ctxt): mov es, bx                ; 8ec3
ss
s
Next at t=15030930
(0) [0x000000007eb8] 0000:7eb8 (unk. ctxt): mov bx, 0x0000            ; bb0000
s
Next at t=15030931
(0) [0x000000007ebb] 0000:7ebb (unk. ctxt): call .+8 (0x00007ec6)     ; e80800
s
Next at t=15030932
(0) [0x000000007ec6] 0000:7ec6 (unk. ctxt): mov di, 0x0005            ; bf0500
s
Next at t=15030933
(0) [0x000000007ec9] 0000:7ec9 (unk. ctxt): push ax                   ; 50
s
Next at t=15030934
(0) [0x000000007eca] 0000:7eca (unk. ctxt): push cx                   ; 51
s
Next at t=15030935
(0) [0x000000007ecb] 0000:7ecb (unk. ctxt): push bx                   ; 53
s
Next at t=15030936
(0) [0x000000007ecc] 0000:7ecc (unk. ctxt): mov bx, word ptr ds:0x8028 ; 8b1e2880
s
Next at t=15030937
(0) [0x000000007ed0] 0000:7ed0 (unk. ctxt): xor dx, dx                ; 31d2
r
CPU0:
rax: 00000000_00000000
rbx: 00000000_00000000
rcx: 00000000_00090000
rdx: 00000000_00000100
rsp: 00000000_00007bf6
rbp: 00000000_00000000
rsi: 00000000_000e8012
rdi: 00000000_00000005
r8 : 00000000_00000000
r9 : 00000000_00000000
r10: 00000000_00000000
r11: 00000000_00000000
r12: 00000000_00000000
r13: 00000000_00000000
r14: 00000000_00000000
r15: 00000000_00000000
rip: 00000000_00007ed0
eflags 0x00000046: id vip vif ac vm rf nt IOPL=0 of df if tf sf ZF af PF cf
s
Next at t=15030938
(0) [0x000000007ed2] 0000:7ed2 (unk. ctxt): div ax, bx                ; f7f3
s
Next at t=15030939
(0) [0x0000000fff53] f000:ff53 (unk. ctxt): iret                      ; cf
s
Next at t=15030940
(0) [0x000000007ed2] 0000:7ed2 (unk. ctxt): div ax, bx                ; f7f3
s
Next at t=15030941
(0) [0x0000000fff53] f000:ff53 (unk. ctxt): iret                      ; cf
s
Next at t=15030942
(0) [0x000000007ed2] 0000:7ed2 (unk. ctxt): div ax, bx                ; f7f3
s
Next at t=15030943
(0) [0x0000000fff53] f000:ff53 (unk. ctxt): iret                      ; cf
s
Next at t=15030944
(0) [0x000000007ed2] 0000:7ed2 (unk. ctxt): div ax, bx                ; f7f3
s
Next at t=15030945
(0) [0x0000000fff53] f000:ff53 (unk. ctxt): iret                      ; cf
s
Next at t=15030946
(0) [0x000000007ed2] 0000:7ed2 (unk. ctxt): div ax, bx                ; f7f3
s
Next at t=15030947
(0) [0x0000000fff53] f000:ff53 (unk. ctxt): iret                      ; cf
ss
s
Next at t=15030948
(0) [0x000000007ed2] 0000:7ed2 (unk. ctxt): div ax, bx                ; f7f3
s
Next at t=15030949
(0) [0x0000000fff53] f000:ff53 (unk. ctxt): iret                      ; cf
s
Next at t=15030950
(0) [0x000000007ed2] 0000:7ed2 (unk. ctxt): div ax, bx                ; f7f3
s
Next at t=15030951
(0) [0x0000000fff53] f000:ff53 (unk. ctxt): iret                      ; cf
s
Next at t=15030952
(0) [0x000000007ed2] 0000:7ed2 (unk. ctxt): div ax, bx                ; f7f3
s
Next at t=15030953
(0) [0x0000000fff53] f000:ff53 (unk. ctxt): iret                      ; cf
s
Next at t=15030954
(0) [0x000000007ed2] 0000:7ed2 (unk. ctxt): div ax, bx                ; f7f3
s
Next at t=15030955
(0) [0x0000000fff53] f000:ff53 (unk. ctxt): iret                      ; cf
s
Next at t=15030956
(0) [0x000000007ed2] 0000:7ed2 (unk. ctxt): div ax, bx                ; f7f3
s
Next at t=15030957
(0) [0x0000000fff53] f000:ff53 (unk. ctxt): iret                      ; cf
ss
s
Next at t=15030958
(0) [0x000000007ed2] 0000:7ed2 (unk. ctxt): div ax, bx                ; f7f3
s
Next at t=15030959
(0) [0x0000000fff53] f000:ff53 (unk. ctxt): iret                      ; cf
q
(0).[15030959] [0x0000000fff53] f000:ff53 (unk. ctxt): iret                      ; cf
normal.log:

Code: Select all

00000000000i[      ] Bochs x86 Emulator 2.6.11
00000000000i[      ]   Built from SVN snapshot on January 5, 2020
00000000000i[      ]   Timestamp: Sun Jan  5 08:36:00 CET 2020
00000000000i[      ] System configuration
00000000000i[      ]   processors: 1 (cores=1, HT threads=1)
00000000000i[      ]   A20 line support: yes
00000000000i[      ] IPS is set to 4000000
00000000000i[      ] CPU configuration
00000000000i[      ]   SMP support: yes, quantum=16
00000000000i[      ]   level: 6
00000000000i[      ]   APIC support: xapic
00000000000i[      ]   FPU support: yes
00000000000i[      ]   MMX support: yes
00000000000i[      ]   3dnow! support: no
00000000000i[      ]   SEP support: yes
00000000000i[      ]   SIMD support: sse2
00000000000i[      ]   XSAVE support: no 
00000000000i[      ]   AES support: no
00000000000i[      ]   SHA support: no
00000000000i[      ]   MOVBE support: no
00000000000i[      ]   ADX support: no
00000000000i[      ]   x86-64 support: yes
00000000000i[      ]   1G paging support: no
00000000000i[      ]   MWAIT support: yes
00000000000i[      ]   VMX support: 1
00000000000i[      ]   SVM support: no
00000000000i[      ] Optimization configuration
00000000000i[      ]   RepeatSpeedups support: yes
00000000000i[      ]   Fast function calls: yes
00000000000i[      ]   Handlers Chaining speedups: no
00000000000i[      ] Devices configuration
00000000000i[      ]   PCI support: i440FX i430FX i440BX
00000000000i[      ]   Networking support: NE2000 E1000
00000000000i[      ]   Sound support: SB16 ES1370
00000000000i[      ]   USB support: UHCI OHCI EHCI xHCI
00000000000i[      ]   VGA extension support: vbe cirrus voodoo
00000000000i[MEM0  ] allocated memory at 0x7f4e5f97d010. after alignment, vector=0x7f4e5f97e000
00000000000i[MEM0  ] 32.00MB
00000000000i[MEM0  ] mem block size = 0x00020000, blocks=256
00000000000i[MEM0  ] rom at 0xfffe0000/131072 ('/usr/share/bochs/BIOS-bochs-latest')
00000000000i[      ] lt_dlhandle is 0x5631c50ce0b0
00000000000i[PLUGIN] loaded plugin libbx_hdimage.so
00000000000i[      ] lt_dlhandle is 0x5631c570ef90
00000000000i[PLUGIN] loaded plugin libbx_soundalsa.so
00000000000i[WAVOUT] ALSA: opened default PCM output device
00000000000i[WAVOUT] changed sample rate to 44101
00000000000i[      ] lt_dlhandle is 0x5631c57294e0
00000000000i[PLUGIN] loaded plugin libbx_pci.so
00000000000i[      ] lt_dlhandle is 0x5631c570fb30
00000000000i[PLUGIN] loaded plugin libbx_pci2isa.so
00000000000i[      ] lt_dlhandle is 0x5631c5737060
00000000000i[PLUGIN] loaded plugin libbx_usb_uhci.so
00000000000i[      ] lt_dlhandle is 0x5631c5739720
00000000000i[PLUGIN] loaded plugin libbx_acpi.so
00000000000i[      ] lt_dlhandle is 0x5631c5739f50
00000000000i[PLUGIN] loaded plugin libbx_hpet.so
00000000000i[      ] lt_dlhandle is 0x5631c573adc0
00000000000i[PLUGIN] loaded plugin libbx_cmos.so
00000000000i[      ] lt_dlhandle is 0x5631c573b720
00000000000i[PLUGIN] loaded plugin libbx_dma.so
00000000000i[      ] lt_dlhandle is 0x5631c573c170
00000000000i[PLUGIN] loaded plugin libbx_pic.so
00000000000i[      ] lt_dlhandle is 0x5631c573c9d0
00000000000i[PLUGIN] loaded plugin libbx_pit.so
00000000000i[      ] lt_dlhandle is 0x5631c573d3d0
00000000000i[PLUGIN] loaded plugin libbx_vga.so
00000000000i[      ] lt_dlhandle is 0x5631c573dc30
00000000000i[PLUGIN] loaded plugin libbx_floppy.so
00000000000i[      ] lt_dlhandle is 0x5631c573e7e0
00000000000i[PLUGIN] loaded plugin libbx_ioapic.so
00000000000i[      ] lt_dlhandle is 0x5631c573efe0
00000000000i[PLUGIN] loaded plugin libbx_keyboard.so
00000000000i[      ] lt_dlhandle is 0x5631c573f7b0
00000000000i[PLUGIN] loaded plugin libbx_harddrv.so
00000000000i[      ] lt_dlhandle is 0x5631c5741a10
00000000000i[PLUGIN] loaded plugin libbx_pci_ide.so
00000000000i[PLUGIN] init_dev of 'pci' plugin device by virtual method
00000000000i[DEV   ] i440FX PMC present at device 0, function 0
00000000000i[PLUGIN] init_dev of 'pci2isa' plugin device by virtual method
00000000000i[DEV   ] PIIX3 PCI-to-ISA bridge present at device 1, function 0
00000000000i[PLUGIN] init_dev of 'cmos' plugin device by virtual method
00000000000i[CMOS  ] Using local time for initial clock
00000000000i[CMOS  ] Setting initial clock to: Thu Jul  2 17:31:07 2020 (time0=1593725467)
00000000000i[PLUGIN] init_dev of 'dma' plugin device by virtual method
00000000000i[DMA   ] channel 4 used by cascade
00000000000i[PLUGIN] init_dev of 'pic' plugin device by virtual method
00000000000i[PLUGIN] init_dev of 'pit' plugin device by virtual method
00000000000i[PLUGIN] init_dev of 'vga' plugin device by virtual method
00000000000i[MEM0  ] Register memory access handlers: 0x0000000a0000 - 0x0000000bffff
00000000000i[VGA   ] interval=200000, mode=realtime
00000000000i[VGA   ] VSYNC using standard mode
00000000000i[MEM0  ] Register memory access handlers: 0x0000e0000000 - 0x0000e0ffffff
00000000000i[BXVGA ] VBE Bochs Display Extension Enabled
00000000000i[XGUI  ] test_alloc_colors: 16 colors available out of 16 colors tried
00000000000i[XGUI  ] font 8 wide x 16 high, display depth = 24
00000000000i[MEM0  ] rom at 0xc0000/41984 ('/usr/share/bochs/VGABIOS-lgpl-latest')
00000000000i[PLUGIN] init_dev of 'floppy' plugin device by virtual method
00000000000i[DMA   ] channel 2 used by Floppy Drive
00000000000i[FLOPPY] fd0: 'floppy.img' ro=1, h=2,t=80,spt=18
00000000000i[FLOPPY] Using boot sequence floppy, none, none
00000000000i[FLOPPY] Floppy boot signature check is enabled
00000000000i[PLUGIN] init_dev of 'acpi' plugin device by virtual method
00000000000i[DEV   ] ACPI Controller present at device 1, function 3
00000000000i[PLUGIN] init_dev of 'hpet' plugin device by virtual method
00000000000i[HPET  ] initializing HPET
00000000000i[MEM0  ] Register memory access handlers: 0x0000fed00000 - 0x0000fed003ff
00000000000i[PLUGIN] init_dev of 'ioapic' plugin device by virtual method
00000000000i[IOAPIC] initializing I/O APIC
00000000000i[MEM0  ] Register memory access handlers: 0x0000fec00000 - 0x0000fec00fff
00000000000i[IOAPIC] IOAPIC enabled (base address = 0xfec00000)
00000000000i[PLUGIN] init_dev of 'keyboard' plugin device by virtual method
00000000000i[KBD   ] will paste characters every 400 keyboard ticks
00000000000i[PLUGIN] init_dev of 'harddrv' plugin device by virtual method
00000000000i[PLUGIN] init_dev of 'pci_ide' plugin device by virtual method
00000000000i[DEV   ] PIIX3 PCI IDE controller present at device 1, function 1
00000000000i[PLUGIN] init_dev of 'unmapped' plugin device by virtual method
00000000000i[PLUGIN] init_dev of 'biosdev' plugin device by virtual method
00000000000i[PLUGIN] init_dev of 'speaker' plugin device by virtual method
00000000000i[PCSPK ] Using lowlevel sound support for output
00000000000i[PLUGIN] init_dev of 'extfpuirq' plugin device by virtual method
00000000000i[PLUGIN] init_dev of 'parallel' plugin device by virtual method
00000000000i[PAR   ] parallel port 1 at 0x0378 irq 7
00000000000i[PLUGIN] init_dev of 'serial' plugin device by virtual method
00000000000i[SER   ] com1 at 0x03f8 irq 4 (mode: null)
00000000000i[PLUGIN] init_dev of 'gameport' plugin device by virtual method
00000000000i[PLUGIN] init_dev of 'iodebug' plugin device by virtual method
00000000000i[PLUGIN] init_dev of 'usb_uhci' plugin device by virtual method
00000000000i[DEV   ] USB UHCI present at device 1, function 2
00000000000i[UHCI  ] USB UHCI initialized
00000000000i[PLUGIN] register state of 'pci' plugin device by virtual method
00000000000i[PLUGIN] register state of 'pci2isa' plugin device by virtual method
00000000000i[PLUGIN] register state of 'cmos' plugin device by virtual method
00000000000i[PLUGIN] register state of 'dma' plugin device by virtual method
00000000000i[PLUGIN] register state of 'pic' plugin device by virtual method
00000000000i[PLUGIN] register state of 'pit' plugin device by virtual method
00000000000i[PLUGIN] register state of 'vga' plugin device by virtual method
00000000000i[PLUGIN] register state of 'floppy' plugin device by virtual method
00000000000i[PLUGIN] register state of 'unmapped' plugin device by virtual method
00000000000i[PLUGIN] register state of 'biosdev' plugin device by virtual method
00000000000i[PLUGIN] register state of 'speaker' plugin device by virtual method
00000000000i[PLUGIN] register state of 'extfpuirq' plugin device by virtual method
00000000000i[PLUGIN] register state of 'parallel' plugin device by virtual method
00000000000i[PLUGIN] register state of 'serial' plugin device by virtual method
00000000000i[PLUGIN] register state of 'gameport' plugin device by virtual method
00000000000i[PLUGIN] register state of 'iodebug' plugin device by virtual method
00000000000i[PLUGIN] register state of 'usb_uhci' plugin device by virtual method
00000000000i[PLUGIN] register state of 'acpi' plugin device by virtual method
00000000000i[PLUGIN] register state of 'hpet' plugin device by virtual method
00000000000i[PLUGIN] register state of 'ioapic' plugin device by virtual method
00000000000i[PLUGIN] register state of 'keyboard' plugin device by virtual method
00000000000i[PLUGIN] register state of 'harddrv' plugin device by virtual method
00000000000i[PLUGIN] register state of 'pci_ide' plugin device by virtual method
00000000000i[SYS   ] bx_pc_system_c::Reset(HARDWARE) called
00000000000i[CPU0  ] cpu hardware reset
00000000000i[APIC0 ] allocate APIC id=0 (MMIO enabled) to 0x0000fee00000
00000000000i[CPU0  ] CPU[0] is the bootstrap processor
00000000000i[CPU0  ] CPUID[0x00000000]: 00000005 756e6547 6c65746e 49656e69
00000000000i[CPU0  ] CPUID[0x00000001]: 00000633 00010800 00002028 1fcbfbff
00000000000i[CPU0  ] CPUID[0x00000002]: 00410601 00000000 00000000 00000000
00000000000i[CPU0  ] CPUID[0x00000003]: 00000000 00000000 00000000 00000000
00000000000i[CPU0  ] CPUID[0x00000004]: 00000000 00000000 00000000 00000000
00000000000i[CPU0  ] CPUID[0x00000005]: 00000040 00000040 00000003 00000020
00000000000i[CPU0  ] CPUID[0x80000000]: 80000008 00000000 00000000 00000000
00000000000i[CPU0  ] CPUID[0x80000001]: 00000000 00000000 00000101 2a100000
00000000000i[CPU0  ] CPUID[0x80000002]: 20202020 20202020 20202020 6e492020
00000000000i[CPU0  ] CPUID[0x80000003]: 286c6574 50202952 69746e65 52286d75
00000000000i[CPU0  ] CPUID[0x80000004]: 20342029 20555043 20202020 00202020
00000000000i[CPU0  ] CPUID[0x80000005]: 01ff01ff 01ff01ff 40020140 40020140
00000000000i[CPU0  ] CPUID[0x80000006]: 00000000 42004200 02008140 00000000
00000000000i[CPU0  ] CPUID[0x80000007]: 00000000 00000000 00000000 00000000
00000000000i[CPU0  ] CPUID[0x80000008]: 00003028 00000000 00000000 00000000
00000000000i[CPU0  ] CPU Features supported:
00000000000i[CPU0  ] 		x87
00000000000i[CPU0  ] 		486ni
00000000000i[CPU0  ] 		pentium_ni
00000000000i[CPU0  ] 		p6ni
00000000000i[CPU0  ] 		mmx
00000000000i[CPU0  ] 		debugext
00000000000i[CPU0  ] 		vme
00000000000i[CPU0  ] 		pse
00000000000i[CPU0  ] 		pae
00000000000i[CPU0  ] 		pge
00000000000i[CPU0  ] 		pse36
00000000000i[CPU0  ] 		mtrr
00000000000i[CPU0  ] 		pat
00000000000i[CPU0  ] 		sysenter_sysexit
00000000000i[CPU0  ] 		clflush
00000000000i[CPU0  ] 		sse
00000000000i[CPU0  ] 		sse2
00000000000i[CPU0  ] 		mwait
00000000000i[CPU0  ] 		vmx
00000000000i[CPU0  ] 		longmode
00000000000i[CPU0  ] 		lm_lahf_sahf
00000000000i[CPU0  ] 		nx
00000000000i[CPU0  ] 		cmpxhg16b
00000000000i[CPU0  ] 		rdtscp
00000000000i[CPU0  ] 		ffxsr
00000000000i[CPU0  ] 		xapic
00000000000i[PLUGIN] reset of 'pci' plugin device by virtual method
00000000000i[PLUGIN] reset of 'pci2isa' plugin device by virtual method
00000000000i[PLUGIN] reset of 'cmos' plugin device by virtual method
00000000000i[PLUGIN] reset of 'dma' plugin device by virtual method
00000000000i[PLUGIN] reset of 'pic' plugin device by virtual method
00000000000i[PLUGIN] reset of 'pit' plugin device by virtual method
00000000000i[PLUGIN] reset of 'vga' plugin device by virtual method
00000000000i[PLUGIN] reset of 'floppy' plugin device by virtual method
00000000000i[PLUGIN] reset of 'acpi' plugin device by virtual method
00000000000i[PLUGIN] reset of 'hpet' plugin device by virtual method
00000000000i[PLUGIN] reset of 'ioapic' plugin device by virtual method
00000000000i[PLUGIN] reset of 'keyboard' plugin device by virtual method
00000000000i[PLUGIN] reset of 'harddrv' plugin device by virtual method
00000000000i[PLUGIN] reset of 'pci_ide' plugin device by virtual method
00000000000i[PLUGIN] reset of 'unmapped' plugin device by virtual method
00000000000i[PLUGIN] reset of 'biosdev' plugin device by virtual method
00000000000i[PLUGIN] reset of 'speaker' plugin device by virtual method
00000000000i[PLUGIN] reset of 'extfpuirq' plugin device by virtual method
00000000000i[PLUGIN] reset of 'parallel' plugin device by virtual method
00000000000i[PLUGIN] reset of 'serial' plugin device by virtual method
00000000000i[PLUGIN] reset of 'gameport' plugin device by virtual method
00000000000i[PLUGIN] reset of 'iodebug' plugin device by virtual method
00000000000i[PLUGIN] reset of 'usb_uhci' plugin device by virtual method
00000000000i[      ] Using debugger log file debug.log
00000000000i[      ] set SIGINT handler to bx_debug_ctrlc_handler
00000004662i[BIOS  ] $Revision: 13752 $ $Date: 2019-12-30 14:16:18 +0100 (Mon, 30 Dec 2019) $
00000318050i[KBD   ] reset-disable command received
00000320814i[BIOS  ] Starting rombios32
00000321255i[BIOS  ] Shutdown flag 0
00000321887i[BIOS  ] ram_size=0x02000000
00000322330i[BIOS  ] ram_end=32MB
00000362973i[BIOS  ] Found 1 cpu(s)
00000376661i[BIOS  ] bios_table_addr: 0x000f9db8 end=0x000fcc00
00000607040i[XGUI  ] charmap update. Font is 9 x 16
00000835579i[PCI   ] i440FX PMC write to PAM register 59 (TLB Flush)
00001294600i[P2ISA ] PCI IRQ routing: PIRQA# set to 0x0b
00001294625i[P2ISA ] PCI IRQ routing: PIRQB# set to 0x09
00001294650i[P2ISA ] PCI IRQ routing: PIRQC# set to 0x0b
00001294675i[P2ISA ] PCI IRQ routing: PIRQD# set to 0x09
00001294685i[P2ISA ] write: ELCR2 = 0x0a
00001295461i[BIOS  ] PIIX3/PIIX4 init: elcr=00 0a
00001309200i[BIOS  ] PCI: bus=0 devfn=0x00: vendor_id=0x8086 device_id=0x1237 class=0x0600
00001311527i[BIOS  ] PCI: bus=0 devfn=0x08: vendor_id=0x8086 device_id=0x7000 class=0x0601
00001313693i[BIOS  ] PCI: bus=0 devfn=0x09: vendor_id=0x8086 device_id=0x7010 class=0x0101
00001313934i[PIDE  ] BAR #4: i/o base address = 0xc000
00001314588i[BIOS  ] region 4: 0x0000c000
00001316654i[BIOS  ] PCI: bus=0 devfn=0x0a: vendor_id=0x8086 device_id=0x7020 class=0x0c03
00001316870i[UHCI  ] BAR #4: i/o base address = 0xc020
00001317524i[BIOS  ] region 4: 0x0000c020
00001317663i[UHCI  ] new IRQ line = 9
00001319608i[BIOS  ] PCI: bus=0 devfn=0x0b: vendor_id=0x8086 device_id=0x7113 class=0x0680
00001319847i[ACPI  ] new IRQ line = 11
00001319868i[ACPI  ] new IRQ line = 9
00001319902i[ACPI  ] new PM base address: 0xb000
00001319916i[ACPI  ] new SM base address: 0xb100
00001319943i[PCI   ] setting SMRAM control register to 0x4a
00001549619i[CPU0  ] Enter to System Management Mode
00001549619i[CPU0  ] enter_system_management_mode: temporary disable VMX while in SMM mode
00001549629i[CPU0  ] RSM: Resuming from System Management Mode
00001779224i[PCI   ] setting SMRAM control register to 0x0a
00001805958i[BIOS  ] MP table addr=0x000f9e90 MPC table addr=0x000f9dc0 size=0xc8
00001807816i[BIOS  ] SMBIOS table addr=0x000f9ea0
00001809934i[BIOS  ] ACPI tables: RSDP addr=0x000f9fd0 ACPI DATA addr=0x01ff0000 size=0xff8
00001813200i[BIOS  ] Firmware waking vector 0x1ff00cc
00001815631i[PCI   ] i440FX PMC write to PAM register 59 (TLB Flush)
00001816358i[BIOS  ] bios_table_cur_addr: 0x000f9ff4
00001945232i[VBIOS ] VGABios $Id: vgabios.c 226 2020-01-02 21:36:23Z vruppert $
00001945303i[BXVGA ] VBE known Display Interface b0c0
00001945335i[BXVGA ] VBE known Display Interface b0c5
00001947978i[VBIOS ] VBE Bios $Id: vbe.c 228 2020-01-02 23:09:02Z vruppert $
00002762420i[XGUI  ] charmap update. Font is 9 x 16
00014479588i[BIOS  ] Booting from 0000:7c00
00015030884i[CPU0  ] [15030884] Stopped on MAGIC BREAKPOINT
00015030884i[XGUI  ] charmap update. Font is 9 x 16
00015030959i[      ] dbg: Quit
00015030959i[CPU0  ] CPU is in real mode (active)
00015030959i[CPU0  ] CS.mode = 16 bit
00015030959i[CPU0  ] SS.mode = 16 bit
00015030959i[CPU0  ] EFER   = 0x00000000
00015030959i[CPU0  ] | EAX=00000000  EBX=00000000  ECX=00090000  EDX=00000000
00015030959i[CPU0  ] | ESP=00007bf0  EBP=00000000  ESI=000e8012  EDI=00000005
00015030959i[CPU0  ] | IOPL=0 id vip vif ac vm rf nt of df if tf sf ZF af PF cf
00015030959i[CPU0  ] | SEG sltr(index|ti|rpl)     base    limit G D
00015030959i[CPU0  ] |  CS:f000( 0004| 0|  0) 000f0000 0000ffff 0 0
00015030959i[CPU0  ] |  DS:0000( 0005| 0|  0) 00000000 0000ffff 0 0
00015030959i[CPU0  ] |  SS:0000( 0005| 0|  0) 00000000 0000ffff 0 0
00015030959i[CPU0  ] |  ES:1000( 0005| 0|  0) 00010000 0000ffff 0 0
00015030959i[CPU0  ] |  FS:0000( 0005| 0|  0) 00000000 0000ffff 0 0
00015030959i[CPU0  ] |  GS:0000( 0005| 0|  0) 00000000 0000ffff 0 0
00015030959i[CPU0  ] | EIP=0000ff53 (00007ed2)
00015030959i[CPU0  ] | CR0=0x60000010 CR2=0x00000000
00015030959i[CPU0  ] | CR3=0x00000000 CR4=0x00000000
00015030959i[CMOS  ] Last time is 1593725470 (Thu Jul  2 17:31:10 2020)
00015030959i[XGUI  ] Exit
00015030959i[SIM   ] quit_sim called with exit code 0
Thanks,
Phil
Octocontrabass
Member
Member
Posts: 5885
Joined: Mon Mar 25, 2013 7:01 pm

Re: Problem stage 2 not loading kernel again.

Post by Octocontrabass »

psimonson1988 wrote:

Code: Select all

r
CPU0:
rax: 00000000_00000000
rbx: 00000000_00000000
rcx: 00000000_00090000
rdx: 00000000_00000100
rsp: 00000000_00007bf6
rbp: 00000000_00000000
rsi: 00000000_000e8012
rdi: 00000000_00000005
r8 : 00000000_00000000
r9 : 00000000_00000000
r10: 00000000_00000000
r11: 00000000_00000000
r12: 00000000_00000000
r13: 00000000_00000000
r14: 00000000_00000000
r15: 00000000_00000000
rip: 00000000_00007ed0
eflags 0x00000046: id vip vif ac vm rf nt IOPL=0 of df if tf sf ZF af PF cf
s
Next at t=15030938
(0) [0x000000007ed2] 0000:7ed2 (unk. ctxt): div ax, bx                ; f7f3
Did you notice that you're dividing by zero? Perhaps BX should not be zero, and you should try to figure out where it's getting that value.
psimonson1988
Member
Member
Posts: 40
Joined: Tue Jul 16, 2019 8:40 pm

Re: Problem stage 2 not loading kernel again.

Post by psimonson1988 »

I'm sorry to ask such a thing, because I want to figure it out with debugging. But I've been trying for awhile now and I cannot seem to figure out where this division by zero actually takes place. I'm at a loss on debugging real mode, because I've never had to debug a bootloader before. Please help, I don't even know how I feel about this. I though that'd it would be fun and exciting in learning how to go into protected mode with a custom two-stage bootloader. But if one of you could look at it and maybe point me in the right direction. It'd be much appreciated. I cannot figure this out on my own, I don't know enough about mixing 16 and 32 bit code apparently. To tell you the truth I just want it to work again with my file table system, so I never have to rewrite my bootloader ever again.

What is causing it to divide by zero and where is it happening? Because I have no clue it's executing code I didn't even write that is in the BIOS data area or something.

- Phil
Octocontrabass
Member
Member
Posts: 5885
Joined: Mon Mar 25, 2013 7:01 pm

Re: Problem stage 2 not loading kernel again.

Post by Octocontrabass »

Code: Select all

(0) [0x000000007ed2] 0000:7ed2 (unk. ctxt): div ax, bx                ; f7f3
This is the instruction where you're dividing by zero. (As evidenced by the register dump you provided, where BX is zero.) The address of this instruction is 0000:7ED2, somewhere in your stage 2.

The DIV instruction shows up twice in your stage 2, but it's pretty easy to figure out which one this is by the instructions that execute just before it.

Code: Select all

s
Next at t=15030932
(0) [0x000000007ec6] 0000:7ec6 (unk. ctxt): mov di, 0x0005            ; bf0500
s
Next at t=15030933
(0) [0x000000007ec9] 0000:7ec9 (unk. ctxt): push ax                   ; 50
s
Next at t=15030934
(0) [0x000000007eca] 0000:7eca (unk. ctxt): push cx                   ; 51
s
Next at t=15030935
(0) [0x000000007ecb] 0000:7ecb (unk. ctxt): push bx                   ; 53
s
Next at t=15030936
(0) [0x000000007ecc] 0000:7ecc (unk. ctxt): mov bx, word ptr ds:0x8028 ; 8b1e2880
s
Next at t=15030937
(0) [0x000000007ed0] 0000:7ed0 (unk. ctxt): xor dx, dx                ; 31d2

Code: Select all

read_disk:
	mov di, 5
.loop:
	push ax
	push cx
	push bx
	; calculate sector
	mov bx, word [iTrackSect]
	xor dx, dx
	div bx
Lines up pretty nicely, right? And from this, we can see the label iTrackSect has been translated to 0x8028 by the assembler. So, where is that label defined? Does the address 0x8028 make sense based on how you've defined it? Where is the data at that address coming from?
psimonson1988
Member
Member
Posts: 40
Joined: Tue Jul 16, 2019 8:40 pm

Re: Problem stage 2 not loading kernel again.

Post by psimonson1988 »

Okay it is in bs.inc (where the bootsector definition is). But it is defined in stage2.asm I'm almost certain. At the very bottom of the assembly code.

stage2.asm:

Code: Select all

; stage 2 boot loader.
; by Philip Simonson.
; =======================

[org 0x7e00]
[bits 16]

start:
	mov [iBootDrive], dl
	call reset_disk

	; set text mode (80x25)
	mov ax, 0x0003
	int 0x10

	call a20_bios
	call check_a20

	mov si, op_loading
	call print
	call load_file
	mov bx, load_segment
	mov es, bx
	xor bx, bx
	call read_disk

	; 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"

[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
load_segment equ 0x1000
run_offset equ 0x00010000

%include "gdt.inc"
%include "bs.inc"
bs.inc:

Code: Select all

bootsector:
	iOEM:			db	"PhilOS  "		; OEM String
	iSectSize:		dw	0x200			; Bytes per sector
	iClustSize:		db	1				; Sectors per cluster
	iResSect:		dw	1				; Number of reserved sectors
	iFatCnt:		db	1				; Number of FAT count
	iRootSize:		dw	224				; Size of root directory
	iTotalSect:		dw	2880			; Total number of sectors
	iMedia:			db	0xf0			; Media descriptor
	iFatSize:		dw	7				; Size of each FAT
	iTrackSect:		dw	9				; Sectors per track
	iHeadCnt:		dw	2				; Number of heads
	iHiddenSect:	dd	0				; Number of hidden sectors
	iSect32:		dd	0				; Number of sectors over 32MB
	iBootDrive:		db	0				; Holds the boot drive
	iReserved:		db	0				; Reserved, empty
	iBootSign:		db	0x29			; Extended boot signature
	iVolID:			dw	0xface			; Disk serial number
	acVolumeLabel:	db	"PRS-FLOPPY "	; Volume label
	acFSType:		db	"PRSFS   "		; File system type
Octocontrabass
Member
Member
Posts: 5885
Joined: Mon Mar 25, 2013 7:01 pm

Re: Problem stage 2 not loading kernel again.

Post by Octocontrabass »

Seems a bit odd to have a second copy of the BPB in your stage 2. Did you perhaps want the pointer to refer to the boot sector that's already in memory as part of stage 1?

And did you check to make sure stage 1 is loading all of stage 2?
psimonson1988
Member
Member
Posts: 40
Joined: Tue Jul 16, 2019 8:40 pm

Re: Problem stage 2 not loading kernel again.

Post by psimonson1988 »

Yeah the pointer to it would be nice how do I do that?
Octocontrabass wrote:And did you check to make sure stage 1 is loading all of stage 2?
Yes, it should be it's getting the starting LBA and total sectors from my make-shift file table system that I named "prsfs".
Octocontrabass
Member
Member
Posts: 5885
Joined: Mon Mar 25, 2013 7:01 pm

Re: Problem stage 2 not loading kernel again.

Post by Octocontrabass »

psimonson1988 wrote:Yeah the pointer to it would be nice how do I do that?
I can think of a couple ways to accomplish it, but I think the most convenient is to define a structure data type with the appropriate base offset. Note that this only defines the structure and not the data contained in the structure; you still need to have a separate definition of the data to use in stage 1. (However, both stages may use the structure if you like.)

Code: Select all

struc bootsector, 0x7c03

iOEM: resb 8
...

endstruc
Something like this, perhaps?
psimonson1988 wrote:it should be
If you're not sure, then check! Use the debugger to examine the contents of memory after stage 2 is loaded and see if all of the data is in memory where it should be.
Post Reply