在定制的操作系统当前的x86权限级别 [英] Current x86 privilege level on a custom OS

查看:260
本文介绍了在定制的操作系统当前的x86权限级别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在在保护模式下的x86上运行一个定制的操作系统,有没有办法来获得当前特权级别,比其他的如执行特权指令,看它是否会崩溃?

In a custom OS running on an x86 in protected mode, is there a way to obtain the current privilege level, other than e.g. executing a privileged instruction and seeing if it crashes?

例如,注册 CR0 包含 PE 位,这表明如果我们在实模式或受保护的运行模式,并可以用汇编code很容易地检索。

For instance, register CR0 contains the PE bit, which indicates if we are running on real mode or protected mode, and can be easily retrieved using assembly code.

是否有权限级别相当于什么?

Is there something equivalent for the privilege level?

的<一个href=\"http://www.intel.com/content/www/us/en/processors/architectures-software-developer-manuals.html\"相对=nofollow>英特尔架构软件开发人员手册提到, EFLAGS 寄存器包含两个 IOPL 位与I / O特权级别。这是与当前特权级(CPL)?

The Intel architecture software developer manual mentions that the EFLAGS register contains two IOPL bits related to I/O privilege levels. Is this the same as the current privilege level (CPL)?

推荐答案

没有它是不一样的。这些重新present的IO权限级别。有些指令,如 OUT CLI 要求IO它使用确定权限 IOPL CPL

No it's not the same. Those represent the io privilege level. Some instructions such as IN, OUT, CLI require io privileges which are determined using the IOPL and the CPL.

另请参阅:

IOPL I / O特权级字段(12和13位) - 指示I / O
  特权
       当前运​​行的程序或任务的级别(IOPL)。的CPL的
       当前正在运行的程序或任务必须小于或等于IOPL到
       访问I / O地址空间。

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 选择读作最低两位:

The CPL can be read simply from the CS selector as the two lowest bits:

mov ax, cs
and ax, 3

这当然只能在保护模式。

This of course only works in protected mode.

这篇关于在定制的操作系统当前的x86权限级别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆