Hello,
I have started picking OSDev back up and ran into a very strange issue when testing my bootloader on real hardware. When booting my OS from a USB flash drive, the MBR / VBR load up the main protected mode bootloader just fine. However, when the bootloader attempts to read a sector from the boot drive, it hangs during int 13h. I suspected stack issues, but when trying any other drive in the system, things work fine. I also made this code be the only part of the bootloader ran to limit the potential amount of corruption issues, but the problem was still there. I suspect that it's probably some BIOS oddity of some sort. The PC I tested it on is a Dell Optiplex 780 from about 2008. I also tested it on a Dell Optiplex 380 from 2009, and that worked fine.
I suspect it could be something in the pmode BIOS layer. That file is at https://github.com/nexos-dev/nexnix/blo ... oscall.asm. The main entry point is at https://github.com/nexos-dev/nexnix/blo ... src/main.c
The repo with the code is at https://github.com/nexos-dev/nexnix.git
Int 13h AH=42h hanging system
-
- Member
- Posts: 5560
- Joined: Mon Mar 25, 2013 7:01 pm
Re: Int 13h AH=42h hanging system
You switch to real mode without loading an appropriate descriptor into SS, that can cause stack issues.nexos wrote:I suspected stack issues, but when trying any other drive in the system, things work fine.
Make sure you're following every step listed in the Intel and AMD manuals for switching to real mode.
Re: Int 13h AH=42h hanging system
I changed that section to look like this
and the problem still arises
Code: Select all
bits 16
.16bitpmode:
; Clear PE bit
mov eax, cr0
and eax, ~(1 << 0)
mov cr0, eax
mov ax, 0
mov ds, ax
mov es, ax
mov fs, ax
mov gs, ax
mov ss, ax
; And to real mode
jmp 0:.realmode
.realmode:
; Adjust interrupt number
pop ecx
mov [.int+1], cl
; Store output
pop ebp
; Store registers
pop es
pop ds
pop edi
pop esi
pop edx
pop ecx
pop ebx
pop eax
mov sp, BIOS_STACK_TOP
sti
-
- Member
- Posts: 5560
- Joined: Mon Mar 25, 2013 7:01 pm
Re: Int 13h AH=42h hanging system
That just introduces a bug by placing instructions between the MOV that clears CR0.PE and the JMP that sets CS. You still aren't loading appropriate descriptors into SS (or any segment register besides CS) before you switch to real mode.
Re: Int 13h AH=42h hanging system
My bad, I thought you meant load real mode selectors before far jumping. I loaded in the proper selectors and it now works. Thank you!