Commit Graph

224 Commits

Author SHA1 Message Date
bunnei bf380b8584 hle: kernel: Remove deprecated Object class. 2021-05-05 16:40:52 -07:00
bunnei 626f746971 hle: kernel: Migrate KPort, KClientPort, and KServerPort to KAutoObject. 2021-05-05 16:40:52 -07:00
bunnei 0297448fbc hle: kernel: Migrate KClientPort to KAutoObject. 2021-05-05 16:40:52 -07:00
bunnei b57c5a9b54 hle: kernel: Migrate KResourceLimit to KAutoObject. 2021-05-05 16:40:52 -07:00
bunnei c7d8b7421c hle: kernel: Migrate KTransferMemory to KAutoObject. 2021-05-05 16:40:51 -07:00
bunnei 7444963bbb hle: kernel: Migrate KSession, KClientSession, and KServerSession to KAutoObject. 2021-05-05 16:40:51 -07:00
bunnei 2e8d6fe9a0 hle: kernel: Migrate KReadableEvent and KWritableEvent to KAutoObject. 2021-05-05 16:40:51 -07:00
bunnei cfa7b92563 hle: kernel: Move slab heaps to their own container. 2021-05-05 16:40:51 -07:00
bunnei b6156e735c hle: kernel: Move slab heap management to KernelCore. 2021-05-05 16:40:51 -07:00
bunnei 7ccbdd4d8d hle: kernel: Migrate KProcess to KAutoObject. 2021-05-05 16:40:50 -07:00
bunnei da7e9553de hle: kernel: Migrate more of KThread to KAutoObject. 2021-05-05 16:40:50 -07:00
bunnei 343eaecd38 hle: kernel: k_memory_layout: Derive memory regions based on board layout. 2021-03-21 14:45:13 -07:00
bunnei b1e27890e8 hle: kernel: Migrate MemoryManager to KMemoryManager. 2021-02-18 16:16:25 -08:00
bunnei 65e0178cc0 hle: kernel: Migrate to KMemoryBlock, KMemoryBlockManager, and others. 2021-02-18 16:16:25 -08:00
bunnei 9e520e8f12 hle: kernel: Migrate SlabHeap to KSlabHeap. 2021-02-18 16:16:25 -08:00
bunnei 0d62f30b00 hle: kernel: Rename SharedMemory to KSharedMemory. 2021-02-18 16:16:12 -08:00
Chloe Marcec 3be1a565f8 kernel: Rewrite resource limit to be more accurate
Matches closer to hardware
2021-01-30 20:40:49 +11:00
bunnei 6e953f7f02 hle: kernel: Allocate a dummy KThread for each host thread, and use it for scheduling. 2021-01-28 21:42:26 -08:00
bunnei 1f99f5473c kernel: k_light_lock: Simplify EmuThreadHandle implementation. 2021-01-28 21:42:26 -08:00
bunnei 4782985013 hle: kernel: Move single core "phantom mode" out of KThread.
- This is a workaround that does not belong in a kernel primitive.
2021-01-28 21:42:25 -08:00
bunnei c0d3aef28c core: hle: kernel: Rename Thread to KThread. 2021-01-28 21:42:25 -08:00
bunnei 8a155c4058 hle: kernel: Remove unnecessary AddressArbiter definition. 2021-01-11 14:23:16 -08:00
bunnei 35c3c078e3 core: hle: kernel: Update KSynchronizationObject. 2021-01-11 14:23:16 -08:00
bunnei dfdac7d38a hle: kernel: Move ServiceThread ownership to KernelCore.
- Fixes a circular dependency which prevented threads from being released on shutdown.
2020-12-29 01:12:39 -08:00
bunnei 9e29e36a78 hle: kernel: Rewrite scheduler implementation based on Mesopshere. 2020-12-06 00:03:24 -08:00
bunnei 63fd1bb503 core: arm: Implement InvalidateCacheRange for CPU cache invalidation. 2020-11-29 01:31:52 -08:00
bunnei 7b642c7781 hle: kernel: multicore: Replace n-JITs impl. with 4 JITs. 2020-11-29 01:31:51 -08:00
Lioncash 07d080ecc8 kernel: Add missing include 2020-07-16 13:51:51 -04:00
Fernando Sahmkow 48fa3b7a0f General: Cleanup legacy code. 2020-06-27 11:36:05 -04:00
Fernando Sahmkow 1567824d2d General: Move ARM_Interface into Threads. 2020-06-27 11:35:58 -04:00
Fernando Sahmkow 7020d498c5 General: Fix microprofile on dynarmic/svc, fix wait tree showing which threads were running. 2020-06-27 11:35:48 -04:00
Fernando Sahmkow d494b074e8 Kernel: Preempt Single core on redudant yields. 2020-06-27 11:35:45 -04:00
Fernando Sahmkow ab9aae28bf General: Initial Setup for Single Core. 2020-06-27 11:35:42 -04:00
Fernando Sahmkow e31425df38 General: Recover Prometheus project from harddrive failure
This commit: Implements CPU Interrupts, Replaces Cycle Timing for Host 
Timing, Reworks the Kernel's Scheduler, Introduce Idle State and 
Suspended State, Recreates the bootmanager, Initializes Multicore 
system.
2020-06-27 11:35:06 -04:00
bunnei 8f75524e55 kernel: Initialize memory layout for new VMM. 2020-04-17 00:59:32 -04:00
Fernando Sahmkow d219a96cc8 Kernel: Address Feedback. 2020-02-22 11:18:07 -04:00
Fernando Sahmkow 5c90d22f3d Kernel: Implement Time Manager. 2020-02-22 11:18:07 -04:00
Fernando Sahmkow 179bafa7cb Kernel: Rename ThreadCallbackHandleTable and Setup Thread Ids on Kernel. 2020-02-22 11:18:06 -04:00
Fernando Sahmkow 0728dfef84 Kernel: Make global scheduler depend on KernelCore 2020-02-22 11:18:06 -04:00
Fernando Sahmkow d23d504d77 Kernel: Refactor synchronization to better match RE 2020-02-11 18:47:31 -04:00
Fernando Sahmkow 2d1984c20c System: Address Feedback 2020-01-27 09:54:11 -04:00
Fernando Sahmkow 4d6a86b03f Core: Refactor CPU Management.
This commit moves ARM Interface and Scheduler handling into the kernel.
2020-01-25 18:55:32 -04:00
Lioncash c3e43c7e81 kernel: Remove unnecessary includes
Over the course of the changes to the kernel code, a few includes are no
longer necessary, particularly with the change over to std::shared_ptr
from Boost's intrusive_ptr.
2019-12-07 22:37:05 -05:00
bunnei ec0ce96c56
core_timing: Use better reference tracking for EventType. (#3159)
* core_timing: Use better reference tracking for EventType.

- Moves ownership of the event to the caller, ensuring we don't fire events for destroyed objects.
- Removes need for unique names - we won't be using this for save states anyways.
2019-11-26 21:48:56 -05:00
bunnei 9046d4a548
kernel: Replace usage of boost::intrusive_ptr with std::shared_ptr for kernel objects. (#3154)
* kernel: Replace usage of boost::intrusive_ptr with std::shared_ptr for kernel objects.

- See https://github.com/citra-emu/citra/pull/4710 for details.
2019-11-24 20:15:51 -05:00
Fernando Sahmkow c32520ceb7 Kernel: Reverse global accessor removal. 2019-10-15 11:55:26 -04:00
Fernando Sahmkow 3073615dbc Kernel: Address Feedback. 2019-10-15 11:55:25 -04:00
Fernando Sahmkow e05a8c2385 Kernel: Remove global system accessor from WaitObject 2019-10-15 11:55:16 -04:00
Fernando Sahmkow 57a71f899a Add interfacing to the Global Scheduler 2019-10-15 11:55:07 -04:00
Zach Hilman fc0bf91a96 kernel: Differentiate kernel and user processes when picking ID
This allows kernel internal type processes to be assigned IDs in the KIP range while userland processes are assigned in the user range.
2019-06-10 00:28:33 -04:00
Lioncash cb2bce8006 kernel/svc: Implement svcGetProcessList
This service function simply copies out a specified number of kernel
process IDs, while simultaneously reporting the total number of
processes.
2019-04-02 00:47:14 -04:00
Lioncash bd7ec1a749 kernel/kernel: Remove unnecessary forward declaration
This is no longer necessary, as ResultVal isn't used anywhere in the
header.
2019-03-24 17:48:54 -04:00
Lioncash 8e510d5afa kernel: Make the address arbiter instance per-process
Now that we have the address arbiter extracted to its own class, we can
fix an innaccuracy with the kernel. Said inaccuracy being that there
isn't only one address arbiter. Each process instance contains its own
AddressArbiter instance in the actual kernel.

This fixes that and gets rid of another long-standing issue that could
arise when attempting to create more than one process.
2019-03-07 23:27:51 -05:00
Lioncash c161389a0f kernel/address_arbiter: Pass in system instance to constructor
Allows getting rid of reliance on the global accessor functions and
instead operating on the provided system instance.
2019-03-05 15:47:03 -05:00
Lioncash ec6664f6d6 kernel/address_arbiter: Convert the address arbiter into a class
Places all of the functions for address arbiter operation into a class.
This will be necessary for future deglobalizing efforts related to both
the memory and system itself.
2019-03-05 12:58:26 -05:00
Lioncash bd983414f6 core_timing: Convert core timing into a class
Gets rid of the largest set of mutable global state within the core.
This also paves a way for eliminating usages of GetInstance() on the
System class as a follow-up.

Note that no behavioral changes have been made, and this simply extracts
the functionality into a class. This also has the benefit of making
dependencies on the core timing functionality explicit within the
relevant interfaces.
2019-02-15 21:50:25 -05:00
Lioncash 48d9d66dc5 core_timing: Rename CoreTiming namespace to Core::Timing
Places all of the timing-related functionality under the existing Core
namespace to keep things consistent, rather than having the timing
utilities sitting in its own completely separate namespace.
2019-02-12 12:42:17 -05:00
Lioncash 414cc1eb1f kernel: Remove the Timer class
A holdover from citra, the Horizon kernel on the switch has no
prominent kernel object that functions as a timer. At least not
to the degree of sophistication that this class provided.

As such, this can be removed entirely. This class also wasn't used at
all in any meaningful way within the core, so this was just code sitting
around doing nothing. This also allows removing a few things from the
main KernelCore class that allows it to use slightly less resources
overall (though very minor and not anything really noticeable).
2019-01-31 23:05:15 -05:00
Lioncash 8435451093 kernel/thread: Make thread_id a 64-bit value
The kernel uses a 64-bit value for the thread ID, so we shouldn't be
using a 32-bit value.
2018-12-18 22:37:03 -05:00
Lioncash 9b3a38e3d3 kernel/process: Make process_id a 64-bit value
In the actual kernel, this is a 64-bit value, so we shouldn't be using a
32-bit type to handle it.
2018-12-18 22:28:55 -05:00
Lioncash 5d46038c5c kernel/resource_limit: Clean up interface
Cleans out the citra/3DS-specific implementation details that don't
apply to the Switch. Sets the stage for implementing ResourceLimit
instances properly.

While we're at it, remove the erroneous checks within CreateThread() and
SetThreadPriority(). While these are indeed checked in some capacity,
they are not checked via a ResourceLimit instance.

In the process of moving out Citra-specifics, this also replaces the
system ResourceLimit instance's values with ones from the Switch.
2018-11-19 18:16:39 -05:00
Lioncash 90a981a03a kernel/process: Make the handle table per-process
In the kernel, there isn't a singular handle table that everything gets
tossed into or used, rather, each process gets its own handle table that
it uses. This currently isn't an issue for us, since we only execute one
process at the moment, but we may as well get this out of the way so
it's not a headache later on.
2018-10-20 16:38:32 -04:00
Lioncash 5c0408596f kernel/thread: Use a regular pointer for the owner/current process
There's no real need to use a shared pointer in these cases, and only
makes object management more fragile in terms of how easy it would be to
introduce cycles. Instead, just do the simple thing of using a regular
pointer. Much of this is just a hold-over from citra anyways.

It also doesn't make sense from a behavioral point of view for a
process' thread to prolong the lifetime of the process itself (the
process is supposed to own the thread, not the other way around).
2018-10-10 02:04:55 -04:00
Lioncash 3f17fe7133 core: Migrate current_process pointer to the kernel
Given we now have the kernel as a class, it doesn't make sense to keep
the current process pointer within the System class, as processes are
related to the kernel.

This also gets rid of a subtle case where memory wouldn't be freed on
core shutdown, as the current_process pointer would never be reset,
causing the pointed to contents to continue to live.
2018-09-06 20:52:58 -04:00
Lioncash 1242c1ec0a service: Migrate global named port map to the KernelCore class
Now that we have a class representing the kernel in some capacity, we
now have a place to put the named port map, so we move it over and get
rid of another piece of global state within the core.
2018-09-02 12:35:30 -04:00
Lioncash 0cbcd6ec9a kernel: Eliminate kernel global state
As means to pave the way for getting rid of global state within core,
This eliminates kernel global state by removing all globals. Instead
this introduces a KernelCore class which acts as a kernel instance. This
instance lives in the System class, which keeps its lifetime contained
to the lifetime of the System class.

This also forces the kernel types to actually interact with the main
kernel instance itself instead of having transient kernel state placed
all over several translation units, keeping everything together. It also
has a nice consequence of making dependencies much more explicit.

This also makes our initialization a tad bit more correct. Previously we
were creating a kernel process before the actual kernel was initialized,
which doesn't really make much sense.

The KernelCore class itself follows the PImpl idiom, which allows
keeping all the implementation details sealed away from everything else,
which forces the use of the exposed API and allows us to avoid any
unnecessary inclusions within the main kernel header.
2018-08-28 22:31:51 -04:00
Lioncash 26de4bb521 core/memory: Get rid of 3DS leftovers
Removes leftover code from citra that isn't needed.
2018-08-03 11:22:47 -04:00
Lioncash bf45092c61 kernel: Move object class to its own source files
General moving to keep kernel object types separate from the direct
kernel code. Also essentially a preliminary cleanup before eliminating
global kernel state in the kernel code.
2018-08-01 23:34:42 -04:00
Subv 013778aa21 Qt: Update the WaitTree widget to show info about the current mutex of each thread. 2018-04-20 21:04:34 -05:00
bunnei 8581404482 kernel: Move stack region outside of application heap. 2018-03-16 18:32:23 -04:00
bunnei 67758857e4 hle: Remove Domain and SyncObject kernel objects. 2018-01-24 22:18:54 -05:00
MerryMage e35644c005 clang-format 2018-01-16 18:05:21 +00:00
bunnei bd58c5470c kernel: Increase default stack size to 64K. 2018-01-14 17:20:55 -05:00
bunnei 4236799832 kernel: Rename Semaphore to ConditionVariable. 2018-01-08 21:41:37 -05:00
bunnei e17c0019c5 kernel: Add basic support for Domain object. 2017-12-28 23:30:21 -05:00
James Rowe 61442d6afb Merge pull request #2839 from Subv/global_kernel_lock
Kernel/HLE: Use a mutex  to synchronize access to the HLE kernel state between the cpu thread and any other possible threads that might touch the kernel (network thread, etc).
2017-08-23 18:17:44 -06:00
Subv bca8916cea Kernel/HLE: Use a mutex to synchronize access to the HLE kernel state between the cpu thread and any other possible threads that might touch the kernel (network thread, etc).
This mutex is acquired in SVC::CallSVC, ie, as soon as the guest application enters the HLE kernel, and should be acquired by the aforementioned threads before modifying kernel structures.
2017-08-22 09:30:55 -05:00
Subv 65f19b51c4 Warnings: Add UNREACHABLE macros to switches that contemplate all possible values. 2017-08-21 08:34:28 -05:00
Yuri Kunde Schlesner be031989ee Kernel: Move HandleTable to a separate file 2017-05-29 17:34:39 -07:00
Yuri Kunde Schlesner 64ecf81a3c Kernel: Move WaitObject to a separate file
Now that HandleTable doesn't directly depend on WaitObject anymore, this
can be separated from the main kernel.h header.
2017-05-29 16:16:46 -07:00
Yuri Kunde Schlesner 9453223075 Kernel: Removed HandleTable::GetWaitObject
This isn't necessary anymore since plain Get works correctly for
WaitObjects.
2017-05-29 15:10:06 -07:00
Yuri Kunde Schlesner b17754f998 Kernel: Extract dynamic Object pointer cast into its own function 2017-05-29 14:42:27 -07:00
Yuri Kunde Schlesner 2cdb40d709 Kernel: Centralize error definitions in errors.h 2017-05-24 21:06:00 -07:00
bunnei 84d72fd92f Merge pull request #2397 from Subv/pulse
Kernel: Implemented Pulse event and timers.
2017-01-10 10:45:00 -05:00
Subv e52ca85711 Kernel: Implemented Pulse event and timers.
Closes #1904
2017-01-05 13:06:17 -05:00
Subv b6a0355568 Kernel/Mutex: Update a mutex priority when a thread stops waiting on it. 2017-01-04 15:58:47 -05:00
Subv 7abf185390 Kernel/Mutex: Implemented priority inheritance.
The implementation is based on reverse engineering of the 3DS's kernel.

A mutex holder's priority will be temporarily boosted to the best priority among any threads that want to acquire any of its held mutexes.
When the holder releases the mutex, it's priority will be boosted to the best priority among the threads that want to acquire any of its remaining held mutexes.
2017-01-04 15:58:46 -05:00
Subv e6a7723f2f Kernel: Object ShouldWait and Acquire calls now take a thread as a parameter.
This will be useful when implementing mutex priority inheritance.
2017-01-04 15:58:45 -05:00
bunnei 4fc8b8229e core: Remove HLE module, consolidate code & various cleanups. 2016-12-21 23:48:13 -05:00
bunnei cda7210fad Merge pull request #2260 from Subv/scheduling
Threading: Reworked the way our scheduler works.
2016-12-16 00:41:22 -05:00
Subv 17b29d8865 WaitSynch: Removed unused variables and reduced SharedPtr copies.
Define a variable with the value of the sync timeout error code.

Use a boost::flat_map instead of an unordered_map to hold the equivalence of objects and wait indices in a WaitSynchN call.
2016-12-09 12:23:09 -05:00
Subv 29d809b6e1 Kernel: Remove the Redirection handle type. 2016-12-05 11:13:22 -05:00
Subv 8634b8cb83 Threading: Reworked the way our scheduler works.
Threads will now be awakened when the objects they're waiting on are signaled, instead of repeating the WaitSynchronization call every now and then.

The scheduler is now called once after every SVC call, and once after a thread is awakened from sleep by its timeout callback.

This new implementation is based off reverse-engineering of the real kernel.

See https://gist.github.com/Subv/02f29bd9f1e5deb7aceea1e8f019c8f4 for a more detailed description of how the real kernel handles rescheduling.
2016-12-03 22:38:14 -05:00
Subv 2eceee3a4c Fixed the rebase mistakes. 2016-11-30 23:28:31 -05:00
Subv 0a33d915f8 fixup! Kernel/IPC: Use Ports and Sessions as the fundamental building block of Inter Process Communication. 2016-11-30 23:02:06 -05:00
Subv 073653e858 Kernel/IPC: Use Ports and Sessions as the fundamental building block of Inter Process Communication.
All handles obtained via srv::GetServiceHandle or svcConnectToPort are references to ClientSessions.
Service modules will wait on the counterpart of those ClientSessions (Called ServerSessions) using svcReplyAndReceive or svcWaitSynchronization[1|N], and will be awoken when a SyncRequest is performed.

HLE Interfaces are now ClientPorts which override the HandleSyncRequest virtual member function to perform command handling immediately.
2016-11-30 23:02:05 -05:00
Subv 1323ab2f5f Kernel/Loader: Grab the system mode from the NCCH ExHeader.
3dsx and elf files default to system mode 2 (96MB allocated to the application).

This allows Home Menu to boot without modifications.
Closes #1849
2016-11-19 20:40:04 -05:00
wwylele 85a83158fb move ResetType to kernel.h 2016-09-22 13:52:52 +08:00
wwylele f69a543110 implement wait tree widget 2016-09-22 13:52:52 +08:00
Emmanuel Gil Peyrot ebdae19fd2 Remove empty newlines in #include blocks.
This makes clang-format useful on those.

Also add a bunch of forgotten transitive includes, which otherwise
prevented compilation.
2016-09-21 11:15:47 +09:00