Skip to content

Conversation

@kryczkal
Copy link
Member

@kryczkal kryczkal commented Dec 9, 2025

2025-12-0923-31-11-ezgif com-video-to-gif-converter
2025-12-1216-44-45-ezgif com-video-to-gif-converter
ezgif-8b4029ce3741d09a

kryczkal and others added 7 commits December 5, 2025 22:49
Super small PR for making a generic SerialDriver.
This was created with the intention of integrating the IO Stream API /
MultiplexerWriter into the current Trace framework / print / etc. But I
decided what's already there, can just stay for now. I'm just going to
implement the new Console using this API.
This is the leftover from this idea, before I stopped myself. The lone
generic UART16550 driver (can be used to writing to QEMU)
## Problem
We want to have a graphic IO with the kernel.

## Solution
<img width="1188" height="734" alt="image"
src="https://github.com/user-attachments/assets/673284b0-f99a-4c25-8135-eb2380a505e9"
/>

- Implement a driver for Framebuffer.
- Enable framebuffer finding in boot modules.
- Init Framebuffer from KernelArgs
- Implement a Video module
- Create an abstract non-owning Surface type (for double/tripple
buffering)
- Create a painter class that knows how to paint a Surface.
- Implement Graphics related primitives
## Problem
There is no way to display text on the screen

## Solution
Implement font support in the kernel,
`Font` is a concept of an object that returns `Glyphs`
`Glyphs` are bitmaps of speciifc "characters". These are then handled by
`Painter` to draw them on a `Surfrace`.
- Added support for PSF2 type fonts, so they can be easily added to the
kernel.
 - Added drdos8x8 as a font

 No truetype font support. No fancy stuff. Just plain old bitmasks
 
 
<img width="1384" height="888" alt="image"
src="https://github.com/user-attachments/assets/d2031e9a-ebc4-4f63-9e37-1b782a7cd9a6"
/>
<img width="1290" height="914" alt="image"
src="https://github.com/user-attachments/assets/c3cef99b-65b0-4fef-a449-54671a4f2a57"
/>

## Note
This is not an implementation of a Console yet. A console would be a
`Writer` that you just put text into and don't care about where it's
gonna be on screen, at what position to display it etc.
This is just adding `DrawString` to `Painter` class.

Console is still on the way
![2025-12-0923-31-11-ezgif
com-video-to-gif-converter](https://github.com/user-attachments/assets/c74fddb2-e716-49f1-ada3-1715169bd0cd)

## Problem
There is no interface to communicate with the OS from a graphical
perspective

## Solution
Implemented a `graphics_console`
and a super basic shell that uses it.
Introduce several new data structures and allocator wrappers:
- CritBitTree: A binary crit-bit tree for NULL-terminated strings.
- LinkedList: Generic single and double linked lists with custom
allocators.
- LruCache: A fixed-capacity LRU cache.
- TaggedPointer: Stores type info in unused pointer bits.
- CustomAllocatorWrapper: Enables using custom allocators with
containers.
Introduces a comprehensive system for building root filesystems,
supporting both initial RAM disks (INITRD) and standalone disk images.

This includes:
- New `cmake/BashConfigHelpers.cmake` for managing bash configurations.
- `register_filesystem` CMake function in `RuntimeHelpers.cmake`.
- `rootfs` subdirectory with its own CMake configuration.
- `scripts/actions/make_rootfs.bash` and `scripts/rootfs/make_fat.bash`
  for orchestrating and creating FAT filesystems.
- A `ramdisk` feature flag to control INITRD vs. image generation.
- New bash helper functions for size conversions.
- Fixes a bug in test filtering logic.
Adds a foundational Virtual File System (VFS) module, providing a
unified interface for file and directory operations across different
filesystems.

Key changes include:
- Introduces the core `VfsModule` for managing filesystem mount points
and routing file operations to appropriate drivers.
- Implements a robust `Path` class for handling absolute and relative
path parsing, manipulation, and normalization.
- Adds comprehensive support for FAT12, FAT16, and FAT32 filesystems
through a generic FAT driver architecture, including file and directory
management.
- Integrates an `InMemory` I/O driver, suitable for boot-time filesystem
interaction and testing.
- Incorporates new utility functions and macros across the codebase,
such as `DivRoundUp` for ceiling division, `OPTIONAL_FIELD` for
conditional struct members, and advanced array template utilities.
- Initializes the VFS during kernel startup, making file operations
available early in the boot process.
- Includes extensive unit tests for the `Path` class, VFS module, and
FAT12 driver to ensure correctness and reliability.
Bootloader now locates and passes ramdisk information to the kernel.
The VFS module mounts the FAT12 ramdisk at the root filesystem.
Introduces 'cd', 'ls', 'cat', and 'pwd' commands to the kernel shell for
basic filesystem interaction.
## Problem
Bug in irq error wrapper callback, having offset to error struct wrong
by 8-bytes
also bug in timing module which doesnt initialize numerator and
denumerator

Also multiboot related code (`x86_64` specific) present in generic
kernel. Moved the related logic to bootloader

## Solution
Fixed those bugs and uncommented uacpi & timing related code
## Problem
Handling keyboard input was done solely through legacy QemuTerminal
functions with a blocking read.

## Solution
Implemented a driver for a ps2 keyboard and connected it to a interrupt
handler. Shell now reads from an abstract Keyboard IReader (a pipe to
which keyboard drivers write)
@kryczkal kryczkal marked this pull request as ready for review December 12, 2025 17:54
@kryczkal kryczkal requested review from F1r3d3v and Jlisowskyy and removed request for Jlisowskyy December 12, 2025 17:55
Jlisowskyy and others added 13 commits December 14, 2025 14:41
Things done in this PR:
- fixed minor issues
- Improved interrupts
- improved exceptions
Introduces a new `BitField` utility for defining and accessing bitfields
with named, type-safe fields.
Enhances `BitArray` with `GetRange` and `SetRange` methods to
efficiently manipulate bit ranges, including boundary-crossing
scenarios. These methods are fundamental for `BitField`'s internal
storage.
Adds `std::bit_cast` for safe reinterpretation of object
representations, enabling `BitField` to convert to/from raw integer
types.
Includes new internal macros to support the `CREATE_BITFIELD` macro.
Adds comprehensive tests for both `BitArray` range operations and the
new `BitField` utility.
- Made PageFaultHandler actually work for anonymous memory.
- Added tests for MMU abstraction
- Implemented kernel new/delete equivalents (KNew, KDelete)
- Enabled tests that should work now (time tests, and pagefaulthandler
test related to anonymous mem)

**Note**: Direct Memory mapping doesn't work and is still in progress
Things done in this PR:
- added GDT code in c++
- added TSS code in c++
- added gdt and TSS per core (stored in core local)
- initialized and flushed gdt for initial core
- cleaned up interrupt assembly
- started switch_task implementation
- added to_string for error enums
- added scheduling module
- added containers for threads and processes
- created thread and process structs
- created task_mgr class managing life time of threads and processes
- tested new containers and templates
- added `AtomicArrayStaticStack` structure
- added `PooledHashMap` structure
- added type `MinimalUnsignedStorage_t`
- added `ScopeGuard` and `BatchedScopeGuard` helpers
## Problem
Programs need to run in userspace in the future
Programs (elfs) need to be loaded from rootfs
in order to be in rootfs, they need to be compiled, and copied there

<img width="773" height="354" alt="image"
src="https://github.com/user-attachments/assets/ae53dfe3-92fb-431d-b8ae-cb5778438250"
/>


## Solution
This PR introduced:
- the `userspace` folder, that handles creating userspaces programs.
- elf loader that creates proper virtual memory regions (in kernel
address space) and jumps to the loaded program

## Bugfixes
Fixed a bug in VFS Path where non-owning view type (that viewed volatile
mem) objects were copied, without copying the underlying thing they
viewed at, causing errors.

## Note
**TDLR**: Hardcoded for x86_64 and only a single program can be executed
per run of alkos

**Long Version**: This this is severly limited, and more of a Proof of
Concept.
1. There is no cleanup that "unloads" a program (and most likely will
not be needed since each program is a process in its own address space,
so destroying an address space is the cleanup itself). This means a
program can only be run once, then its loaded into memory, and cant be
loaded again (since the vmem areas are already used).
3. Since there is no libc and syscalls yet, this PR added a workaround
where userspace programs are compiled in such a way that address of a
desired print function is passed into them.
This allowed of testing that indeed the elf loading functionality works
out, without waiting for syscalls and libc to be fully implemented. This
needs to be cleaned up later.
This is temporarily hardcoded for `x86_64`
## Problem
MMU was simplfied and there was no recursive unmapping of previous
pages.

## Solution
Implemented reference counting for all page directories in the page
metadata, that allowed to know when to cleanup an entry.
Implemneted cleaning up stale entries.
## Problem
Since leaving bootloader, there were still some issues and
inconsistencies with the state of AlkOS kernel.
Namely: 
- The first 10gb of mem were still identity mapped by the bootloader (a
legacy mapping)
- The kernel was mapped into the vmem, but the virtual memory manager
wasn't AWARE that the kernel itself is mapped.
- The hardware (page tables) and software (bookkeeping info) were
desynced

## Solution
This PR:
- Tears down all memory mappings below the higher half
- Implements bookkeeping that allows to effectively unmap pages
- Synchronizes hardware with the bookkeeping structures
- Fixes all legacy direct uses of physical ptrs

## Bugs
Tearing down the identity mapping exposed a BUG which behaved this way:
- The MSR GsBase register is set up to point to a valid address
- After flushing a new GDT, the MSR GsBase is set to 0x0 as a side
effect
- The GsBase is not adjusted, so it points to 0x0
- 0x0 is a valid address under the legacy mapping. Code reads garbage
- After tearing down the legacy mapping it stops working
- This means the trace framework itself is paralyzed and doesn't work
- Nothing is reported or logged. Just random crash SOMEWHERE.
This is fixed. :DD and it took me a long time.
## Problem:
Page flags need to enable writing during loading an elf, but need to be
set to
read only after it is loaded.

## Solution
Added mechanizm to update the flags of a vmemarea
Also fixed various bugs
most noticalbly - stack misalignment after return from error idt.
Things done in this PR:
- Finished switch task function for kernel threads
- introduced concept of kthreads
- added convertion function
- tested context switching
The past 3 mmu/vmm commits redone in a cleaner way.
kryczkal and others added 24 commits December 29, 2025 20:18
Things done in this PR:
- added support for context switching on interrupt return
- added support for gs fs saving
- added support for user space jump
## Problem
Userspace processes may need a stack. Currently there is no way to get
it

## Solution
Added functionality that finds gaps of desired size in a desired range
of the address space.
The gaps are then used to insert Anonymous Vmem Areas there (as stack,
or valloc, whatever you need)
Things done in this PR:
- added float state save/restore
- cleaned up scheduling code
Things done in this PR:
- cleaned up task_mgr functions
- added first working process - trace dumper
Adjust GDT selectors to correctly set RPL for user-mode segments.
Implement `ExecuteElf64` to load ELF binaries into a process's address
space and spawn an initial thread.
Enhance address space switching logic to use the VMM's `SwitchAddrSpace`
for better control during context switches and ELF loading.
Initialize VFS earlier to support ELF loading from the filesystem.
Launch a basic 'hello world' user program at boot to demonstrate
functionality.
Establish a complete file descriptor system (FdTable, FileTable,
OpenFileTable)
and overhaul the syscall handler to support std::expected returns,
std::span
arguments, and FAST_CALL. New syscalls for file operations (open, close,
read,
write, seek) are now available.

This commit also transitions core type definitions from types.hpp to
types.h for
C-compatibility, integrates RefCounted and RefPtr for robust resource
handling,
upgrades uACPI to 3.2.0, and enhances page fault diagnostics. The new
file I/O
syscalls are connected to libc and demonstrated in userspace programs.
Things done in PR:
- Added time accounting to scheduler 
- Fixed some minor bugs
- Improved core local data access
Refactors the file descriptor management system to use `RefPtr` for
resource tracking. Implements `sys_dup` and `sys_dup2` syscalls,
along with `crt0` startup code and a `stdio` library for userspace.
Also adds a `stdout-tracer` kernel worker to monitor process output.
Things done in this PR:
- added policies to scheduler
- added better statistics collection during scheduling
- added thread states
- added instrusive lists
- added bitmap priority queue
- Relocates shell from kernel to userspace.
- Adds syscalls for directory listing, file info, and power management.
- Refactors graphics code into a standalone `libgraphics` library.
- Updates CRT0 and build system to support C++ global constructors.
- Fixes x86_64 syscall argument passing for SysV ABI compatibility.

---------

Co-authored-by: Łukasz Kryczka <lukasz.kryczka000@gmail.com>
Things done in this PR: 
- intrusive front list added
- simple random gen for tests added
- added intrusive rb tree
- added sleep syscalls
- added sleep support to scheduler
- added better timing event to scheduler
Co-authored-by: F1r3d3v <ogieniewski.dev@gmail.com>
Things done in this  PR:
- added syscall exec
- finished exec cmd
- added recursive interrupt lock
@Jlisowskyy Jlisowskyy merged commit 2cbe7d9 into main Jan 7, 2026
3 of 4 checks passed
@Jlisowskyy Jlisowskyy deleted the dev branch January 7, 2026 20:17
@Jlisowskyy Jlisowskyy restored the dev branch January 7, 2026 20:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants