Commit Graph

6043 Commits

Author SHA1 Message Date
James Mintram
e35222a76e Kernel: Move ScopedCritical + SmapDisabler CPP files into x86 common 2021-10-16 15:43:41 -07:00
James Mintram
8e4d53f216 Kernel: Add MiniStdLib to the Aarch64 kernel 2021-10-16 23:31:52 +01:00
James Mintram
3a9c7ce9d4 Kernel: Add StdLib.cpp to aarch64 build and update stubs in dummy.cpp 2021-10-15 21:48:45 +01:00
James Mintram
e8f09279d3 Kernel: Move spinlock into Arch
Spinlocks are tied to the platform they are built for, this is why they
have been moved into the Arch folder. They are still available via
"Locking/Spinlock.h"

An Aarch64 stub has been created
2021-10-15 21:48:45 +01:00
James Mintram
dfe4810c3a Kernel: Add cross platform RegisterState header and Aarch64 version
A new RegisterState header includes the platform specific RegisterState
header based on the platform being compiled.

The Aarch64 RegisterState header contains stubs for Debug
2021-10-15 21:48:45 +01:00
James Mintram
0fbeac6011 Kernel: Split SmapDisabler so header is platform independent
A new header file has been created in the Arch/ folder while the
implementation has been moved into a CPP living in the X86 folder.
2021-10-15 21:48:45 +01:00
James Mintram
f4fb637914 Kernel: Split ScopedCritical so header is platform independent
A new header file has been created in the Arch/ folder while the
implementation has been moved into a CPP living in the X86 folder.
2021-10-15 21:48:45 +01:00
Nico Weber
b135efe870 Kernel: List AK_SOURCES only once 2021-10-15 17:49:54 +01:00
Marcin Undak
d14d7ee78b Kernel: Discover initial exception level when booting Aarch64
When booting on RPI3 firmware puts CPU in EL2 mode which is
different from QEMU's default EL3.

I've added logic to discover initial mode at boot
and then act accordingly. This results in Serenity corectly
switching to EL1 on target hardware now.
2021-10-15 17:47:39 +01:00
Marcin Undak
ebf810f9a6 Kernel: Make Aarch64 register variables bit more descriptive 2021-10-15 17:47:39 +01:00
Marcin Undak
2d9fa8146c Kernel: Switch processor to EL1 immediately after boot on Aarch64 2021-10-15 17:47:39 +01:00
Marcin Undak
d6021300d5 Kernel: Move wait_cycles() function to Aarch_asm_utils.S
Just a bit of housekeeping.
2021-10-15 17:47:39 +01:00
Marcin Undak
18eb4a59d6 Kernel: Print current CPU exception level after booting on Aarch64
This is a first step to switch to exception level 1.

This is also my first patch for SerenityOS :)
2021-10-15 17:47:39 +01:00
James Mintram
a48985422c Kernel: Add UBSanitizer.cpp to the Aarch64 kernel build 2021-10-14 10:20:03 +01:00
James Mintram
ceb3328877 Kernel: Fix all linker errors for Aarch64 build 2021-10-14 01:23:08 +01:00
James Mintram
ab70268d61 Kernel: Add the AK sources to the Aarch64 kernel build 2021-10-14 01:23:08 +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
James Mintram
23676bee1f Kernel: Add -fsigned-char to ensure consistency across platforms 2021-10-14 01:23:08 +01:00
James Mintram
2a4969d281 Kernel: Move asserts inside platform #if clauses 2021-10-14 01:23:08 +01:00
James Mintram
580006d784 Kernel: Replace includes with a forward declaration 2021-10-14 01:23:08 +01:00
James Mintram
baa7925c0c Kernel: Remove unused includes 2021-10-14 01:23:08 +01:00
James Mintram
26d7c25076 Kernel: Add header includes closer to their use 2021-10-14 01:23:08 +01:00
James Mintram
d92967406a Kernel: Add post build step to generate kernel8.img
Add a postbuild step which creates a raw binary file called kernel8.img
from the Prekernel elf file.
2021-10-13 23:34:29 +01:00
Rodrigo Tobar
e1093c3403 Kernel: Implement pread syscall
The OpenFileDescription class already offers the necessary functionlity,
so implementing this was only a matter of following the structure for
`read` while handling the additional `offset` argument.
2021-10-13 16:10:50 +02:00
Rodrigo Tobar
8936b111a7 Kernel: Factor out common code from read/readv syscalls
Having these bits of code factored out not only prevents duplication
now, but will also allow us to implement pread without repeating
ourselves (too much).
2021-10-13 16:10:50 +02:00
James Mintram
a8e5130183 Kernel: Pass RegisterState by ref to event buffer 2021-10-12 10:49:56 -07:00
James Mintram
a4509ba633 Kernel: Accept RegisterState in append_with_ip_and_bp 2021-10-12 10:49:56 -07:00
Rodrigo Tobar
bf4e536f00 Kernel: Correctly interpret ioctl's FIONBIO user value
Values in `ioctl` are given through a pointer, but ioctl's FIONBIO
implementation was interpreting this pointer as an integer directly.
This meant that programs using `ioctl` to set a file descriptor in
blocking mode met with incorrect behavior: they passed a non-null
pointer pointing to a value of 0, but the kernel interpreted the pointer
as a non-zero integer, thus making the file non-blocking.

This commit fixes this behavior by reading the value from the userspace
pointer and using that to set the non-blocking flag on the file
descriptor.

This bug was found while trying to run the openssl tool on serenity,
which used `ioctl` to ensure newly-created sockets are in blocking mode.
2021-10-11 10:46:01 -07:00
Ben Wiederhake
fd8300e52d Kernel: Declare copy-ability of IOAddressGroup 2021-10-10 21:03:27 +01:00
Liav A
f8489da8ee Kernel/SysFS: Provide a way to "truncate" and "set" mtime on inodes
Normally, trying to truncate a SysFSInode should result in EPERM error.
However, as suggested by Ali (@alimpfard), we can allow the PowerState
node to be "truncated" so one can open that file with O_TRUNC option.
Likewise, we also need to provide a way to set modified time on SysFS
inodes. For most inodes, we should return ENOTIMPL error, but for the
power state switch, we ignore the modified time setting and just return
KSuccess.

These fixes allow to do "echo -n 1 > /sys/firmware/power_state" in Shell
after gaining root permissions, to switch the power state.
2021-10-09 12:07:56 +02:00
David Isaksson
b2e57f555b Kernel: Add ioctl request for getting a storage device's block size 2021-10-09 12:06:47 +02:00
David Isaksson
3b089032f4 Kernel: Add STORAGE_DEVICE_GET_SIZE ioctl request
This ioctl request makes it possible to get the size of a storage device
that has not yet been mounted.
2021-10-09 12:06:47 +02:00
Liav A
741c871bc1 Kernel/Storage: Unify all ATA devices
There's basically no real difference in software between a SATA harddisk
and IDE harddisk. The difference in the implementation is for the host
bus adapter protocol and registers layout.
Therefore, there's no point in putting a distinction in software to
these devices.

This change also greatly simplifies and removes stale APIs and removes
unnecessary parameters in constructor calls, which tighten things
further everywhere.
2021-10-09 01:39:55 +02:00
Nico Weber
1cdb12e920 Kernel: Fix -Wunreachable-code warnings from clang 2021-10-08 23:33:46 +02:00
Idan Horowitz
4174fe0156 Kernel: Use find_largest_not_above in VirtualRangeAllocator
Instead of iterating over the regions in the tree which is O(n), we can
just use RedBlackTree's find_largest_not_above method, which is O(logn)
2021-10-07 22:10:45 +02:00
Luke Wilde
49259777ef Kernel: Note if the page fault address is a destroyed smart pointer
While I was working on LibWeb, I got a page fault at 0xe0e0e0e4.
This indicates a destroyed RefPtr if compiled with SANITIZE_PTRS
defined. However, the page fault handler didn't print out this
indication.

This makes the page fault handler print out a note if the faulting
address looks like a recently destroyed RefPtr, OwnPtr, NonnullRefPtr,
NonnullOwnPtr, ThreadSafeRefPtr or ThreadSafeNonnullRefPtr. It will
only do this if SANITIZE_PTRS is defined, as smart pointers don't get
scrubbed without it being defined.
2021-10-07 21:30:13 +02:00
Idan Horowitz
399b5ffb64 Kernel: Add the /proc/stat ProcFS component
This exposes a small subset of the information exposed by the Linux
equivalent, and will be used to optimize applications that would like
to know the current CPU usage statistics, but don't want to read all of
the unrelated information in /proc/all
2021-10-07 21:09:38 +02:00
Idan Horowitz
900fac27c6 Kernel: Add Processor::time_spent_idle() 2021-10-07 21:09:38 +02:00
Andreas Kling
5b1f697460 AK+Kernel: Make automatically locking RefPtr & co a kernel-only thing
Some time ago, automatic locking was added to the AK smart pointers to
paper over various race conditions in the kernel. Until we've actually
solved the issues in the kernel, we're stuck with the locking.

However, we don't need to punish single-threaded userspace programs with
the high cost of locking. This patch moves the thread-safe variants of
RefPtr, NonnullRefPtr, WeakPtr and RefCounted into Kernel/Library/.
2021-10-07 19:27:30 +02:00
Tim Schumacher
228a32effc Kernel: Don't retrieve possibly nonexistent APIC table 2021-10-06 17:11:02 +02:00
Peter Elliott
669b23ac0a Kernel: Handle backspace for tab character in TTY cooked mode
Before, serenity would only backspace one character for a tab.
This is the only feature that my OS has and serenity doesn't.
2021-10-06 12:31:13 +02:00
Idan Horowitz
ce334ee1bc Kernel: Validate x86_64 address canonicality before SafeMem operations
This ensures we don't GP on x86_64 when a non-canonical address is fed
to a safe_foo() operation.
2021-10-05 02:07:43 +02:00
Idan Horowitz
cd975668d6 Kernel: Detect and store the virtual address bit width during CPU init 2021-10-05 02:07:43 +02:00
Brian Gianforcaro
9d17070047 Kernel: Fix copy paste in VirtIO::RNG::class_name()
Ben noticed this copy paste error during code review.

Co-authored-by: Ben Wiederhake <BenWiederhake.GitHub@gmx.de>
2021-10-03 13:36:10 +02:00
Brian Gianforcaro
40a58f1fd4 Kernel: Remove unused partition name API
I was about to convert this to use KString, but then I realized it
wasn't actually used at all, so lets remove it until the day it is
needed.
2021-10-03 13:36:10 +02:00
Brian Gianforcaro
54a2aaaa6f Kernel: Remove now unused StorageDevice constructor 2021-10-03 13:36:10 +02:00
Brian Gianforcaro
70ad18fbcd Kernel: Remove most String usage from storage_name() API
This change is another minor step towards removing `AK::String` from
the Kernel. Instead of dynamically allocating the storage_name we can
instead allocate it via a KString in the factory for each device, and
then push the device name down into the StorageDevice base class.

We don't have a way of doing `AK::String::formatted(..)` with a KString
at the moment, so cleaning that up will be left for a later day.
2021-10-03 13:36:10 +02:00
Brian Gianforcaro
3a945051fc Kernel: Use operator ""sv in all purpose() implementations
Previously there was a mix of returning plain strings and returning
explicit string views using `operator ""sv`. This change switches them
all to standardized on `operator ""sv` as it avoids a call to strlen.
2021-10-03 13:36:10 +02:00
Brian Gianforcaro
5f1c98e576 Kernel: Use operator ""sv in all class_name() implementations
Previously there was a mix of returning plain strings and returning
explicit string views using `operator ""sv`. This change switches them
all to standardized on `operator ""sv` as it avoids a call to strlen.
2021-10-03 13:36:10 +02:00
Brian Gianforcaro
836c22ea13 Kernel: Remove AK::String usage from Storage/StorageManagement.cpp 2021-10-03 13:36:10 +02:00
Brian Gianforcaro
7f88d5058e Kernel: Remove AK::String usage from Storage/IDEChannel.cpp 2021-10-03 13:36:10 +02:00
Nico Weber
2c0d329bf6 Kernel: Make aarch64 UART::print_num() print u64s 2021-10-02 21:23:28 +01:00
Nico Weber
bc213ad7a2 Kernel: Add a Timer class for aarch64
For now, this can only query microseconds since boot.

Use this to print a timestamp every second. This busy-loops
until a second has passed. This might be a good first use of
interrupts soon.

qemu used to not implement this timer at some point, but
it seems to work fine even in qemu now (qemu v 5.2.0).
2021-10-02 21:23:28 +01:00
Brian Gianforcaro
92844a6af6 Kernel: Access Processor static methods statically
SonarCloud flagged this "Code Smell", where we are accessing these
static methods as if they are instance methods. While it is technically
possible, it is very confusing to read when you realize they are static
functions.
2021-10-02 18:16:15 +02:00
Brian Gianforcaro
0223faf6f4 Kernel: Access MemoryManager static functions statically
SonarCloud flagged this "Code Smell", where we are accessing these
static methods as if they are instance methods. While it is technically
possible, it is very confusing to read when you realize they are static
functions.
2021-10-02 18:16:15 +02:00
Nico Weber
6c4392bc50 Prekernel: Better datasheet link for RPi3 2021-10-02 02:01:07 +02:00
Brian Gianforcaro
b90cc1148a Kernel: Switch RTL8168NetworkAdapter::possible_device_name to StringView
There is no need to allocate a `AK::String` for the device name, when
the list of devices is entirely static.
2021-10-01 17:22:17 +00:00
Brian Gianforcaro
2770433d30 Kernel: Convert network adapter names to Kernel::KString
Another step of incremental progress of removing `AK::String` from the
kernel, to harden against OOM.
2021-10-01 17:22:17 +00:00
Liav A
4974727dbb Kernel: Move x86 IO instructions code into the x86 specific folder 2021-10-01 12:27:20 +02:00
Liav A
3e9dfd2e74 Kernel: Remove IO.h include from a bunch of places 2021-10-01 12:27:20 +02:00
Nico Weber
5a951d6258 Kernel: Fix a few typos 2021-10-01 00:51:49 +01:00
Andreas Kling
eeb4f2fa9b Kernel: Exclude userspace heap memory from coredumps by default
When a process with a large heap crashes (e.g WebContent), it gets very
cumbersome to dump out a huge amount of memory.

In the vast majority of cases, we're only interested in generating a
nice backtrace from the coredump, so let's have the kernel skip over
userspace heap regions when dumping memory for now.

This is not ideal, and almost a little bit ugly, but it does make
investigating 500 MiB WebContent crashes significantly easier for now.
2021-09-30 17:54:32 +02:00
Nico Weber
94d0562569 Kernel: Make UART::print_num(0) work on aarch64 2021-09-30 15:38:43 +01:00
Nico Weber
d0c1db5efc Kernel: Zero out .bss contents on aarch64
After building and running

     objcopy -O binary Build/aarch64/Kernel/Prekernel/Prekernel \
                       /media/sdcard/kernel8.img

things start booting on an actual RPi4 :^)

(Assuming the sdcard contains RPi firmware, an empty config.txt,
and no other kernel*.img files).
2021-09-30 15:38:43 +01:00
Rodrigo Tobar
d16131b100 Kernel: Implement getsockopt(SO_TYPE)
This is easy to implement, and is required by some applications like
python's ssl module.
2021-09-30 11:45:24 +02:00
Liav A
ef9b8ff0c7 Kernel/PCI: Remove all macros and replace them with enum classes 2021-09-29 11:24:33 +02:00
Liav A
9d9d57056e Kernel/PCI: Remove Address from enumeration callback
If we need that address, we can always get it from the DeviceIdentifier.
2021-09-29 11:24:33 +02:00
Liav A
a411a44fda Kernel/PCI: Cache interrupt line and interrupt pin of a device
This allows us to remove the PCI::get_interrupt_line API function. As a
result, this removes a bunch of not so great patterns that we used to
cache PCI interrupt line in many IRQHandler derived classes instead of
just using interrupt_number method of IRQHandler class.
2021-09-29 11:24:33 +02:00
Liav A
057f5a12c2 Kernel/PCI: Propagate usage of DeviceIdentifier everywhere
This allows us to remove a bunch of PCI API functions, and instead to
leverage the cached data from DeviceIdentifier object in many places.
2021-09-29 11:24:33 +02:00
Liav A
da327746a2 Kernel: Rename two PCI components
Rename ID => HardwareID, and PhysicalID => DeviceIdentifier.
This change merely does that to clarify what these objects really are.
2021-09-29 11:24:33 +02:00
Liav A
82bb08a15c Kernel/PCI: Cache more details about PCI devices when enumerating them
There's no good reason to fetch these values each time we need them.
2021-09-29 11:24:33 +02:00
Hendiadyoin1
683bf558e4 AK: Add missing AK/Types.h include to VirtIO/Protocol.h
How did this even work?
2021-09-28 03:13:54 +03:00
Liav A
acd44bdcad Kernel/Graphics: Modernize somewhat the code of BochsGraphicsAdapter
Reduce the amount of macros in favor to enum classes.
2021-09-27 16:15:04 +02:00
Liav A
38bddca378 Kernel/Graphics: Ensure we set BGR format of bochs-display if supported
Instead of blindly forcing BGR format on the bochs-display device, let's
ensure we do that only on QEMU bochs-display and not on VirtualBox
graphics adapter too.
2021-09-27 16:15:04 +02:00
Liav A
de1b649783 Kernel/Graphics: Force BGR format when modesetting the bochs-display
By default bochs-display uses the BGR format, but for future-proof
solution, let's force it explicitly to use that format.
2021-09-27 16:15:04 +02:00
Nico Weber
b0858b2a55 Kernel: Fix a typo in a comment 2021-09-27 10:17:52 +02:00
Nico Weber
4c876e88e0 Kernel: Adjust aarch64 linker script
- .text now starts at 0x80000, where an actual (non-qemu) RPi expects
- use magic section name ".text.first" to make sure the linker script
  puts the kernel entry point at the start of the .text section
- remove a few things from the x86 linker script that aren't needed
  for aarch64 (yet?)
2021-09-27 10:17:52 +02:00
Nico Weber
cbdf4b575d Kernel: Move prekernel linker.ld into Arch subdirectories
This moves Kernel/Prekernel/linker.ld unchanged to
Kernel/Prekernel/Arch/aarch64 and Kernel/Prekernel/Arch/x86.
The aarch64 will change in a future commit.

No behavior change.
2021-09-27 10:17:52 +02:00
Nico Weber
54aabb07f9 Kernel: Add UART class for aarch64 2021-09-26 23:14:01 +00:00
Nico Weber
44c787e88b Kernel: Add Mailbox::set_clock_rate() 2021-09-26 23:14:01 +00:00
Nico Weber
fdc86ddae5 Kernel: Add a GPIO class for aarch64
This allows configuring the alternate pin functions and pin
pull up/down states, which is needed for using the UART.
2021-09-26 11:55:51 +02:00
Jelle Raaijmakers
9a6283c524 Kernel: Define PT_READ_I and PT_READ_D
Looking at how these two constants are commonly used in other systems,
we should be able to mimic their behavior using our PT_PEEK constant.

For example, see:
https://man.netbsd.org/NetBSD-6.0.1/i386/ptrace.2
2021-09-23 18:51:21 +02:00
Eric Seifert
8924b1f532 Kernel: Allow PROT_NONE in mmap and mprotect for stack regions
To allow for userspace guard pages (ruby uses this).
Redundant since serenity creates them automatically,
but should be allowed anyway.
2021-09-23 04:14:41 +00:00
Ben Wiederhake
12247fe9b4 Kernel: Use AK::Variant default initialization where appropriate 2021-09-21 04:22:52 +04:30
Ben Wiederhake
de15a6a657 Kernel: Clean up PCI::Device namespace formatting 2021-09-20 16:00:43 +03:00
Idan Horowitz
574a1c522d Kernel: Store device class name as member of VirtIO devices
This ensures we dont try to hold the PCI Access mutex under IRQ when
printing VirtIO debug logs (which is not allowed and results in an
assertion). This is also relatively free, as it requires no allocations
(we're just storing a pointer to the rodata section).
2021-09-19 21:51:03 +02:00
Idan Horowitz
53cf28c47c Kernel: Use StringView literals in VirtIO::determine_device_class()
Since the return type is StringView we can just create them at compile
time and avoid the run-time construction.
2021-09-19 21:51:03 +02:00
Nico Weber
697e6ccb89 Kernel: Add a Mailbox class for aarch64
As a demo, query the firmware version. `Meta/serenity.sh gdb aarch64`
can be used to observe that qemu puts 0x548E1 in x0 in response
to this mailbox message.
2021-09-19 17:45:59 +02:00
Nico Weber
d0b9c7a20b Kernel: Add a MMIO class for aarch64
It doesn't do anything yet except figure out the peripheral base
address.

Very likely belongs in Kernel, not Prekernel, eventually.
2021-09-19 17:45:59 +02:00
Nico Weber
3a24eb323f Kernel: Use new halt() for all our halting needs in aarch64 Prekernel 2021-09-19 17:45:59 +02:00
Nico Weber
0319aa315a Kernel: Add __stack_chk_fail to aarch64 Prekernel init
This is needed for some functions with local variables. We'll grow
such a function soon.
2021-09-19 17:45:59 +02:00
Eric Seifert
edbc5489a8 Kernel: Add support for O_NONBLOCK in pipe syscall
While working on a port, I saw a pipe creation fail due to missing
nonblock support in pipe syscall.
2021-09-19 12:20:16 +02:00
Sahan Fernando
2e079c6d69 Kernel/VirtIO: Remove lazy allocation of VirtIO::Device BAR regions
This fixes a Kernel Panic where the lazy allocation triggers inside an
ISR and grabs a mutex, which isn't allowed when interrupts are
disabled. This also fixes a bug where the mapping for VirtIO device
BARs is never allocated. #9876
2021-09-19 11:46:09 +03:00
Przemysław R. Kusiak
c6e23e45c5 Kernel: Let MouseDevice and KeyboardDevice write method return EINVAL
Currently, writing anything to `/dev/mouse0` or `/dev/keyboard0` causes
the Kernel to panic. The reason for this is that
`[Mouse,Keyboard]Device::write` always returns 0, which is explicitly
prohibited by `VERIFY` macro in `Process::sys$write`.  The fix seems
trivial; `write` should return EINVAL instead (as is the case with, for
example, `KCOVDevice`).
2021-09-18 22:57:42 +03:00
Liav A
23ef46f4f7 Kernel/Net: Enable usage of RTL8168E and RTL8168H in RTL8168 driver
I tested both (version 15 and 30 of the RTL8168 chipset) with PCI-
passthrough of these cards, and they seem to work just fine with the
driver.
2021-09-18 17:49:24 +03:00
Liav A
86fa5d71c0 Kernel/Memory: Add more super pages to satisfy contiguous allocations
When testing the RTL8168 driver, it seems we can't allocate super pages
anymore. Either we expand the super pages range, or find a solution to
dynamically expand the range (or let drivers utilize other ranges).
2021-09-18 17:49:24 +03:00
Liav A
d19bd59e28 Kernel/Storage: Tidy up RamdiskDevice class 2021-09-18 15:05:51 +03:00
Nico Weber
a339b73fc2 Kernel: Don't link Prekernel against kernel_heap
This was added in b5c98ede08, but it looks like a copy-paste
mistake from Kernel/CMakeLists.txt.

Unbreaks building for aarch64.
2021-09-17 17:59:22 +03: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