Page 1 of 1

V86 Mode

Posted: Sun Sep 02, 2007 2:07 pm
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

Posted: Sun Sep 02, 2007 3:22 pm
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)

Posted: Mon Sep 03, 2007 7:39 am
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.

Posted: Mon Sep 03, 2007 7:50 am
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

Posted: Mon Sep 03, 2007 8:08 am
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.

Posted: Tue Sep 04, 2007 1:45 pm
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 ...