Rename debug folder + add kernel/debug part

This commit is contained in:
Yann MAGNIN 2020-02-27 10:11:37 +01:00
parent c48424dd24
commit aea7368d46
5 changed files with 138 additions and 4 deletions

1
.gitignore vendored
View File

@ -55,7 +55,6 @@ dkms.conf
# Other
*.txt
build/
debug
.tests
.old
*.g1a

View File

@ -14,7 +14,7 @@ include ../../global.mk
HEADER := -I../../include
BUILD := ../../build/kernel
OUTPUT := ../../output
DEBUG := ../../debug
DEBUG := ../../debug_bin
NAME := vhex
EXEC := $(OUTPUT)/$(NAME).g1a

View File

@ -0,0 +1,135 @@
#include <kernel/util/debug.h>
#include <stdarg.h>
void printk(int x, int y, char const *str, ...)
{
char hex[] = "0123456789abcdef";
char buffer[16];
int default_pos_x;
int starting_x;
int digits;
int32_t nb;
uint8_t base;
va_list ap;
int i;
// Get starting variable args
va_start(ap, str);
// Initialize part
i = -1;
starting_x = x;
x = x * (KERNEL_FONT_REAL_WIDTH + 1);
y = y * (KERNEL_FONT_REAL_HEIGHT + 1);
default_pos_x = x;
// Walk into string and display character by character
while (str[++i] != '\0')
{
// New line
if (str[i] == '\n')
{
y = y + KERNEL_FONT_REAL_HEIGHT + 1;
x = default_pos_x;
continue;
}
// Horizontal tab
if (str[i] == '\t')
{
x = x / (KERNEL_FONT_REAL_WIDTH + 1);
x = (x + (4 - ((x - starting_x) & 3))) * (KERNEL_FONT_REAL_WIDTH + 1);
continue;
}
// String format "simple"
if (str[i] == '%')
{
if (str[i + 1] == 'd' || str[i + 1] == 'x')
{
// Initialise
digits = 0;
nb = va_arg(ap, int32_t);
base = (str[i + 1] == 'd') ? 10 : 16;
// Check negative value
// FIXME: negative error (max)
if (nb < 0 && str[i + 1] == 'd')
{
nb = 0 - nb;
kvram_ascii(x, y, '-');
x = x + KERNEL_FONT_REAL_WIDTH + 1;
}
// Generate buffer
// @note: generate in LSB mode.
while (digits == 0 || nb != 0)
{
buffer[digits++] = hex[nb % base];
nb = nb / base;
}
// Reverse dans display string
while (--digits >= 0)
{
kvram_ascii(x, y, buffer[digits]);
x = x + KERNEL_FONT_REAL_WIDTH + 1;
}
i = i + 1;
continue;
}
if ((str[i + 1] == '#' && str[i + 2] == 'x') || str[i + 1] == 'p')
{
// add @ if 'p' (pointer)
if (str[i + 1] == 'p')
{
kvram_ascii(x, y, '@');
x = x + KERNEL_FONT_REAL_WIDTH + 1;
}
// Add "0x"
kvram_ascii(x, y, '0');
x = x + KERNEL_FONT_REAL_WIDTH + 1;
kvram_ascii(x, y, 'x');
x = x + KERNEL_FONT_REAL_WIDTH + 1;
// Get value
digits = 0;
nb = va_arg(ap, uint32_t);
while (digits < 8)
{
buffer[digits++] = hex[nb & 0x0f];
nb = nb >> 4;
}
// Display string.
while (--digits >= 0)
{
kvram_ascii(x, y, buffer[digits]);
x = x + KERNEL_FONT_REAL_WIDTH + 1;
}
// Update cursor
i = (str[i + 1] == '#') ? i + 2 : i + 1;
continue;
}
if (str[i + 1] == 's')
{
digits = 0;
nb = va_arg(ap, uint32_t);
while (((char*)nb)[digits] != '\0')
{
kvram_ascii(x, y, ((char*)nb)[digits++]);
x = x + KERNEL_FONT_REAL_WIDTH + 1;
}
i = i + 1;
continue;
}
}
// Default, display character
kvram_ascii(x, y, str[i]);
x = x + KERNEL_FONT_REAL_WIDTH + 1;
}
// End of variodic args.
va_end(ap);
}

View File

@ -11,7 +11,7 @@ include ../../../global.mk
HEADER := -I../../../include -I../../../include/user
LIBS := -L../../lib/ -l_unistd -l_stdio -l_string -l_display
BUILD := ../../../build/user/shell
DEBUG := ../../../debug
DEBUG := ../../../debug_bin
OUTPUT := ../../../output
NAME := shell

View File

@ -11,7 +11,7 @@ include ../../../global.mk
HEADER := -I../../../include -I../../../include/user
LIBS := -L../../lib/ -l_unistd -l_stdio -l_string -l_display
BUILD := ../../../build/user/test
DEBUG := ../../../debug
DEBUG := ../../../debug_bin
OUTPUT := ../../../output
NAME := test