如何通过BIOS中断在实模式下处理键盘?
我必须为一个可以运行计算器的操作系统编写代码。它就像一个桌面计算器。为此,我正在阅读 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您想使用高级 BIOS 键盘服务,而不是自己处理键盘中断,那么 INT 16h 就是您想要的。
INT 16h
与AH=00h
或10h
将阻塞等待按键(在AL
中返回 ASCII 结果);如果要避免阻塞,请先使用AH=01h
或11h
查询按键是否可用(如果有按键,则立即返回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
withAH=00h
or10h
will block waiting for a keypress (returns ASCII result inAL
); useAH=01h
or11h
to query whether a keypress is available first if you want to avoid blocking (returns immediately withZF
clear if a key is available, or set if not). See e.g. here, or here (or Google "INT 16h" for more).您可以处理 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/.
最小 GAS 引导扇区 BIOS 示例
当您输入字符时,它会打印到屏幕上。
main.S
编译并运行:
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
Compile and run:
GitHub upstream.
Tested on Ubuntu 14.04 AMD64, Binutils 2.24, QEMU 2.0.0 and on real hardware Lenovo Thinkpad T400.