如何禁用浮点单元(FPU)? [英] How to disable floating point unit (FPU)?

查看:238
本文介绍了如何禁用浮点单元(FPU)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在x86系统中禁用FPU / MMX / SSE指令,我将实现不可用设备异常的处理程序。我已经提到了控制注册维基页面;看来我必须在cr0寄存器中设置一些标志。如何在cr0中设置这些标志,并且这个工作在启动时执行?

I want to disable FPU/MMX/SSE instructions in x86 system, and I will implement a handler for the Device-Not-Available exception. I have referred to Control register wiki page; It seems that I have to set some flags in cr0 register. How to set these flags in cr0 and Do this work do at boot time?

推荐答案

用于管理FPU状态的Linux内核代码可以在 arch / x86 / kernel / trap中找到。 c do_device_not_available()。默认情况下,Linux内核会禁用所有进程的FPU,并在第一次访问时启用它。这允许内核减少不使用FPU的进程的上下文切换开销。但是,这也意味着在启动时设置TS一次是不够的;您必须修改管理TS标志的Linux内核代码才能维持此状态。

The Linux kernel code for managing FPU state can be found in arch/x86/kernel/traps.c, do_device_not_available(). By default, the Linux kernel disables the FPU for all processes, and enables it on first access. This allows the kernel to reduce context switch overhead for processes that don't use the FPU. However, it also means that setting TS once at startup is insufficient; you must alter the Linux kernel code that manages the TS flag to maintain this state.

通过将早期检查添加到 do_device_not_available()用于禁用标志,并提出信号或采取其他措施,您可以禁用对FPU的访问。请注意,如果在进程首次使用该特定CPU上的FPU后执行此操作,FPU可能会保持可用时间,直到FPU寄存器被上下文切换,并且FPU被重新禁用。如果您希望避免这种情况,您将不得不使用 stts()显式重新禁用FPU。

By adding an early check to do_device_not_available() for a disable flag and raising a signal or taking some other action, you can disable access to the FPU. Note that if you're doing this after the process's first use of the FPU on that particular CPU, the FPU may remain usable for some time, until the FPU registers are context-switched out, and the FPU is re-disabled. If you wish to avoid this, you will have to explicitly re-disable the FPU with stts().

请注意,由于Linux ABI假定您有FPU(仿真FPU或硬件FPU - 如果您的内核都不会启动),这可能会导致应用程序出现意外的行为。此外,使用FPU的任何内部内核代码(不确定是否有任何内容)也可能会中断。执行此事您自己承担风险。

Note that as the Linux ABI assumes you have a FPU (either emulated FPU or hardware FPU - if you have neither the kernel will not boot), this may cause unexpected behavior in applications. Additionally, any internal kernel code using the FPU (not sure if there is any) is likely to break as well. Implement this at your own risk.

这篇关于如何禁用浮点单元(FPU)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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