Int 13h AH=42h hanging system

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.
Post Reply
nexos
Member
Member
Posts: 1081
Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos

Int 13h AH=42h hanging system

Post 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
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg
Octocontrabass
Member
Member
Posts: 5560
Joined: Mon Mar 25, 2013 7:01 pm

Re: Int 13h AH=42h hanging system

Post 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.
nexos
Member
Member
Posts: 1081
Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos

Re: Int 13h AH=42h hanging system

Post 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
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg
Octocontrabass
Member
Member
Posts: 5560
Joined: Mon Mar 25, 2013 7:01 pm

Re: Int 13h AH=42h hanging system

Post 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.
nexos
Member
Member
Posts: 1081
Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos

Re: Int 13h AH=42h hanging system

Post 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!
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg
Post Reply