Refactor to use the print function, at byte formatter, at memdump cmd
This commit is contained in:
parent
831b49d8dd
commit
5c8f8defe0
3 changed files with 81 additions and 60 deletions
|
@ -68,7 +68,8 @@ void free(void *data) {
|
|||
}
|
||||
|
||||
void print_memory() {
|
||||
terminal_write("==== MEM DUMP ====\n", 19);
|
||||
print("____________________\n");
|
||||
print(" === MEM DUMP === \n");
|
||||
page_tag *curr_page = start;
|
||||
int i = 0;
|
||||
while (curr_page != NULL) {
|
||||
|
@ -79,7 +80,7 @@ void print_memory() {
|
|||
|
||||
void *empty_start = (void *) curr_page + sizeof(page_tag) + curr_page->size;
|
||||
if (empty_start + sizeof(page_tag) < (void *) curr_page->next) {
|
||||
print("_: empty_page (%d, %d)\n",
|
||||
print("_: empty page (%d, %d)\n",
|
||||
sizeof(page_tag),
|
||||
(void *) curr_page->next -
|
||||
(empty_start + sizeof(page_tag)));
|
||||
|
@ -90,8 +91,13 @@ void print_memory() {
|
|||
curr_page = curr_page->next;
|
||||
i += 1;
|
||||
}
|
||||
terminal_write("------------------\n\n", 20);
|
||||
print("____________________\n");
|
||||
}
|
||||
|
||||
int command_mem_dump(char*string){
|
||||
print_memory();
|
||||
}
|
||||
|
||||
//
|
||||
//void test_allocs() {
|
||||
// void *ptr0 = __alloc(64);
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include "terminal.c"
|
||||
#include "inline_asm.c"
|
||||
#include "drivers/keyboard/keyboard.c"
|
||||
#include "memory.c"
|
||||
|
||||
char buffer[SHELL_CMD_BUFFER_SIZE];
|
||||
int buffer_idx = 0;
|
||||
|
@ -48,63 +49,61 @@ int get_gdt(char* unused) {
|
|||
|
||||
//terminal_writestring("\nEntry ");
|
||||
//terminal_writeint(entry_num, 10);
|
||||
terminal_writestring("base = 0x");
|
||||
terminal_writeint(base, 16);
|
||||
terminal_writestring("\nlimit = 0x");
|
||||
terminal_writeint(limit, 16);
|
||||
terminal_writestring("\nflags = 0b");
|
||||
terminal_writeint((entry.flags_limit_higher >> 4), 2);
|
||||
print("base = %x\n", base);
|
||||
print("limit = %x\n", limit);
|
||||
print("flags = %b\n", (entry.flags_limit_higher >> 4));
|
||||
|
||||
if ((flags & 0b1000) == 0) {
|
||||
terminal_writestring(" (byte granularity");
|
||||
print(" (byte granularity");
|
||||
} else {
|
||||
terminal_writestring(" (page granularity");
|
||||
print(" (page granularity");
|
||||
}
|
||||
|
||||
if ((flags & 0b0100) == 0) {
|
||||
terminal_writestring(", 16 bit)");
|
||||
print(", 16 bit)");
|
||||
} else {
|
||||
terminal_writestring(", 32 bit)");
|
||||
print(", 32 bit)");
|
||||
}
|
||||
print("\n");
|
||||
|
||||
terminal_writestring("\naccess = 0b");
|
||||
terminal_writeint(entry.access_byte, 2);
|
||||
terminal_writestring(" (ring ");
|
||||
terminal_writeint((entry.access_byte & 0b01100000) >> 5, 10);
|
||||
print("access = %b (ring %d",
|
||||
entry.access_byte,
|
||||
(entry.access_byte & 0b01100000) >> 5
|
||||
);
|
||||
if ((entry.access_byte & 0b00010000) == 0) {
|
||||
terminal_writestring(", System");
|
||||
print(", System");
|
||||
}
|
||||
if (is_data) {
|
||||
terminal_writestring(", Data");
|
||||
print(", Data");
|
||||
|
||||
if ((entry.access_byte & 0b00000100) == 0) {
|
||||
terminal_writestring(" (growing up, ");
|
||||
print(" (growing up, ");
|
||||
} else {
|
||||
terminal_writestring(" (growing down, ");
|
||||
print(" (growing down, ");
|
||||
}
|
||||
|
||||
if ((entry.access_byte & 0b00000010) == 0) {
|
||||
terminal_writestring("r--)");
|
||||
print("r--)");
|
||||
} else {
|
||||
terminal_writestring("rw-)");
|
||||
print("rw-)");
|
||||
}
|
||||
} else {
|
||||
terminal_writestring(", Code");
|
||||
print(", Code");
|
||||
|
||||
if ((entry.access_byte & 0b00000100) == 0) {
|
||||
terminal_writestring(" (non-conforming, ");
|
||||
print(" (non-conforming, ");
|
||||
} else {
|
||||
terminal_writestring(" (conforming, ");
|
||||
print(" (conforming, ");
|
||||
}
|
||||
|
||||
if ((entry.access_byte & 0b00000010) == 0) {
|
||||
terminal_writestring("--x)");
|
||||
print("--x)");
|
||||
} else {
|
||||
terminal_writestring("r-x)");
|
||||
print("r-x)");
|
||||
}
|
||||
}
|
||||
|
||||
terminal_writestring(")\n");
|
||||
print(")\n");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
@ -118,6 +117,10 @@ int ree(char* unused) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
int save_text(char *text) {
|
||||
|
||||
}
|
||||
|
||||
// TODO This is ugly, fix this
|
||||
const char *shell_commands_strings[] = {
|
||||
"echo",
|
||||
|
@ -125,6 +128,7 @@ const char* shell_commands_strings[] = {
|
|||
"cls",
|
||||
"ree",
|
||||
"getgdt",
|
||||
"memdump",
|
||||
NULL
|
||||
};
|
||||
|
||||
|
@ -133,7 +137,8 @@ int (*shell_commands_functions[]) (char*) = {
|
|||
hello,
|
||||
cls,
|
||||
ree,
|
||||
get_gdt
|
||||
get_gdt,
|
||||
command_mem_dump,
|
||||
};
|
||||
|
||||
int run_command(char *buffer) {
|
||||
|
@ -176,7 +181,7 @@ void shell_step() {
|
|||
buffer_idx = 0;
|
||||
|
||||
if (result == -1) {
|
||||
terminal_writestring("No such command\n");
|
||||
print("No such command\n");
|
||||
}
|
||||
} else if (curr_char == 0x08) {
|
||||
if (buffer_idx != 0) {
|
||||
|
|
|
@ -14,6 +14,7 @@
|
|||
* - %c: character
|
||||
* - %d: digit (integer)
|
||||
* - %x: hexadecimal value. Can be used to print pointers to
|
||||
* - %b: binary value. Digits with base 2
|
||||
* @param fmt Formatter string
|
||||
* @param ... Variable amount of arguments to be inserted
|
||||
*/
|
||||
|
@ -46,10 +47,19 @@ void print(const char *fmt, ...) {
|
|||
terminal_writestring(s);
|
||||
break;
|
||||
case 'x':
|
||||
terminal_writestring("0x");
|
||||
|
||||
i = va_arg(argp, int);
|
||||
s = itoa(i, fmtbuf, 16);
|
||||
terminal_writestring(s);
|
||||
break;
|
||||
case 'b':
|
||||
terminal_writestring("0b");
|
||||
|
||||
i = va_arg(argp, int);
|
||||
s = itoa(i, fmtbuf, 2);
|
||||
terminal_writestring(s);
|
||||
break;
|
||||
case '%':
|
||||
terminal_putchar('%');
|
||||
break;
|
||||
|
|
Loading…
Reference in a new issue