快速CPU环形模式保护问题

发布于 2024-09-02 16:54:38 字数 323 浏览 9 评论 0原文

我很好奇搞乱硬件。但到目前为止,我的顶级“混乱”是 C 程序中的链接或内联汇编程序。如果我对 CPU 和环模式的理解是正确的,我无法直接从用户模式应用程序访问一些低级 CPU 功能,例如禁用中断或更改保护模式段,因此我必须使用系统调用来完成我想要的一切。

但是,如果我是对的,驱动程序可以在环模式 0 下运行。实际上我对驱动程序了解不多,但这就是我所要求的。我只是想知道,学习如何编写自己的驱动程序,然后按照我应该走的方式调用它们,做我写的事情吗?

我知道我可以编写全新的操作系统(至少在某种程度上),但我真正想做的是从标准 Windows 应用程序访问硬件的一些低级功能。那么,司机是正确的选择吗?

I am very curious in messing up with HW. But my top level "messing" so far was linked or inline assembler in C program. If my understanding of CPU and ring mode is right, I cannot directly from user mode app access some low level CPU features, like disabling interrupts, or changing protected mode segments, so I must use system calls to do everything I want.

But, if I am right, drivers can run in ring mode 0. I actually don´t know much about drivers, but this is what I ask for. I just want to know, is learning how to write your own drivers and than call them the way I should go, to do what I wrote?

I know I could write whole new OS (at least to some point), but what I exactly want to do is acessing some low level features of HW from standart windows application. So, is driver the way to go?

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

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

发布评论

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

评论(2

梦言归人 2024-09-09 16:54:38

简短的回答:是的。

长答案:管理对低级硬件功能的访问正是操作系统内核的工作,如果您只想访问单个功能,则无需从头开始启动自己的操作系统。大多数现代操作系统,例如 WIndows、Linux 或 BSD,都允许您通过内核模块向内核添加代码。

当编写内核模块(或设备驱动程序)时,您编写的代码将在操作系统内核内部执行,因此将在 CPU 环 0 中运行。能力越大,责任越大,在这种情况下,这意味着您应该真正知道你在做什么,因为不会有预先配置的操作系统界面来防止你做错误的事情。因此,您应该研究您的硬件手册(例如,Intel 的 x86 软件开发人员手册、设备规格等)以及标准操作系统开发文献(您还可以在网络上找到大量的资料 - OSDev, OSDeverOSRLinux 设备驱动程序)。

Short answer: yes.

Long answer: Managing access to low-level hardware features is exactly the job of the OS kernel and if you only want access to a single feature there's no need to start your own OS from scratch. Most modern OSes, such as WIndows, Linux, or the BSDs, allow you to add code to the kernel through kernel modules.

When writing a kernel module (or device driver), you write code that is going to be executed inside the OS kernel and will thus be running in CPU ring 0. Great power comes with great responsibility, which in this case means that you should really know what you're doing as there will be no pre-configured OS interface to prevent you from doing the wrong things. You should therefore study the manuals of your hardware (e.g., Intel's x86 software developer's manuals, device specs, ...) as well as standard operating systems development literature (where you're also going to find plenty on the web -- OSDev, OSDever, OSR, Linux Device Drivers).

莫多说 2024-09-09 16:54:38

如果您想使用硬件,请为 16 位实模式编写一些程序(或者甚至您自己过渡到保护模式)。在那里你必须处理 ASM、BIOS 中断、段、视频内存和许多其他低级的东西。

If you want to play with HW write some programs for 16-bit real-mode (or even with your own transition to protected-mode). There you have to deal with ASM, BIOS interrupts, segments, video memory and a lot of other low-level stuff.

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