Software Archive
Read-only legacy content
17061 Discussions

MWAIT support for CPL=1,2 and 3

vishwa_m
Beginner
776 Views
Reading through the Intel documentation, it appears that MWAIT is not a privileged instruction. Executing MWAIT with non-zero CPL always results in a #UD exception. The documentation seems ambiguous on what needs to be done in-order to enable MWAIT execution in CPL 1,2 or 3. (Before executing mwait I do make sure that CPUID reports MWAIT support) .

In the code snippet below; mwait takes a UD. Note that mwait is executed without a monitor (I think this should be ok since without a monitor mwait should just move to the next instruction). Does anybody know what needs to be done to execute MWAIT successfully at non-zero CPL?



Code snippet:
//CPL = 0
int 1; -> software interrupt
jump to handler;
after_iret:
//CPL = 3
mov ecx, 0
mwait --> this results in UD

handler:
manipulate stack image for CPL = 3
iret

0 Kudos
2 Replies
Intel_Software_Netw1
776 Views

Our engineering contacts recommend that you refer to the Intel 64 and IA-32 Architectures Software Developer's Manual Volume 2A: Instruction Set Reference, A-M.

Page 630 (Nov 2006 version) states:

The MONITOR CPUID feature flag (ECX bit 3; CPUID executed EAX = 1) indicates the availability of MONITOR and MWAIT in the processor. When set, the unconditional execution of MONITOR is supported at privilege levels 0; conditional execution is supported at privilege levels 1 through 3 (test for the appropriate support before unconditional use). The operating system or system BIOS may disable this instruction by using the IA32_MISC_ENABLES MSR; disabling MONITOR clears the CPUID feature flag and causes execution to generate an illegal opcode exception.

The instructions operation is the same in non-64-bit modes and 64-bit mode.

Essentially, this says that the instruction will not work at ring 1,2,3, asyou observed. There is not a way to enable the instruction.

==

Lexi S.

IntelSoftware NetworkSupport

http://www.intel.com/software

Contact us

0 Kudos
levicki
Valued Contributor I
776 Views

First, if he already has the ability to run part of his code in CPL0 he can re-enable the MONITOR/MWAIT by setting bit 18 in MSR 0x1A0 to 1.

Second, you could have suggested why BIOS might have disabled MONITOR/MWAIT -- it could be because Max. CPUID level limit is set to "Enable".

0 Kudos
Reply