Page 1 of 1

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

Posted: Tue May 22, 2018 6:55 am
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.

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

Posted: Tue May 22, 2018 10:13 am
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.

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

Posted: Wed May 23, 2018 4:19 am
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.
=======================

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

Posted: Wed May 23, 2018 6:04 am
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!