Commit Graph

479 Commits

Author SHA1 Message Date
Skye Sprung
eca85f2050 Kernel: Changed serial debug functions and variables for readability
Change the name of set_serial_debug(bool on_or_off) to
set_serial_debug_enabled(bool desired_state). This is to make the names
more expressive and less unclear as to what the function does, as it
only sets the enabled state.
Likewise, change the name of get_serial_debug() to
is_serial_debug_enabled() in order to make clear from the name that
this is simply the state of s_serial_debug_enabled.
Change the name of serial_debug to s_serial_debug_enabled since this is
a static bool describing this state.
Finally, change the signature of set_serial_debug_enabled to return a
bool, as this is more logical and understandable.
2022-08-27 19:42:52 +01:00
Samuel Bowman
91574ed677 Kernel: Fix boot profiling
Boot profiling was previously broken due to init_stage2() passing the
event mask to sys$profiling_enable() via kernel pointer, but a user
pointer is expected.

To fix this, I added Process::profiling_enable() as an alternative to
Process::sys$profiling_enable which takes a u64 rather than a
Userspace<u64 const*>. It's a bit of a hack, but it works.
2022-08-23 11:48:50 +02:00
Andreas Kling
11eee67b85 Kernel: Make self-contained locking smart pointers their own classes
Until now, our kernel has reimplemented a number of AK classes to
provide automatic internal locking:

- RefPtr
- NonnullRefPtr
- WeakPtr
- Weakable

This patch renames the Kernel classes so that they can coexist with
the original AK classes:

- RefPtr => LockRefPtr
- NonnullRefPtr => NonnullLockRefPtr
- WeakPtr => LockWeakPtr
- Weakable => LockWeakable

The goal here is to eventually get rid of the Lock* classes in favor of
using external locking.
2022-08-20 17:20:43 +02:00
Liav A
00dbd667d5 Kernel/Graphics: Rename TextModeConsole => VGATextModeConsole
This change represents well the fact that the text mode console is based
on VGA text mode.
2022-07-13 19:15:17 +01:00
sin-ack
3f3f45580a Everywhere: Add sv suffix to strings relying on StringView(char const*)
Each of these strings would previously rely on StringView's char const*
constructor overload, which would call __builtin_strlen on the string.
Since we now have operator ""sv, we can replace these with much simpler
versions. This opens the door to being able to remove
StringView(char const*).

No functional changes.
2022-07-12 23:11:35 +02:00
sin-ack
c70f45ff44 Everywhere: Explicitly specify the size in StringView constructors
This commit moves the length calculations out to be directly on the
StringView users. This is an important step towards the goal of removing
StringView(char const*), as it moves the responsibility of calculating
the size of the string to the user of the StringView (which will prevent
naive uses causing OOB access).
2022-07-12 23:11:35 +02:00
Liav A
290eb53cb5 Kernel/SysFS: Stop cluttering the codebase with pieces of SysFS parts
Instead, start to put everything in one place to resemble the directory
structure of the SysFS when actually using it.
2022-06-17 11:01:27 +02:00
Timon Kruiper
f085903f62 Kernel: Move IRQController and InterruptManagement to Arch directory
These 2 classes currently contain much code that is x86(_64) specific.
Move them to the architecture specific directory. This also allows for a
simpler implementation for aarch64.
2022-06-02 13:14:12 +01:00
Peter Elliott
12c7b954e1 Kernel+WindowServer: Move setting tty graphical mode to Userspace
This will allow using the console tty and WindowServer regardless of
your kernel command line. Also this fixes a bug where, when booting in
text mode, the console was in graphical mode, and would not accept
input.
2022-04-29 19:52:32 +02:00
Liav A
02566d8091 Kernel: Move VMWareBackdoor to new directory in the Firmware directory 2022-04-20 19:21:32 +02:00
Idan Horowitz
086969277e Everywhere: Run clang-format 2022-04-01 21:24:45 +01:00
Lorenz Steinert
78f8821152 Kernel: Propagate HIDManagement initialisation error to init
Initialisation errors for HIDManagement are now returned to the init. In
the init we assert by MUST if we get an error.
2022-03-28 11:36:17 +02:00
Tom
c2f6152db8 Kernel: Change the BSP Processor instance to not have a constructor
This solves a problem where any non-trivial member in the global BSP
Processor instance would get re-initialized (improperly), losing data
that was already initialized earlier.
2022-03-27 18:54:56 +02:00
Idan Horowitz
f0166efe8c Kernel: Use the whole kernel PD range when randomizing the KASLR offset
Now that we reclaim the memory range that is created by KASLR before
the start of the kernel image, there's no need to be conservative with
the KASLR offset.
2022-03-23 19:49:49 +02:00
Liav A
12867d60ad Kernel: Create SelfTTYDevice class to help replace /dev/tty symlink
This will replace the /dev/tty symlink created by SystemServer, so
instead of a symlink, a character device will be created. When doing
read(2), write(2) and ioctl(2) on this device, it will "redirect" these
operations to the attached TTY of the current process.
2022-03-22 20:26:05 +01:00
Idan Horowitz
e18632660f Kernel: Use the pre-image kernel memory range introduced by KASLR
This ensures we don't just waste the memory range between the default
base load address and the actual load address that was shifted by the
KASLR offset.
2022-03-22 16:46:51 +01:00
Liav A
3bbb5734af Kernel: Don't initialize early framebuffer console if address is invalid
To do so, we now check that the framebuffer type is RGB so we know that
the Multiboot bootloader actually provided a valid framebuffer to work
with.

This fixes a problem I observed on my ICH7 test machine that apparently
the multiboot_framebuffer_addr was not null but there was no framebuffer
that was set up for RGB colors, and by initializing that console, there
was a memory curroption caused somewhere in the EBDA area to probably
cause a complete system lockup.
2022-03-18 09:22:10 +00:00
Liav A
eca8f292a5 Kernel: Allow to disable early boot console
This aid debugging on bare metal when we suspect that the boot console
does something wrong that interferes with other kernel components.
2022-03-18 09:22:10 +00:00
Daniel Bertalan
70ccdb300b Kernel: Panic if the init process dies
If init crashes, all other userspace processes exit too, thus rendering
the system unusable. Previously, the kernel would still keep running
even without a userland, showing just a black screen without any
indication of the issue.

We now panic the kernel, which shows a message on the console. In the
case of the CI runners, it shuts down the virtual machine, so we don't
have to wait for the 1 hour timeout if an issue arises with
SystemServer.
2022-03-08 23:30:47 +01:00
Liav A
2272d93215 Kernel/PCI: Unify disable checks under PCI::Access::is_disabled method
To declare that we don't have a PCI bus in the system we do two things:
1. Probe IO ports before enabling access -
In case we are using the QEMU ISA-PC machine type, IO probing results in
floating bus condition (returning 0xFF values), thus, we know we don't
have PCI bus on the system.
2. Allow the user to specify to not use the PCI bus at all in the kernel
commandline.
2022-03-02 18:41:54 +01:00
Liav A
f6e635938f Kernel: Change PCI access commandline option to also represent no access
This change allow the user to request the kernel to not use any PCI
resources/devices at all.

Also, don't try to initialize devices that rely on PCI if disabled.
2022-03-02 18:41:54 +01:00
Jakub Berkop
895a050e04 Kernel: Fixed argument passing for profiling_enable syscall
Arguments larger than 32bit need to be passed as a pointer on a 32bit
architectures. sys$profiling_enable has u64 event_mask argument,
which means that it needs to be passed as an pointer. Previously upper
32bits were filled by garbage.
2022-02-19 11:37:02 +01:00
Liav A
6efa27537a Kernel/Audio: Introduce a new design architecture for the subsystem
We have 3 new components:
1. The AudioManagement singleton. This class like in other subsystems,
is responsible to find hardware audio controllers and keep a reference
to them.
2. AudioController class - this class is the parent class for hardware
controllers like the Sound Blaster 16 or Intel 82801AA (AC97). For now,
this class has simple interface for getting and controlling sample rate
of audio channels, as well a write interface for specific audio channel
but not reading from it. One AudioController object might have multiple
AudioChannel "child" objects to hold with reference counting.
3. AudioChannel class - this is based on the CharacterDevice class, and
represents hardware PCM audio channel. It facilitates an ioctl interface
which should be consistent across all supported hardware currently.
It has a weak reference to a parent AudioController, and when trying to
write to a channel, it redirects the data to the parent AudioController.
Each audio channel device should be added into a new directory under the
/dev filesystem called "audio".
2022-02-14 11:39:19 +01:00
Liav A
c6c3e2a7fd Kernel: Instantiate a TextModeConsole early on if there's no framebuffer
If the bootloader that loaded us is providing a framebuffer details from
the Multiboot protocol then we can instantiate a framebuffer console.
Otherwise, we should use a text mode console, assuming that the BIOS and
the bootloader didn't try to modeset the screen resolution so we have is
a VGA 80x25 text mode being displayed on screen.

Since "boot_framebuffer_console" is no longer a good representative as a
global variable name, it's changed to g_boot_console to match the fact
that it can be assigned with a text mode console and not framebuffer
console if needed.
2022-02-09 21:05:48 +00:00
Tom
24f2f3ba4e Kernel: Set up an initial boot framebuffer console
Instead of seeing a black screen until GraphicsManagement was fully
initialized, this allows us to see the console output much earlier.
So, if the bootloader provided us with a framebuffer, set up a console
as early as possible.
2022-02-04 21:34:12 +01:00
Pankaj Raghav
d234e6b801 Kernel: Add polling support to NVMe
Add polling support to NVMe so that it does not use interrupt to
complete a IO but instead actively polls for completion. This probably
is not very efficient in terms of CPU usage but it does not use
interrupts to complete a IO which is beneficial at the moment as there
is no MSI(X) support and it can reduce the latency of an IO in a very
fast NVMe device.

The NVMeQueue class has been made the base class for NVMeInterruptQueue
and NVMePollQueue. The factory function `NVMeQueue::try_create` will
return the appropriate queue to the controller based on the polling
boot parameter.

The polling mode can be enabled by adding an extra boot parameter:
`nvme_poll`.
2022-02-02 18:26:59 +01:00
Idan Horowitz
c9d026d7bc Kernel: Perform DeviceManagement initialization after MM is initialized
There's no need to perform it this early, and until the MemoryManager
is initialized we have very limited kmalloc capacity, so let's try and
keep anything that's not required to be there out of there.
2022-01-25 22:41:26 +02:00
Liav A
b1ca39411b Kernel/Devices: Introduce the Device Control Device
This device will assist userspace to manage hotplug events.
A userspace application reads a DeviceEvent entry until the return value
is zero which indicates no events that are queued and waiting for
processing.
Trying to read with a buffer smaller than sizeof(DeviceEvent) results in
EOVERFLOW.
For now, there's no ioctl mechanism for this device but in the future an
acknowledgement mechanism can be implemented via ioctl(2) interface.
2022-01-23 00:38:02 +00:00
Andreas Kling
3399b6c57f Kernel: Remove old SlabAllocator :^)
This is no longer useful since kmalloc() does automatic slab allocation
without any of the limitations of the old SlabAllocator. :^)
2021-12-26 21:22:59 +01:00
Pankaj Raghav
1a27220bca Kernel: Encapsulate APIC initialization inside InterruptManagement
Currently the APIC class is constructed irrespective of whether it
is used or not.

So, move APIC initialization from init to the InterruptManagement
class and construct the APIC class only when it is needed.
2021-12-26 16:22:09 +02:00
Brian Gianforcaro
1c950773fb Kernel: Make MemoryManager::protect_ksyms_after_init UNMAP_AFTER_INIT
The function to protect ksyms after initialization, is only used during
boot of the system, so it can be UNMAP_AFTER_INIT as well.

This requires we switch the order of the init sequence, so we now call
`MM.protect_ksyms_after_init()` before `MM.unmap_text_after_init()`.
2021-12-24 14:28:59 -08:00
Liav A
52e01b46eb Kernel: Move Multi Processor Parser code to a separate directory 2021-12-23 23:18:58 -08:00
Daniel Bertalan
4fc28bfe02 Kernel: Unmap Prekernel pages after they are no longer needed
The Prekernel's memory is only accessed until MemoryManager has been
initialized. Keeping them around afterwards is both unnecessary and bad,
as it prevents the userland from using the 0x100000-0x155000 virtual
address range.

Co-authored-by: Idan Horowitz <idan.horowitz@gmail.com>
2021-12-22 00:02:36 -08:00
Idan Horowitz
fd3be7ffcc Kernel: Setup APIC AP cores boot environment before init_stage2
Since this range is mapped in already in the kernel page directory, we
can initialize it before jumping into the first kernel process which
lets us avoid mapping in the range into init_stage2's address space.

This brings us half-way to removing the shared bottom 2 MiB mapping in
every process, leaving only the Prekernel.
2021-12-22 00:02:36 -08:00
Andreas Kling
1f2d0d0ad4 Kernel: Use ksyms in-place instead of duplicating them into eternal heap
We can leave the .ksyms section mapped-but-read-only and then have the
symbols index simply point into it.

Note that we manually insert null-terminators into the symbols section
while parsing it.

This gets rid of ~950 KiB of kmalloc_eternal() at startup. :^)
2021-12-18 11:30:10 +01:00
Liav A
ac7953f945 Kernel: Allow switching to IOAPIC mode even without enabling SMP
This small change allows to use the IOAPIC by default without to enable
SMP mode, which emulates Uni-Processor setup with IOAPIC instead of
using the PIC.

This opens the opportunity to utilize other types of interrupts like MSI
and MSI-X interrupts.
2021-12-14 09:02:06 +01:00
Sam Atkins
c6a97ea843 Kernel: Mark kernel smart-pointer classes as [[nodiscard]]
And cast the unused return values to void.
2021-12-05 15:31:03 +01:00
Jelle Raaijmakers
7a2a0c1052 Kernel: Implement AC97 audio device driver 2021-11-23 10:06:24 +01:00
Jelle Raaijmakers
1aafb6cd23 Kernel: Teach DeviceManagement to handle multiple audio devices 2021-11-23 10:06:24 +01:00
Jelle Raaijmakers
61d77274db Kernel: Move SB16 to Audio subdirectory 2021-11-23 10:06:24 +01:00
Daniel Bertalan
a8fefd89cd Everywhere: Make some symbols __attribute__((used)) for LTO
With these changes, the userland builds correctly with Clang's ThinLTO
enabled.
2021-10-17 17:09:58 +01:00
James Mintram
545ce5b595 Kernel: Add per platform Processor.h headers
The platform independent Processor.h file includes the shared processor
code and includes the specific platform header file.

All references to the Arch/x86/Processor.h file have been replaced with
a reference to Arch/Processor.h.
2021-10-14 01:23:08 +01:00
Liav A
44f5f72add Kernel/Devices: Use try_create_device helper for SB16 2021-09-17 01:02:48 +03:00
Liav A
fd4397a430 Kernel/Devices: Use try_create_device helper for ConsoleDevice 2021-09-17 01:02:48 +03:00
Liav A
aee4786d8e Kernel: Introduce the DeviceManagement singleton
This singleton simplifies many aspects that we struggled with before:
1. There's no need to make derived classes of Device expose the
constructor as public anymore. The singleton is a friend of them, so he
can call the constructor. This solves the issue with try_create_device
helper neatly, hopefully for good.
2. Getting a reference of the NullDevice is now being done from this
singleton, which means that NullDevice no longer needs to use its own
singleton, and we can apply the try_create_device helper on it too :)
3. We can now defer registration completely after the Device constructor
which means the Device constructor is merely assigning the major and
minor numbers of the Device, and the try_create_device helper ensures it
calls the after_inserting method immediately after construction. This
creates a great opportunity to make registration more OOM-safe.
2021-09-17 01:02:48 +03:00
Liav A
33f033066c Kernel: Unify BIOS and ACPI components in the SysFS firmware directory
Both should reside in the SysFS firmware directory which is normally
located in /sys/firmware.
Also, apply some OOM-safety patterns when creating the BIOS and ACPI
directories.
2021-09-12 11:52:16 +02:00
Liav A
9132596b8e Kernel: Move ACPI and BIOS code into the new Firmware directory
This will somwhat help unify them also under the same SysFS directory in
the commit.
Also, it feels much more like this change reflects the reality that both
ACPI and the BIOS are part of the firmware on x86 computers.
2021-09-12 11:52:16 +02:00
Liav A
026f80a95b Kernel/ACPI: Simplify parser initialization
Let's remove the DynamicParser class, as it really did nothing yet in
the Kernel. Instead, when we add support for AML parsing, we can figure
out how to do it properly without the need of a derived class that just
complicates everything for no good reason.
2021-09-10 22:01:23 +02:00
Liav A
fb7b4caa57 Kernel/Storage: Implement basic AHCI hotplug support
This is really a basic support for AHCI hotplug events, so we know how
to add a node representing the device in /sys/dev/block and removing it
according to the event type (insertion/removal).

This change doesn't take into account what happens if the device was
mounted or a read/write operation is being handled.

For this to work correctly, StorageManagement now uses the Singleton
container, as it might be accessed simultaneously from many CPUs
for hotplug events. DiskPartition holds a WeakPtr instead of a RefPtr,
to allow removal of a StorageDevice object from the heap.
StorageDevices are now stored and being referenced to via an
IntrusiveList to make it easier to remove them on hotplug event.

In future changes, all of the stated above might change, but for now,
this commit represents the least amount of changes to make everything
to work correctly.
2021-09-08 00:42:20 +02:00
Liav A
6a9c717a30 Kernel: Expose device presence in /sys/dev/char and /sys/dev/block
These files are not marked as block devices or character devices so they
are not meant to be used as device nodes. The filenames are formatted to
the pattern "major:minor", but a Userland program need to call the parse
these format and inspect the the major and minor numbers and create the
real device nodes in /dev.

Later on, it might be a good idea to ensure we don't create new
SysFSComponents on the heap for each Device, but rather generate
them only when required (and preferably to not create a SysFSComponent
at all if possible).
2021-09-08 00:42:20 +02:00