OSDev.org

The Place to Start for Operating System Developers
It is currently Mon Apr 12, 2021 10:52 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 67 posts ]  Go to page 1, 2, 3, 4, 5  Next
Author Message
 Post subject: virtual mode...
PostPosted: Wed May 30, 2007 4:40 pm 
Offline
Member
Member
User avatar

Joined: Fri Sep 29, 2006 8:59 am
Posts: 397
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:
File comment: kernel
knl.tar.gz [14.95 KiB]
Downloaded 45 times
File comment: IMG
a.tar.gz [46.98 KiB]
Downloaded 29 times
Top
 Profile  
 
 Post subject:
PostPosted: Wed May 30, 2007 10:09 pm 
Offline
Member
Member

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

_________________
Pedigree | GitHub | Twitter | LinkedIn


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 31, 2007 4:53 am 
Offline
Member
Member
User avatar

Joined: Fri Sep 29, 2006 8:59 am
Posts: 397
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:
Quote:
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.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 31, 2007 6:43 am 
Offline
Member
Member
User avatar

Joined: Sat Nov 25, 2006 3:55 am
Posts: 416
Location: Wisconsin
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.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 31, 2007 7:35 am 
Offline
Member
Member
User avatar

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


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 31, 2007 7:48 am 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9289
Location: On the balcony, where I can actually keep 1½m distance
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 ]


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 31, 2007 8:55 am 
Offline
Member
Member
User avatar

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


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 31, 2007 3:20 pm 
Offline
Member
Member

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

_________________
Pedigree | GitHub | Twitter | LinkedIn


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 31, 2007 4:15 pm 
Offline
Member
Member
User avatar

Joined: Fri Sep 29, 2006 8:59 am
Posts: 397
Hi...
Quote:
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.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 31, 2007 4:38 pm 
Offline
Member
Member
User avatar

Joined: Wed Oct 18, 2006 3:45 am
Posts: 9289
Location: On the balcony, where I can actually keep 1½m distance
(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 ]


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 31, 2007 11:38 pm 
Offline
Member
Member

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

_________________
Pedigree | GitHub | Twitter | LinkedIn


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 01, 2007 5:39 am 
Offline
Member
Member
User avatar

Joined: Fri Sep 29, 2006 8:59 am
Posts: 397
Hi...
Quote:
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?

Quote:
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.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 01, 2007 6:07 am 
Offline
Member
Member

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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 01, 2007 6:12 am 
Offline
Member
Member
User avatar

Joined: Sun Oct 22, 2006 7:01 am
Posts: 2637
Location: Devon, UK
Quote:
Okay,would some one please tell me where did this faulty eip come from?


use objdump -x yourexefile.exe>file.txt


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 01, 2007 9:14 am 
Offline
Member
Member
User avatar

Joined: Fri Sep 29, 2006 8:59 am
Posts: 397
unfortunately nothing is working :( :( :(


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 67 posts ]  Go to page 1, 2, 3, 4, 5  Next

All times are UTC - 6 hours


Who is online

Users browsing this forum: MichaelPetch and 10 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group