diff options
| author | 2014-06-16 23:18:10 -0400 | |
|---|---|---|
| committer | 2014-06-16 23:43:33 -0400 | |
| commit | 13bdaa6c609a8718d4ce6ca3ce5f1e16f4d7c600 (patch) | |
| tree | 5d8cc87a93620948424be3bee61c206279f4dc7a /src/core/loader/loader.cpp | |
| parent | Elf: Renamed modules to be consistent with new loader naming, fixed tabs -> s... (diff) | |
| download | yuzu-13bdaa6c609a8718d4ce6ca3ce5f1e16f4d7c600.tar.gz yuzu-13bdaa6c609a8718d4ce6ca3ce5f1e16f4d7c600.tar.xz yuzu-13bdaa6c609a8718d4ce6ca3ce5f1e16f4d7c600.zip | |
Loader: Cleaned up and removed unused code, refactored ELF namespace.
Diffstat (limited to 'src/core/loader/loader.cpp')
| -rw-r--r-- | src/core/loader/loader.cpp | 142 |
1 files changed, 3 insertions, 139 deletions
diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp index d8060c0e6..1a647d8a5 100644 --- a/src/core/loader/loader.cpp +++ b/src/core/loader/loader.cpp | |||
| @@ -2,98 +2,14 @@ | |||
| 2 | // Licensed under GPLv2 | 2 | // Licensed under GPLv2 |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "common/common_types.h" | ||
| 6 | #include "common/file_util.h" | ||
| 7 | |||
| 8 | #include "core/loader/loader.h" | 5 | #include "core/loader/loader.h" |
| 9 | #include "core/loader/elf.h" | 6 | #include "core/loader/elf.h" |
| 10 | #include "core/loader/ncch.h" | 7 | #include "core/loader/ncch.h" |
| 11 | #include "core/system.h" | ||
| 12 | #include "core/core.h" | ||
| 13 | #include "core/hle/kernel/kernel.h" | ||
| 14 | #include "core/mem_map.h" | ||
| 15 | 8 | ||
| 16 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 9 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 17 | 10 | ||
| 18 | /// Loads a CTR ELF file | ||
| 19 | bool Load_ELF(std::string &filename) { | ||
| 20 | std::string full_path = filename; | ||
| 21 | std::string path, file, extension; | ||
| 22 | SplitPath(ReplaceAll(full_path, "\\", "/"), &path, &file, &extension); | ||
| 23 | #if EMU_PLATFORM == PLATFORM_WINDOWS | ||
| 24 | path = ReplaceAll(path, "/", "\\"); | ||
| 25 | #endif | ||
| 26 | File::IOFile f(filename, "rb"); | ||
| 27 | |||
| 28 | if (f.IsOpen()) { | ||
| 29 | u64 size = f.GetSize(); | ||
| 30 | u8* buffer = new u8[size]; | ||
| 31 | ElfReader* elf_reader = NULL; | ||
| 32 | |||
| 33 | f.ReadBytes(buffer, size); | ||
| 34 | |||
| 35 | elf_reader = new ElfReader(buffer); | ||
| 36 | elf_reader->LoadInto(0x00100000); | ||
| 37 | |||
| 38 | Kernel::LoadExec(elf_reader->GetEntryPoint()); | ||
| 39 | |||
| 40 | delete[] buffer; | ||
| 41 | delete elf_reader; | ||
| 42 | } else { | ||
| 43 | return false; | ||
| 44 | } | ||
| 45 | f.Close(); | ||
| 46 | |||
| 47 | return true; | ||
| 48 | } | ||
| 49 | |||
| 50 | /// Loads a CTR BIN file extracted from an ExeFS | ||
| 51 | bool Load_BIN(std::string &filename) { | ||
| 52 | std::string full_path = filename; | ||
| 53 | std::string path, file, extension; | ||
| 54 | SplitPath(ReplaceAll(full_path, "\\", "/"), &path, &file, &extension); | ||
| 55 | #if EMU_PLATFORM == PLATFORM_WINDOWS | ||
| 56 | path = ReplaceAll(path, "/", "\\"); | ||
| 57 | #endif | ||
| 58 | File::IOFile f(filename, "rb"); | ||
| 59 | |||
| 60 | if (f.IsOpen()) { | ||
| 61 | u64 size = f.GetSize(); | ||
| 62 | u8* buffer = new u8[size]; | ||
| 63 | |||
| 64 | f.ReadBytes(buffer, size); | ||
| 65 | |||
| 66 | u32 entry_point = 0x00100000; // Hardcoded, read from exheader | ||
| 67 | |||
| 68 | const u8 *src = buffer; | ||
| 69 | u8 *dst = Memory::GetPointer(entry_point); | ||
| 70 | u32 srcSize = size; | ||
| 71 | u32 *s = (u32*)src; | ||
| 72 | u32 *d = (u32*)dst; | ||
| 73 | for (int j = 0; j < (int)(srcSize + 3) / 4; j++) | ||
| 74 | { | ||
| 75 | *d++ = (*s++); | ||
| 76 | } | ||
| 77 | |||
| 78 | Kernel::LoadExec(entry_point); | ||
| 79 | |||
| 80 | delete[] buffer; | ||
| 81 | } | ||
| 82 | else { | ||
| 83 | return false; | ||
| 84 | } | ||
| 85 | f.Close(); | ||
| 86 | |||
| 87 | return true; | ||
| 88 | } | ||
| 89 | |||
| 90 | namespace Loader { | 11 | namespace Loader { |
| 91 | 12 | ||
| 92 | bool IsBootableDirectory() { | ||
| 93 | ERROR_LOG(TIME, "Unimplemented function!"); | ||
| 94 | return true; | ||
| 95 | } | ||
| 96 | |||
| 97 | /** | 13 | /** |
| 98 | * Identifies the type of a bootable file | 14 | * Identifies the type of a bootable file |
| 99 | * @param filename String filename of bootable file | 15 | * @param filename String filename of bootable file |
| @@ -107,15 +23,7 @@ FileType IdentifyFile(std::string &filename) { | |||
| 107 | } | 23 | } |
| 108 | std::string extension = filename.size() >= 5 ? filename.substr(filename.size() - 4) : ""; | 24 | std::string extension = filename.size() >= 5 ? filename.substr(filename.size() - 4) : ""; |
| 109 | 25 | ||
| 110 | if (File::IsDirectory(filename)) { | 26 | if (!strcasecmp(extension.c_str(), ".elf")) { |
| 111 | if (IsBootableDirectory()) { | ||
| 112 | return FILETYPE_DIRECTORY_CXI; | ||
| 113 | } | ||
| 114 | else { | ||
| 115 | return FILETYPE_NORMAL_DIRECTORY; | ||
| 116 | } | ||
| 117 | } | ||
| 118 | else if (!strcasecmp(extension.c_str(), ".elf")) { | ||
| 119 | return FILETYPE_CTR_ELF; // TODO(bunnei): Do some filetype checking :p | 27 | return FILETYPE_CTR_ELF; // TODO(bunnei): Do some filetype checking :p |
| 120 | } | 28 | } |
| 121 | else if (!strcasecmp(extension.c_str(), ".axf")) { | 29 | else if (!strcasecmp(extension.c_str(), ".axf")) { |
| @@ -127,24 +35,6 @@ FileType IdentifyFile(std::string &filename) { | |||
| 127 | else if (!strcasecmp(extension.c_str(), ".cci")) { | 35 | else if (!strcasecmp(extension.c_str(), ".cci")) { |
| 128 | return FILETYPE_CTR_CCI; // TODO(bunnei): Do some filetype checking :p | 36 | return FILETYPE_CTR_CCI; // TODO(bunnei): Do some filetype checking :p |
| 129 | } | 37 | } |
| 130 | else if (!strcasecmp(extension.c_str(), ".bin")) { | ||
| 131 | return FILETYPE_CTR_BIN; | ||
| 132 | } | ||
| 133 | else if (!strcasecmp(extension.c_str(), ".dat")) { | ||
| 134 | return FILETYPE_LAUNCHER_DAT; | ||
| 135 | } | ||
| 136 | else if (!strcasecmp(extension.c_str(), ".zip")) { | ||
| 137 | return FILETYPE_ARCHIVE_ZIP; | ||
| 138 | } | ||
| 139 | else if (!strcasecmp(extension.c_str(), ".rar")) { | ||
| 140 | return FILETYPE_ARCHIVE_RAR; | ||
| 141 | } | ||
| 142 | else if (!strcasecmp(extension.c_str(), ".r00")) { | ||
| 143 | return FILETYPE_ARCHIVE_RAR; | ||
| 144 | } | ||
| 145 | else if (!strcasecmp(extension.c_str(), ".r01")) { | ||
| 146 | return FILETYPE_ARCHIVE_RAR; | ||
| 147 | } | ||
| 148 | return FILETYPE_UNKNOWN; | 38 | return FILETYPE_UNKNOWN; |
| 149 | } | 39 | } |
| 150 | 40 | ||
| @@ -161,10 +51,7 @@ bool LoadFile(std::string &filename, std::string *error_string) { | |||
| 161 | switch (IdentifyFile(filename)) { | 51 | switch (IdentifyFile(filename)) { |
| 162 | 52 | ||
| 163 | case FILETYPE_CTR_ELF: | 53 | case FILETYPE_CTR_ELF: |
| 164 | return Load_ELF(filename); | 54 | return Loader::Load_ELF(filename, error_string); |
| 165 | |||
| 166 | case FILETYPE_CTR_BIN: | ||
| 167 | return Load_BIN(filename); | ||
| 168 | 55 | ||
| 169 | case FILETYPE_CTR_CXI: | 56 | case FILETYPE_CTR_CXI: |
| 170 | case FILETYPE_CTR_CCI: | 57 | case FILETYPE_CTR_CCI: |
| @@ -175,29 +62,6 @@ bool LoadFile(std::string &filename, std::string *error_string) { | |||
| 175 | *error_string = "Error reading file"; | 62 | *error_string = "Error reading file"; |
| 176 | break; | 63 | break; |
| 177 | 64 | ||
| 178 | case FILETYPE_ARCHIVE_RAR: | ||
| 179 | #ifdef WIN32 | ||
| 180 | *error_string = "RAR file detected (Require WINRAR)"; | ||
| 181 | #else | ||
| 182 | *error_string = "RAR file detected (Require UnRAR)"; | ||
| 183 | #endif | ||
| 184 | break; | ||
| 185 | |||
| 186 | case FILETYPE_ARCHIVE_ZIP: | ||
| 187 | #ifdef WIN32 | ||
| 188 | *error_string = "ZIP file detected (Require WINRAR)"; | ||
| 189 | #else | ||
| 190 | *error_string = "ZIP file detected (Require UnRAR)"; | ||
| 191 | #endif | ||
| 192 | break; | ||
| 193 | |||
| 194 | case FILETYPE_NORMAL_DIRECTORY: | ||
| 195 | ERROR_LOG(LOADER, "Just a directory."); | ||
| 196 | *error_string = "Just a directory."; | ||
| 197 | break; | ||
| 198 | |||
| 199 | case FILETYPE_UNKNOWN_BIN: | ||
| 200 | case FILETYPE_UNKNOWN_ELF: | ||
| 201 | case FILETYPE_UNKNOWN: | 65 | case FILETYPE_UNKNOWN: |
| 202 | default: | 66 | default: |
| 203 | ERROR_LOG(LOADER, "Failed to identify file"); | 67 | ERROR_LOG(LOADER, "Failed to identify file"); |
| @@ -207,4 +71,4 @@ bool LoadFile(std::string &filename, std::string *error_string) { | |||
| 207 | return false; | 71 | return false; |
| 208 | } | 72 | } |
| 209 | 73 | ||
| 210 | } // namespace \ No newline at end of file | 74 | } // namespace Loader |