首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

理解 x87 FPU 的执行环境(2)

理解 x87 FPU 的执行环境(2)

2.2 protected mode 下的 state image在保护模式下 state image 的排列有相应的改变
2.2.1 32 位的内存模式
在这里同样,我们用代码来验证一下 state image:

上面这个图是在 vmware 运行的结果截图,这个示例代码运行在 32-bit protected mode 下,红色标注分别是:last instruction pointer 和 last data pointer 的 selector 值。这个图的运行结果直观地验证了 intel 给出的 32 位的保护模式下的 state image 结构。
仔细对比一下 real-mode 的 32 位 state image 和 proected-mode 的 32 位 state image,我们会发现在 last instruction pointer 和 last data pointer 的 selector(或者说高 16 位)排列是不同的。
本例的源代码和映像下载:x87environment_demo_protected32.zip

2.2.2 16 位内存模式再来看看在 protected mode 下的 16 位 state image 是如何:

很显然和 16 位 real mode 下的 state image 是存在差别的,在 16 位 proected mode 的 state image 中并没有 last opcode
下面是试验结果:

同样是在 protected mode 下,但是我使用了 16-bit 的 operand size:
        db 0x66                                        ; override to 16-bit
        fnstenv [state]                                ; default operand-size is 32-bit
对比一下结果,可以知道和 16-bit real mode 下的 state image 是不同的。

2.3 64-bit 模式下的 state image使用 fstenv/fnstenv 指令我们只能得到 32 位的 state image,因此我们需要使用 fxsave 指令来获得 64 位的 state image,下面的实验是基于 fxsave 指令进行的。
2.3.1 64 位的 state image
下面我使用了 fxsave 指令 64 位的 operand size 进行保存 state image:
        db 0x48                                ; operand size is 64-bit
        fxsave [IMAGE64]
运行结果如下:

这个结果显示了在 64 位模式下的 64 位 state image,last instruction pointer 和 last data pointer 都是 64 位宽,在示例中 last instruction pointer 的值是:0xFFFFFFF80000000B,这是 64 位的地址值。
本例的源代码和映像下载:x87environment_demo_long64.zip
2.3.2 32 位的 state image下面看看 64-bit 模式下的 32 位 state image:

下面我们来看看显示 64-bit 位模式下的 32 位 state image 运行结果:

我们的 last instruction pointer 依然是 0xFFFFFFF80000000B,可是可以看到在这个 32 位 state image 保存的结果是不对的,last instruction pointer 和 last data pointer 都是 32 位。在上图结果中保存在 state image 的 last instruction pointer 变成了 0x0000000B
因此,在 64-bit 运行环境下,我们应该使用 64-bit 的 state image,当然在 compatibility mode 下应该使用 32-bit 的 state image
继承事业,薪火相传
返回列表