summaryrefslogtreecommitdiff
path: root/src/core/hle/kernel
diff options
context:
space:
mode:
authorGravatar bunnei2014-07-04 21:58:08 -0400
committerGravatar bunnei2014-07-04 21:58:08 -0400
commitad1adb2f9270cc48bfbfd8b12ad1dac162c48e39 (patch)
tree6bb6ab148504beaacdfa02ed1dd069e3a5f61427 /src/core/hle/kernel
parentMerge pull request #22 from bunnei/loader-improvements (diff)
parentNCCH: Updated ExeFS memory allocation to be safer. (diff)
downloadyuzu-ad1adb2f9270cc48bfbfd8b12ad1dac162c48e39.tar.gz
yuzu-ad1adb2f9270cc48bfbfd8b12ad1dac162c48e39.tar.xz
yuzu-ad1adb2f9270cc48bfbfd8b12ad1dac162c48e39.zip
Merge pull request #26 from bunnei/romfs-archive
Adds preliminary RomFS archive support
Diffstat (limited to 'src/core/hle/kernel')
-rw-r--r--src/core/hle/kernel/archive.cpp157
-rw-r--r--src/core/hle/kernel/archive.h38
-rw-r--r--src/core/hle/kernel/kernel.cpp3
-rw-r--r--src/core/hle/kernel/kernel.h1
4 files changed, 199 insertions, 0 deletions
diff --git a/src/core/hle/kernel/archive.cpp b/src/core/hle/kernel/archive.cpp
new file mode 100644
index 000000000..76b2520da
--- /dev/null
+++ b/src/core/hle/kernel/archive.cpp
@@ -0,0 +1,157 @@
1// Copyright 2014 Citra Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#include "common/common_types.h"
6
7#include "core/file_sys/archive.h"
8#include "core/hle/service/service.h"
9#include "core/hle/kernel/kernel.h"
10#include "core/hle/kernel/archive.h"
11
12////////////////////////////////////////////////////////////////////////////////////////////////////
13// Kernel namespace
14
15namespace Kernel {
16
17// Command to access archive file
18enum class FileCommand : u32 {
19 Dummy1 = 0x000100C6,
20 Control = 0x040100C4,
21 OpenSubFile = 0x08010100,
22 Read = 0x080200C2,
23 Write = 0x08030102,
24 GetSize = 0x08040000,
25 SetSize = 0x08050080,
26 GetAttributes = 0x08060000,
27 SetAttributes = 0x08070040,
28 Close = 0x08080000,
29 Flush = 0x08090000,
30};
31
32class Archive : public Object {
33public:
34 const char* GetTypeName() const { return "Archive"; }
35 const char* GetName() const { return name.c_str(); }
36
37 static Kernel::HandleType GetStaticHandleType() { return HandleType::Archive; }
38 Kernel::HandleType GetHandleType() const { return HandleType::Archive; }
39
40 std::string name; ///< Name of archive (optional)
41 FileSys::Archive* backend; ///< Archive backend interface
42
43 /**
44 * Synchronize kernel object
45 * @param wait Boolean wait set if current thread should wait as a result of sync operation
46 * @return Result of operation, 0 on success, otherwise error code
47 */
48 Result SyncRequest(bool* wait) {
49 u32* cmd_buff = Service::GetCommandBuffer();
50 FileCommand cmd = static_cast<FileCommand>(cmd_buff[0]);
51 switch (cmd) {
52
53 // Read from archive...
54 case FileCommand::Read:
55 {
56 u64 offset = cmd_buff[1] | ((u64) cmd_buff[2]) << 32;
57 u32 length = cmd_buff[3];
58 u32 address = cmd_buff[5];
59 cmd_buff[2] = backend->Read(offset, length, Memory::GetPointer(address));
60 break;
61 }
62
63 // Unknown command...
64 default:
65 ERROR_LOG(KERNEL, "Unknown command=0x%08X!", cmd);
66 return -1;
67 }
68 cmd_buff[1] = 0; // No error
69 return 0;
70 }
71
72 /**
73 * Wait for kernel object to synchronize
74 * @param wait Boolean wait set if current thread should wait as a result of sync operation
75 * @return Result of operation, 0 on success, otherwise error code
76 */
77 Result WaitSynchronization(bool* wait) {
78 // TODO(bunnei): ImplementMe
79 ERROR_LOG(OSHLE, "(UNIMPLEMENTED)");
80 return 0;
81 }
82};
83
84////////////////////////////////////////////////////////////////////////////////////////////////////
85
86std::map<FileSys::Archive::IdCode, Handle> g_archive_map; ///< Map of file archives by IdCode
87
88/**
89 * Opens an archive
90 * @param id_code IdCode of the archive to open
91 * @return Handle to archive if it exists, otherwise a null handle (0)
92 */
93Handle OpenArchive(FileSys::Archive::IdCode id_code) {
94 auto itr = g_archive_map.find(id_code);
95 if (itr == g_archive_map.end()) {
96 return 0;
97 }
98 return itr->second;
99}
100
101/**
102 * Mounts an archive
103 * @param archive Pointer to the archive to mount
104 * @return Result of operation, 0 on success, otherwise error code
105 */
106Result MountArchive(Archive* archive) {
107 FileSys::Archive::IdCode id_code = archive->backend->GetIdCode();
108 if (0 != OpenArchive(id_code)) {
109 ERROR_LOG(KERNEL, "Cannot mount two archives with the same ID code! (%d)", (int) id_code);
110 return -1;
111 }
112 g_archive_map[id_code] = archive->GetHandle();
113 INFO_LOG(KERNEL, "Mounted archive %s", archive->GetName());
114 return 0;
115}
116
117/**
118 * Creates an Archive
119 * @param handle Handle to newly created archive object
120 * @param backend File system backend interface to the archive
121 * @param name Optional name of Archive
122 * @return Newly created Archive object
123 */
124Archive* CreateArchive(Handle& handle, FileSys::Archive* backend, const std::string& name) {
125 Archive* archive = new Archive;
126 handle = Kernel::g_object_pool.Create(archive);
127 archive->name = name;
128 archive->backend = backend;
129
130 MountArchive(archive);
131
132 return archive;
133}
134
135/**
136 * Creates an Archive
137 * @param backend File system backend interface to the archive
138 * @param name Optional name of Archive
139 * @return Handle to newly created Archive object
140 */
141Handle CreateArchive(FileSys::Archive* backend, const std::string& name) {
142 Handle handle;
143 Archive* archive = CreateArchive(handle, backend, name);
144 return handle;
145}
146
147/// Initialize archives
148void ArchiveInit() {
149 g_archive_map.clear();
150}
151
152/// Shutdown archives
153void ArchiveShutdown() {
154 g_archive_map.clear();
155}
156
157} // namespace Kernel
diff --git a/src/core/hle/kernel/archive.h b/src/core/hle/kernel/archive.h
new file mode 100644
index 000000000..3758e7061
--- /dev/null
+++ b/src/core/hle/kernel/archive.h
@@ -0,0 +1,38 @@
1// Copyright 2014 Citra Emulator Project
2// Licensed under GPLv2
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include "common/common_types.h"
8
9#include "core/hle/kernel/kernel.h"
10#include "core/file_sys/archive.h"
11
12////////////////////////////////////////////////////////////////////////////////////////////////////
13// Kernel namespace
14
15namespace Kernel {
16
17/**
18 * Opens an archive
19 * @param id_code IdCode of the archive to open
20 * @return Handle to archive if it exists, otherwise a null handle (0)
21 */
22Handle OpenArchive(FileSys::Archive::IdCode id_code);
23
24/**
25 * Creates an Archive
26 * @param backend File system backend interface to the archive
27 * @param name Optional name of Archive
28 * @return Handle to newly created Archive object
29 */
30Handle CreateArchive(FileSys::Archive* backend, const std::string& name);
31
32/// Initialize archives
33void ArchiveInit();
34
35/// Shutdown archives
36void ArchiveShutdown();
37
38} // namespace FileSys
diff --git a/src/core/hle/kernel/kernel.cpp b/src/core/hle/kernel/kernel.cpp
index cda183add..7d9bd261e 100644
--- a/src/core/hle/kernel/kernel.cpp
+++ b/src/core/hle/kernel/kernel.cpp
@@ -9,6 +9,7 @@
9#include "core/core.h" 9#include "core/core.h"
10#include "core/hle/kernel/kernel.h" 10#include "core/hle/kernel/kernel.h"
11#include "core/hle/kernel/thread.h" 11#include "core/hle/kernel/thread.h"
12#include "core/hle/kernel/archive.h"
12 13
13namespace Kernel { 14namespace Kernel {
14 15
@@ -133,11 +134,13 @@ Object* ObjectPool::CreateByIDType(int type) {
133/// Initialize the kernel 134/// Initialize the kernel
134void Init() { 135void Init() {
135 Kernel::ThreadingInit(); 136 Kernel::ThreadingInit();
137 Kernel::ArchiveInit();
136} 138}
137 139
138/// Shutdown the kernel 140/// Shutdown the kernel
139void Shutdown() { 141void Shutdown() {
140 Kernel::ThreadingShutdown(); 142 Kernel::ThreadingShutdown();
143 Kernel::ArchiveShutdown();
141 144
142 g_object_pool.Clear(); // Free all kernel objects 145 g_object_pool.Clear(); // Free all kernel objects
143} 146}
diff --git a/src/core/hle/kernel/kernel.h b/src/core/hle/kernel/kernel.h
index 3f15da0ac..69f4ddd37 100644
--- a/src/core/hle/kernel/kernel.h
+++ b/src/core/hle/kernel/kernel.h
@@ -29,6 +29,7 @@ enum class HandleType : u32 {
29 Arbiter = 9, 29 Arbiter = 9,
30 File = 10, 30 File = 10,
31 Semaphore = 11, 31 Semaphore = 11,
32 Archive = 12,
32}; 33};
33 34
34enum { 35enum {