virtual 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.
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

virtual mode...

Post 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.
Attachments
a.tar.gz
IMG
(46.98 KiB) Downloaded 110 times
knl.tar.gz
kernel
(14.95 KiB) Downloaded 101 times
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post 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).
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Post 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.
User avatar
XCHG
Member
Member
Posts: 416
Joined: Sat Nov 25, 2006 3:55 am
Location: Wisconsin
Contact:

Post 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.
On the field with sword and shield amidst the din of dying of men's wails. War is waged and the battle will rage until only the righteous prevails.
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Post 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.
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 »

I get
00049357362e[CPU0 ] call_protected: EIP not within CS limits
Surely you have checked where THAT came from?
"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 ]
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Post 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.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post 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.
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Post 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.
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 »

(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.
"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 ]
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post 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.
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Post 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.
jnc100
Member
Member
Posts: 775
Joined: Mon Apr 09, 2007 12:10 pm
Location: London, UK
Contact:

Post 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.
User avatar
AJ
Member
Member
Posts: 2646
Joined: Sun Oct 22, 2006 7:01 am
Location: Devon, UK
Contact:

Post by AJ »

Okay,would some one please tell me where did this faulty eip come from?
use objdump -x yourexefile.exe>file.txt
User avatar
xyjamepa
Member
Member
Posts: 397
Joined: Fri Sep 29, 2006 8:59 am

Post by xyjamepa »

unfortunately nothing is working :( :( :(
Post Reply