Commit graph

8360 commits

Author SHA1 Message Date
Hendiadyoin1 aea244efe1 Kernel: Mark SDHC InterruptStatus structured view as const
This view is really nice to check flags, but when clearing them we must
make sure that we only ever try to set 1 bit at a time, which makes
setting bits through the structured view a footgun, as that fetches,
ors in and then sets, potentially resetting other flags.
2023-10-06 08:16:56 +02:00
Vladimir Serbinenko 2e9a28272e Kernel/Audio: Fail AC97 probe if no good BAR1 is found
Otherwise we get a kernel panic later on Intel SOF.
2023-10-03 16:19:03 -06:00
Vladimir Serbinenko 3e1146d4b8 Kernel: Detect PS2 keyboards on some chromebooks properly
Some chromebooks don't support PS2 controller reset and ignore it.
Other OSes in case of failed reset check by keyboard ID. Do the same
2023-10-03 16:19:03 -06:00
Vladimir Serbinenko 160609d80a Kernel/Memory: Map framebuffer and address space <4GiB
Address space under 4GiB is used for I/O but is absent
from memory maps on some systems.
2023-10-03 16:19:03 -06:00
Vladimir Serbinenko 342c707be3 Kernel: Don't use framebuffer if flag is not set
According to multiboot spec if flag for framebuffer isn't
set then corresponding fields are invalid. In reality they're set
to 0 but let's be defensive.
2023-10-03 16:19:03 -06:00
Vladimir Serbinenko 10d4bbd133 Prekernel: Fix wrong and misleading comment
Comment speaks about MULTIBOOT_MEMORY_INFO but those fields are actually
about aout kludge.
2023-10-03 16:19:03 -06:00
Vladimir Serbinenko 19cede9b3b Prekernel: Load multiboot values before loading kernel
This makes sure we don't clobber multiboot structure before we need it
2023-10-03 16:19:03 -06:00
Vladimir Serbinenko d13609a607 Prekernel: Support kernel preloaded at high address
Loaders try to put modules as low as reasonable but on
EFI often "reasonable" is much higher than on BIOS. As
a result target can be easily higher than source.

Then we have 2 problems:
* memmove compares virtual address and since target
  is mapped higher it ends up going backwards which
  is wrong if target is physically below source
* order of copying of sections must be inverted if
  target is below source
2023-10-03 16:19:03 -06:00
Vladimir Serbinenko 982ce17927 Prekernel: Map entire 4GiB space
Prekernel code currently assumes that mapping until MAX_KERNEL_SIZE
is enough to make the modules accessible. GRUB tries to load as low
as possible but higher than 1 MiB. Hence this is usually true.
However on EFI some ranges may already be used by boot services and
GRUB tries to avoid them if possible. This pushes modules higher.
The simplest solution is to map entire 4 GiB space.
As an additional benefit it makes the framebuffer accessible that
can be used for the debugging.
2023-10-03 16:19:03 -06:00
kleines Filmröllchen 398d271a46 Kernel: Share Processor class (and others) across architectures
About half of the Processor code is common across architectures, so
let's share it with a templated base class. Also, other code that can be
shared in some ways, like FPUState and TrapFrame functions, is adjusted
here. Functions which cannot be shared trivially (without internal
refactoring) are left alone for now.
2023-10-03 16:08:29 -06:00
Tim Ledbetter ad984ba522 Kernel: Populate stat.st_dev with fsid
This allows userland programs to differentiate inodes on different
filesystems.
2023-10-01 13:34:41 +02:00
kleines Filmröllchen 9a026fc8d5 AK: Implement SipHash as the default hash algorithm for most use cases
SipHash is highly HashDoS-resistent, initialized with a random seed at
startup (i.e. non-deterministic) and usable for security-critical use
cases with large enough parameters. We just use it because it's
reasonably secure with parameters 1-3 while having excellent properties
and not being significantly slower than before.
2023-10-01 11:06:36 +03:30
Timon Kruiper d170186163 Kernel/aarch64: Subtract KERNEL_MAPPING_BASE from driver_init section
This subtraction is necessary to ensure that the section has the correct
address. Also, without this change, the Kernel ELF binary would explode
in size. This was forgotten in a0dd6ec6b1.
2023-09-30 16:58:15 +02:00
Hendiadyoin1 29292bbdbf Kernel/USB: Add a crude USB MassStorage driver :^) 2023-09-29 16:14:47 -06:00
Hendiadyoin1 c230a0d96f Kernel: Avoid some copies during USBInterface enumeration/creation 2023-09-29 16:14:47 -06:00
Hendiadyoin1 b857c6b92f Kernel/USB: Make USBControllers pseudo StorageControllers
This will be needed in the next commit to generate valid LUNs
2023-09-29 16:14:47 -06:00
Hendiadyoin1 4b327bdc95 Kernel/USB: Add UKBuffer variants of certain BulkPipe/Transfer functions
These will be useful for directly accessing the source/destination
buffers, without going through a third buffer first.
2023-09-29 16:14:47 -06:00
Hendiadyoin1 8335803045 Kernel/USB: Explicitely copy descriptor.hub_characteristics for printing
This field is in a packed struct, which makes it possibly misaligned.
This knowledge is lost when invoking `dbgln` triggering an unaligned
access to it, aka UB. By explicitely copying it we avoid this issue.
2023-09-29 16:14:47 -06:00
Hendiadyoin1 c9a4ab9987 Kernel/USB: Add missing include in USBInterface.h 2023-09-29 16:14:47 -06:00
Hendiadyoin1 d39acfb908 Kernel/USB: Copy device configurations when copying devices 2023-09-29 16:14:47 -06:00
Hendiadyoin1 4f46fb9891 Kernel: Allow adding storage devices after init 2023-09-29 16:14:47 -06:00
Hendiadyoin1 0b649878a5 Kernel: Remove UNMAP_ATER_INIT from StorageDeviceSysFSDirectory
We will need these when plugging in USB drives
2023-09-29 16:14:47 -06:00
Liav A 7718842829 Kernel/VirtIO: Ensure proper error propagation in core methods
Simplify core methods in the VirtIO bus handling code by ensuring proper
error propagation. This makes initialization of queues, handling changes
in device configuration, and other core patterns more readable as well.

It also allows us to remove the obnoxious pattern of checking for
boolean "success" and if we get false answer then returning an actual
errno code.
2023-09-24 19:54:23 -06:00
Hendiadyoin1 cfba182b61 Kernel/PCI: Make SATAProgIF comparable with ProgrammingInterface
This makes checking it a bit nicer
2023-09-22 18:39:37 -06:00
Hendiadyoin1 d64d03e0d6 Kernel: Make Graphics device detection a bit more idomatic 2023-09-22 18:39:37 -06:00
Hendiadyoin1 e7012a9245 Kernel: Use PCI/Definitions.h for PCI-USB controller magic numbers 2023-09-22 18:39:37 -06:00
Hendiadyoin1 693f3ad33e Kernel: Add some more PCI [Sub]Class IDs 2023-09-22 18:39:37 -06:00
Hendiadyoin1 66647b58d4 Kernel: Make PCI [Sub]ClassCode comparable to the corresponding ID enums 2023-09-22 18:39:37 -06:00
Hendiadyoin1 d168bfabc4 Kernel/USB: Detach devices from their driver when they are detached 2023-09-18 11:09:19 -06:00
Jesse Buhagiar b4cd354bae Kernel/USB: Add driver search on device plug
When a device is plugged into the machine (and hence, when
`Device::try_create()` is called), then we attempt to load a driver by
calling that driver's probe function.
2023-09-18 11:09:19 -06:00
Jesse Buhagiar b0ed126538 Kernel/USB: Expose USBConfiguration in USBInterface 2023-09-18 11:09:19 -06:00
Jesse Buhagiar 3cfdc6e363 Kernel/USB: Add get_driver_by_name helper in USBManagement 2023-09-18 11:09:19 -06:00
Jesse Buhagiar 2aa17f619c Kernel/USB: Add USB Driver register/unregister function 2023-09-18 11:09:19 -06:00
Jesse Buhagiar 3cead2801a Kernel: Call USB Driver initialize functions during init 2023-09-18 11:09:19 -06:00
Jesse Buhagiar a0dd6ec6b1 Kernel/USB: Add driver_init section
At any one given time, there can be an abitrary number of USB drivers in
the system. The way driver mapping works (i.e, a device is inserted, and
a potentially matching driver is probed) requires us to have
instantiated driver objects _before_ a device is inserted. This leaves
us with a slight "chicken and egg" problem. We cannot call the probe
function before the driver is initialised, but we need to know _what_
driver to initialise.

This section is designed to store pointers to functions that are called
during the last stage of the early `_init` sequence in the Kernel. The
accompanying macro in `USBDriver` emits a symbol, based on the driver
name, into this table that is then automatically called.

This way, we enforce a "common" driver model; driver developers are not
only required to write their driver and inherit from `USB::Driver`, but
are also required to have a free floating init function that registers
their driver with the USB Core.
2023-09-18 11:09:19 -06:00
Jesse Buhagiar 8883da9586 Kernel/USB: Add new Driver base class
Co-Authored-By: Liav A <liavalb@gmail.com>
Co-Authored-By: Leon Albrecht <leon2002.la@gmail.com>
2023-09-18 11:09:19 -06:00
Liav A d61c23569e Kernel/VirtIO: Introduce the concept of transport options
The VirtIO specification defines many types of devices with different
purposes, and it also defines 3 possible transport mediums where devices
could be connected to the host machine.

We only care about the PCIe transport, but this commit puts the actual
foundations for supporting the lean MMIO transport too in the future.

To ensure things are kept abstracted but still functional, the VirtIO
transport code is responsible for what is deemed as related to an actual
transport type - allocation of interrupt handlers and tinkering with low
level transport-related registers, etc.
2023-09-16 14:04:17 -06:00
Liav A 68c3f9aa5a Kernel/Interrupts: Move PCIIRQHandler => PCI::IRQHandler
This class is part of the PCI code so let's move it to the PCI namespace
like other handling code parts of the PCI bus.
2023-09-16 14:04:17 -06:00
Hendiadyoin1 a2810d3cf8 Kernel: Use Processor::wait_check in loops waiting for HW to respond
This gives the processor the hint that it is in a hot loop and allows us
to do other work in between
2023-09-15 11:07:35 -06:00
Liav A cbaa3465a8 Kernel: Add jail semantics to methods iterating over thread lists
We should consider whether the selected Thread is within the same jail
or not.
Therefore let's make it clear to callers with jail semantics if a called
method checks if the desired Thread object is within the same jail.

As for Thread::for_each_* methods, currently nothing in the kernel
codebase needs iteration with consideration for jails, so the old
Thread::for_each* were simply renamed to include "ignoring_jails" suffix
in their names.
2023-09-15 11:06:48 -06:00
Liav A 3a55a1b592 Kernel: Use Process::get_thread_from_thread_list in Syscalls/thread.cpp
Some syscalls could be simplified by using the non-static method
Process::get_thread_from_thread_list which should ensure that the
specified tid is of a Thread in the same Process of the current Thread.
2023-09-15 11:06:48 -06:00
Liav A 50429d3b22 LibC+Kernel: Move GPU-related API methods to a LibC header file
The Kernel/API directory in general shouldn't include userspace code,
but structure definitions that both are shared between the Kernel and
userspace.

All users of the ioctl API obviously use LibC so LibC is the most common
and shared library for the affected programs.
2023-09-15 11:05:25 -06:00
Liav A 8fe74c7d57 LibC+Kernel: Move device-files related methods to a LibC header file
The Kernel/API directory in general shouldn't include userspace code,
but structure definitions that both are shared between the Kernel and
userspace.

LibC is the most appropriate place for these methods as they're already
included in the sys/sysmacros.h file to create a set of convenient
macros for these methods.
2023-09-15 11:05:25 -06:00
Liav A b49f2937f0 Kernel/TTY: Don't return NonnullLockRefPtr when creating MasterPTY
We can just return a normal NonnullRefPtr because nobody needs an actual
*LockRefPtrs here anymore.
2023-09-09 12:08:59 -06:00
Liav A 82428e2a05 Kernel/TTY: Protect SlavePTY pointer with proper spinlock
Instead of using a LockRefPtr, we could easily use SpinlockProtected to
ensure proper locking of this pointer.
2023-09-09 12:08:59 -06:00
Liav A b55199c227 Kernel: Move TTY-related code to a new subdirectory under Devices
The TTY subsystem is represented with unix devices, so it should be
under the Devices directory like the Audio, Storage, GPU and HID
subsystems.
2023-09-09 12:08:59 -06:00
Jakub Berkop 54e79aa1d9 Kernel+ProfileViewer: Display additional filesystem events 2023-09-09 11:26:51 -06:00
Jakub Berkop c184a0786f Kernel: Protect access to PerformanceEventBuffer strings with spinlock 2023-09-09 11:26:51 -06:00
DaftMouse 29c89d3b95 Kernel: Implement scrolling critical messages vga text mode console 2023-09-09 10:18:17 -06:00
DaftMouse 6f7f0b3a8c Kernel: Implement scrolling critical messages in framebuffer console 2023-09-09 10:18:17 -06:00