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 | |
| 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')
| -rw-r--r-- | src/core/loader/3dsx.cpp | 11 | ||||
| -rw-r--r-- | src/core/loader/3dsx.h | 8 | ||||
| -rw-r--r-- | src/core/loader/elf.cpp | 13 | ||||
| -rw-r--r-- | src/core/loader/elf.h | 8 | ||||
| -rw-r--r-- | src/core/loader/loader.cpp | 37 | ||||
| -rw-r--r-- | src/core/loader/loader.h | 8 | ||||
| -rw-r--r-- | src/core/loader/ncch.cpp | 20 | ||||
| -rw-r--r-- | src/core/loader/ncch.h | 12 |
8 files changed, 88 insertions, 29 deletions
diff --git a/src/core/loader/3dsx.cpp b/src/core/loader/3dsx.cpp index 5d806c5d0..5aaeb53d8 100644 --- a/src/core/loader/3dsx.cpp +++ b/src/core/loader/3dsx.cpp | |||
| @@ -8,9 +8,10 @@ | |||
| 8 | #include "common/logging/log.h" | 8 | #include "common/logging/log.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/elf.h" | 13 | #include "core/loader/elf.h" |
| 12 | #include "core/loader/ncch.h" | 14 | #include "core/loader/ncch.h" |
| 13 | #include "core/hle/service/fs/archive.h" | ||
| 14 | #include "core/mem_map.h" | 15 | #include "core/mem_map.h" |
| 15 | 16 | ||
| 16 | #include "3dsx.h" | 17 | #include "3dsx.h" |
| @@ -229,8 +230,12 @@ ResultStatus AppLoader_THREEDSX::Load() { | |||
| 229 | if (!file->IsOpen()) | 230 | if (!file->IsOpen()) |
| 230 | return ResultStatus::Error; | 231 | return ResultStatus::Error; |
| 231 | 232 | ||
| 232 | Load3DSXFile(*file, 0x00100000); | 233 | Kernel::g_current_process = Kernel::Process::Create(filename, 0); |
| 233 | Kernel::LoadExec(0x00100000); | 234 | Kernel::g_current_process->static_address_mappings = default_address_mappings; |
| 235 | |||
| 236 | Load3DSXFile(*file, Memory::EXEFS_CODE_VADDR); | ||
| 237 | |||
| 238 | Kernel::g_current_process->Run(Memory::EXEFS_CODE_VADDR, 48, Kernel::DEFAULT_STACK_SIZE); | ||
| 234 | 239 | ||
| 235 | is_loaded = true; | 240 | is_loaded = true; |
| 236 | return ResultStatus::Success; | 241 | return ResultStatus::Success; |
diff --git a/src/core/loader/3dsx.h b/src/core/loader/3dsx.h index a11667400..096b3ec20 100644 --- a/src/core/loader/3dsx.h +++ b/src/core/loader/3dsx.h | |||
| @@ -4,6 +4,8 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <string> | ||
| 8 | |||
| 7 | #include "common/common_types.h" | 9 | #include "common/common_types.h" |
| 8 | #include "core/loader/loader.h" | 10 | #include "core/loader/loader.h" |
| 9 | 11 | ||
| @@ -15,7 +17,8 @@ namespace Loader { | |||
| 15 | /// Loads an 3DSX file | 17 | /// Loads an 3DSX file |
| 16 | class AppLoader_THREEDSX final : public AppLoader { | 18 | class AppLoader_THREEDSX final : public AppLoader { |
| 17 | public: | 19 | public: |
| 18 | AppLoader_THREEDSX(std::unique_ptr<FileUtil::IOFile>&& file) : AppLoader(std::move(file)) { } | 20 | AppLoader_THREEDSX(std::unique_ptr<FileUtil::IOFile>&& file, std::string filename) |
| 21 | : AppLoader(std::move(file)), filename(std::move(filename)) {} | ||
| 19 | 22 | ||
| 20 | /** | 23 | /** |
| 21 | * Returns the type of the file | 24 | * Returns the type of the file |
| @@ -29,6 +32,9 @@ public: | |||
| 29 | * @return ResultStatus result of function | 32 | * @return ResultStatus result of function |
| 30 | */ | 33 | */ |
| 31 | ResultStatus Load() override; | 34 | ResultStatus Load() override; |
| 35 | |||
| 36 | private: | ||
| 37 | std::string filename; | ||
| 32 | }; | 38 | }; |
| 33 | 39 | ||
| 34 | } // namespace Loader | 40 | } // namespace Loader |
diff --git a/src/core/loader/elf.cpp b/src/core/loader/elf.cpp index 467e91924..ac3f84d04 100644 --- a/src/core/loader/elf.cpp +++ b/src/core/loader/elf.cpp | |||
| @@ -10,9 +10,9 @@ | |||
| 10 | #include "common/logging/log.h" | 10 | #include "common/logging/log.h" |
| 11 | #include "common/symbols.h" | 11 | #include "common/symbols.h" |
| 12 | 12 | ||
| 13 | #include "core/mem_map.h" | ||
| 14 | #include "core/loader/elf.h" | ||
| 15 | #include "core/hle/kernel/kernel.h" | 13 | #include "core/hle/kernel/kernel.h" |
| 14 | #include "core/loader/elf.h" | ||
| 15 | #include "core/mem_map.h" | ||
| 16 | 16 | ||
| 17 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 17 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 18 | // ELF Header Constants | 18 | // ELF Header Constants |
| @@ -350,9 +350,14 @@ ResultStatus AppLoader_ELF::Load() { | |||
| 350 | if (file->ReadBytes(&buffer[0], size) != size) | 350 | if (file->ReadBytes(&buffer[0], size) != size) |
| 351 | return ResultStatus::Error; | 351 | return ResultStatus::Error; |
| 352 | 352 | ||
| 353 | Kernel::g_current_process = Kernel::Process::Create(filename, 0); | ||
| 354 | Kernel::g_current_process->static_address_mappings = default_address_mappings; | ||
| 355 | |||
| 353 | ElfReader elf_reader(&buffer[0]); | 356 | ElfReader elf_reader(&buffer[0]); |
| 354 | elf_reader.LoadInto(0x00100000); | 357 | elf_reader.LoadInto(Memory::EXEFS_CODE_VADDR); |
| 355 | Kernel::LoadExec(elf_reader.GetEntryPoint()); | 358 | // TODO: Fill application title |
| 359 | |||
| 360 | Kernel::g_current_process->Run(elf_reader.GetEntryPoint(), 48, Kernel::DEFAULT_STACK_SIZE); | ||
| 356 | 361 | ||
| 357 | is_loaded = true; | 362 | is_loaded = true; |
| 358 | return ResultStatus::Success; | 363 | return ResultStatus::Success; |
diff --git a/src/core/loader/elf.h b/src/core/loader/elf.h index b6e6651f5..32841606a 100644 --- a/src/core/loader/elf.h +++ b/src/core/loader/elf.h | |||
| @@ -4,6 +4,8 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <string> | ||
| 8 | |||
| 7 | #include "common/common_types.h" | 9 | #include "common/common_types.h" |
| 8 | #include "core/loader/loader.h" | 10 | #include "core/loader/loader.h" |
| 9 | 11 | ||
| @@ -15,7 +17,8 @@ namespace Loader { | |||
| 15 | /// Loads an ELF/AXF file | 17 | /// Loads an ELF/AXF file |
| 16 | class AppLoader_ELF final : public AppLoader { | 18 | class AppLoader_ELF final : public AppLoader { |
| 17 | public: | 19 | public: |
| 18 | AppLoader_ELF(std::unique_ptr<FileUtil::IOFile>&& file) : AppLoader(std::move(file)) { } | 20 | AppLoader_ELF(std::unique_ptr<FileUtil::IOFile>&& file, std::string filename) |
| 21 | : AppLoader(std::move(file)), filename(std::move(filename)) { } | ||
| 19 | 22 | ||
| 20 | /** | 23 | /** |
| 21 | * Returns the type of the file | 24 | * Returns the type of the file |
| @@ -29,6 +32,9 @@ public: | |||
| 29 | * @return ResultStatus result of function | 32 | * @return ResultStatus result of function |
| 30 | */ | 33 | */ |
| 31 | ResultStatus Load() override; | 34 | ResultStatus Load() override; |
| 35 | |||
| 36 | private: | ||
| 37 | std::string filename; | ||
| 32 | }; | 38 | }; |
| 33 | 39 | ||
| 34 | } // namespace Loader | 40 | } // namespace Loader |
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 | ||
diff --git a/src/core/loader/loader.h b/src/core/loader/loader.h index 2b87239cf..bf027a878 100644 --- a/src/core/loader/loader.h +++ b/src/core/loader/loader.h | |||
| @@ -9,6 +9,8 @@ | |||
| 9 | #include "common/common_types.h" | 9 | #include "common/common_types.h" |
| 10 | #include "common/file_util.h" | 10 | #include "common/file_util.h" |
| 11 | 11 | ||
| 12 | #include "core/hle/kernel/process.h" | ||
| 13 | |||
| 12 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 14 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 13 | // Loader namespace | 15 | // Loader namespace |
| 14 | 16 | ||
| @@ -105,6 +107,12 @@ protected: | |||
| 105 | }; | 107 | }; |
| 106 | 108 | ||
| 107 | /** | 109 | /** |
| 110 | * Common address mappings found in most games, used for binary formats that don't have this | ||
| 111 | * information. | ||
| 112 | */ | ||
| 113 | extern const std::initializer_list<Kernel::StaticAddressMapping> default_address_mappings; | ||
| 114 | |||
| 115 | /** | ||
| 108 | * Identifies and loads a bootable file | 116 | * Identifies and loads a bootable file |
| 109 | * @param filename String filename of bootable file | 117 | * @param filename String filename of bootable file |
| 110 | * @return ResultStatus result of function | 118 | * @return ResultStatus result of function |
diff --git a/src/core/loader/ncch.cpp b/src/core/loader/ncch.cpp index 9bce2b79d..531000137 100644 --- a/src/core/loader/ncch.cpp +++ b/src/core/loader/ncch.cpp | |||
| @@ -5,9 +5,12 @@ | |||
| 5 | #include <memory> | 5 | #include <memory> |
| 6 | 6 | ||
| 7 | #include "common/logging/log.h" | 7 | #include "common/logging/log.h" |
| 8 | #include "common/make_unique.h" | ||
| 9 | #include "common/string_util.h" | ||
| 10 | #include "common/swap.h" | ||
| 8 | 11 | ||
| 9 | #include "core/loader/ncch.h" | ||
| 10 | #include "core/hle/kernel/kernel.h" | 12 | #include "core/hle/kernel/kernel.h" |
| 13 | #include "core/loader/ncch.h" | ||
| 11 | #include "core/mem_map.h" | 14 | #include "core/mem_map.h" |
| 12 | 15 | ||
| 13 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 16 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| @@ -117,8 +120,21 @@ ResultStatus AppLoader_NCCH::LoadExec() const { | |||
| 117 | 120 | ||
| 118 | std::vector<u8> code; | 121 | std::vector<u8> code; |
| 119 | if (ResultStatus::Success == ReadCode(code)) { | 122 | if (ResultStatus::Success == ReadCode(code)) { |
| 123 | std::string process_name = Common::StringFromFixedZeroTerminatedBuffer( | ||
| 124 | (const char*)exheader_header.codeset_info.name, 8); | ||
| 125 | u64 program_id = *reinterpret_cast<u64_le const*>(&ncch_header.program_id[0]); | ||
| 126 | Kernel::g_current_process = Kernel::Process::Create(process_name, program_id); | ||
| 127 | |||
| 128 | // Copy data while converting endianess | ||
| 129 | std::array<u32, ARRAY_SIZE(exheader_header.arm11_kernel_caps.descriptors)> kernel_caps; | ||
| 130 | std::copy_n(exheader_header.arm11_kernel_caps.descriptors, kernel_caps.size(), begin(kernel_caps)); | ||
| 131 | Kernel::g_current_process->ParseKernelCaps(kernel_caps.data(), kernel_caps.size()); | ||
| 132 | |||
| 120 | Memory::WriteBlock(entry_point, &code[0], code.size()); | 133 | Memory::WriteBlock(entry_point, &code[0], code.size()); |
| 121 | Kernel::LoadExec(entry_point); | 134 | |
| 135 | s32 priority = exheader_header.arm11_system_local_caps.priority; | ||
| 136 | u32 stack_size = exheader_header.codeset_info.stack_size; | ||
| 137 | Kernel::g_current_process->Run(entry_point, priority, stack_size); | ||
| 122 | return ResultStatus::Success; | 138 | return ResultStatus::Success; |
| 123 | } | 139 | } |
| 124 | return ResultStatus::Error; | 140 | return ResultStatus::Error; |
diff --git a/src/core/loader/ncch.h b/src/core/loader/ncch.h index 44c72a4e2..dec46e86c 100644 --- a/src/core/loader/ncch.h +++ b/src/core/loader/ncch.h | |||
| @@ -6,7 +6,9 @@ | |||
| 6 | 6 | ||
| 7 | #include <memory> | 7 | #include <memory> |
| 8 | 8 | ||
| 9 | #include "common/bit_field.h" | ||
| 9 | #include "common/common_types.h" | 10 | #include "common/common_types.h" |
| 11 | #include "common/swap.h" | ||
| 10 | 12 | ||
| 11 | #include "core/loader/loader.h" | 13 | #include "core/loader/loader.h" |
| 12 | 14 | ||
| @@ -109,7 +111,13 @@ struct ExHeader_StorageInfo{ | |||
| 109 | struct ExHeader_ARM11_SystemLocalCaps{ | 111 | struct ExHeader_ARM11_SystemLocalCaps{ |
| 110 | u8 program_id[8]; | 112 | u8 program_id[8]; |
| 111 | u32 core_version; | 113 | u32 core_version; |
| 112 | u8 flags[3]; | 114 | u8 reserved_flags[2]; |
| 115 | union { | ||
| 116 | u8 flags0; | ||
| 117 | BitField<0, 2, u8> ideal_processor; | ||
| 118 | BitField<2, 2, u8> affinity_mask; | ||
| 119 | BitField<4, 4, u8> system_mode; | ||
| 120 | }; | ||
| 113 | u8 priority; | 121 | u8 priority; |
| 114 | u8 resource_limit_descriptor[0x10][2]; | 122 | u8 resource_limit_descriptor[0x10][2]; |
| 115 | ExHeader_StorageInfo storage_info; | 123 | ExHeader_StorageInfo storage_info; |
| @@ -120,7 +128,7 @@ struct ExHeader_ARM11_SystemLocalCaps{ | |||
| 120 | }; | 128 | }; |
| 121 | 129 | ||
| 122 | struct ExHeader_ARM11_KernelCaps{ | 130 | struct ExHeader_ARM11_KernelCaps{ |
| 123 | u8 descriptors[28][4]; | 131 | u32_le descriptors[28]; |
| 124 | u8 reserved[0x10]; | 132 | u8 reserved[0x10]; |
| 125 | }; | 133 | }; |
| 126 | 134 | ||