Commit Graph

355 Commits

Author SHA1 Message Date
Marco
9b27b0cd1a Kernel: init: Make comment clearer 2021-03-03 14:18:43 +01:00
Brian Gianforcaro
afe099388e Kernel: Add 'boot_prof' option to enable full system profiling on boot
The full system profiling functionality is useful for profiling the
boot performance of the system. Add a new kernel boot option to start
the system with profiling enabled. This lets you disable and view a
profile once the system is booted.

You can use it by running:
```
$ run.sh qcmd boot_prof
```
2021-03-03 11:05:16 +01:00
Brian Gianforcaro
84a399de5d Kernel: Move Kernel CommandLine parsing to strongly typed API.
Previously all of the CommandLine parsing was spread out around the
Kernel. Instead move it all into the Kernel CommandLine class, and
expose a strongly typed API for querying the state of options.
2021-03-03 11:05:16 +01:00
Andrew Kaster
5046213556 Kernel: Add self-test boot mode, an alias for text mode
Add a special boot mode for running tests, rather than using the system
as a general purpose OS. We'll use this in SystemServer to specify
only services needed to run tests and exit.
2021-02-28 18:19:37 +01:00
Andreas Kling
98f08a8bad Kernel: Panic early if the kernel gets too big for its memory slot
Let's help our future selves find this problem sooner next time it
happens. Hopefully we'll come up with a nicer loader before then,
but who knows. :^)
2021-02-24 20:57:47 +01:00
Andreas Kling
5d180d1f99 Everywhere: Rename ASSERT => VERIFY
(...and ASSERT_NOT_REACHED => VERIFY_NOT_REACHED)

Since all of these checks are done in release builds as well,
let's rename them to VERIFY to prevent confusion, as everyone is
used to assertions being compiled out in release.

We can introduce a new ASSERT macro that is specifically for debug
checks, but I'm doing this wholesale conversion first since we've
accumulated thousands of these already, and it's not immediately
obvious which ones are suitable for ASSERT.
2021-02-23 20:56:54 +01:00
Andreas Kling
5100dabb96 Kernel: Copy the kernel command line to a good location at boot
When building the kernel with -O2, we somehow ended up with the kernel
command line outside of the lower 8MB of physical memory. Since we don't
map that area in our initial page table setup, we would triple fault
when trying to parse the command line.

This patch sidesteps the issue by copying the (first 4KB of) the kernel
command line to a buffer in a known safe location at boot.
2021-02-23 19:43:44 +01:00
Andreas Kling
fdf03852c9 Kernel: Slap UNMAP_AFTER_INIT on a whole bunch of functions
There's no real system here, I just added it to various functions
that I don't believe we ever want to call after initialization
has finished.

With these changes, we're able to unmap 60 KiB of kernel text
after init. :^)
2021-02-19 20:23:05 +01:00
Andreas Kling
6136faa4eb Kernel: Add .unmap_after_init section for code we don't need after init
You can now declare functions with UNMAP_AFTER_INIT and they'll get
segregated into a separate kernel section that gets completely
unmapped at the end of initialization.

This can be used for anything we don't need to call once we've booted
into userspace.

There are two nice things about this mechanism:

- It allows us to free up entire pages of memory for other use.
  (Note that this patch does not actually make use of the freed
  pages yet, but in the future we totally could!)

- It allows us to get rid of obviously dangerous gadgets like
  write-to-CR0 and write-to-CR4 which are very useful for an attacker
  trying to disable SMAP/SMEP/etc.

I've also made sure to include a helpful panic message in case you
hit a kernel crash because of this protection. :^)
2021-02-19 20:23:05 +01:00
Andreas Kling
7a78a4915a Kernel: Mark a handful of things in init.cpp as READONLY_AFTER_INIT 2021-02-14 18:12:00 +01:00
Andreas Kling
d8013c60bb Kernel: Add mechanism to make some memory read-only after init finishes
You can now use the READONLY_AFTER_INIT macro when declaring a variable
and we will put it in a special ".ro_after_init" section in the kernel.

Data in that section remains writable during the boot and init process,
and is then marked read-only just before launching the SystemServer.

This is based on an idea from the Linux kernel. :^)
2021-02-14 18:11:32 +01:00
Andreas Kling
b712345c92 Kernel: Use PANIC() in a bunch of places :^) 2021-02-14 09:36:58 +01:00
Owen Smith
c2de22a635 Kernel: Merge split function and data sections into one during linking
Also add an assertion to make sure the safemem sections are never
discarded by the linker.
2021-02-12 08:57:26 +01:00
Jean-Baptiste Boric
edd2362f39 Kernel: Add NE2000 network card driver
Remember, friends don't let friends use NE2000 network cards :^)
2021-02-05 09:35:02 +01:00
Liav A
f2faf11d61 Kernel: Try to detect Sound Blaster 16 before creating an instance
We shouldn't create a SB16 instance without checking if the Sound
Blaster 16 card is actually installed in the system.
2021-02-05 08:54:02 +01:00
Liav A
5ab1864497 Kernel: Introduce the MemoryDevice
This is a character device that is being used by the dmidecode utility.
We only allow to map the BIOS ROM area to userspace with this device.
2021-02-01 17:13:23 +01:00
Liav A
df59b80e23 Kernel: Expose SMBIOS blobs in ProcFS 2021-02-01 17:13:23 +01:00
Tom
d5472426ec Kernel: Retire SchedulerData and add Thread lookup table
This allows us to get rid of the thread lists in SchedulerData.
Also, instead of iterating over all threads to find a thread by id,
just use a lookup table. In the rare case of having to iterate over
all threads, just iterate the lookup table.
2021-01-28 17:35:41 +01:00
Maciej Zygmanowski
67e93745cb Kernel: Ensure that HPET is initialized before using random the first time 2021-01-26 21:14:44 +01:00
Jean-Baptiste Boric
8941d831bb Kernel: Allow "serial_debug" everywhere on the command line 2021-01-23 16:53:03 +01:00
Jean-Baptiste Boric
ec056f3bd1 Kernel: Parse boot modules from Multiboot specification 2021-01-22 22:17:39 +01:00
asynts
019c9eb749 Everywhere: Replace a bundle of dbg with dbgln.
These changes are arbitrarily divided into multiple commits to make it
easier to find potentially introduced bugs with git bisect.
2021-01-09 21:11:09 +01:00
Jesse Buhagiar
6df15aca7e Kernel/USB: Implement test transfer
We can now test a _very_ basic transaction via `do_debug_transfer()`.
This function merely attaches some TDs to the LSCTRL queue head
and points some input and output buffers. We then sense an interrupt
with USBSTS value of 1, meaning Interrupt On Completion
(of the transaction). At this point, the input buffer is filled with
some data.
2021-01-09 13:48:15 +01:00
Jesse Buhagiar
770a729e59 Kernel/USB: Add basic root port detection/management
We can now read/write to the two root ports exposed to the
UHCI controller, and detect when a device is plugged in or
out via a kernel process that constantly scans the port
for any changes. This is very basic, but is a bit of fun to see
the kernel detecting hardware on the fly :^)
2021-01-09 13:48:15 +01:00
Jesse Buhagiar
33d73c600c Kernel/USB: Move USB classes into USB namespace
The entire USB spec involves more than just UHCI, so
let's put everything into it's own nice namespace :^)
2021-01-09 13:48:15 +01:00
Jesse Buhagiar
0dbb9361b8 Kernel/USB: Move USB related files to into specific directory
As the USB/UHCI driver grows in size, it'll be much cleaner to have
all of the USB related files in one folder where they can be easily
accessed :^)
2021-01-09 13:48:15 +01:00
Liav A
72b1998f0d Kernel: Introduce a new partitioning subsystem
The partitioning code was very outdated, and required a full refactor.
The new subsystem removes duplicated code and uses more AK containers.

The most important change is that all implementations of the
PartitionTable class conform to one interface, which made it possible
to remove unnecessary code in the EBRPartitionTable class.

Finding partitions is now done in the StorageManagement singleton,
instead of doing so in init.cpp.

Also, now we don't try to find partitions on demand - the kernel will
try to detect if a StorageDevice is partitioned, and if so, will check
what is the partition table, which could be MBR, GUID or EBR.
Then, it will create DiskPartitionMetadata object for each partition
that is available in the partition table. This object will be used
by the partition enumeration code to create a DiskPartition with the
correct minor number.
2020-12-27 23:07:44 +01:00
Liav A
3a19e18d1e Kernel: Move Partition code files to the Storage folder
This folder is more appropriate for these files.
2020-12-27 23:07:44 +01:00
Liav A
469f20d4ee Kernel: Introduce the StorageManagement class
The StorageManagement class has 2 roles:
1. During boot, it should find all storage controllers in the machine,
and then determine what is the boot device.
2. Later on boot, it is a registrar of all storage controllers and
storage devices. Thus, it could be used to show information about these
devices when implemented.

This change allows the user to specify a boot driver other than /dev/hda
and if it's connected in the machine - it will boot.
2020-12-21 00:19:21 +01:00
Liav A
0a2b00a1bf Kernel: Introduce the new Storage subsystem
This new subsystem is somewhat replacing the IDE disk code we had with a
new flexible design.

StorageDevice is a generic class that represent a generic storage
device. It is meant that specific storage hardware will override the
interface. StorageController is a generic class that represent
a storage controller that can be found in a machine.

The IDEController class governs two IDEChannels. An IDEChannel is
responsible to manage the master & slave devices of the channel,
therefore an IDEChannel is an IRQHandler.
2020-12-21 00:19:21 +01:00
Tom
6a620562cc Kernel: Allow passing a thread argument for new kernel threads
This adds the ability to pass a pointer to kernel thread/process.
Also add the ability to use a closure as thread function, which
allows passing information to a kernel thread more easily.
2020-11-30 13:17:02 +01:00
Tom
2b78b17926 Kernel: Enable VMWareBackdoor immediately at boot
Rather than waiting until we get the first mouse packet, enable the
absolute mode immediately. This avoids having to click first to be
able to move the mouse.
2020-11-26 10:00:01 +01:00
Tom
91db31880f Kernel: Add I8042Controller to detect and manage PS/2 devices
Rework the PS/2 keyboard and mouse drivers to use a common 8042
controller driver. Also, reset and reconfigure the 8042 controller
as they are not guaranteed to be in the state that we expect.
2020-11-12 18:04:16 +01:00
Tom
fe615e601a Kernel: Set up and calibrate APIC timer, and enable timer on all CPUs
This enables the APIC timer on all CPUs, which means Scheduler::timer_tick
is now called on all CPUs independently. We still don't do anything on
the APs as it instantly crashes due to a number of other problems.
2020-10-25 21:18:35 +01:00
AnotherTest
dd60fe4d37 Kernel: Optionally take some arguments to pass to the init program
This makes it possible to start _everything_ under UserspaceEmulator, by
setting `init_args` to `--report-to-debug,/bin/SystemServer` and `init`
to `/bin/UserspaceEmulator`.
With the UE patches before this, we get to spawn WindowServer, and crash
because of FLD_RM32 (nothing tested past that) in graphical mode.
But we get a working shell in text mode :^) (and DHCPClient fails when
setting whatever settings it has received)
2020-10-25 10:13:03 +01:00
Tom
838d9fa251 Kernel: Make Thread refcounted
Similar to Process, we need to make Thread refcounted. This will solve
problems that will appear once we schedule threads on more than one
processor. This allows us to hold onto threads without necessarily
holding the scheduler lock for the entire duration.
2020-09-27 19:46:04 +02:00
Andreas Kling
e834c24eea Kernel/USB: Start fleshing out a basic UHCI controller driver :^)
Let's see if we can talk to some USB devices. We will now detect
a UHCI controller if present on the PCI bus.
2020-09-04 21:21:41 +02:00
Tom
81780e607d Kernel: Copy command line to a safe place
This avoids kmalloc overwriting it because it may be within the
kmalloc or eternal pool.
2020-08-25 09:48:48 +02:00
Tom
d89582880e Kernel: Switch singletons to use new Singleton class
MemoryManager cannot use the Singleton class because
MemoryManager::initialize is called before the global constructors
are run. That caused the Singleton to be re-initialized, causing
it to create another MemoryManager instance.

Fixes #3226
2020-08-25 09:48:48 +02:00
Andreas Kling
2fd9e72264 Revert "Kernel: Switch singletons to use new Singleton class"
This reverts commit f48feae0b2.
2020-08-22 18:01:59 +02:00
Andreas Kling
8a21491d86 Revert "Kernel: Copy command line to a safe place"
This reverts commit 41c005cb14.
2020-08-22 16:34:12 +02:00
Tom
41c005cb14 Kernel: Copy command line to a safe place
This avoids kmalloc overwriting it because it may be within the
kmalloc or eternal pool.
2020-08-22 10:46:24 +02:00
Tom
f48feae0b2 Kernel: Switch singletons to use new Singleton class
Fixes #3226
2020-08-21 11:47:35 +02:00
Andreas Kling
6d9b59f1b7 Kernel: Simplify the way we check for "serial_debug" on command line 2020-08-13 20:18:11 +02:00
Ben Wiederhake
936d5dcc01 Kernel: Tell compiler about invisible calls
This makes the Kernel build cleanly with -Wmissing-declarations.
2020-08-12 20:40:59 +02:00
Ben Wiederhake
8a41ce5cc7 Kernel: Group C++ ABI functions together
As suggested in #3096.
2020-08-12 20:40:59 +02:00
Tom
08ff25f4ef Kernel: Invoke heap constructors separately early on
By having a separate list of constructors for the kernel heap
code, we can properly use constructors without re-running them
after the heap was already initialized. This solves some problems
where values were wiped out because they were overwritten by
running their constructors later in the initialization process.
2020-08-10 20:05:18 +02:00
Ben Wiederhake
bee08a4b9f Kernel: More PID/TID typing 2020-08-10 11:51:45 +02:00
Luke
98bea083c4 Kernel: Make BXVGA detection actually detect VBoxVGA
I decided to play around with trying to run Serenity in VirtualBox.
It crashed WindowServer with a beautiful array of multi-color
flashing letters :^)

Skipping getting side-tracked seeing that it chose MBVGA in the
serial debug and trying to debug why it caused such a display,
I finally checked BXVGA.

While find_framebuffer_address checks for VBoxVGA, init_stage2 didn't.
Whoops!
2020-07-30 17:01:41 +02:00
Florian Angermeier
d8fa8c5f82 Kernel: Ensure there are all VirtualConsoles properly initialized
It is possible to switch to VirtualConsoles 1 to 4 via the shortcut
ALT + [1-4]. Therefor the array of VirtualConsoles should be guaranteed
to be initialized.

Also add an constant for the maximum number of VirtualConsoles to
guarantee consistency.
2020-07-17 00:36:50 +02:00