Kernel - Move debug hooks to common handler
authorJohn Hodge <[email protected]>
Sat, 15 Mar 2014 09:13:01 +0000 (17:13 +0800)
committerJohn Hodge <[email protected]>
Sat, 15 Mar 2014 09:13:01 +0000 (17:13 +0800)
KernelLand/Kernel/Makefile
KernelLand/Kernel/debug_hooks.c [new file with mode: 0644]
KernelLand/Kernel/drv/serial.c
KernelLand/Kernel/include/debug_hooks.h
KernelLand/Modules/Input/Keyboard/main.c

index fde1bda..cc4f230 100644 (file)
@@ -55,7 +55,7 @@ BUILDINFO_SRC := $(OBJDIR)buildinfo.c$(OBJSUFFIX)
 
 OBJ := $(addprefix arch/$(ARCHDIR)/,$(A_OBJ))
 OBJ += pmemmap.o
-OBJ += heap.o logging.o debug.o lib.o libc.o adt.o time.o utf16.o
+OBJ += heap.o logging.o debug.o lib.o libc.o adt.o time.o utf16.o debug_hooks.o
 OBJ += drvutil_video.o drvutil_disk.o
 OBJ += messages.o modules.o syscalls.o system.o
 OBJ += threads.o mutex.o semaphore.o workqueue.o events.o rwlock.o
diff --git a/KernelLand/Kernel/debug_hooks.c b/KernelLand/Kernel/debug_hooks.c
new file mode 100644 (file)
index 0000000..cc54b67
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * Acess2 Kernel
+ * - By John Hodge (thePowersGang)
+ * 
+ * debug_hooks.c
+ * - Keyboard/serial kernel debug hooks
+ */
+#include <acess.h>
+#include <debug_hooks.h>
+
+// === CODE ===
+void DebugHook_HandleInput(tDebugHook *HookHandle, size_t Length, const char *Input)
+{
+       switch(*Input)
+       {
+       case '0' ... '9':
+               HookHandle->Value *= 10;
+               HookHandle->Value += *Input - '0';
+               break;
+       // Instruction Tracing
+       case 't':
+               Log("Toggle instruction tracing on %i\n", HookHandle->Value);
+               Threads_ToggleTrace( HookHandle->Value );
+               HookHandle->Value = 0;
+               break;
+       
+       // 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;
+       
+       // Validate structures
+       //case 'v':
+       //      Validate_VirtualMemoryUsage();
+       //      return;
+       }
+}
+
index 2792df9..bc7597e 100644 (file)
@@ -12,6 +12,8 @@
 #include <drv_pty.h>
 #include <debug_hooks.h>
 
+extern void    Validate_VirtualMemoryUsage(void);
+
 // === TYPES ===
 struct sSerialPort
 {
@@ -67,23 +69,32 @@ void Serial_ByteReceived(tSerialPort *Port, char Ch)
                return ;
        if( Port == gSerial_KernelDebugPort )
        {
+               static tDebugHook       info;
                static int serial_debug_mode = 0;
                // Kernel serial debug hooks.
-               if( serial_debug_mode )
+               if( serial_debug_mode == 2 )
+               {
+                       // Leave latched mode
+                       if( Ch == '.' )
+                               serial_debug_mode = 0;
+                       else
+                               DebugHook_HandleInput(&info, 1, &Ch);
+                       return ;
+               }
+               else if( serial_debug_mode )
                {
-                       switch(Ch)
-                       {
-                       case 'p':
-                               Threads_Dump();
-                               break;
-                       case 'h':
-                               Heap_Dump();
-                               break;
-                       case 'X'-'A'+1:
+                       if( Ch == 'X'-'A'+1 ) {
                                PTY_SendInput(Port->PTY, &Ch, 1);
-                               break;
+                               serial_debug_mode = 0;
+                       }
+                       else if( Ch == '~' ) {
+                               // Enter latched mode
+                               serial_debug_mode = 2;
+                       }
+                       else {
+                               DebugHook_HandleInput(&info, 1, &Ch);
+                               serial_debug_mode = 0;
                        }
-                       serial_debug_mode = 0;
                        return ;
                }
                else if( Ch == 'X'-'A'+1 )
index befcd5d..27df6cf 100644 (file)
@@ -8,6 +8,15 @@
 #ifndef _DEBUG_HOOKS_H_
 #define _DEBUG_HOOKS_H_
 
+
+typedef struct sDebugHook {
+       //tDebugHookOutput      Output;
+       Uint    Value;
+       // TODO: Console support?
+} tDebugHook;
+
+extern void    DebugHook_HandleInput(tDebugHook *HookHandle, size_t Length, const char *Input);
+
 extern void    Heap_Dump(void);
 extern void    Threads_Dump(void);
 extern void    Threads_ToggleTrace(int TID);
index c2775a0..377ae30 100644 (file)
@@ -20,6 +20,8 @@
 
 #define USE_KERNEL_MAGIC       1
 
+extern void    Validate_VirtualMemoryUsage(void);
+
 // === PROTOTYPES ===
  int   Keyboard_Install(char **Arguments);
  int   Keyboard_Cleanup(void);
@@ -43,8 +45,7 @@ tDevFS_Driver gKB_DevInfo = {
        { .Type = &gKB_NodeType }
 };
 #if USE_KERNEL_MAGIC
- int   giKB_MagicAddress = 0;
- int   giKB_MagicAddressPos = 0;
+tDebugHook     gKB_DebugHookInfo;
 #endif
 
 // === CODE ===
@@ -146,6 +147,11 @@ void Keyboard_RemoveInstance(tKeyboard *Instance)
        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
@@ -249,52 +255,29 @@ void Keyboard_HandleKey(tKeyboard *Source, Uint32 HIDKeySym)
                break;
        }
 
-       // --- Check for Kernel Magic Combos
+       // Magic debug hooks
        #if USE_KERNEL_MAGIC
-       if(bPressed
-       && Source->KeyStates[KEYSYM_LEFTCTRL/8] & (1 << (KEYSYM_LEFTCTRL&7))
-       && Source->KeyStates[KEYSYM_LEFTALT/8]  & (1 << (KEYSYM_LEFTALT &7)) )
+       if(bPressed && IsPressed(Source, KEYSYM_LEFTCTRL) && IsPressed(Source, KEYSYM_LEFTALT))
        {
-                int    val;
-               switch(trans)
-               {
-               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;
+               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))
+         )
        {
                if( HIDKeySym == KEYSYM_DELETE )
                {

UCC git Repository :: git.ucc.asn.au