Commit graph

105 commits

Author SHA1 Message Date
bunnei
a57419b925 Merge pull request #1303 from lioncash/error
kernel/errors: Amend invalid thread priority and invalid processor ID error codes
2018-09-12 12:14:51 -04:00
Lioncash
8bdae1d7ff svc: Return ERR_INVALID_PROCESSOR_ID in CreateThread() if an invalid processor ID is given
This is what the kernel does for an out-of-range processor ID.
2018-09-12 05:20:02 -04:00
Lioncash
d5ec89c1fb kernel/errors: Correct error codes for invalid thread priority and invalid processor ID 2018-09-12 05:19:57 -04:00
Lioncash
4b9e65a70c svc: Do nothing if svcOutputDebugString() is given a length of zero
While unlikely, it does avoid constructing a std::string and
unnecessarily calling into the memory code if a game or executable
decides to be really silly about their logging.
2018-09-12 04:51:44 -04:00
Lioncash
00b69a9527 svc: Correct parameter type for OutputDebugString()
This should be a u64 to represent size.
2018-09-12 04:49:11 -04:00
Lioncash
cd22f4d32e 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
84f855a61d core/core: Replace includes with forward declarations where applicable
The follow-up to 88597535d6, which
replaces most of the includes in the core header with forward declarations.

This makes it so that if any of the headers the core header was
previously including change, then no one will need to rebuild the bulk
of the core, due to core.h being quite a prevalent inclusion.

This should make turnaround for changes much faster for developers.
2018-08-31 16:30:14 -04:00
Lioncash
4913549d6b 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
d99d679e9e svc: Return process title ID if queried in GetInfo()
We already have the variable itself set up to perform this task, so we
can just return its value from the currently executing process instead
of always stubbing it to zero.
2018-08-25 05:02:28 -04:00
Lioncash
9f6aa5cda8 kernel/svc: Log svcBreak parameters
Given if we hit here all is lost, we should probably be logging the
break reason code and associated information to distinguish between the
causes.
2018-08-14 20:54:05 -04:00
bunnei
a1aacf27d7 Merge pull request #1043 from Subv/timing
Use an approximated amortized amount of ticks when advancing timing.
2018-08-12 22:31:55 -04:00
Subv
a063b51094 Kernel/SVC: Don't reschedule the current core when creating a new thread.
The current core may have nothing to do with the core where the new thread was scheduled to run. In case it's the same core, then the following PrepareReshedule call will take care of that.
2018-08-12 20:38:37 -05:00
Subv
8f493f43e7 Kernel/Mutex: Don't duplicate threads in the mutex waiter list.
Exit from AddMutexWaiter early if the thread is already waiting for a mutex owned by the owner thread.

This accounts for the possibility of a thread that is waiting on a condition variable being awakened twice in a row.

Also added more validation asserts.

This should fix one of the random crashes in Breath Of The Wild.
2018-08-12 16:35:27 -05:00
Lioncash
ec7319a5de kernel/vm_manager: Use const where applicable
Makes our immutable state explicit.
2018-08-02 12:21:46 -04:00
bunnei
b9d19ca36e Merge pull request #877 from lioncash/remove
kernel: Remove unused object_address_table.cpp/.h
2018-07-31 20:11:39 -07:00
Lioncash
ea4e7b7fc5 kernel: Remove unused object_address_table.cpp/.h
These source files were entirely unused throughout the rest of the
codebase. This also has the benefit of getting rid of a global variable
as well.
2018-07-31 11:03:08 -04:00
Lioncash
3d2d454c36 kernel: Remove unnecessary includes
Removes unnecessary direct dependencies in some headers and also gets
rid of indirect dependencies that were being relied on to be included.
2018-07-31 10:15:17 -04:00
Mat M
2113988e81 Merge pull request #804 from lioncash/log
svc: Log parameters in SetMemoryAttribute()
2018-07-25 14:43:24 -04:00
Lioncash
46a1bbceea svc: Resolve sign comparison warnings in WaitSynchronization()
The loop's induction variable was signed, but we were comparing against
an unsigned variable.
2018-07-24 09:55:17 -04:00
Lioncash
5bd30caa5c svc: Log parameters in SetMemoryAttribute()
Provides slightly more context than only logging out the address value.
2018-07-24 09:46:46 -04:00
Subv
e9639ffafa Kernel/SVC: Perform atomic accesses in SignalProcessWideKey as per the real kernel. 2018-07-22 12:27:24 -05:00
Lioncash
059d0017f1 thread: Convert ThreadStatus into an enum class
Makes the thread status strongly typed, so implicit conversions can't
happen. It also makes it easier to catch mistakes at compile time.
2018-07-19 22:08:56 -04:00
Lioncash
9ee475f731 svc: Correct always true assertion case in SetThreadCoreMask
The reason this would never be true is that ideal_processor is a u8 and
THREADPROCESSORID_DEFAULT is an s32. In this case, it boils down to how
arithmetic conversions are performed before performing the comparison.

If an unsigned value has a lesser conversion rank (aka smaller size)
than the signed type being compared, then the unsigned value is promoted
to the signed value (i.e. u8 -> s32 happens before the comparison). No
sign-extension occurs here either.

An alternative phrasing:

Say we have a variable named core and it's given a value of -2.

u8 core = -2;

This becomes 254 due to the lack of sign. During integral promotion to
the signed type, this still remains as 254, and therefore the condition
will always be true, because no matter what value the u8 is given it
will never be -2 in terms of 32 bits.

Now, if one type was a s32 and one was a u32, this would be entirely
different, since they have the same bit width (and the signed type would
be converted to unsigned instead of the other way around) but would
still have its representation preserved in terms of bits, allowing the
comparison to be false in some cases, as opposed to being true all the
time.

---

We also get rid of two signed/unsigned comparison warnings while we're
at it.
2018-07-19 15:46:17 -04:00
James Rowe
d74d2a77cb Update clang format 2018-07-02 21:45:47 -04:00
James Rowe
e159c550d8 Rename logging macro back to LOG_* 2018-07-02 21:45:47 -04:00
Michael Scire
a3509a9e74 Kernel/Arbiters: Fix casts, cleanup comments/magic numbers 2018-06-22 00:47:59 -06:00
Michael Scire
28fe461cd3 Add additional missing format. 2018-06-21 21:09:51 -06:00
Michael Scire
2a0ea82fec Kernel/Arbiters: Initialize arb_wait_address in thread struct. 2018-06-21 05:13:06 -06:00
Michael Scire
d12af72c8f Kernel/Arbiters: Mostly implement SignalToAddress 2018-06-21 04:10:11 -06:00
Michael Scire
6e9b11ffa0 Kernel/Arbiters: Add stubs for 4.x SignalToAddress/WaitForAddres SVCs. 2018-06-21 00:49:43 -06:00
Subv
cb4ff57322 Build: Fixed some MSVC warnings in various parts of the code. 2018-06-20 11:39:10 -05:00
bunnei
149fef99a0 Merge pull request #572 from Armada651/user-except-stub
svc: Add a stub for UserExceptionContextAddr.
2018-06-18 11:37:13 -04:00
Jules Blok
5614c1329e svc: Add a stub for UserExceptionContextAddr. 2018-06-18 09:29:11 +02:00
Subv
40c82fc9c5 Kernel/SVC: Support special core values -2 and -3 in svcSetThreadCoreMask.
Also added some proper error handling.
2018-05-30 21:36:29 -05:00
Subv
e3e8902d40 Kernel/SVC: Signal the highest priority threads first in svcSignalProcessWideKey. 2018-05-19 16:58:30 -05:00
Subv
8ce8160ce3 Kernel/Threads: Reschedule the proper core when operating on that core's threads. 2018-05-19 16:57:44 -05:00
Subv
8935ca8e11 SVC: Removed unused WaitSynchronization1 function 2018-05-19 16:56:33 -05:00
bunnei
ce7d89cb0e thread: Rename mask to affinity_masks. 2018-05-10 19:34:53 -04:00
bunnei
5a5850af69 threading: Reschedule only on cores that are necessary. 2018-05-10 19:34:52 -04:00
bunnei
9e559ceb09 svc: Implement GetThreadCoreMask and SetThreadCoreMask. 2018-05-10 19:34:51 -04:00
bunnei
7b6dd22605 svc: SignalProcessWideKey should apply to all cores. 2018-05-10 19:34:49 -04:00
bunnei
6c4f161ba2 svc: Implement GetCurrentProcessorNumber. 2018-05-10 19:34:49 -04:00
bunnei
44c565aeca core: Implement multicore support. 2018-05-10 19:34:46 -04:00
Lioncash
1b310cbb3a general: Make formatting of logged hex values more straightforward
This makes the formatting expectations more obvious (e.g. any zero padding specified
is padding that's entirely dedicated to the value being printed, not any pretty-printing
that also gets tacked on).
2018-05-02 09:49:36 -04:00
Lioncash
d1e3e0eb42 string_util: Remove StringFromFormat() and related functions
Given we utilize fmt, we don't need to provide our own functions for formatting anymore
2018-04-29 18:52:33 -04:00
Lioncash
324ee31fc3 general: Convert assertion macros over to be fmt-compatible 2018-04-27 10:04:02 -04:00
Lioncash
bd9414dd31 kernel: Migrate logging macros to fmt-compatible ones 2018-04-25 20:32:09 -04:00
bunnei
5ff201a288 Merge pull request #370 from Subv/sync_primitives
Kernel: Reworked the new kernel synchronization primitives.
2018-04-23 16:33:00 -04:00
Subv
329bec6dbd Kernel: Implemented mutex priority inheritance.
Verified with a hwtest and implemented based on reverse engineering.

Thread A's priority will get bumped to the highest priority among all the threads that are waiting for a mutex that A holds.
Once A releases the mutex and ownership is transferred to B, A's priority will return to normal and B's priority will be bumped.
2018-04-23 11:23:44 -05:00
Subv
f5a2b1920b Kernel: Remove unused ConditionVariable class. 2018-04-20 21:04:33 -05:00