Commit Graph

8510 Commits

Author SHA1 Message Date
Idan Horowitz
e38ccebfc8 Kernel: Stop swallowing thread unblocks while process is stopped
This easily led to kernel deadlocks if the stopped thread held an
important global mutex (like the disk cache lock) while blocking.
Resolve this by ensuring stopped threads have a chance to return to the
userland boundary before actually stopping.
2024-02-10 08:42:53 +01:00
Idan Horowitz
458e990b7b Kernel: Stop locking the scheduler spinlock before the ptrace mutex
Locking a mutex while holding a spinlock is always wrong, but in the
case of the scheduler lock, it also causes an assertion failure. (Which
would be triggered by 2 separate threads trying to ptrace at the same
time).
2024-02-10 08:42:53 +01:00
Idan Horowitz
03cb3e5370 Kernel: Move NVMeQueue's m_cq_lock to NVMePollQueue
It's only used by that subclass, so there's no reason for it to be
defined as part of the parent class.
2024-02-10 08:42:53 +01:00
Idan Horowitz
45aee20ea9 Kernel: Switch to SpinlockProtected to protect NVMeQueue's requests map
This helps ensure no one accidentally accesses m_requests without first
locking it's spinlock. In fact this change fixed such a case, since
process_cq() implicitly assumed the caller locked the lock, which was
not the case for NVMePollQueue::submit_sqe().
2024-02-10 08:42:53 +01:00
Idan Horowitz
263127f21a Kernel: Actually report nvme request status
Due to an incorrect lambda scope capture declaration, we would copy the
result status at the start of the function, before it actually got
updated with the final status. Capture it by reference instead to
ensure we report the updated result.
2024-02-10 08:42:53 +01:00
Idan Horowitz
38dad2e27f Kernel: Replace bespoke & rickety NVMeIO synchronization mechanism
Instead of assuming data races won't occur and trying to somehow verify
it with manual un-atomic tracking, we can just use a recursive spinlock
instead of a normal one, to resolve the original deadlock.
2024-02-10 08:42:53 +01:00
Idan Horowitz
a957907f4b Kernel: Merge NVME Queue complete_current_request implementations
Most of the actual logic is identical, with the only real difference
being that one wraps it with an async work item.
Merge the implementations to reduce duplications (which will also
require the fixes in the next commits to only be done once).
2024-02-10 08:42:53 +01:00
Tim Ledbetter
a580118e53 Kernel/HID: Set Caps Lock state before doing code point remapping
This restores Caps Lock functionality, while still ensuring that
shortcut keys are remapped correctly.
2024-02-09 12:28:08 -07:00
Sönke Holz
d0e3065ced Kernel/riscv64: Don't touch reserved fields of the sstatus CSR in boot.S
Multiple fields in sstatus are defined as WPRI "Reserved Writes Preserve
Values, Reads Ignore Values", which means we have to preserve their
values when writing to other fields in the same CSR.

We don't really need to touch any fields except SIE.
Interrupts are probably already disabled, but just to be safe,
disable them explicitly.
2024-02-08 08:13:47 -07:00
John te Bokkel
d70424bb0f Kernel/HID: Move code_point assignment before its use key in assignment
We need to handle the character map to set the code point before we can
reassign the correct key to the queued_event.key. This fixes keyboard
shortcuts using the incorrect keys based on the keyboard layout.
2024-02-08 08:06:41 -07:00
Sönke Holz
c0d7749654 Kernel/riscv64: Add QEMU virt machine memory map
We can remove this temporary memory map once we support parsing the
device tree provided to us by the firmware.
2024-02-08 07:16:20 -07:00
Tom Finet
227aa8f2e4 Kernel/Net: E1000ENetworkAdapter detect EEPROM
The presence of EEPROM is detected by reading the
EE_PRES bit from the EECD register.
2024-02-08 07:05:46 -07:00
Ali Mohammad Pur
54ab6fe5b9 LibVT+Everywhere: Introduce 'automarks' and 'clear previous command'
Automarks are similar to bookmarks placed by the terminal, allowing the
user to selectively remove a single command and its output from the
terminal scrollback.
This commit implements a single way to add marks: automatically placing
them when the shell becomes interactive.

To make sure the shell behaves correctly after its expected prompt
position changes, the terminal layer forces a resize event to be passed
to the shell on such (possibly) partial clears; this also has the nice
side effect of fixing the disappearing prompt on the preexisting "clear
including history" action: Fixes #4192.
2024-02-07 00:43:11 +01:00
Sönke Holz
8878e0c815 Kernel/riscv64: Implement everything in PageDirectory.cpp
This code is heavily based on aarch64's PageDirectory.cpp.
2024-01-29 05:17:03 -07:00
Sönke Holz
0a4ef6f3b7 Kernel/riscv64: Stub out InterruptManagement::find_controllers
We don't support any IRQControllers for RISC-V (like the PLIC) yet,
so just do nothing here for now.
2024-01-23 13:13:18 -07:00
Sönke Holz
cec20908a5 Kernel/riscv64: Add assembly trap handler
This trap handler can't handle traps from userspace yet.
2024-01-23 13:13:18 -07:00
Sönke Holz
df21d435eb Kernel/riscv64: Add C++ trap handler
This is a basic trap handler which can handle interrupts and some
exceptions. Syscalls aren't handled yet.
2024-01-23 13:13:18 -07:00
Sönke Holz
0111fe0d24 Kernel/riscv64: Implement Processor::exit_trap
This function is copy-pasted from aarch64's Processor.cpp
2024-01-23 13:13:18 -07:00
Sönke Holz
0e6659d1eb Kernel/riscv64: Implement dump_registers() 2024-01-23 13:13:18 -07:00
Sönke Holz
9bbf513c27 Kernel/riscv64: Implement initialize_interrupts() 2024-01-23 13:13:18 -07:00
Sönke Holz
7b7578bc1b Kernel/riscv64: Add AK::Formatter for scause CSR 2024-01-23 13:13:18 -07:00
Sönke Holz
6d8378735b Kernel/riscv64: Add AK::Formatter for sstatus CSR 2024-01-23 13:13:18 -07:00
Sönke Holz
d061da4cf5 Kernel/riscv64: Clean up Timer class
I just copy-pasted microseconds_since_boot and
set_interrupt_interval_usec from aarch64.
However, on RISC-V, they are not in microseconds.
The TimerRegisters struct is also unused.

current_time and set_compare can also be private and static.
2024-01-23 13:13:18 -07:00
Sönke Holz
8582f0720f Kernel/riscv64: Make RISC-V Timer inherit from GenericInterruptHandler
IRQHandler is not the correct class to inherit from, as the timer
is not connected to an IRQController.
Each hart has one of these Timers directly connected to it.
2024-01-23 13:13:18 -07:00
Sönke Holz
8c017c3078 Kernel/riscv64: Remove unnecessary InterruptController header
I originally added this header because I misunderstood how
IRQControllers are supposed to be used.
I thought that I would need a IRQController class for the hart-local
interrupt controller, but apparently, this class is supposed to be used
for non-local interrupt controllers like the IOAPIC or RISC-V PLIC.
x86 LAPICs don't use this class either.
2024-01-23 13:13:18 -07:00
Sönke Holz
0e6d87fe83 Kernel/riscv64: Don't disable stack protector and sanitizers
I am not sure why 096cecb95e disabled the stack protector and sanitizers
for all files, but this is not necessary.
Only the pre_init code needs to run without them, as that code runs
identity mapped.
2024-01-22 20:07:36 -07:00
Jelle Raaijmakers
f5dec55fd6 Kernel: Correct mapping of PS/2 keyboard exclamation point
Pressing Shift+1 resulted in `Key_Escape` being sent as the event's key.
2024-01-14 15:06:37 -07:00
Jelle Raaijmakers
015622bc22 Kernel: Set correct KeyCode count
The underlying value of the `KeyCode::Key_*` enum values starts at 0,
so we should add 1 to `Key_Menu` to get the correct count.
2024-01-14 15:06:37 -07:00
Liav A
a10e63f08e Kernel/FileSystem: Send proper filetypes when traversing RAM-backed FSes
SysFS, ProcFS and DevPtsFS were all sending filetype 0 when traversing
their directories, but it is actually very easy to send proper filetypes
in these filesystems.
This patch binds all RAM backed filesystems to use only one enum for
their internal filetype, to simplify the implementation and allow
sharing of code.
Please note that the Plan9FS case is currently not solved as I am not
familiar with this filesystem and its constructs.

The ProcFS mostly keeps track of the filetype, and a fix was needed for
the /proc root directory - all processes exhibit a directory inside it
which makes it very easy to hardcode the directory filetype for them.
There's also the `self` symlink inode which is now exposed as DT_LNK.

As for SysFS, we could leverage the fact everything inherits from the
SysFSComponent class, so we could have a virtual const method to return
the proper filetype.
Most of the files in SysFS are "regular" files though, so the base class
has a non-pure virtual method.

Lastly, the DevPtsFS simply hardcodes '.' and '..' as directory file
type, and everything else is hardcoded to send the character device file
type, as this filesystem is only exposing character pts device files.
2024-01-13 19:01:07 -07:00
Sönke Holz
959f2c0342 Kernel/riscv64: Implement debug_output and change cmdline to use it
Just implementing `debug_output` (and adding "serial_debug" to the
cmdline) makes the kernel print its first assertion failure!
2024-01-12 16:46:46 -07:00
Sönke Holz
dfce2f6341 Kernel/riscv64: Explicitly discard temporary local symbols
This is for some reason needed for riscv64 clang, as otherwise the
kernel.map file would grow too big to fit in its section inside the
kernel image.
None of our other architectures have temporary locals in their
kernel.map.
2024-01-12 16:46:46 -07:00
Sönke Holz
da33e2a564 Kernel/riscv64: Add MMU initialization code
We initialize the MMU by first setting up the page tables for the
kernel image and the initial kernel stack.
Then we jump to a identity mapped page which makes the newly created
kernel root page table active by setting `satp` and then jumps to
`init`.
2024-01-12 16:46:46 -07:00
Sönke Holz
27860cfaa2 Kernel/riscv64: Add a basic trap handler to pre_init
This trap handler uses the SBI to print an error message via a newly
introduced panic function, which is necessary as `pre_init` is running
identity mapped.
Also add a header file for `pre_init.cpp` as we wan't to use the panic
and `dbgln` function in the MMU init code as well.
2024-01-12 16:46:46 -07:00
Jared
dd53f64d2f Kernel: Properly ack segment
Fixed a mistake where we did not acknowledge a segment in the FinWait2
state.
2024-01-12 16:29:08 -07:00
Sönke Holz
e4244f7469 Kernel/riscv64: Implement support for "panic=shutdown" cmdline option 2024-01-12 16:25:46 -07:00
Sönke Holz
8547813b6d Kernel/riscv64: Implement arch_specific_{reboot,shutdown} using the SBI
We first try to use the newer "SRST" extension for rebooting and
shutting down and if that fails, we try to shutdown using the legacy
"System Shutdown" extension (which can't reboot, so we always shutdown).
The kernel will halt, if we return from here due to all attempts at
rebooting / shutting down failing.
2024-01-12 16:25:46 -07:00
Sönke Holz
21b2d1de65 Kernel/riscv64: Add AK::Formatter for SBI errors
This allows us to print errors returned to us via the SBI.
The error messages are taken from the SBI spec.
2024-01-12 16:25:46 -07:00
Sönke Holz
27087318bc Kernel/riscv64: Add support for SRST "System Reset" SBI extension
This extension will be used for rebooting and shutting down.
2024-01-12 16:25:46 -07:00
Sönke Holz
cac7dc8d71 Kernel/riscv64: Add support for legacy "System Shutdown" SBI extension 2024-01-12 16:25:46 -07:00
Liav A
8a0a3638f0 Kernel/HID: Introduce the all-mice device
This device will be used by userspace to read mouse packets from all
mouse devices that are attached to the machine.

This change is a preparation before we can enable seamless hotplug
capabilities in WindowServer for mouse devices, without any major change
on the userspace side.
2024-01-12 16:08:08 -07:00
Liav A
b634792022 Kernel: Enable i8042 first port translation by default
Without this, we have many issues with the keyboard, so enable this for
now until this is figured out.
2024-01-12 16:02:13 -07:00
Liav A
2a5f66e4d8 Kernel/HID: Fix PS2 keyboard scan code tables
We do this by implementing the following fixes:
- The Key_Plus is assigned to a proper map entry index now which is 0x4e
  both on the keypad and non-keypad keys.
- Shift+Q now prints out "Q" properly on scan code set 2.
- Key BackSlash (or Pipe on shift key being pressed down) is now working
  properly as well.
- Key_Pipe (which is "|" for en-US layout) is now working in scan code
  set 2.
- Numpad keys as well as the decimal separator key are working again.
2024-01-12 16:02:13 -07:00
Hendiadyoin1
23d6c88027 Kernel/MM: Don't allocate a temporary Vector when parsing the memory map
Instead we can achieve the same by just using an optional.
2024-01-12 15:59:47 -07:00
Hendiadyoin1
adac43ab1c Kernel: Use new PCI BAR API in IOWindow and correct IO bounds checks
The IO bounds checks were on 32 bit instead of the actual limit of
16 bit, which would have caused problems later down the line.
2024-01-12 15:59:47 -07:00
Hendiadyoin1
bd118f4eb0 Kernel: Use the new BAR address API for the NVMe stack
This includes changing the cached `m_bar` value to a `PhysicalAddress`
2024-01-12 15:59:47 -07:00
Hendiadyoin1
2dc20f9e39 Kernel: Use the new API to query and map BAR spaces in most places
This might be a bit overkill in some instances, but it's nice to be
consistent
2024-01-12 15:59:47 -07:00
Hendiadyoin1
c65455e122 Kernel: Expand BAR address mask up to 64 bit
Otherwise we would end up truncating the address when applying the mask

Co-Authored-By: Sönke Holz <sholz8530@gmail.com>
2024-01-12 15:59:47 -07:00
Hendiadyoin1
2f98c7d470 Kernel: Add convenience helpers for mapping PCI BAR spaces 2024-01-12 15:59:47 -07:00
Taj Morton
55cd89aea8 Kernel/FileSystem/FATFS: Use AssertSize to enforce FAT structure sizes 2024-01-12 15:54:46 -07:00
Taj Morton
d6a519e9af Kernel/FileSystem/FATFS: Restrict reads to the size of the file
Resolves issue where empty portions of a sector (or empty sectors in
a cluster) would be included with the returned data in a read().
2024-01-12 15:54:46 -07:00