Espresso 0.0.1b

This commit is contained in:
2025-06-27 14:48:06 -05:00
parent fca025a9bf
commit c336584114
39 changed files with 2676 additions and 936 deletions

45
include/drivers/elf.h Normal file
View File

@ -0,0 +1,45 @@
#ifndef _ELF_H
#define _ELF_H
#include <types.h>
#define EI_NIDENT 16
#define PT_NULL 0
#define PT_LOAD 1
typedef struct {
unsigned char e_ident[EI_NIDENT];
uint16_t e_type;
uint16_t e_machine;
uint32_t e_version;
uint32_t e_entry;
uint32_t e_phoff;
uint32_t e_shoff;
uint32_t e_flags;
uint16_t e_ehsize;
uint16_t e_phentsize;
uint16_t e_phnum;
uint16_t e_shentsize;
uint16_t e_shnum;
uint16_t e_shstrndx;
} Elf32_Ehdr;
typedef struct {
uint32_t p_type;
uint32_t p_offset;
uint32_t p_vaddr;
uint32_t p_paddr;
uint32_t p_filesz;
uint32_t p_memsz;
uint32_t p_flags;
uint32_t p_align;
} Elf32_Phdr;
typedef struct {
void* entry_point;
} elf_executable_t;
elf_executable_t* load_elf32(void* elf_data);
#endif

View File

@ -0,0 +1,8 @@
#ifndef _ELF_LOADER_H
#define _ELF_LOADER_H
#include <types.h>
#endif

View File

@ -3,6 +3,52 @@
#include <types.h>
void duckfs_init(void);
#define DUCKFS_MAGIC "DUCKFS1"
#define DUCKFS_NAME_LEN 32
typedef enum { DUCKFS_TYPE_FILE = 0, DUCKFS_TYPE_DIR = 1, DUCKFS_TYPE_SYMLINK = 2 } duckfs_type_t;
typedef struct {
char name[DUCKFS_NAME_LEN];
duckfs_type_t type;
uint8_t permissions; /* rwxrwxrwx packed into 9 bits */
uint16_t uid;
uint16_t gid;
uint64_t size;
uint64_t created;
uint64_t modified;
uint64_t first_block_lba;
uint64_t next_file_lba;
uint64_t child_lba; /* only for directories */
} __attribute__((packed)) duckfs_file_header_t;
typedef struct {
char magic[8]; /* "DUCKFS1\0" */
uint32_t block_size;
uint64_t total_blocks;
uint64_t root_header_lba;
uint64_t free_list_lba;
uint32_t fs_version;
} __attribute__((packed)) duckfs_superblock_t;
struct free_block {
uint64_t next;
};
/* DuckFS API */
int32_t duckfs_mount(void);
int32_t duckfs_find(const char* path, duckfs_file_header_t* out);
int32_t duckfs_create_file(const char* name, const void* content, size_t size, uint16_t uid, uint16_t gid, uint8_t perms, duckfs_file_header_t* parent_dir);
int32_t duckfs_create_dir(const char* name, uint16_t uid, uint16_t gid, uint8_t perms, duckfs_file_header_t* parent_dir);
int32_t duckfs_delete_file(const char* name, duckfs_file_header_t* parent_dir);
int32_t duckfs_delete_dir(const char* name, duckfs_file_header_t* parent_dir);
int32_t duckfs_read_file(const duckfs_file_header_t* file, void* buffer, size_t size);
int32_t duckfs_write_data(duckfs_file_header_t* file, const void* data, size_t offset, size_t length);
int32_t duckfs_append_data(duckfs_file_header_t* file, const void* data, size_t length);
int32_t duckfs_truncate(duckfs_file_header_t* file, size_t new_size);
#endif

38
include/fs/fat16.h Normal file
View File

@ -0,0 +1,38 @@
#ifndef _FAT16_H
#define _FAT16_H
#include <types.h>
#define FAT16_MAX_FILENAME 256
#define FAT16_ATTR_DIRECTORY 0x10
typedef struct {
uint8_t drive;
uint32_t fat_start;
uint32_t root_dir_start;
uint32_t data_start;
uint16_t bytes_per_sector;
uint8_t sectors_per_cluster;
uint16_t root_entry_count;
uint32_t current_dir_cluster;
} fat16_t;
typedef struct {
char name[FAT16_MAX_FILENAME];
uint8_t attr;
uint32_t cluster;
uint32_t size;
} fat16_dir_entry_t;
int32_t fat16_init(uint8_t drive);
uint32_t cluster_to_lba(uint16_t cluster);
uint16_t fat16_get_fat_entry(uint16_t cluster);
uint16_t fat16_alloc_cluster(void);
int32_t fat16_list_dir(fat16_dir_entry_t* entries, size_t max_entries);
int32_t fat16_change_dir(const char* dirname);
int32_t fat16_read_file(const char* filename, void* buffer, size_t max_size);
int32_t fat16_write_file(const char* filename, const void* data, size_t size);
#endif

View File

@ -8,10 +8,15 @@
int32_t fat32_init(int32_t drive); /* 0 = primary master */
int32_t fat32_list_root(void);
int32_t fat32_read_file(const char *name, uint8_t *buffer, uint32_t max_len);
int32_t fat32_write_file(const char *name, const uint8_t *buffer, uint32_t len);
int32_t fat32_create_file(const char *name);
int32_t fat32_create_directory(const char *name);
int32_t fat32_change_directory(const char *name);
void format_83_name(const char* input, char* output);
#endif

View File

@ -5,16 +5,6 @@
typedef int32_t FILE;
void vfs_init(void);
FILE create_file(char* filename, char type, char encryption, FILE parent);
int32_t delete_file(FILE file);
FILE open_file(char* filename);
FILE write_file(FILE file, void* data, size_t len);
int32_t read_file(FILE file, void* buf, size_t buflen);
int32_t reset_read_offset(FILE file);
#endif

44
include/kernel/kconfig.h Normal file
View File

@ -0,0 +1,44 @@
#ifndef _KCONFIG_H
#define _KCONFIG_H
#include <types.h>
#ifdef __cplusplus
extern "C" {
#endif
#define ENABLE_DEBUGGING_MESSAGES
//#define ENABLE_FILESYSTEMS
#define ENABLE_IDE
//#define ENABLE_USB
//#define ENABLE_NETWORK
static inline kconf_t get_kconfig(void)
{
kconf_t kc = { false, false, false, false, false };
#ifdef ENABLE_DEBUGGING_MESSAGES
kc.enable_debug = true;
#endif
#ifdef ENABLE_FILESYSTEMS
kc.enable_fs = true;
#endif
#ifdef ENABLE_IDE
kc.enable_ide = true;
#endif
#ifdef ENABLE_USB
kc.enable_usb = true;
#endif
#ifdef ENABLE_NETWORK
kc.enable_networking = true;
#endif
return kc;
}
#ifdef __cplusplus
}
#endif
#endif

View File

@ -9,10 +9,4 @@ typedef struct {
uint32_t mantissa; /* 23 bits stored (MSB implicit for normalized numbers) */
} soft_float32_t;
typedef struct {
uint8_t sign; /* 0 = positive, 1 = negative */
uint16_t exponent; /* 11-bit biased exponent (bias = 1023) */
uint64_t mantissa; /* 52 bits stored (MSB implicit for normalized numbers) */
} soft_float64_t;
#endif

View File

@ -1,7 +1,7 @@
#ifndef _PMM_H
#define _PMM_H
#include <stdint.h>
#include <types.h>
#include <multiboot.h>
void pmm_init(multiboot_info_t* mb_info);

View File

@ -1,19 +1,19 @@
#ifndef _PROCESSES_H
#define _PROCESSES_H
#include <stdint.h>
#include <types.h>
#include <drivers/elf.h>
struct process
{
uint16_t id;
uint8_t policy;
uint16_t priority;
typedef struct process {
int32_t id;
int32_t group;
char name[16];
elf_executable_t* exe;
struct process* next;
};
} process_t;
int32_t make_process(char* name, char* group, elf_executable_t* exe);
#endif

View File

@ -3,14 +3,15 @@
#include <types.h>
/* TODO: change all applicable 'int32_t's with 'size_t's. */
/* TODO: change all applicable `int32_t`s with `size_t`s. */
size_t strlen(const char* str);
size_t strcmp(const char *s1, const char *s2);
int32_t strcmp(const char *s1, const char *s2);
int32_t strncmp(const char *s1, const char *s2, size_t n);
size_t strcpy(char *dst, const char *src);
char *strncpy(char *dest, const char *src, uint32_t n);
void strcat(char *dest, const char *src);
int32_t strcasecmp(const char* s1, const char* s2);
char* strcpy(char *dst, const char *src);
char* strncpy(char *dest, const char *src, uint32_t n);
char* strcat(char *dest, const char *src);
char* strdup(const char* s);
char* strtok(char* str, const char* delim);
char* strchr(const char* s, int c);
@ -19,12 +20,14 @@ int32_t ischar(int32_t c);
int32_t isspace(char c);
int32_t isalpha(char c);
char upper(char c);
char lower(char c);
char toupper(char c);
char lower(char c);
void *memset(void *dst, char c, uint32_t n);
void *memcpy(void *dst, const void *src, uint32_t n);
int32_t memcmp(uint8_t *s1, uint8_t *s2, uint32_t n);
int32_t memcmp(const void *s1, const void *s2, size_t n);
void* memclr(void* m_start, size_t m_count);
#endif

8
include/time.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef _TIME_H
#define _TIME_H
#include <types.h>
void ksleep(uint64_t millis);
#endif