#include <Input/Keyboard/include/keyboard.h>
#include "keymap_int.h"
#include "layout_kbdus.h"
-#include <hal_proc.h>
+#include <debug_hooks.h>
#define USE_KERNEL_MAGIC 1
-// === IMPORTS ===
-#if USE_KERNEL_MAGIC
-extern void Threads_ToggleTrace(int TID);
-extern void Threads_Dump(void);
-extern void Heap_Stats(void);
-#endif
+extern void Validate_VirtualMemoryUsage(void);
// === PROTOTYPES ===
int Keyboard_Install(char **Arguments);
-void Keyboard_Cleanup(void);
+ int Keyboard_Cleanup(void);
// - Internal
tKeymap *Keyboard_LoadMap(const char *Name);
void Keyboard_FreeMap(tKeymap *Keymap);
{ .Type = &gKB_NodeType }
};
#if USE_KERNEL_MAGIC
- int giKB_MagicAddress = 0;
- int giKB_MagicAddressPos = 0;
+tDebugHook gKB_DebugHookInfo;
#endif
// === CODE ===
/**
* \brief Pre-unload cleanup function
*/
-void Keyboard_Cleanup(void)
+int Keyboard_Cleanup(void)
{
// TODO: Do I need this?
+ return 0;
}
// --- Map Management ---
*/
tKeyboard *Keyboard_CreateInstance(int MaxSym, const char *Name)
{
- tKeyboard *ret;
- int sym_bitmap_size = (MaxSym + 7)/8;
- int string_size = strlen(Name) + 1;
+ size_t sym_bitmap_size = (MaxSym + 7)/8;
+ size_t string_size = strlen(Name) + 1;
- ret = malloc( sizeof(tKeyboard) + sym_bitmap_size + string_size );
+ tKeyboard *ret = calloc( 1, sizeof(tKeyboard) + sym_bitmap_size + string_size );
if( !ret ) {
return NULL;
}
- // Clear
- memset(ret, 0, sizeof(tKeyboard) + sym_bitmap_size );
// Set name
- ret->Name = (char*)ret + sizeof(tKeyboard) + sym_bitmap_size;
- memcpy(ret->Name, Name, string_size);
+ ret->Name = (char*)( &ret->KeyStates[sym_bitmap_size] );
+ strcpy(ret->Name, Name);
// Set node and default keymap
ret->Node = &gKB_DevInfo.RootNode;
ret->Keymap = &gKeymap_KBDUS;
Log_Error("Keyboard", "TODO: Implement Keyboard_RemoveInstance");
}
+inline bool IsPressed(tKeyboard *Kb, Uint8 KeySym)
+{
+ return !!(Kb->KeyStates[KeySym/8] & (1 << (KeySym&7)));
+}
+
/*
* Handle a key press/release event
* - See Input/Keyboard/include/keyboard.h
Uint32 flag;
Uint8 layer;
+ if( !Source ) {
+ Log_Error("Keyboard", "Passed NULL handle");
+ return ;
+ }
+ if( !Source->Node ) {
+ Log_Error("Keyboard", "Passed handle with NULL node");
+ return ;
+ }
+
bPressed = !(HIDKeySym & (1 << 31));
HIDKeySym &= 0x7FFFFFFF;
break;
}
- // --- Check for Kernel Magic Combos
+ // Magic debug hooks
#if USE_KERNEL_MAGIC
+ if(bPressed && IsPressed(Source, KEYSYM_LEFTCTRL) && IsPressed(Source, KEYSYM_LEFTALT))
+ {
+ if( trans == '~' ) {
+ // TODO: Latch mode
+ }
+ else {
+ char str[5]; // utf8 only supports 8 bytes
+ size_t len = WriteUTF8((Uint8*)str, trans);
+ str[len] = '\0';
+ DebugHook_HandleInput(&gKB_DebugHookInfo, len, str);
+ }
+ return ;
+ }
+ #endif
+
+ // Ctrl-Alt-Del == Reboot
+ #if defined(ARCHDIR_is_x86) || defined(ARCHDIR_is_x86_64)
if(bPressed
- && Source->KeyStates[KEYSYM_LEFTCTRL/8] & (1 << (KEYSYM_LEFTCTRL&7))
- && Source->KeyStates[KEYSYM_LEFTALT/8] & (1 << (KEYSYM_LEFTALT &7)) )
+ && (IsPressed(Source, KEYSYM_LEFTCTRL) || IsPressed(Source, KEYSYM_RIGHTCTRL))
+ && (IsPressed(Source, KEYSYM_LEFTALT) || IsPressed(Source, KEYSYM_LEFTALT))
+ )
{
- int val;
- switch(trans)
+ if( HIDKeySym == KEYSYM_DELETE )
{
- case '0': val = 0; goto _av; case '1': val = 1; goto _av;
- case '2': val = 2; goto _av; case '3': val = 3; goto _av;
- case '4': val = 4; goto _av; case '5': val = 5; goto _av;
- case '6': val = 6; goto _av; case '7': val = 7; goto _av;
- case '8': val = 8; goto _av; case '9': val = 9; goto _av;
- case 'a': val = 10; goto _av; case 'b': val = 11; goto _av;
- case 'c': val = 12; goto _av; case 'd': val = 13; goto _av;
- case 'e': val = 14; goto _av; case 'f': val = 15; goto _av;
- _av:
- if(giKB_MagicAddressPos == BITS/4) break;
- giKB_MagicAddress |= (Uint)val << giKB_MagicAddressPos;
- giKB_MagicAddressPos ++;
- break;
-
- // Instruction Tracing
- case 't':
- Log("Toggle instruction tracing on %i\n", giKB_MagicAddress);
- Threads_ToggleTrace( giKB_MagicAddress );
- giKB_MagicAddress = 0; giKB_MagicAddressPos = 0;
- return;
-
- // Thread List Dump
- case 'p': Threads_Dump(); return;
- // Heap Statistics
- case 'h': Heap_Stats(); return;
- // PMem Statistics
- case 'm': MM_DumpStatistics(); return;
- // Dump Structure
- case 's': return;
+ // Trigger triple fault
+ __asm__ __volatile__ ("lgdt (%esp) ; int $0x0");
+ for(;;);
}
}
#endif