Commit Graph

97 Commits

Author SHA1 Message Date
asynts
dd727d1fec 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-22 22:14:30 +01:00
asynts
67583bc424 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-22 22:14:30 +01:00
asynts
dca6f1f49b 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.Everything:
2021-01-11 11:55:47 +01:00
asynts
938e5c7719 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.Everything:

The modifications in this commit were automatically made using the
following command:

    find . -name '*.cpp' -exec sed -i -E 's/dbg\(\) << ("[^"{]*");/dbgln\(\1\);/' {} \;
2021-01-09 21:11:09 +01:00
Tom
901ef3f1c8 Kernel: Specify default memory order for some non-synchronizing Atomics 2021-01-04 19:13:52 +01:00
Tom
476f17b3f1 Kernel: Merge PurgeableVMObject into AnonymousVMObject
This implements memory commitments and lazy-allocation of committed
memory.
2021-01-01 23:43:44 +01:00
Linus Groh
bbe787a0af Everywhere: Re-format with clang-format-11
Compared to version 10 this fixes a bunch of formatting issues, mostly
around structs/classes with attributes like [[gnu::packed]], and
incorrect insertion of spaces in parameter types ("T &"/"T &&").
I also removed a bunch of // clang-format off/on and FIXME comments that
are no longer relevant - on the other hand it tried to destroy a couple of
neatly formatted comments, so I had to add some as well.
2020-12-31 21:51:00 +01:00
Lenny Maiorani
b2316701a8 Everywhere: void arguments to C functions
Problem:
- C functions with no arguments require a single `void` in the argument list.

Solution:
- Put the `void` in the argument list of functions in C header files.
2020-12-26 10:10:27 +01:00
Liav A
39c1783387 Kernel: Allow to install a real IRQ handler on a spurious one
IRQ 7 and 15 on the PIC architecture are used for spurious interrupts.
IRQ 7 could also be used for LPT connection, and IRQ 15 can be used for
the secondary IDE channel. Therefore, we need to allow to install a
real IRQ handler and check if a real IRQ was asserted. If so, we handle
them in the usual way.

A note on this fix - unregistering or registering a new IRQ handler
after we already registered one in the spurious interrupt handler is
not supported yet.
2020-12-21 00:19:21 +01:00
Lenny Maiorani
765936ebae
Everywhere: Switch from (void) to [[maybe_unused]] (#4473)
Problem:
- `(void)` simply casts the expression to void. This is understood to
  indicate that it is ignored, but this is really a compiler trick to
  get the compiler to not generate a warning.

Solution:
- Use the `[[maybe_unused]]` attribute to indicate the value is unused.

Note:
- Functions taking a `(void)` argument list have also been changed to
  `()` because this is not needed and shows up in the same grep
  command.
2020-12-21 00:09:48 +01:00
Tom
5e08ae4e14 Kernel: Fix counting interrupts
Move counting interrupts out of the handle_interrupt method so that
it is done in all cases without the interrupt handler having to
implement it explicitly.

Also make the counter an atomic value as e.g. the LocalAPIC interrupts
may be triggered on multiple processors simultaneously.

Fixes #4297
2020-12-02 23:19:59 +01:00
Tom
7a4fb5deef Kernel: Don't remap IOAPIC registers every time we try to read/write
Remapping these registers every time we try to read from or write to
them causes a lot of SMP broadcasts and a lot of other overhead.
This improves boot time noticeably.
2020-11-01 10:30:20 +01:00
Tom
8c764319ad Kernel: Various APIC timer fixes 2020-10-26 08:57:25 +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
Andreas Kling
af20b9424f Kernel: Unbreak /proc/interrupts when running with APIC
We can't assert here since these are exposed through /proc JSON.
2020-10-18 14:40:16 +02:00
Andreas Kling
c7a13b7a74 Kernel: Tweak strange PAGE_ROUND_UP(1) in APIC code 2020-10-18 14:18:38 +02:00
Ben Wiederhake
64cc3f51d0 Meta+Kernel: Make clang-format-10 clean 2020-09-25 21:18:17 +02:00
Liav A
82b0171812 Kernel: Fix assertion statement in GenericInterruptHandler
We need to assert if interrupts are not disabled when changing the
interrupt number of an interrupt handler.
Before this fix, any change like this would lead to a crash,
because we are using InterruptDisabler in IRQHandler::change_irq_number.
2020-09-19 16:44:40 +02:00
Luke
68b361bd21 Kernel: Return ENOMEM in more places
There are plenty of places in the kernel that aren't
checking if they actually got their allocation.

This fixes some of them, but definitely not all.

Fixes #3390
Fixes #3391

Also, let's make find_one_free_page() return nullptr
if it doesn't get a free index. This stops the kernel
crashing when out of memory and allows memory purging
to take place again.

Fixes #3487
2020-09-16 20:38:19 +02:00
asynts
ec1080b18a Refactor: Replace usages of FixedArray with Vector. 2020-09-08 14:01:21 +02:00
asynts
9c83d6ff46 Refactor: Replace usages of FixedArray with Array. 2020-09-08 14:01:21 +02:00
Ben Wiederhake
eac3bbdcee Kernel: Unbreak building with extra debug macros, part 1 2020-08-30 09:43:49 +02:00
Liav A
ab87d42200 Kernel: Remove the enabled concept of IRQ handlers
An IRQ handler should always be ready to respond to any IRQ.
We must remember that hardware can generate IRQs without any interaction
from our code at all. Ignoring IRQs in such cases is obviously not the
right thing to do.
2020-08-28 09:16:18 +02:00
Liav A
a431108ab6 Kernel: Add and remove explicit keyword where needed 2020-08-28 09:16:18 +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
8925ad3fa0 Revert "Kernel: Move Singleton class to AK"
This reverts commit f0906250a1.
2020-08-22 16:34:49 +02:00
Andreas Kling
68580d5a8d Revert "AK: Get rid of make_singleton function"
This reverts commit 5a98e329d1.
2020-08-22 16:34:14 +02:00
Tom
5a98e329d1 AK: Get rid of make_singleton function
Just default the InitFunction template argument.
2020-08-22 10:46:24 +02:00
Tom
f0906250a1 Kernel: Move Singleton class to AK 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
Muhammad Zahalqa
8c7b5fb97b
Kernel: Remove unneeded header (#3196)
AK/HashTable.h is not needed from SpuriousInterruptHandler
2020-08-17 22:58:09 +02:00
Brian Gianforcaro
2eae70b097 Kernel: Mark MSIHandler as final 2020-08-10 09:57:50 +02:00
Tom
b02d33bd63 Kernel: Fix some flaws that caused crashes or hangs during boot
We need to halt the BSP briefly until all APs are ready for the
first context switch, but we can't hold the same spinlock by all
of them while doing so. So, while the APs are waiting on each other
they need to release the scheduler lock, and then once signaled
re-acquire it. Should solve some timing dependent hangs or crashes,
most easily observed using qemu with kvm disabled.
2020-07-09 23:24:55 +02:00
Tom
bc107d0b33 Kernel: Add SMP IPI support
We can now properly initialize all processors without
crashing by sending SMP IPI messages to synchronize memory
between processors.

We now initialize the APs once we have the scheduler running.
This is so that we can process IPI messages from the other
cores.

Also rework interrupt handling a bit so that it's more of a
1:1 mapping. We need to allocate non-sharable interrupts for
IPIs.

This also fixes the occasional hang/crash because all
CPUs now synchronize memory with each other.
2020-07-06 17:07:44 +02:00
Andreas Kling
11c4a28660 Kernel: Move headers intended for userspace use into Kernel/API/ 2020-07-04 17:22:23 +02:00
Tom
fb41d89384 Kernel: Implement software context switching and Processor structure
Moving certain globals into a new Processor structure for
each CPU allows us to eventually run an instance of the
scheduler on each CPU.
2020-07-01 12:07:01 +02:00
Tom
0bc92c259d Kernel: Detect APs and boot them into protected mode
This isn't fully working, the APs pretend like they're
fully initialized and are just halted permanently for now.
2020-06-04 18:15:23 +02:00
Andreas Kling
d83d46fd7a Kernel: Remove outdated FIXME in InterruptManagement::locate_apic_data 2020-05-28 10:55:51 +02:00
Andreas Kling
a75c290e51 Kernel: Use TypedMapping for accessing IOAPIC registers 2020-05-23 15:57:48 +02:00
Andreas Kling
59a56a78c0 Kernel: Oops, we need to use map_typed_writable() for write access :^) 2020-05-23 15:50:50 +02:00
Andreas Kling
a04c8d7101 Kernel: Use TypedMappings when looking for APIC information 2020-05-23 15:46:56 +02:00
Andreas Kling
2fe6b3725a Kernel: Use TypedMappings in the very unfinished APIC code 2020-05-23 15:25:43 +02:00
Andreas Kling
8ec8304d74 Kernel: Tweak some suspicious casts in InterruptManagement
This code needs a closer looking-into at some point. It doesn't seem
entirely safe to be casting u32's to pointers like it does.
2020-05-23 15:25:43 +02:00
Andreas Kling
4b847810bf Kernel: Simplify scanning BIOS/EBDA and MP parser initialization
Add a MappedROM::find_chunk_starting_with() helper since that's a very
common usage pattern in clients of this code.

Also convert MultiProcessorParser from a persistent singleton object
to a temporary object constructed via a failable factory function.
2020-05-22 13:36:57 +02:00
Andreas Kling
21d5f4ada1 Kernel: Absorb LibBareMetal back into the kernel
This was supposed to be the foundation for some kind of pre-kernel
environment, but nobody is working on it right now, so let's move
everything back into the kernel and remove all the confusion.
2020-05-16 12:00:04 +02:00
Andreas Kling
03eb0e5638 Kernel: Let's say that IO::delay(N) delays for N microseconds
Supposedly that's how much delay you get when doing I/O on port 0x80.
2020-05-16 10:55:54 +02:00
Shannon Booth
113a95e9e1 Kernel: Annotate UnhandledInterruptHandler::eoi with [[noreturn]] 2020-05-16 09:51:31 +02:00
Andreas Kling
d92f62db43 Kernel: Remove ref-counting from interrupt override metadata
I don't see a reason for these to be reference-counted, and removing it
simplifies a bunch of surrounding data structures.
2020-05-08 21:12:16 +02:00
Liav A
0fa50b6405 Interrupts: Simplify initialization a bit more 2020-04-09 20:45:44 +02:00