This commit is contained in:
2025-05-28 14:41:02 -05:00
commit 6d366537dd
73 changed files with 4448 additions and 0 deletions

6
include/drivers/ahci.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef _AHCI_H
#define _AHCI_H
#endif

40
include/drivers/ide.h Normal file
View File

@ -0,0 +1,40 @@
#ifndef _IDE_H
#define _IDE_H
#include <stdint.h>
#include <stddef.h>
#define ATA_PRIMARY_IO 0x1F0
#define ATA_PRIMARY_CTRL 0x3F6
#define ATA_MASTER 0x00
#define ATA_SLAVE 0x10
#define ATA_REG_DATA 0x00
#define ATA_REG_ERROR 0x01
#define ATA_REG_SECCOUNT0 0x02
#define ATA_REG_LBA0 0x03
#define ATA_REG_LBA1 0x04
#define ATA_REG_LBA2 0x05
#define ATA_REG_LBA3 0x06 // LBA48 higher bits
#define ATA_REG_LBA4 0x07 // LBA48 higher bits
#define ATA_REG_LBA5 0x08 // LBA48 higher bits
#define ATA_REG_HDDEVSEL 0x06
#define ATA_REG_COMMAND 0x07
#define ATA_REG_STATUS 0x07
#define ATA_CMD_READ_SECTORS 0x20
#define ATA_CMD_WRITE_SECTORS 0x30
#define ATA_CMD_READ_SECTORS_EXT 0x24
#define ATA_CMD_WRITE_SECTORS_EXT 0x34
#define ATA_SR_BSY 0x80
#define ATA_SR_DRDY 0x40
#define ATA_SR_DRQ 0x08
#define ATA_SR_ERR 0x01
void ide_initialize(void);
int32_t ide_identify(uint8_t drive, uint16_t* buffer);
int32_t ide_read48(uint8_t drive, uint64_t lba, uint8_t sector_count, void* buffer);
int32_t ide_write48(uint8_t drive, uint64_t lba, uint8_t sector_count, const void* buffer);
#endif

10
include/drivers/pci.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef _PCI_H
#define _PCI_H
#include <stdint.h>
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);
#endif

7
include/drivers/pit.h Normal file
View File

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

View File

@ -0,0 +1,10 @@
#ifndef _PS2_KEYBOARD_H
#define _PS2_KEYBOARD_H
#include <types.h>
#include <isr.h>
void keyboard_init(void);
void keyboard_handler(isr_stack_t* regs);
#endif

79
include/fs/duckfs.h Normal file
View File

@ -0,0 +1,79 @@
#ifndef _DUCKFS_H
#define _DUCKFS_H
#include <stdint.h>
#define DFS_MAGIC 0xDF1984CC
#define DFS_BLOCK_SIZE 512
#define DFS_VERSION_0 "DuckFS, wheresDax?"
#define DFS_VERSION_1 "DuckFS, Terminator"
#define DFS_VERSION_2 "DuckFS-Terminator2"
#define DFS_VERSION_3 "DuckFS,StarWarsEIV"
#define DFS_VERSION_4 "DuckFS QUACK,QUACK"
#define DFS_FILE_ERROR -8
#define DFS_FILE_UNUSED -1
#define DFS_FILE_USED 0
#define DFS_FILE_TEXT 0
#define DFS_FILE_BINARY 1
#define DFS_FILE_DIRECTORY 2
/* encryption algorithms */
#define DFS_CAESAR_5 88
#define DFS_CAESAR_8 84
#define DFS_CAESAR_2 09
#define DFS_QUACK_32 99
#define DFS_MAX_FILENAME_LEN 64
#define DFS_MAX_FILES 256
typedef struct duckfs_file_header {
char filename[DFS_MAX_FILENAME_LEN + 1]; /* + 1 for the \0 */
char permissions[3]; /* Same thing here */
/*
512 Bytes per sector, meaning a 2 sector file is 1024 bytes, or 1 KiB.
Only valid if this file is not a directory.
*/
int32_t num_sectors;
int16_t type; /* Indicates the file type. -1 for null file, 0 for a text file, 1 for a binary file, and 2 for a directory. */
uint16_t _reserved0; /* (align to 4) */
struct duckfs_file_header* next;
struct duckfs_file_header* prev;
struct duckfs_file_header* contents; /* contains the directories files. only valid if this file is a directory. */
uint32_t lba_start; /* only is valid if this file is not a directory. */
uint32_t lba_end; /* only is valid if this file is not a directory. */
uint8_t _reserved1[158]; /* padding to 256 bytes total */
} duckfs_file_header_t;
typedef struct duckfs_superblock {
int32_t duckfs_magic; /* must be DFS_MAGIC. */
char duckfs_version_string[19];
char volume_label[19]; /* 18 characters and a null zero. */
int16_t encryption;
struct duckfs_file_header* duckfs_root;
uint32_t _padding[116];
} duckfs_superblock_t;
int32_t duckfs_init(int16_t drive);
void duckfs_format(int16_t drive);
int32_t duckfs_makedir(const char* filename, const char* perms);
void duckfs_free_directory(duckfs_file_header_t* dir);
duckfs_file_header_t duckfs_create_entry(const char* name, const char* perms, const char* type);
bool duckfs_add_entry(duckfs_file_header_t* dir, duckfs_file_header_t* entry);
#endif

16
include/fs/fat32.h Normal file
View File

@ -0,0 +1,16 @@
#ifndef _FAT32_H
#define _FAT32_H
#include <stdint.h>
#define FAT32_MAX_FILENAME 11
#define FAT32_ATTR_DIRECTORY 0x10
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);
#endif

53
include/fs/ramfs.h Normal file
View File

@ -0,0 +1,53 @@
#ifndef _RAM_FS_H
#define _RAM_FS_H
#include <stdint.h>
#include <stdbool.h>
#define RAMFS_MAX_FILES 128
#define RAMFS_BLOCK_SIZE 4096
#define RAMFS_MAX_PATH_LEN 255
#define RAMFS_PERM_READ 0x01
#define RAMFS_PERM_WRITE 0x02
#define RAMFS_PERM_EXEC 0x04
#define RAMFS_PERM_ALL (RAMFS_PERM_READ | RAMFS_PERM_WRITE | RAMFS_PERM_EXEC)
typedef struct ramfs_file {
char name[RAMFS_MAX_PATH_LEN];
uint32_t size;
uint8_t* data;
uint8_t permissions;
} ramfs_file_t;
typedef struct ramfs_directory {
char name[RAMFS_MAX_PATH_LEN];
ramfs_file_t* files[RAMFS_MAX_FILES];
uint32_t file_count;
} ramfs_directory_t;
void ramfs_init();
ramfs_file_t* ramfs_create_file(const char* name, uint32_t size, uint8_t permissions);
bool ramfs_delete_file(const char* name);
ramfs_file_t* ramfs_find_file(const char* name);
bool ramfs_create_directory(const char* name);
bool ramfs_delete_directory(const char* name);
bool ramfs_check_permissions(const char* name, uint8_t required_permissions);
bool ramfs_resize_file(const char* name, uint32_t new_size);
bool ramfs_append_to_file(const char* name, const uint8_t* data, uint32_t data_size);
bool ramfs_read_file(const char* name, uint8_t* buffer, uint32_t buffer_size);
bool ramfs_write_file(const char* name, const uint8_t* data, uint32_t size);
bool ramfs_overwrite_file(const char* name, const uint8_t* data, uint32_t size);
void ramfs_list_files();
void ramfs_list_directories();
#endif

23
include/gdt.h Normal file
View File

@ -0,0 +1,23 @@
#ifndef _GDT_H
#define _GDT_H
#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);
#endif

25
include/idt.h Normal file
View File

@ -0,0 +1,25 @@
#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

16
include/io.h Normal file
View File

@ -0,0 +1,16 @@
/* Defines a abstract base for I/O in the Espresso kernel. */
#ifndef ESPRESSO_IO_H
#define ESPRESSO_IO_H
#include <stdint.h>
#include <text_display.h>
void print(const char* str);
char* input(uint8_t dev=0);
void writefile(uint8_t mode, char* file, char* data);
char* readfile(char* file);
#endif

23
include/isr.h Normal file
View File

@ -0,0 +1,23 @@
#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

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

@ -0,0 +1,7 @@
#ifndef _KERNEL_BOOT_H
#define _KERNEL_BOOT_H
uint8_t parse_boot_data(const char* data);
#endif

View File

@ -0,0 +1,8 @@
#ifndef _INTRO_ANIMATION_H
#define _INTRO_ANIMATION_H
#include <types.h>
int16_t begin_anim(const char* version);
#endif

View File

@ -0,0 +1,8 @@
#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

@ -0,0 +1,18 @@
#ifndef _SOFTWARE_FLOAT_H
#define _SOFTWARE_FLOAT_H
#include <stdint.h>
typedef struct {
uint8_t sign; /* 0 = positive, 1 = negative */
uint8_t exponent; /* 8-bit biased exponent (bias = 127) */
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

19
include/mm/heap.h Normal file
View File

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

8
include/mm/mm.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef _MM_H
#define _MM_H
#include <mm/pmm.h>
#include <mm/heap.h>
#include <mm/paging.h>
#endif

9
include/mm/paging.h Normal file
View File

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

11
include/mm/pmm.h Normal file
View File

@ -0,0 +1,11 @@
#ifndef _PMM_H
#define _PMM_H
#include <stdint.h>
#include <multiboot.h>
void pmm_init(multiboot_info_t* mb_info);
void* alloc_page(void);
void free_page(void* ptr);
#endif

274
include/multiboot.h Normal file
View File

@ -0,0 +1,274 @@
/* multiboot.h - Multiboot header file. */
/* Copyright (C) 1999,2003,2007,2008,2009,2010 Free Software Foundation, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
* deal in the Software without restriction, including without limitation the
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
* sell copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ANY
* DEVELOPER OR DISTRIBUTOR BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
* IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#ifndef MULTIBOOT_HEADER
#define MULTIBOOT_HEADER 1
/* How many bytes from the start of the file we search for the header. */
#define MULTIBOOT_SEARCH 8192
#define MULTIBOOT_HEADER_ALIGN 4
/* The magic field should contain this. */
#define MULTIBOOT_HEADER_MAGIC 0x1BADB002
/* This should be in %eax. */
#define MULTIBOOT_BOOTLOADER_MAGIC 0x2BADB002
/* Alignment of multiboot modules. */
#define MULTIBOOT_MOD_ALIGN 0x00001000
/* Alignment of the multiboot info structure. */
#define MULTIBOOT_INFO_ALIGN 0x00000004
/* Flags set in the flags member of the multiboot header. */
/* Align all boot modules on i386 page (4KB) boundaries. */
#define MULTIBOOT_PAGE_ALIGN 0x00000001
/* Must pass memory information to OS. */
#define MULTIBOOT_MEMORY_INFO 0x00000002
/* Must pass video information to OS. */
#define MULTIBOOT_VIDEO_MODE 0x00000004
/* This flag indicates the use of the address fields in the header. */
#define MULTIBOOT_AOUT_KLUDGE 0x00010000
/* Flags to be set in the flags member of the multiboot info structure. */
/* is there basic lower/upper memory information? */
#define MULTIBOOT_INFO_MEMORY 0x00000001
/* is there a boot device set? */
#define MULTIBOOT_INFO_BOOTDEV 0x00000002
/* is the command-line defined? */
#define MULTIBOOT_INFO_CMDLINE 0x00000004
/* are there modules to do something with? */
#define MULTIBOOT_INFO_MODS 0x00000008
/* These next two are mutually exclusive */
/* is there a symbol table loaded? */
#define MULTIBOOT_INFO_AOUT_SYMS 0x00000010
/* is there an ELF section header table? */
#define MULTIBOOT_INFO_ELF_SHDR 0X00000020
/* is there a full memory map? */
#define MULTIBOOT_INFO_MEM_MAP 0x00000040
/* Is there drive info? */
#define MULTIBOOT_INFO_DRIVE_INFO 0x00000080
/* Is there a config table? */
#define MULTIBOOT_INFO_CONFIG_TABLE 0x00000100
/* Is there a boot loader name? */
#define MULTIBOOT_INFO_BOOT_LOADER_NAME 0x00000200
/* Is there a APM table? */
#define MULTIBOOT_INFO_APM_TABLE 0x00000400
/* Is there video information? */
#define MULTIBOOT_INFO_VBE_INFO 0x00000800
#define MULTIBOOT_INFO_FRAMEBUFFER_INFO 0x00001000
#ifndef ASM_FILE
typedef unsigned char multiboot_uint8_t;
typedef unsigned short multiboot_uint16_t;
typedef unsigned int multiboot_uint32_t;
typedef unsigned long long multiboot_uint64_t;
struct multiboot_header
{
/* Must be MULTIBOOT_MAGIC - see above. */
multiboot_uint32_t magic;
/* Feature flags. */
multiboot_uint32_t flags;
/* The above fields plus this one must equal 0 mod 2^32. */
multiboot_uint32_t checksum;
/* These are only valid if MULTIBOOT_AOUT_KLUDGE is set. */
multiboot_uint32_t header_addr;
multiboot_uint32_t load_addr;
multiboot_uint32_t load_end_addr;
multiboot_uint32_t bss_end_addr;
multiboot_uint32_t entry_addr;
/* These are only valid if MULTIBOOT_VIDEO_MODE is set. */
multiboot_uint32_t mode_type;
multiboot_uint32_t width;
multiboot_uint32_t height;
multiboot_uint32_t depth;
};
/* The symbol table for a.out. */
struct multiboot_aout_symbol_table
{
multiboot_uint32_t tabsize;
multiboot_uint32_t strsize;
multiboot_uint32_t addr;
multiboot_uint32_t reserved;
};
typedef struct multiboot_aout_symbol_table multiboot_aout_symbol_table_t;
/* The section header table for ELF. */
struct multiboot_elf_section_header_table
{
multiboot_uint32_t num;
multiboot_uint32_t size;
multiboot_uint32_t addr;
multiboot_uint32_t shndx;
};
typedef struct multiboot_elf_section_header_table multiboot_elf_section_header_table_t;
struct multiboot_info
{
/* Multiboot info version number */
multiboot_uint32_t flags;
/* Available memory from BIOS */
multiboot_uint32_t mem_lower;
multiboot_uint32_t mem_upper;
/* "root" partition */
multiboot_uint32_t boot_device;
/* Kernel command line */
multiboot_uint32_t cmdline;
/* Boot-Module list */
multiboot_uint32_t mods_count;
multiboot_uint32_t mods_addr;
union
{
multiboot_aout_symbol_table_t aout_sym;
multiboot_elf_section_header_table_t elf_sec;
} u;
/* Memory Mapping buffer */
multiboot_uint32_t mmap_length;
multiboot_uint32_t mmap_addr;
/* Drive Info buffer */
multiboot_uint32_t drives_length;
multiboot_uint32_t drives_addr;
/* ROM configuration table */
multiboot_uint32_t config_table;
/* Boot Loader Name */
multiboot_uint32_t boot_loader_name;
/* APM table */
multiboot_uint32_t apm_table;
/* Video */
multiboot_uint32_t vbe_control_info;
multiboot_uint32_t vbe_mode_info;
multiboot_uint16_t vbe_mode;
multiboot_uint16_t vbe_interface_seg;
multiboot_uint16_t vbe_interface_off;
multiboot_uint16_t vbe_interface_len;
multiboot_uint64_t framebuffer_addr;
multiboot_uint32_t framebuffer_pitch;
multiboot_uint32_t framebuffer_width;
multiboot_uint32_t framebuffer_height;
multiboot_uint8_t framebuffer_bpp;
#define MULTIBOOT_FRAMEBUFFER_TYPE_INDEXED 0
#define MULTIBOOT_FRAMEBUFFER_TYPE_RGB 1
#define MULTIBOOT_FRAMEBUFFER_TYPE_EGA_TEXT 2
multiboot_uint8_t framebuffer_type;
union
{
struct
{
multiboot_uint32_t framebuffer_palette_addr;
multiboot_uint16_t framebuffer_palette_num_colors;
};
struct
{
multiboot_uint8_t framebuffer_red_field_position;
multiboot_uint8_t framebuffer_red_mask_size;
multiboot_uint8_t framebuffer_green_field_position;
multiboot_uint8_t framebuffer_green_mask_size;
multiboot_uint8_t framebuffer_blue_field_position;
multiboot_uint8_t framebuffer_blue_mask_size;
};
};
};
typedef struct multiboot_info multiboot_info_t;
struct multiboot_color
{
multiboot_uint8_t red;
multiboot_uint8_t green;
multiboot_uint8_t blue;
};
struct multiboot_mmap_entry
{
multiboot_uint32_t size;
multiboot_uint64_t addr;
multiboot_uint64_t len;
#define MULTIBOOT_MEMORY_AVAILABLE 1
#define MULTIBOOT_MEMORY_RESERVED 2
#define MULTIBOOT_MEMORY_ACPI_RECLAIMABLE 3
#define MULTIBOOT_MEMORY_NVS 4
#define MULTIBOOT_MEMORY_BADRAM 5
multiboot_uint32_t type;
} __attribute__((packed));
typedef struct multiboot_mmap_entry multiboot_memory_map_t;
struct multiboot_mod_list
{
/* the memory used goes from bytes mod_start to mod_end-1 inclusive */
multiboot_uint32_t mod_start;
multiboot_uint32_t mod_end;
/* Module command line */
multiboot_uint32_t cmdline;
/* padding to take it to 16 bytes (must be zero) */
multiboot_uint32_t pad;
};
typedef struct multiboot_mod_list multiboot_module_t;
/* APM BIOS info. */
struct multiboot_apm_info
{
multiboot_uint16_t version;
multiboot_uint16_t cseg;
multiboot_uint32_t offset;
multiboot_uint16_t cseg_16;
multiboot_uint16_t dseg;
multiboot_uint16_t flags;
multiboot_uint16_t cseg_len;
multiboot_uint16_t cseg_16_len;
multiboot_uint16_t dseg_len;
};
#endif /* ! ASM_FILE */
#endif /* ! MULTIBOOT_HEADER */

30
include/panic.h Normal file
View File

@ -0,0 +1,30 @@
#ifndef _KERNEL_PANIC_H
#define _KERNEL_PANIC_H
#include <stddef.h>
#include <tty.h>
void panic(const char* arr)
{
uint8_t color = 0x1F;
uint8_t blank = 0xFF;
for (size_t y = 0; y < VGA_HEIGHT; y++)
{
for (size_t x = 0; x < VGA_WIDTH; x++)
{
const size_t index = y * VGA_WIDTH + x;
VGA_MEMORY[index] = (uint16_t) ' ' | (uint16_t) blank << 8;
}
}
int i;
for (i = 0; i < 75; i += 2)
{
VGA_MEMORY[i] = arr[i];
VGA_MEMORY[i + 1] = color;
}
}
#endif

46
include/port_io.h Normal file
View File

@ -0,0 +1,46 @@
#ifndef _PORT_IO_H
#define _PORT_IO_H
#include <stdint.h>
static inline uint32_t inl(uint16_t port)
{
uint32_t rv;
asm volatile ("inl %%dx, %%eax" : "=a" (rv) : "dN" (port));
return rv;
}
static inline void outl(uint16_t port, uint32_t data)
{
asm volatile ("outl %%eax, %%dx" : : "dN" (port), "a" (data));
}
static inline void outb(uint16_t port, uint8_t val)
{
asm volatile ( "outb %0, %1" : : "a"(val), "Nd"(port) : "memory");
}
static inline uint8_t inb(uint16_t port)
{
uint8_t ret;
asm volatile ( "inb %1, %0"
: "=a"(ret)
: "Nd"(port)
: "memory");
return ret;
}
static inline void io_wait()
{
outb(0x80, 0);
}
static inline void insw(uint16_t port, void* addr, uint32_t count) {
__asm__ volatile ("rep insw" : "+D"(addr), "+c"(count) : "d"(port) : "memory");
}
static inline void outsw(uint16_t port, const void* addr, uint32_t count) {
__asm__ volatile ("rep outsw" : "+S"(addr), "+c"(count) : "d"(port));
}
#endif

19
include/printf.h Normal file
View File

@ -0,0 +1,19 @@
#ifndef _PRINTF_H
#define _PRINTF_H
#include <tty.h>
#include <string.h>
#include <vga/vga.h> /* Only for the vga_color enum */
void printwc(const char*, uint8_t);
void printd(const char* str);
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_double(double value, int precision);
#endif

19
include/processes.h Normal file
View File

@ -0,0 +1,19 @@
#ifndef _PROCESSES_H
#define _PROCESSES_H
#include <stdint.h>
struct process
{
uint16_t id;
uint8_t policy;
uint16_t priority;
char name[16];
struct process* next;
};
#endif

2
include/stdio.h Normal file
View File

@ -0,0 +1,2 @@
#include <printf.h>

9
include/stdlib.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef STDLIB_H
#define STDLIB_H
#include <mm/mm.h>
#include <stdio.h>
#include <string.h>
#include <types.h>
#endif

27
include/string.h Normal file
View File

@ -0,0 +1,27 @@
#ifndef STRING_H
#define STRING_H
#include <types.h>
/* 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 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 ischar(int32_t c);
int32_t isspace(char c);
int32_t isalpha(char c);
char upper(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);
#endif

6
include/syscall.h Normal file
View File

@ -0,0 +1,6 @@
#ifndef _SYSCALL_H
#define _SYSCALL_H
#endif

28
include/tty.h Normal file
View File

@ -0,0 +1,28 @@
#ifndef _TTY_H
#define _TTY_H
#include <stddef.h>
#include <stdbool.h>
#include <stdint.h>
static const size_t VGA_WIDTH = 80;
static const size_t VGA_HEIGHT = 25;
static uint16_t* const VGA_MEMORY = (uint16_t*) 0xB8000;
void terminal_initialize(void);
void terminal_initializec(uint8_t color);
void terminal_putentryat(unsigned char c, uint8_t color, size_t x, size_t y);
void terminal_putchar(char c);
void terminal_write(const char* data, size_t size);
void terminal_writestring(const char* data);
void terminal_debug_writestring(const char* data);
void terminal_setcolor(uint8_t color);
uint8_t terminal_getcolor(void);
void terminal_clear(void);
void terminal_clearl(size_t num_lines);
void terminal_scroll(void);
#endif

8
include/types.h Normal file
View File

@ -0,0 +1,8 @@
#ifndef _TYPES_H
#define _TYPES_H
#include <stdint.h>
#include <stddef.h>
#include <stdbool.h>
#endif

View File

@ -0,0 +1,27 @@
#ifndef _SSE_H
#define _SSE_H
#define SSE_XMM_SIZE 128
void enable_sse(void);
int32_t test_sse(void);
void sse2_add_double_arrays(double *dst, const double *a, const double *b, size_t count);
void sse2_add_int32_arrays(int32_t *dst, const int32_t *a, const int32_t *b, size_t count);
void sse2_add_int64_arrays(int64_t *dst, const int64_t *a, const int64_t *b, size_t count);
char *sse2_strncpy(char *dest, const char *src, uint32_t n);
void *sse2_memcpy(void *dst, const void *src, uint32_t n);
void double_vector_to_int_vector(const double *src, int32_t *dst);
void int_vector_to_double_vector(const int32_t *src, double *dst);
void *memclr_sse2(const void *const m_start, const size_t m_count);
#endif

30
include/vga/vga.h Normal file
View File

@ -0,0 +1,30 @@
#ifndef VGA_DRIVER_H
#define VGA_DRIVER_H
#include <stdint.h>
/* Hardware text mode color constants. */
enum vga_color {
VGA_COLOR_BLACK = 0,
VGA_COLOR_BLUE = 1,
VGA_COLOR_GREEN = 2,
VGA_COLOR_CYAN = 3,
VGA_COLOR_RED = 4,
VGA_COLOR_MAGENTA = 5,
VGA_COLOR_BROWN = 6,
VGA_COLOR_LIGHT_GREY = 7,
VGA_COLOR_DARK_GREY = 8,
VGA_COLOR_LIGHT_BLUE = 9,
VGA_COLOR_LIGHT_GREEN = 10,
VGA_COLOR_LIGHT_CYAN = 11,
VGA_COLOR_LIGHT_RED = 12,
VGA_COLOR_LIGHT_MAGENTA = 13,
VGA_COLOR_LIGHT_BROWN = 14,
VGA_COLOR_WHITE = 15,
};
uint8_t vga_entry_color(enum vga_color fg, enum vga_color bg);
uint16_t vga_entry(unsigned char uc, uint8_t color);
#endif