The easiest way is to simply run the command (x86) and catch the corresponding error.
eg. (SEH, Windows, kernel mode)
bool ring_lower_0 = false;
__try
{
__asm { <cmd> };
ring_lower_0 = true;
}
__except( GetExceptionCode() == EXCEPTION_PRIV_INSTRUCTION )
{
ring_lower_0 = false;
}
Notes:
cmd, is an assembler command. See Intel Architecture Reference Guides for a list of commands and their respective call levels.
Linux has a slightly different concept.
But remember that lower level virtual machines can mask the result by emulating a challenge.
(NB: The task of the virtual machine is to translate the incorrect instruction into a meaningful call)
, , , " ".