mirror of
https://github.com/Fennix-Project/Kernel.git
synced 2025-05-27 15:04:33 +00:00
Update crash keyboard driver
This commit is contained in:
parent
85c0de688d
commit
3b65386399
@ -35,160 +35,155 @@
|
|||||||
#include "../../kernel.h"
|
#include "../../kernel.h"
|
||||||
|
|
||||||
const char sc_ascii_low[] = {'?', '?', '1', '2', '3', '4', '5', '6',
|
const char sc_ascii_low[] = {'?', '?', '1', '2', '3', '4', '5', '6',
|
||||||
'7', '8', '9', '0', '-', '=', '?', '?', 'q', 'w', 'e', 'r', 't', 'y',
|
'7', '8', '9', '0', '-', '=', '?', '?', 'q', 'w', 'e', 'r', 't', 'y',
|
||||||
'u', 'i', 'o', 'p', '[', ']', '?', '?', 'a', 's', 'd', 'f', 'g',
|
'u', 'i', 'o', 'p', '[', ']', '?', '?', 'a', 's', 'd', 'f', 'g',
|
||||||
'h', 'j', 'k', 'l', ';', '\'', '`', '?', '\\', 'z', 'x', 'c', 'v',
|
'h', 'j', 'k', 'l', ';', '\'', '`', '?', '\\', 'z', 'x', 'c', 'v',
|
||||||
'b', 'n', 'm', ',', '.', '/', '?', '?', '?', ' '};
|
'b', 'n', 'm', ',', '.', '/', '?', '?', '?', ' '};
|
||||||
|
|
||||||
const char sc_ascii_high[] = {'?', '?', '!', '@', '#', '$', '%', '^',
|
const char sc_ascii_high[] = {'?', '?', '!', '@', '#', '$', '%', '^',
|
||||||
'&', '*', '(', ')', '_', '+', '?', '?', 'Q', 'W', 'E', 'R', 'T', 'Y',
|
'&', '*', '(', ')', '_', '+', '?', '?', 'Q', 'W', 'E', 'R', 'T', 'Y',
|
||||||
'U', 'I', 'O', 'P', '{', '}', '?', '?', 'A', 'S', 'D', 'F', 'G',
|
'U', 'I', 'O', 'P', '{', '}', '?', '?', 'A', 'S', 'D', 'F', 'G',
|
||||||
'H', 'J', 'K', 'L', ';', '\"', '~', '?', '|', 'Z', 'X', 'C', 'V',
|
'H', 'J', 'K', 'L', ';', '\"', '~', '?', '|', 'Z', 'X', 'C', 'V',
|
||||||
'B', 'N', 'M', '<', '>', '?', '?', '?', '?', ' '};
|
'B', 'N', 'M', '<', '>', '?', '?', '?', '?', ' '};
|
||||||
|
|
||||||
static int LowerCase = true;
|
static int LowerCase = true;
|
||||||
|
|
||||||
static inline int GetLetterFromScanCode(uint8_t ScanCode)
|
static inline int GetLetterFromScanCode(uint8_t ScanCode)
|
||||||
{
|
{
|
||||||
if (ScanCode & 0x80)
|
if (ScanCode & 0x80)
|
||||||
{
|
{
|
||||||
switch (ScanCode)
|
switch (ScanCode)
|
||||||
{
|
{
|
||||||
case KEY_U_LSHIFT:
|
case KEY_U_LSHIFT:
|
||||||
LowerCase = true;
|
LowerCase = true;
|
||||||
return KEY_INVALID;
|
return KEY_INVALID;
|
||||||
case KEY_U_RSHIFT:
|
case KEY_U_RSHIFT:
|
||||||
LowerCase = true;
|
LowerCase = true;
|
||||||
return KEY_INVALID;
|
return KEY_INVALID;
|
||||||
default:
|
default:
|
||||||
return KEY_INVALID;
|
return KEY_INVALID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
switch (ScanCode)
|
switch (ScanCode)
|
||||||
{
|
{
|
||||||
case KEY_D_RETURN:
|
case KEY_D_RETURN:
|
||||||
return '\n';
|
return '\n';
|
||||||
case KEY_D_LSHIFT:
|
case KEY_D_LSHIFT:
|
||||||
LowerCase = false;
|
LowerCase = false;
|
||||||
return KEY_INVALID;
|
return KEY_INVALID;
|
||||||
case KEY_D_RSHIFT:
|
case KEY_D_RSHIFT:
|
||||||
LowerCase = false;
|
LowerCase = false;
|
||||||
return KEY_INVALID;
|
return KEY_INVALID;
|
||||||
case KEY_D_BACKSPACE:
|
case KEY_D_BACKSPACE:
|
||||||
return ScanCode;
|
return ScanCode;
|
||||||
default:
|
default:
|
||||||
{
|
{
|
||||||
if (ScanCode > 0x39)
|
if (ScanCode > 0x39)
|
||||||
break;
|
break;
|
||||||
if (LowerCase)
|
if (LowerCase)
|
||||||
return sc_ascii_low[ScanCode];
|
return sc_ascii_low[ScanCode];
|
||||||
else
|
else
|
||||||
return sc_ascii_high[ScanCode];
|
return sc_ascii_high[ScanCode];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return KEY_INVALID;
|
return KEY_INVALID;
|
||||||
}
|
}
|
||||||
|
|
||||||
namespace CrashHandler
|
namespace CrashHandler
|
||||||
{
|
{
|
||||||
CrashKeyboardDriver::CrashKeyboardDriver() : Interrupts::Handler(1) /* IRQ1 */
|
CrashKeyboardDriver::CrashKeyboardDriver() : Interrupts::Handler(1) /* IRQ1 */
|
||||||
{
|
{
|
||||||
#if defined(a86)
|
#if defined(a86)
|
||||||
while (inb(0x64) & 0x1)
|
while (inb(0x64) & 0x1)
|
||||||
inb(0x60);
|
inb(0x60);
|
||||||
|
|
||||||
outb(0x64, 0xAE);
|
outb(0x64, 0xAE);
|
||||||
outb(0x64, 0x20);
|
outb(0x64, 0x20);
|
||||||
uint8_t ret = (inb(0x60) | 1) & ~0x10;
|
uint8_t ret = (inb(0x60) | 1) & ~0x10;
|
||||||
outb(0x64, 0x60);
|
outb(0x64, 0x60);
|
||||||
outb(0x60, ret);
|
outb(0x60, ret);
|
||||||
outb(0x60, 0xF4);
|
outb(0x60, 0xF4);
|
||||||
|
|
||||||
outb(0x21, 0xFD);
|
outb(0x21, 0xFD);
|
||||||
outb(0xA1, 0xFF);
|
outb(0xA1, 0xFF);
|
||||||
#endif // defined(a86)
|
#endif // defined(a86)
|
||||||
|
|
||||||
CPU::Interrupts(CPU::Enable); // Just to be sure.
|
CPU::Interrupts(CPU::Enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
CrashKeyboardDriver::~CrashKeyboardDriver()
|
CrashKeyboardDriver::~CrashKeyboardDriver()
|
||||||
{
|
{
|
||||||
error("CrashKeyboardDriver::~CrashKeyboardDriver() called!");
|
error("CrashKeyboardDriver::~CrashKeyboardDriver() called!");
|
||||||
}
|
}
|
||||||
|
|
||||||
int BackSpaceLimit = 0;
|
int BackSpaceLimit = 0;
|
||||||
static char UserInputBuffer[1024];
|
static char UserInputBuffer[1024];
|
||||||
|
|
||||||
#if defined(a64)
|
#if defined(a64)
|
||||||
SafeFunction void CrashKeyboardDriver::OnInterruptReceived(CPU::x64::TrapFrame *Frame)
|
SafeFunction void CrashKeyboardDriver::OnInterruptReceived(CPU::x64::TrapFrame *Frame)
|
||||||
#elif defined(a32)
|
#elif defined(a32)
|
||||||
SafeFunction void CrashKeyboardDriver::OnInterruptReceived(CPU::x32::TrapFrame *Frame)
|
SafeFunction void CrashKeyboardDriver::OnInterruptReceived(CPU::x32::TrapFrame *Frame)
|
||||||
#elif defined(aa64)
|
#elif defined(aa64)
|
||||||
SafeFunction void CrashKeyboardDriver::OnInterruptReceived(CPU::aarch64::TrapFrame *Frame)
|
SafeFunction void CrashKeyboardDriver::OnInterruptReceived(CPU::aarch64::TrapFrame *Frame)
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
#if defined(a86)
|
#if defined(a86)
|
||||||
UNUSED(Frame);
|
UNUSED(Frame);
|
||||||
uint8_t scanCode = inb(0x60);
|
uint8_t scanCode = inb(0x60);
|
||||||
if (scanCode == KEY_D_TAB ||
|
if (scanCode == KEY_D_TAB ||
|
||||||
scanCode == KEY_D_LCTRL ||
|
scanCode == KEY_D_LCTRL ||
|
||||||
scanCode == KEY_D_LALT ||
|
scanCode == KEY_D_LALT ||
|
||||||
scanCode == KEY_U_LCTRL ||
|
scanCode == KEY_U_LCTRL ||
|
||||||
scanCode == KEY_U_LALT)
|
scanCode == KEY_U_LALT)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
switch (scanCode)
|
switch (scanCode)
|
||||||
{
|
{
|
||||||
case KEY_D_UP:
|
case KEY_D_UP:
|
||||||
case KEY_D_LEFT:
|
case KEY_D_LEFT:
|
||||||
case KEY_D_RIGHT:
|
case KEY_D_RIGHT:
|
||||||
case KEY_D_DOWN:
|
case KEY_D_DOWN:
|
||||||
ArrowInput(scanCode);
|
ArrowInput(scanCode);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
int key = GetLetterFromScanCode(scanCode);
|
int key = GetLetterFromScanCode(scanCode);
|
||||||
if (key != KEY_INVALID)
|
if (key != KEY_INVALID)
|
||||||
{
|
{
|
||||||
if (key == KEY_D_BACKSPACE)
|
if (key == KEY_D_BACKSPACE)
|
||||||
{
|
{
|
||||||
if (BackSpaceLimit > 0)
|
if (BackSpaceLimit > 0)
|
||||||
{
|
{
|
||||||
Display->Print('\b', SBIdx);
|
Display->Print('\b', SBIdx);
|
||||||
backspace(UserInputBuffer);
|
backspace(UserInputBuffer);
|
||||||
BackSpaceLimit--;
|
BackSpaceLimit--;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (key == '\n')
|
else if (key == '\n')
|
||||||
{
|
{
|
||||||
UserInput(UserInputBuffer);
|
UserInput(UserInputBuffer);
|
||||||
BackSpaceLimit = 0;
|
BackSpaceLimit = 0;
|
||||||
UserInputBuffer[0] = '\0';
|
UserInputBuffer[0] = '\0';
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
append(UserInputBuffer, s_cst(char, key));
|
append(UserInputBuffer, s_cst(char, key));
|
||||||
Display->Print((char)key, SBIdx);
|
Display->Print((char)key, SBIdx);
|
||||||
BackSpaceLimit++;
|
BackSpaceLimit++;
|
||||||
}
|
}
|
||||||
Display->SetBuffer(SBIdx); // Update as we type.
|
Display->SetBuffer(SBIdx); /* Update as we type. */
|
||||||
}
|
}
|
||||||
#endif // a64 || a32
|
#endif // a64 || a32
|
||||||
}
|
}
|
||||||
|
|
||||||
SafeFunction void HookKeyboard()
|
SafeFunction void HookKeyboard()
|
||||||
{
|
{
|
||||||
CrashKeyboardDriver kbd; // We don't want to allocate memory.
|
CrashKeyboardDriver kbd; /* We don't want to allocate memory. */
|
||||||
#if defined(a86)
|
CPU::Halt(true);
|
||||||
asmv("KeyboardHookLoop: nop; jmp KeyboardHookLoop;");
|
}
|
||||||
#elif defined(aa64)
|
|
||||||
asmv("KeyboardHookLoop: nop; b KeyboardHookLoop;");
|
|
||||||
#endif
|
|
||||||
// CPU::Halt(true); // This is an infinite loop.
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user