如何通过BIOS中断在实模式下处理键盘?

发布于 2024-10-01 02:38:23 字数 434 浏览 4 评论 0原文

我必须为一个可以运行计算器的操作系统编写代码。它就像一个桌面计算器。为此,我正在阅读 brokenthorn 操作开发系列 我已经完成了 引导加载程序的第二阶段 引导加载程序处于实模式。接下来作者正在解释保护模式。我不想使用保护模式。我没有时间做那个。所以我想通过使用BIOS中断以实模式编写计算器。是否可以?我认为它可以写在引导加载程序的第二阶段(我不确定。)意味着我不必使用内核(我不确定)。我不知道如何使用BIOS中断来处理键盘。有人可以给我提供一个可以帮助我的链接吗?如果我上面的假设有任何错误,请纠正我。提前致谢。

I have to code for a operating system on which I can run a calculater.It is like a desktop calculater. For this I am reading the brokenthorn operating development series I have completed the second stage of bootloader The bootloader is in real mode. After this the author is explaining the protected mode. I don't want to use the protected mode. I don't have time for that. So I want to write the calculater in real mode by using bios interrupts. Is it possible? I think it can be written on the second stage of the bootloader(I am not sure.) Means I don't have to use a kernel(I am not sure). I don't know how to use BIOS interrupts to handle the keyboard. Can anybody provide me a link which will help me in this? And If anything wrong in whatevet I assumed above is wrong, please correct me.Thanks in advance.

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

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

发布评论

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

评论(3

烟─花易冷 2024-10-08 02:38:23

如果您想使用高级 BIOS 键盘服务,而不是自己处理键盘中断,那么 INT 16h 就是您想要的。

INT 16hAH=00h10h 将阻塞等待按键(在 AL 中返回 ASCII 结果);如果要避免阻塞,请先使用 AH=01h11h 查询按键是否可用(如果有按键,则立即返回 ZF 清除)可用,否则设置)。请参阅此处,或此处(或 Google“INT 16h”了解更多信息)。

If you want to use high-level BIOS keyboard services, rather than handling the keyboard interrupts yourself, then INT 16h is what you want.

INT 16h with AH=00h or 10h will block waiting for a keypress (returns ASCII result in AL); use AH=01h or 11h to query whether a keypress is available first if you want to avoid blocking (returns immediately with ZF clear if a key is available, or set if not). See e.g. here, or here (or Google "INT 16h" for more).

送舟行 2024-10-08 02:38:23

您可以处理 IRQ 1(由 x86 控制器映射到中断 9)并从端口 60h 读取密钥。

请参阅http://inglorion.net/documents/tutorials/x86ostut/keyboard/

You can handle IRQ 1 (mapped to interrupt 9 by the x86 controller) and read the keys from port 60h.

See http://inglorion.net/documents/tutorials/x86ostut/keyboard/.

十雾 2024-10-08 02:38:23

最小 GAS 引导扇区 BIOS 示例

当您输入字符时,它会打印到屏幕上。

main.S

.code16
.global _start
_start:
cli

/* Set SS and SP as they may get used by BIOS calls. */
xor %ax, %ax
mov %ax, %ss
mov $0x0000, %sp

/* Get input to %al */
mov $0x00, %ah
int $0x16

/* Print the input from %al */
mov $0x0E, %ah
int $0x10

hlt

.org 510
.word 0xaa55

编译并运行:

as -o main.o main.S
ld --oformat binary -o main.img -Ttext 0x7C00 main.o
qemu-system-i386 -hda main.img

GitHub 上游

在 Ubuntu 14.04 AMD64、Binutils 2.24、QEMU 2.0.0 和真实硬件 Lenovo Thinkpad T400 上进行了测试。

Minimal GAS boot sector BIOS example

When you enter a character, it gets printed to the screen.

main.S

.code16
.global _start
_start:
cli

/* Set SS and SP as they may get used by BIOS calls. */
xor %ax, %ax
mov %ax, %ss
mov $0x0000, %sp

/* Get input to %al */
mov $0x00, %ah
int $0x16

/* Print the input from %al */
mov $0x0E, %ah
int $0x10

hlt

.org 510
.word 0xaa55

Compile and run:

as -o main.o main.S
ld --oformat binary -o main.img -Ttext 0x7C00 main.o
qemu-system-i386 -hda main.img

GitHub upstream.

Tested on Ubuntu 14.04 AMD64, Binutils 2.24, QEMU 2.0.0 and on real hardware Lenovo Thinkpad T400.

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