Commit Graph

1118 Commits

Author SHA1 Message Date
f1a72cc9da Kernel: Implemented banos - a WIP C driver API
Banos is a stable WIP C driver API that is supposed to provide a simple
interface to interact with the kernel and load the modules dynamically.
It is WIP and atm this just implements module loading with a custom
banos_install syscall. Banos will not try to substitute parts of the
kernel instead it will just expose kernel functionality via a stable
BINARY API. Meaning binaries (should) remain forward and backward
compatible on a binary level.

Banos modules work similarly to those in linux, you expose symbols via
BANOS_EXPORT which allows you to export a name + addr paired symbol.
It puts it in the .banos-export section. Drivers provide metadata about
themselves in the REQUIRED .banos-driver section. Symbols are resolved
at runtime. The kernel exposes the driver functionality via the same
.banos-export export mechanism.

Banos modules are elf RELOCATABLE files (object files) which have
partial linking (only banos symbols should remain). Modules will
eventually define dependencies, will export symbols and will allow you
to build a complex object hierarchy.

This patch adds the banos_install syscall which takes in the driver
image to install and may only be executed by super users. The API
doesn't validate already loaded modules, as thats something the
userspace MAY choose to keep track of. Multi-instance functionality
shall be implemented via driver specific behaviuor (exposed in the dev
filesystem or some other means).

Modules are supposed to allow you to alter kernel behavior and extend
it, allowing you to create filesystems, drivers, networking
modifications, schedulers, probers, and more (hopefully) whilst
remaining binary compatible with any version of the kernel (again,
hopefully).
2026-05-20 17:52:19 +03:00
718379ce3b Kernel: moved read/write_from_user out of Process 2026-05-20 17:52:19 +03:00
14aa28b043 Kernel: Handle TTY ioctls on all inodes not implementing it
This reduces debug spam while compiling software
2026-05-20 16:57:24 +03:00
a19e6938eb Kernel: Remove TTY keyboard thread
This was really hacky as it had no idea when the keyboard had events
and the blocking was just one millisecond sleeps :D

Now keyboard device checks if current tty is receiving input and if so
it forwards the events to the TTY.
2026-05-20 04:17:03 +03:00
94f92d982c Kernel: Optimize PageTable address space reservation
I only did this for the 64 bit target.
2026-05-20 02:01:16 +03:00
4f5f84bb5b Kernel: Speed up mmap address space reservation by a lot
Instead of scanning the page table for free range, we not use the
process's mapped regions to find a slot. This speeds up mmap by a lot!
2026-05-20 01:08:08 +03:00
7704e3c5c0 Kernel: Implement per cpu fast pages
Basically every fast page usage should be converted into this but I'll
do them one by one when they show up in profiles
2026-05-20 00:16:56 +03:00
376e4b4c45 Kernel: Reduce the number of sent IPIs
Only send an IPI when the target processors don't have pending messages.
This basically gets rid of TLB shootdowns from showing up in profiles.
Before they were taking maybe >10% kernel time :^D
2026-05-19 23:52:38 +03:00
24c37e7381 Kernel: Move TLB invalidation out of standard SMPMessages
This makes accessing TLB messages much faster as TLB flushes are very
frequent in comparison to other messages
2026-05-19 23:51:01 +03:00
fb9c67ab15 Kernel: Add PageTable API to invalidate full address space 2026-05-19 23:46:56 +03:00
1dc26d3c06 Kernel: Cleanup inode stat updating
Inode now handles stat upates itself and calls sync function to make
updates visible on the underlying filesystem
2026-05-19 13:00:05 +03:00
deb2f52a35 Kernel: Add support for named pipes
These only copy inodes stat when created, if you fchmod/fchown a named
pipe, the change will not be visible on the filesystem
2026-05-19 00:15:25 +03:00
8224659c48 Kernel: Allow creating FIFOs in tmpfs 2026-05-19 00:05:22 +03:00
1922d78661 Kernel: Add support for mkfifo{,at} mkdir at
Opening FIFOs still dont work as expected but at least you can create
them now :D
2026-05-18 23:53:09 +03:00
6d1ecc2388 Kernel: Clean up file creation 2026-05-18 15:26:59 +03:00
ef2738bfb7 Kernel: Disable devfs device add/remove logging 2026-05-17 03:38:18 +03:00
d7865b2929 Kernel: Don't msync file backed pages that were never mapped writable 2026-05-17 03:21:08 +03:00
9c79971bdc LibC/Kernel: Add support for detached pthreads 2026-05-17 00:40:56 +03:00
6e95519acc Kernel: Make TTY write lock a mutex instead of a spinlock
The mutex could not be locked while processing ANSI DGR in VTTY
2026-05-17 00:29:20 +03:00
d081655913 Kernel: Add API for mutex to check if it is locked by current thread
Also add assertion that you have interrupts enabled :^)
2026-05-17 00:29:20 +03:00
1fcd72e578 Kernel: replaced is_partition/storage with kind 2026-05-15 21:37:18 +03:00
5e1b5c329b Kernel: Allow HDA stream reset to timeout
This was hanging on some version of qemu :^)
2026-05-15 21:30:41 +03:00
16967cd9c0 Kernel: Replace is_* with kind field
Replaced the is_* virtual functions with a kind field instead
2026-05-15 21:23:12 +03:00
647d6a273d Kernel: Changed stat values from func to be field
- Removed virtual functions for all of the stat stuff.
This did however introduce some issues, mainly with /proc
becoming out of sync if you changed your ID. I propose we
do the linux thing and just have a stat update function
which is optional, but allows dynamic updates of stat fields
for cases such as those in uid/gid in /proc.
- Simplified the API, although still kind of annoying
it is a bit simpler.
- Moved some of the FS structure from having the FS inode inside
the in memory inode to a Serialise <-> Deserialise model where
Inodes are deserialised from disk into in memory ones and then
back into on disk ones when it comes time for syncing.
This makes it semantically better in my opinion, as it explicitly
separates disk and non-disk functionality.
2026-05-15 20:49:04 +03:00
05c9f0640c Kernel/LibC: Replace terminal syscalls with ioctls
isatty, tc{get,set}attr, tc{get,set}pgrp are now implemented as ioctls
instead of separate syscalls
2026-05-15 17:03:33 +03:00
28b873b949 Kernel: Allow recursive rwlock write lock 2026-05-15 17:03:33 +03:00
c352fb600f Kernel: Reduce ext2 locking
Replace the mutex with a rwlock and lock when its not necessary
2026-05-14 17:23:06 +03:00
0bf7328e04 Kernel: Handle TIOC{G,S}WINSZ on pipes
GCC likes to do this a lot and debug logging is excessive
2026-05-09 23:28:00 +03:00
9f4271f6d8 Kernel: Remove the big inode lock
This moves locking to the inodes themselves which allows reducing lock
times significantly. Main inodes (ext2 and tmpfs) still do contain a
single big mutex that gets locked during operations but now we have the
architecture to optimize these.
2026-05-09 23:28:00 +03:00
a7356716ff Kernel: Reduce locking FileBackedRegions 2026-05-09 15:08:26 +03:00
6966475dcf Kernel: Make E1000 sending lockless and mostly non-blocking
Now we only block if all 256 tx descriptors are waiting to be sent. This
removes TCP acks from taking 30% of profiles while DOWNLOADING files
2026-05-04 21:15:15 +03:00
93e1091252 Kernel: Rewrite kmalloc
Kmalloc is now a bitmap allocator with dynamic resizing and we dont need
to allocate 64 MiB static block of memory reserved for kmalloc :^)
2026-05-04 20:26:02 +03:00
f293377e31 Kernel: Dynamically allocate PCI devices
There was no need to prealloce almost a 5 MiB buffer for PCI all
possible pci devies :D
2026-05-04 20:26:02 +03:00
f4e2e62d04 Kernel: Remove kmalloc API for identity mapped results
This is no longer used. This finally allows me to rewrite kmalloc :^)
2026-05-04 20:26:02 +03:00
d42b363fb1 Kernel: Remove kmalloc identity map requirement from USB keyboard
This is the last place requiring kmalloc identity mapping
2026-05-04 20:26:02 +03:00
8091127150 Kernel: Add page table api to map multiple fast pages
This is not currently used, but can be handy in the future
2026-05-04 20:26:02 +03:00
b8dc199738 Kernel: Fix ByteRingBuffer->back() 2026-05-04 20:26:02 +03:00
74127c0f45 Kernel: Cleanup inline assembly accessing cpu specific data 2026-05-04 20:26:02 +03:00
fde085e04b Kernel: Pass current cpu index as a GDT limit
I had no idea LSL was an instruction. This cleans up code to get the
current cpu by a lot and does not require extra segment usage :D
2026-05-04 20:26:02 +03:00
f37d9dbdb1 Kernel: Remove kmalloc_vaddr_of
This is no longer needed. It was only used for x86_64 paging and AP
stack initialization
2026-05-04 20:26:01 +03:00
b7cedad891 Kernel: Wrap syscall macro value in paranthesis 2026-05-04 20:26:01 +03:00
03fccdffe1 Kernel: Rewrite paging and AP initialization
Initial step of paging now just prepares fast page for heap, actual page
table initialization happens after heap is initialized which allows
x86_64 to never depend on kmalloc for pages.

Processor's stacks are now also spawned with PMM/VMM allocated stacks
instead of kmalloc identity mapped.
2026-05-04 20:26:01 +03:00
ab8bcbec3e Kernel: Allow mapping dma regions as not uncached 2026-04-27 19:36:32 +03:00
cf2e8ffaff Kernel: Remove unnecessary custom RefPtr hashes
RefPtr now exposes its own default hash
2026-04-25 22:10:01 +03:00
b74812d669 Kernel: Remove unnused features from VirtualRange
On-demand paging has not been used ever since I made userspace stack be
a normal MemoryRegion.
2026-04-21 19:58:09 +03:00
a8e496310b Kernel: Use HashMap for fd->epoll_event mapping
I don't know why it was a static array :D
2026-04-21 00:14:24 +03:00
71649ffe09 Kernel Rework ThreadBlocker
I don't know why I though the block chain had to be stored fully in the
ThreadBlocker, that did not even fix the problem I was trying to fix
when I last rewrote it. Roll back to doubly linked list of block chain
and now just check that the node is contained within the ThreadBlocker
before removing and after acquiring the ThreadBlocker's lock. Also there
is no need to have a separate lock the node's blocker field. We can just
perform an atomic reads and writes to it. We can still get a blocker
that the node is no longer part of, but this can be resolved with a
simple check. This patch reduces ThreadBlocker's size from over 200
bytes to just 12 bytes +4 bytes padding
2026-04-20 12:50:09 +03:00
c849293f3d Kernel: Add support for loading gzip compressed initrd 2026-04-13 16:48:57 +03:00
42964ad0b4 Kernel: Remove concept of OpenFile
This was just RefPtr<OpenFileDescription> and descriptor flags.
Descriptor flags only define O_CLOEXEC, so we can just store fd's
cloexec status in a bitmap rather than separate fields. This cuts down
the size of OpenFileDescriptorSet to basically half!
2026-04-12 04:42:08 +03:00
ac6e6f3ec1 Kernel: Add ioctl to sync rectangular areas in framebuffer
msync is not really the best API for framebuffer synchronization
2026-04-11 08:29:10 +03:00