summaryrefslogtreecommitdiff
path: root/src/core
diff options
context:
space:
mode:
Diffstat (limited to 'src/core')
-rw-r--r--src/core/core.cpp29
-rw-r--r--src/core/core.h17
-rw-r--r--src/core/file_sys/archive_ncch.cpp39
-rw-r--r--src/core/hle/service/apt/apt.cpp2
-rw-r--r--src/core/hle/service/err_f.cpp2
-rw-r--r--src/core/hle/service/fs/archive.cpp4
-rw-r--r--src/core/hle/service/fs/fs_user.cpp3
-rw-r--r--src/core/loader/loader.h7
-rw-r--r--src/core/loader/ncch.cpp12
-rw-r--r--src/core/loader/ncch.h4
10 files changed, 96 insertions, 23 deletions
diff --git a/src/core/core.cpp b/src/core/core.cpp
index 450e7566d..5429bcb26 100644
--- a/src/core/core.cpp
+++ b/src/core/core.cpp
@@ -3,7 +3,7 @@
3// Refer to the license.txt file included. 3// Refer to the license.txt file included.
4 4
5#include <memory> 5#include <memory>
6 6#include <utility>
7#include "audio_core/audio_core.h" 7#include "audio_core/audio_core.h"
8#include "common/logging/log.h" 8#include "common/logging/log.h"
9#include "core/arm/arm_interface.h" 9#include "core/arm/arm_interface.h"
@@ -26,6 +26,7 @@ namespace Core {
26/*static*/ System System::s_instance; 26/*static*/ System System::s_instance;
27 27
28System::ResultStatus System::RunLoop(int tight_loop) { 28System::ResultStatus System::RunLoop(int tight_loop) {
29 status = ResultStatus::Success;
29 if (!cpu_core) { 30 if (!cpu_core) {
30 return ResultStatus::ErrorNotInitialized; 31 return ResultStatus::ErrorNotInitialized;
31 } 32 }
@@ -59,7 +60,7 @@ System::ResultStatus System::RunLoop(int tight_loop) {
59 HW::Update(); 60 HW::Update();
60 Reschedule(); 61 Reschedule();
61 62
62 return ResultStatus::Success; 63 return status;
63} 64}
64 65
65System::ResultStatus System::SingleStep() { 66System::ResultStatus System::SingleStep() {
@@ -73,14 +74,25 @@ System::ResultStatus System::Load(EmuWindow* emu_window, const std::string& file
73 LOG_CRITICAL(Core, "Failed to obtain loader for %s!", filepath.c_str()); 74 LOG_CRITICAL(Core, "Failed to obtain loader for %s!", filepath.c_str());
74 return ResultStatus::ErrorGetLoader; 75 return ResultStatus::ErrorGetLoader;
75 } 76 }
77 std::pair<boost::optional<u32>, Loader::ResultStatus> system_mode =
78 app_loader->LoadKernelSystemMode();
79
80 if (system_mode.second != Loader::ResultStatus::Success) {
81 LOG_CRITICAL(Core, "Failed to determine system mode (Error %i)!",
82 static_cast<int>(system_mode.second));
83 System::Shutdown();
76 84
77 boost::optional<u32> system_mode{app_loader->LoadKernelSystemMode()}; 85 switch (system_mode.second) {
78 if (!system_mode) { 86 case Loader::ResultStatus::ErrorEncrypted:
79 LOG_CRITICAL(Core, "Failed to determine system mode!"); 87 return ResultStatus::ErrorLoader_ErrorEncrypted;
80 return ResultStatus::ErrorSystemMode; 88 case Loader::ResultStatus::ErrorInvalidFormat:
89 return ResultStatus::ErrorLoader_ErrorInvalidFormat;
90 default:
91 return ResultStatus::ErrorSystemMode;
92 }
81 } 93 }
82 94
83 ResultStatus init_result{Init(emu_window, system_mode.get())}; 95 ResultStatus init_result{Init(emu_window, system_mode.first.get())};
84 if (init_result != ResultStatus::Success) { 96 if (init_result != ResultStatus::Success) {
85 LOG_CRITICAL(Core, "Failed to initialize system (Error %i)!", init_result); 97 LOG_CRITICAL(Core, "Failed to initialize system (Error %i)!", init_result);
86 System::Shutdown(); 98 System::Shutdown();
@@ -101,7 +113,8 @@ System::ResultStatus System::Load(EmuWindow* emu_window, const std::string& file
101 return ResultStatus::ErrorLoader; 113 return ResultStatus::ErrorLoader;
102 } 114 }
103 } 115 }
104 return ResultStatus::Success; 116 status = ResultStatus::Success;
117 return status;
105} 118}
106 119
107void System::PrepareReschedule() { 120void System::PrepareReschedule() {
diff --git a/src/core/core.h b/src/core/core.h
index 6af772831..4e3b6b409 100644
--- a/src/core/core.h
+++ b/src/core/core.h
@@ -40,7 +40,10 @@ public:
40 ErrorLoader_ErrorEncrypted, ///< Error loading the specified application due to encryption 40 ErrorLoader_ErrorEncrypted, ///< Error loading the specified application due to encryption
41 ErrorLoader_ErrorInvalidFormat, ///< Error loading the specified application due to an 41 ErrorLoader_ErrorInvalidFormat, ///< Error loading the specified application due to an
42 /// invalid format 42 /// invalid format
43 ErrorSystemFiles, ///< Error in finding system files
44 ErrorSharedFont, ///< Error in finding shared font
43 ErrorVideoCore, ///< Error in the video core 45 ErrorVideoCore, ///< Error in the video core
46 ErrorUnknown ///< Any other error
44 }; 47 };
45 48
46 /** 49 /**
@@ -105,6 +108,17 @@ public:
105 PerfStats perf_stats; 108 PerfStats perf_stats;
106 FrameLimiter frame_limiter; 109 FrameLimiter frame_limiter;
107 110
111 void SetStatus(ResultStatus new_status, const char* details = nullptr) {
112 status = new_status;
113 if (details) {
114 status_details = details;
115 }
116 }
117
118 const std::string& GetStatusDetails() const {
119 return status_details;
120 }
121
108private: 122private:
109 /** 123 /**
110 * Initialize the emulated system. 124 * Initialize the emulated system.
@@ -130,6 +144,9 @@ private:
130 std::unique_ptr<Core::TelemetrySession> telemetry_session; 144 std::unique_ptr<Core::TelemetrySession> telemetry_session;
131 145
132 static System s_instance; 146 static System s_instance;
147
148 ResultStatus status = ResultStatus::Success;
149 std::string status_details = "";
133}; 150};
134 151
135inline ARM_Interface& CPU() { 152inline ARM_Interface& CPU() {
diff --git a/src/core/file_sys/archive_ncch.cpp b/src/core/file_sys/archive_ncch.cpp
index 89455e39c..6d9007731 100644
--- a/src/core/file_sys/archive_ncch.cpp
+++ b/src/core/file_sys/archive_ncch.cpp
@@ -9,7 +9,9 @@
9#include "common/file_util.h" 9#include "common/file_util.h"
10#include "common/logging/log.h" 10#include "common/logging/log.h"
11#include "common/string_util.h" 11#include "common/string_util.h"
12#include "core/core.h"
12#include "core/file_sys/archive_ncch.h" 13#include "core/file_sys/archive_ncch.h"
14#include "core/file_sys/errors.h"
13#include "core/file_sys/ivfc_archive.h" 15#include "core/file_sys/ivfc_archive.h"
14#include "core/hle/service/fs/archive.h" 16#include "core/hle/service/fs/archive.h"
15 17
@@ -33,11 +35,44 @@ ArchiveFactory_NCCH::ArchiveFactory_NCCH(const std::string& nand_directory)
33ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_NCCH::Open(const Path& path) { 35ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_NCCH::Open(const Path& path) {
34 auto vec = path.AsBinary(); 36 auto vec = path.AsBinary();
35 const u32* data = reinterpret_cast<u32*>(vec.data()); 37 const u32* data = reinterpret_cast<u32*>(vec.data());
36 std::string file_path = GetNCCHPath(mount_point, data[1], data[0]); 38 u32 high = data[1];
39 u32 low = data[0];
40 std::string file_path = GetNCCHPath(mount_point, high, low);
37 auto file = std::make_shared<FileUtil::IOFile>(file_path, "rb"); 41 auto file = std::make_shared<FileUtil::IOFile>(file_path, "rb");
38 42
39 if (!file->IsOpen()) { 43 if (!file->IsOpen()) {
40 return ResultCode(-1); // TODO(Subv): Find the right error code 44 // High Title ID of the archive: The category (https://3dbrew.org/wiki/Title_list).
45 constexpr u32 shared_data_archive = 0x0004009B;
46 constexpr u32 system_data_archive = 0x000400DB;
47
48 // Low Title IDs.
49 constexpr u32 mii_data = 0x00010202;
50 constexpr u32 region_manifest = 0x00010402;
51 constexpr u32 ng_word_list = 0x00010302;
52
53 LOG_DEBUG(Service_FS, "Full Path: %s. Category: 0x%X. Path: 0x%X.", path.DebugStr().c_str(),
54 high, low);
55
56 if (high == shared_data_archive) {
57 if (low == mii_data) {
58 LOG_ERROR(Service_FS, "Failed to get a handle for shared data archive: Mii data. ");
59 Core::System::GetInstance().SetStatus(Core::System::ResultStatus::ErrorSystemFiles,
60 "Mii data");
61 } else if (low == region_manifest) {
62 LOG_ERROR(Service_FS,
63 "Failed to get a handle for shared data archive: region manifest.");
64 Core::System::GetInstance().SetStatus(Core::System::ResultStatus::ErrorSystemFiles,
65 "Region manifest");
66 }
67 } else if (high == system_data_archive) {
68 if (low == ng_word_list) {
69 LOG_ERROR(Service_FS,
70 "Failed to get a handle for system data archive: NG bad word list.");
71 Core::System::GetInstance().SetStatus(Core::System::ResultStatus::ErrorSystemFiles,
72 "NG bad word list");
73 }
74 }
75 return ERROR_NOT_FOUND;
41 } 76 }
42 auto size = file->GetSize(); 77 auto size = file->GetSize();
43 78
diff --git a/src/core/hle/service/apt/apt.cpp b/src/core/hle/service/apt/apt.cpp
index 366d1eacf..4c587e3c8 100644
--- a/src/core/hle/service/apt/apt.cpp
+++ b/src/core/hle/service/apt/apt.cpp
@@ -5,6 +5,7 @@
5#include "common/common_paths.h" 5#include "common/common_paths.h"
6#include "common/file_util.h" 6#include "common/file_util.h"
7#include "common/logging/log.h" 7#include "common/logging/log.h"
8#include "core/core.h"
8#include "core/hle/applets/applet.h" 9#include "core/hle/applets/applet.h"
9#include "core/hle/kernel/event.h" 10#include "core/hle/kernel/event.h"
10#include "core/hle/kernel/mutex.h" 11#include "core/hle/kernel/mutex.h"
@@ -74,6 +75,7 @@ void GetSharedFont(Service::Interface* self) {
74 LOG_ERROR(Service_APT, "shared font file missing - go dump it from your 3ds"); 75 LOG_ERROR(Service_APT, "shared font file missing - go dump it from your 3ds");
75 rb.Push<u32>(-1); // TODO: Find the right error code 76 rb.Push<u32>(-1); // TODO: Find the right error code
76 rb.Skip(1 + 2, true); 77 rb.Skip(1 + 2, true);
78 Core::System::GetInstance().SetStatus(Core::System::ResultStatus::ErrorSharedFont);
77 return; 79 return;
78 } 80 }
79 81
diff --git a/src/core/hle/service/err_f.cpp b/src/core/hle/service/err_f.cpp
index 9da55f328..4f4dc6dc7 100644
--- a/src/core/hle/service/err_f.cpp
+++ b/src/core/hle/service/err_f.cpp
@@ -10,6 +10,7 @@
10#include "common/bit_field.h" 10#include "common/bit_field.h"
11#include "common/common_types.h" 11#include "common/common_types.h"
12#include "common/logging/log.h" 12#include "common/logging/log.h"
13#include "core/core.h"
13#include "core/hle/result.h" 14#include "core/hle/result.h"
14#include "core/hle/service/err_f.h" 15#include "core/hle/service/err_f.h"
15 16
@@ -172,6 +173,7 @@ static void ThrowFatalError(Interface* self) {
172 const ErrInfo* errinfo = reinterpret_cast<ErrInfo*>(&cmd_buff[1]); 173 const ErrInfo* errinfo = reinterpret_cast<ErrInfo*>(&cmd_buff[1]);
173 LOG_CRITICAL(Service_ERR, "Fatal error type: %s", 174 LOG_CRITICAL(Service_ERR, "Fatal error type: %s",
174 GetErrType(errinfo->errinfo_common.specifier).c_str()); 175 GetErrType(errinfo->errinfo_common.specifier).c_str());
176 Core::System::GetInstance().SetStatus(Core::System::ResultStatus::ErrorUnknown);
175 177
176 // Generic Info 178 // Generic Info
177 LogGenericInfo(errinfo->errinfo_common); 179 LogGenericInfo(errinfo->errinfo_common);
diff --git a/src/core/hle/service/fs/archive.cpp b/src/core/hle/service/fs/archive.cpp
index 632712f2c..21929e966 100644
--- a/src/core/hle/service/fs/archive.cpp
+++ b/src/core/hle/service/fs/archive.cpp
@@ -258,9 +258,7 @@ ResultVal<ArchiveHandle> OpenArchive(ArchiveIdCode id_code, FileSys::Path& archi
258 258
259 auto itr = id_code_map.find(id_code); 259 auto itr = id_code_map.find(id_code);
260 if (itr == id_code_map.end()) { 260 if (itr == id_code_map.end()) {
261 // TODO: Verify error against hardware 261 return FileSys::ERROR_NOT_FOUND;
262 return ResultCode(ErrorDescription::NotFound, ErrorModule::FS, ErrorSummary::NotFound,
263 ErrorLevel::Permanent);
264 } 262 }
265 263
266 CASCADE_RESULT(std::unique_ptr<ArchiveBackend> res, itr->second->Open(archive_path)); 264 CASCADE_RESULT(std::unique_ptr<ArchiveBackend> res, itr->second->Open(archive_path));
diff --git a/src/core/hle/service/fs/fs_user.cpp b/src/core/hle/service/fs/fs_user.cpp
index e53a970d3..c1825e9c8 100644
--- a/src/core/hle/service/fs/fs_user.cpp
+++ b/src/core/hle/service/fs/fs_user.cpp
@@ -8,6 +8,7 @@
8#include "common/logging/log.h" 8#include "common/logging/log.h"
9#include "common/scope_exit.h" 9#include "common/scope_exit.h"
10#include "common/string_util.h" 10#include "common/string_util.h"
11#include "core/core.h"
11#include "core/file_sys/errors.h" 12#include "core/file_sys/errors.h"
12#include "core/hle/kernel/client_session.h" 13#include "core/hle/kernel/client_session.h"
13#include "core/hle/result.h" 14#include "core/hle/result.h"
@@ -130,7 +131,7 @@ static void OpenFileDirectly(Service::Interface* self) {
130 ResultVal<ArchiveHandle> archive_handle = OpenArchive(archive_id, archive_path); 131 ResultVal<ArchiveHandle> archive_handle = OpenArchive(archive_id, archive_path);
131 if (archive_handle.Failed()) { 132 if (archive_handle.Failed()) {
132 LOG_ERROR(Service_FS, 133 LOG_ERROR(Service_FS,
133 "failed to get a handle for archive archive_id=0x%08X archive_path=%s", 134 "Failed to get a handle for archive archive_id=0x%08X archive_path=%s",
134 static_cast<u32>(archive_id), archive_path.DebugStr().c_str()); 135 static_cast<u32>(archive_id), archive_path.DebugStr().c_str());
135 cmd_buff[1] = archive_handle.Code().raw; 136 cmd_buff[1] = archive_handle.Code().raw;
136 cmd_buff[3] = 0; 137 cmd_buff[3] = 0;
diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h
index 1d80766ae..48bbf687d 100644
--- a/src/core/loader/loader.h
+++ b/src/core/loader/loader.h
@@ -8,6 +8,7 @@
8#include <initializer_list> 8#include <initializer_list>
9#include <memory> 9#include <memory>
10#include <string> 10#include <string>
11#include <utility>
11#include <vector> 12#include <vector>
12#include <boost/optional.hpp> 13#include <boost/optional.hpp>
13#include "common/common_types.h" 14#include "common/common_types.h"
@@ -100,11 +101,11 @@ public:
100 * Loads the system mode that this application needs. 101 * Loads the system mode that this application needs.
101 * This function defaults to 2 (96MB allocated to the application) if it can't read the 102 * This function defaults to 2 (96MB allocated to the application) if it can't read the
102 * information. 103 * information.
103 * @returns Optional with the kernel system mode 104 * @returns A pair with the optional system mode, and and the status.
104 */ 105 */
105 virtual boost::optional<u32> LoadKernelSystemMode() { 106 virtual std::pair<boost::optional<u32>, ResultStatus> LoadKernelSystemMode() {
106 // 96MB allocated to the application. 107 // 96MB allocated to the application.
107 return 2; 108 return std::make_pair(2, ResultStatus::Success);
108 } 109 }
109 110
110 /** 111 /**
diff --git a/src/core/loader/ncch.cpp b/src/core/loader/ncch.cpp
index beeb13ffa..ffc019560 100644
--- a/src/core/loader/ncch.cpp
+++ b/src/core/loader/ncch.cpp
@@ -121,12 +121,16 @@ FileType AppLoader_NCCH::IdentifyType(FileUtil::IOFile& file) {
121 return FileType::Error; 121 return FileType::Error;
122} 122}
123 123
124boost::optional<u32> AppLoader_NCCH::LoadKernelSystemMode() { 124std::pair<boost::optional<u32>, ResultStatus> AppLoader_NCCH::LoadKernelSystemMode() {
125 if (!is_loaded) { 125 if (!is_loaded) {
126 if (LoadExeFS() != ResultStatus::Success) 126 ResultStatus res = LoadExeFS();
127 return boost::none; 127 if (res != ResultStatus::Success) {
128 return std::make_pair(boost::none, res);
129 }
128 } 130 }
129 return exheader_header.arm11_system_local_caps.system_mode.Value(); 131 // Set the system mode as the one from the exheader.
132 return std::make_pair(exheader_header.arm11_system_local_caps.system_mode.Value(),
133 ResultStatus::Success);
130} 134}
131 135
132ResultStatus AppLoader_NCCH::LoadExec() { 136ResultStatus AppLoader_NCCH::LoadExec() {
diff --git a/src/core/loader/ncch.h b/src/core/loader/ncch.h
index 4ef95b5c6..0ebd47fd5 100644
--- a/src/core/loader/ncch.h
+++ b/src/core/loader/ncch.h
@@ -179,9 +179,9 @@ public:
179 179
180 /** 180 /**
181 * Loads the Exheader and returns the system mode for this application. 181 * Loads the Exheader and returns the system mode for this application.
182 * @return Optional with the kernel system mode 182 * @returns A pair with the optional system mode, and and the status.
183 */ 183 */
184 boost::optional<u32> LoadKernelSystemMode() override; 184 std::pair<boost::optional<u32>, ResultStatus> LoadKernelSystemMode() override;
185 185
186 ResultStatus ReadCode(std::vector<u8>& buffer) override; 186 ResultStatus ReadCode(std::vector<u8>& buffer) override;
187 187