Espresso 0.0.0e

This commit is contained in:
2025-06-13 18:03:39 -05:00
parent 6d366537dd
commit 1e5b4a765b
40 changed files with 742 additions and 718 deletions

8
include/drivers/gdt_ec.c Normal file
View File

@ -0,0 +1,8 @@
#ifndef _GDT_EC_H
#define _GDT_EC_H
#include <types.h>
void create_descriptor(uint32_t base, uint32_t limit, uint16_t flag);
#endif

50
include/drivers/gdt_ec.h Normal file
View File

@ -0,0 +1,50 @@
#ifndef _GDT_EC_H
#define _GDT_EC_H
#include <types.h>
// Each define here is for a specific flag in the descriptor.
// Refer to the intel documentation for a description of what each one does.
#define SEG_DESCTYPE(x) ((x) << 0x04) // Descriptor type (0 for system, 1 for code/data)
#define SEG_PRES(x) ((x) << 0x07) // Present
#define SEG_SAVL(x) ((x) << 0x0C) // Available for system use
#define SEG_LONG(x) ((x) << 0x0D) // Long mode
#define SEG_SIZE(x) ((x) << 0x0E) // Size (0 for 16-bit, 1 for 32)
#define SEG_GRAN(x) ((x) << 0x0F) // Granularity (0 for 1B - 1MB, 1 for 4KB - 4GB)
#define SEG_PRIV(x) (((x) & 0x03) << 0x05) // Set privilege level (0 - 3)
#define SEG_DATA_RD 0x00 // Read-Only
#define SEG_DATA_RDA 0x01 // Read-Only, accessed
#define SEG_DATA_RDWR 0x02 // Read/Write
#define SEG_DATA_RDWRA 0x03 // Read/Write, accessed
#define SEG_DATA_RDEXPD 0x04 // Read-Only, expand-down
#define SEG_DATA_RDEXPDA 0x05 // Read-Only, expand-down, accessed
#define SEG_DATA_RDWREXPD 0x06 // Read/Write, expand-down
#define SEG_DATA_RDWREXPDA 0x07 // Read/Write, expand-down, accessed
#define SEG_CODE_EX 0x08 // Execute-Only
#define SEG_CODE_EXA 0x09 // Execute-Only, accessed
#define SEG_CODE_EXRD 0x0A // Execute/Read
#define SEG_CODE_EXRDA 0x0B // Execute/Read, accessed
#define SEG_CODE_EXC 0x0C // Execute-Only, conforming
#define SEG_CODE_EXCA 0x0D // Execute-Only, conforming, accessed
#define SEG_CODE_EXRDC 0x0E // Execute/Read, conforming
#define SEG_CODE_EXRDCA 0x0F // Execute/Read, conforming, accessed
#define GDT_CODE_PL0 SEG_DESCTYPE(1) | SEG_PRES(1) | SEG_SAVL(0) | \
SEG_LONG(0) | SEG_SIZE(1) | SEG_GRAN(1) | \
SEG_PRIV(0) | SEG_CODE_EXRD
#define GDT_DATA_PL0 SEG_DESCTYPE(1) | SEG_PRES(1) | SEG_SAVL(0) | \
SEG_LONG(0) | SEG_SIZE(1) | SEG_GRAN(1) | \
SEG_PRIV(0) | SEG_DATA_RDWR
#define GDT_CODE_PL3 SEG_DESCTYPE(1) | SEG_PRES(1) | SEG_SAVL(0) | \
SEG_LONG(0) | SEG_SIZE(1) | SEG_GRAN(1) | \
SEG_PRIV(3) | SEG_CODE_EXRD
#define GDT_DATA_PL3 SEG_DESCTYPE(1) | SEG_PRES(1) | SEG_SAVL(0) | \
SEG_LONG(0) | SEG_SIZE(1) | SEG_GRAN(1) | \
SEG_PRIV(3) | SEG_DATA_RDWR
#endif

13
include/drivers/idt.h Normal file
View File

@ -0,0 +1,13 @@
#ifndef _IDT_H
#define _IDT_H
#include <types.h>
void idt_init(void);
void pic_remap(void);
void idt_set_descriptor(uint8_t vector, void* isr, uint8_t flags);
void exception_dispatcher(uint32_t int_no, uint32_t err_code);
#endif

8
include/drivers/irq.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef _IRQ_H
#define _IRQ_H
#include <types.h>
void irq_handler(uint8_t irq_number);
#endif

View File

@ -3,5 +3,7 @@
#include <types.h>
void pit_init(uint32_t freq);
void sleep(uint32_t millis);
#endif

View File

@ -2,9 +2,7 @@
#define _PS2_KEYBOARD_H
#include <types.h>
#include <isr.h>
void keyboard_init(void);
void keyboard_handler(isr_stack_t* regs);
#endif

11
include/drivers/timer.h Normal file
View File

@ -0,0 +1,11 @@
#ifndef _TIMER_H
#define _TIMER_H
#include <stdint.h>
extern volatile uint32_t tick_count;
void timer_sleep(uint32_t ms);
void pit_init(uint32_t frequency);
#endif

View File

@ -1,6 +1,7 @@
#ifndef _FAT32_H
#define _FAT32_H
#include <stdint.h>
#include <types.h>
#define FAT32_MAX_FILENAME 11
#define FAT32_ATTR_DIRECTORY 0x10

View File

@ -3,21 +3,7 @@
#include <stdint.h>
struct gdt_entry {
uint16_t limit_low; /* Lower 16 bits of limit */
uint16_t base_low; /* Lower 16 bits of base */
uint8_t base_middle; /* Next 8 bits of base */
uint8_t access; /* Access flags */
uint8_t granularity; /* Granularity + high 4 bits of limit */
uint8_t base_high; /* Last 8 bits of base */
} __attribute__((packed));
struct gdt_ptr {
uint16_t limit; /* Size of GDT - 1 */
uint32_t base; /* Base address of GDT */
} __attribute__((packed));
void gdt_install();
void gdt_set_entry(int num, uint32_t base, uint32_t limit, uint8_t access, uint8_t gran);
void gdt_install(bool prnt_gdt);
void create_descriptor(int index, uint32_t base, uint32_t limit, uint16_t flag, bool prnt_gdt);
#endif

View File

@ -1,25 +0,0 @@
#ifndef _IDT_H
#define _IDT_H
#include <stdint.h>
struct idt_entry {
uint16_t base_low;
uint16_t sel; /* Kernel segment selector */
uint8_t always0; /* Always 0 */
uint8_t flags; /* Type and attributes */
uint16_t base_high;
} __attribute__((packed));
struct idt_ptr {
uint16_t limit;
uint32_t base;
} __attribute__((packed));
void idt_install(void);
void idt_install_isrs(void);
void idt_install_syscall(void);
void pic_remap(void);
void idt_set_entry(int num, uint32_t base, uint16_t sel, uint8_t flags);
#endif

View File

@ -4,7 +4,6 @@
#define ESPRESSO_IO_H
#include <stdint.h>
#include <text_display.h>
void print(const char* str);
@ -13,4 +12,4 @@ char* input(uint8_t dev=0);
void writefile(uint8_t mode, char* file, char* data);
char* readfile(char* file);
#endif
#endif

View File

@ -1,23 +0,0 @@
#ifndef _ISR_H
#define _ISR_H
#include <types.h>
typedef struct {
uint32_t ds, edi, esi, ebp, esp, ebx, edx, ecx, eax;
uint32_t int_no, err_code;
uint32_t eip, cs, eflags, useresp, ss;
} regs_t;
typedef struct {
uint32_t ds;
uint32_t edi, esi, ebp, esp, ebx, edx, ecx, eax;
uint32_t int_no, err_code;
uint32_t eip, cs, eflags, useresp, ss;
} isr_stack_t;
void isr_handler(isr_stack_t *r);
void syscall_handler(regs_t *r);
void register_interrupt_handler(uint8_t n, void (*handler)(isr_stack_t *));
#endif

View File

@ -1,8 +0,0 @@
#ifndef _SYSCALLS_H
#define _SYSCALLS_H
#include <stdint.h>
int16_t syscall_write(int32_t fd, const void* buffer, int32_t length);
#endif

View File

@ -14,6 +14,7 @@ void printf(const char*, ...);
void print_int(int32_t value);
void print_uint(uint32_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);
#endif