Espresso 0.0.2c

This commit is contained in:
2026-03-20 16:57:08 -05:00
parent 021fdbbcef
commit 5971218b56
77 changed files with 4538 additions and 518 deletions

View File

@ -6,6 +6,12 @@
#include <kernel/ksh_debug.h>
#include <arch/x86/intrin.h>
#include <drivers/elf.h>
#include <kernel/syscall.h>
#include <scheduler.h>
#include <fs/fat16.h>
#include <kernel/kshell.h>
@ -15,7 +21,7 @@ const char* shell_version = "0.0.2";
char* prompt = NULL;
int command = -1;
bool _debug = false;
bool _debug = true;
int execute(void);
@ -44,18 +50,7 @@ static void print_intro(void)
printf("CPU: %s\n", _temp == NULL ? "No info" : _temp);
printf("CPU vendor: %s\n", temp_ == NULL ? "No info" : temp_);
printf("\nCopyright 2025 David J Goeke\n");
}
static void parse_opts(int argc, char** argv)
{
for (int i = 0; i < argc; i++)
{
if (strcmp(argv[i], "--color") == 0)
{
}
}
printf("\nCopyright %s David J Goeke\n", KERNEL_RELEASE_YEAR);
}
static char* commands[] = {
@ -76,19 +71,28 @@ static char* commands[] = {
"printrandom",
"acm", /* ACcess Memory */
"testfat16",
"printc",
"testscheduler",
"readfat16",
"help",
"exec",
"int16test",
NULL,
};
#define NUM_COMMANDS 15 /* Yes, including the NULL */
const int NUM_COMMANDS = 19; /* Yes, including the NULL */
int kshell_start(int argc, char** argv)
void kshell_start(void)
{
(void)argc;
(void)argv;
printf("Welcome to the kshell!\n");
prompt = strdup(">");
@ -102,7 +106,17 @@ int kshell_start(int argc, char** argv)
{
printf("%s ", prompt);
i = gets();
/*i = gets();*/
int j = 0;
i = gets_new(&j);
if (j == 0)
{
printf("Error?\n");
break;
}
i = strnlstrip(i);
command = -1;
@ -165,14 +179,14 @@ int kshell_start(int argc, char** argv)
} while (1);
if (i != NULL)
if (i)
{
free(i);
}
printf("Goodbye!\n");
return 0;
return;
}
/*
@ -194,7 +208,7 @@ int kshell_start(int argc, char** argv)
"printrandom",
"acm",
"testfat16",
NULL,
};
@ -321,31 +335,6 @@ int execute(void)
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)
@ -402,6 +391,151 @@ int execute(void)
fat16_delete_file(fat_name);
break;
}
case 13:
{
printf("Enter char to print in decimal: ");
char* g = gets();
int val = atoi(g);
if (*g == '\0')
{
printf("Empty string entered\n");
break;
}
printf("%c\n", (char) val);
break;
}
case 14:
{
#if 0
void taskA() { while (1) printf("A"); }
void taskB() { while (1) printf("B"); }
create_task(taskA);
create_task(taskB);
#endif
break;
}
case 15:
{
char* filename = "t.bin";
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(filename, fat_name);
retv = fat16_find_file(fat_name, &file);
if (retv != 0)
{
printf("file %s could not be found\n", filename);
break;
}
uint8_t buffer[256];
memset(buffer, 0, sizeof(buffer));
retv = fat16_read_file(&file, buffer);
if (retv != 0)
{
printf("Could not read file s\n", (char*) filename);
break;
}
printf("read data: %s\n", (char*) buffer);
break;
}
case 16:
{
printf("Commands:\n");
for (int i = 0; i < NUM_COMMANDS; i++)
{
printf("%s\n", commands[i]);
}
break;
}
case 17:
{
char* filename = "hello.elf";
printf("Loading and executing file %s\n", filename);
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(filename, fat_name);
retv = fat16_find_file(fat_name, &file);
if (retv != 0)
{
printf("file %s could not be found\n", filename);
break;
}
uint8_t* buffer = malloc(file.size);
memset(buffer, 0, file.size);
retv = fat16_read_file(&file, buffer);
if (retv != 0)
{
printf("Could not read file s\n", (char*) filename);
break;
}
printf("Parsing ELF headers\n");
elf_executable_t* f = load_elf32(buffer);
printf("Attempting execution of executable...\n");
retv = f->entry_point();
printf("\nreturn value: %i\n", retv);
break;
}
case 18:
{
printf("testing int 16\n");
const char* str = "HELLO!\n";
syscall1(SYS_TERMINAL_WRITESTRING, str);
printf("test ran\n");
break;
}
}