From befee0cf6bd5388a7102d6689e6af6eae0fe5649 Mon Sep 17 00:00:00 2001 From: Ali Mashtizadeh Date: Sun, 13 Jul 2014 14:22:59 -0700 Subject: [PATCH] Debug console working over serial --- include/string.h | 1 + sys/dev/console.c | 11 +++++++-- sys/dev/x86/vgacons.c | 6 +++++ sys/kern/debug.c | 52 ++++++++++++++++++++++++++++++++++++++++--- 4 files changed, 65 insertions(+), 5 deletions(-) diff --git a/include/string.h b/include/string.h index b42fa4c..40d2175 100644 --- a/include/string.h +++ b/include/string.h @@ -7,6 +7,7 @@ void *memcpy(void *dst, const void *src, size_t len); void *memset(void *dst, int c, size_t len); +char *strchr(const char *s, int c); int strcmp(const char *s1, const char *s2); char *strcpy(char *to, const char *from); size_t strlen(const char *str); diff --git a/sys/dev/console.c b/sys/dev/console.c index 6b82e23..060d267 100644 --- a/sys/dev/console.c +++ b/sys/dev/console.c @@ -43,8 +43,15 @@ Console_Gets(char *str, size_t n) for (i = 0; i < (n - 1); i++) { char ch = Console_Getc(); - if (ch == '\r') - { + if (ch == '\b') { + if (i > 0) { + Console_Putc(ch); + i--; + } + i--; + continue; + } + if (ch == '\r') { Console_Putc('\n'); str[i] = '\0'; return; diff --git a/sys/dev/x86/vgacons.c b/sys/dev/x86/vgacons.c index 4470824..eebeb19 100644 --- a/sys/dev/x86/vgacons.c +++ b/sys/dev/x86/vgacons.c @@ -110,6 +110,12 @@ void VGA_Putc(short c) c |= (TextAttribute << 8); switch (c & 0xFF) { + case '\b': + if (CurrentX > 0) { + CurrentX--; + VideoBuffer[CurrentX + CurrentY * SizeX] = 0x20 | (TextAttribute << 8); + } + break; case '\n': if (CurrentY >= (SizeY - 1)) { VGA_ScrollDisplay(); diff --git a/sys/kern/debug.c b/sys/kern/debug.c index 9832754..460a9be 100644 --- a/sys/kern/debug.c +++ b/sys/kern/debug.c @@ -16,12 +16,16 @@ #include #include +#include #include #include #include "../dev/console.h" +#define DEBUG_MAX_LINE 128 +#define DEBUG_MAX_ARGS 16 + void Debug_PrintHex(const char *data, size_t length, off_t off, size_t limit) { @@ -73,16 +77,38 @@ Debug_PrintHex(const char *data, size_t length, off_t off, size_t limit) } } +#define PHELP(_cmd, _msg) kprintf("%-16s %s\n", _cmd, _msg) + +void +Debug_Help(int argc, const char *argv[]) +{ + PHELP("dump", "Dump a region of memory"); + PHELP("help", "Display the list of commands"); +} + +void +Debug_Echo(int argc, const char *argv[]) +{ + int i; + + for (i = 1; i < argc; i++) + { + kprintf("%s ", argv[i]); + } + kprintf("\n"); +} + void Debug_Dump(int argc, const char *argv[]) { } -#define DEBUG_MAX_LINE 128 - void Debug_Prompt() { + int argc; + char *argv[DEBUG_MAX_ARGS]; + char *nextArg; char buf[DEBUG_MAX_LINE]; kprintf("Entered Debugger!\n"); @@ -90,11 +116,31 @@ Debug_Prompt() kprintf("> "); // read input - Console_Gets(&buf, DEBUG_MAX_LINE); + Console_Gets((char *)&buf, DEBUG_MAX_LINE); // parse input + argv[0] = buf; + for (argc = 1; argc < DEBUG_MAX_ARGS; argc++) { + nextArg = strchr(argv[argc - 1], ' '); + if (nextArg == NULL) + { + break; + } + + *nextArg = '\0'; + argv[argc] = nextArg + 1; + } // execute command + if (strcmp(argv[0], "help") == 0) { + Debug_Help(argc, argv); + } else if (strcmp(argv[0], "dump") == 0) { + Debug_Dump(argc, argv); + } else if (strcmp(argv[0], "echo") == 0) { + Debug_Echo(argc, argv); + } else if (strcmp(argv[0], "") != 0) { + kprintf("Unknown command '%s'\n", argv[0]); + } } }