x86 组件上的保护模式键盘访问
我正在为我正在开发的一个非常基本的内核进行键盘输入,但我完全陷入困境。 我似乎无法在网上找到任何可以向我展示我需要了解的信息的信息。
我的内核现在正在保护模式下运行,因此如果不跳入实模式并返回,我就无法使用实模式键盘例程,这是我试图避免的。 我希望能够从保护模式访问我的键盘。 有谁知道如何做到这一点? 到目前为止,我发现的唯一一件事是它涉及使用输入/输出端口直接与控制器对话,但除此之外我还很难过。 当然,这并不是经常出现的事情。 通常,汇编教程假设您正在运行一个操作系统。
我对 x86 程序集非常陌生,所以我只是在寻找一些好的资源来使用保护模式下的标准硬件。 我正在使用 NASM 编译汇编源代码,并将其链接到使用 DJGPP 编译的 C 源代码。 有什么建议么?
I'm working on keyboard input for a very basic kernel that I'm developing and I'm completely stuck. I can't seem to find any information online that can show me the information I need to know.
My kernel is running in protected mode right now, so I can't use the real mode keyboard routines without jumping into real mode and back, which I'm trying to avoid. I want to be able to access my keyboard from protected mode. Does anyone know how to do this? The only thing I have found so far is that it involves talking to the controller directly using in/out ports, but beyond that I'm stumped. This is, of course, is not something that comes up very often. Normally, Assembly tutorials assume you're running an operating system underneath.
I'm very new to the x86 assembly, so I'm just looking for some good resources for working with the standard hardware from protected mode. I'm compiling the Assembly source code with NASM and linking it to the C source code compiled with DJGPP. Any suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
MIT 操作系统课程 有很多很好的参考资料。 特别是,请查看 Adam Chapweske 的有关键盘和鼠标编程的资源。
简而言之,是的,您将使用原始输入/输出端口,这需要在内核模式下运行,或者在 EFLAGS 寄存器中设置 I/O 权限位 (IOPL)。 有关 I/O 权限的更多详细信息,请参阅此页面 。
The MIT operating systems class has lots of good references. In particular, check out Adam Chapweske's resources on keyboard and mouse programming.
In short, yes, you will be using the raw in/out ports, which requires either running in kernel mode, or having the I/O permission bits (IOPL) set in the EFLAGS register. See this page for more details on I/O permissions.
您可以在实模式和保护模式下以相同的方式使用标准旧硬件。 在本例中,您希望与 I/O 端口 0x60 至 0x6f 处的 8042 通信,而 8042 又将与线路另一端键盘内的控制器通信。
快速谷歌搜索发现我在 http://heim.ifi .uio.no/~stanisls/helppc/8042.html(对于 8042)和 http://heim.ifi.uio.no/~stanisls/helppc/keyboard_commands.html(对于键盘)。
如果您不习惯,可以通过 IN(读)和 OUT(写)操作码与 I/O 端口上的组件进行通信,这些操作码接收 I/O 端口号(16 位值)和要发送的值。可以读取或写入(8、16 或 32 位)。 请注意,读取或写入的大小很重要! 将 16 位写入需要 8 位的内容(反之亦然)会导致灾难。 习惯这些操作码,因为您将经常使用它们(这是与某些外设通信的唯一方法,包括几个基本外设;其他外设使用内存映射 I/O (MMIO) 或总线主控 DMA)。
You work with standard legacy hardware the same way on real and protected modes. In this case, you want to talk with the 8042 at I/O ports 0x60 to 0x6f, which in turn will talk to the controller within the keyboard at the other end of the wire.
A quick Google search found me an interesting resource at http://heim.ifi.uio.no/~stanisls/helppc/8042.html (for the 8042) and http://heim.ifi.uio.no/~stanisls/helppc/keyboard_commands.html (for the keyboard).
In case you are not used to it, you talk with components at I/O ports via the IN (read) and OUT (write) opcodes, which receive the I/O port number (a 16-bit value) and the value to be read or written (either 8, 16, or 32 bits). Note that the size read or written is important! Writing 16 bits to something which is expecting 8 bits (or vice versa) is a recipe for disaster. Get used to these opcodes, since you will be using them a lot (it is the only way to talk to some peripherals, including several essential ones; other peripherals use memory-mapped I/O (MMIO) or bus-mastering DMA).
8042 PS/2 控制器看起来是最简单的可能性。
oszur11 操作系统教程在 https://sourceforge.net/p/oszur11/code/ci/master/tree/Chapter_06_Shell/04_Makepp/arch/i386/arch/devices/i8042.c
刚刚:
在 Ubuntu 上测试14.04 AMD64。
我的 GitHub 镜像(上游不活动): https://github.com/cirosantilli/oszur11-operating -system-examples
不在这里复制它,因为代码太长,如果我设法在一个最小的示例中隔离键盘部分,将会更新。
The 8042 PS/2 Controller looks like the simplest possibility.
The oszur11 OS tutorial contains a working example under https://sourceforge.net/p/oszur11/code/ci/master/tree/Chapter_06_Shell/04_Makepp/arch/i386/arch/devices/i8042.c
Just:
Tested on Ubuntu 14.04 AMD64.
My GitHub mirror (upstream inactive): https://github.com/cirosantilli/oszur11-operating-system-examples
Not reproducing it here because the code it too long, will update if I manage to isolate the keyboard part in a minimal example.