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/hle/kernel/process.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/hle/kernel/process.cpp')
| -rw-r--r-- | src/core/hle/kernel/process.cpp | 96 |
1 files changed, 96 insertions, 0 deletions
diff --git a/src/core/hle/kernel/process.cpp b/src/core/hle/kernel/process.cpp new file mode 100644 index 000000000..a444e22e5 --- /dev/null +++ b/src/core/hle/kernel/process.cpp | |||
| @@ -0,0 +1,96 @@ | |||
| 1 | // Copyright 2015 Citra Emulator Project | ||
| 2 | // Licensed under GPLv2 or any later version | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include "common/assert.h" | ||
| 6 | #include "common/common_funcs.h" | ||
| 7 | #include "common/logging/log.h" | ||
| 8 | |||
| 9 | #include "core/hle/kernel/process.h" | ||
| 10 | #include "core/hle/kernel/thread.h" | ||
| 11 | #include "core/mem_map.h" | ||
| 12 | |||
| 13 | namespace Kernel { | ||
| 14 | |||
| 15 | SharedPtr<Process> Process::Create(std::string name, u64 program_id) { | ||
| 16 | SharedPtr<Process> process(new Process); | ||
| 17 | |||
| 18 | process->name = std::move(name); | ||
| 19 | process->program_id = program_id; | ||
| 20 | |||
| 21 | process->flags.raw = 0; | ||
| 22 | process->flags.memory_region = MemoryRegion::APPLICATION; | ||
| 23 | |||
| 24 | return process; | ||
| 25 | } | ||
| 26 | |||
| 27 | void Process::ParseKernelCaps(const u32* kernel_caps, size_t len) { | ||
| 28 | for (int i = 0; i < len; ++i) { | ||
| 29 | u32 descriptor = kernel_caps[i]; | ||
| 30 | u32 type = descriptor >> 20; | ||
| 31 | |||
| 32 | if (descriptor == 0xFFFFFFFF) { | ||
| 33 | // Unused descriptor entry | ||
| 34 | continue; | ||
| 35 | } else if ((type & 0xF00) == 0xE00) { // 0x0FFF | ||
| 36 | // Allowed interrupts list | ||
| 37 | LOG_WARNING(Loader, "ExHeader allowed interrupts list ignored"); | ||
| 38 | } else if ((type & 0xF80) == 0xF00) { // 0x07FF | ||
| 39 | // Allowed syscalls mask | ||
| 40 | unsigned int index = ((descriptor >> 24) & 7) * 24; | ||
| 41 | u32 bits = descriptor & 0xFFFFFF; | ||
| 42 | |||
| 43 | while (bits && index < svc_access_mask.size()) { | ||
| 44 | svc_access_mask.set(index, bits & 1); | ||
| 45 | ++index; bits >>= 1; | ||
| 46 | } | ||
| 47 | } else if ((type & 0xFF0) == 0xFE0) { // 0x00FF | ||
| 48 | // Handle table size | ||
| 49 | handle_table_size = descriptor & 0x3FF; | ||
| 50 | } else if ((type & 0xFF8) == 0xFF0) { // 0x007F | ||
| 51 | // Misc. flags | ||
| 52 | flags.raw = descriptor & 0xFFFF; | ||
| 53 | } else if ((type & 0xFFE) == 0xFF8) { // 0x001F | ||
| 54 | // Mapped memory range | ||
| 55 | if (i+1 >= len || ((kernel_caps[i+1] >> 20) & 0xFFE) != 0xFF8) { | ||
| 56 | LOG_WARNING(Loader, "Incomplete exheader memory range descriptor ignored."); | ||
| 57 | continue; | ||
| 58 | } | ||
| 59 | u32 end_desc = kernel_caps[i+1]; | ||
| 60 | ++i; // Skip over the second descriptor on the next iteration | ||
| 61 | |||
| 62 | AddressMapping mapping; | ||
| 63 | mapping.address = descriptor << 12; | ||
| 64 | mapping.size = (end_desc << 12) - mapping.address; | ||
| 65 | mapping.writable = descriptor & BIT(20); | ||
| 66 | mapping.unk_flag = end_desc & BIT(20); | ||
| 67 | |||
| 68 | address_mappings.push_back(mapping); | ||
| 69 | } else if ((type & 0xFFF) == 0xFFE) { // 0x000F | ||
| 70 | // Mapped memory page | ||
| 71 | AddressMapping mapping; | ||
| 72 | mapping.address = descriptor << 12; | ||
| 73 | mapping.size = Memory::PAGE_SIZE; | ||
| 74 | mapping.writable = true; // TODO: Not sure if correct | ||
| 75 | mapping.unk_flag = false; | ||
| 76 | } else if ((type & 0xFE0) == 0xFC0) { // 0x01FF | ||
| 77 | // Kernel version | ||
| 78 | int minor = descriptor & 0xFF; | ||
| 79 | int major = (descriptor >> 8) & 0xFF; | ||
| 80 | LOG_INFO(Loader, "ExHeader kernel version ignored: %d.%d", major, minor); | ||
| 81 | } else { | ||
| 82 | LOG_ERROR(Loader, "Unhandled kernel caps descriptor: 0x%08X", descriptor); | ||
| 83 | } | ||
| 84 | } | ||
| 85 | } | ||
| 86 | |||
| 87 | void Process::Run(VAddr entry_point, s32 main_thread_priority, u32 stack_size) { | ||
| 88 | Kernel::SetupMainThread(stack_size, entry_point, main_thread_priority); | ||
| 89 | } | ||
| 90 | |||
| 91 | Kernel::Process::Process() {} | ||
| 92 | Kernel::Process::~Process() {} | ||
| 93 | |||
| 94 | SharedPtr<Process> g_current_process; | ||
| 95 | |||
| 96 | } | ||