Commit Graph

505 Commits

Author SHA1 Message Date
Billy Laws
5f942e2dff Split VFS implementations from API
This allows better validation and simplified default argument handling.
Could also be useful in the future when we switch to proper VFS error
reporting.
2021-03-06 18:58:04 +05:30
Billy Laws
48acb6d369 Address a bunch of issues detected by clang-tidy 2021-03-06 18:58:04 +05:30
Billy Laws
9d5138bef1 Support Ioctl3 without the inline output buffer
This is used by Project Diva for GET_VA_REGIONS
2021-03-05 23:54:32 +05:30
Billy Laws
c489da610e Add locking to GPU VMM and fix a few codestyle issues
As VMM can be accessed by nvdrv and the GPFIFO thread at the same
time locking is needed to prevent races.
2021-03-05 23:54:32 +05:30
Billy Laws
c1aec00ed1 Rework GPFIFO pushing to optimise performance and accuracy
* Pushbuffer data is now stored in a member buffer to avoid reallocating
  it for each pushbuffer which hampered performance before.
* Don't prefetch pushbuffers as it puts unnecessary load on the guest
  thread that is better suited for the GPFIFO thread.
* Clean up some misc code to avoid pointless casts of a 4 byte object
  and handle GPFIFO control opcodes.
2021-03-05 23:54:32 +05:30
Billy Laws
78cdb1eeb4 Add locking to nvhost-ctrl syncpoint events and sync with switchbrew
NvHostEvents were renamed to SyncpointEvents which is a much clearer
name that more accurately describes them. Locking is needed as IOCTLs
can be called asynchronously and so event registration and signalling
can race.
2021-03-05 23:54:32 +05:30
PixelyIon
c282276b74 Address CR Comments 2 (#132) + Fix Several Scheduler Bugs
The following scheduler bugs were fixed:
* It was assumed that all non-cooperative `Rotate` calls were from a preemptive yield and changed the state of `KThread::isPreempted` incorrectly which could lead to UB, an example of a scenario with it would be:
* * Preemptive thread A gets a signal to yield from cooperative thread B due to it being ready to schedule and higher priority
* * A complies with this request but there's an assumption that the signal was actually from it's preemption timer therefore it doesn't reset it (As it isn't required if the timer was responsible for the signal)
* * A receives the actual preemption signal a while later, causing UB as the signal handler is invoked twice
* `Scheduler::UpdatePriority`
* * A check for `currentIt == core->queue.begin()` existed which caused an incorrect early return 
* * The preemption timer was armed correctly when a priority transition from cooperative priority -> preemption priority occurred but not disarmed when a transition from preemption priority -> cooperative priority occurred
* * The timer was unnecessarily disarmed in the case of updating the priority of a non-running thread, this isn't as much a bug as it is just pointless
* Priority inheritance in `KProcess::MutexLock` is fundamentally broken as it performs UB with `waitThread` being accessed prior to being assigned
* When a thread sets its own priority using  `SvcSetThreadCoreMask` and its current core is no longer in the affinity mask, it wouldn't actually move to the new thread until the next time the thread is load balanced
2021-03-05 14:55:34 +05:30
PixelyIon
fe5061a8e0 Address CR Comments (#132) + Change Core Migration API
This addresses all CR comments including more codebase-wide changes arising from certain review comments like proper usage of its/it's and consistent contraction of it is into it's. 

An overhaul was made to the presentation and formatting of `KThread.h` and `LoadBalance` works has been superseded by `GetOptimalCoreForThread` which can be used alongside `InsertThread` or `MigrateToCore`. It makes the API far more atomic and neater. This was a major point of contention for the design prior, it's simplified some code and potentially improved performance.
2021-03-05 14:55:34 +05:30
PixelyIon
0ea02f2d56 Fix Non-Cooperative Core Migration + Fix yieldWithCoreMigration + Improve Mutex Locking in ConditionalVariableWait
The case of a thread not being in the core queue during a non-cooperative core affinity change would break things as the thread was non-conditionally removed and inserted, this has been fixed by adding a check to see if the thread exists in the core's queue prior to migration. In addition, `yieldWithCoreMigration` was broken by the previous commit as the fallthrough was intentional and removing it cause core migration without a yield which led to breakage in certain circumstances. The mutex locking logic was also improved in `ConditionalVariableWait` to use atomics in a more effective manner with less atomic operations being performed overall.
2021-03-05 14:55:34 +05:30
PixelyIon
0233916489 Increase Code Region Size to 4GiB
The code region's size was previously set at the same value as it is for 36-bit ASes, this value is inadequate for certain larger games and needed to be expanded. We've chosen 4GiB as the new value which should easily encompass all Switch games.
2021-03-05 14:55:34 +05:30
PixelyIon
11c5f50d37 Use likelihood attributes in NCE + Fix System Version + SVC improvements
The SVCs improvements are as follows:
* Make SVC logs more concise for:
* * `SleepThread`
* * `ClearEvent`
* * `CloseHandle`
* * `ResetSignal`
* * `WaitSynchronization` (Special case for single handle)
* * `ArbitrateLock`
* * `ArbitrateUnlock`
* * `WaitProcessWideKeyAtomic`
* * `SignalProcessWideKey`
* Fix unintentional fallthrough into `yieldWithoutCoreMigration` from `yieldWithCoreMigration` in `SleepThread`
* Return `result::InvalidState` when an unsignalled handle is reset in `ResetSignal`
* Return `Result{}` (Success) in `CancelSynchronization`
* Do not return `result::InvalidCurrentMemory` in `ArbitrateLock` as it's not a failure condition
* Make `count` in `WaitProcessWideKeyAtomic` a `i32` from a `u32`, zero and all negative values result in waking all waiters
2021-03-05 14:55:34 +05:30
PixelyIon
1884d98163 Implement Address Arbiter
The entirety of the address arbiter is implemented in this commit, all three arbitration types: `WaitIfLessThan`, `DecrementAndWaitIfLessThan` and `WaitIfEqual`, and all three signal types: `Signal`, `SignalAndIncrementIfEqual` and `SignalAndModifyBasedOnWaitingThreadCountIfEqual` have been implemented. 
This allows any application which uses levent (Light Events) to function which includes titles such as ARMS.
2021-03-05 14:55:34 +05:30
PixelyIon
20bdda6a63 Support Core Migration for Running External Thread
We did not support migration of threads which were running in a non-cooperative manner, this was partially due to the dependence on per-core conditional variables rather than per-thread which made this harder to do programmatically. This has been fixed by moving to per-thread cvars and therefore the limitation can be removed, this feature is used by Unity games.
2021-03-05 14:55:34 +05:30
◱ PixelyIon
861d7e9eb2 Fix SvcClearEvent resetting behaviour
SvcClearEvent previously set the `signalled` flag directly rather than
calling `ResetSignal`, which skipped the locking necessary to make it
globally visible. Switch it to use `ResetSignal` to fix this.
2021-03-05 14:55:34 +05:30
◱ PixelyIon
a621408b9c Move to using ASCII separators for Logger
We've moved to using RS and GS from ASCII as delimiters rather than
'\n' and '|', this allows more robust parsing and increases the
readability of the log files
2021-03-05 14:55:34 +05:30
◱ PixelyIon
31db70f1d4 Lock decryption in CtrEncryptedBacking
This prevents a race where two threads could read at the same time and
end up using the wrong IV leading to garbage data being read. This
caused crashes in several games including Celeste.
2021-03-05 14:55:34 +05:30
Billy Laws
ce0e032255 Avoid constantly signalling audren DSP done event
This was causing a significant amount of sched thrashing and pinning a
core to 100% as games constantly updated audren, now change it to only
signal on buffer release.
2021-03-05 14:55:34 +05:30
◱ PixelyIon
7e7a792dc5 Use per-thread scheduler condvars and clean up AS filters
Per-thread condvars previously caused issues due to an audren bug, now
that's fixed they have a clear performance benefit.
2021-03-05 14:55:34 +05:30
PixelyIon
2bbf526419 Fix Logger Settings + Use Java 8 + Update Kotlin + Extract Native SOs 2021-03-05 14:55:34 +05:30
◱ PixelyIon
80302cf1ad Update NDK, Gradle and dependencies + Improve Settings API + Migrate to PugiXML 2021-03-05 14:55:34 +05:30
◱ PixelyIon
1f48fdd4a5 Fix Thread Insertion Optimization + Revert Per-Thread Scheduler Conditions 2021-03-05 14:55:34 +05:30
◱ PixelyIon
d5d133372f Fix Clean Exiting + Optimize Core Queues + Optimize Thread Insertion + Implement HID SendVibrationValue 2021-03-05 14:55:34 +05:30
◱ PixelyIon
98b1fd9056 Optimize Scheduler/IPC/HID + Fix Various Bugs
* Optimize Scheduler With Per-Thread Scheduler Conditions
* Optimize IPC by yielding
* Optimize HID Vibration
* Fix Priority Inheritance
* Fix `KThread` Start/Kill/Signal Races 
* Fix `YieldPending` Races in `StartThread` & `SvcHandler` 
* Fix POSIX Time -> NN CalendarTime Conversion 
* Fix HID `TouchScreen`/`NPad` Activation
2021-03-05 14:55:34 +05:30
◱ PixelyIon
ef52e22cef Improve Synchronization SVCs + Fix TLS Page Allocation Race + Fix KProcess::GetHandle<KObject> 2021-03-05 14:55:34 +05:30
◱ PixelyIon
ebadc1d1e1 Generate Stack Traces + More Robust Terminate Handler + Exit Process on Signal in Guest 2021-03-05 14:55:34 +05:30
◱ PixelyIon
14dbb5305a Fix Priority Queue + Cooperative Yielding + Conditional Variable Timeouts 2021-03-05 14:55:34 +05:30
◱ PixelyIon
33bbfb9fb7 Implement Conditional Variables 2021-03-05 14:55:34 +05:30
◱ PixelyIon
7079f11add Implement PI-Mutexes + Optimize InsertThread 2021-03-05 14:55:34 +05:30
◱ PixelyIon
7ba7cd2394 Support Priority & Affinity Mask Changes 2021-03-05 14:55:34 +05:30
◱ PixelyIon
f41bcd1e22 Implement Preemptive Scheduling 2021-03-05 14:55:34 +05:30
◱ PixelyIon
cf000f5750 Implement Cooperative Scheduling With Load Balancing 2021-03-05 14:55:34 +05:30
◱ PixelyIon
8564edcb16 Address CR Comments #2 2020-11-23 11:44:43 +05:30
◱ PixelyIon
fbf9f06244 Address CR Comments + Fix Clock Rescaling 2020-11-22 23:56:17 +05:30
◱ PixelyIon
a3dd759a1c Fix Circular Queue Destructor + Memory Infos + Improve Priority Documentation 2020-11-22 23:56:17 +05:30
Billy Laws
7167393e3c Only initialise maxEntry for active input devices
This caused the menus in Sonic Mania to be nonfunctional, futhermore,
default init is not ran for the input structs so the default max
definition in CommonHeader never actually applied.
2020-11-22 23:56:17 +05:30
◱ PixelyIon
bc5c094860 Fix CircularQueue + NPDM ACI0 & Kernel Capability Parsing 2020-11-22 23:56:17 +05:30
◱ PixelyIon
a5927c5c7b Fix Native-Initiated Exiting 2020-11-22 23:56:17 +05:30
◱ PixelyIon
d155e9cd71 Complete Exceptional Signal Handler Implementation + Fix More Destruction Behavior 2020-11-22 23:56:17 +05:30
Billy Laws
8bf08ed66f Fix CircularQueue and improve debug logging + exefs loading
CircularQueue was looping around too early resulting in the wrong
pushbuffers being used. The debug logging is useful for interpreting the
GPU method call logs.

Exefs loading was changed to check if an NSO exists before trying to
read it, preventing exceptions that get annoying while debugging.
2020-11-22 23:56:17 +05:30
Billy Laws
c161ef0cac Various accuracy improvements in services
* 'Fix' memory accounting to not measure reserved regions
* Fix some copy bugs introduced by switch to span
* Correct remap the behaviour of Modify so it actually works
2020-11-22 23:56:17 +05:30
Billy Laws
c7e5202042 Rework GPU VMM variable naming 2020-11-22 23:56:17 +05:30
Billy Laws
4c9d453008 Update formatter config for new AS and reformat 2020-11-22 23:56:17 +05:30
◱ PixelyIon
668f623256 Implement Exceptional Signal Handler + Fix Destruction Behavior
An exceptional signal handler allows us to convert an OS signal into a C++ exception, this allows us to alleviate a lot of crashes that would otherwise occur from signals being thrown during execution of games and be able to handle them gracefully.
2020-11-22 23:56:17 +05:30
◱ PixelyIon
3cde568c51 Run Guest on Main Emulator Thread + Remove Mutex/GroupMutex + Introduce PresentationEngine 2020-11-22 23:56:17 +05:30
◱ PixelyIon
779884edcf Introduce TID to Logger + Fix VMM Bug + Fix NSO Backtrace + Improve Logger 2020-11-22 23:56:17 +05:30
Billy Laws
39f0345ac7 Fix bugs introduced by refactoring
GPU VMM was mistakenly checking the alignment of the PA rather than the
VA and NvMap::Free was not accounting for the handle index starting from
one.
2020-11-22 23:56:17 +05:30
◱ PixelyIon
c65c91e1bc Implement NPDM, Core Mask SVCs + Fix VMM bug + Introduce Verbose Log Level 2020-11-22 23:56:17 +05:30
◱ PixelyIon
324381908b Implement SvcMap/UnmapPhysicalMemory + Fix W-Register Writing + Improve Accuracy of SvcGetInfo 2020-11-22 23:56:17 +05:30
◱ PixelyIon
657beea070 JVM Auto-Attach + Fix Thread Exiting + Fix Thread Signal Handler 2020-11-22 23:56:17 +05:30
◱ PixelyIon
6f2cd41470 Move .patch to start of executable (Pre-Patching) 2020-11-22 23:56:17 +05:30
◱ PixelyIon
369bd469f6 Dynamic Guest Memory Base Allocation 2020-11-22 23:56:17 +05:30
◱ PixelyIon
cffbfc8034 Skip Saving Callee-Saved Registers + Fix GetMemoryObject 2020-11-22 23:56:17 +05:30
Billy Laws
31efb5e930 Correct an NSO loader bug and use the correct address space extents 2020-11-22 23:56:17 +05:30
Billy Laws
17feb68eb5 Fix audren voice sample copying 2020-11-22 23:56:17 +05:30
◱ PixelyIon
745ea19f42 Use u64s for FmtCast + Remove Functional Casts + Fix VMM Bugs 2020-11-22 23:56:17 +05:30
◱ PixelyIon
1db76dee1e NCE3: In-Process Guest Execution 2020-11-22 23:56:17 +05:30
◱ PixelyIon
90127740f0 Rework NCE/KThread/KProcess + Remove Guest Process 2020-11-22 23:56:17 +05:30
◱ PixelyIon
878cb24389 Make fmt::ptr implicit for raw pointers + Update Submodules 2020-11-22 23:56:17 +05:30
◱ PixelyIon
02f3e37c4f Remove KProcess Memory Functions 2020-11-22 23:56:17 +05:30
◱ PixelyIon
60e82e6af0 Rework VMM + Adapt KMemory Objects to be in-process
Note: This commit isn't functional on it's own, it will require the rest of NCE3 to work
2020-11-22 23:56:17 +05:30
Willi Ye
7b13f2d387 Add visibility toggle for osc 2020-11-12 22:19:55 +05:30
Willi Ye
f479aeb4ac Add comments 2020-11-12 22:19:55 +05:30
Willi Ye
7526a985fb Use property delegate to handle preferences
* Add option to disable joystick recentering
2020-11-12 22:19:55 +05:30
Willi Ye
5c4aa95da6 Add on screen controls layout edit settings 2020-11-12 22:19:55 +05:30
Willi Ye
22140defae Rewrite adapter to handle any layout 2020-11-12 22:19:55 +05:30
Willi Ye
e023dbbf0a Add joystick press and general clean up 2020-11-12 22:19:55 +05:30
Willi Ye
3057e4b29a Add on screen controls
* Fix missing default constructor for dialog fragments
2020-11-12 22:19:55 +05:30
Billy Laws
85d5dd3619
Extend NvServices and implement IDirectory (#107)
* Fix alignment handling in NvHostAsGpu::AllocSpace

* Implement Ioctl{2,3} ioctls

These were added in HOS 3.0.0 in order to ease handling ioctl buffers.

* Introduce support for GPU address space remapping

* Fix nvdrv and am service bugs

Syncpoints are supposed to be allocated from ID 1, they were allocated
at 0 before. The ioctl functions were also missing from the service map

* Fix friend:u service name

* Stub NVGPU_IOCTL_CHANNEL_SET_TIMESLICE

* Stub IManagerForApplication::CheckAvailability

* Add OsFileSystem Directory support and add a size field to directory entries

The size field will be needed by the incoming HOS IDirectory support.

* Implement support for IDirectory

This is used by applications to list the contents of a directory.

* Address feedback
2020-11-03 15:10:42 +05:30
◱ PixelyIon
7ad86ec46f Improve span::as_string and other minor fixes 2020-10-02 15:28:48 +00:00
◱ PixelyIon
97ac45d83b Update Logger to use NDK Logger APIs + Improve Backing API + Fix FDSAN issues 2020-10-02 15:28:48 +00:00
◱ PixelyIon
4070686897 Refactor Comments + Other Minor Fixes 2020-10-02 15:28:48 +00:00
◱ PixelyIon
429af1990a Equal -> Brace Initializer + Remove Constexpr Auto for Integers 2020-10-02 15:28:48 +00:00
◱ PixelyIon
2764bd7c96 Use Vector for Kernel Handles + Remove Redundant Includes 2020-10-02 15:28:48 +00:00
◱ PixelyIon
20559c5dca Introduce Custom Span Class + IPC Buffer -> Span 2020-10-02 15:28:48 +00:00
◱ PixelyIon
4d6ae9aa26 Constexpr Maps for Service Functions 2020-10-02 15:28:48 +00:00
◱ PixelyIon
157c54f918 Implement a few HID Functions + Fix FAB handler 2020-10-02 15:28:48 +00:00
◱ PixelyIon
4970e58999 Address CR Comments (#102) 2020-09-20 20:07:33 +00:00
◱ PixelyIon
bb2c31264d Implement IOCTL2 & IOCTL3 2020-09-20 20:07:33 +00:00
◱ PixelyIon
a5fece8020 NVDRV IOCTL Refactor
Buffer -> Span + All buffers as arguments + Return -> NvStatus + Print Service Names + Function Names
2020-09-20 20:07:33 +00:00
◱ PixelyIon
70d67ef563 Constexpr Maps for NvDevice IOCTLs 2020-09-20 20:07:33 +00:00
◱ PixelyIon
20253a9573 Improve NvDevice Registration + Access 2020-09-20 20:07:33 +00:00
◱ PixelyIon
4cc3a3b2e8 Move NVDRV + IHOSBinder Internals to Discrete Components + Fix Lint 2020-09-20 20:07:33 +00:00
◱ PixelyIon
5f0073dd87 Fix Surface Deswizzling OOB writes + Fix PL README 2020-09-20 20:07:33 +00:00
Willi Ye
4076d84efc
NCA decryption (#99)
* NCA decryption
* Remove unnecessary new lines
* Remove loader error dialog
* Always show ROMs
* Address CRs
* Add subtitle padding in grid mode
2020-09-14 19:23:40 +05:30
◱ PixelyIon
65019375ca Implement Guest Touch-Screen Support 2020-09-08 12:55:33 +00:00
Billy Laws
89718804d0 Refactor service functions to return result codes 2020-09-06 19:12:18 +00:00
Billy Laws
74a150dff1 Rework service API to be cleaner with significantly less boilerplate
This patch reduces the burden of adding services significantly, rather
than having to create an enum entry and add strings in the constructor
it will all be determined at runtime through RTTI. A macro is also used
in the service creation case to reduce clutter.
2020-09-06 19:12:18 +00:00
◱ PixelyIon
21e2c826a1 Improve Accuracy of Vibration + Unify Translation + Add Comments 2020-09-06 15:31:20 +00:00
◱ PixelyIon
1a58a2e967 Implement Rumble Support for Controllers and Device Vibrators 2020-09-06 15:31:20 +00:00
Billy Laws
d8ccdd723e
Refactor Audio + Fix NV Bugs (#92)
* Fix NvHostCtrl:EventSignal event ID parsing
* Divide the audout buffer length by the sample size
* Correct audout channel quantity handling
* A few bugfixes for audio tracks
* * Correctly lock in CheckReleasedBuffers and only call the callback once
* * Check if the identifier queue is empty before accessing it's iterator
* Refactor audio to better fit the codestyle
* Explictly specify reference when using GetReference
* Fix CheckReleasedBuffers
2020-08-21 18:58:47 +05:30
◱ PixelyIon
7290a80c3e Move to Callback for Input Initialization + ConditionalVariable for Surface 2020-08-21 11:48:29 +00:00
◱ PixelyIon
07c2f2d891 Significantly Improve Accuracy of HID
This commit significantly increases the accuracy of the prior HID code due to testing on the Switch. It is now fully accurate in all supported scenarios, them being assignment mode, orientation, color writes and system properties. In addition, review comments were addressed and fixed in the PR.
2020-08-21 11:48:29 +00:00
◱ PixelyIon
ee2fdbdf6a Fix Joy-Con Pair Crash + Implement More HID Service Functions
This fixes a Joy-Con Pair bug which caused a crash when a partner device was set to none while being set as a partner. In addition, the following HID service functions were implemented:
* GetSupportedNpadStyleSet
* ActivateNpadWithRevision
* GetNpadJoyHoldType
* AcquireNpadStyleSetUpdateEventHandle
2020-08-21 11:48:29 +00:00
◱ PixelyIon
6a931b95b0 Implement C++ Support for Controller Configuration
This commit adds support to the C++ end of things for controller configuration. It isn't targeting being 1:1 to HOS for controller assignment but is rather based on intuition of how things should be.
2020-08-21 11:48:29 +00:00
◱ PixelyIon
75d485a9a7 Addition of Controller Configuration UI
This commit adds in the UI for Controller Configuration to Settings, in addition to introducing the storage and loading of aforementioned configurations to a file that can be saved/loaded at runtime. This commit also fixes updating of individual fields in Settings when changed from an external activity.
2020-08-21 11:48:29 +00:00
◱ PixelyIon
8e1f8ae7e9 Make UI fully usable using a controller
This commit focuses on making the UI completely usable using a controller so that a user won't have to switch between their device's touch screen and a controller constantly.
2020-08-21 11:48:29 +00:00
◱ PixelyIon
102f26d08e Refactor C++ Input
This commit refactors the C++ end of Input so it'll be in line with the rest of the codebase and be ready for the extension with multiple players and controller configuration.
2020-08-21 11:48:29 +00:00
◱ PixelyIon
5fec7eefd0 Refactor HID Shared Memory
This commit refactors and reorders a lot of the HID Shared Memory from the previous commits to be in line with the rest of the codebase.
2020-08-21 11:48:29 +00:00
Billy Laws
b167abcdb7 Initial Kotlin Input Implementation
This commit contains the Kotlin side of the initial Input implementation, this is based on the work done in the `hid` branch in `bylaws/skyline`.
Co-authored-by: ◱ PixelyIon <pixelyion@protonmail.com>
2020-08-21 11:48:29 +00:00
Billy Laws
0219eda2db Initial C++ Input Implementation
This commit contains the C++ side of the initial Input implementation, this is based on the work done in the `hid` branch in `bylaws/skyline`.
Co-authored-by: ◱ PixelyIon <pixelyion@protonmail.com>
2020-08-21 11:48:29 +00:00
Billy Laws
817d37600e Convert all make all hex uppercase according to codestyle 2020-08-15 10:21:41 +00:00
Billy Laws
e5264f7762 Address review comments 2020-08-15 10:21:41 +00:00
Billy Laws
ae131502c6 Fix reservation in GPU VMM
Rather than reserving a region so it *can* be used by MapAllocate
reserved actually prevents a region from being used by MapAllocate.
2020-08-15 10:21:41 +00:00
Billy Laws
ade8a711fb Format code and misc cleanup 2020-08-15 10:21:41 +00:00
Billy Laws
fcae5d54da Switch NvHostCtrlGpu to use QueryEvent 2020-08-15 10:21:41 +00:00
Billy Laws
cf60869fac Stub INotificationService 2020-08-15 10:21:41 +00:00
Billy Laws
9d90cd877c Stub IFile:Flush 2020-08-15 10:21:41 +00:00
Billy Laws
c69efed2ad Implement GetAccumulatedSuspendedTickChangedEvent 2020-08-15 10:21:41 +00:00
Billy Laws
6c9e0a943c Add some IApplicationFunctions calls used by newer games 2020-08-15 10:21:41 +00:00
Billy Laws
9e39cbaf7b Implement GetBase in IProfile 2020-08-15 10:21:41 +00:00
Billy Laws
dc6da8303e Add support for listing users in account services 2020-08-15 10:21:41 +00:00
Billy Laws
cae270a174 Use nvhost fences in IHOSBinderDriver 2020-08-15 10:21:41 +00:00
Billy Laws
94d1b40faf Add an empty ISslContext service 2020-08-15 10:21:41 +00:00
Billy Laws
7503496bb0 Implement the basis of the Maxwell 3D engine together with a macro
interpreter.

The Maxwell 3D engine handles all 3D rendering, currently only non
rendering related methods are implemented. Macros are small pieces of
code that run on the GPU and allow methods to be quickly called for
things like instanced drawing.
2020-08-15 10:21:41 +00:00
Billy Laws
68d5a48df1 Implement syncpoints and nvhost events and fix an nvmap bug
These are used to allow the CPU to synchronise with the GPU as it
reaches specific points in its command stream.

Also fixes an nvmap bug where a struct was incorrect.
2020-08-15 10:21:41 +00:00
Billy Laws
ed3ff862f6 Extend GPU VMM with unmapping/remapping support + code cleanup 2020-08-15 10:21:41 +00:00
Billy Laws
cf468c20e2 Extend the GPFIFO implementation with support for engines and fix a few
bugs

An engine is effectively a HW block in the GPU, the main one is the
Maxwell 3D which is used for 3D graphics. Engines can be bound to
individual subchannels and then methods within them can be called
through pushbuffers.

The engine side of the GPFIO is also included, it currently does nothing
but will need to be extended in the future with semaphores.
2020-08-15 10:21:41 +00:00
Billy Laws
9fd0dd848b Add support for processing GP Entries and the pushbuffers they contain
This is the backbone of the GPU, in the future this will be expanded to
support calling into engines.
2020-08-15 10:21:41 +00:00
Billy Laws
8dc9a10324 Implement the host side of host1x syncpoints
This will be extended in the future to support interfacing with the GPU.
2020-08-15 10:21:41 +00:00
Billy Laws
3c5cc33a34 Minor bug fixes in GPU VMM and add support for reading 2020-08-15 10:21:41 +00:00
Billy Laws
78712712c7 Fix a few bugs in CreateStrayLayer 2020-08-15 10:21:41 +00:00
Billy Laws
6edf89b538
Initial Savedata Implementation (#75)
* Rework VFS to support creating and writing files and introduce OsFileSystem
OsFileSystem abstracts a directory on the device using the filesystem API.
This also introduces GetEntryType and changes FileExists to use it.

* Implement the Horizon FileSystem APIs using our VFS framework
Horizon provides access to files through its IFileSystem class, we can
closely map this to our vfs::FileSystem class.

* Add support for creating application savedata
This implements basic savedata creation using the OsFileSystem API. The
data is stored in Skyline's private directory is stored in the same
format as yuzu.
2020-08-09 01:08:51 +05:30
Willi Ye
f72b81fcea
Make sure icons have a 1:1 ratio (#80)
* Make sure icons have a 1:1 ratio
* Use recyclerview padding to increase grid edge margins
* Fix race condition in searching roms
* Use notify insert for adapter
2020-08-08 23:31:21 +05:30
Willi Ye
392a1ac437 account: Remove unnecessary null termination 2020-07-21 18:29:45 +00:00
Willi Ye
1f282af87e More code style aligning
* Null terminate nickname array and correct character limit in settings perference
2020-07-21 18:29:45 +00:00
Willi Ye
93da9f2826 Align code style with project
* Return correct error code for invalid user
* Always return first icon color
2020-07-21 18:29:45 +00:00
Willi Ye
ffb9e743dd Add profile service to support custom usernames 2020-07-21 18:29:45 +00:00
Willi Ye
b86aac26d7 Align with code style and remove unnecessary code 2020-07-21 18:11:43 +00:00
Willi Ye
c3e54d1abf Redesign cards in grid view
* Refactor some classes and clean up
* Refresh style on the fly
2020-07-21 18:11:43 +00:00
Billy Laws
b23779bda1 Implement a block based GPU virtual memory manager
The GPU has it's own seperate address space to the CPU. It is able to
address 40 bit addresses and accesses the system memory. A sorted vector
has been used to store blocks as insertions are not very frequent.
2020-07-17 16:21:34 +00:00
Billy Laws
80e7b82bad Fix the LUT shift in the audio resampler
We do not need to shift back as we use a struct to hold the LUT entries.
2020-07-17 14:30:53 +00:00
Billy Laws
a3a2cb682e Truncate service names to 8 chars maximum 2020-07-17 14:30:53 +00:00
Billy Laws
8684e20a29 Treat GetAudioDeviceServiceWithRevisionInfo as GetAudioDeviceService 2020-07-17 14:30:53 +00:00
Billy Laws
3734599615 Extend the IAudioController implementation with volume stubs
This is used by ARMS.
2020-07-17 14:30:53 +00:00
Billy Laws
4cd7502df2 Implement post 4.0.0 language list features in ISettingsServer 2020-07-17 14:30:53 +00:00
Billy Laws
d1c1fa214c Stub (un)lockExit in ISelfController 2020-07-17 14:30:53 +00:00
Billy Laws
c2fadffe60 Extend time services with support for the steady clock
The steady clock has a fixed timepoint that can not change while an
application is running.
2020-07-17 14:30:53 +00:00
Billy Laws
e3313ae731 Use the device sample rate when creating an audio track in audren 2020-07-17 14:30:53 +00:00
Willi Ye
27d7839bcb MainActivity: Fix snackbar overlapping FABs 2020-07-14 09:15:57 +00:00
Willi Ye
c69e72a12e services: Add missing audio functions
* Those are needed to run playtone and audren from switch homebrew examples
2020-07-13 21:14:57 +01:00
Willi Ye
118b4d8a43 MainActivity: Fix shadows of FABs
* Don't cut them off
2020-07-09 20:19:55 +01:00
Billy Laws
6548d4914d Implement IAudioDevice for accessing audio output properties
This is used by Super Mario Odyssey in its init routine.
2020-07-09 18:42:36 +00:00
Billy Laws
f71b54b901 Stub SetRestartMessageEnabled in ISelfController
This is used by Super Mario Odyssey.
2020-07-09 18:42:36 +00:00
Billy Laws
2b4adee213 Stub gameplay recording and save data checking functions
Gameplay recording does not need to be emulated and EnsureSaveData isn't
necessary for proper save data support.
2020-07-09 18:42:36 +00:00
Billy Laws
2e60b5e60d Stub play reporting services 2020-07-09 18:42:36 +00:00
Billy Laws
378e494d82 Add an empty ssl service implementation
This stubs a single function that is needed for SMO's init.
2020-07-09 18:42:36 +00:00
Billy Laws
a2c6a2a4ff Add a base socket (bsd) services implementation
This stubs enough to pass SMO's socket init.
2020-07-09 18:42:36 +00:00
Billy Laws
2aefb4ae84 Implement network interface services
nifm:u is used by applications to enable a connection to the network.
2020-07-09 18:42:36 +00:00
Billy Laws
7102fa910e Implement nfp services 2020-07-09 18:42:36 +00:00
Billy Laws
4cf7f9288e Add an empty friend service implementation
This is used to access a users friends. It is used by Super Mario
Odyssey.
2020-07-09 18:42:36 +00:00
Billy Laws
ff5dddbd5b Extend account services to support BAAS and some user operations
These are needed by Super Mario Odyssey and several other games.
2020-07-09 18:42:36 +00:00
Billy Laws
80270637c1 Fix the spacing on lm log messages 2020-07-09 18:42:36 +00:00
Billy Laws
dae799dbb5 Implement svcClearEvent
This removes a signal from a KEvent. It is used by Mario Odyssey.
2020-07-09 18:42:36 +00:00
Billy Laws
92e3f84242 Stub SetGraphicsFirmwareMemoryMarginEnabled
This is used by most retail games released after 3.0.
2020-07-09 18:42:36 +00:00
Billy Laws
ef9760570b Extend parental control services 2020-07-09 18:42:36 +00:00
◱ PixelyIon
180ba97440 Print the sleep duration before actually sleeping 2020-07-09 14:08:58 +00:00
Billy Laws
c708c353e3 Fix block insertion
The subtraction was the wrong way round causing an underflow.
2020-07-09 14:08:58 +00:00
Billy Laws
1383e17341 Mark CodeStatic regions that are writable as CodeMutable instead
This is required for applications that attempt to map from the bss.
2020-07-09 14:08:58 +00:00
Billy Laws
2f8a217204 Use the heap size rather than the heap address when calculating the
total memory usage

Without this fix allocations are broken in Puyo Puyo Tetris.
2020-07-09 14:08:58 +00:00
Billy Laws
f1a28f7a1c Fix the behaviour of svcQueryMemory and allow getting the extents of
unmapped regions

svcQueryMemory will return a valid descriptor for anything in the
address space, from 0 to 1 << addrSpaceBits, this was handled
incorrectly before and we were only returning descriptors if the
address was in a mapped region.

If an address in an unmapped region is requested then the extents of the
unmapped region up to the address space end are returned. If the address
requested is outside of the address space then the extents of the
inaccessible address space are returned.

To facilitate this support was added to MemoryManager::Get for
generating the extents of unmapped regions using the chunk list.
2020-07-09 14:08:58 +00:00
Billy Laws
670a80d2c4 Create a memory chunk for the stack shared memory
As the stack is automatically mapped in the guest by `clone` we do not
need to explicitly map it. This adds a flag to solve the issue.

Also mark the stack as stack rather than reserved.
2020-07-09 14:08:58 +00:00
Billy Laws
7884a60679 Make regions public members of the memory class and drop the type enum
There isn't really much benefit in having a getter or an enum, so drop
it.
2020-07-09 14:08:58 +00:00
Billy Laws
eadc016525 Lock the audio buffer lock when reading released buffers
This is required to prevent races in Puyo Puyo Tetris and potentially
other games.
2020-07-09 14:08:58 +00:00
Billy Laws
6329537a9e Correct audren event handling and zero the sample buffer
Not zeroing the sample buffer causes issues when a voice is started but
is playing no samples. The system event handling was also reworked
according to Thog's info.
2020-07-09 14:08:58 +00:00
Billy Laws
24d086cbec Correctly check the usage bits in DequeueBuffer and fix it's result
The extra parameters in result are required for retail games to accept
it as valid.
2020-07-09 14:08:58 +00:00
Billy Laws
a96b8eb7a3 Add vi:u and vi:s to service list and fix the result parcel type of OpenLayer
vi:u is used by user applications and games and it has the same api as
vi:m.
2020-07-09 14:08:58 +00:00
◱ PixelyIon
9ef25a6beb IPC bug fixes
This fixes two bugs in IPC that were discovered when running Puyo Puyo
Tetris.

The CloneCurrentObject control IPC will now correctly return the handle
of the newly created object through move handles, rather than pushing it
as a result.

The size array of u16s with the sizes of each C buffer is now taken into
account when reading them. Before this change C buffers were entirely
broken.
2020-07-09 14:08:58 +00:00
Billy Laws
6e074d596c Extend applet manager services for the library applet
This commit adds stubs for the library applet and adds support for
writing to an AM IStorage.
2020-07-09 13:57:28 +00:00
Billy Laws
30936ce6dc Implement an ADPCM decoder for audren
This is used by many retail games, it only supports mono sound.

This implementation is based on Ryu's.
2020-07-09 13:56:04 +00:00
Billy Laws
b1e15efbab Use new android R APIs for hiding insets 2020-07-08 20:11:55 +00:00
Billy Laws
012be0adae Fix some warnings produced by enabling -Wall 2020-07-08 20:11:55 +00:00
Billy Laws
af709efb15 Kotlin updates for compatibility with the Android R SDK preview 2020-07-08 20:11:55 +00:00
Billy Laws
68fcb2e4e5 Extend account services and add support for PopLaunchParameters
This is needed for Puyo Puyo Tetris.
2020-07-07 16:21:13 +00:00
Billy Laws
ff1c0e254f Add an empty account services implementation
This implements the base account service and stubs
InitializeApplicationInfoV0 which is used by Puyo Puyo Tetris. Support
for the entirety of account services will be added in the future.
2020-07-06 21:04:31 +01:00
Billy Laws
3a343d3a48 Implement log services (lm)
lm is used by applications to print messages to the system log. Log
messages are made up of a header and then several fields containing
metadata or string messages.
2020-07-06 19:59:26 +00:00
Billy Laws
8985fe705f Implement IStorage services in Applet Manager
In the case of am, IStorage is used to exchange buffers of data such
as application launch parameters or an applets result. It has no
relation to fsp-srv's IStorage.
2020-07-06 19:57:00 +00:00
Billy Laws
162df93870 Add an empty pctl implementation
This is required by Puyo Puyo Tetris. It may be stubbed further if
needed in the future.
2020-07-06 20:46:38 +01:00
Billy Laws
23d6b596b2 Add an empty aoc:u implementation
This is required by Puyo Puyo Tetris, it will be extended in the future
to allow using real DLC with the emulator.
2020-07-06 19:43:17 +00:00
Billy Laws
4a88adafb6 Implement the set service together with GetAvailableLanguageCodes
The 'set' service is used to obtain user settings such as language.
This is used by Puyo Puyo Tetris.
2020-07-06 19:17:20 +00:00
Billy Laws
801382e43a Implement pl:u for accessing shared fonts
Fonts are stored in an array of TTF data with an 8 byte header
containing a magic and an XOR'd length. Instead of requiring users to
provide original Nintendo fonts we pack open source replacements.
They are generated with the scripts here
https://github.com/FearlessTobi/yuzu_system_archives. All the fonts are
licenced under the Open Font or Apache 2 License so we can include them
all freely.
2020-07-06 19:17:02 +00:00
Billy Laws
45b4811c5b Create adaptive icons for pinned games 2020-07-01 06:24:41 +00:00
Billy Laws
f2c5b96b04 Revert "Use X9 rather than LR when jumping to the guest"
This caused issues loading retail games and will be soon obsoleted by
pre-patching.
This reverts commit f381883c0b.
2020-07-01 06:24:41 +00:00
Billy Laws
a53d6266c7 Implement a basic NSP loader
An NSP (Nintendo Submission Package) is effectively a PFS0 containing
NCAs, there are also tickets and a CNMT file which contains metadata
about updates. The current implementation is very basic and only
support Control and Program NCAs which is enough for loading games.

Support for updates and dlc will be added at a later date.
2020-07-01 06:24:41 +00:00
Billy Laws
a5513bd7e6 Implement an NCA parser and loader
Nintendo Content Archives are used to store the assets, executables
and updates of applications. They support holding either a PFS0 or a
RomFS.

An NCA's ExeFS can be loaded by placing each NSO sequentially into
memory, starting with rtld which will link them together.

Currently only decrypted NCAs are supported, encryption and BKTR
handling will be added at a later time.
2020-07-01 06:24:41 +00:00
Billy Laws
db64f53cfb Implement filesystem backends for RomFS and Partition FS
RomFS is a hierarchial filesystem where each level is made up of a
linked list of files and child directories. It is used in NCAs to store
the applications icon as well as by applications themselves for
accessing assets.

Partition FS encapsulates both the HFS0 found in XCIs and the PFS0 used
for ExeFS images and NSPs, it is purely file based and has no support at
all for directories aside from the root.
2020-07-01 06:24:41 +00:00
Billy Laws
2071796696 Implement basic filesystem support in VFS
This mirrors Horizon's IFileSystem, it will be used by the nsp and nca
loaders to read their content.
https://switchbrew.org/wiki/Filesystem_services#IFileSystem
2020-07-01 06:24:41 +00:00
Billy Laws
e2bd50a1fd Implement a simple directory system in VFS
This mirrors Horizon's IDirectory:
https://switchbrew.org/wiki/Filesystem_services#IDirectory
2020-07-01 06:24:41 +00:00
Billy Laws
7114ad1734 Use the first available language entry in NACPs rather than hardcoding
American English

Without this, if an NACP didn't contain a title for a US english it
would show in the UI as blank.
2020-07-01 06:24:41 +00:00
Billy Laws
26025d9adf Implement backing modes
These are used to determine the capabilities of a backing.
2020-07-01 06:24:41 +00:00
Billy Laws
b94248cec0 Move the loader backing out of the main loader class
The presence of a backing is an implementation detail.
2020-07-01 06:24:41 +00:00
Billy Laws
3a23ec06a4 Implement NSO loader
The NSO format is used by all retail games and some homebrew. It
supports compressing sections with lz4 and dynamic linking through the
use of rtld.
2020-06-28 07:54:12 +00:00
Billy Laws
bf46293fc7 Commonise executable loading infrastructure
Mapping and writing segments into memory is now handled by a common
function that can be shared between all loaders. All they need to do now
is to pack each segment into a common struct.
2020-06-28 07:54:12 +00:00
◱ PixelyIon
e7f880e782 Clear floating point registers on guest entry
Mesosphere does this too:
fa4a96d021/libraries/libmesosphere/source/arch/arm64/kern_k_thread_context.cpp (L135)
2020-06-28 03:49:10 +00:00
Billy Laws
f381883c0b Use X9 rather than LR when jumping to the guest
The homebrew ABI expects LR to be zero otherwise on exit it will jump to
it upon exit rather than exiting. Use X9 instead to fix this.
2020-06-28 03:49:10 +00:00
Billy Laws
b823f1cd0d Correct the handle argument in svcGetThreadPriority
The thread handle is sent in w1 rather than w0.
2020-06-28 03:49:10 +00:00
Billy Laws
138e219e0c Emulate TPIDR_EL0 accesses using TLS 2020-06-28 03:49:10 +00:00
Billy Laws
c423a66020
Fixes for control IPC (#57)
* Correctly handle -WithContext IPC Requests

They should be treated the same as the non WithContext variants.

* Only send domain data on non-control IPC responses

Control IPC doesn't make use of domains so we shouldn't send extra data
in the response.

* Add the IStorage implementation to CMakeLists
2020-06-23 18:49:06 +00:00
Billy Laws
8d470d3218 Introduce basic RomFS support
This commit adds support for reading the RomFS data from an NRO and
obtaining an IStorage handle to it through 'OpenDataStorageByCurrentProcess'.
There is currently only support for reading and no support
for enlarging or writing.

Also fixup a few capitalisation issues.
2020-06-22 16:45:32 +00:00
Billy Laws
b9b889fc3c Add loader to the emulator state
This will allow accessing data from the loader within other parts of the
emulator, such as in fssrv for RomFS.
2020-06-22 16:45:32 +00:00
Billy Laws
1bb979a7e1 Introduce new loader JNI for parsing application data and port Kotlin
code to use it

This will help ease the process of implementing new formats in the
future and remove duplicated code.
2020-06-20 20:26:53 +00:00