diff options
| author | 2015-05-08 21:20:37 -0400 | |
|---|---|---|
| committer | 2015-05-08 21:20:37 -0400 | |
| commit | 917ac23dfcab37c65e11e3413e397863bd4bc000 (patch) | |
| tree | 956ca5d1a4aad3383c4a3bfc9103476abe3f1987 /src/core/loader/loader.cpp | |
| parent | Merge pull request #728 from lioncash/vars (diff) | |
| parent | Kernel: Remove unused g_main_thread variable (diff) | |
| download | yuzu-917ac23dfcab37c65e11e3413e397863bd4bc000.tar.gz yuzu-917ac23dfcab37c65e11e3413e397863bd4bc000.tar.xz yuzu-917ac23dfcab37c65e11e3413e397863bd4bc000.zip | |
Merge pull request #731 from yuriks/app-info
Kernel: Process class and ExHeader caps parsing
Diffstat (limited to 'src/core/loader/loader.cpp')
| -rw-r--r-- | src/core/loader/loader.cpp | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp index de0ab540a..505e2d280 100644 --- a/src/core/loader/loader.cpp +++ b/src/core/loader/loader.cpp | |||
| @@ -8,16 +8,23 @@ | |||
| 8 | #include "common/make_unique.h" | 8 | #include "common/make_unique.h" |
| 9 | 9 | ||
| 10 | #include "core/file_sys/archive_romfs.h" | 10 | #include "core/file_sys/archive_romfs.h" |
| 11 | #include "core/hle/kernel/process.h" | ||
| 12 | #include "core/hle/service/fs/archive.h" | ||
| 11 | #include "core/loader/3dsx.h" | 13 | #include "core/loader/3dsx.h" |
| 12 | #include "core/loader/elf.h" | 14 | #include "core/loader/elf.h" |
| 13 | #include "core/loader/ncch.h" | 15 | #include "core/loader/ncch.h" |
| 14 | #include "core/hle/service/fs/archive.h" | ||
| 15 | #include "core/mem_map.h" | 16 | #include "core/mem_map.h" |
| 16 | 17 | ||
| 17 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 18 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 18 | 19 | ||
| 19 | namespace Loader { | 20 | namespace Loader { |
| 20 | 21 | ||
| 22 | const std::initializer_list<Kernel::AddressMapping> default_address_mappings = { | ||
| 23 | { 0x1FF50000, 0x8000, true }, // part of DSP RAM | ||
| 24 | { 0x1FF70000, 0x8000, true }, // part of DSP RAM | ||
| 25 | { 0x1F000000, 0x600000, false }, // entire VRAM | ||
| 26 | }; | ||
| 27 | |||
| 21 | /** | 28 | /** |
| 22 | * Identifies the type of a bootable file | 29 | * Identifies the type of a bootable file |
| 23 | * @param file open file | 30 | * @param file open file |
| @@ -42,19 +49,11 @@ static FileType IdentifyFile(FileUtil::IOFile& file) { | |||
| 42 | 49 | ||
| 43 | /** | 50 | /** |
| 44 | * Guess the type of a bootable file from its extension | 51 | * Guess the type of a bootable file from its extension |
| 45 | * @param filename String filename of bootable file | 52 | * @param extension String extension of bootable file |
| 46 | * @return FileType of file | 53 | * @return FileType of file |
| 47 | */ | 54 | */ |
| 48 | static FileType GuessFromFilename(const std::string& filename) { | 55 | static FileType GuessFromExtension(const std::string& extension_) { |
| 49 | if (filename.size() == 0) { | 56 | std::string extension = Common::ToLower(extension_); |
| 50 | LOG_ERROR(Loader, "invalid filename %s", filename.c_str()); | ||
| 51 | return FileType::Error; | ||
| 52 | } | ||
| 53 | |||
| 54 | size_t extension_loc = filename.find_last_of('.'); | ||
| 55 | if (extension_loc == std::string::npos) | ||
| 56 | return FileType::Unknown; | ||
| 57 | std::string extension = Common::ToLower(filename.substr(extension_loc)); | ||
| 58 | 57 | ||
| 59 | if (extension == ".elf") | 58 | if (extension == ".elf") |
| 60 | return FileType::ELF; | 59 | return FileType::ELF; |
| @@ -100,8 +99,11 @@ ResultStatus LoadFile(const std::string& filename) { | |||
| 100 | return ResultStatus::Error; | 99 | return ResultStatus::Error; |
| 101 | } | 100 | } |
| 102 | 101 | ||
| 102 | std::string filename_filename, filename_extension; | ||
| 103 | Common::SplitPath(filename, nullptr, &filename_filename, &filename_extension); | ||
| 104 | |||
| 103 | FileType type = IdentifyFile(*file); | 105 | FileType type = IdentifyFile(*file); |
| 104 | FileType filename_type = GuessFromFilename(filename); | 106 | FileType filename_type = GuessFromExtension(filename_extension); |
| 105 | 107 | ||
| 106 | if (type != filename_type) { | 108 | if (type != filename_type) { |
| 107 | LOG_WARNING(Loader, "File %s has a different type than its extension.", filename.c_str()); | 109 | LOG_WARNING(Loader, "File %s has a different type than its extension.", filename.c_str()); |
| @@ -115,11 +117,11 @@ ResultStatus LoadFile(const std::string& filename) { | |||
| 115 | 117 | ||
| 116 | //3DSX file format... | 118 | //3DSX file format... |
| 117 | case FileType::THREEDSX: | 119 | case FileType::THREEDSX: |
| 118 | return AppLoader_THREEDSX(std::move(file)).Load(); | 120 | return AppLoader_THREEDSX(std::move(file), filename_filename).Load(); |
| 119 | 121 | ||
| 120 | // Standard ELF file format... | 122 | // Standard ELF file format... |
| 121 | case FileType::ELF: | 123 | case FileType::ELF: |
| 122 | return AppLoader_ELF(std::move(file)).Load(); | 124 | return AppLoader_ELF(std::move(file), filename_filename).Load(); |
| 123 | 125 | ||
| 124 | // NCCH/NCSD container formats... | 126 | // NCCH/NCSD container formats... |
| 125 | case FileType::CXI: | 127 | case FileType::CXI: |
| @@ -129,7 +131,6 @@ ResultStatus LoadFile(const std::string& filename) { | |||
| 129 | 131 | ||
| 130 | // Load application and RomFS | 132 | // Load application and RomFS |
| 131 | if (ResultStatus::Success == app_loader.Load()) { | 133 | if (ResultStatus::Success == app_loader.Load()) { |
| 132 | Kernel::g_program_id = app_loader.GetProgramId(); | ||
| 133 | Service::FS::RegisterArchiveType(Common::make_unique<FileSys::ArchiveFactory_RomFS>(app_loader), Service::FS::ArchiveIdCode::RomFS); | 134 | Service::FS::RegisterArchiveType(Common::make_unique<FileSys::ArchiveFactory_RomFS>(app_loader), Service::FS::ArchiveIdCode::RomFS); |
| 134 | return ResultStatus::Success; | 135 | return ResultStatus::Success; |
| 135 | } | 136 | } |
| @@ -139,11 +140,15 @@ ResultStatus LoadFile(const std::string& filename) { | |||
| 139 | // Raw BIN file format... | 140 | // Raw BIN file format... |
| 140 | case FileType::BIN: | 141 | case FileType::BIN: |
| 141 | { | 142 | { |
| 143 | Kernel::g_current_process = Kernel::Process::Create(filename_filename, 0); | ||
| 144 | Kernel::g_current_process->svc_access_mask.set(); | ||
| 145 | Kernel::g_current_process->address_mappings = default_address_mappings; | ||
| 146 | |||
| 142 | size_t size = (size_t)file->GetSize(); | 147 | size_t size = (size_t)file->GetSize(); |
| 143 | if (file->ReadBytes(Memory::GetPointer(Memory::EXEFS_CODE_VADDR), size) != size) | 148 | if (file->ReadBytes(Memory::GetPointer(Memory::EXEFS_CODE_VADDR), size) != size) |
| 144 | return ResultStatus::Error; | 149 | return ResultStatus::Error; |
| 145 | 150 | ||
| 146 | Kernel::LoadExec(Memory::EXEFS_CODE_VADDR); | 151 | Kernel::g_current_process->Run(Memory::EXEFS_CODE_VADDR, 0x30, Kernel::DEFAULT_STACK_SIZE); |
| 147 | return ResultStatus::Success; | 152 | return ResultStatus::Success; |
| 148 | } | 153 | } |
| 149 | 154 | ||