Page 1 of 5

virtual mode...

Posted: Wed May 30, 2007 4:40 pm
by xyjamepa
Hi...
I'm tring to have a support for virtual mode in my kernel
I made a simple virtual task it dosen't do any thing just
prints a simple message and go back...
My hardware multitasking works fine and I can switch from PL0
to PL3 and go back,my virtual task works in PL3...
I just changed the EFLAGS to 0x23202L that means I sat the VM bit to 1
It suppose to work but unfortunately it didn't and I got
general protection fault, so here's a minimized vesion of my kernel
and an IMG file.

please note paging isn't enabled.

Thanx.

Posted: Wed May 30, 2007 10:09 pm
by pcmattman
GPF fires in Virtual Mode when it hits a priveleged instruction, such as IRET, or INT.

You need to, in your GPF handler, check for VM bit in EFLAGS and then emulate the instruction (search google for virtual 8086 mode monitor).

Also, I'd suggest changing your IOPL to 0, as you'll save yourself a lot of trouble later. At IOPL0 your GPF handler is asked to handle all priveleged instructions (the safest way to do it).

Posted: Thu May 31, 2007 4:53 am
by xyjamepa
Hi...
I don't have a GPF handler yet, now I just want to print a simple
message from a virtual mode task...
Also I read in the Intel manual:
The CPL is always 3 while running in virtual-8086 mode
this means the vitrual task must be in PL3,I'm I right?


Thanx.

Posted: Thu May 31, 2007 6:43 am
by XCHG
CPL is the Code Segment's Privilege Level and is equal to the DPL field of the Code Segment's Descriptor in the GDT/LDT. CPL is not the RPL because RPL is the 3 rightmost bits of the Segment Selector.

Posted: Thu May 31, 2007 7:35 am
by xyjamepa
humm...
so my question would be can a virtual task work in PL0?

My virtual task suppose to work in PL3,but as soon as I
enable multitasking I get general protection fault...
I don't know what's wrong with my code, my hardware
multitasking works fine and I can switch from PL0
to PL3 and go back successfully, I only changed EFLAGS
from 0x3202L to 0x23202L so the VM bit is set to 1
but unfortunately it didn't work. :(
so would you please check the code above ...


Thanx.

Posted: Thu May 31, 2007 7:48 am
by Combuster
I get
00049357362e[CPU0 ] call_protected: EIP not within CS limits
Surely you have checked where THAT came from?

Posted: Thu May 31, 2007 8:55 am
by xyjamepa
Hi...

tss[1].eip=(dword)&task;
cs:eip points to task() which is my virtual task
also the tss[1].cs=0x18 | 3 and tss[0].cs=0x18 | 3
0x18 is code segment descriptor PL3
I'm sure of this descriptor It was working fine before
enabling VM bit in EFLAGS...
let's form this again:
my hardware multitasking consists of two tasks:
main() which is PL0 and task() which is PL3
my multitasking works fine and I can switch between PL0 and PL3
successfully, but when I changed the EFLAGS from 0x3202L to 0x23202L
I got general protection fault ...

paging not enabled.

Thanx.

Posted: Thu May 31, 2007 3:20 pm
by pcmattman
abuashraf wrote:so my question would be can a virtual task work in PL0?
Read the manuals further. I'm talking about the IOPL, the I/O privilege level. Completely different from the CPL and RPL.

Posted: Thu May 31, 2007 4:15 pm
by xyjamepa
Hi...
I'm talking about the IOPL, the I/O privilege level. Completely different from the CPL and RPL.
Okay I know that
Also I'll read the Intel manual again but ,did any one
find out what's wrong with my code ?I've checked it out
about more than thousand times and till now I don't know
what's wrong with it.
It's realy confusing ...right now I just want to enable virtual mode
print a message and go back that's it.

Thanx.

Posted: Thu May 31, 2007 4:38 pm
by Combuster
(hint)
EIP > segment limit
(hint)
virtual 8086 mode
(hint)
64k segments
(hint)
request to check things
(hint)
obviousness of the problem
(HINT)
:shock:

The whole idea of debugging is to find the problem and that what causes it. Bochs bluntly shoves the first under your nose, so all you have to do is to find out where that faulty eip comes from and why. If you have trouble doing that, IMNSHO asking about that would be far better than a request to find the bug.

Posted: Thu May 31, 2007 11:38 pm
by pcmattman
I had heaps of trouble getting Virtual mode implemented. It took about a month until I figured out the problems and why they weren't working (for me, my TSS was setup wrong).

Bochs' debugger is your best friend in this situation.

Posted: Fri Jun 01, 2007 5:39 am
by xyjamepa
Hi...
so all you have to do is to find out where that faulty eip comes from and why. If you have trouble doing that, IMNSHO asking about that would be far better than a request to find the bug.
Okay,would some one please tell me where did this faulty eip come from?
Bochs' debugger is your best friend in this situation.
unfortunately I don't have one :(
I'm using Bochs 2.2.6 for windows I downloaded it as an .exe file
It doesn't have a debugger.

Thanx.

Posted: Fri Jun 01, 2007 6:07 am
by jnc100
abuashraf wrote:I'm using Bochs 2.2.6 for windows I downloaded it as an .exe file
It doesn't have a debugger.
Try 'bochsdbg'. You should have it.

Regards,
John.

Posted: Fri Jun 01, 2007 6:12 am
by AJ
Okay,would some one please tell me where did this faulty eip come from?
use objdump -x yourexefile.exe>file.txt

Posted: Fri Jun 01, 2007 9:14 am
by xyjamepa
unfortunately nothing is working :( :( :(