mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:48:12 +00:00
Add IRQHandler class that can be subclasses to handle an IRQ.
Also move Keyboard to a class implementation using this pattern.
This commit is contained in:
parent
8f941561b4
commit
a9ca75c98b
8 changed files with 152 additions and 100 deletions
|
@ -1,11 +1,10 @@
|
|||
#include "types.h"
|
||||
#include "i386.h"
|
||||
#include "IO.h"
|
||||
#include "IPC.h"
|
||||
#include "Task.h"
|
||||
#include "VGA.h"
|
||||
#include "PIC.h"
|
||||
#include "Keyboard.h"
|
||||
#include <AK/Assertions.h>
|
||||
|
||||
#define IRQ_KEYBOARD 1
|
||||
|
||||
|
@ -16,36 +15,6 @@
|
|||
#define DATA_AVAILABLE 0x01
|
||||
#define I8042_ACK 0xFA
|
||||
|
||||
extern "C" void handleKeyboardInterrupt();
|
||||
extern "C" void keyboard_ISR();
|
||||
|
||||
static BYTE s_ledState;
|
||||
|
||||
asm(
|
||||
".globl keyboard_ISR \n"
|
||||
"keyboard_ISR: \n"
|
||||
" pusha\n"
|
||||
" pushw %ds\n"
|
||||
" pushw %es\n"
|
||||
" pushw %ss\n"
|
||||
" pushw %ss\n"
|
||||
" popw %ds\n"
|
||||
" popw %es\n"
|
||||
" call handleKeyboardInterrupt\n"
|
||||
" popw %es\n"
|
||||
" popw %ds\n"
|
||||
" popa\n"
|
||||
" iret\n"
|
||||
);
|
||||
|
||||
void handleKeyboardInterrupt()
|
||||
{
|
||||
IRQHandlerScope scope(IRQ_KEYBOARD);
|
||||
Keyboard::handleInterrupt();
|
||||
}
|
||||
|
||||
namespace Keyboard {
|
||||
|
||||
#define MOD_ALT 1
|
||||
#define MOD_CTRL 2
|
||||
#define MOD_SHIFT 4
|
||||
|
@ -66,19 +35,18 @@ static char shift_map[0x100] =
|
|||
'Z', 'X', 'C', 'V', 'B', 'N', 'M', '<', '>', '?',
|
||||
};
|
||||
|
||||
static BYTE s_modifiers;
|
||||
|
||||
void handleInterrupt()
|
||||
void Keyboard::handleIRQ()
|
||||
{
|
||||
while (IO::in8(0x64) & 1) {
|
||||
BYTE ch = IO::in8(0x60);
|
||||
switch (ch) {
|
||||
case 0x38: s_modifiers |= MOD_ALT; break;
|
||||
case 0xB8: s_modifiers &= ~MOD_ALT; break;
|
||||
case 0x1D: s_modifiers |= MOD_CTRL; break;
|
||||
case 0x9D: s_modifiers &= ~MOD_CTRL; break;
|
||||
case 0x2A: s_modifiers |= MOD_SHIFT; break;
|
||||
case 0xAA: s_modifiers &= ~MOD_SHIFT; break;
|
||||
case 0x38: m_modifiers |= MOD_ALT; break;
|
||||
case 0xB8: m_modifiers &= ~MOD_ALT; break;
|
||||
case 0x1D: m_modifiers |= MOD_CTRL; break;
|
||||
case 0x9D: m_modifiers &= ~MOD_CTRL; break;
|
||||
case 0x2A: m_modifiers |= MOD_SHIFT; break;
|
||||
case 0xAA: m_modifiers &= ~MOD_SHIFT; break;
|
||||
case 0x1C: /* enter */ kprintf("\n"); break;
|
||||
case 0xFA: /* i8042 ack */ break;
|
||||
default:
|
||||
|
@ -86,50 +54,30 @@ void handleInterrupt()
|
|||
// key has been depressed
|
||||
break;
|
||||
}
|
||||
if (!s_modifiers)
|
||||
if (!m_modifiers)
|
||||
kprintf("%c", map[ch]);
|
||||
else if (s_modifiers & MOD_SHIFT)
|
||||
else if (m_modifiers & MOD_SHIFT)
|
||||
kprintf("%c", shift_map[ch]);
|
||||
else if (s_modifiers & MOD_CTRL)
|
||||
else if (m_modifiers & MOD_CTRL)
|
||||
kprintf("^%c", shift_map[ch]);
|
||||
}
|
||||
//break;
|
||||
}
|
||||
}
|
||||
|
||||
void initialize()
|
||||
Keyboard::Keyboard()
|
||||
: IRQHandler(IRQ_KEYBOARD)
|
||||
{
|
||||
s_modifiers = 0;
|
||||
s_ledState = 0;
|
||||
|
||||
// Empty the buffer of any pending data.
|
||||
// I don't care what you've been pressing until now!
|
||||
while (IO::in8(I8042_STATUS ) & DATA_AVAILABLE)
|
||||
IO::in8(I8042_BUFFER);
|
||||
|
||||
registerInterruptHandler(IRQ_VECTOR_BASE + IRQ_KEYBOARD, keyboard_ISR);
|
||||
|
||||
PIC::enable(IRQ_KEYBOARD);
|
||||
enableIRQ();
|
||||
}
|
||||
|
||||
void setLED(LED led)
|
||||
Keyboard::~Keyboard()
|
||||
{
|
||||
s_ledState |= (BYTE)led & 7;
|
||||
|
||||
while (IO::in8(I8042_STATUS) & DATA_AVAILABLE);
|
||||
IO::out8(I8042_BUFFER, SET_LEDS);
|
||||
while (IO::in8(I8042_BUFFER) != I8042_ACK);
|
||||
IO::out8(I8042_BUFFER, s_ledState);
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
|
||||
void unsetLED(LED led)
|
||||
{
|
||||
s_ledState &= ~((BYTE)led & 7);
|
||||
|
||||
while (IO::in8(I8042_STATUS) & DATA_AVAILABLE);
|
||||
IO::out8(I8042_BUFFER, SET_LEDS);
|
||||
while (IO::in8(I8042_BUFFER) != I8042_ACK);
|
||||
IO::out8(I8042_BUFFER, s_ledState);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue