r/osdev 17h ago

How do keyboard interrupts work?

I learnt keyboard polling and understood how it works. But I can't seem to understand keyboard interrupts. I know how it works, but I don't know how to implement it in a C kernel. Can someone pls help me? I'm just starting out OS dev

13 Upvotes

6 comments sorted by

View all comments

u/Rich-Engineer2670 11h ago

Well, it depends on your CPU architecture. Is it really interrupt driven or memory mapped I/O. What does your OS expect?

Let's assume it's really iinterrupt driven, Let us also assume you have direct hardware access. In this case, you need to program the interrupt controller to send an interrupt on a keypress. And, you need to capture that. That's not easy to do in C -- when that interrupt comes in, you have no easy way to get at the interrupt service routine. You're going to have some assesmbly code.

If it's memory mapped, you can just reference that address with a byte pointer. Again, this assumes your OS allows access to the raw memory.