Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
f85145e
[SERVICES] added services
Aug 2, 2026
3f345a5
Merge branch 'threading' into services
Aug 2, 2026
fd35887
Merge branch 'threading' into services
Aug 2, 2026
12be274
Merge branch 'threading' into services
Aug 3, 2026
ad3e6ba
Merge branch 'threading' into services
Aug 3, 2026
1947884
Merge branch 'threading' into services
Aug 2, 2026
7195633
Merge branch 'threading' into services
Aug 3, 2026
bed3a6f
Merge branch 'threading' into services
Aug 3, 2026
607ae12
Merge branch 'threading' into services
Aug 3, 2026
707d927
[JOB] always interrupt kernel
Aug 2, 2026
bd268c2
[JOB] proper reuse of kstack
Aug 6, 2026
aa3e1ee
[PACKAGEMAN] tools dir
Aug 7, 2026
543dd0d
[FAT32] stat fix
Aug 8, 2026
605df03
[APP_BUNDLE] added package identifiers (not yet parsed)
Aug 8, 2026
3de0af4
[FS] added transform operations
Aug 8, 2026
8248550
[KBD] differentiate between key press and key continue
Aug 10, 2026
ed8ecdd
[SHARED] sign fix
Aug 10, 2026
9cb5b03
[JOB] replace the stack using virtual mapping
Aug 11, 2026
f7049b1
[MMU] restored flushes to header
Aug 12, 2026
de08b95
[F32] using new allocator
Aug 18, 2026
f0337d6
[JOB] fat32/stack fix
Aug 18, 2026
c09a186
[JOB, CORR] nvm
Aug 18, 2026
688eaad
[TERM] brought back c term
Aug 18, 2026
bfb4687
[JOB] per-page buffer copying on fulfill
Aug 18, 2026
4220fe4
[PROJ] moved shared back to main
Aug 18, 2026
dd82b73
[JOB] simplify stack creation and fix fat32 crash
Aug 18, 2026
ee3ed74
[SHARED] using diylib-compatible branch
Aug 18, 2026
0e12de3
[SHARED] compatibility with new rendering and draw lib refactoring
Aug 29, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ endif

.PHONY: all shared user kernel clean raspi virt run debug dump prepare-fs help install

all: kshared modules kernel shared user tools libs docs
all: kshared modules kernel shared user tools libs services docs
@echo "Build complete."
./createfs

Expand All @@ -33,6 +33,9 @@ kernel: kshared modules
tools: shared libs prepare-fs
$(MAKE) -C tools

services: shared libs prepare-fs
$(MAKE) -C services

libs: shared
$(MAKE) -C libs

Expand All @@ -50,6 +53,7 @@ clean:
$(MAKE) -C tools $@
$(MAKE) -C modules $@
$(MAKE) -C libs $@
$(MAKE) -C services $@
@echo "removing images"
$(RM) kernel.img kernel.elf dump

Expand All @@ -72,6 +76,7 @@ dump:
$(ARCH)objdump -S -D kernel.elf > dump
$(MAKE) -C user $@
$(MAKE) -C tools $@
$(MAKE) -C services $@

install:
$(MAKE) clean
Expand Down
70 changes: 38 additions & 32 deletions kernel/filesystem/fat32.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#include "fat32.hpp"
#include "alloc/mem_types.h"
#include "disk.h"
#include "memory/page_allocator.h"
#include "files/system_module.h"
#include "console/kio.h"
#include "std/memory_access.h"
#include "std/string.h"
#include "std/memory.h"
#include "memory/memory.h"
#include "memory/memory_access.h"
#include "math/math.h"
#include "syscalls/syscalls.h"
#include "exceptions/irq.h"
#include "files/dir_list.h"
#include "filesystem/modules/module_loader.h"
#include "alloc/allocate.h"

#define kprintfv(fmt, ...) \
({ \
Expand All @@ -18,10 +19,14 @@
}\
})

void* f32palloc(size_t size){
return palloc(size, MEM_PRIV_KERNEL, MEM_DEV | MEM_RW, true);
}

bool FAT32FS::init(uint32_t partition_sector){
fs_page = palloc(0x1000, MEM_PRIV_KERNEL, MEM_DEV | MEM_RW, false);
fs_page = f32palloc(PAGE_SIZE);

mbs = (fat32_mbs*)kalloc(fs_page, 512, ALIGN_64B, MEM_PRIV_KERNEL);
mbs = (fat32_mbs*)allocate(fs_page, 512, f32palloc);
if (!mbs) return false;

partition_first_sector = partition_sector;
Expand Down Expand Up @@ -65,7 +70,7 @@ sizedptr FAT32FS::read_cluster(uint32_t cluster_start, uint32_t cluster_size, ui
if (root_index < 2 || root_index >= total_fat_entries) return (sizedptr){ 0, 0};

size_t size = cluster_count * cluster_size * 512;
void* buffer = kalloc(fs_page, size, ALIGN_64B, MEM_PRIV_KERNEL);
void *buffer = allocate(fs_page, size, f32palloc);
if (!buffer) return (sizedptr){0, 0};

uint32_t next_index = root_index;
Expand Down Expand Up @@ -114,7 +119,7 @@ bool FAT32FS::write_section_to_cluster(u32 cluster, u32 offset, void *buf, size_

u32 sector_count = ceil(((float)offset + size)/512);

void *initial = kalloc(fs_page, 512 * sector_count, ALIGN_64B, MEM_PRIV_KERNEL);
void *initial = allocate(fs_page, 512 * sector_count, f32palloc);

disk_read(initial, sector, sector_count);

Expand Down Expand Up @@ -175,23 +180,23 @@ f32_walk_result FAT32FS::walk_directory(uint32_t cluster_count, uint32_t root_in
u32 cluster_byte_size = cluster_size * 512;
for (uint64_t i = 0; i + sizeof(f32file_entry) <= buf_ptr.size;) {
if (buffer[i] == 0) {
kfree(buffer, buf_ptr.size);
release(buffer);
return {};
}
if (buffer[i] == 0xE5){
i += sizeof(f32file_entry);
continue;
}
bool long_name = buffer[i + 0xB] == 0xF;
char filename[256] = {0};
char filename[256] = {};
if (long_name){
f32longname *first_longname = (f32longname*)&buffer[i];
uint16_t count = 0;
do {
i += sizeof(f32longname);
count++;
if (i + sizeof(f32file_entry) > buf_ptr.size) {
kfree(buffer, buf_ptr.size);
release(buffer);
return {};
}
} while (buffer[i + 0xB] == 0xF);
Expand All @@ -215,16 +220,16 @@ f32_walk_result FAT32FS::walk_directory(uint32_t cluster_count, uint32_t root_in
.offset = offset,
.found = true,
};
kfree(buffer, buf_ptr.size);
release(buffer);
return result;
}
kfree(buffer, buf_ptr.size);
release(buffer);
return found_entry;
}
i += sizeof(f32file_entry);
}

kfree(buffer, buf_ptr.size);
release(buffer);
return {};
}

Expand All @@ -236,9 +241,9 @@ sizedptr FAT32FS::list_directory(uint32_t cluster_count, uint32_t root_index) {
f32file_entry *entry = 0;
if (!buffer || !buf_ptr.size) return { 0, 0};
size_t full_size = buf_ptr.size + 4;
void *list_buffer = kalloc(fs_page, full_size, ALIGN_64B, MEM_PRIV_KERNEL);
void *list_buffer = allocate(fs_page, full_size, f32palloc);
if (!list_buffer) {
kfree(buffer, buf_ptr.size);
release(buffer);
return { 0, 0};
}

Expand All @@ -261,8 +266,8 @@ sizedptr FAT32FS::list_directory(uint32_t cluster_count, uint32_t root_index) {
i += sizeof(f32longname);
long_count++;
if (i + sizeof(f32file_entry) > buf_ptr.size) {
kfree(buffer, buf_ptr.size);
kfree(list_buffer, full_size);
release(buffer);
release(list_buffer);
return { 0, 0 };
}
} while (buffer[i + 0xB] == 0xF);
Expand All @@ -286,7 +291,7 @@ sizedptr FAT32FS::list_directory(uint32_t cluster_count, uint32_t root_index) {
}

*(uint32_t*)list_buffer = count;
kfree(buffer, buf_ptr.size);
release(buffer);

return (sizedptr){(uintptr_t)list_buffer, full_size};
}
Expand All @@ -299,22 +304,22 @@ sizedptr FAT32FS::read_full_file(uint32_t cluster_start, uint32_t cluster_size,
char *buffer = (char*)buf_ptr.ptr;
if (!buffer || !buf_ptr.size) return {0, 0};

if (!file_page) file_page = page_alloc(PAGE_SIZE);
if (!file_page) file_page = f32palloc(PAGE_SIZE);

void *file = allocate(file_page, file_size ? file_size : 1, page_alloc);
void *file = allocate(file_page, file_size ? file_size : 1, f32palloc);
if (!file) {
kfree(buffer, buf_ptr.size);
release(buffer);
return {0, 0};
}

if (file_size) memcpy(file, (void*)buffer, file_size);
kfree(buffer, buf_ptr.size);
release(buffer);

return (sizedptr){(uintptr_t)file,file_size};
}

void FAT32FS::read_FAT(uint32_t location, uint32_t size, uint8_t count){
fat = (uint32_t*)kalloc(fs_page, size * 512, ALIGN_64B, MEM_PRIV_KERNEL);
fat = (uint32_t*)allocate(fs_page, size*512, f32palloc);
if (!fat) {
total_fat_entries = 0;
return;
Expand Down Expand Up @@ -402,7 +407,7 @@ u32 FAT32FS::alloc_fat(){

f32_walk_result FAT32FS::read_entry_handler(FAT32FS *instance, f32file_entry *entry, char *filename, const char *seek) {
if (entry->flags.volume_id) return {};

size_t name_len = strlen_max(filename, 0);
int matched = strstart_case(seek, filename, true);
if (matched != (int)name_len) return {};
Expand All @@ -417,7 +422,7 @@ f32_walk_result FAT32FS::read_entry_handler(FAT32FS *instance, f32file_entry *en
uint32_t bpc = bps * spc;
uint32_t count = entry->filesize > 0 ? ((entry->filesize + bpc - 1) / bpc) : instance->count_FAT(filecluster);

if (entry->flags.directory) return instance->walk_directory(count, filecluster, next, read_entry_handler);
if (entry->flags.directory && *next) return instance->walk_directory(count, filecluster, next, read_entry_handler);
if (*next != '\0') return {};
return {.entry = *entry, .cluster = 0, .offset = 0, .found = true};
}
Expand Down Expand Up @@ -448,9 +453,9 @@ FS_RESULT FAT32FS::open_file(const char* path, file* descriptor){
if (!buf || !buf_ptr.size) return FS_RESULT_NOTFOUND;
descriptor->id = fid;
descriptor->size = buf_ptr.size;
mfile = (module_file*)kalloc(fs_page, sizeof(module_file), ALIGN_64B, MEM_PRIV_KERNEL);
mfile = (module_file*)allocate(fs_page, sizeof(module_file), f32palloc);
if (!mfile) {
kfree(buf, buf_ptr.size ? buf_ptr.size : 1);
release(buf);
return FS_RESULT_DRIVER_ERROR;
}
memset(mfile, 0, sizeof(module_file));
Expand All @@ -472,8 +477,8 @@ FS_RESULT FAT32FS::open_file(const char* path, file* descriptor){
int ok = hash_map_put(open_files, &fid, sizeof(uint64_t), mfile);
irq_restore(irq);
if (ok < 0) {
kfree(mfile->file_buffer.buffer, mfile->file_size ? mfile->file_size : 1);
kfree(mfile, sizeof(module_file));
release(mfile->file_buffer.buffer);
release(mfile);
return FS_RESULT_DRIVER_ERROR;
}
return FS_RESULT_SUCCESS;
Expand Down Expand Up @@ -524,7 +529,7 @@ void FAT32FS::close_file(file* descriptor){
hash_map_remove(open_files, &descriptor->id, sizeof(uint64_t), 0);
irq_restore(irq);
buffer_destroy(&mfile->file_buffer);
kfree(mfile, sizeof(module_file));
release(mfile);
return;
}
irq_restore(irq);
Expand Down Expand Up @@ -605,7 +610,7 @@ size_t FAT32FS::list_contents(const char *path, void* buf, size_t size, uint64_t
}

*(uint32_t*)buf = count;
kfree((void*)ptr.ptr, ptr.size);
release((void*)ptr.ptr);

return (uintptr_t)write_ptr-(uintptr_t)buf;
}
Expand Down Expand Up @@ -703,6 +708,7 @@ system_module boot_fs_module = (system_module){
.truncate = boot_truncate,
.getstat = boot_stat,
.readdir = boot_partition_readdir,
.transform = 0,
.alias_info = {}
};

Expand Down
24 changes: 24 additions & 0 deletions kernel/filesystem/filesystem.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,11 @@ FS_RESULT open_file_global(module_root *root, const char* path, file* descriptor
FS_RESULT result = FS_RESULT_DRIVER_ERROR;
if (mod->owner != get_kernel_proc()->id){
job_make(job_open, mod, {
//TODO: here, out_mod is in the stack, and we're referencing it through a pointer, which we of course lose as we move the stack the first time.
job_serialize_str(&app, 0, search_path);
job_serialize_fd(&app, 1, descriptor, copy_on_end);
});
*out_mod = mod;
return j_ret;
} else {
result = mod->open(search_path, descriptor);
Expand Down Expand Up @@ -141,6 +143,28 @@ size_t read_file(file *descriptor, char* buf, size_t size){
return amount_read;
}

size_t transform_file(module_root *root, const char* path, void* buf, size_t size){
const char *search_path = path;
if (*search_path == '/') search_path++;
if (!*search_path) return FS_RESULT_NOTFOUND;
system_module *mod = get_module_from(root, &search_path);
if (!mod) return FS_RESULT_NOTFOUND;
if (!mod->transform) return FS_RESULT_NOTFOUND;
FS_RESULT result = FS_RESULT_DRIVER_ERROR;
if (mod->owner != get_kernel_proc()->id){
job_make(job_transform, mod, {
job_serialize_str(&app, 0, search_path);
job_serialize_buf(&app, 1, true, (void*)buf, size, copy_on_start | copy_on_end);
});
return j_ret;
} else {
result = mod->transform(search_path, buf, size);
}
if (result != FS_RESULT_SUCCESS) return result;
if (!open_files) return FS_RESULT_DRIVER_ERROR;
return FS_RESULT_SUCCESS;
}

void close_file(file *descriptor){
if (!open_files || !descriptor) return;
open_file_descriptors *ofile = 0;
Expand Down
1 change: 1 addition & 0 deletions kernel/filesystem/filesystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ FS_RESULT open_file_global(module_root *root, const char* path, file* descriptor
FS_RESULT open_file(module_root *root, const char* path, file* descriptor);
FS_RESULT instance_local_fd(system_module *mod, file *descriptor);
size_t read_file(file *descriptor, char* buf, size_t size);
size_t transform_file(module_root *root, const char* path, void* buf, size_t size);
size_t write_file(file *descriptor, const char* buf, size_t size);
void close_file_global(file *descriptor, system_module *mod);
void close_file(file *descriptor);
Expand Down
1 change: 1 addition & 0 deletions kernel/filesystem/virtio_9p_pci.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,7 @@ system_module p9_fs_module = (system_module){
.truncate = shared_truncate,
.getstat = shared_stat,
.readdir = shared_readdir,
.transform = 0,
.alias_info = {}
};

Expand Down
2 changes: 1 addition & 1 deletion kernel/graph/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ extern "C" {
#include "types.h"
#include "graphic_types.h"
#include "std/string.h"
#include "ui/draw/draw.h"
#include "draw/draw.h"
#include "files/system_module.h"

bool gpu_ready();
Expand Down
2 changes: 1 addition & 1 deletion kernel/graph/tres.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include "types.h"
#include "ui/draw/draw.h"
#include "draw/draw.h"
#include "data/struct/linked_list.h"
#include "process/process.h"

Expand Down
23 changes: 19 additions & 4 deletions kernel/kernel_processes/boot/bootprocess.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@
#include "input/input_dispatch.h"
#include "usb/usb.h"
#include "graph/graphics.h"
#include "exceptions/exception_handler.h"
#include "kernel_processes/boot/screensaver.h"
#include "kernel_processes/boot/login_screen.h"
#include "kernel_processes/windows/dos.h"
#include "tools/tools.h"
#include "files/helpers.h"

enum {
bsm_none,
bsm_screensaver,
bsm_login,
bsm_services,
bsm_userland
} boot_state;

Expand All @@ -27,12 +28,25 @@ void visual_init(){
mouse_config((gpu_point){(i32)screen_size.width/2,(i32)screen_size.height/2}, screen_size);
}

void load_service(const char *directory, const char *service){
if (strlen(service) && *service == '.') return;
string full_name = string_format("%s/%s",directory,service);
process_t *proc = execute(full_name.data, 0, 0, EXEC_MODE_KEEP_FOCUS);
string_free(full_name);
if (!proc) print("[BOOT error] failed to load service %s",service);
}

void bootsm_transition(int new_state){
boot_state = new_state;
switch (boot_state) {
case bsm_none: break;
case bsm_screensaver: current_proc = start_screensaver(); break;
case bsm_login: current_proc = present_login(); break;
case bsm_services: {
traverse_directory("/boot/redos/services", false, load_service);
current_proc = 0;
break;
}
case bsm_userland: {
if (system_config.headless || !system_config.use_windows){
const char *argv = system_config.headless ? "headless" : "";
Expand All @@ -55,9 +69,10 @@ void bootsm_advance(){
bootsm_transition(bsm_screensaver);
break;
}
bootsm_transition(bsm_userland); break;
case bsm_screensaver: bootsm_transition(bsm_userland); break;
case bsm_login: bootsm_transition(system_config.headless ? bsm_userland : bsm_screensaver); break;
bootsm_transition(bsm_services); break;
case bsm_screensaver: bootsm_transition(bsm_services); break;
case bsm_login: bootsm_transition(system_config.headless ? bsm_services : bsm_screensaver); break;
case bsm_services: bootsm_transition(bsm_userland); break;
case bsm_userland: bootsm_transition(bsm_none); break;
}
}
Expand Down
Loading
Loading