How to handle the keyboard in real mode through BIOS interrupts?

I need to code for an operating system on which I can run calculater. It looks like a desktop calculator. For this, I am reading the brokenthorn series . I completed the second stage

+5
source share
3 answers

If you want to use the high-level keyboard keyboard services, rather than handle keyboard interrupts, then INT 16hthis is what you want.

INT 16hc AH=00hor 10hwill block waiting for a keypress (returns ASCII result in AL); use AH=01hor 11hto request whether a key press is available if you want to avoid blocking (immediately returns using ZFclear if the key is available, or set if not). See here or here (or google "INT 16h" for more).

+8
source

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

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

+3
source

BIOS :

.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

make run RUN=bios_keyboard.

Then, when you enter a character, it is printed on the screen.

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

+1
source

All Articles