自定义 OS 上的当前 x86 权限级别
Current x86 privilege level on a custom OS
在保护模式下的 x86 上的自定义 OS 运行 中,有没有办法获得当前的特权级别,除了例如执行特权指令并查看它是否崩溃?
例如,寄存器 CR0
包含 PE
位,它指示我们 运行 处于实模式还是保护模式,并且可以使用汇编代码轻松检索。
特权级别是否有等效项?
Intel architecture software developer manual 提到 EFLAGS
寄存器包含两个与 I/O 特权级别相关的 IOPL
位。这与当前特权级别 (CPL) 相同吗?
不,这不一样。这些代表 io 特权级别。 IN
、OUT
、CLI
等一些指令需要使用 IOPL
和 CPL
.
确定的 io 权限
另请参阅:
IOPL I/O privilege level field (bits 12 and 13) -- Indicates the I/O
privilege
level (IOPL) of the currently running program or task. The CPL of the
currently running program or task must be less than or equal to the IOPL to
access the I/O address space.
CPL
可以简单地从 CS
选择器读取为两个最低位:
mov ax, cs
and ax, 3
这当然只适用于保护模式。
在保护模式下的 x86 上的自定义 OS 运行 中,有没有办法获得当前的特权级别,除了例如执行特权指令并查看它是否崩溃?
例如,寄存器 CR0
包含 PE
位,它指示我们 运行 处于实模式还是保护模式,并且可以使用汇编代码轻松检索。
特权级别是否有等效项?
Intel architecture software developer manual 提到 EFLAGS
寄存器包含两个与 I/O 特权级别相关的 IOPL
位。这与当前特权级别 (CPL) 相同吗?
不,这不一样。这些代表 io 特权级别。 IN
、OUT
、CLI
等一些指令需要使用 IOPL
和 CPL
.
另请参阅:
IOPL I/O privilege level field (bits 12 and 13) -- Indicates the I/O privilege level (IOPL) of the currently running program or task. The CPL of the currently running program or task must be less than or equal to the IOPL to access the I/O address space.
CPL
可以简单地从 CS
选择器读取为两个最低位:
mov ax, cs
and ax, 3
这当然只适用于保护模式。