Commit Graph

288 Commits

Author SHA1 Message Date
Liav A
65f939b55c Kernel: Keep records of PCI::Address & PCI::ID pairs for enumeration 2020-04-11 10:02:31 +02:00
Liav A
9bb4a6ecf6 Kernel: Create BXVGA device if found in the PCI bus 2020-04-09 23:43:30 +02:00
Liav A
a7c5a1fe69 Kernel: Simplify the Time management initialization 2020-04-09 19:59:53 +02:00
Liav A
8e336798b5 Kernel: Run clang-format on init.cpp 2020-04-09 19:59:53 +02:00
Liav A
8139688ef1 Kernel: Simplify the Interrupt management initialization 2020-04-09 19:59:53 +02:00
Andreas Kling
871d450b93 Kernel: Remove redundant "ACPI" from filenames in ACPI/ 2020-04-09 18:17:27 +02:00
Andreas Kling
1c865ee8d4 Kernel: Merge ACPI::StaticParser into ACPI::Parser
There's no need for StaticParser to be a separate thing from Parser.
2020-04-09 18:15:02 +02:00
Andreas Kling
4644217094 Kernel: Remove "non-operational" ACPI parser state
If we don't support ACPI, just don't instantiate an ACPI parser.
This is way less confusing than having a special parser class whose
only purpose is to do nothing.

We now search for the RSDP in ACPI::initialize() instead of letting
the parser constructor do it. This allows us to defer the decision
to create a parser until we're sure we can make a useful one.
2020-04-09 17:19:11 +02:00
Andreas Kling
95e44a33c1 Kernel: Move ACPI initialization from init.cpp to ACPI::initialize() 2020-04-09 13:39:10 +02:00
Andreas Kling
f25d2f5518 Kernel: Move NetworkTask startup into NetworkTask::spawn() 2020-04-09 13:31:05 +02:00
Andreas Kling
f2ebfb9e4e Kernel: Simplify PCI initialization logic
- Get rid of the PCI::Initializer object which was not serving any real
  purpose or holding any data members.
- Move command line parsing from init to PCI::initialize().
2020-04-08 17:39:17 +02:00
Andreas Kling
5cc09b0245 Kernel: Simplify VMWareBackdoor somewhat
- If there is no VMWare backdoor, don't allocate memory for it.
- Remove the "unsupported" state, instead just don't instantiate.
- Move the command-line parsing from init to the driver.
- Move mouse packet reception from PS2MouseDevice to VMWareBackdoor.
2020-04-08 17:19:46 +02:00
Andreas Kling
e4ab908fe0 Kernel: Move global constructor invocation a bit earlier 2020-04-08 17:19:46 +02:00
Andreas Kling
a066dd1fac Kernel: Move sync and finalization tasks into their own files
Instead of clogging up the initialization sequence, put these tasks
in their own files.
2020-04-08 17:19:46 +02:00
Andreas Kling
befe4c6709 Kernel: Remove DebugLogDevice
This was a cute idea but ultimately it's just not useful since we
already have the dbgputch() and dbgputstr() syscalls.
2020-04-08 17:19:46 +02:00
Andreas Kling
c8087a42fc Kernel: Move more things from init() to init_stage2()
The purpose of init() is to get multi-tasking up and running. We don't
want to do anything in init() that doesn't advance that goal.

This patch moves some things from init() to init_stage2(), and adds a
comment block explaining the split.
2020-04-08 17:19:46 +02:00
Andreas Kling
a7bbfda034 Kernel: Rename KParams => Kernel::CommandLine
Let's make this read more like English.
2020-04-08 17:19:46 +02:00
Andreas Kling
dc7340332d Kernel: Update cryptically-named functions related to symbolication 2020-04-08 17:19:46 +02:00
Liav A
ecee76b741 Kernel: Change Ext2FS to be backed by a file instead of a block device
In contrast to the previous patchset that was reverted, this time we use
a "special" method to access a file with block size of 512 bytes (like
a harddrive essentially).
2020-04-06 15:36:36 +02:00
Andreas Kling
c2a8bbcb59 Revert "Kernel: Change Ext2FS to be backed by a file instead of a block device"
This reverts commit 6b59311d4b.

Reverting these changes since they broke things.
Fixes #1608.
2020-04-03 21:29:03 +02:00
Liav A
6b59311d4b Kernel: Change Ext2FS to be backed by a file instead of a block device
This ensures that we can mount image files as virtual disks without the
need of implementing gross hacks like loopback devices :)
2020-04-02 12:03:08 +02:00
Andreas Kling
c50fbf6da0 Kernel: Remove the floppy driver
Nobody was using this code, and it was not actively worked on, so let's
just not have it. Press F.
2020-03-28 10:09:48 +01:00
Liav A
9db291d885 Kernel: Introduce the new Time management subsystem
This new subsystem includes better abstractions of how time will be
handled in the OS. We take advantage of the existing RTC timer to aid
in keeping time synchronized. This is standing in contrast to how we
handled time-keeping in the kernel, where the PIT was responsible for
that function in addition to update the scheduler about ticks.
With that new advantage, we can easily change the ticking dynamically
and still keep the time synchronized.

In the process context, we no longer use a fixed declaration of
TICKS_PER_SECOND, but we call the TimeManagement singleton class to
provide us the right value. This allows us to use dynamic ticking in
the future, a feature known as tickless kernel.

The scheduler no longer does by himself the calculation of real time
(Unix time), and just calls the TimeManagment singleton class to provide
the value.

Also, we can use 2 new boot arguments:
- the "time" boot argument accpets either the value "modern", or
  "legacy". If "modern" is specified, the time management subsystem will
  try to setup HPET. Otherwise, for "legacy" value, the time subsystem
  will revert to use the PIT & RTC, leaving HPET disabled.
  If this boot argument is not specified, the default pattern is to try
  to setup HPET.
- the "hpet" boot argumet accepts either the value "periodic" or
  "nonperiodic". If "periodic" is specified, the HPET will scan for
  periodic timers, and will assert if none are found. If only one is
  found, that timer will be assigned for the time-keeping task. If more
  than one is found, both time-keeping task & scheduler-ticking task
  will be assigned to periodic timers.
  If this boot argument is not specified, the default pattern is to try
  to scan for HPET periodic timers. This boot argument has no effect if
  HPET is disabled.

In hardware context, PIT & RealTimeClock classes are merely inheriting
from the HardwareTimer class, and they allow to use the old i8254 (PIT)
and RTC devices, managing them via IO ports. By default, the RTC will be
programmed to a frequency of 1024Hz. The PIT will be programmed to a
frequency close to 1000Hz.

About HPET, depending if we need to scan for periodic timers or not,
we try to set a frequency close to 1000Hz for the time-keeping timer
and scheduler-ticking timer. Also, if possible, we try to enable the
Legacy replacement feature of the HPET. This feature if exists,
instructs the chipset to disconnect both i8254 (PIT) and RTC.
This behavior is observable on QEMU, and was verified against the source
code:
ce967e2f33

The HPETComparator class is inheriting from HardwareTimer class, and is
responsible for an individual HPET comparator, which is essentially a
timer. Therefore, it needs to call the singleton HPET class to perform
HPET-related operations.

The new abstraction of Hardware timers brings an opportunity of more new
features in the foreseeable future. For example, we can change the
callback function of each hardware timer, thus it makes it possible to
swap missions between hardware timers, or to allow to use a hardware
timer for other temporary missions (e.g. calibrating the LAPIC timer,
measuring the CPU frequency, etc).
2020-03-19 15:48:00 +01:00
Liav A
425a2ca6ad Init Stage: Allow to boot with smp=on
One can now set the kernel boot argument smp to on, and therefore, to
instruct the kernel to use the IOAPIC instead of the PIC.
2020-03-06 10:32:32 +01:00
Liav A
0fc60e41dd Kernel: Use klog() instead of kprintf()
Also, duplicate data in dbg() and klog() calls were removed.
In addition, leakage of virtual address to kernel log is prevented.
This is done by replacing kprintf() calls to dbg() calls with the
leaked data instead.
Also, other kprintf() calls were replaced with klog().
2020-03-02 22:23:39 +01:00
Liav A
c616eb6aaf Init Stage: Use latest changes
Now we setup interrupts before ACPI, and we don't use the ACPI
parser to find the MADT table anymore.
2020-02-29 00:12:46 +01:00
Liav A
fcb1426a2b Init Stage: Use dbg() instead of dbgprintf() 2020-02-27 13:05:12 +01:00
Liav A
85307dd26e Kernel: Don't use references or pointers to physical addresses
Now the ACPI & PCI code is more safer, because we don't use raw pointers
or references to objects or data that are located in the physical
address space, so an accidental dereference cannot happen easily.
Instead, we use the PhysicalAddress class to represent those addresses.
2020-02-24 11:27:03 +01:00
Liav A
4448597c64 Kernel: Update the init stage to use all the latest changes
gdt_init() and idt_init() will be invoked earlier in the boot process.
Also, setup_interrupts() will be called to setup the interrupt mode.
2020-02-24 11:27:03 +01:00
Andreas Kling
48f7c28a5c Kernel: Replace "current" with Thread::current and Process::current
Suggested by Sergey. The currently running Thread and Process are now
Thread::current and Process::current respectively. :^)
2020-02-17 15:04:27 +01:00
Andreas Kling
a356e48150 Kernel: Move all code into the Kernel namespace 2020-02-16 01:27:42 +01:00
Andreas Kling
6cbd72f54f AK: Remove bitrotted Traits::dump() mechanism
This was only used by HashTable::dump() which I used when doing the
first HashTable implementation. Removing this allows us to also remove
most includes of <AK/kstdio.h>.
2020-02-10 11:55:34 +01:00
Liav A
e559af2008 Kernel: Apply changes to use LibBareMetal definitions 2020-02-09 19:38:17 +01:00
Andreas Kling
88ea152b24 Kernel: Merge unnecessary DiskDevice class into BlockDevice 2020-02-08 02:20:03 +01:00
Liav A
0bce5f7403 Kernel Commandline: Change nopci_mmio to be pci_mmio
Instead of having nopci_mmio, the boot argument now is
pci_mmio='on|off'.
2020-02-05 23:01:41 +01:00
Liav A
8a41256497 Kernel Commandline: Change no_vmmouse boot argument to be vmmouse
Instead of having no_vmmouse, the boot argument now is vmmouse='on|off'.
2020-02-05 23:01:41 +01:00
Liav A
b5857ceaad Kernel Commandline: Remove noacpi & noacpi_aml boot arguments
Instead of having boot arguments like noacpi & noacpi_aml, we have one
boot argument - acpi='on|off|limited'.
2020-02-05 23:01:41 +01:00
Liav A
47978a5828 Kernel: Add support for vmmouse
We add this feature together with the VMWareBackdoor class.
VMWareBackdoor class is responsible for enabling the vmmouse, and then
controlling it from the PS2 mouse IRQ handler.
2020-02-04 19:11:52 +01:00
Liav A
583e9ad372 Kernel: Detect devices when enumerating the PCI bus
Instead of making each driver to enumerate the PCI bus itself,
PCI::Initializer will call detect_devices() to do one enumeration
of the bus.
2020-02-02 00:57:13 +01:00
Liav A
81544dc5b4 Partition Table: Add support for Extended partitions
Now also MBR configurations with extended partitions are supported.
2020-02-02 00:20:41 +01:00
Liav A
5d760bf172 Partition Table: Allow to boot with a partition number higher than 4
This is true currently only to GUID partitions,
Booting with an MBR partition is still limited to partition numbers 1-4.
2020-02-01 17:32:25 +01:00
Andreas Kling
934b1d8a9b Kernel: Finalizer should not go back to sleep if there's more to do
Before putting itself back on the wait queue, the finalizer task will
now check if there's more work to do, and if so, do it first. :^)

This patch also puts a bunch of process/thread debug logging behind
PROCESS_DEBUG and THREAD_DEBUG since it was unbearable to debug this
stuff with all the spam.
2020-02-01 10:56:17 +01:00
Andreas Kling
e64c335e5a Revert "Kernel: Replace IRQHandler with the new InterruptHandler class"
This reverts commit 6c72736b26.

I am unable to boot on my home machine with this change in the tree.
2020-01-22 22:27:06 +01:00
Liav A
6c72736b26 Kernel: Replace IRQHandler with the new InterruptHandler class
System components that need an IRQ handling are now inheriting the
InterruptHandler class.

In addition to that, the initialization process of PATAChannel was
changed to fit the changes.
PATAChannel, E1000NetworkAdapter and RTL8139NetworkAdapter are now
inheriting from PCI::Device instead of InterruptHandler directly.
2020-01-22 12:22:09 +01:00
Liav A
200a5b0649 Kernel: Remove map_for_kernel() in MemoryManager
We don't need to have this method anymore. It was a hack that was used
in many components in the system but currently we use better methods to
create virtual memory mappings. To prevent any further use of this
method it's best to just remove it completely.

Also, the APIC code is disabled for now since it doesn't help booting
the system, and is broken since it relies on identity mapping to exist
in the first 1MB. Any call to the APIC code will result in assertion
failed.

In addition to that, the name of the method which is responsible to
create an identity mapping between 1MB to 2MB was changed, to be more
precise about its purpose.
2020-01-21 11:29:58 +01:00
Andreas Kling
17d4e74518 Kernel: Clean up and reorganize init.cpp
This is where we first enter into the kernel, so we should make at
least some effort to keep things nice and understandable.
2020-01-18 10:24:57 +01:00
Andreas Kling
6fea316611 Kernel: Move all CPU feature initialization into cpu_setup()
..and do it very very early in boot.
2020-01-18 10:11:29 +01:00
Andreas Kling
210adaeca6 ACPI: Re-enable ACPI initialization after paging changes 2020-01-18 10:03:14 +01:00
Andreas Kling
94ca55cefd Meta: Add license header to source files
As suggested by Joshua, this commit adds the 2-clause BSD license as a
comment block to the top of every source file.

For the first pass, I've just added myself for simplicity. I encourage
everyone to add themselves as copyright holders of any file they've
added or modified in some significant way. If I've added myself in
error somewhere, feel free to replace it with the appropriate copyright
holder instead.

Going forward, all new source files should include a license header.
2020-01-18 09:45:54 +01:00
Andreas Kling
e362b56b4f Kernel: Move kernel above the 3GB virtual address mark
The kernel and its static data structures are no longer identity-mapped
in the bottom 8MB of the address space, but instead move above 3GB.

The first 8MB above 3GB are pseudo-identity-mapped to the bottom 8MB of
the physical address space. But things don't have to stay this way!

Thanks to Jesse who made an earlier attempt at this, it was really easy
to get device drivers working once the page tables were in place! :^)

Fixes #734.
2020-01-17 22:34:26 +01:00