Espresso 0.0.2a
This commit is contained in:
@ -38,7 +38,7 @@ char* get_cpu_vendor_string(void)
|
||||
return strdup(vendor);
|
||||
}
|
||||
|
||||
char* get_cpu_brand_string(void)
|
||||
/*char* get_cpu_brand_string(void)
|
||||
{
|
||||
unsigned int eax = 0, ebx = 0, ecx = 0, edx = 0;
|
||||
|
||||
@ -63,4 +63,4 @@ char* get_cpu_brand_string(void)
|
||||
|
||||
brand[48] = '\0';
|
||||
return strdup(brand);
|
||||
}
|
||||
}*/
|
||||
|
||||
@ -136,10 +136,6 @@ void kernel_main(multiboot_info_t* mbd, uint32_t magic)
|
||||
|
||||
terminal_setcolor(VGA_COLOR_LIGHT_GREEN);
|
||||
|
||||
|
||||
/*pit_sleep(4000);
|
||||
begin_anim(kernel_version);*/
|
||||
|
||||
printf("Guten tag and welcome to Espresso %s\n", kernel_version);
|
||||
|
||||
sleep(1000);
|
||||
|
||||
285
kernel/kshell.c
285
kernel/kshell.c
@ -4,6 +4,9 @@
|
||||
#include <drivers/ps2_keyboard.h>
|
||||
#include <tty.h>
|
||||
#include <kernel/ksh_debug.h>
|
||||
#include <arch/x86/intrin.h>
|
||||
|
||||
#include <fs/fat16.h>
|
||||
|
||||
#include <kernel/kshell.h>
|
||||
|
||||
@ -27,29 +30,20 @@ static void print_intro(void)
|
||||
|
||||
printf("\nSSE level: ");
|
||||
|
||||
command = 0;
|
||||
command = 1;
|
||||
|
||||
execute();
|
||||
|
||||
extern char* get_cpu_vendor_string(void);
|
||||
extern char* get_cpu_brand_string(void);
|
||||
|
||||
/* XXX: NOTE: these do not need freeing. */
|
||||
char* temp_ = get_cpu_vendor_string();
|
||||
char* _temp = get_cpu_brand_string();
|
||||
|
||||
printf("CPU: %s\n", _temp == NULL ? "No info" : _temp);
|
||||
printf("CPU vendor: %s\n", temp_ == NULL ? "No info" : temp_);
|
||||
|
||||
if (temp_)
|
||||
{
|
||||
free(temp_);
|
||||
}
|
||||
|
||||
if (_temp)
|
||||
{
|
||||
free(_temp);
|
||||
}
|
||||
|
||||
printf("\nCopyright 2025 David J Goeke\n");
|
||||
}
|
||||
|
||||
@ -64,6 +58,33 @@ static void parse_opts(int argc, char** argv)
|
||||
}
|
||||
}
|
||||
|
||||
static char* commands[] = {
|
||||
"kinfo",
|
||||
"sseinfo",
|
||||
"kernelmem",
|
||||
"sectionmem",
|
||||
|
||||
"enable_debug",
|
||||
"disable_debug",
|
||||
"toggle_debug",
|
||||
"get_debug",
|
||||
|
||||
"dumpregs",
|
||||
"dumpgprs",
|
||||
|
||||
"testascii",
|
||||
|
||||
"printrandom",
|
||||
|
||||
"acm", /* ACcess Memory */
|
||||
|
||||
"testfat16",
|
||||
|
||||
NULL,
|
||||
};
|
||||
|
||||
#define NUM_COMMANDS 15 /* Yes, including the NULL */
|
||||
|
||||
int kshell_start(int argc, char** argv)
|
||||
{
|
||||
(void)argc;
|
||||
@ -73,8 +94,6 @@ int kshell_start(int argc, char** argv)
|
||||
|
||||
char* i = NULL;
|
||||
|
||||
terminal_setcolor(VGA_COLOR_LIGHT_BLUE);
|
||||
|
||||
print_intro();
|
||||
|
||||
command = -1;
|
||||
@ -95,59 +114,36 @@ int kshell_start(int argc, char** argv)
|
||||
{
|
||||
break;
|
||||
}
|
||||
else if (strcmp(i, "sseinfo") == 0)
|
||||
|
||||
for (int j = 0; j < NUM_COMMANDS; j++)
|
||||
{
|
||||
command = 0;
|
||||
if (strcmp(i, commands[j]) == 0)
|
||||
{
|
||||
command = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (strcmp(i, "kinfo") == 0)
|
||||
{
|
||||
command = 1;
|
||||
}
|
||||
else if (strcmp(i, "enable_debug") == 0)
|
||||
{
|
||||
_debug = true;
|
||||
}
|
||||
else if (strcmp(i, "disable_debug") == 0)
|
||||
{
|
||||
_debug = false;
|
||||
}
|
||||
else if (strcmp(i, "toggle_debug") == 0)
|
||||
{
|
||||
_debug = !_debug;
|
||||
}
|
||||
else if (strcmp(i, "get_debug") == 0)
|
||||
{
|
||||
printf("Debugging: %s\n", _debug == true ? "On" : "Off");
|
||||
}
|
||||
else if (strcmp(i, "dumpregs") == 0)
|
||||
{
|
||||
command = 2;
|
||||
}
|
||||
else if (strcmp(i, "dumpgprs") == 0)
|
||||
{
|
||||
command = 3;
|
||||
}
|
||||
else if (strcmp(i, "kernelmem") == 0)
|
||||
{
|
||||
command = 4;
|
||||
}
|
||||
else if (strcmp(i, "sectionmem") == 0)
|
||||
{
|
||||
command = 5;
|
||||
}
|
||||
else if (strcmp(i, "testascii") == 0)
|
||||
{
|
||||
command = 6;
|
||||
}
|
||||
else if (strcmp(i, "asciitype") == 0)
|
||||
{
|
||||
command = 7;
|
||||
}
|
||||
else
|
||||
|
||||
if (command == -1)
|
||||
{
|
||||
printf("Unknown command %s len %i\n", i, strlen(i));
|
||||
}
|
||||
|
||||
else if (command == 4)
|
||||
{
|
||||
_debug = true;
|
||||
}
|
||||
else if (command == 5)
|
||||
{
|
||||
_debug = false;
|
||||
}
|
||||
else if (command == 6)
|
||||
{
|
||||
_debug = !_debug;
|
||||
}
|
||||
else if (command == 7)
|
||||
{
|
||||
printf("Debugging: %s\n", _debug == true ? "On" : "Off");
|
||||
}
|
||||
|
||||
if (_debug)
|
||||
{
|
||||
@ -163,23 +159,63 @@ int kshell_start(int argc, char** argv)
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
printf("C: %s; %i\n", commands[command], command);
|
||||
|
||||
execute();
|
||||
|
||||
} while (1);
|
||||
|
||||
free(i);
|
||||
if (i != NULL)
|
||||
{
|
||||
free(i);
|
||||
}
|
||||
|
||||
printf("Goodbye\n");
|
||||
printf("Goodbye!\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
static char* commands[] = {
|
||||
"kinfo",
|
||||
"sseinfo",
|
||||
"kernelmem",
|
||||
"sectionmem",
|
||||
|
||||
"enable_debug",
|
||||
"disable_debug",
|
||||
"toggle_debug",
|
||||
"get_debug",
|
||||
|
||||
"dumpregs",
|
||||
"dumpgprs",
|
||||
|
||||
"testascii",
|
||||
|
||||
"printrandom",
|
||||
|
||||
"acm",
|
||||
|
||||
NULL,
|
||||
};
|
||||
*/
|
||||
|
||||
int execute(void)
|
||||
{
|
||||
|
||||
switch (command)
|
||||
{
|
||||
case 0: {
|
||||
printf("Espresso %s ", KERNEL_VERSION);
|
||||
|
||||
#ifdef _DEBUG
|
||||
printf("DEBUG BUILD");
|
||||
#endif
|
||||
|
||||
printf("\n");
|
||||
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
extern int sse_initialized;
|
||||
|
||||
switch (sse_initialized)
|
||||
@ -214,20 +250,7 @@ int execute(void)
|
||||
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
printf("Espresso %s\n", KERNEL_VERSION);
|
||||
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
print_all_regs();
|
||||
break;
|
||||
}
|
||||
case 3: {
|
||||
print_gprs();
|
||||
break;
|
||||
}
|
||||
case 4: {
|
||||
extern uint8_t __kernel_start;
|
||||
extern uint8_t __kernel_end;
|
||||
size_t kernel_size = (size_t)&__kernel_end - (size_t)&__kernel_start;
|
||||
@ -240,7 +263,7 @@ int execute(void)
|
||||
|
||||
break;
|
||||
}
|
||||
case 5: {
|
||||
case 3: {
|
||||
extern uint8_t __kernel_text_start;
|
||||
extern uint8_t __kernel_text_end;
|
||||
extern uint8_t __kernel_rodata_start;
|
||||
@ -255,7 +278,15 @@ int execute(void)
|
||||
|
||||
break;
|
||||
}
|
||||
case 6: {
|
||||
case 8: {
|
||||
print_all_regs();
|
||||
break;
|
||||
}
|
||||
case 9: {
|
||||
print_gprs();
|
||||
break;
|
||||
}
|
||||
case 10: {
|
||||
/*extern void terminal_clear(void);*/
|
||||
|
||||
terminal_clear();
|
||||
@ -271,14 +302,106 @@ int execute(void)
|
||||
printf("%c", (char) i);
|
||||
}
|
||||
|
||||
printf("\nCool ASCII art\n%c%c\n%c%c\n", 0xDA, 0xBF, 0xC0, 0xD9);
|
||||
printf("\n\n\\/ Cool ASCII art \\/\n%c%c\n%c%c\n", 0xDA, 0xBF, 0xC0, 0xD9);
|
||||
|
||||
gets();
|
||||
|
||||
break;
|
||||
}
|
||||
case 7: {
|
||||
case 11: {
|
||||
extern void seed_rand(uint32_t seed);
|
||||
extern uint32_t ulrand(void);
|
||||
|
||||
uint64_t v = rdtsc();
|
||||
|
||||
seed_rand((uint32_t) v);
|
||||
|
||||
printf("%ull\n", ulrand());
|
||||
|
||||
break;
|
||||
}
|
||||
case 12: {
|
||||
printf("Enter hexadecimal address to access: ");
|
||||
char* g = gets();
|
||||
|
||||
int val = atoi(g);
|
||||
|
||||
if (val == 0)
|
||||
{
|
||||
printf("Improper/Malformed string entered\n");
|
||||
|
||||
break;
|
||||
}
|
||||
else if (val < 0x100000)
|
||||
{
|
||||
printf("Invalid address, must be higher than 0x100000\n");
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
int val_ = *((int*) val);
|
||||
|
||||
printf("value at %u: %i\n", val, val_);
|
||||
|
||||
break;
|
||||
}
|
||||
case 13: {
|
||||
int retv = fat16_mount(0);
|
||||
|
||||
if (retv != 0)
|
||||
{
|
||||
printf("There was an error while mounting volume 0.\n");
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
printf("Volume 0 mounted successfully.\n");
|
||||
|
||||
char fat_name[12];
|
||||
fat16_file_t file;
|
||||
|
||||
filename_to_83("test.txt", fat_name);
|
||||
|
||||
retv = fat16_create_file(fat_name, &file);
|
||||
|
||||
if (retv != 0)
|
||||
{
|
||||
printf("There was an error while creating a file on volume 0.\n");
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
uint8_t buf[512];
|
||||
memset(buf, 0, sizeof(buf));
|
||||
strcpy((char*) buf, "fg");
|
||||
|
||||
retv = fat16_write_file(&file, buf, (strlen((char*) buf)));
|
||||
|
||||
if (retv != 0)
|
||||
{
|
||||
printf("There was an error while writing to a file on volume 0.\n");
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
uint8_t rbuf[512];
|
||||
memset(rbuf, 0, sizeof(rbuf));
|
||||
|
||||
retv = fat16_read_file(&file, rbuf);
|
||||
|
||||
if (retv != 0)
|
||||
{
|
||||
printf("There was an error while reading from a file on volume 0.\n");
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
printf("The data read should be: %s\n", (char*) buf);
|
||||
printf("Read data: %s\n", (char*) rbuf);
|
||||
printf("Deleting test file\n");
|
||||
|
||||
fat16_delete_file(fat_name);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,13 +4,22 @@
|
||||
|
||||
#include <kernel/vars.h>
|
||||
|
||||
/*
|
||||
Number of bytes in kernel variable space: 4096 (4KiB)
|
||||
Number of bits in kernel variable space: 32768 (32Mib)
|
||||
*/
|
||||
|
||||
static uint8_t* vars_start = NULL;
|
||||
|
||||
static int num_bytes_used = 0;
|
||||
uint8_t vars[KERNEL_VARIABLES_SIZE];
|
||||
|
||||
void init_vars(void)
|
||||
{
|
||||
vars_start = (uint8_t*) malloc(8 * 1024); /* 1 KiB */
|
||||
memclr(vars_start, (size_t) 1024);
|
||||
memset(vars, 0, KERNEL_VARIABLES_SIZE);
|
||||
}
|
||||
|
||||
/* bo = bit offset */
|
||||
void set_bit_bo(uint32_t offset, uint8_t val)
|
||||
{
|
||||
/* First, extract the byte offset. (round down to a multiple of 8, and divide by 8. */
|
||||
(void) offset;
|
||||
(void) val;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user