diff options
| author | 2015-05-08 16:51:48 -0300 | |
|---|---|---|
| committer | 2015-05-08 22:11:44 -0300 | |
| commit | 2af30d465fa4e9c3421f01b557141673eb0a2115 (patch) | |
| tree | ebbbbee64f504163feddf312a6844a58c5c5052a /src | |
| parent | Common: Add BIT macro (diff) | |
| download | yuzu-2af30d465fa4e9c3421f01b557141673eb0a2115.tar.gz yuzu-2af30d465fa4e9c3421f01b557141673eb0a2115.tar.xz yuzu-2af30d465fa4e9c3421f01b557141673eb0a2115.zip | |
Process: Support parsing of exheader kernel caps
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/hle/kernel/process.cpp | 73 | ||||
| -rw-r--r-- | src/core/hle/kernel/process.h | 3 | ||||
| -rw-r--r-- | src/core/loader/3dsx.cpp | 1 | ||||
| -rw-r--r-- | src/core/loader/elf.cpp | 1 | ||||
| -rw-r--r-- | src/core/loader/loader.cpp | 1 | ||||
| -rw-r--r-- | src/core/mem_map.h | 2 |
6 files changed, 77 insertions, 4 deletions
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp index 734d6f3ef..3aa4d8784 100644 --- a/src/core/hle/kernel/process.cpp +++ b/src/core/hle/kernel/process.cpp | |||
| @@ -3,24 +3,91 @@ | |||
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "common/assert.h" | 5 | #include "common/assert.h" |
| 6 | #include "common/common_funcs.h" | ||
| 7 | #include "common/logging/log.h" | ||
| 6 | 8 | ||
| 7 | #include "core/hle/kernel/process.h" | 9 | #include "core/hle/kernel/process.h" |
| 8 | #include "core/hle/kernel/thread.h" | 10 | #include "core/hle/kernel/thread.h" |
| 11 | #include "core/mem_map.h" | ||
| 9 | 12 | ||
| 10 | namespace Kernel { | 13 | namespace Kernel { |
| 11 | 14 | ||
| 12 | SharedPtr<Process> Process::Create(std::string name, u64 program_id) { | 15 | SharedPtr<Process> Process::Create(std::string name, u64 program_id) { |
| 13 | SharedPtr<Process> process(new Process); | 16 | SharedPtr<Process> process(new Process); |
| 14 | 17 | ||
| 15 | process->svc_access_mask.set(); | ||
| 16 | process->name = std::move(name); | 18 | process->name = std::move(name); |
| 17 | process->program_id = program_id; | 19 | process->program_id = program_id; |
| 18 | 20 | ||
| 19 | return process; | 21 | return process; |
| 20 | } | 22 | } |
| 21 | 23 | ||
| 22 | void Process::ParseKernelCaps(const u32 * kernel_caps, size_t len) { | 24 | void Process::ParseKernelCaps(const u32* kernel_caps, size_t len) { |
| 23 | //UNIMPLEMENTED(); | 25 | for (int i = 0; i < len; ++i) { |
| 26 | u32 descriptor = kernel_caps[i]; | ||
| 27 | u32 type = descriptor >> 20; | ||
| 28 | |||
| 29 | if (descriptor == 0xFFFFFFFF) { | ||
| 30 | // Unused descriptor entry | ||
| 31 | continue; | ||
| 32 | } else if ((type & 0xF00) == 0xE00) { // 0x0FFF | ||
| 33 | // Allowed interrupts list | ||
| 34 | LOG_WARNING(Loader, "ExHeader allowed interrupts list ignored"); | ||
| 35 | } else if ((type & 0xF80) == 0xF00) { // 0x07FF | ||
| 36 | // Allowed syscalls mask | ||
| 37 | unsigned int index = ((descriptor >> 24) & 7) * 24; | ||
| 38 | u32 bits = descriptor & 0xFFFFFF; | ||
| 39 | |||
| 40 | while (bits && index < svc_access_mask.size()) { | ||
| 41 | svc_access_mask.set(index, bits & 1); | ||
| 42 | ++index; bits >>= 1; | ||
| 43 | } | ||
| 44 | } else if ((type & 0xFF0) == 0xFE0) { // 0x00FF | ||
| 45 | // Handle table size | ||
| 46 | handle_table_size = descriptor & 0x3FF; | ||
| 47 | } else if ((type & 0xFF8) == 0xFF0) { // 0x007F | ||
| 48 | // Misc. flags | ||
| 49 | bool allow_debug = descriptor & BIT(0); | ||
| 50 | bool force_debug = descriptor & BIT(1); | ||
| 51 | bool allow_nonalphanum = descriptor & BIT(2); | ||
| 52 | shared_page_writable = descriptor & BIT(3); | ||
| 53 | privileged_priority = descriptor & BIT(4); | ||
| 54 | bool allow_main_args = descriptor & BIT(5); | ||
| 55 | bool shared_device_mem = descriptor & BIT(6); | ||
| 56 | bool runnable_on_sleep = descriptor & BIT(7); | ||
| 57 | loaded_high = descriptor & BIT(12); | ||
| 58 | memory_region = MemoryRegion((descriptor >> 8) & 0xF); | ||
| 59 | } else if ((type & 0xFFE) == 0xFF8) { // 0x001F | ||
| 60 | // Mapped memory range | ||
| 61 | if (i+1 >= len || ((kernel_caps[i+1] >> 20) & 0xFFE) != 0xFF8) { | ||
| 62 | LOG_WARNING(Loader, "Incomplete exheader memory range descriptor ignored."); | ||
| 63 | continue; | ||
| 64 | } | ||
| 65 | u32 end_desc = kernel_caps[i+1]; | ||
| 66 | ++i; // Skip over the second descriptor on the next iteration | ||
| 67 | |||
| 68 | StaticAddressMapping mapping; | ||
| 69 | mapping.address = descriptor << 12; | ||
| 70 | mapping.size = (end_desc << 12) - mapping.address; | ||
| 71 | mapping.writable = descriptor & BIT(20); | ||
| 72 | mapping.unk_flag = end_desc & BIT(20); | ||
| 73 | |||
| 74 | static_address_mappings.push_back(mapping); | ||
| 75 | } else if ((type & 0xFFF) == 0xFFE) { // 0x000F | ||
| 76 | // Mapped memory page | ||
| 77 | StaticAddressMapping mapping; | ||
| 78 | mapping.address = descriptor << 12; | ||
| 79 | mapping.size = Memory::PAGE_SIZE; | ||
| 80 | mapping.writable = true; // TODO: Not sure if correct | ||
| 81 | mapping.unk_flag = false; | ||
| 82 | } else if ((type & 0xFE0) == 0xFC0) { // 0x01FF | ||
| 83 | // Kernel version | ||
| 84 | int minor = descriptor & 0xFF; | ||
| 85 | int major = (descriptor >> 8) & 0xFF; | ||
| 86 | LOG_INFO(Loader, "ExHeader kernel version ignored: %d.%d", major, minor); | ||
| 87 | } else { | ||
| 88 | LOG_ERROR(Loader, "Unhandled kernel caps descriptor: 0x%08X", descriptor); | ||
| 89 | } | ||
| 90 | } | ||
| 24 | } | 91 | } |
| 25 | 92 | ||
| 26 | void Process::Run(VAddr entry_point, s32 main_thread_priority, u32 stack_size) { | 93 | void Process::Run(VAddr entry_point, s32 main_thread_priority, u32 stack_size) { |
diff --git a/src/core/hle/kernel/process.h b/src/core/hle/kernel/process.h index 8abd881e3..d16979263 100644 --- a/src/core/hle/kernel/process.h +++ b/src/core/hle/kernel/process.h | |||
| @@ -14,10 +14,11 @@ | |||
| 14 | namespace Kernel { | 14 | namespace Kernel { |
| 15 | 15 | ||
| 16 | struct StaticAddressMapping { | 16 | struct StaticAddressMapping { |
| 17 | // Address and size must be 4K-aligned | 17 | // Address and size must be page-aligned |
| 18 | VAddr address; | 18 | VAddr address; |
| 19 | u32 size; | 19 | u32 size; |
| 20 | bool writable; | 20 | bool writable; |
| 21 | bool unk_flag; | ||
| 21 | }; | 22 | }; |
| 22 | 23 | ||
| 23 | enum class MemoryRegion { | 24 | enum class MemoryRegion { |
diff --git a/src/core/loader/3dsx.cpp b/src/core/loader/3dsx.cpp index 5aaeb53d8..a0266a4e0 100644 --- a/src/core/loader/3dsx.cpp +++ b/src/core/loader/3dsx.cpp | |||
| @@ -231,6 +231,7 @@ ResultStatus AppLoader_THREEDSX::Load() { | |||
| 231 | return ResultStatus::Error; | 231 | return ResultStatus::Error; |
| 232 | 232 | ||
| 233 | Kernel::g_current_process = Kernel::Process::Create(filename, 0); | 233 | Kernel::g_current_process = Kernel::Process::Create(filename, 0); |
| 234 | Kernel::g_current_process->svc_access_mask.set(); | ||
| 234 | Kernel::g_current_process->static_address_mappings = default_address_mappings; | 235 | Kernel::g_current_process->static_address_mappings = default_address_mappings; |
| 235 | 236 | ||
| 236 | Load3DSXFile(*file, Memory::EXEFS_CODE_VADDR); | 237 | Load3DSXFile(*file, Memory::EXEFS_CODE_VADDR); |
diff --git a/src/core/loader/elf.cpp b/src/core/loader/elf.cpp index ac3f84d04..94d1c9fa4 100644 --- a/src/core/loader/elf.cpp +++ b/src/core/loader/elf.cpp | |||
| @@ -351,6 +351,7 @@ ResultStatus AppLoader_ELF::Load() { | |||
| 351 | return ResultStatus::Error; | 351 | return ResultStatus::Error; |
| 352 | 352 | ||
| 353 | Kernel::g_current_process = Kernel::Process::Create(filename, 0); | 353 | Kernel::g_current_process = Kernel::Process::Create(filename, 0); |
| 354 | Kernel::g_current_process->svc_access_mask.set(); | ||
| 354 | Kernel::g_current_process->static_address_mappings = default_address_mappings; | 355 | Kernel::g_current_process->static_address_mappings = default_address_mappings; |
| 355 | 356 | ||
| 356 | ElfReader elf_reader(&buffer[0]); | 357 | ElfReader elf_reader(&buffer[0]); |
diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp index 2718e88c1..8976d0372 100644 --- a/src/core/loader/loader.cpp +++ b/src/core/loader/loader.cpp | |||
| @@ -141,6 +141,7 @@ ResultStatus LoadFile(const std::string& filename) { | |||
| 141 | case FileType::BIN: | 141 | case FileType::BIN: |
| 142 | { | 142 | { |
| 143 | Kernel::g_current_process = Kernel::Process::Create(filename_filename, 0); | 143 | Kernel::g_current_process = Kernel::Process::Create(filename_filename, 0); |
| 144 | Kernel::g_current_process->svc_access_mask.set(); | ||
| 144 | Kernel::g_current_process->static_address_mappings = default_address_mappings; | 145 | Kernel::g_current_process->static_address_mappings = default_address_mappings; |
| 145 | 146 | ||
| 146 | size_t size = (size_t)file->GetSize(); | 147 | size_t size = (size_t)file->GetSize(); |
diff --git a/src/core/mem_map.h b/src/core/mem_map.h index 1fb77c94a..fb582d65a 100644 --- a/src/core/mem_map.h +++ b/src/core/mem_map.h | |||
| @@ -10,6 +10,8 @@ namespace Memory { | |||
| 10 | 10 | ||
| 11 | //////////////////////////////////////////////////////////////////////////////////////////////////// | 11 | //////////////////////////////////////////////////////////////////////////////////////////////////// |
| 12 | 12 | ||
| 13 | const u32 PAGE_SIZE = 0x1000; | ||
| 14 | |||
| 13 | enum : u32 { | 15 | enum : u32 { |
| 14 | BOOTROM_SIZE = 0x00010000, ///< Bootrom (super secret code/data @ 0x8000) size | 16 | BOOTROM_SIZE = 0x00010000, ///< Bootrom (super secret code/data @ 0x8000) size |
| 15 | BOOTROM_PADDR = 0x00000000, ///< Bootrom physical address | 17 | BOOTROM_PADDR = 0x00000000, ///< Bootrom physical address |