feature: heap command prints the status of the allocator

kprintf: change KERN_DEFAULT to 0
This commit is contained in:
0x35c 2024-09-22 01:57:27 +02:00
parent deca2b9bfc
commit 283f073124
5 changed files with 26 additions and 25 deletions

View File

@ -2,15 +2,15 @@
#include <stdarg.h>
#define KERN_EMERG "0"
#define KERN_ALERT "1"
#define KERN_CRIT "2"
#define KERN_ERR "3"
#define KERN_WARNING "4"
#define KERN_NOTICE "5"
#define KERN_INFO "6"
#define KERN_DEBUG "7"
#define KERN_DEFAULT "8"
#define KERN_DEFAULT "0"
#define KERN_EMERG "1"
#define KERN_ALERT "2"
#define KERN_CRIT "3"
#define KERN_ERR "4"
#define KERN_WARNING "5"
#define KERN_NOTICE "6"
#define KERN_INFO "7"
#define KERN_DEBUG "8"
int kprintf(const char *restrict format, ...);
int kvprintf(const char *restrict format, va_list ap);

View File

@ -35,7 +35,6 @@ void kernel_main(void)
char *str = kalloc(10);
kfree(str);
str = kalloc(10);
show_alloc_mem();
strcpy(str, "Hello world\n");
kprintf("%s", str);
shell_init();

View File

@ -10,7 +10,7 @@ int print_int_base(int32_t number, const char *prefix, const char *base);
static int get_level(const char *str)
{
if (!str || !isdigit(str[0]))
return 8;
return 0;
return str[0] - '0';
}
@ -42,9 +42,9 @@ int kvprintf(const char *restrict format, va_list ap)
const char *start = format;
int ret = 0;
int level = get_level(format);
const int level = get_level(format);
set_color_level(level);
if (level != 8)
if (level)
start++;
while (*start != '\0') {
if (*start == '%' && *(start + 1) != '\0') {
@ -55,7 +55,7 @@ int kvprintf(const char *restrict format, va_list ap)
}
start++;
}
set_color_level(8);
set_color_level(0);
update_cursor();
return ret;
}

View File

@ -1,9 +1,10 @@
#include "alloc.h"
#include "kprintf.h"
#include "shell.h"
#include "string.h"
#include "terminal.h"
#define NB_CMDS 8
#define NB_CMDS (sizeof(commands) / sizeof(commands[0]))
#define BORDER "==========================================================="
#define HEADER "Welcome to bozOShell - Available Commands"
@ -17,12 +18,13 @@ struct shell_command {
static void help(void);
static const struct shell_command commands[NB_CMDS] = {
static const struct shell_command commands[] = {
{"help", "Print this help menu", help},
{"reboot", "Reboot the system", reboot},
{"poweroff", "Shut down the system", halt},
{"halt", "Stop all CPU functions", halt},
{"stack", "Print the stack trace", print_stack},
{"heap", "Print the heaps", show_alloc_mem},
{"clear", "Clear the current terminal", terminal_clear},
{"date", "Display the current time and date (UTC+0)", date},
{"merdella", "Surprise", merdella},
@ -36,7 +38,7 @@ static void help(void)
kprintf(" %s\n", HEADER);
kprintf("%s\n", BORDER);
for (size_t i = 0; i < sizeof(commands) / sizeof(commands[0]); i++) {
for (size_t i = 0; i < NB_CMDS; i++) {
kprintf(" %s", commands[i].name);
for (size_t j = 0; j < (padding - strlen(commands[i].name));
j++)
@ -107,7 +109,7 @@ void shell_init(void)
kprintf(PROMPT);
read_line();
bool invalid = true;
for (int i = 0; i < NB_CMDS; i++) {
for (unsigned i = 0; i < NB_CMDS; i++) {
if (!strcmp(commands[i].name, screen->line)) {
commands[i].fn();
invalid = false;

View File

@ -163,31 +163,31 @@ void set_color_level(int level)
{
switch (level) {
case 0:
screen->color = VGA_COLOR_RED;
screen->color = VGA_COLOR_WHITE;
break;
case 1:
screen->color = VGA_COLOR_RED;
break;
case 2:
screen->color = VGA_COLOR_MAGENTA;
screen->color = VGA_COLOR_RED;
break;
case 3:
screen->color = VGA_COLOR_LIGHT_YELLOW;
screen->color = VGA_COLOR_MAGENTA;
break;
case 4:
screen->color = VGA_COLOR_LIGHT_YELLOW;
break;
case 5:
screen->color = VGA_COLOR_LIGHT_BLUE;
screen->color = VGA_COLOR_LIGHT_YELLOW;
break;
case 6:
screen->color = VGA_COLOR_GREEN;
screen->color = VGA_COLOR_LIGHT_BLUE;
break;
case 7:
screen->color = VGA_COLOR_LIGHT_GREY;
screen->color = VGA_COLOR_GREEN;
break;
case 8:
screen->color = VGA_COLOR_WHITE;
screen->color = VGA_COLOR_LIGHT_GREY;
break;
default:
break;