Debug console working over serial

This commit is contained in:
Ali Mashtizadeh 2014-07-13 14:22:59 -07:00
parent 6b0d427898
commit befee0cf6b
4 changed files with 65 additions and 5 deletions

View File

@ -7,6 +7,7 @@
void *memcpy(void *dst, const void *src, size_t len); void *memcpy(void *dst, const void *src, size_t len);
void *memset(void *dst, int c, 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); int strcmp(const char *s1, const char *s2);
char *strcpy(char *to, const char *from); char *strcpy(char *to, const char *from);
size_t strlen(const char *str); size_t strlen(const char *str);

View File

@ -43,8 +43,15 @@ Console_Gets(char *str, size_t n)
for (i = 0; i < (n - 1); i++) for (i = 0; i < (n - 1); i++)
{ {
char ch = Console_Getc(); 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'); Console_Putc('\n');
str[i] = '\0'; str[i] = '\0';
return; return;

View File

@ -110,6 +110,12 @@ void VGA_Putc(short c)
c |= (TextAttribute << 8); c |= (TextAttribute << 8);
switch (c & 0xFF) switch (c & 0xFF)
{ {
case '\b':
if (CurrentX > 0) {
CurrentX--;
VideoBuffer[CurrentX + CurrentY * SizeX] = 0x20 | (TextAttribute << 8);
}
break;
case '\n': case '\n':
if (CurrentY >= (SizeY - 1)) { if (CurrentY >= (SizeY - 1)) {
VGA_ScrollDisplay(); VGA_ScrollDisplay();

View File

@ -16,12 +16,16 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include <string.h>
#include <kassert.h> #include <kassert.h>
#include <kdebug.h> #include <kdebug.h>
#include "../dev/console.h" #include "../dev/console.h"
#define DEBUG_MAX_LINE 128
#define DEBUG_MAX_ARGS 16
void void
Debug_PrintHex(const char *data, size_t length, off_t off, size_t limit) 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 void
Debug_Dump(int argc, const char *argv[]) Debug_Dump(int argc, const char *argv[])
{ {
} }
#define DEBUG_MAX_LINE 128
void void
Debug_Prompt() Debug_Prompt()
{ {
int argc;
char *argv[DEBUG_MAX_ARGS];
char *nextArg;
char buf[DEBUG_MAX_LINE]; char buf[DEBUG_MAX_LINE];
kprintf("Entered Debugger!\n"); kprintf("Entered Debugger!\n");
@ -90,11 +116,31 @@ Debug_Prompt()
kprintf("> "); kprintf("> ");
// read input // read input
Console_Gets(&buf, DEBUG_MAX_LINE); Console_Gets((char *)&buf, DEBUG_MAX_LINE);
// parse input // 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 // 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]);
}
} }
} }