Espresso 0.0.2a

This commit is contained in:
2025-10-20 21:57:30 -05:00
parent 102d517097
commit ff6cba1164
59 changed files with 29272 additions and 773 deletions

16
include/ctype.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef _CHAR_TYPE_H
#define _CHAR_TYPE_H
#include <types.h>
int32_t ischar(int32_t c);
int32_t isspace(char c);
int32_t isalpha(char c);
int isprint(int c);
char upper(char c);
char toupper(char c);
char lower(char c);
char toupper(char c);
char lower(char c);
#endif

View File

@ -62,6 +62,8 @@ struct pci_header_type_0 {
uint8_t max_latency;
} __attribute__((packed));
void pci_init(void);
uint32_t pci_config_read(uint8_t bus, uint8_t device, uint8_t function, uint8_t offset);
void pci_config_write(uint8_t bus, uint8_t device, uint8_t function, uint8_t offset, uint32_t value);
void pci_enumerate(void);

View File

@ -2,16 +2,26 @@
#define _PS2_KEYBOARD_H
#include <types.h>
#include <drivers/irq.h>
typedef enum {
KEY_NONE = 0,
KEY_ARROW_UP = 0xAA0,
KEY_ARROW_UP = 0xFC,
KEY_ARROW_DOWN,
KEY_ARROW_LEFT,
KEY_ARROW_RIGHT,
/* Note: add more special keys here */
} special_key;
typedef enum {
KEY_UP = 0x1E,
KEY_DOWN = 0x1F,
KEY_RIGHT = 0x1C,
KEY_LEFT = 0x1D,
} lower_key;
typedef void (*ps2_hook_t)(char);
void keyboard_init(void);
void keyboard_handler(void);
@ -19,4 +29,9 @@ char get_char(void);
uint16_t get_key(void);
char* get_string(void);
char* kbd_gets(void);
bool setup_hook(ps2_hook_t func);
bool remove_hook(ps2_hook_t func);
#endif

14
include/drivers/serio.h Normal file
View File

@ -0,0 +1,14 @@
#ifndef _SERIAL_IO_H
#define _SERIAL_IO_H
#include <types.h>
int serial_init(void);
void serial_write(char a);
void serial_puts(const char* s);
char serial_read(void);
bool use_serial(void);
#endif

19
include/fs/ssfs.h Normal file
View File

@ -0,0 +1,19 @@
#ifndef _STUPID_SIMPLE_FS_H
#define _STUPID_SIMPLE_FS_H
#include <types.h>
typedef struct ssfs_file_header {
char filename[16]; /* 15 chars + null zero */
uint32_t num_sectors;
uint64_t start_sector;
uint32_t num_bytes;
/*uint8_t padding_[11];*/ /* 32 bytes without this */
} __attribute__((packed)) ssfs_file_header_t;
int ssfs_read_file(const char* name, void* buffer, int size);
int ssfs_write_file(const char* name, void* data, int size);
#endif

15
include/kdebug.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef _KERNEL_DEBUG_H
#define _KERNEL_DEBUG_H
#include <types.h>
void set_debug(void);
void clear_debug(void);
void toggle_debug(void);
bool get_debug(void);
#endif

View File

@ -2,6 +2,6 @@
#define _KERNEL_BOOT_H
uint8_t parse_boot_data(const char* data);
void clear_bss(void);
#endif

View File

@ -3,6 +3,7 @@
#include <types.h>
void intro_begin(void);
int16_t begin_anim(const char* version);
#endif

View File

@ -0,0 +1,7 @@
#ifndef _KERNEL_SHELL_DEBUGGER_H
#define _KERNEL_SHELL_DEBUGGER_H
void print_all_regs(void);
void print_gprs(void);
#endif

0
include/kernel/kshell.c Normal file
View File

8
include/kernel/kshell.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef _KERNEL_SHELL_H
#define _KERNEL_SHELL_H
#include <types.h>
int kshell_start(int argc, char** argv);
#endif

7
include/kernel/vars.h Normal file
View File

@ -0,0 +1,7 @@
#ifndef _KERNEL_VARIABLES_H
#define _KERNEL_VARIABLES_H
void init_vars(void);
#endif

View File

@ -1,23 +0,0 @@
#ifndef _KSYMTAB_H
#define _KSYMTAB_H
#include <types.h>
typedef struct kfunc {
/*
Bit 31 = 1 -> driver/module function, Bit 31 = 0 -> kernel function
Bits 30-20 -> module/driver ID (11 bits)
Bits 19-0 -> function ID (20 bits)
*/
uint32_t id;
uint32_t addr; /* Pointer to function, 0x0 if nonexistent */
} kfunc_t;
uint64_t kfunc_call(kfunc_t* func, uint32_t a, uint32_t b, uint32_t c, uint32_t d);
uint64_t call_kfunc_by_id(uint32_t id, uint32_t a, uint32_t b, uint32_t c, uint32_t d);
uint32_t add_kfunc(void* addr, bool module, uint16_t module_id, uint32_t function_id);
kfunc_t make_kfunc(void* addr, bool module, uint16_t module_id, uint32_t function_id);
#endif

17
include/math.h Normal file
View File

@ -0,0 +1,17 @@
#ifndef _MATH_H
#define _MATH_H
#include <types.h>
bool is_low_power_of_two(int n);
uint64_t int_pow(uint64_t base, uint32_t exp);
/* Divide a by b, rounding up */
static inline int div_round_up(int a, int b)
{
return (a + b - 1) / b;
}
#endif

View File

@ -1,19 +1,13 @@
#ifndef _HEAP_H
#define _HEAP_H
#include <types.h>
#define HEAP_START 0xC0000000
#define HEAP_SIZE (1024 * 4096) /* 1MB heap */
void heap_init(void);
#include <stddef.h>
#include <stdint.h>
void heap_init(uint32_t start, uint32_t size);
void* malloc(size_t size);
void* malloc_aligned(size_t size, size_t alignment);
void free(void* ptr);
void* calloc(size_t nmemb, size_t size);
void* realloc(void* ptr, size_t size);
void free(void* ptr);
#endif

View File

@ -1,9 +1,9 @@
#ifndef _PAGING_H
#define _PAGING_H
#include <types.h>
#include <stdint.h>
void paging_init(void);
void map_page(void* phys, void* virt);
void map_page(void* phys_addr, void* virt_addr);
#endif

View File

@ -4,8 +4,8 @@
#include <types.h>
#include <multiboot.h>
void pmm_init(multiboot_info_t* mb_info);
void* alloc_page(void);
void free_page(void* ptr);
void pmm_init(multiboot_info_t* mb);
void* pmm_alloc_page(void);
void pmm_free_page(void* addr);
#endif

12
include/mm_macros.h Normal file
View File

@ -0,0 +1,12 @@
#ifndef _MM_MACROS_H
#define _MM_MACROS_H
#define MEMSET(ptr, value, num) \
do { \
unsigned char *_p = (unsigned char*)(ptr); \
for (size_t _i = 0; _i < (num); ++_i) \
_p[_i] = (unsigned char)(value); \
} while (0)
#endif

View File

@ -12,9 +12,13 @@ void printd(const char* str);
void printf(const char*, ...);
void print_int(int32_t value);
void print_lint(int64_t value);
void print_uint(uint32_t value);
void print_luint(uint64_t value);
void print_hex(uint32_t value, int width, bool uppercase);
void print_hex64(uint64_t value, int width, bool uppercase);
void print_double(double value, int precision);
void printf_set_color(uint8_t _color);
#endif

View File

@ -6,5 +6,11 @@
char getchar(void);
char* getstring(void);
char* gets(void); /* Use this instead of getstring() */
static inline void putchar(char c)
{
printf("%c", c);
}
#endif

View File

@ -2,6 +2,7 @@
#define STRING_H
#include <types.h>
#include <ctype.h>
/* TODO: change all applicable `int32_t`s with `size_t`s. */
@ -16,18 +17,17 @@ char* strdup(const char* s);
char* strtok(char* str, const char* delim);
char* strchr(const char* s, int c);
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 lowers(char* str);
void uppers(char* str);
void* memset(void *dst, char c, uint32_t n);
void* memset(void* dst, int c, size_t n);
void* memcpy(void *dst, const void *src, uint32_t n);
int32_t memcmp(const void *s1, const void *s2, size_t n);
void* memclr(void* m_start, size_t m_count);
void* memmove(void* dest, const void* src, size_t n);
int atoi(const char *str);
long atol(const char *str);
double atof(const char *str);
#endif

View File

@ -26,5 +26,6 @@ void terminal_scroll(void);
unsigned char terminal_get_shifted(unsigned char uc);
void terminal_set_cursor(uint16_t row, uint16_t column);
void terminal_update_cursor(void);
#endif