diff options
| author | 2015-05-04 00:01:16 -0300 | |
|---|---|---|
| committer | 2015-05-08 22:11:02 -0300 | |
| commit | 6d60acf0f1afcae873988da5218f2f1c7bc9d151 (patch) | |
| tree | cec75198ab74759002dd1da78f6ac2af5e61949f /src/core/loader/loader.cpp | |
| parent | Common: Add StringFromFixedZeroTerminatedBuffer (diff) | |
| download | yuzu-6d60acf0f1afcae873988da5218f2f1c7bc9d151.tar.gz yuzu-6d60acf0f1afcae873988da5218f2f1c7bc9d151.tar.xz yuzu-6d60acf0f1afcae873988da5218f2f1c7bc9d151.zip | |
Kernel: Introduce skeleton Process class to hold process data
Diffstat (limited to 'src/core/loader/loader.cpp')
| -rw-r--r-- | src/core/loader/loader.cpp | 37 |
1 files changed, 21 insertions, 16 deletions
diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp index de0ab540a..97525fbeb 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::StaticAddressMapping> 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: |
| @@ -139,11 +141,14 @@ ResultStatus LoadFile(const std::string& filename) { | |||
| 139 | // Raw BIN file format... | 141 | // Raw BIN file format... |
| 140 | case FileType::BIN: | 142 | case FileType::BIN: |
| 141 | { | 143 | { |
| 144 | Kernel::g_current_process = Kernel::Process::Create(filename_filename, 0); | ||
| 145 | Kernel::g_current_process->static_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 | ||