Booting OS as a VMM

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Post Reply
MJ
Posts: 6
Joined: Fri Aug 06, 2010 11:58 am

Booting OS as a VMM

Post by MJ »

HI,

Hoping someone can help. I am working on getting an OS booted in VMM mode on an intel processor. I am using OWC 17 as the compiler. So far I have paging enabled and working. (32 bit mode with segmentation enabled). I checked the cpuid for the processor I am using and it does support VMX. I allocate a region in memory equal to size shown in IA32_VMX_BASIC_MSR (bits44:32) = 800 so I set it up as 2048 = 2k region size. I set the VMCS revision Identifier as shown in bits 31:0 of this msr = 13 (on my test processor). It is a 4k aligned region. My vmxon address is 66c000 (looks ok). Control Registers:
CR0 = 8001003b
CR4 = 2200
IA32_FEATURE_CONTROL MSR = 0xd
IA32_EFER.LMA = 0x0
EFLAGS = 246
A20 = 0x0
Then when I call vmxon I get interrupt 13 a GP - seems to not like my memory reference to the vmxon region?

Watcom does not have support for the Intel VMX instruction set so had to add lib with opcode for vmxon

unsigned long long vmxon_region;


void __near vmxon(void);
#pragma aux vmxon = \
"nop" \
"nop" \
"push ebx" \
"mov ebx, offset vmxon_region" \
"nop" \
"nop" \
0xF3 0x0F 0xC7 0x33 \
"nop" \
"nop" \
"pop ebx" \
"nop" \
"nop";
I assign the 32 bit addres to vmxon_region (a 64 bit long long) in another function and then call vmxon. I am not real clear about how vmxon works does it take indirect or direct address? Tried both and haven't gotten anything but GP
MJ
Posts: 6
Joined: Fri Aug 06, 2010 11:58 am

Re: Booting OS as a VMM

Post by MJ »

Thanks, I saw a newsgroup that you needed to call vmxon from a 64 bit code segment. I'll give it a try!
MJ
Posts: 6
Joined: Fri Aug 06, 2010 11:58 am

Re: Booting OS as a VMM

Post by MJ »

bump
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:

Re: Booting OS as a VMM

Post by Combuster »

bump
Where? :twisted:
"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 ]
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Booting OS as a VMM

Post by gerryg400 »

Are all your segments registers valid ?

Is your code segment readable ?
If a trainstation is where trains stop, what is a workstation ?
Cognition
Member
Member
Posts: 191
Joined: Tue Apr 15, 2008 6:37 pm
Location: Gotham, Batmanistan

Re: Booting OS as a VMM

Post by Cognition »

VMXON takes a memory address that should point to the physical address of the region, similar to how INVLPG works but with a physical address. Intel's SDM Volume 2B describes in depth the scenarios which can cause the VMXON instruction to GP fault. If I had to guess it's probably has to do with the setting of reserved bits in CR0/CR4, the settings of which can be determined from specific MSRs listed in Volume 3B of the SDM. This thread might be of some use to you.
Reserved for OEM use.
MJ
Posts: 6
Joined: Fri Aug 06, 2010 11:58 am

Re: Booting OS as a VMM

Post by MJ »

Yes all segment registers are valid
yes code segment is readable
I tried putting the vmxon region in both GS and DS and still get GP.

The MSR's related to setting the control registers:

IA32_VMX_CR0_FIXED0 = 0x80000021
IA32_VMX_CR0_FIXED0 = 0xFFFFFFFF
IA32_VMX_CR4_FIXED0 = 0x2000
IA32_VMX_CR4_FIXED1= 0x67FF
CR0 = 0x8001003B
CR4 = 0x2200

CR0 and CR4 seem to be correct as far as I can tell. I am still thinking that it may be how I am handling the address in the vmxon opcode? I am using an indirect address??
gerryg400
Member
Member
Posts: 1801
Joined: Thu Mar 25, 2010 11:26 pm
Location: Melbourne, Australia

Re: Booting OS as a VMM

Post by gerryg400 »

I don't know whether the opcodes are correct, but my understanding is that you pass a register containing a 32 bit pointer to the 64 bit value in memory. I'm not certain you need the 2nd level of indirection. Did you try the opcode sequence ?

Code: Select all

0xF3 0x0F 0xC7 0xF1
EDIT: Actually, on 2nd thought, it's very unlikely that I'm right.
If a trainstation is where trains stop, what is a workstation ?
MJ
Posts: 6
Joined: Fri Aug 06, 2010 11:58 am

Re: Booting OS as a VMM

Post by MJ »

ok tried F3 and get invalid opcode?
MJ
Posts: 6
Joined: Fri Aug 06, 2010 11:58 am

Re: Booting OS as a VMM

Post by MJ »

I used F3 instead of F1 because I am using EBX. I assmume it does not matter which register you use.
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Re: Booting OS as a VMM

Post by 01000101 »

Have you checked out this stub I made a while ago? I'm going to re-implement some old code of mine into a more basic OS soon to do some more testing. When I'm at my workstation I'll re-read your issue and see if I can find some differences and hopefully get around to adding information to that wiki article. I'd also be grateful if you did the same as you progress in your VMX journey. :-)
User avatar
01000101
Member
Member
Posts: 1599
Joined: Fri Jun 22, 2007 12:47 pm
Contact:

Re: Booting OS as a VMM

Post by 01000101 »

I dug up an old copy of my VMX code. You can find it (and earlier revisions or that plus its associated header) in the ArcticOS repository. http://quokforge.org/projects/arcticos/repository/revisions/145/entry/trunk/Core/vmx.c

Sorry I don't have much else to help with at this time, still juggling a few other things before I get to working on VMX stuff.
Post Reply