禁用 L2/L1 缓存

发布于 2024-07-26 09:46:13 字数 399 浏览 7 评论 0原文

我正在尝试禁用CPU的内部和外部内存缓存,我的配置如下: -DELL精密工作站 -英特尔酷睿 2 双核 E6550 2.33 GHz -Ubuntu 8.10

我尝试通过 BIOS 禁用它,但 DELL 计算机似乎不允许用户访问缓存,我​​找到了另一种方法,即以编程方式禁用缓存,Intel 架构手册 A.3 指出cr0 寄存器可以通过设置位 30 设置为禁用缓存,然后我编写了上面的代码:

invd

mov eax,cr0

mov eax,40000000H ;set bit 30

mov cr0,eax

程序编译成功,但是当我尝试运行 exe 文件时,它段错误(我正在使用NASM)

任何人都可以帮助我吗?

I am trying to disable the internal and external memory cache of my CPU, my configuration is above:
-DELL Precision WorkStation
-Intel Core 2 Duo E6550 2.33 GHz
-Ubuntu 8.10

I've tried to disable it through BIOS, but it apears that DELL computers doesn't let users to access cache memory, I found then another way, it is to disable cache programmaticaly, Intel Architecture manual A.3 indicates that cr0 register can be set to disable cache by setting bit 30, i wrote the above code then :

invd

mov eax,cr0

mov eax,40000000H ;set bit 30

mov cr0,eax

The program compiled successfully, but when I try to run exe file,it Seg Faults (i'm using NASM)

Anyone can help me?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

素食主义者 2024-08-02 09:46:13

请注意,即使您由于在内核中或在 DOS 上以保护模式等方式运行工具而处于 Ring 0 中,将 0x40000000 移动到 cr0 肯定会导致灾难。 你看,控制寄存器(cr0)控制着影响处理器运行方式的各种事情,例如启用分页、保护模式(不是直接)等。如果你取消设置所有这些位,你最终会得到一个完全不同的结果如果您之前启用了分页,那么出现分段错误就不足为奇了。

你应该这样做:

mov eax,cr0
or eax, 40000000H ;set bit 30 without clearing the others
mov cr0,eax

Please note that even if you're in ring 0 because you're in the kernel or run your tool on DOS in protected mode etc, moving 0x40000000 to cr0 will definitely cause a disaster. You see, the control register (cr0) controls all sorts of things that effect the way the processor operates, such as enabling paging, protected mode (not directly) etc. If you unset all those bits, you will end up in a totally different environment and getting a segmentation fault is not surprising at all if you had paging enabled previously.

You should do this instead:

mov eax,cr0
or eax, 40000000H ;set bit 30 without clearing the others
mov cr0,eax
说不完的你爱 2024-08-02 09:46:13

我在维基百科上找到了控制寄存器上的此文档。 这证实了你所说的:

CR0 寄存器的长度为 32 位
386 及更高版本的处理器。 在
x86-64 处理器处于长模式,它
(和其他控制寄存器)是
64 位长。 CR0有多种控制
修改基本操作的标志
处理器的。
位名称 全名 描述
31 PG 寻呼 如果为 1,
启用分页并使用 CR3
注册,否则禁用分页
30 CD 缓存禁用

这使我找到了 Intel 64 和 IA-32 架构软件开发人员指南手册。 它说,我在这里再次引用:

大多数系统限制对系统的访问
寄存器(除了 EFLAGS
注册)通过应用程序。
然而,可以设计系统,
所有程序和过程运行的地方
在最特权级别
(权限级别 0)。 在这种情况下,
应用程序将是
允许修改系统
寄存器。

可能你的程序在语义上是正确的你的代码有一个错误,可能会锁定机器,但即使修复它也需要在主管模式下运行。 请注意,您需要 中的值,以免影响其他寄存器(正如其他人指出的那样)。

I found this document on the control register at wikipedia. That confirms what you say:

The CR0 register is 32 bits long on
the 386 and higher processors. On
x86-64 processors in long mode, it
(and the other control registers) are
64 bits long. CR0 has various control
flags that modify the basic operation
of the processor.
Bit Name Full Name Description
31 PG Paging If 1,
enable paging and use the CR3
register, else disable paging
30 CD Cache disable

This led me to the Intel 64 and IA-32 Architectures Software Developer’s Manual. It says, and I quote here again:

Most systems restrict access to system
registers (other than the EFLAGS
register) by application programs.
Systems can be designed, however,
where all programs and procedures run
at the most privileged level
(privilege level 0). In such a case,
appli- cation programs would be
allowed to modify the system
registers.

Probably your program is semantically correctYour code has a bug that will probably lock up the machine, but even fixed it would need to run in supervisor mode. Note that you need to or the value in so as not to affect the other registers (as others have noted).

月亮坠入山谷 2024-08-02 09:46:13

应该是“or eax,40000000h”来设置位 30。
但无论如何,用户进程都不允许更改控制寄存器。 您需要在内核中进行更改。 我毫不怀疑有一些系统调用或设备接口可以完成您想要的操作。

That should be "or eax,40000000h" to set bit 30.
But a user process won't be allowed to change control registers anyways. You'll need to make the change in the kernel. I wouldn't doubt that there's some system call or device interface to do what you want.

幸福还没到 2024-08-02 09:46:13

您需要从 Windows 或 Linux 上的驱动程序执行此操作,因为只有内核在梯级 0 中运行,并且我认为您无法为一个进程执行此操作,您必须为所有进程执行此操作。

我假设您正在尝试在没有缓存的情况下进行内存写入?

如果您尝试执行可怕的线程代码,也许您想研究缓存刷新指令?

You would need to do this from a driver on windows or linux as only the kernel runs in rung 0 and I don't think you could do it for one process, you would have to do it for all of them.

I'm assuming that you're trying to do memory writes without caching?

Perhaps you want to look into cache flush instructions if your trying to do scary threading code?

提笔书几行 2024-08-02 09:46:13

如果任何在用户模式下运行的代码能够做到这一点,我会感到惊讶 - 这将是一场可怕的 DoS 攻击。

I would be surprised if any code running in user mode would be able to do that - that would be one hell of a DoS attack.

眸中客 2024-08-02 09:46:13

我认为你必须以 root 身份登录才能执行此操作。 我想知道为什么要禁用缓存,禁用 L1 和 L2 很可能会导致计算机锁定。

I think you have to log in as root to do that. I was wondering why would you want to disable the cache, in all likelyhood disabling the L1 and L2 will cause the computer to lock up.

冬天旳寂寞 2024-08-02 09:46:13

实际上,第二条指令(mov eax,cr0)似乎出现了段错误,我只是尝试注释所有其他指令,并且它确实出现了段错误......
但我还是不明白为什么??

我也尝试在运行级别 0 中编译/运行它(telinit 1 命令行作为 root),但它仍然出现段错误...

我想知道控制寄存器 0 (cr0) 是否没有写保护... ?

Actually, it seems to Seg fault at the second instruction (mov eax,cr0), I've just tried to comment all other instructions, and it did seg faults....
But I still don't know why??

I've tryed also to compile/run it in runlevel 0 (telinit 1 command line as root) but it still seg faults...

I'm wondering if the Control Register 0 (cr0) is not write-protected then...?

囚我心虐我身 2024-08-02 09:46:13

我终于可以通过运行代码为 Ring0 来禁用缓存,谢谢 DrJokepu,你给我的链接正是我所需要的。
但我有新问题,因为当我插入禁用缓存的新模块时,效果很好,我只需要 insmod 我的 .ko 文件,以及过程 init我的代码编写的地方被调用。
但现在我想再次以编程方式重新启用缓存,它应该与编写一个 clean 程序一起重置 cr0,并在通过 rmmod 删除模块时调用它,但实际上它什么也不做...我可以检查 cat /proc/modules ,它确实删除了它,但显然,它在删除它之前没有调用我的清理程序...

帮助?

I could finally disable the cache by running the code as Ring0, Thank you DrJokepu, the link you gave me was exactly what I needed..
but I have new problem, cause when I insert the new module who disables the cache, that works grate, I just have to insmod my .ko file, and the procedure init where my code is written is called.
but now I would like to re-enable the cache programmatically again, It should work with writing a clean procedure witch reset the cr0, and call it when remove the module by rmmod it, but actually it does nothing...I can check at cat /proc/modules and it really removed it, but apparently, it hasn't called my clean procedure before removing it....

help?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文