Page 1 of 1

Int 13h AH=42h hanging system

Posted: Mon Nov 06, 2023 1:32 pm
by nexos
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

Re: Int 13h AH=42h hanging system

Posted: Mon Nov 06, 2023 2:46 pm
by Octocontrabass
nexos wrote:I suspected stack issues, but when trying any other drive in the system, things work fine.
You switch to real mode without loading an appropriate descriptor into SS, that can cause stack issues.

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

Posted: Mon Nov 06, 2023 3:09 pm
by nexos
I changed that section to look like this

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
and the problem still arises

Re: Int 13h AH=42h hanging system

Posted: Mon Nov 06, 2023 3:14 pm
by Octocontrabass
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

Posted: Mon Nov 06, 2023 3:31 pm
by nexos
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!