x86程序集上的保护模式键盘访问

时间:2022-09-01 08:12:14

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.

我的内核现在正在保护模式下运行,因此我不能使用实模式键盘例程而不会跳转到实模式和后退,这是我试图避免的。我希望能够从保护模式访问我的键盘。有谁知道如何做到这一点?到目前为止,我唯一发现的是它涉及使用输入/输出端口直接与控制器通信,但除此之外我感到难过。当然,这不是经常出现的事情。通常,Assembly教程假设您正在运行下面的操作系统。

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?

我是x86程序集的新手,所以我只是在寻找一些好的资源来处理来自保护模式的标准硬件。我正在用NASM编译汇编源代码并将其链接到用DJGPP编译的C源代码。有什么建议?

3 个解决方案

#1


12  

The MIT operating systems class has lots of good references. In particular, check out Adam Chapweske's resources on keyboard and mouse programming.

MIT操作系统类有很多很好的参考。特别是,请查看Adam Chapweske关于键盘和鼠标编程的资源。

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.

简而言之,是的,您将使用原始输入/输出端口,这需要在内核模式下运行,或者在EFLAGS寄存器中设置I / O权限位(IOPL)。有关I / O权限的更多详细信息,请参阅此页面。

#2


3  

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.

您可以在实际和受保护模式下以相同方式使用标准传统硬件。在这种情况下,您希望在I / O端口0x60到0x6f与8042通信,而I / O端口又与电线另一端的键盘内的控制器通信。

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).

一个快速的谷歌搜索在http://heim.ifi.uio.no/~stanisls/helppc/8042.html(8042)和http://heim.ifi.uio.no/~stanisls找到了一个有趣的资源/helppc/keyboard_commands.html(用于键盘)。

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).

如果您不习惯,可以通过IN(读取)和OUT(写入)操作码与I / O端口的组件通信,这些操作码接收I / O端口号(16位值),值为被读或写(8,16或32位)。请注意,读取或写入的大小很重要!将16位写入期望8位的东西(反之亦然)是一种灾难。习惯这些操作码,因为你会经常使用它们(这是与某些外围设备通信的唯一方式,包括几个基本外设;其他外设使用内存映射I / O(MMIO)或总线主控DMA)。

#3


0  

The 8042 PS/2 Controller looks like the simplest possibility.

8042 PS / 2控制器看起来是最简单的可能性。

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

该oszur11操作系统教程包含下https://sourceforge.net/p/oszur11/code/ci/master/tree/Chapter_06_Shell/04_Makepp/arch/i386/arch/devices/i8042.c工作示例

Just:

sudo apt-get install build-essential qemu
sudo ln -s /usr/bin/qemu-system-i386 /usr/bin/qemu
git clone git://git.code.sf.net/p/oszur11/code oszur11
cd oszur11/Chapter_06_Shell/04_Makepp
make qemu

Tested on Ubuntu 14.04 AMD64.

在Ubuntu 14.04 AMD64上测试。

My GitHub mirror (upstream inactive): https://github.com/**/oszur11-operating-system-examples

我的GitHub镜像(上游不活动):https://github.com/**/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.

这里不再复制,因为代码太长了,如果我设法在一个最小的例子中隔离键盘部分,它将更新。

#1


12  

The MIT operating systems class has lots of good references. In particular, check out Adam Chapweske's resources on keyboard and mouse programming.

MIT操作系统类有很多很好的参考。特别是,请查看Adam Chapweske关于键盘和鼠标编程的资源。

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.

简而言之,是的,您将使用原始输入/输出端口,这需要在内核模式下运行,或者在EFLAGS寄存器中设置I / O权限位(IOPL)。有关I / O权限的更多详细信息,请参阅此页面。

#2


3  

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.

您可以在实际和受保护模式下以相同方式使用标准传统硬件。在这种情况下,您希望在I / O端口0x60到0x6f与8042通信,而I / O端口又与电线另一端的键盘内的控制器通信。

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).

一个快速的谷歌搜索在http://heim.ifi.uio.no/~stanisls/helppc/8042.html(8042)和http://heim.ifi.uio.no/~stanisls找到了一个有趣的资源/helppc/keyboard_commands.html(用于键盘)。

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).

如果您不习惯,可以通过IN(读取)和OUT(写入)操作码与I / O端口的组件通信,这些操作码接收I / O端口号(16位值),值为被读或写(8,16或32位)。请注意,读取或写入的大小很重要!将16位写入期望8位的东西(反之亦然)是一种灾难。习惯这些操作码,因为你会经常使用它们(这是与某些外围设备通信的唯一方式,包括几个基本外设;其他外设使用内存映射I / O(MMIO)或总线主控DMA)。

#3


0  

The 8042 PS/2 Controller looks like the simplest possibility.

8042 PS / 2控制器看起来是最简单的可能性。

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

该oszur11操作系统教程包含下https://sourceforge.net/p/oszur11/code/ci/master/tree/Chapter_06_Shell/04_Makepp/arch/i386/arch/devices/i8042.c工作示例

Just:

sudo apt-get install build-essential qemu
sudo ln -s /usr/bin/qemu-system-i386 /usr/bin/qemu
git clone git://git.code.sf.net/p/oszur11/code oszur11
cd oszur11/Chapter_06_Shell/04_Makepp
make qemu

Tested on Ubuntu 14.04 AMD64.

在Ubuntu 14.04 AMD64上测试。

My GitHub mirror (upstream inactive): https://github.com/**/oszur11-operating-system-examples

我的GitHub镜像(上游不活动):https://github.com/**/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.

这里不再复制,因为代码太长了,如果我设法在一个最小的例子中隔离键盘部分,它将更新。