feature: heap command prints the status of the allocator
kprintf: change KERN_DEFAULT to 0
This commit is contained in:
parent
deca2b9bfc
commit
283f073124
@ -2,15 +2,15 @@
|
|||||||
|
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
|
|
||||||
#define KERN_EMERG "0"
|
#define KERN_DEFAULT "0"
|
||||||
#define KERN_ALERT "1"
|
#define KERN_EMERG "1"
|
||||||
#define KERN_CRIT "2"
|
#define KERN_ALERT "2"
|
||||||
#define KERN_ERR "3"
|
#define KERN_CRIT "3"
|
||||||
#define KERN_WARNING "4"
|
#define KERN_ERR "4"
|
||||||
#define KERN_NOTICE "5"
|
#define KERN_WARNING "5"
|
||||||
#define KERN_INFO "6"
|
#define KERN_NOTICE "6"
|
||||||
#define KERN_DEBUG "7"
|
#define KERN_INFO "7"
|
||||||
#define KERN_DEFAULT "8"
|
#define KERN_DEBUG "8"
|
||||||
|
|
||||||
int kprintf(const char *restrict format, ...);
|
int kprintf(const char *restrict format, ...);
|
||||||
int kvprintf(const char *restrict format, va_list ap);
|
int kvprintf(const char *restrict format, va_list ap);
|
||||||
|
@ -35,7 +35,6 @@ void kernel_main(void)
|
|||||||
char *str = kalloc(10);
|
char *str = kalloc(10);
|
||||||
kfree(str);
|
kfree(str);
|
||||||
str = kalloc(10);
|
str = kalloc(10);
|
||||||
show_alloc_mem();
|
|
||||||
strcpy(str, "Hello world\n");
|
strcpy(str, "Hello world\n");
|
||||||
kprintf("%s", str);
|
kprintf("%s", str);
|
||||||
shell_init();
|
shell_init();
|
||||||
|
@ -10,7 +10,7 @@ int print_int_base(int32_t number, const char *prefix, const char *base);
|
|||||||
static int get_level(const char *str)
|
static int get_level(const char *str)
|
||||||
{
|
{
|
||||||
if (!str || !isdigit(str[0]))
|
if (!str || !isdigit(str[0]))
|
||||||
return 8;
|
return 0;
|
||||||
return str[0] - '0';
|
return str[0] - '0';
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,9 +42,9 @@ int kvprintf(const char *restrict format, va_list ap)
|
|||||||
const char *start = format;
|
const char *start = format;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
int level = get_level(format);
|
const int level = get_level(format);
|
||||||
set_color_level(level);
|
set_color_level(level);
|
||||||
if (level != 8)
|
if (level)
|
||||||
start++;
|
start++;
|
||||||
while (*start != '\0') {
|
while (*start != '\0') {
|
||||||
if (*start == '%' && *(start + 1) != '\0') {
|
if (*start == '%' && *(start + 1) != '\0') {
|
||||||
@ -55,7 +55,7 @@ int kvprintf(const char *restrict format, va_list ap)
|
|||||||
}
|
}
|
||||||
start++;
|
start++;
|
||||||
}
|
}
|
||||||
set_color_level(8);
|
set_color_level(0);
|
||||||
update_cursor();
|
update_cursor();
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,10 @@
|
|||||||
|
#include "alloc.h"
|
||||||
#include "kprintf.h"
|
#include "kprintf.h"
|
||||||
#include "shell.h"
|
#include "shell.h"
|
||||||
#include "string.h"
|
#include "string.h"
|
||||||
#include "terminal.h"
|
#include "terminal.h"
|
||||||
|
|
||||||
#define NB_CMDS 8
|
#define NB_CMDS (sizeof(commands) / sizeof(commands[0]))
|
||||||
#define BORDER "==========================================================="
|
#define BORDER "==========================================================="
|
||||||
#define HEADER "Welcome to bozOShell - Available Commands"
|
#define HEADER "Welcome to bozOShell - Available Commands"
|
||||||
|
|
||||||
@ -17,12 +18,13 @@ struct shell_command {
|
|||||||
|
|
||||||
static void help(void);
|
static void help(void);
|
||||||
|
|
||||||
static const struct shell_command commands[NB_CMDS] = {
|
static const struct shell_command commands[] = {
|
||||||
{"help", "Print this help menu", help},
|
{"help", "Print this help menu", help},
|
||||||
{"reboot", "Reboot the system", reboot},
|
{"reboot", "Reboot the system", reboot},
|
||||||
{"poweroff", "Shut down the system", halt},
|
{"poweroff", "Shut down the system", halt},
|
||||||
{"halt", "Stop all CPU functions", halt},
|
{"halt", "Stop all CPU functions", halt},
|
||||||
{"stack", "Print the stack trace", print_stack},
|
{"stack", "Print the stack trace", print_stack},
|
||||||
|
{"heap", "Print the heaps", show_alloc_mem},
|
||||||
{"clear", "Clear the current terminal", terminal_clear},
|
{"clear", "Clear the current terminal", terminal_clear},
|
||||||
{"date", "Display the current time and date (UTC+0)", date},
|
{"date", "Display the current time and date (UTC+0)", date},
|
||||||
{"merdella", "Surprise", merdella},
|
{"merdella", "Surprise", merdella},
|
||||||
@ -36,7 +38,7 @@ static void help(void)
|
|||||||
kprintf(" %s\n", HEADER);
|
kprintf(" %s\n", HEADER);
|
||||||
kprintf("%s\n", BORDER);
|
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);
|
kprintf(" %s", commands[i].name);
|
||||||
for (size_t j = 0; j < (padding - strlen(commands[i].name));
|
for (size_t j = 0; j < (padding - strlen(commands[i].name));
|
||||||
j++)
|
j++)
|
||||||
@ -107,7 +109,7 @@ void shell_init(void)
|
|||||||
kprintf(PROMPT);
|
kprintf(PROMPT);
|
||||||
read_line();
|
read_line();
|
||||||
bool invalid = true;
|
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)) {
|
if (!strcmp(commands[i].name, screen->line)) {
|
||||||
commands[i].fn();
|
commands[i].fn();
|
||||||
invalid = false;
|
invalid = false;
|
||||||
|
@ -163,31 +163,31 @@ void set_color_level(int level)
|
|||||||
{
|
{
|
||||||
switch (level) {
|
switch (level) {
|
||||||
case 0:
|
case 0:
|
||||||
screen->color = VGA_COLOR_RED;
|
screen->color = VGA_COLOR_WHITE;
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
screen->color = VGA_COLOR_RED;
|
screen->color = VGA_COLOR_RED;
|
||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
screen->color = VGA_COLOR_MAGENTA;
|
screen->color = VGA_COLOR_RED;
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
screen->color = VGA_COLOR_LIGHT_YELLOW;
|
screen->color = VGA_COLOR_MAGENTA;
|
||||||
break;
|
break;
|
||||||
case 4:
|
case 4:
|
||||||
screen->color = VGA_COLOR_LIGHT_YELLOW;
|
screen->color = VGA_COLOR_LIGHT_YELLOW;
|
||||||
break;
|
break;
|
||||||
case 5:
|
case 5:
|
||||||
screen->color = VGA_COLOR_LIGHT_BLUE;
|
screen->color = VGA_COLOR_LIGHT_YELLOW;
|
||||||
break;
|
break;
|
||||||
case 6:
|
case 6:
|
||||||
screen->color = VGA_COLOR_GREEN;
|
screen->color = VGA_COLOR_LIGHT_BLUE;
|
||||||
break;
|
break;
|
||||||
case 7:
|
case 7:
|
||||||
screen->color = VGA_COLOR_LIGHT_GREY;
|
screen->color = VGA_COLOR_GREEN;
|
||||||
break;
|
break;
|
||||||
case 8:
|
case 8:
|
||||||
screen->color = VGA_COLOR_WHITE;
|
screen->color = VGA_COLOR_LIGHT_GREY;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user