diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/citra_qt/debugger/graphics_breakpoints_p.h | 2 | ||||
| -rw-r--r-- | src/citra_qt/debugger/profiler.h | 2 | ||||
| -rw-r--r-- | src/citra_qt/util/spinbox.cpp | 3 | ||||
| -rw-r--r-- | src/common/thread.h | 81 | ||||
| -rw-r--r-- | src/common/thread_queue_list.h | 18 | ||||
| -rw-r--r-- | src/core/arm/dyncom/arm_dyncom.h | 2 | ||||
| -rw-r--r-- | src/core/arm/skyeye_common/vfp/vfp_helper.h | 3 | ||||
| -rw-r--r-- | src/core/arm/skyeye_common/vfp/vfpsingle.cpp | 72 | ||||
| -rw-r--r-- | src/core/file_sys/disk_archive.h | 2 | ||||
| -rw-r--r-- | src/core/hle/function_wrappers.h | 7 | ||||
| -rw-r--r-- | src/core/hle/hle.cpp | 1 | ||||
| -rw-r--r-- | src/core/hle/kernel/address_arbiter.cpp | 4 | ||||
| -rw-r--r-- | src/core/hle/kernel/kernel.cpp | 2 | ||||
| -rw-r--r-- | src/core/hle/kernel/mutex.cpp | 10 | ||||
| -rw-r--r-- | src/core/hle/kernel/shared_memory.cpp | 1 | ||||
| -rw-r--r-- | src/core/hle/kernel/thread.cpp | 50 | ||||
| -rw-r--r-- | src/core/hle/kernel/thread.h | 32 | ||||
| -rw-r--r-- | src/core/hle/kernel/timer.cpp | 2 | ||||
| -rw-r--r-- | src/core/hle/service/apt/apt.cpp | 13 | ||||
| -rw-r--r-- | src/core/hle/service/service.cpp | 43 | ||||
| -rw-r--r-- | src/core/hle/service/service.h | 55 | ||||
| -rw-r--r-- | src/core/hle/svc.cpp | 52 |
22 files changed, 256 insertions, 201 deletions
diff --git a/src/citra_qt/debugger/graphics_breakpoints_p.h b/src/citra_qt/debugger/graphics_breakpoints_p.h index 232bfc863..34e72e859 100644 --- a/src/citra_qt/debugger/graphics_breakpoints_p.h +++ b/src/citra_qt/debugger/graphics_breakpoints_p.h | |||
| @@ -25,7 +25,7 @@ public: | |||
| 25 | QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; | 25 | QVariant data(const QModelIndex& index, int role = Qt::DisplayRole) const override; |
| 26 | QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; | 26 | QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; |
| 27 | 27 | ||
| 28 | bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole); | 28 | bool setData(const QModelIndex& index, const QVariant& value, int role = Qt::EditRole) override; |
| 29 | 29 | ||
| 30 | public slots: | 30 | public slots: |
| 31 | void OnBreakPointHit(Pica::DebugContext::Event event); | 31 | void OnBreakPointHit(Pica::DebugContext::Event event); |
diff --git a/src/citra_qt/debugger/profiler.h b/src/citra_qt/debugger/profiler.h index a6d87aa0f..fabf279b8 100644 --- a/src/citra_qt/debugger/profiler.h +++ b/src/citra_qt/debugger/profiler.h | |||
| @@ -18,7 +18,7 @@ class ProfilerModel : public QAbstractItemModel | |||
| 18 | public: | 18 | public: |
| 19 | ProfilerModel(QObject* parent); | 19 | ProfilerModel(QObject* parent); |
| 20 | 20 | ||
| 21 | QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; | 21 | QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const override; |
| 22 | QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override; | 22 | QModelIndex index(int row, int column, const QModelIndex& parent = QModelIndex()) const override; |
| 23 | QModelIndex parent(const QModelIndex& child) const override; | 23 | QModelIndex parent(const QModelIndex& child) const override; |
| 24 | int columnCount(const QModelIndex& parent = QModelIndex()) const override; | 24 | int columnCount(const QModelIndex& parent = QModelIndex()) const override; |
diff --git a/src/citra_qt/util/spinbox.cpp b/src/citra_qt/util/spinbox.cpp index 2e2076a27..de4060116 100644 --- a/src/citra_qt/util/spinbox.cpp +++ b/src/citra_qt/util/spinbox.cpp | |||
| @@ -29,6 +29,7 @@ | |||
| 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 29 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 30 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 31 | 31 | ||
| 32 | #include <cstdlib> | ||
| 32 | #include <QLineEdit> | 33 | #include <QLineEdit> |
| 33 | #include <QRegExpValidator> | 34 | #include <QRegExpValidator> |
| 34 | 35 | ||
| @@ -206,7 +207,7 @@ QString CSpinBox::TextFromValue() | |||
| 206 | { | 207 | { |
| 207 | return prefix | 208 | return prefix |
| 208 | + QString(HasSign() ? ((value < 0) ? "-" : "+") : "") | 209 | + QString(HasSign() ? ((value < 0) ? "-" : "+") : "") |
| 209 | + QString("%1").arg(abs(value), num_digits, base, QLatin1Char('0')).toUpper() | 210 | + QString("%1").arg(std::abs(value), num_digits, base, QLatin1Char('0')).toUpper() |
| 210 | + suffix; | 211 | + suffix; |
| 211 | } | 212 | } |
| 212 | 213 | ||
diff --git a/src/common/thread.h b/src/common/thread.h index a45728e1e..5fdb6baeb 100644 --- a/src/common/thread.h +++ b/src/common/thread.h | |||
| @@ -51,109 +51,60 @@ int CurrentThreadId(); | |||
| 51 | void SetThreadAffinity(std::thread::native_handle_type thread, u32 mask); | 51 | void SetThreadAffinity(std::thread::native_handle_type thread, u32 mask); |
| 52 | void SetCurrentThreadAffinity(u32 mask); | 52 | void SetCurrentThreadAffinity(u32 mask); |
| 53 | 53 | ||
| 54 | class Event | 54 | class Event { |
| 55 | { | ||
| 56 | public: | 55 | public: |
| 57 | Event() | 56 | Event() : is_set(false) {} |
| 58 | : is_set(false) | ||
| 59 | {} | ||
| 60 | 57 | ||
| 61 | void Set() | 58 | void Set() { |
| 62 | { | ||
| 63 | std::lock_guard<std::mutex> lk(m_mutex); | 59 | std::lock_guard<std::mutex> lk(m_mutex); |
| 64 | if (!is_set) | 60 | if (!is_set) { |
| 65 | { | ||
| 66 | is_set = true; | 61 | is_set = true; |
| 67 | m_condvar.notify_one(); | 62 | m_condvar.notify_one(); |
| 68 | } | 63 | } |
| 69 | } | 64 | } |
| 70 | 65 | ||
| 71 | void Wait() | 66 | void Wait() { |
| 72 | { | ||
| 73 | std::unique_lock<std::mutex> lk(m_mutex); | 67 | std::unique_lock<std::mutex> lk(m_mutex); |
| 74 | m_condvar.wait(lk, IsSet(this)); | 68 | m_condvar.wait(lk, [&]{ return is_set; }); |
| 75 | is_set = false; | 69 | is_set = false; |
| 76 | } | 70 | } |
| 77 | 71 | ||
| 78 | void Reset() | 72 | void Reset() { |
| 79 | { | ||
| 80 | std::unique_lock<std::mutex> lk(m_mutex); | 73 | std::unique_lock<std::mutex> lk(m_mutex); |
| 81 | // no other action required, since wait loops on the predicate and any lingering signal will get cleared on the first iteration | 74 | // no other action required, since wait loops on the predicate and any lingering signal will get cleared on the first iteration |
| 82 | is_set = false; | 75 | is_set = false; |
| 83 | } | 76 | } |
| 84 | 77 | ||
| 85 | private: | 78 | private: |
| 86 | class IsSet | 79 | bool is_set; |
| 87 | { | ||
| 88 | public: | ||
| 89 | IsSet(const Event* ev) | ||
| 90 | : m_event(ev) | ||
| 91 | {} | ||
| 92 | |||
| 93 | bool operator()() | ||
| 94 | { | ||
| 95 | return m_event->is_set; | ||
| 96 | } | ||
| 97 | |||
| 98 | private: | ||
| 99 | const Event* const m_event; | ||
| 100 | }; | ||
| 101 | |||
| 102 | volatile bool is_set; | ||
| 103 | std::condition_variable m_condvar; | 80 | std::condition_variable m_condvar; |
| 104 | std::mutex m_mutex; | 81 | std::mutex m_mutex; |
| 105 | }; | 82 | }; |
| 106 | 83 | ||
| 107 | // TODO: doesn't work on windows with (count > 2) | 84 | class Barrier { |
| 108 | class Barrier | ||
| 109 | { | ||
| 110 | public: | 85 | public: |
| 111 | Barrier(size_t count) | 86 | Barrier(size_t count) : m_count(count), m_waiting(0) {} |
| 112 | : m_count(count), m_waiting(0) | ||
| 113 | {} | ||
| 114 | 87 | ||
| 115 | // block until "count" threads call Sync() | 88 | /// Blocks until all "count" threads have called Sync() |
| 116 | bool Sync() | 89 | void Sync() { |
| 117 | { | ||
| 118 | std::unique_lock<std::mutex> lk(m_mutex); | 90 | std::unique_lock<std::mutex> lk(m_mutex); |
| 119 | 91 | ||
| 120 | // TODO: broken when next round of Sync()s | 92 | // TODO: broken when next round of Sync()s |
| 121 | // is entered before all waiting threads return from the notify_all | 93 | // is entered before all waiting threads return from the notify_all |
| 122 | 94 | ||
| 123 | if (m_count == ++m_waiting) | 95 | if (++m_waiting == m_count) { |
| 124 | { | ||
| 125 | m_waiting = 0; | 96 | m_waiting = 0; |
| 126 | m_condvar.notify_all(); | 97 | m_condvar.notify_all(); |
| 127 | return true; | 98 | } else { |
| 128 | } | 99 | m_condvar.wait(lk, [&]{ return m_waiting == 0; }); |
| 129 | else | ||
| 130 | { | ||
| 131 | m_condvar.wait(lk, IsDoneWating(this)); | ||
| 132 | return false; | ||
| 133 | } | 100 | } |
| 134 | } | 101 | } |
| 135 | 102 | ||
| 136 | private: | 103 | private: |
| 137 | class IsDoneWating | ||
| 138 | { | ||
| 139 | public: | ||
| 140 | IsDoneWating(const Barrier* bar) | ||
| 141 | : m_bar(bar) | ||
| 142 | {} | ||
| 143 | |||
| 144 | bool operator()() | ||
| 145 | { | ||
| 146 | return (0 == m_bar->m_waiting); | ||
| 147 | } | ||
| 148 | |||
| 149 | private: | ||
| 150 | const Barrier* const m_bar; | ||
| 151 | }; | ||
| 152 | |||
| 153 | std::condition_variable m_condvar; | 104 | std::condition_variable m_condvar; |
| 154 | std::mutex m_mutex; | 105 | std::mutex m_mutex; |
| 155 | const size_t m_count; | 106 | const size_t m_count; |
| 156 | volatile size_t m_waiting; | 107 | size_t m_waiting; |
| 157 | }; | 108 | }; |
| 158 | 109 | ||
| 159 | void SleepCurrentThread(int ms); | 110 | void SleepCurrentThread(int ms); |
diff --git a/src/common/thread_queue_list.h b/src/common/thread_queue_list.h index 444abf115..4f27fc899 100644 --- a/src/common/thread_queue_list.h +++ b/src/common/thread_queue_list.h | |||
| @@ -40,6 +40,18 @@ struct ThreadQueueList { | |||
| 40 | return -1; | 40 | return -1; |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | T get_first() { | ||
| 44 | Queue *cur = first; | ||
| 45 | while (cur != nullptr) { | ||
| 46 | if (!cur->data.empty()) { | ||
| 47 | return cur->data.front(); | ||
| 48 | } | ||
| 49 | cur = cur->next_nonempty; | ||
| 50 | } | ||
| 51 | |||
| 52 | return T(); | ||
| 53 | } | ||
| 54 | |||
| 43 | T pop_first() { | 55 | T pop_first() { |
| 44 | Queue *cur = first; | 56 | Queue *cur = first; |
| 45 | while (cur != nullptr) { | 57 | while (cur != nullptr) { |
| @@ -79,6 +91,12 @@ struct ThreadQueueList { | |||
| 79 | cur->data.push_back(thread_id); | 91 | cur->data.push_back(thread_id); |
| 80 | } | 92 | } |
| 81 | 93 | ||
| 94 | void move(const T& thread_id, Priority old_priority, Priority new_priority) { | ||
| 95 | remove(old_priority, thread_id); | ||
| 96 | prepare(new_priority); | ||
| 97 | push_back(new_priority, thread_id); | ||
| 98 | } | ||
| 99 | |||
| 82 | void remove(Priority priority, const T& thread_id) { | 100 | void remove(Priority priority, const T& thread_id) { |
| 83 | Queue *cur = &queues[priority]; | 101 | Queue *cur = &queues[priority]; |
| 84 | boost::remove_erase(cur->data, thread_id); | 102 | boost::remove_erase(cur->data, thread_id); |
diff --git a/src/core/arm/dyncom/arm_dyncom.h b/src/core/arm/dyncom/arm_dyncom.h index 822b3bbb9..2488c879c 100644 --- a/src/core/arm/dyncom/arm_dyncom.h +++ b/src/core/arm/dyncom/arm_dyncom.h | |||
| @@ -27,7 +27,7 @@ public: | |||
| 27 | 27 | ||
| 28 | void AddTicks(u64 ticks) override; | 28 | void AddTicks(u64 ticks) override; |
| 29 | 29 | ||
| 30 | void ResetContext(Core::ThreadContext& context, u32 stack_top, u32 entry_point, u32 arg); | 30 | void ResetContext(Core::ThreadContext& context, u32 stack_top, u32 entry_point, u32 arg) override; |
| 31 | void SaveContext(Core::ThreadContext& ctx) override; | 31 | void SaveContext(Core::ThreadContext& ctx) override; |
| 32 | void LoadContext(const Core::ThreadContext& ctx) override; | 32 | void LoadContext(const Core::ThreadContext& ctx) override; |
| 33 | 33 | ||
diff --git a/src/core/arm/skyeye_common/vfp/vfp_helper.h b/src/core/arm/skyeye_common/vfp/vfp_helper.h index 5d1b4e53f..6b3dae280 100644 --- a/src/core/arm/skyeye_common/vfp/vfp_helper.h +++ b/src/core/arm/skyeye_common/vfp/vfp_helper.h | |||
| @@ -36,9 +36,6 @@ | |||
| 36 | #include "common/common_types.h" | 36 | #include "common/common_types.h" |
| 37 | #include "core/arm/skyeye_common/armdefs.h" | 37 | #include "core/arm/skyeye_common/armdefs.h" |
| 38 | 38 | ||
| 39 | #define pr_info //printf | ||
| 40 | #define pr_debug //printf | ||
| 41 | |||
| 42 | #define do_div(n, base) {n/=base;} | 39 | #define do_div(n, base) {n/=base;} |
| 43 | 40 | ||
| 44 | enum : u32 { | 41 | enum : u32 { |
diff --git a/src/core/arm/skyeye_common/vfp/vfpsingle.cpp b/src/core/arm/skyeye_common/vfp/vfpsingle.cpp index 8b2dfa388..a78bdc430 100644 --- a/src/core/arm/skyeye_common/vfp/vfpsingle.cpp +++ b/src/core/arm/skyeye_common/vfp/vfpsingle.cpp | |||
| @@ -51,6 +51,8 @@ | |||
| 51 | * =========================================================================== | 51 | * =========================================================================== |
| 52 | */ | 52 | */ |
| 53 | 53 | ||
| 54 | #include "common/logging/log.h" | ||
| 55 | |||
| 54 | #include "core/arm/skyeye_common/vfp/vfp_helper.h" | 56 | #include "core/arm/skyeye_common/vfp/vfp_helper.h" |
| 55 | #include "core/arm/skyeye_common/vfp/asm_vfp.h" | 57 | #include "core/arm/skyeye_common/vfp/asm_vfp.h" |
| 56 | #include "core/arm/skyeye_common/vfp/vfp.h" | 58 | #include "core/arm/skyeye_common/vfp/vfp.h" |
| @@ -63,8 +65,8 @@ static struct vfp_single vfp_single_default_qnan = { | |||
| 63 | 65 | ||
| 64 | static void vfp_single_dump(const char *str, struct vfp_single *s) | 66 | static void vfp_single_dump(const char *str, struct vfp_single *s) |
| 65 | { | 67 | { |
| 66 | pr_debug("VFP: %s: sign=%d exponent=%d significand=%08x\n", | 68 | LOG_DEBUG(Core_ARM11, "%s: sign=%d exponent=%d significand=%08x", |
| 67 | str, s->sign != 0, s->exponent, s->significand); | 69 | str, s->sign != 0, s->exponent, s->significand); |
| 68 | } | 70 | } |
| 69 | 71 | ||
| 70 | static void vfp_single_normalise_denormal(struct vfp_single *vs) | 72 | static void vfp_single_normalise_denormal(struct vfp_single *vs) |
| @@ -154,7 +156,7 @@ u32 vfp_single_normaliseround(ARMul_State* state, int sd, struct vfp_single *vs, | |||
| 154 | } else if ((rmode == FPSCR_ROUND_PLUSINF) ^ (vs->sign != 0)) | 156 | } else if ((rmode == FPSCR_ROUND_PLUSINF) ^ (vs->sign != 0)) |
| 155 | incr = (1 << (VFP_SINGLE_LOW_BITS + 1)) - 1; | 157 | incr = (1 << (VFP_SINGLE_LOW_BITS + 1)) - 1; |
| 156 | 158 | ||
| 157 | pr_debug("VFP: rounding increment = 0x%08x\n", incr); | 159 | LOG_DEBUG(Core_ARM11, "rounding increment = 0x%08x", incr); |
| 158 | 160 | ||
| 159 | /* | 161 | /* |
| 160 | * Is our rounding going to overflow? | 162 | * Is our rounding going to overflow? |
| @@ -209,10 +211,8 @@ pack: | |||
| 209 | vfp_single_dump("pack: final", vs); | 211 | vfp_single_dump("pack: final", vs); |
| 210 | { | 212 | { |
| 211 | s32 d = vfp_single_pack(vs); | 213 | s32 d = vfp_single_pack(vs); |
| 212 | #if 1 | 214 | LOG_DEBUG(Core_ARM11, "%s: d(s%d)=%08x exceptions=%08x", func, |
| 213 | pr_debug("VFP: %s: d(s%d)=%08x exceptions=%08x\n", func, | 215 | sd, d, exceptions); |
| 214 | sd, d, exceptions); | ||
| 215 | #endif | ||
| 216 | vfp_put_float(state, d, sd); | 216 | vfp_put_float(state, d, sd); |
| 217 | } | 217 | } |
| 218 | 218 | ||
| @@ -302,7 +302,7 @@ u32 vfp_estimate_sqrt_significand(u32 exponent, u32 significand) | |||
| 302 | u32 z, a; | 302 | u32 z, a; |
| 303 | 303 | ||
| 304 | if ((significand & 0xc0000000) != 0x40000000) { | 304 | if ((significand & 0xc0000000) != 0x40000000) { |
| 305 | pr_debug("VFP: estimate_sqrt: invalid significand\n"); | 305 | LOG_DEBUG(Core_ARM11, "invalid significand"); |
| 306 | } | 306 | } |
| 307 | 307 | ||
| 308 | a = significand << 1; | 308 | a = significand << 1; |
| @@ -392,7 +392,7 @@ sqrt_invalid: | |||
| 392 | term = (u64)vsd.significand * vsd.significand; | 392 | term = (u64)vsd.significand * vsd.significand; |
| 393 | rem = ((u64)vsm.significand << 32) - term; | 393 | rem = ((u64)vsm.significand << 32) - term; |
| 394 | 394 | ||
| 395 | pr_debug("VFP: term=%016llx rem=%016llx\n", term, rem); | 395 | LOG_DEBUG(Core_ARM11, "term=%016lx rem=%016lx", term, rem); |
| 396 | 396 | ||
| 397 | while (rem < 0) { | 397 | while (rem < 0) { |
| 398 | vsd.significand -= 1; | 398 | vsd.significand -= 1; |
| @@ -624,7 +624,7 @@ static u32 vfp_single_ftoui(ARMul_State* state, int sd, int unused, s32 m, u32 f | |||
| 624 | } | 624 | } |
| 625 | } | 625 | } |
| 626 | 626 | ||
| 627 | pr_debug("VFP: ftoui: d(s%d)=%08x exceptions=%08x\n", sd, d, exceptions); | 627 | LOG_DEBUG(Core_ARM11, "ftoui: d(s%d)=%08x exceptions=%08x", sd, d, exceptions); |
| 628 | 628 | ||
| 629 | vfp_put_float(state, d, sd); | 629 | vfp_put_float(state, d, sd); |
| 630 | 630 | ||
| @@ -703,7 +703,7 @@ static u32 vfp_single_ftosi(ARMul_State* state, int sd, int unused, s32 m, u32 f | |||
| 703 | } | 703 | } |
| 704 | } | 704 | } |
| 705 | 705 | ||
| 706 | pr_debug("VFP: ftosi: d(s%d)=%08x exceptions=%08x\n", sd, d, exceptions); | 706 | LOG_DEBUG(Core_ARM11, "ftosi: d(s%d)=%08x exceptions=%08x", sd, d, exceptions); |
| 707 | 707 | ||
| 708 | vfp_put_float(state, (s32)d, sd); | 708 | vfp_put_float(state, (s32)d, sd); |
| 709 | 709 | ||
| @@ -800,7 +800,7 @@ vfp_single_add(struct vfp_single *vsd, struct vfp_single *vsn, | |||
| 800 | 800 | ||
| 801 | if (vsn->significand & 0x80000000 || | 801 | if (vsn->significand & 0x80000000 || |
| 802 | vsm->significand & 0x80000000) { | 802 | vsm->significand & 0x80000000) { |
| 803 | pr_info("VFP: bad FP values in %s\n", __func__); | 803 | LOG_WARNING(Core_ARM11, "bad FP values"); |
| 804 | vfp_single_dump("VSN", vsn); | 804 | vfp_single_dump("VSN", vsn); |
| 805 | vfp_single_dump("VSM", vsm); | 805 | vfp_single_dump("VSM", vsm); |
| 806 | } | 806 | } |
| @@ -871,7 +871,7 @@ vfp_single_multiply(struct vfp_single *vsd, struct vfp_single *vsn, struct vfp_s | |||
| 871 | struct vfp_single *t = vsn; | 871 | struct vfp_single *t = vsn; |
| 872 | vsn = vsm; | 872 | vsn = vsm; |
| 873 | vsm = t; | 873 | vsm = t; |
| 874 | pr_debug("VFP: swapping M <-> N\n"); | 874 | LOG_DEBUG(Core_ARM11, "swapping M <-> N"); |
| 875 | } | 875 | } |
| 876 | 876 | ||
| 877 | vsd->sign = vsn->sign ^ vsm->sign; | 877 | vsd->sign = vsn->sign ^ vsm->sign; |
| @@ -924,7 +924,7 @@ vfp_single_multiply_accumulate(ARMul_State* state, int sd, int sn, s32 m, u32 fp | |||
| 924 | s32 v; | 924 | s32 v; |
| 925 | 925 | ||
| 926 | v = vfp_get_float(state, sn); | 926 | v = vfp_get_float(state, sn); |
| 927 | pr_debug("VFP: s%u = %08x\n", sn, v); | 927 | LOG_DEBUG(Core_ARM11, "s%u = %08x", sn, v); |
| 928 | vfp_single_unpack(&vsn, v); | 928 | vfp_single_unpack(&vsn, v); |
| 929 | if (vsn.exponent == 0 && vsn.significand) | 929 | if (vsn.exponent == 0 && vsn.significand) |
| 930 | vfp_single_normalise_denormal(&vsn); | 930 | vfp_single_normalise_denormal(&vsn); |
| @@ -939,7 +939,7 @@ vfp_single_multiply_accumulate(ARMul_State* state, int sd, int sn, s32 m, u32 fp | |||
| 939 | vsp.sign = vfp_sign_negate(vsp.sign); | 939 | vsp.sign = vfp_sign_negate(vsp.sign); |
| 940 | 940 | ||
| 941 | v = vfp_get_float(state, sd); | 941 | v = vfp_get_float(state, sd); |
| 942 | pr_debug("VFP: s%u = %08x\n", sd, v); | 942 | LOG_DEBUG(Core_ARM11, "s%u = %08x", sd, v); |
| 943 | vfp_single_unpack(&vsn, v); | 943 | vfp_single_unpack(&vsn, v); |
| 944 | if (vsn.exponent == 0 && vsn.significand != 0) | 944 | if (vsn.exponent == 0 && vsn.significand != 0) |
| 945 | vfp_single_normalise_denormal(&vsn); | 945 | vfp_single_normalise_denormal(&vsn); |
| @@ -961,7 +961,7 @@ vfp_single_multiply_accumulate(ARMul_State* state, int sd, int sn, s32 m, u32 fp | |||
| 961 | */ | 961 | */ |
| 962 | static u32 vfp_single_fmac(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr) | 962 | static u32 vfp_single_fmac(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr) |
| 963 | { | 963 | { |
| 964 | pr_debug("In %sVFP: s%u = %08x\n", __FUNCTION__, sn, sd); | 964 | LOG_DEBUG(Core_ARM11, "s%u = %08x", sn, sd); |
| 965 | return vfp_single_multiply_accumulate(state, sd, sn, m, fpscr, 0, "fmac"); | 965 | return vfp_single_multiply_accumulate(state, sd, sn, m, fpscr, 0, "fmac"); |
| 966 | } | 966 | } |
| 967 | 967 | ||
| @@ -970,7 +970,8 @@ static u32 vfp_single_fmac(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr) | |||
| 970 | */ | 970 | */ |
| 971 | static u32 vfp_single_fnmac(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr) | 971 | static u32 vfp_single_fnmac(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr) |
| 972 | { | 972 | { |
| 973 | pr_debug("In %sVFP: s%u = %08x\n", __FUNCTION__, sd, sn); | 973 | // TODO: this one has its arguments inverted, investigate. |
| 974 | LOG_DEBUG(Core_ARM11, "s%u = %08x", sd, sn); | ||
| 974 | return vfp_single_multiply_accumulate(state, sd, sn, m, fpscr, NEG_MULTIPLY, "fnmac"); | 975 | return vfp_single_multiply_accumulate(state, sd, sn, m, fpscr, NEG_MULTIPLY, "fnmac"); |
| 975 | } | 976 | } |
| 976 | 977 | ||
| @@ -979,7 +980,7 @@ static u32 vfp_single_fnmac(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr | |||
| 979 | */ | 980 | */ |
| 980 | static u32 vfp_single_fmsc(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr) | 981 | static u32 vfp_single_fmsc(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr) |
| 981 | { | 982 | { |
| 982 | pr_debug("In %sVFP: s%u = %08x\n", __FUNCTION__, sn, sd); | 983 | LOG_DEBUG(Core_ARM11, "s%u = %08x", sn, sd); |
| 983 | return vfp_single_multiply_accumulate(state, sd, sn, m, fpscr, NEG_SUBTRACT, "fmsc"); | 984 | return vfp_single_multiply_accumulate(state, sd, sn, m, fpscr, NEG_SUBTRACT, "fmsc"); |
| 984 | } | 985 | } |
| 985 | 986 | ||
| @@ -988,7 +989,7 @@ static u32 vfp_single_fmsc(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr) | |||
| 988 | */ | 989 | */ |
| 989 | static u32 vfp_single_fnmsc(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr) | 990 | static u32 vfp_single_fnmsc(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr) |
| 990 | { | 991 | { |
| 991 | pr_debug("In %sVFP: s%u = %08x\n", __FUNCTION__, sn, sd); | 992 | LOG_DEBUG(Core_ARM11, "s%u = %08x", sn, sd); |
| 992 | return vfp_single_multiply_accumulate(state, sd, sn, m, fpscr, NEG_SUBTRACT | NEG_MULTIPLY, "fnmsc"); | 993 | return vfp_single_multiply_accumulate(state, sd, sn, m, fpscr, NEG_SUBTRACT | NEG_MULTIPLY, "fnmsc"); |
| 993 | } | 994 | } |
| 994 | 995 | ||
| @@ -1001,7 +1002,7 @@ static u32 vfp_single_fmul(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr) | |||
| 1001 | u32 exceptions; | 1002 | u32 exceptions; |
| 1002 | s32 n = vfp_get_float(state, sn); | 1003 | s32 n = vfp_get_float(state, sn); |
| 1003 | 1004 | ||
| 1004 | pr_debug("In %sVFP: s%u = %08x\n", __FUNCTION__, sn, n); | 1005 | LOG_DEBUG(Core_ARM11, "s%u = %08x", sn, n); |
| 1005 | 1006 | ||
| 1006 | vfp_single_unpack(&vsn, n); | 1007 | vfp_single_unpack(&vsn, n); |
| 1007 | if (vsn.exponent == 0 && vsn.significand) | 1008 | if (vsn.exponent == 0 && vsn.significand) |
| @@ -1024,7 +1025,7 @@ static u32 vfp_single_fnmul(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr | |||
| 1024 | u32 exceptions; | 1025 | u32 exceptions; |
| 1025 | s32 n = vfp_get_float(state, sn); | 1026 | s32 n = vfp_get_float(state, sn); |
| 1026 | 1027 | ||
| 1027 | pr_debug("VFP: s%u = %08x\n", sn, n); | 1028 | LOG_DEBUG(Core_ARM11, "s%u = %08x", sn, n); |
| 1028 | 1029 | ||
| 1029 | vfp_single_unpack(&vsn, n); | 1030 | vfp_single_unpack(&vsn, n); |
| 1030 | if (vsn.exponent == 0 && vsn.significand) | 1031 | if (vsn.exponent == 0 && vsn.significand) |
| @@ -1048,7 +1049,7 @@ static u32 vfp_single_fadd(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr) | |||
| 1048 | u32 exceptions; | 1049 | u32 exceptions; |
| 1049 | s32 n = vfp_get_float(state, sn); | 1050 | s32 n = vfp_get_float(state, sn); |
| 1050 | 1051 | ||
| 1051 | pr_debug("VFP: s%u = %08x\n", sn, n); | 1052 | LOG_DEBUG(Core_ARM11, "s%u = %08x", sn, n); |
| 1052 | 1053 | ||
| 1053 | /* | 1054 | /* |
| 1054 | * Unpack and normalise denormals. | 1055 | * Unpack and normalise denormals. |
| @@ -1071,7 +1072,7 @@ static u32 vfp_single_fadd(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr) | |||
| 1071 | */ | 1072 | */ |
| 1072 | static u32 vfp_single_fsub(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr) | 1073 | static u32 vfp_single_fsub(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr) |
| 1073 | { | 1074 | { |
| 1074 | pr_debug("In %sVFP: s%u = %08x\n", __FUNCTION__, sn, sd); | 1075 | LOG_DEBUG(Core_ARM11, "s%u = %08x", sn, sd); |
| 1075 | /* | 1076 | /* |
| 1076 | * Subtraction is addition with one sign inverted. | 1077 | * Subtraction is addition with one sign inverted. |
| 1077 | */ | 1078 | */ |
| @@ -1091,7 +1092,7 @@ static u32 vfp_single_fdiv(ARMul_State* state, int sd, int sn, s32 m, u32 fpscr) | |||
| 1091 | s32 n = vfp_get_float(state, sn); | 1092 | s32 n = vfp_get_float(state, sn); |
| 1092 | int tm, tn; | 1093 | int tm, tn; |
| 1093 | 1094 | ||
| 1094 | pr_debug("VFP: s%u = %08x\n", sn, n); | 1095 | LOG_DEBUG(Core_ARM11, "s%u = %08x", sn, n); |
| 1095 | 1096 | ||
| 1096 | vfp_single_unpack(&vsn, n); | 1097 | vfp_single_unpack(&vsn, n); |
| 1097 | vfp_single_unpack(&vsm, m); | 1098 | vfp_single_unpack(&vsm, m); |
| @@ -1213,7 +1214,6 @@ u32 vfp_single_cpdo(ARMul_State* state, u32 inst, u32 fpscr) | |||
| 1213 | unsigned int sm = vfp_get_sm(inst); | 1214 | unsigned int sm = vfp_get_sm(inst); |
| 1214 | unsigned int vecitr, veclen, vecstride; | 1215 | unsigned int vecitr, veclen, vecstride; |
| 1215 | struct op *fop; | 1216 | struct op *fop; |
| 1216 | pr_debug("In %s\n", __FUNCTION__); | ||
| 1217 | 1217 | ||
| 1218 | vecstride = 1 + ((fpscr & FPSCR_STRIDE_MASK) == FPSCR_STRIDE_MASK); | 1218 | vecstride = 1 + ((fpscr & FPSCR_STRIDE_MASK) == FPSCR_STRIDE_MASK); |
| 1219 | 1219 | ||
| @@ -1239,11 +1239,11 @@ u32 vfp_single_cpdo(ARMul_State* state, u32 inst, u32 fpscr) | |||
| 1239 | else | 1239 | else |
| 1240 | veclen = fpscr & FPSCR_LENGTH_MASK; | 1240 | veclen = fpscr & FPSCR_LENGTH_MASK; |
| 1241 | 1241 | ||
| 1242 | pr_debug("VFP: vecstride=%u veclen=%u\n", vecstride, | 1242 | LOG_DEBUG(Core_ARM11, "vecstride=%u veclen=%u", vecstride, |
| 1243 | (veclen >> FPSCR_LENGTH_BIT) + 1); | 1243 | (veclen >> FPSCR_LENGTH_BIT) + 1); |
| 1244 | 1244 | ||
| 1245 | if (!fop->fn) { | 1245 | if (!fop->fn) { |
| 1246 | printf("VFP: could not find single op %d, inst=0x%x@0x%x\n", FEXT_TO_IDX(inst), inst, state->Reg[15]); | 1246 | LOG_CRITICAL(Core_ARM11, "could not find single op %d, inst=0x%x@0x%x", FEXT_TO_IDX(inst), inst, state->Reg[15]); |
| 1247 | exit(-1); | 1247 | exit(-1); |
| 1248 | goto invalid; | 1248 | goto invalid; |
| 1249 | } | 1249 | } |
| @@ -1255,17 +1255,17 @@ u32 vfp_single_cpdo(ARMul_State* state, u32 inst, u32 fpscr) | |||
| 1255 | 1255 | ||
| 1256 | type = (fop->flags & OP_DD) ? 'd' : 's'; | 1256 | type = (fop->flags & OP_DD) ? 'd' : 's'; |
| 1257 | if (op == FOP_EXT) | 1257 | if (op == FOP_EXT) |
| 1258 | pr_debug("VFP: itr%d (%c%u) = op[%u] (s%u=%08x)\n", | 1258 | LOG_DEBUG(Core_ARM11, "itr%d (%c%u) = op[%u] (s%u=%08x)", |
| 1259 | vecitr >> FPSCR_LENGTH_BIT, type, dest, sn, | 1259 | vecitr >> FPSCR_LENGTH_BIT, type, dest, sn, |
| 1260 | sm, m); | 1260 | sm, m); |
| 1261 | else | 1261 | else |
| 1262 | pr_debug("VFP: itr%d (%c%u) = (s%u) op[%u] (s%u=%08x)\n", | 1262 | LOG_DEBUG(Core_ARM11, "itr%d (%c%u) = (s%u) op[%u] (s%u=%08x)", |
| 1263 | vecitr >> FPSCR_LENGTH_BIT, type, dest, sn, | 1263 | vecitr >> FPSCR_LENGTH_BIT, type, dest, sn, |
| 1264 | FOP_TO_IDX(op), sm, m); | 1264 | FOP_TO_IDX(op), sm, m); |
| 1265 | 1265 | ||
| 1266 | except = fop->fn(state, dest, sn, m, fpscr); | 1266 | except = fop->fn(state, dest, sn, m, fpscr); |
| 1267 | pr_debug("VFP: itr%d: exceptions=%08x\n", | 1267 | LOG_DEBUG(Core_ARM11, "itr%d: exceptions=%08x", |
| 1268 | vecitr >> FPSCR_LENGTH_BIT, except); | 1268 | vecitr >> FPSCR_LENGTH_BIT, except); |
| 1269 | 1269 | ||
| 1270 | exceptions |= except; | 1270 | exceptions |= except; |
| 1271 | 1271 | ||
diff --git a/src/core/file_sys/disk_archive.h b/src/core/file_sys/disk_archive.h index dbbdced74..770bd715e 100644 --- a/src/core/file_sys/disk_archive.h +++ b/src/core/file_sys/disk_archive.h | |||
| @@ -24,7 +24,7 @@ class DiskArchive : public ArchiveBackend { | |||
| 24 | public: | 24 | public: |
| 25 | DiskArchive(const std::string& mount_point_) : mount_point(mount_point_) {} | 25 | DiskArchive(const std::string& mount_point_) : mount_point(mount_point_) {} |
| 26 | 26 | ||
| 27 | virtual std::string GetName() const { return "DiskArchive: " + mount_point; } | 27 | virtual std::string GetName() const override { return "DiskArchive: " + mount_point; } |
| 28 | 28 | ||
| 29 | std::unique_ptr<FileBackend> OpenFile(const Path& path, const Mode mode) const override; | 29 | std::unique_ptr<FileBackend> OpenFile(const Path& path, const Mode mode) const override; |
| 30 | bool DeleteFile(const Path& path) const override; | 30 | bool DeleteFile(const Path& path) const override; |
diff --git a/src/core/hle/function_wrappers.h b/src/core/hle/function_wrappers.h index 0b6b6f518..be2626eef 100644 --- a/src/core/hle/function_wrappers.h +++ b/src/core/hle/function_wrappers.h | |||
| @@ -46,6 +46,13 @@ template<ResultCode func(u32*, u32, u32, u32, u32, u32)> void Wrap(){ | |||
| 46 | FuncReturn(retval); | 46 | FuncReturn(retval); |
| 47 | } | 47 | } |
| 48 | 48 | ||
| 49 | template<ResultCode func(u32*, s32, u32, u32, u32, s32)> void Wrap() { | ||
| 50 | u32 param_1 = 0; | ||
| 51 | u32 retval = func(¶m_1, PARAM(0), PARAM(1), PARAM(2), PARAM(3), PARAM(4)).raw; | ||
| 52 | Core::g_app_core->SetReg(1, param_1); | ||
| 53 | FuncReturn(retval); | ||
| 54 | } | ||
| 55 | |||
| 49 | template<ResultCode func(s32*, u32*, s32, bool, s64)> void Wrap() { | 56 | template<ResultCode func(s32*, u32*, s32, bool, s64)> void Wrap() { |
| 50 | s32 param_1 = 0; | 57 | s32 param_1 = 0; |
| 51 | s32 retval = func(¶m_1, (Handle*)Memory::GetPointer(PARAM(1)), (s32)PARAM(2), | 58 | s32 retval = func(¶m_1, (Handle*)Memory::GetPointer(PARAM(1)), (s32)PARAM(2), |
diff --git a/src/core/hle/hle.cpp b/src/core/hle/hle.cpp index 1aaeaa9c9..c645d6563 100644 --- a/src/core/hle/hle.cpp +++ b/src/core/hle/hle.cpp | |||
| @@ -13,6 +13,7 @@ | |||
| 13 | #include "core/hle/shared_page.h" | 13 | #include "core/hle/shared_page.h" |
| 14 | #include "core/hle/kernel/thread.h" | 14 | #include "core/hle/kernel/thread.h" |
| 15 | #include "core/hle/service/service.h" | 15 | #include "core/hle/service/service.h" |
| 16 | #include "core/hle/svc.h" | ||
| 16 | 17 | ||
| 17 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 18 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 18 | 19 | ||
diff --git a/src/core/hle/kernel/address_arbiter.cpp b/src/core/hle/kernel/address_arbiter.cpp index 42f8ce2d9..19135266c 100644 --- a/src/core/hle/kernel/address_arbiter.cpp +++ b/src/core/hle/kernel/address_arbiter.cpp | |||
| @@ -46,14 +46,12 @@ ResultCode AddressArbiter::ArbitrateAddress(ArbitrationType type, VAddr address, | |||
| 46 | case ArbitrationType::WaitIfLessThan: | 46 | case ArbitrationType::WaitIfLessThan: |
| 47 | if ((s32)Memory::Read32(address) <= value) { | 47 | if ((s32)Memory::Read32(address) <= value) { |
| 48 | Kernel::WaitCurrentThread_ArbitrateAddress(address); | 48 | Kernel::WaitCurrentThread_ArbitrateAddress(address); |
| 49 | HLE::Reschedule(__func__); | ||
| 50 | } | 49 | } |
| 51 | break; | 50 | break; |
| 52 | case ArbitrationType::WaitIfLessThanWithTimeout: | 51 | case ArbitrationType::WaitIfLessThanWithTimeout: |
| 53 | if ((s32)Memory::Read32(address) <= value) { | 52 | if ((s32)Memory::Read32(address) <= value) { |
| 54 | Kernel::WaitCurrentThread_ArbitrateAddress(address); | 53 | Kernel::WaitCurrentThread_ArbitrateAddress(address); |
| 55 | GetCurrentThread()->WakeAfterDelay(nanoseconds); | 54 | GetCurrentThread()->WakeAfterDelay(nanoseconds); |
| 56 | HLE::Reschedule(__func__); | ||
| 57 | } | 55 | } |
| 58 | break; | 56 | break; |
| 59 | case ArbitrationType::DecrementAndWaitIfLessThan: | 57 | case ArbitrationType::DecrementAndWaitIfLessThan: |
| @@ -62,7 +60,6 @@ ResultCode AddressArbiter::ArbitrateAddress(ArbitrationType type, VAddr address, | |||
| 62 | Memory::Write32(address, memory_value); | 60 | Memory::Write32(address, memory_value); |
| 63 | if (memory_value <= value) { | 61 | if (memory_value <= value) { |
| 64 | Kernel::WaitCurrentThread_ArbitrateAddress(address); | 62 | Kernel::WaitCurrentThread_ArbitrateAddress(address); |
| 65 | HLE::Reschedule(__func__); | ||
| 66 | } | 63 | } |
| 67 | break; | 64 | break; |
| 68 | } | 65 | } |
| @@ -73,7 +70,6 @@ ResultCode AddressArbiter::ArbitrateAddress(ArbitrationType type, VAddr address, | |||
| 73 | if (memory_value <= value) { | 70 | if (memory_value <= value) { |
| 74 | Kernel::WaitCurrentThread_ArbitrateAddress(address); | 71 | Kernel::WaitCurrentThread_ArbitrateAddress(address); |
| 75 | GetCurrentThread()->WakeAfterDelay(nanoseconds); | 72 | GetCurrentThread()->WakeAfterDelay(nanoseconds); |
| 76 | HLE::Reschedule(__func__); | ||
| 77 | } | 73 | } |
| 78 | break; | 74 | break; |
| 79 | } | 75 | } |
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp index 498b2ec98..6261b82b6 100644 --- a/src/core/hle/kernel/kernel.cpp +++ b/src/core/hle/kernel/kernel.cpp | |||
| @@ -154,7 +154,7 @@ void Shutdown() { | |||
| 154 | */ | 154 | */ |
| 155 | bool LoadExec(u32 entry_point) { | 155 | bool LoadExec(u32 entry_point) { |
| 156 | // 0x30 is the typical main thread priority I've seen used so far | 156 | // 0x30 is the typical main thread priority I've seen used so far |
| 157 | g_main_thread = Kernel::SetupMainThread(Kernel::DEFAULT_STACK_SIZE, entry_point, 0x30); | 157 | g_main_thread = Kernel::SetupMainThread(Kernel::DEFAULT_STACK_SIZE, entry_point, THREADPRIO_DEFAULT); |
| 158 | 158 | ||
| 159 | return true; | 159 | return true; |
| 160 | } | 160 | } |
diff --git a/src/core/hle/kernel/mutex.cpp b/src/core/hle/kernel/mutex.cpp index be2c49706..ebc9e79d7 100644 --- a/src/core/hle/kernel/mutex.cpp +++ b/src/core/hle/kernel/mutex.cpp | |||
| @@ -56,7 +56,15 @@ SharedPtr<Mutex> Mutex::Create(bool initial_locked, std::string name) { | |||
| 56 | } | 56 | } |
| 57 | 57 | ||
| 58 | bool Mutex::ShouldWait() { | 58 | bool Mutex::ShouldWait() { |
| 59 | return lock_count > 0 && holding_thread != GetCurrentThread();; | 59 | auto thread = GetCurrentThread(); |
| 60 | bool wait = lock_count > 0 && holding_thread != thread; | ||
| 61 | |||
| 62 | // If the holding thread of the mutex is lower priority than this thread, that thread should | ||
| 63 | // temporarily inherit this thread's priority | ||
| 64 | if (wait && thread->current_priority < holding_thread->current_priority) | ||
| 65 | holding_thread->BoostPriority(thread->current_priority); | ||
| 66 | |||
| 67 | return wait; | ||
| 60 | } | 68 | } |
| 61 | 69 | ||
| 62 | void Mutex::Acquire() { | 70 | void Mutex::Acquire() { |
diff --git a/src/core/hle/kernel/shared_memory.cpp b/src/core/hle/kernel/shared_memory.cpp index 4211fcf04..9b2511b53 100644 --- a/src/core/hle/kernel/shared_memory.cpp +++ b/src/core/hle/kernel/shared_memory.cpp | |||
| @@ -16,6 +16,7 @@ SharedPtr<SharedMemory> SharedMemory::Create(std::string name) { | |||
| 16 | SharedPtr<SharedMemory> shared_memory(new SharedMemory); | 16 | SharedPtr<SharedMemory> shared_memory(new SharedMemory); |
| 17 | 17 | ||
| 18 | shared_memory->name = std::move(name); | 18 | shared_memory->name = std::move(name); |
| 19 | shared_memory->base_address = 0x0; | ||
| 19 | 20 | ||
| 20 | return shared_memory; | 21 | return shared_memory; |
| 21 | } | 22 | } |
diff --git a/src/core/hle/kernel/thread.cpp b/src/core/hle/kernel/thread.cpp index be1aed615..33d66b986 100644 --- a/src/core/hle/kernel/thread.cpp +++ b/src/core/hle/kernel/thread.cpp | |||
| @@ -140,6 +140,28 @@ void ArbitrateAllThreads(u32 address) { | |||
| 140 | } | 140 | } |
| 141 | } | 141 | } |
| 142 | 142 | ||
| 143 | /// Boost low priority threads (temporarily) that have been starved | ||
| 144 | static void PriorityBoostStarvedThreads() { | ||
| 145 | u64 current_ticks = CoreTiming::GetTicks(); | ||
| 146 | |||
| 147 | for (auto& thread : thread_list) { | ||
| 148 | // TODO(bunnei): Threads that have been waiting to be scheduled for `boost_ticks` (or | ||
| 149 | // longer) will have their priority temporarily adjusted to 1 higher than the highest | ||
| 150 | // priority thread to prevent thread starvation. This general behavior has been verified | ||
| 151 | // on hardware. However, this is almost certainly not perfect, and the real CTR OS scheduler | ||
| 152 | // should probably be reversed to verify this. | ||
| 153 | |||
| 154 | const u64 boost_timeout = 2000000; // Boost threads that have been ready for > this long | ||
| 155 | |||
| 156 | u64 delta = current_ticks - thread->last_running_ticks; | ||
| 157 | |||
| 158 | if (thread->status == THREADSTATUS_READY && delta > boost_timeout && !thread->idle) { | ||
| 159 | const s32 priority = std::max(ready_queue.get_first()->current_priority - 1, 0); | ||
| 160 | thread->BoostPriority(priority); | ||
| 161 | } | ||
| 162 | } | ||
| 163 | } | ||
| 164 | |||
| 143 | /** | 165 | /** |
| 144 | * Switches the CPU's active thread context to that of the specified thread | 166 | * Switches the CPU's active thread context to that of the specified thread |
| 145 | * @param new_thread The thread to switch to | 167 | * @param new_thread The thread to switch to |
| @@ -151,6 +173,7 @@ static void SwitchContext(Thread* new_thread) { | |||
| 151 | 173 | ||
| 152 | // Save context for previous thread | 174 | // Save context for previous thread |
| 153 | if (previous_thread) { | 175 | if (previous_thread) { |
| 176 | previous_thread->last_running_ticks = CoreTiming::GetTicks(); | ||
| 154 | Core::g_app_core->SaveContext(previous_thread->context); | 177 | Core::g_app_core->SaveContext(previous_thread->context); |
| 155 | 178 | ||
| 156 | if (previous_thread->status == THREADSTATUS_RUNNING) { | 179 | if (previous_thread->status == THREADSTATUS_RUNNING) { |
| @@ -168,6 +191,9 @@ static void SwitchContext(Thread* new_thread) { | |||
| 168 | ready_queue.remove(new_thread->current_priority, new_thread); | 191 | ready_queue.remove(new_thread->current_priority, new_thread); |
| 169 | new_thread->status = THREADSTATUS_RUNNING; | 192 | new_thread->status = THREADSTATUS_RUNNING; |
| 170 | 193 | ||
| 194 | // Restores thread to its nominal priority if it has been temporarily changed | ||
| 195 | new_thread->current_priority = new_thread->nominal_priority; | ||
| 196 | |||
| 171 | Core::g_app_core->LoadContext(new_thread->context); | 197 | Core::g_app_core->LoadContext(new_thread->context); |
| 172 | } else { | 198 | } else { |
| 173 | current_thread = nullptr; | 199 | current_thread = nullptr; |
| @@ -364,7 +390,8 @@ ResultVal<SharedPtr<Thread>> Thread::Create(std::string name, VAddr entry_point, | |||
| 364 | thread->status = THREADSTATUS_DORMANT; | 390 | thread->status = THREADSTATUS_DORMANT; |
| 365 | thread->entry_point = entry_point; | 391 | thread->entry_point = entry_point; |
| 366 | thread->stack_top = stack_top; | 392 | thread->stack_top = stack_top; |
| 367 | thread->initial_priority = thread->current_priority = priority; | 393 | thread->nominal_priority = thread->current_priority = priority; |
| 394 | thread->last_running_ticks = CoreTiming::GetTicks(); | ||
| 368 | thread->processor_id = processor_id; | 395 | thread->processor_id = processor_id; |
| 369 | thread->wait_set_output = false; | 396 | thread->wait_set_output = false; |
| 370 | thread->wait_all = false; | 397 | thread->wait_all = false; |
| @@ -400,17 +427,15 @@ static void ClampPriority(const Thread* thread, s32* priority) { | |||
| 400 | void Thread::SetPriority(s32 priority) { | 427 | void Thread::SetPriority(s32 priority) { |
| 401 | ClampPriority(this, &priority); | 428 | ClampPriority(this, &priority); |
| 402 | 429 | ||
| 403 | if (current_priority == priority) { | 430 | // If thread was ready, adjust queues |
| 404 | return; | 431 | if (status == THREADSTATUS_READY) |
| 405 | } | 432 | ready_queue.move(this, current_priority, priority); |
| 406 | 433 | ||
| 407 | if (status == THREADSTATUS_READY) { | 434 | nominal_priority = current_priority = priority; |
| 408 | // If thread was ready, adjust queues | 435 | } |
| 409 | ready_queue.remove(current_priority, this); | 436 | |
| 410 | ready_queue.prepare(priority); | 437 | void Thread::BoostPriority(s32 priority) { |
| 411 | ready_queue.push_back(priority, this); | 438 | ready_queue.move(this, current_priority, priority); |
| 412 | } | ||
| 413 | |||
| 414 | current_priority = priority; | 439 | current_priority = priority; |
| 415 | } | 440 | } |
| 416 | 441 | ||
| @@ -440,6 +465,9 @@ SharedPtr<Thread> SetupMainThread(u32 stack_size, u32 entry_point, s32 priority) | |||
| 440 | 465 | ||
| 441 | void Reschedule() { | 466 | void Reschedule() { |
| 442 | Thread* prev = GetCurrentThread(); | 467 | Thread* prev = GetCurrentThread(); |
| 468 | |||
| 469 | PriorityBoostStarvedThreads(); | ||
| 470 | |||
| 443 | Thread* next = PopNextReadyThread(); | 471 | Thread* next = PopNextReadyThread(); |
| 444 | HLE::g_reschedule = false; | 472 | HLE::g_reschedule = false; |
| 445 | 473 | ||
diff --git a/src/core/hle/kernel/thread.h b/src/core/hle/kernel/thread.h index cfd073a70..233bcbdbd 100644 --- a/src/core/hle/kernel/thread.h +++ b/src/core/hle/kernel/thread.h | |||
| @@ -17,17 +17,19 @@ | |||
| 17 | #include "core/hle/kernel/kernel.h" | 17 | #include "core/hle/kernel/kernel.h" |
| 18 | #include "core/hle/result.h" | 18 | #include "core/hle/result.h" |
| 19 | 19 | ||
| 20 | enum ThreadPriority { | 20 | enum ThreadPriority : s32{ |
| 21 | THREADPRIO_HIGHEST = 0, ///< Highest thread priority | 21 | THREADPRIO_HIGHEST = 0, ///< Highest thread priority |
| 22 | THREADPRIO_DEFAULT = 16, ///< Default thread priority for userland apps | 22 | THREADPRIO_USERLAND_MAX = 24, ///< Highest thread priority for userland apps |
| 23 | THREADPRIO_LOW = 31, ///< Low range of thread priority for userland apps | 23 | THREADPRIO_DEFAULT = 48, ///< Default thread priority for userland apps |
| 24 | THREADPRIO_LOWEST = 63, ///< Thread priority max checked by svcCreateThread | 24 | THREADPRIO_LOWEST = 63, ///< Lowest thread priority |
| 25 | }; | 25 | }; |
| 26 | 26 | ||
| 27 | enum ThreadProcessorId { | 27 | enum ThreadProcessorId : s32 { |
| 28 | THREADPROCESSORID_0 = 0xFFFFFFFE, ///< Enables core appcode | 28 | THREADPROCESSORID_DEFAULT = -2, ///< Run thread on default core specified by exheader |
| 29 | THREADPROCESSORID_1 = 0xFFFFFFFD, ///< Enables core syscore | 29 | THREADPROCESSORID_ALL = -1, ///< Run thread on either core |
| 30 | THREADPROCESSORID_ALL = 0xFFFFFFFC, ///< Enables both cores | 30 | THREADPROCESSORID_0 = 0, ///< Run thread on core 0 (AppCore) |
| 31 | THREADPROCESSORID_1 = 1, ///< Run thread on core 1 (SysCore) | ||
| 32 | THREADPROCESSORID_MAX = 2, ///< Processor ID must be less than this | ||
| 31 | }; | 33 | }; |
| 32 | 34 | ||
| 33 | enum ThreadStatus { | 35 | enum ThreadStatus { |
| @@ -88,6 +90,12 @@ public: | |||
| 88 | void SetPriority(s32 priority); | 90 | void SetPriority(s32 priority); |
| 89 | 91 | ||
| 90 | /** | 92 | /** |
| 93 | * Temporarily boosts the thread's priority until the next time it is scheduled | ||
| 94 | * @param priority The new priority | ||
| 95 | */ | ||
| 96 | void BoostPriority(s32 priority); | ||
| 97 | |||
| 98 | /** | ||
| 91 | * Gets the thread's thread ID | 99 | * Gets the thread's thread ID |
| 92 | * @return The thread's ID | 100 | * @return The thread's ID |
| 93 | */ | 101 | */ |
| @@ -135,8 +143,10 @@ public: | |||
| 135 | u32 entry_point; | 143 | u32 entry_point; |
| 136 | u32 stack_top; | 144 | u32 stack_top; |
| 137 | 145 | ||
| 138 | s32 initial_priority; | 146 | s32 nominal_priority; ///< Nominal thread priority, as set by the emulated application |
| 139 | s32 current_priority; | 147 | s32 current_priority; ///< Current thread priority, can be temporarily changed |
| 148 | |||
| 149 | u64 last_running_ticks; ///< CPU tick when thread was last running | ||
| 140 | 150 | ||
| 141 | s32 processor_id; | 151 | s32 processor_id; |
| 142 | 152 | ||
diff --git a/src/core/hle/kernel/timer.cpp b/src/core/hle/kernel/timer.cpp index 610e26a3c..1ec2a4b10 100644 --- a/src/core/hle/kernel/timer.cpp +++ b/src/core/hle/kernel/timer.cpp | |||
| @@ -66,7 +66,7 @@ static void TimerCallback(u64 timer_handle, int cycles_late) { | |||
| 66 | SharedPtr<Timer> timer = timer_callback_handle_table.Get<Timer>(static_cast<Handle>(timer_handle)); | 66 | SharedPtr<Timer> timer = timer_callback_handle_table.Get<Timer>(static_cast<Handle>(timer_handle)); |
| 67 | 67 | ||
| 68 | if (timer == nullptr) { | 68 | if (timer == nullptr) { |
| 69 | LOG_CRITICAL(Kernel, "Callback fired for invalid timer %08X", timer_handle); | 69 | LOG_CRITICAL(Kernel, "Callback fired for invalid timer %08lX", timer_handle); |
| 70 | return; | 70 | return; |
| 71 | } | 71 | } |
| 72 | 72 | ||
diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp index 4861d9e5f..190c5df7a 100644 --- a/src/core/hle/service/apt/apt.cpp +++ b/src/core/hle/service/apt/apt.cpp | |||
| @@ -32,7 +32,8 @@ static Kernel::SharedPtr<Kernel::SharedMemory> shared_font_mem = nullptr; | |||
| 32 | 32 | ||
| 33 | static Kernel::SharedPtr<Kernel::Mutex> lock = nullptr; | 33 | static Kernel::SharedPtr<Kernel::Mutex> lock = nullptr; |
| 34 | static Kernel::SharedPtr<Kernel::Event> notification_event = nullptr; ///< APT notification event | 34 | static Kernel::SharedPtr<Kernel::Event> notification_event = nullptr; ///< APT notification event |
| 35 | static Kernel::SharedPtr<Kernel::Event> pause_event = nullptr; ///< APT pause event | 35 | static Kernel::SharedPtr<Kernel::Event> start_event = nullptr; ///< APT start event |
| 36 | |||
| 36 | static std::vector<u8> shared_font; | 37 | static std::vector<u8> shared_font; |
| 37 | 38 | ||
| 38 | static u32 cpu_percent = 0; ///< CPU time available to the running application | 39 | static u32 cpu_percent = 0; ///< CPU time available to the running application |
| @@ -44,11 +45,11 @@ void Initialize(Service::Interface* self) { | |||
| 44 | 45 | ||
| 45 | cmd_buff[2] = 0x04000000; // According to 3dbrew, this value should be 0x04000000 | 46 | cmd_buff[2] = 0x04000000; // According to 3dbrew, this value should be 0x04000000 |
| 46 | cmd_buff[3] = Kernel::g_handle_table.Create(notification_event).MoveFrom(); | 47 | cmd_buff[3] = Kernel::g_handle_table.Create(notification_event).MoveFrom(); |
| 47 | cmd_buff[4] = Kernel::g_handle_table.Create(pause_event).MoveFrom(); | 48 | cmd_buff[4] = Kernel::g_handle_table.Create(start_event).MoveFrom(); |
| 48 | 49 | ||
| 49 | // TODO(bunnei): Check if these events are cleared/signaled every time Initialize is called. | 50 | // TODO(bunnei): Check if these events are cleared every time Initialize is called. |
| 50 | notification_event->Clear(); | 51 | notification_event->Clear(); |
| 51 | pause_event->Signal(); // Fire start event | 52 | start_event->Clear(); |
| 52 | 53 | ||
| 53 | ASSERT_MSG((nullptr != lock), "Cannot initialize without lock"); | 54 | ASSERT_MSG((nullptr != lock), "Cannot initialize without lock"); |
| 54 | lock->Release(); | 55 | lock->Release(); |
| @@ -81,7 +82,7 @@ void NotifyToWait(Service::Interface* self) { | |||
| 81 | u32* cmd_buff = Kernel::GetCommandBuffer(); | 82 | u32* cmd_buff = Kernel::GetCommandBuffer(); |
| 82 | u32 app_id = cmd_buff[1]; | 83 | u32 app_id = cmd_buff[1]; |
| 83 | // TODO(Subv): Verify this, it seems to get SWKBD and Home Menu further. | 84 | // TODO(Subv): Verify this, it seems to get SWKBD and Home Menu further. |
| 84 | pause_event->Signal(); | 85 | start_event->Signal(); |
| 85 | 86 | ||
| 86 | cmd_buff[1] = RESULT_SUCCESS.raw; // No error | 87 | cmd_buff[1] = RESULT_SUCCESS.raw; // No error |
| 87 | LOG_WARNING(Service_APT, "(STUBBED) app_id=%u", app_id); | 88 | LOG_WARNING(Service_APT, "(STUBBED) app_id=%u", app_id); |
| @@ -312,7 +313,7 @@ void Init() { | |||
| 312 | 313 | ||
| 313 | // TODO(bunnei): Check if these are created in Initialize or on APT process startup. | 314 | // TODO(bunnei): Check if these are created in Initialize or on APT process startup. |
| 314 | notification_event = Kernel::Event::Create(RESETTYPE_ONESHOT, "APT_U:Notification"); | 315 | notification_event = Kernel::Event::Create(RESETTYPE_ONESHOT, "APT_U:Notification"); |
| 315 | pause_event = Kernel::Event::Create(RESETTYPE_ONESHOT, "APT_U:Pause"); | 316 | start_event = Kernel::Event::Create(RESETTYPE_ONESHOT, "APT_U:Start"); |
| 316 | } | 317 | } |
| 317 | 318 | ||
| 318 | void Shutdown() { | 319 | void Shutdown() { |
diff --git a/src/core/hle/service/service.cpp b/src/core/hle/service/service.cpp index 134ff1740..d50327cb9 100644 --- a/src/core/hle/service/service.cpp +++ b/src/core/hle/service/service.cpp | |||
| @@ -51,6 +51,49 @@ namespace Service { | |||
| 51 | std::unordered_map<std::string, Kernel::SharedPtr<Interface>> g_kernel_named_ports; | 51 | std::unordered_map<std::string, Kernel::SharedPtr<Interface>> g_kernel_named_ports; |
| 52 | std::unordered_map<std::string, Kernel::SharedPtr<Interface>> g_srv_services; | 52 | std::unordered_map<std::string, Kernel::SharedPtr<Interface>> g_srv_services; |
| 53 | 53 | ||
| 54 | /** | ||
| 55 | * Creates a function string for logging, complete with the name (or header code, depending | ||
| 56 | * on what's passed in) the port name, and all the cmd_buff arguments. | ||
| 57 | */ | ||
| 58 | static std::string MakeFunctionString(const char* name, const char* port_name, const u32* cmd_buff) { | ||
| 59 | // Number of params == bits 0-5 + bits 6-11 | ||
| 60 | int num_params = (cmd_buff[0] & 0x3F) + ((cmd_buff[0] >> 6) & 0x3F); | ||
| 61 | |||
| 62 | std::string function_string = Common::StringFromFormat("function '%s': port=%s", name, port_name); | ||
| 63 | for (int i = 1; i <= num_params; ++i) { | ||
| 64 | function_string += Common::StringFromFormat(", cmd_buff[%i]=%u", i, cmd_buff[i]); | ||
| 65 | } | ||
| 66 | return function_string; | ||
| 67 | } | ||
| 68 | |||
| 69 | ResultVal<bool> Interface::SyncRequest() { | ||
| 70 | u32* cmd_buff = Kernel::GetCommandBuffer(); | ||
| 71 | auto itr = m_functions.find(cmd_buff[0]); | ||
| 72 | |||
| 73 | if (itr == m_functions.end() || itr->second.func == nullptr) { | ||
| 74 | std::string function_name = (itr == m_functions.end()) ? Common::StringFromFormat("0x%08X", cmd_buff[0]) : itr->second.name; | ||
| 75 | LOG_ERROR(Service, "unknown / unimplemented %s", MakeFunctionString(function_name.c_str(), GetPortName().c_str(), cmd_buff).c_str()); | ||
| 76 | |||
| 77 | // TODO(bunnei): Hack - ignore error | ||
| 78 | cmd_buff[1] = 0; | ||
| 79 | return MakeResult<bool>(false); | ||
| 80 | } else { | ||
| 81 | LOG_TRACE(Service, "%s", MakeFunctionString(itr->second.name, GetPortName().c_str(), cmd_buff).c_str()); | ||
| 82 | } | ||
| 83 | |||
| 84 | itr->second.func(this); | ||
| 85 | |||
| 86 | return MakeResult<bool>(false); // TODO: Implement return from actual function | ||
| 87 | } | ||
| 88 | |||
| 89 | void Interface::Register(const FunctionInfo* functions, size_t n) { | ||
| 90 | m_functions.reserve(n); | ||
| 91 | for (size_t i = 0; i < n; ++i) { | ||
| 92 | // Usually this array is sorted by id already, so hint to instead at the end | ||
| 93 | m_functions.emplace_hint(m_functions.cend(), functions[i].id, functions[i]); | ||
| 94 | } | ||
| 95 | } | ||
| 96 | |||
| 54 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 97 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 55 | // Module interface | 98 | // Module interface |
| 56 | 99 | ||
diff --git a/src/core/hle/service/service.h b/src/core/hle/service/service.h index bfe16ebad..21ada67b5 100644 --- a/src/core/hle/service/service.h +++ b/src/core/hle/service/service.h | |||
| @@ -4,20 +4,15 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <algorithm> | ||
| 8 | #include <string> | 7 | #include <string> |
| 9 | #include <unordered_map> | 8 | #include <unordered_map> |
| 10 | #include <vector> | ||
| 11 | 9 | ||
| 12 | #include <boost/container/flat_map.hpp> | 10 | #include <boost/container/flat_map.hpp> |
| 13 | 11 | ||
| 14 | #include "common/common.h" | 12 | #include "common/common.h" |
| 15 | #include "common/string_util.h" | ||
| 16 | #include "core/mem_map.h" | ||
| 17 | 13 | ||
| 18 | #include "core/hle/kernel/kernel.h" | 14 | #include "core/hle/kernel/kernel.h" |
| 19 | #include "core/hle/kernel/session.h" | 15 | #include "core/hle/kernel/session.h" |
| 20 | #include "core/hle/svc.h" | ||
| 21 | 16 | ||
| 22 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 17 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 23 | // Namespace Service | 18 | // Namespace Service |
| @@ -26,31 +21,11 @@ namespace Service { | |||
| 26 | 21 | ||
| 27 | static const int kMaxPortSize = 8; ///< Maximum size of a port name (8 characters) | 22 | static const int kMaxPortSize = 8; ///< Maximum size of a port name (8 characters) |
| 28 | 23 | ||
| 29 | class Manager; | ||
| 30 | |||
| 31 | /// Interface to a CTROS service | 24 | /// Interface to a CTROS service |
| 32 | class Interface : public Kernel::Session { | 25 | class Interface : public Kernel::Session { |
| 33 | // TODO(yuriks): An "Interface" being a Kernel::Object is mostly non-sense. Interface should be | 26 | // TODO(yuriks): An "Interface" being a Kernel::Object is mostly non-sense. Interface should be |
| 34 | // just something that encapsulates a session and acts as a helper to implement service | 27 | // just something that encapsulates a session and acts as a helper to implement service |
| 35 | // processes. | 28 | // processes. |
| 36 | |||
| 37 | friend class Manager; | ||
| 38 | |||
| 39 | /** | ||
| 40 | * Creates a function string for logging, complete with the name (or header code, depending | ||
| 41 | * on what's passed in) the port name, and all the cmd_buff arguments. | ||
| 42 | */ | ||
| 43 | std::string MakeFunctionString(const char* name, const char* port_name, const u32* cmd_buff) { | ||
| 44 | // Number of params == bits 0-5 + bits 6-11 | ||
| 45 | int num_params = (cmd_buff[0] & 0x3F) + ((cmd_buff[0] >> 6) & 0x3F); | ||
| 46 | |||
| 47 | std::string function_string = Common::StringFromFormat("function '%s': port=%s", name, port_name); | ||
| 48 | for (int i = 1; i <= num_params; ++i) { | ||
| 49 | function_string += Common::StringFromFormat(", cmd_buff[%i]=%u", i, cmd_buff[i]); | ||
| 50 | } | ||
| 51 | return function_string; | ||
| 52 | } | ||
| 53 | |||
| 54 | public: | 29 | public: |
| 55 | std::string GetName() const override { return GetPortName(); } | 30 | std::string GetName() const override { return GetPortName(); } |
| 56 | 31 | ||
| @@ -70,25 +45,7 @@ public: | |||
| 70 | return "[UNKNOWN SERVICE PORT]"; | 45 | return "[UNKNOWN SERVICE PORT]"; |
| 71 | } | 46 | } |
| 72 | 47 | ||
| 73 | ResultVal<bool> SyncRequest() override { | 48 | ResultVal<bool> SyncRequest() override; |
| 74 | u32* cmd_buff = Kernel::GetCommandBuffer(); | ||
| 75 | auto itr = m_functions.find(cmd_buff[0]); | ||
| 76 | |||
| 77 | if (itr == m_functions.end() || itr->second.func == nullptr) { | ||
| 78 | std::string function_name = (itr == m_functions.end()) ? Common::StringFromFormat("0x%08X", cmd_buff[0]) : itr->second.name; | ||
| 79 | LOG_ERROR(Service, "unknown / unimplemented %s", MakeFunctionString(function_name.c_str(), GetPortName().c_str(), cmd_buff).c_str()); | ||
| 80 | |||
| 81 | // TODO(bunnei): Hack - ignore error | ||
| 82 | cmd_buff[1] = 0; | ||
| 83 | return MakeResult<bool>(false); | ||
| 84 | } else { | ||
| 85 | LOG_TRACE(Service, "%s", MakeFunctionString(itr->second.name, GetPortName().c_str(), cmd_buff).c_str()); | ||
| 86 | } | ||
| 87 | |||
| 88 | itr->second.func(this); | ||
| 89 | |||
| 90 | return MakeResult<bool>(false); // TODO: Implement return from actual function | ||
| 91 | } | ||
| 92 | 49 | ||
| 93 | protected: | 50 | protected: |
| 94 | 51 | ||
| @@ -96,14 +53,12 @@ protected: | |||
| 96 | * Registers the functions in the service | 53 | * Registers the functions in the service |
| 97 | */ | 54 | */ |
| 98 | template <size_t N> | 55 | template <size_t N> |
| 99 | void Register(const FunctionInfo (&functions)[N]) { | 56 | inline void Register(const FunctionInfo (&functions)[N]) { |
| 100 | m_functions.reserve(N); | 57 | Register(functions, N); |
| 101 | for (auto& fn : functions) { | ||
| 102 | // Usually this array is sorted by id already, so hint to instead at the end | ||
| 103 | m_functions.emplace_hint(m_functions.cend(), fn.id, fn); | ||
| 104 | } | ||
| 105 | } | 58 | } |
| 106 | 59 | ||
| 60 | void Register(const FunctionInfo* functions, size_t n); | ||
| 61 | |||
| 107 | private: | 62 | private: |
| 108 | boost::container::flat_map<u32, FunctionInfo> m_functions; | 63 | boost::container::flat_map<u32, FunctionInfo> m_functions; |
| 109 | 64 | ||
diff --git a/src/core/hle/svc.cpp b/src/core/hle/svc.cpp index bbb4eb9cd..76e9b171a 100644 --- a/src/core/hle/svc.cpp +++ b/src/core/hle/svc.cpp | |||
| @@ -283,8 +283,13 @@ static ResultCode ArbitrateAddress(Handle handle, u32 address, u32 type, u32 val | |||
| 283 | if (arbiter == nullptr) | 283 | if (arbiter == nullptr) |
| 284 | return ERR_INVALID_HANDLE; | 284 | return ERR_INVALID_HANDLE; |
| 285 | 285 | ||
| 286 | return arbiter->ArbitrateAddress(static_cast<Kernel::ArbitrationType>(type), | 286 | auto res = arbiter->ArbitrateAddress(static_cast<Kernel::ArbitrationType>(type), |
| 287 | address, value, nanoseconds); | 287 | address, value, nanoseconds); |
| 288 | |||
| 289 | if (res == RESULT_SUCCESS) | ||
| 290 | HLE::Reschedule(__func__); | ||
| 291 | |||
| 292 | return res; | ||
| 288 | } | 293 | } |
| 289 | 294 | ||
| 290 | /// Used to output a message on a debug hardware unit - does nothing on a retail unit | 295 | /// Used to output a message on a debug hardware unit - does nothing on a retail unit |
| @@ -312,7 +317,7 @@ static ResultCode GetResourceLimitCurrentValues(s64* values, Handle resource_lim | |||
| 312 | } | 317 | } |
| 313 | 318 | ||
| 314 | /// Creates a new thread | 319 | /// Creates a new thread |
| 315 | static ResultCode CreateThread(u32* out_handle, u32 priority, u32 entry_point, u32 arg, u32 stack_top, u32 processor_id) { | 320 | static ResultCode CreateThread(Handle* out_handle, s32 priority, u32 entry_point, u32 arg, u32 stack_top, s32 processor_id) { |
| 316 | using Kernel::Thread; | 321 | using Kernel::Thread; |
| 317 | 322 | ||
| 318 | std::string name; | 323 | std::string name; |
| @@ -323,6 +328,27 @@ static ResultCode CreateThread(u32* out_handle, u32 priority, u32 entry_point, u | |||
| 323 | name = Common::StringFromFormat("unknown-%08x", entry_point); | 328 | name = Common::StringFromFormat("unknown-%08x", entry_point); |
| 324 | } | 329 | } |
| 325 | 330 | ||
| 331 | // TODO(bunnei): Implement resource limits to return an error code instead of the below assert. | ||
| 332 | // The error code should be: Description::NotAuthorized, Module::OS, Summary::WrongArgument, | ||
| 333 | // Level::Permanent | ||
| 334 | ASSERT_MSG(priority >= THREADPRIO_USERLAND_MAX, "Unexpected thread priority!"); | ||
| 335 | |||
| 336 | if (priority > THREADPRIO_LOWEST) { | ||
| 337 | return ResultCode(ErrorDescription::OutOfRange, ErrorModule::OS, | ||
| 338 | ErrorSummary::InvalidArgument, ErrorLevel::Usage); | ||
| 339 | } | ||
| 340 | |||
| 341 | switch (processor_id) { | ||
| 342 | case THREADPROCESSORID_DEFAULT: | ||
| 343 | case THREADPROCESSORID_0: | ||
| 344 | case THREADPROCESSORID_1: | ||
| 345 | break; | ||
| 346 | default: | ||
| 347 | // TODO(bunnei): Implement support for other processor IDs | ||
| 348 | ASSERT_MSG(false, "Unsupported thread processor ID: %d", processor_id); | ||
| 349 | break; | ||
| 350 | } | ||
| 351 | |||
| 326 | CASCADE_RESULT(SharedPtr<Thread> thread, Kernel::Thread::Create( | 352 | CASCADE_RESULT(SharedPtr<Thread> thread, Kernel::Thread::Create( |
| 327 | name, entry_point, priority, arg, processor_id, stack_top)); | 353 | name, entry_point, priority, arg, processor_id, stack_top)); |
| 328 | CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(thread))); | 354 | CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(thread))); |
| @@ -331,10 +357,7 @@ static ResultCode CreateThread(u32* out_handle, u32 priority, u32 entry_point, u | |||
| 331 | "threadpriority=0x%08X, processorid=0x%08X : created handle=0x%08X", entry_point, | 357 | "threadpriority=0x%08X, processorid=0x%08X : created handle=0x%08X", entry_point, |
| 332 | name.c_str(), arg, stack_top, priority, processor_id, *out_handle); | 358 | name.c_str(), arg, stack_top, priority, processor_id, *out_handle); |
| 333 | 359 | ||
| 334 | if (THREADPROCESSORID_1 == processor_id) { | 360 | HLE::Reschedule(__func__); |
| 335 | LOG_WARNING(Kernel_SVC, | ||
| 336 | "thread designated for system CPU core (UNIMPLEMENTED) will be run with app core scheduling"); | ||
| 337 | } | ||
| 338 | 361 | ||
| 339 | return RESULT_SUCCESS; | 362 | return RESULT_SUCCESS; |
| 340 | } | 363 | } |
| @@ -374,8 +397,11 @@ static ResultCode CreateMutex(Handle* out_handle, u32 initial_locked) { | |||
| 374 | SharedPtr<Mutex> mutex = Mutex::Create(initial_locked != 0); | 397 | SharedPtr<Mutex> mutex = Mutex::Create(initial_locked != 0); |
| 375 | CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(mutex))); | 398 | CASCADE_RESULT(*out_handle, Kernel::g_handle_table.Create(std::move(mutex))); |
| 376 | 399 | ||
| 400 | HLE::Reschedule(__func__); | ||
| 401 | |||
| 377 | LOG_TRACE(Kernel_SVC, "called initial_locked=%s : created handle=0x%08X", | 402 | LOG_TRACE(Kernel_SVC, "called initial_locked=%s : created handle=0x%08X", |
| 378 | initial_locked ? "true" : "false", *out_handle); | 403 | initial_locked ? "true" : "false", *out_handle); |
| 404 | |||
| 379 | return RESULT_SUCCESS; | 405 | return RESULT_SUCCESS; |
| 380 | } | 406 | } |
| 381 | 407 | ||
| @@ -390,6 +416,9 @@ static ResultCode ReleaseMutex(Handle handle) { | |||
| 390 | return ERR_INVALID_HANDLE; | 416 | return ERR_INVALID_HANDLE; |
| 391 | 417 | ||
| 392 | mutex->Release(); | 418 | mutex->Release(); |
| 419 | |||
| 420 | HLE::Reschedule(__func__); | ||
| 421 | |||
| 393 | return RESULT_SUCCESS; | 422 | return RESULT_SUCCESS; |
| 394 | } | 423 | } |
| 395 | 424 | ||
| @@ -428,6 +457,9 @@ static ResultCode ReleaseSemaphore(s32* count, Handle handle, s32 release_count) | |||
| 428 | return ERR_INVALID_HANDLE; | 457 | return ERR_INVALID_HANDLE; |
| 429 | 458 | ||
| 430 | CASCADE_RESULT(*count, semaphore->Release(release_count)); | 459 | CASCADE_RESULT(*count, semaphore->Release(release_count)); |
| 460 | |||
| 461 | HLE::Reschedule(__func__); | ||
| 462 | |||
| 431 | return RESULT_SUCCESS; | 463 | return RESULT_SUCCESS; |
| 432 | } | 464 | } |
| 433 | 465 | ||
| @@ -520,6 +552,9 @@ static ResultCode SetTimer(Handle handle, s64 initial, s64 interval) { | |||
| 520 | return ERR_INVALID_HANDLE; | 552 | return ERR_INVALID_HANDLE; |
| 521 | 553 | ||
| 522 | timer->Set(initial, interval); | 554 | timer->Set(initial, interval); |
| 555 | |||
| 556 | HLE::Reschedule(__func__); | ||
| 557 | |||
| 523 | return RESULT_SUCCESS; | 558 | return RESULT_SUCCESS; |
| 524 | } | 559 | } |
| 525 | 560 | ||
| @@ -534,6 +569,9 @@ static ResultCode CancelTimer(Handle handle) { | |||
| 534 | return ERR_INVALID_HANDLE; | 569 | return ERR_INVALID_HANDLE; |
| 535 | 570 | ||
| 536 | timer->Cancel(); | 571 | timer->Cancel(); |
| 572 | |||
| 573 | HLE::Reschedule(__func__); | ||
| 574 | |||
| 537 | return RESULT_SUCCESS; | 575 | return RESULT_SUCCESS; |
| 538 | } | 576 | } |
| 539 | 577 | ||