Compare commits

...
10 Commits
Author SHA1 Message Date
pavelkalas 3a52d15dd8 Kernel: vylepšen setup/restart tok a napojen bootlog na chybu odpojení média 2026-07-13 21:57:01 +02:00
pavelkalas 9b6afdeee0 AsterFS: odolnější serializace uzlů a bezpečnější flush na disk 2026-07-13 21:56:58 +02:00
pavelkalas be1841d633 AsterFS: přidána deklarace asterfs_sync do veřejného rozhraní 2026-07-13 21:56:54 +02:00
pavelkalas 12033fe1b2 Bootloader: načítání počtu sektorů jádra z generovaného include 2026-07-13 21:56:46 +02:00
pavelkalas 05734c710a Build: zapojen bootlog objekt a generování počtu sektorů jádra 2026-07-13 21:56:40 +02:00
pavelkalas feeadfd1fa Přidán modul bootlog pro stavové výpisy 2026-07-13 21:56:37 +02:00
pavelkalas 457a8c0a43 Přidán header bootlogu s jednotným stavovým API 2026-07-13 21:43:36 +02:00
pavelkalas 337d806183 sysapps: přidaná ukázková appka helloworld
Přidáno: sysapps/helloworld.c

- nová appka s entrypointem void init(void)

- vypisuje text 'Hello, world!' přes aster_api_print

Upraveno/Odstraněno: nic
2026-07-13 20:59:32 +02:00
pavelkalas fd44a945fb headers: přidaný runtime kontrakt pro sysapps
Přidáno: include/sysapps_runtime.h

- typ funkce sysapp_init_fn_t s podpisem void init(void)

- struktura sysapp_entry_t (name + entry)

- extern deklarace registru g_sysapps

Upraveno/Odstraněno: nic
2026-07-13 20:59:22 +02:00
pavelkalas 1235929f17 shell: spuštění sysapps podle názvu příkazu
Upraveno: kernel/main.c

- přidané napojení na runtime registr sysapps

- přidaná funkce run_sysapp_by_name()

- shell teď před chybou 'Neznamy prikaz' zkusí sysapp

- doplněná help hláška o příkazech ze složky sysapps

Přidáno/Odstraněno: nic mimo kernel/main.c
2026-07-13 20:59:15 +02:00
9 changed files with 292 additions and 38 deletions
+11 -2
View File
@@ -28,6 +28,7 @@ KERNEL_OBJS := \
$(BUILD)/arch/x86_64/interrupts.o \
$(BUILD)/arch/x86_64/cpu.o \
$(BUILD)/kernel/main.o \
$(BUILD)/kernel/bootlog.o \
$(BUILD)/kernel/panic.o \
$(BUILD)/kernel/printk.o \
$(BUILD)/kernel/memory.o \
@@ -54,8 +55,16 @@ $(BUILD):
$(BUILD)/boot/boot.bin: boot/boot.asm | $(BUILD)
$(AS) -f bin $< -o $@
$(BUILD)/boot/stage2.bin: boot/stage2.asm boot/disk.asm | $(BUILD)
$(AS) -I boot/ -f bin $< -o $@
$(BUILD)/boot/kernel_sectors.inc: $(BUILD)/kernel.bin | $(BUILD)
mkdir -p $(dir $@)
@size=$$(wc -c < $(BUILD)/kernel.bin); \
sectors=$$(( (size + 511) / 512 )); \
if [ $$sectors -lt 1 ]; then sectors=1; fi; \
echo "; auto-generated from build/kernel.bin" > $@; \
echo "KERNEL_SECTORS equ $$sectors" >> $@
$(BUILD)/boot/stage2.bin: boot/stage2.asm boot/disk.asm $(BUILD)/boot/kernel_sectors.inc | $(BUILD)
$(AS) -I boot/ -I $(BUILD)/boot/ -f bin $< -o $@
$(BUILD)/arch/x86_64/%.o: arch/x86_64/%.asm | $(BUILD)
$(AS) -f elf64 $< -o $@
+1 -1
View File
@@ -11,8 +11,8 @@
jmp start2
%include "disk.asm"
%include "kernel_sectors.inc"
KERNEL_SECTORS equ 256
KERNEL_START_LBA equ 17
KERNEL_LOAD_SEG equ 0x1000
PML4_ADDR equ 0x00070000
+55 -17
View File
@@ -38,8 +38,6 @@
#define ASTERFS_MAGIC "ASTERFS1"
#define ASTERFS_VERSION 1U
#define ASTERFS_NODE_BYTES (ASTERFS_NAME_LEN + 1 + 2 + 1 + ASTERFS_DATA_LEN)
#define ASTERFS_NODE_SECTORS (((ASTERFS_MAX_FILES * ASTERFS_NODE_BYTES) + 511) / 512)
#define ASTERFS_DISK_START_LBA 1U
typedef struct {
@@ -56,7 +54,12 @@ typedef struct {
u16 size;
u8 reserved;
u8 data[ASTERFS_DATA_LEN];
} asterfs_disk_node_t;
} __attribute__((packed)) asterfs_disk_node_t;
#define ASTERFS_NODE_BYTES ((usize)sizeof(asterfs_disk_node_t))
#define ASTERFS_NODE_SECTORS (((ASTERFS_MAX_FILES * ASTERFS_NODE_BYTES) + 511) / 512)
_Static_assert(sizeof(asterfs_disk_node_t) == (ASTERFS_NAME_LEN + 1 + 2 + 1 + ASTERFS_DATA_LEN),
"asterfs_disk_node_t layout mismatch");
static asterfs_node_t nodes[ASTERFS_MAX_FILES];
static int nodes_used = 0;
@@ -222,31 +225,39 @@ static void fs_reset_memory(void) {
nodes_used = 0;
}
static void fs_encode_nodes(u8 *out) {
static void fs_encode_nodes(void) {
int i;
for (i = 0; i < ASTERFS_MAX_FILES; ++i) {
asterfs_disk_node_t d;
usize off = (usize)i * ASTERFS_NODE_BYTES;
if (off + ASTERFS_NODE_BYTES > sizeof(g_nodes_blob)) {
break;
}
aster_memset(&d, 0, sizeof(d));
aster_memcpy(d.name, nodes[i].name, ASTERFS_NAME_LEN);
d.is_dir = nodes[i].is_dir;
d.size = nodes[i].size;
aster_memcpy(d.data, nodes[i].data, ASTERFS_DATA_LEN);
aster_memcpy(out + off, &d, ASTERFS_NODE_BYTES);
aster_memcpy(g_nodes_blob + off, &d, ASTERFS_NODE_BYTES);
}
}
static void fs_decode_nodes(const u8 *in) {
static void fs_decode_nodes(void) {
int i;
for (i = 0; i < ASTERFS_MAX_FILES; ++i) {
asterfs_disk_node_t d;
usize off = (usize)i * ASTERFS_NODE_BYTES;
aster_memcpy(&d, in + off, ASTERFS_NODE_BYTES);
if (off + ASTERFS_NODE_BYTES > sizeof(g_nodes_blob)) {
break;
}
aster_memcpy(&d, g_nodes_blob + off, ASTERFS_NODE_BYTES);
aster_memset(nodes[i].name, 0, ASTERFS_NAME_LEN);
aster_memcpy(nodes[i].name, d.name, ASTERFS_NAME_LEN);
@@ -287,7 +298,7 @@ static int fs_flush_disk(void) {
return -1;
}
fs_encode_nodes(g_nodes_blob);
fs_encode_nodes();
for (sector = 0; sector < ASTERFS_NODE_SECTORS; ++sector) {
usize off = (usize)sector * 512;
aster_memset(g_sector_buffer, 0, sizeof(g_sector_buffer));
@@ -337,7 +348,7 @@ static int fs_load_disk(void) {
}
}
fs_decode_nodes(g_nodes_blob);
fs_decode_nodes();
if (super.nodes_used > ASTERFS_MAX_FILES) {
nodes_used = ASTERFS_MAX_FILES;
} else {
@@ -519,7 +530,10 @@ int asterfs_create_file(const char *name) {
nodes[nodes_used].size = 0;
nodes[nodes_used].is_dir = 0;
++nodes_used;
(void)fs_flush_disk();
if (fs_flush_disk() != 0) {
--nodes_used;
return -1;
}
return 0;
}
@@ -548,7 +562,10 @@ int asterfs_create_dir(const char *name) {
nodes[nodes_used].size = 0;
nodes[nodes_used].is_dir = 1;
++nodes_used;
(void)fs_flush_disk();
if (fs_flush_disk() != 0) {
--nodes_used;
return -1;
}
return 0;
}
@@ -570,7 +587,9 @@ int asterfs_remove_file(const char *name) {
}
--nodes_used;
(void)fs_flush_disk();
if (fs_flush_disk() != 0) {
return -1;
}
return 0;
}
@@ -603,7 +622,9 @@ int asterfs_remove_dir(const char *name) {
}
--nodes_used;
(void)fs_flush_disk();
if (fs_flush_disk() != 0) {
return -1;
}
return 0;
}
@@ -630,13 +651,30 @@ int asterfs_write_file(const char *name, const u8 *data, u16 len) {
len = ASTERFS_DATA_LEN;
}
aster_memset(nodes[idx].data, 0, ASTERFS_DATA_LEN);
aster_memcpy(nodes[idx].data, data, len);
nodes[idx].size = len;
(void)fs_flush_disk();
{
u8 old_data[ASTERFS_DATA_LEN];
u16 old_size = nodes[idx].size;
aster_memcpy(old_data, nodes[idx].data, ASTERFS_DATA_LEN);
aster_memset(nodes[idx].data, 0, ASTERFS_DATA_LEN);
aster_memcpy(nodes[idx].data, data, len);
nodes[idx].size = len;
if (fs_flush_disk() != 0) {
aster_memcpy(nodes[idx].data, old_data, ASTERFS_DATA_LEN);
nodes[idx].size = old_size;
return -1;
}
}
return len;
}
int asterfs_sync(void) {
return fs_flush_disk();
}
int asterfs_read_file(const char *name, u8 *out, u16 max_len) {
int idx;
u16 len;
+20
View File
@@ -0,0 +1,20 @@
/*
* AsterOS Kernel
* Autor: Pavel Kalas
* Rok: 2026
*
*/
/*
* Header deklaruje jednoduche API pro jednotne stavove vypisy
* ve stylu [ STAV ] zprava, pouzivane hlavne pri boot/setup toku.
*/
#ifndef ASTER_BOOTLOG_H
#define ASTER_BOOTLOG_H
void bootlog_state(const char *state, unsigned char state_color, const char *msg);
void bootlog_ok(const char *msg);
void bootlog_error(const char *msg);
#endif
+1
View File
@@ -35,6 +35,7 @@ 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);
int asterfs_sync(void);
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));
+25
View File
@@ -0,0 +1,25 @@
/*
* AsterOS Kernel
* Autor: Pavel Kalas
* Rok: 2026
*
*/
/*
* Runtime registr pro sysapps: kazda app je mapovana na prikaz podle
* nazvu souboru a spousti se pres init(void).
*/
#ifndef ASTER_SYSAPPS_RUNTIME_H
#define ASTER_SYSAPPS_RUNTIME_H
typedef void (*sysapp_init_fn_t)(void);
typedef struct {
const char *name;
sysapp_init_fn_t entry;
} sysapp_entry_t;
extern const sysapp_entry_t g_sysapps[];
#endif
+35
View File
@@ -0,0 +1,35 @@
/*
* AsterOS Kernel
* Autor: Pavel Kalas
* Rok: 2026
*
*/
/*
* Tento modul sjednocuje stavove vypisy jadra ve formatu [ STAV ] zprava.
* Poskytuje jednoduche helpery pro bezne uspesne a chybove hlaseni,
* aby byly boot/setup logy konzistentni na jednom miste.
*/
#include "bootlog.h"
#include "display.h"
#include "printk.h"
void bootlog_state(const char *state, unsigned char state_color, const char *msg) {
display_set_color(0x0F, 0x00);
aster_print("[ ");
display_set_color(state_color, 0x00);
aster_print(state ? state : "NEZNAMY");
display_set_color(0x0F, 0x00);
aster_print(" ] ");
printk("%s\n", msg ? msg : "");
}
void bootlog_ok(const char *msg) {
bootlog_state("HOTOVO", 0x0A, msg);
}
void bootlog_error(const char *msg) {
bootlog_state("CHYBA", 0x0C, msg);
}
+139 -18
View File
@@ -12,6 +12,7 @@
*/
#include "cpu.h"
#include "bootlog.h"
#include "display.h"
#include "drivers.h"
#include "memory.h"
@@ -20,10 +21,12 @@
#include "scheduler.h"
#include "storage.h"
#include "string.h"
#include "sysapps_runtime.h"
#include "syscall.h"
#include "timer.h"
void app_tetris_main(void);
extern const sysapp_entry_t g_sysapps[];
static char g_cwd[ASTERFS_NAME_LEN] = "/";
static unsigned long g_timer_hz = 100UL;
@@ -63,6 +66,9 @@ static void auth_readline_plain(char *out, int max_len);
static void auth_readline_secret(char *out, int max_len);
static void auth_clear_users(void);
static int auth_add_user(const char *name, const char *pass);
static void cmd_reboot(void);
static int installer_detach_medium(void);
static int run_sysapp_by_name(const char *name);
static char g_fm_names[FM_MAX_ENTRIES][ASTERFS_NAME_LEN];
static u8 g_fm_types[FM_MAX_ENTRIES];
static u16 g_fm_sizes[FM_MAX_ENTRIES];
@@ -464,7 +470,7 @@ static void boot_step_finish(const char *label, const char *state, u8 state_colo
}
static void boot_step_ok(const char *label) {
boot_step_finish(label, "OK", 0x0A);
boot_step_finish(label, "Uspesne", 0x0A);
}
static void boot_step_skip(const char *label) {
@@ -614,6 +620,33 @@ static int system_is_installed(void) {
return asterfs_get_type(INSTALL_FLAG_FILE) == 0;
}
static int run_sysapp_by_name(const char *name) {
usize i;
if (!name || name[0] == '\0') {
return -1;
}
for (i = 0; g_sysapps[i].name; ++i) {
if (aster_strcmp(g_sysapps[i].name, name) == 0) {
g_sysapps[i].entry();
render_shell_statusbar();
return 0;
}
}
return -1;
}
static int installer_detach_medium(void) {
if (asterfs_sync() != 0) {
return -1;
}
/* Removable install medium is not controllable in current runtime. */
return -1;
}
static void cmd_setup_install(void) {
static const char readme[] =
"AsterOS base install\n"
@@ -631,6 +664,7 @@ static void cmd_setup_install(void) {
char setup_user[AUTH_NAME_LEN];
char setup_pass[AUTH_PASS_LEN];
char user_home[ASTERFS_NAME_LEN];
int k;
usize p = 0;
aster_print("Setup: instalace systemu na AsterFS disk...\n");
@@ -648,19 +682,6 @@ static void cmd_setup_install(void) {
aster_print("Setup heslo (prazdne = auto-login): ");
auth_readline_secret(setup_pass, sizeof(setup_pass));
auth_clear_users();
if (auth_add_user(setup_user, setup_pass) != 0 || auth_save_users() != 0) {
print_error("Setup error: nelze ulozit uzivatele");
return;
}
aster_memset(g_current_user, 0, sizeof(g_current_user));
p = aster_strlen(setup_user);
if (p >= sizeof(g_current_user)) {
p = sizeof(g_current_user) - 1;
}
aster_memcpy(g_current_user, setup_user, p);
if (fs_ensure_dir("/etc") != 0) {
print_error("Setup error: nelze pripravit slozku /etc");
return;
@@ -714,9 +735,43 @@ static void cmd_setup_install(void) {
return;
}
auth_clear_users();
if (auth_add_user(setup_user, setup_pass) != 0 || auth_save_users() != 0) {
print_error("Setup error: nelze ulozit uzivatele");
return;
}
aster_memset(g_current_user, 0, sizeof(g_current_user));
p = aster_strlen(setup_user);
if (p >= sizeof(g_current_user)) {
p = sizeof(g_current_user) - 1;
}
aster_memcpy(g_current_user, setup_user, p);
ensure_aliases_file();
aster_print("Setup complete: system nainstalovan na disk\n");
aster_print("Restartovat system nyni? [y/N] ");
k = keyboard_read_key();
if (k != '\n') {
display_putc((char)k);
}
display_putc('\n');
if (k == 'y' || k == 'Y') {
if (installer_detach_medium() != 0) {
bootlog_error("Nelze odpojit instalacni medium, stiskni ENTER pro pokracovani");
for (;;) {
int kk = keyboard_read_key();
if (kk == '\n') {
break;
}
}
}
timer_sleep_ms(1500);
cmd_reboot();
}
}
static void show_welcome_banner(void) {
@@ -804,6 +859,7 @@ static const char g_help_lines[][80] = {
"edit filename - editor (Ctrl+S, ESC)",
"calc A op B - vypocet (+ - * /)",
"tetris - testovaci hra nad app API",
"<sysapps nazvy> - appka ze slozky sysapps",
"echo text - vypis textu",
"ticks - pocet tiknuti casovace",
"alloc N - alokovat N bajtu",
@@ -1127,6 +1183,7 @@ static void auth_login_screen(void) {
auth_readline_plain(name, sizeof(name));
aster_print("Heslo: ");
auth_readline_secret(pass, sizeof(pass));
timer_sleep_ms(1000);
{
int idx = auth_find_user(name);
@@ -1137,8 +1194,8 @@ static void auth_login_screen(void) {
}
}
print_error("Spatny login nebo heslo");
timer_sleep_ms(1000);
print_error("Spatny login nebo heslo, zkus to znovu...");
timer_sleep_ms(4000);
}
}
@@ -2394,7 +2451,34 @@ static void show_calc_ui(long a, long b, char op, long r) {
}
static void cmd_reboot(void) {
aster_print("Reboot...\n");
display_clear();
display_set_color(0x0F, 0x00);
aster_print("System restart sequence\n\n");
boot_step_begin("Stopping user session");
aster_memset(g_current_user, 0, sizeof(g_current_user));
boot_step_ok("Stopping user session");
boot_step_begin("Unloading modules");
keyboard_set_refresh_callback(0, 0);
boot_step_ok("Unloading modules");
boot_step_begin("Freeing memory");
g_status_marquee_only = 0;
status_clear_marquee();
status_clear_left_hint();
boot_step_ok("Freeing memory");
boot_step_begin("Syncing filesystems");
if (asterfs_sync() == 0) {
boot_step_ok("Syncing filesystems");
} else {
boot_step_finish("Syncing filesystems", "CHYBA", 0x0C);
}
timer_sleep_ms(2000);
boot_step_begin("Issuing hardware reset");
__asm__ volatile ("cli");
if (kbc_wait_input_clear()) {
@@ -2864,6 +2948,8 @@ static void shell_loop(void) {
cmd_reboot();
} else if (aster_strcmp(exec_cmd, "shutdown") == 0) {
cmd_shutdown();
} else if (run_sysapp_by_name(exec_cmd) == 0) {
continue;
} else {
print_error("Neznamy prikaz. Zadej help.");
}
@@ -2873,21 +2959,56 @@ static void shell_loop(void) {
void kmain(void) {
display_init();
boot_step_begin("Serial ovladac");
serial_init();
if (serial_is_ready()) {
printk("[serial] COM1 initialized\n");
boot_step_ok("Serial ovladac");
} else {
boot_step_skip("Serial ovladac");
}
boot_step_begin("CPU jadro");
cpu_init();
boot_step_ok("CPU jadro");
boot_step_begin("Spravce pameti nacten");
memory_init();
boot_step_ok("Spravce pameti nacten");
boot_step_begin("Spravce procesu");
process_init();
boot_step_ok("Spravce procesu");
boot_step_begin("Planovac");
scheduler_init();
boot_step_ok("Planovac");
boot_step_begin("Vrstva syscalls");
syscall_init();
boot_step_ok("Vrstva syscalls");
boot_step_begin("Klavesnicovy ovladac");
keyboard_init();
boot_step_ok("Klavesnicovy ovladac");
boot_step_begin("Casovac");
timer_init((unsigned int)g_timer_hz);
boot_step_ok("Casovac");
boot_step_begin("Obnova shellu");
keyboard_set_refresh_callback(shell_status_refresh_callback, g_timer_hz ? g_timer_hz : 100UL);
boot_step_ok("Obnova shellu");
boot_step_begin("Diskovy ovladac");
storage_init();
boot_step_ok("Diskovy ovladac");
boot_step_begin("Preruseni");
interrupts_init();
boot_step_ok("Preruseni");
aster_print("\nBoot sekvence dokoncena\n");
timer_sleep_ms(1500);
for (;;) {
auth_login_screen();
+5
View File
@@ -0,0 +1,5 @@
#include "aster_api.h"
void init(void) {
aster_api_print("Hello, world!");
}