Commit Graph
1172 Commits
Author SHA1 Message Date
Bananymous 28bd9cf353 Kernel: Fix PS/2 scancode set detection logic
If we cannot determine current scancode set because either the keyboard
does not respond or responds with bogus value, assume scancode set 1 and
mark the scancode set as uncertain. If we receive the byte 0xF0 while
having the uncertain flag set, swap to scancode set 2. 0xF0 is unused in
scancode set 1 but indicates key release in scancode set 2, so it will
be sent after every key press.
2026-08-22 11:57:19 +03:00
Bananymous 2f25bfb2db Kernel: Use min heap for scheduler block list
This makes insertion to block list O(log n) instead of O(n) when
blocking with wake time. This is more heavy and currently slower than
the previous implementation, but that is just because we don't really
have too many threads running at any given time. This will be more
scalable in the future and even allows implementing priorities if I ever
wish so
2026-08-19 21:32:36 +03:00
Bananymous 1231b16cc3 Kernel: Add mixer support to IHDA
This has not been tested as I don't have any hardware with mixers on
output paths :P
2026-08-19 21:32:36 +03:00
Bananymous 4aead25970 Kernel: Cleanup IHDA volume control and report the actual volume 2026-08-19 21:32:36 +03:00
Bananymous 36b34b0df0 Kernel: Don't store copy of palette in virtual TTY
It can be just queried from the terminal driver
2026-08-19 21:32:36 +03:00
Bananymous bf0bd19289 Kernel: Refactor includes to reduce include dependencies
Now modifying Scheduler.h or Thread.h doesnt trigger practically a full
kernel rebuild. This required moving Mutex and RWLock of of line but
that should be fine :^)
2026-08-19 21:32:36 +03:00
Bananymous 8cd9e6dfa8 Kernel: Keep track of thread user and system time separately 2026-08-19 21:32:36 +03:00
Bananymous f0a114f4e5 Kernel: Fix shm object freeing and track lpid
I was deleting based on the key instead of the id which of course does
not work :D
2026-08-19 21:32:36 +03:00
Bananymous fc40820150 Kernel/Userspace: Replace my custom SHM system with SysV shm
This allows xbanan to use shm!
2026-08-08 01:52:12 +03:00
Bananymous 2c4fee4a82 Kernel: Expose Inode::can_access as static member 2026-08-08 01:41:48 +03:00
Bananymous 0d390e2246 Kernel: Send EOI after handling the interrupt
There is no need to send it prior to handling. This required us to not
yield from HPET/PIT irq so that the EOI actually gets sent
2026-07-20 10:43:50 +03:00
Bananymous a3b7a758eb Kernel: Allow allocating shared interrupts and setting trigger mode 2026-07-20 10:28:18 +03:00
Bananymous d46d7a5123 Kernel: Cleanup entering acpi mode
There is no need to pass the current mode as an argument as ACPI has
access to that info either way.

Only route INTx objects when using ACPI, they won't be used otherwise
2026-07-20 09:02:18 +03:00
Bananymous 6ebd3a8aca Kernel: Rewrite the AHCI driver
There was a lot of stuff wrong with this driver and it was only getting
speeds of ~2.5 MB/s. Now 4K blocks get ~17 MB/s which is not good but
definitely better. I'm pretty sure the issue is qemu's emulation as 85%
of time is spent between sending the command and it to complete.
Large blocks are now supported too, qemu with block size 1M gets around
600 MB/s read speeds.
2026-07-20 06:58:30 +03:00
Bananymous 20e36125c8 Kernel: Cleanup very old AHCI code 2026-07-20 04:07:23 +03:00
Bananymous 19c228362b Kernel: Make ext2 block buffers page aligned 2026-07-20 04:07:23 +03:00
Bananymous 5329ec5912 Kernel: Rework spinlock usage when blocking the current thread
The old SpinLockAsMutex was pretty confusing first of all. It also was
causing the issue thats been around for maybe a year now which is the
only consistently happening kernel panic. I've been pretty confused
about this and finally figured out what was causing this.

The main issue was that we were accidentally enabling interrupts when
blocking a thread that passed SpinLockAsMutex from normally interrupt
enabled context. This led to receiving IPI for thread unblock while
we were actively blocking the thread. I'm very suprized this had't
caused any more serious issues than occasional kernel panics :^)
2026-07-20 04:07:23 +03:00
Bananymous edc95e1c09 Kernel: Disable SMP message handling while blocking a thread
There were some race conditions on a thread getting unblocked before
being moved to the block queue
2026-07-20 04:07:23 +03:00
Bananymous 51b9dcebbc Kernel: Support FIONBIO ioctl 2026-07-20 04:07:23 +03:00
Bananymous ecfd98fad0 bootloader: Don't use random packing in memory map 2026-07-08 21:48:14 +03:00
Bananymous 49662aa994 Kernel: Don't use peridic interrupts for scheduling
Scheduler will now set a timer interrupt deadline for when it should get
interrupted next. This fixes a big issue I've had for a long time where
sleeping on an idle core would have to wait for the next periodic
interrupt to wake up. This could cause 1 ms sleeps to be close to 10 ms.

This currently only supports lapic timers and will still fallback to
periodic interrupts when running with PIC. I should add deadline support
to PIT/HPET but why would you run with APIC disabled ;)
2026-07-07 04:53:41 +03:00
Bananymous eee0b7c3ff Kernel: Make ioctl take unsigned long instead of int
this is what linux does :D

also fix one or two `return ioctl` instead of `return ioctl_impl`
2026-07-07 03:12:39 +03:00
Bananymous 63b2284324 Kernel/LibC: support RDTSCP based clock_gettime
RDTSCP seems to be faster than LSL and it removes the need for getting
the current cpu twice to make sure TSC is read on the correct CPU
2026-07-03 06:32:04 +03:00
Bananymous 7219eac65f Kernel: Remove unnecessary page table validation
Processes always have a page table when they are initialized. This was
not true a long time ago when kernel threads could also be processes
2026-07-02 20:02:24 +03:00
Bananymous 0dc74beb0f Kernel/LibC: Allocate thread stacks in userspace
This adds support for pthread function for stack manipulation.

Also keep track of main threads stack in the uthread
2026-07-02 20:02:24 +03:00
Bananymous 6d1696b77e Kernel: Don't allocate userspace stacks in Thread
Thread only cares about stack's vaddr and size. Stacks are now allocated
before creating the threads.
2026-07-02 20:02:24 +03:00
Bananymous f449ca8161 Kenrel: Separate pthread API from kernel API
It didn't really make sense for the syscalls to be named as the pthread
equivalents. Now the kernel just uses thread ids
2026-07-02 20:02:24 +03:00
Bananymous 5540bc4147 Kernel: Fix USB SCSI device naming 2026-07-02 20:02:24 +03:00
Bananymous d8f136a76f Kernel: Remove the weird StorageController base class
This wasn't really used for anything and broke nvme controller as it was
now doubly ref counted :P
2026-07-02 20:02:24 +03:00
Bananymous d241975ce1 Kernel: Remove SYS_SLEEP and cleanup SYS_NANOSLEEP
`sleep` is now implemented in terms of `nanosleep`. `nanosleep` is now
more precise and handles overflow when calculating wakeup time. I don't
think anything was depending on this, but I could see a program sleeping
for max time to block until signal.
2026-07-02 15:22:52 +03:00
Bananymous 20663b533b Kernel: Rework sleeping API
instead of sleep_{ns,ms} we now have sleep_{for,until}_{ns,ms}. This
makes code cleaner that just wants to sleep until some timestamp
2026-07-02 15:22:52 +03:00
Bananymous ddb7641b05 Kernel: Support hardware checksum offload on E1000 receive 2026-06-30 20:14:38 +03:00
Bananymous a6ad9b9b2e Kernel: Add system for hardware checksum offload on received packets 2026-06-30 20:14:38 +03:00
Bananymous 8f4e15b78e Kernel: Use spinlocks and disable interrupts with loopback interface
This makes sure we don't get pre-empted after acquiring a descriptor but
before finishing marking it ready
2026-06-30 20:14:38 +03:00
Bananymous 17e6e53948 Kernel: Move Ethernet header prepending from NIC to helper 2026-06-30 20:14:38 +03:00
Bananymous aedd53b3e0 Kernel: Disable interrupts while appending packet in E1000
This avoids getting rescheduled and having other packets waiting to get
sent because of that
2026-06-30 20:14:37 +03:00
Bananymous 6339044e4c Kernel: Fix RTL8169 driver
This now works properly on real hardware. Main issue was a race
condition with now ISR was handled in the interrupt handler. We now loop
until we read back ISR as zero
2026-06-30 20:14:37 +03:00
Bananymous 9919cbf66e Kernel: Pass interpreter base address in auxiliary vector 2026-06-30 20:14:37 +03:00
Bananymous 579cd07109 Kernel: Expose process cpu time in proc filesystem 2026-06-27 03:24:15 +03:00
Bananymous 58aff97c28 Kernel: Implement getsockname for UNIX sockets 2026-06-27 03:24:15 +03:00
Bananymous 2bb9b9b4b3 Kernel: Don't read CR registers on every exception 2026-06-27 03:24:15 +03:00
Bananymous 59ec05c898 Kernel: Make TSC based timer monotonic
Prior to this I was just blindly rebasing the current TSC stats every
once in a while. Now I check for drift and scale the multiplier
accordingly to keep the timer from drifting
2026-06-27 03:24:15 +03:00
Bananymous ac0ef53e87 Kernel: Fix HPET interrupt routing
If the HPET did not support legacy routing we would still use IRQ0 which
lead to using PIT irq which fired ~18 times per second
2026-06-27 03:24:15 +03:00
Bananymous 92d10f612e Kernel: Make sure PCIeInfo is zero initialized 2026-06-25 01:42:02 +03:00
Bananymous d266d2ca88 Kernel: Allow network interface ioctls on interfaces
previously it was only on the sockets
2026-05-25 02:14:04 +03:00
Bananymous 8fccb74542 Kernel: Add indirect block cache to ext2 inode
This reduces indirect block lookup by a lot :)
2026-05-25 02:14:04 +03:00
Bananymous bc8ecbd6fa Kernel: Add directory entry cache for ext2 inodes 2026-05-25 02:14:04 +03:00
Bananymous 12158d9208 Kernel: Add OpenFileDescriptorSet::get_max_open_fd 2026-05-21 14:59:35 +03:00
Bananymous 5c94c30e1b Kernel: Use spinlocks instead of mutexes for RWLock
All the operations are super fast, just checking or changing few
integers, there is no need for a yielding mutex :^)
2026-05-21 02:17:34 +03:00
Bananymous 81d8ab3d79 Kernel: Remove completely unnecessary lock on file lookup
Mount point lookup already does locking internally, there is no need for
a lock for the whole duration of the lookup :D
2026-05-21 01:59:36 +03:00