Entering vm86 Mode?

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
Perica
Member
Member
Posts: 454
Joined: Sat Nov 25, 2006 12:50 am

Entering vm86 Mode?

Post by Perica »

..
Last edited by Perica on Sun Dec 03, 2006 9:00 pm, edited 2 times in total.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Entering vm86 Mode?

Post by Pype.Clicker »

check the intel manual (chapter about 8086 emulation) to be 100% sure. Here's my local cache version:

push-order is (--GS)(--FS)(--DS)(--ES)(--SS)(ESP)(FLaGZ)(--CS)(EIP)

Note that segment registers are pushed as 32 bits words. The corresponding code would be

Code: Select all

xor eax,eax
mov ax, *s
push eax
Perica
Member
Member
Posts: 454
Joined: Sat Nov 25, 2006 12:50 am

Calling BIOS Interrupts from vm86-Mode?

Post by Perica »

..
Last edited by Perica on Sun Dec 03, 2006 9:00 pm, edited 1 time in total.
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Entering vm86 Mode?

Post by Pype.Clicker »

i'm not convinced it's a very good idea, but i'll try to help nonetheless (you must have real good reason not to use realmode INT13 and bios memcopy INT15 features ... i don't want to start a flame war :) )

what you should do is read [requested_interrupt*4] to get the actual CS:IP for the interrupt you want to call, and set the appropriate values on your pmode stack for the V86 invokation.

transferring values in registers (for int arguments) shouldn't be hard.
What you should take care of is what the real-mode interrupt will do when its work is complete. I suggest you add the address of a HLT instruction on the rmode stack so that when INT13 will try to call IRET, it will branch on a HLT instruction, which is prohibited in v86mode --> it will raise a GPF that you'll be able to use to finish the V86 call...
Tim

Re:Entering vm86 Mode?

Post by Tim »

At the risk of starting a flame war... :)

Don't bother using V86 mode in a boot sector if all you're doing it loading from disk into extended memory. Unreal mode will be enough. There are tutorials around which will tell you how to do this. Briefly, you need to:
  • set up a GDT with at least a data segment whose base is zero and whose limit is 4GB
  • set CR0.PE
  • load FS with your data selector
  • set FS to zero
  • clear CR0.PE
Now you can use full 32-bit addresses as long as you use the FS segment override. This means that you can load some sectors using INT 13h then REP MOVSD them into extended memory (assuming you use the 32-bit prefix and FS override on the REP MOVSD instruction).

This is a lot easier and more reliable than setting V86 mode inside your boot sector.
Perica
Member
Member
Posts: 454
Joined: Sat Nov 25, 2006 12:50 am

Re:Entering vm86 Mode?

Post by Perica »

..
Last edited by Perica on Sun Dec 03, 2006 9:00 pm, edited 1 time in total.
Tim

Re:Entering vm86 Mode?

Post by Tim »

Perica Senjak wrote:UnrealMode on the other hand isn't a very good idea (It can cause errors in your code, and also may not work on some machines)
Really? I could mention an entire generation of computer games which cast that into doubt.
and i don't see how you could move something into upper memory from UnrealMode using movsb/movsw/movsd, because in RealMode those instructions use 16-Bit Registers (si, di etc.); Is there a way around this? If so, how would it be done?
Yes; use the O32 prefix on REP MOVSD (or is it A32? a quick experiment could verify that). If you're not happy with unreal mode then could I suggest the INT 15h services which Pype mentioned earlier?
Post Reply