V86 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
stafe
Posts: 22
Joined: Fri Oct 29, 2004 11:00 pm

V86 Mode

Post by stafe »

Hello,

i've a big problem to make a V86 task ... i need V86 mode to switch to another VBE mode ...

in my OS i can schedule ring0 and ring3 tasks ...
is it true that i only set the V86 bit in the EFLAGS to choos the V86 mode ?

Here is an example how i set the V86-Task-Stack up:

Code: Select all

  stackptr=kernstack;
*--stackptr=0x20|3;
*--stackptr=0x20|3;
*--stackptr=0x20|3;
*--stackptr=0x20|3;
*--stackptr=0x20|3;
*--stackptr=(unsigned long)userstack;
*--stackptr=0x20002L;
*--stackptr=0x18|3;
*--stackptr=(unsigned long)startpunkt;
*--stackptr=0x0;    //EAX
*--stackptr=0x0;    //ECX
*--stackptr=0x0;    //EDX
*--stackptr=0x0;    //EBX
*--stackptr=0x0;    //-->ESP kann Null sein
*--stackptr=0x0;    //EBP
*--stackptr=0x0;    //ESI
*--stackptr=0x0; //EDI
*--stackptr=0x10; //ds
*--stackptr=0x10; //es
*--stackptr=0x10; //fs
*--stackptr=0x10; //gs
I don't that the error is in this part.
Bochs show me these errors:


Code: Select all

00084951475-i-@00102142-[CPU  ] IRET to V86-mode: ignoring upper 16-bits
00084951478-i-@00000003-[CPU  ] LOCK prefix unallowed (op1=0x53, attr=0x0, mod=0x0, nnn=0)
and many errors like:

Code: Select all

00084951522-e-@00101852-[CPU  ] seg = DS
00084951522-e-@00101852-[CPU  ] seg->selector.value = 0000
I don't know if the task is running in V86 mode ... I hope somebody have made experiance with the virtual 86 mode and can help me ...

Thanks,
stafe
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

when IRETing to v8086 mode, you must have all the segment registers present on the stack to be popped. ATM you use protected-mode values for the segment registers, rather than the expected v8086 mode (real-mode) values, which makes everything point to garbage. (0x230 or 0x1B0 is added to all offsets)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
digo_rp
Member
Member
Posts: 233
Joined: Sun Jun 05, 2005 11:00 pm

Post by digo_rp »

this is the right stack setup to use vm86 in your kernel

p = (dword)0x1fff8; <- stack address any address below 1MB mark. don´t forget.
*--p = r->gs; /* gs */<- 16 bits segment 0x1000 e.g.
*--p = r->fs; /* fs */<- 16 bits segment 0x1000 e.g.
*--p = r->ds; /* ds */<- 16 bits segment 0x1000 e.g.
*--p = r->es; /* es */ <- 16 bits segment 0x1000 e.g.
*--p = r->cs; /* ss */ <- stack segment for that vm86 task
*--p = 0xfff8; /* esp */ <- stack point for "" ""
*--p = 0x20000L; /* eflags */
*--p = r->cs; /* cs */ <- vm86 16 bits selector " 0x1000 " example
*--p = r->eip; /* eip */
*--p = r->eax; /* eax */
*--p = r->ecx; /* ecx */
*--p = r->edx; /* edx */
*--p = r->ebx; /* ebx */
*--p = 0; /* nullesp*/
*--p = r->ebp; /* ebp */
*--p = r->esi; /* esi */
*--p = r->edi; /* edi */
*--p = 0x10; /* gs */ <- PM32 bits selector
*--p = 0x10; /* fs */ <- PM32 bits selector
*--p = 0x10; /* es */ <- PM32 bits selector
*--p = 0x10; /* ds */ <- PM32 bits selector

you can change that layout according with your kernel. just remenber.

any atempt of putting anything from vm86 segment address at segment selector ds,es,fs,gs while your kernel is in pm32 bits you´ll get gpf you can only cange that 4 value first in your stack layout, ther last 4 selectors is the pm32 bits selector from your kernel 0x10, 0x20 whatever.
stafe
Posts: 22
Joined: Fri Oct 29, 2004 11:00 pm

Post by stafe »

Thanks for you answers.

@digo_rp:

I tried you V86 stack but it's the same problem than before.

What does this error mean?

Code: Select all

00084951520-e-@00101852-[CPU  ] seg = DS
00084951520-e-@00101852-[CPU  ] seg->selector.value = 0000
This error is very often shown ...

Thanks
User avatar
JamesM
Member
Member
Posts: 2935
Joined: Tue Jul 10, 2007 5:27 am
Location: York, United Kingdom
Contact:

Post by JamesM »

Means that the data segment register is loaded with the null selector, I think. Either that or one of the integral fields is null.
stafe
Posts: 22
Joined: Fri Oct 29, 2004 11:00 pm

Post by stafe »

Thanks to bluecode ... he helped me to solve the main problem ...

the Problem was that I load DS,GS,FS and ES with a null selector ...

When the CPU switch from V86 back to RING0 the segment registers were loaded with an NULL selector ... I only have to set the segment registers ...

Now the V86 Task occurs a General Protection Fault and I can call the V86-Monitor to emulate the Interrupts ...

Thanks again to bluecode ...
Post Reply