BIOS fnc. interrupts corrupted in real mode after a far jump

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
User avatar
Ycep
Member
Member
Posts: 401
Joined: Mon Dec 28, 2015 11:11 am

BIOS fnc. interrupts corrupted in real mode after a far jump

Post by Ycep »

Hello,
as I have mentioned in another post somewhere here on this forum I have started again, actually this time.

Back on the problem I have debugged the OS using bochsdbg just before INT 0x10 execution,
all conditions are just like they are supposed to,
but interrupt never executes, it gets stuck in some SLDT loop, which I assume it's some memory corruption.
It works perfectly fine in 0:0x7C00 (bootloader) but not in 0:0x8000, after a far jump to that address.
It's either aforementioned memory corruption or some segment mis-setup, I don't know...
What do you think? Anyone?
I have added a zipped attachment containing this code.
Attachments
death.zip
(6.94 KiB) Downloaded 65 times
Octocontrabass
Member
Member
Posts: 5586
Joined: Mon Mar 25, 2013 7:01 pm

Re: BIOS fnc. interrupts corrupted in real mode after a far

Post by Octocontrabass »

Why all the segment register manipulation? Set all of the segments to 0 and use proper org statements: "org 0x7c00" for stage one and "org 0x8000" for stage two.

Why RETF instead of JMPF? You're wasting space if the destination address is a constant.

Your ReadSectors routine would be easier to understand if you made proper use of BP-relative addressing to access parameters on the stack. Use "RET 4" to clean up the 4 bytes of parameters you pass to the function, instead of manipulating the stack directly. (You may also find the ENTER and LEAVE instructions useful, although it's usually better to use "PUSH BP; MOV BP, SP" instead of ENTER to save a byte.)

What is the address of the last instruction that executes correctly? What is the address of the first instruction that executes incorrectly? Knowing exactly where things go wrong might help us narrow down the problem.
User avatar
Ycep
Member
Member
Posts: 401
Joined: Mon Dec 28, 2015 11:11 am

Re: BIOS fnc. interrupts corrupted in real mode after a far

Post by Ycep »

Damn, removing all these segment related stuff cleaned my code that much that it does not even look like I wrote it :)
And not only that, it fixed the problem! Probably I made a mistake somewhere dealing with segments, but, as it's really not in existance anymore, neither it does matter. Thanks anyway...
I plan to make ReadSectors more readable by generally doing what you said in thy post.
=======================
=Problem solved.
=======================
User avatar
MichaelFarthing
Member
Member
Posts: 167
Joined: Thu Mar 10, 2016 7:35 am
Location: Lancaster, England, Disunited Kingdom

Re: BIOS fnc. interrupts corrupted in real mode after a far

Post by MichaelFarthing »

Lukand wrote: I plan to make ReadSectors more readable by generally doing what you said in thy post.
Ooh! A little bug there: "doing what thou said in thy post". The abandoment of thou and thy is a great loss to the English language. I'm all for them!
Post Reply