-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
printf support added to make output and debugging easier. It outputs …
…to an internal buffer and also outputs to VGA buffer based on a flag.
- Loading branch information
Showing
12 changed files
with
324 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
/*****************************************************************************/ | ||
/* File: debug.c */ | ||
/* */ | ||
/* Description: Source file for debugging support. */ | ||
/* */ | ||
/* Author: Shoily O Rahman <[email protected]> */ | ||
/* */ | ||
/* Date: Nov 6, 2020 */ | ||
/* */ | ||
/*****************************************************************************/ | ||
|
||
#include "debug.h" | ||
#include "lock.h" | ||
#include "util.h" | ||
#include "system.h" | ||
|
||
char* cur_debug_mem; | ||
spinlock lock_debug_mem; | ||
int cur_offset; | ||
extern int _kernel_debug_buffer; | ||
int debug_level_for_vga; | ||
|
||
void debug_init() { | ||
|
||
cur_debug_mem = (char *)&_kernel_debug_buffer; | ||
cur_offset = 0; | ||
debug_level_for_vga = KERNEL_DEBUG; | ||
INIT_SPIN_LOCK(&lock_debug_mem); | ||
} | ||
|
||
typedef enum _va_type { | ||
|
||
VA_BYTE = 0, | ||
VA_PERCENT = 1, | ||
VA_CHAR = 2, | ||
VA_UCHAR = 3, | ||
VA_INT = 4, | ||
VA_UINT = 5, | ||
VA_HEX = 6, | ||
VA_SHORT = 7, | ||
VA_USHORT = 8 | ||
} va_type; | ||
|
||
void printf(int level, char *fmt, ...) { | ||
|
||
va_list list; | ||
va_start(fmt, list); | ||
char *p = fmt; | ||
char *ptr; | ||
|
||
union { | ||
char c; | ||
int i; | ||
unsigned int u; | ||
long long ll; | ||
char *s; | ||
void *p; | ||
} val; | ||
char str[20]; | ||
char *buf; | ||
|
||
spinlock_lock(&lock_debug_mem); | ||
buf = cur_debug_mem; | ||
|
||
while(*p) { | ||
|
||
if (*p == '%') { | ||
p++; | ||
if (*p == 37 || *p == '\0') { | ||
|
||
*buf++ = 37; | ||
//if (*p != '\0') | ||
// p++; | ||
} else { | ||
|
||
if (*p == 'c') { | ||
|
||
val.c = va_arg(list, char); | ||
*buf++ = val.c; | ||
} else if (*p == 'i' || *p == 'd' || *p == 'x') { | ||
|
||
val.i = va_arg(list, int); | ||
itoa(val.i, str, (*p == 'x') ? 16 : 10); | ||
ptr = str; | ||
while(*ptr) { | ||
*buf++ = *ptr++; | ||
} | ||
} else if (*p == 'p') { | ||
|
||
val.p = va_arg(list, void*); | ||
ptrtoa(val.p, str, 16); | ||
ptr = str; | ||
while(*ptr) { | ||
*buf++ = *ptr++; | ||
} | ||
} else if (*p == 'u') { | ||
|
||
val.u = va_arg(list, unsigned int); | ||
lltoa(val.u, str, 10); | ||
ptr = str; | ||
while(*ptr) { | ||
*buf++ = *ptr++; | ||
} | ||
} else if (*p == 'l' && *(p+1) == 'l') { | ||
|
||
p++; | ||
val.ll = va_arg(list, long long); | ||
lltoa(val.ll,str, 10); | ||
ptr = str; | ||
while(*ptr) { | ||
*buf++ = *ptr++; | ||
} | ||
} else if (*p == 's') { | ||
|
||
ptr = val.s = va_arg(list, char*); | ||
while(*ptr) { | ||
*buf++ = *ptr++; | ||
} | ||
} | ||
} | ||
} else { | ||
|
||
*buf++ = *p; | ||
} | ||
|
||
p++; | ||
} | ||
|
||
*buf++ = '\0'; | ||
|
||
if (level >= debug_level_for_vga) { | ||
|
||
print_vga(cur_debug_mem); | ||
} | ||
|
||
cur_debug_mem = buf; | ||
|
||
spinlock_unlock(&lock_debug_mem); | ||
} | ||
/* | ||
void debug_msg(int flags, char *msg, int len) { | ||
int i = 0; | ||
spinlock_lock(&lock_debug_mem); | ||
while (i < len) { | ||
*cur_debug_mem++ = msg[i++]; | ||
} | ||
*cur_debug_mem++ = 0; | ||
*cur_debug_mem++ = 0; | ||
spinlock_unlock(&lock_debug_mem); | ||
} | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
/*****************************************************************************/ | ||
/* File: debug.h */ | ||
/* */ | ||
/* Description: Header file for debugging support. */ | ||
/* */ | ||
/* Author: Shoily O Rahman <[email protected]> */ | ||
/* */ | ||
/* Date: Nov 6, 2020 */ | ||
/* */ | ||
/*****************************************************************************/ | ||
|
||
#ifndef _DEBUG_H | ||
#define _DEBUG_H | ||
|
||
#define KERNEL_DEBUG 1 | ||
#define KERNEL_INFO 2 | ||
#define KERNEL_WARN 3 | ||
#define KERNEL_ERR 4 | ||
#define KERNEL_CRIT 5 | ||
|
||
void debug_init(); | ||
void printf(int level, char *fmt, ...); | ||
//void debug_msg(char *msg, int len); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.