OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 10:28 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Int 13h AH=42h hanging system
PostPosted: Mon Nov 06, 2023 1:32 pm 
Offline
Member
Member

Joined: Tue Feb 18, 2020 3:29 pm
Posts: 1071
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/blob/dev/source/nexboot/fw/bios/cpu/i386/bioscall.asm. The main entry point is at https://github.com/nexos-dev/nexnix/blob/dev/source/nexboot/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


Top
 Profile  
 
 Post subject: Re: Int 13h AH=42h hanging system
PostPosted: Mon Nov 06, 2023 2:46 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
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.


Top
 Profile  
 
 Post subject: Re: Int 13h AH=42h hanging system
PostPosted: Mon Nov 06, 2023 3:09 pm 
Offline
Member
Member

Joined: Tue Feb 18, 2020 3:29 pm
Posts: 1071
I changed that section to look like this
Code:
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


Top
 Profile  
 
 Post subject: Re: Int 13h AH=42h hanging system
PostPosted: Mon Nov 06, 2023 3:14 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
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.


Top
 Profile  
 
 Post subject: Re: Int 13h AH=42h hanging system
PostPosted: Mon Nov 06, 2023 3:31 pm 
Offline
Member
Member

Joined: Tue Feb 18, 2020 3:29 pm
Posts: 1071
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


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot], Majestic-12 [Bot] and 52 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group