Pridana verze v0.1
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* AsterOS Kernel
|
||||
* Autor: Pavel Kalas
|
||||
* Rok: 2026
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Tento header definuje experimentalni API vrstvu pro C aplikace.
|
||||
* API je navrzene pro budouci user-space runtime, ale lze ho uz ted
|
||||
* pouzit pro jednotne volani kernel sluzeb v internich aplikacich.
|
||||
*/
|
||||
|
||||
#ifndef ASTER_API_H
|
||||
#define ASTER_API_H
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#define ASTER_APP_API_VERSION 1
|
||||
|
||||
typedef struct {
|
||||
u32 api_version;
|
||||
u32 reserved;
|
||||
} aster_app_context_t;
|
||||
|
||||
int aster_api_print(const char *text);
|
||||
int aster_api_clear(void);
|
||||
int aster_api_ticks(u64 *out_ticks);
|
||||
void *aster_api_alloc(usize size);
|
||||
int aster_api_file_create(const char *path);
|
||||
int aster_api_file_read(const char *path, u8 *out, u16 max_len);
|
||||
int aster_api_file_write(const char *path, const u8 *data, u16 len);
|
||||
int aster_api_process_spawn(void (*entry)(void), const char *name, u8 priority);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
* AsterOS Kernel
|
||||
* Autor: Pavel Kalaš
|
||||
* Rok: 2026
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Tento header definuje datovy tvar CPU kontextu ulozeneho pri preruseni.
|
||||
* Obsahuje strukturu interrupt_frame_t a rozhrani pro inicializaci CPU,
|
||||
* nastaveni tabulek preruseni a centralni dispatch obsluhy preruseni.
|
||||
*/
|
||||
|
||||
#ifndef ASTER_CPU_H
|
||||
#define ASTER_CPU_H
|
||||
|
||||
#include "types.h"
|
||||
|
||||
typedef struct {
|
||||
u64 r15;
|
||||
u64 r14;
|
||||
u64 r13;
|
||||
u64 r12;
|
||||
u64 r11;
|
||||
u64 r10;
|
||||
u64 r9;
|
||||
u64 r8;
|
||||
u64 rsi;
|
||||
u64 rdi;
|
||||
u64 rbp;
|
||||
u64 rdx;
|
||||
u64 rcx;
|
||||
u64 rbx;
|
||||
u64 rax;
|
||||
u64 vector;
|
||||
u64 error;
|
||||
u64 rip;
|
||||
u64 cs;
|
||||
u64 rflags;
|
||||
u64 rsp;
|
||||
u64 ss;
|
||||
} interrupt_frame_t;
|
||||
|
||||
void cpu_init(void);
|
||||
void interrupts_init(void);
|
||||
void interrupt_dispatch(interrupt_frame_t *frame);
|
||||
void cpu_halt(void);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* AsterOS Kernel
|
||||
* Autor: Pavel Kalaš
|
||||
* Rok: 2026
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Tento header vystavuje jednotne API pro textovy vystup v VGA rezimu.
|
||||
* Definuje operace pro inicializaci, cisteni obrazovky, zapis znaku,
|
||||
* zapis retezce a zmenu barevne palety textove konzole.
|
||||
*/
|
||||
|
||||
#ifndef ASTER_DISPLAY_H
|
||||
#define ASTER_DISPLAY_H
|
||||
|
||||
#include "types.h"
|
||||
|
||||
void display_init(void);
|
||||
void display_clear(void);
|
||||
void display_putc(char c);
|
||||
void display_write(const char *text);
|
||||
void display_set_color(u8 fg, u8 bg);
|
||||
void display_get_cursor(usize *out_row, usize *out_col);
|
||||
void display_set_cursor(usize new_row, usize new_col);
|
||||
void display_fill_row(usize target_row, char ch, u8 fg, u8 bg);
|
||||
void display_write_at(usize target_row, usize target_col, const char *text, u8 fg, u8 bg);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* AsterOS Kernel
|
||||
* Autor: Pavel Kalaš
|
||||
* Rok: 2026
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Tento soubor slouzi jako centralni rozcestnik pro verejne ovladace jadra.
|
||||
* Drzi pohromade deklarace klavesnice, casovace a storage vrstvy,
|
||||
* aby je kernel mohl jednoduse inicializovat z jednoho mista.
|
||||
*/
|
||||
|
||||
#ifndef ASTER_DRIVERS_H
|
||||
#define ASTER_DRIVERS_H
|
||||
|
||||
#define ASTER_KEY_F1 0x101
|
||||
#define ASTER_KEY_F2 0x102
|
||||
#define ASTER_KEY_UP 0x103
|
||||
#define ASTER_KEY_DOWN 0x104
|
||||
#define ASTER_KEY_LEFT 0x105
|
||||
#define ASTER_KEY_RIGHT 0x106
|
||||
|
||||
void keyboard_init(void);
|
||||
int keyboard_read_key(void);
|
||||
int keyboard_try_read_key(void);
|
||||
int keyboard_readline(char *buffer, int max_len);
|
||||
|
||||
void timer_init(unsigned int hz);
|
||||
unsigned long timer_ticks(void);
|
||||
|
||||
void storage_init(void);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* AsterOS Kernel
|
||||
* Autor: Pavel Kalaš
|
||||
* Rok: 2026
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Tento header definuje rozhrani pametoveho subsystému jadra.
|
||||
* Obsahuje API pro allocator fyzickych stranek, jednoduche heap alokace
|
||||
* a funkce pro cteni zakladnich statistik o celkove a volne pameti.
|
||||
*/
|
||||
|
||||
#ifndef ASTER_MEMORY_H
|
||||
#define ASTER_MEMORY_H
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#define PAGE_SIZE 4096
|
||||
|
||||
void memory_init(void);
|
||||
void *page_alloc(void);
|
||||
void page_free(void *page);
|
||||
void *kmalloc(usize size);
|
||||
void kfree(void *ptr);
|
||||
usize memory_total_pages(void);
|
||||
usize memory_free_pages(void);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* AsterOS Kernel
|
||||
* Autor: Pavel Kalaš
|
||||
* Rok: 2026
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Tento header deklaruje fatalni panic cestu jadra.
|
||||
* Funkce panic je urcena pro situace, kdy nelze bezpecne pokracovat,
|
||||
* proto vypise duvod chyby a prevede system do zastaveneho stavu.
|
||||
*/
|
||||
|
||||
#ifndef ASTER_PANIC_H
|
||||
#define ASTER_PANIC_H
|
||||
|
||||
void panic(const char *reason);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,20 @@
|
||||
/*
|
||||
* AsterOS Kernel
|
||||
* Autor: Pavel Kalaš
|
||||
* Rok: 2026
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Tento soubor definuje rozhrani pro kernelovy diagnosticky vystup.
|
||||
* Poskytuje jednoduche API pro vypis retezce i formatovany log,
|
||||
* ktery slouzi pro ladeni bootu, preruseni i behu kernel sluzeb.
|
||||
*/
|
||||
|
||||
#ifndef ASTER_PRINTK_H
|
||||
#define ASTER_PRINTK_H
|
||||
|
||||
void aster_print(const char *text);
|
||||
void printk(const char *fmt, ...);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* AsterOS Kernel
|
||||
* Autor: Pavel Kalaš
|
||||
* Rok: 2026
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Tento header popisuje procesovy model jadra.
|
||||
* Obsahuje stavy procesu, kontext CPU registru a strukturu process_t,
|
||||
* plus API pro vytvareni procesu, ukonceni a pristup k procesove tabulce.
|
||||
*/
|
||||
|
||||
#ifndef ASTER_PROCESS_H
|
||||
#define ASTER_PROCESS_H
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#define ASTER_MAX_PROCESSES 16
|
||||
|
||||
typedef enum {
|
||||
PROCESS_UNUSED = 0,
|
||||
PROCESS_READY,
|
||||
PROCESS_RUNNING,
|
||||
PROCESS_BLOCKED,
|
||||
PROCESS_EXITED
|
||||
} process_state_t;
|
||||
|
||||
typedef struct {
|
||||
u64 r15;
|
||||
u64 r14;
|
||||
u64 r13;
|
||||
u64 r12;
|
||||
u64 rbx;
|
||||
u64 rbp;
|
||||
u64 rip;
|
||||
} context_t;
|
||||
|
||||
typedef struct {
|
||||
u32 pid;
|
||||
process_state_t state;
|
||||
u8 priority;
|
||||
u8 *stack_base;
|
||||
u64 stack_top;
|
||||
context_t context;
|
||||
const char *name;
|
||||
} process_t;
|
||||
|
||||
void process_init(void);
|
||||
process_t *process_create(const char *name, void (*entry)(void), u8 priority);
|
||||
void process_exit(void);
|
||||
process_t *process_current(void);
|
||||
void process_set_current(process_t *p);
|
||||
process_t *process_table(void);
|
||||
usize process_count(void);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* AsterOS Kernel
|
||||
* Autor: Pavel Kalaš
|
||||
* Rok: 2026
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Tento soubor deklaruje planovac, ktery rozhoduje o prideleni CPU casu.
|
||||
* Popisuje vstupni body pro inicializaci, periodicky tick a prepnuti,
|
||||
* a funkce pro vyber dalsiho kandidata k vykonu.
|
||||
*/
|
||||
|
||||
#ifndef ASTER_SCHEDULER_H
|
||||
#define ASTER_SCHEDULER_H
|
||||
|
||||
#include "process.h"
|
||||
|
||||
void scheduler_init(void);
|
||||
void scheduler_tick(void);
|
||||
void scheduler_run_once(void);
|
||||
void scheduler_yield(void);
|
||||
process_t *scheduler_pick_next(void);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* AsterOS Kernel
|
||||
* Autor: Pavel Kalaš
|
||||
* Rok: 2026
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Tento header definuje verejne rozhrani jednoducheho AsterFS.
|
||||
* Popisuje format uzlu souboru nebo adresare a deklaruje operace
|
||||
* pro inicializaci, vytvareni, cteni, zapis a vypis obsahu.
|
||||
*/
|
||||
|
||||
#ifndef ASTER_STORAGE_H
|
||||
#define ASTER_STORAGE_H
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#define ASTERFS_MAX_FILES 64
|
||||
#define ASTERFS_NAME_LEN 64
|
||||
#define ASTERFS_DATA_LEN 512
|
||||
|
||||
typedef struct {
|
||||
char name[ASTERFS_NAME_LEN];
|
||||
u8 is_dir;
|
||||
u16 size;
|
||||
u8 data[ASTERFS_DATA_LEN];
|
||||
} asterfs_node_t;
|
||||
|
||||
void asterfs_init(void);
|
||||
int asterfs_create_file(const char *name);
|
||||
int asterfs_create_dir(const char *name);
|
||||
int asterfs_remove_file(const char *name);
|
||||
int asterfs_remove_dir(const char *name);
|
||||
int asterfs_write_file(const char *name, const u8 *data, u16 len);
|
||||
int asterfs_read_file(const char *name, u8 *out, u16 max_len);
|
||||
int asterfs_get_type(const char *name);
|
||||
void asterfs_list(void (*cb)(const char *name, u8 is_dir, u16 size));
|
||||
void asterfs_list_dir(const char *path, void (*cb)(const char *name, u8 is_dir, u16 size));
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* AsterOS Kernel
|
||||
* Autor: Pavel Kalaš
|
||||
* Rok: 2026
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Tento soubor deklaruje minimalisticke utility bez zavislosti na libc.
|
||||
* Obsahuje zakladni operace nad retezci a pameti, ktere kernel potrebuje
|
||||
* uz v ranych fazich bootu, kdy standardni knihovny nejsou dostupne.
|
||||
*/
|
||||
|
||||
#ifndef ASTER_STRING_H
|
||||
#define ASTER_STRING_H
|
||||
|
||||
#include "types.h"
|
||||
|
||||
usize aster_strlen(const char *s);
|
||||
int aster_strcmp(const char *a, const char *b);
|
||||
int aster_strncmp(const char *a, const char *b, usize n);
|
||||
void *aster_memcpy(void *dst, const void *src, usize n);
|
||||
void *aster_memset(void *dst, int v, usize n);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* AsterOS Kernel
|
||||
* Autor: Pavel Kalaš
|
||||
* Rok: 2026
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Tento header popisuje syscall ABI mezi user casti a jadrem.
|
||||
* Definuje cisla volani, centralni dispatcher a obalove funkce,
|
||||
* ktere mapuji uzivatelske pozadavky na kernelove sluzby.
|
||||
*/
|
||||
|
||||
#ifndef ASTER_SYSCALL_H
|
||||
#define ASTER_SYSCALL_H
|
||||
|
||||
#include "types.h"
|
||||
|
||||
#define SYSCALL_WRITE 0
|
||||
#define SYSCALL_ALLOC 1
|
||||
#define SYSCALL_PROCESS_CREATE 2
|
||||
|
||||
void syscall_init(void);
|
||||
u64 syscall_dispatch(u64 id, u64 a1, u64 a2, u64 a3, u64 a4);
|
||||
|
||||
u64 aster_write(const char *text);
|
||||
void *aster_alloc(usize size);
|
||||
i64 aster_process_create(void (*entry)(void), const char *name, u8 priority);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* AsterOS Kernel
|
||||
* Autor: Pavel Kalaš
|
||||
* Rok: 2026
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Tento soubor deklaruje casovaci vrstvu nad PIT hardwarem.
|
||||
* Zahrnuje inicializaci frekvence, cteni tiku, inkrement z ISR
|
||||
* a blokujici uspani jadra na zadany pocet milisekund.
|
||||
*/
|
||||
|
||||
#ifndef ASTER_TIMER_H
|
||||
#define ASTER_TIMER_H
|
||||
|
||||
void timer_init(unsigned int hz);
|
||||
unsigned long timer_ticks(void);
|
||||
void timer_tick_advance(void);
|
||||
void timer_sleep_ms(unsigned long ms);
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* AsterOS Kernel
|
||||
* Autor: Pavel Kalaš
|
||||
* Rok: 2026
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* Tento header sjednocuje zakladni celoctiselne typy jadra.
|
||||
* Cilem je mit stabilni velikosti typu nezavisle na kompilatoru
|
||||
* a pouzivat je konzistentne ve vsech kernel subsystémech.
|
||||
*/
|
||||
|
||||
#ifndef ASTER_TYPES_H
|
||||
#define ASTER_TYPES_H
|
||||
|
||||
typedef unsigned long long u64;
|
||||
typedef signed long long i64;
|
||||
typedef unsigned int u32;
|
||||
typedef signed int i32;
|
||||
typedef unsigned short u16;
|
||||
typedef signed short i16;
|
||||
typedef unsigned char u8;
|
||||
typedef signed char i8;
|
||||
typedef unsigned long usize;
|
||||
typedef long isize;
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user