Implement reading from RomFS

This commit is contained in:
wheremyfoodat 2022-10-09 18:28:45 +03:00
parent 272cdefca1
commit df4cd0642d
10 changed files with 157 additions and 33 deletions

View file

@ -44,6 +44,18 @@ struct FSPath {
u32 pointer; // Pointer to the actual path data
};
class ArchiveBase;
struct FileSession {
ArchiveBase* archive = nullptr;
FSPath path;
bool isOpen;
FileSession(ArchiveBase* archive, const FSPath& filePath, bool isOpen = true) : archive(archive), isOpen(isOpen) {
path = filePath;
}
};
class ArchiveBase {
protected:
using Result = u32;
@ -56,6 +68,10 @@ public:
virtual bool openFile(const FSPath& path) = 0;
virtual ArchiveBase* openArchive(FSPath& path) = 0;
// Read size bytes from a file starting at offset "offset" into a certain buffer in memory
// Returns the number of bytes read, or nullopt if the read failed
virtual std::optional<u32> readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) = 0;
ArchiveBase(Memory& mem) : mem(mem) {}
};

View file

@ -4,25 +4,11 @@ class SelfNCCHArchive : public ArchiveBase {
public:
SelfNCCHArchive(Memory& mem) : ArchiveBase(mem) {}
u64 getFreeBytes() override { return 0; }
const char* name() override { return "SelfNCCH"; }
bool openFile(const FSPath& path) override {
if (path.type != PathType::Binary) {
printf("Invalid SelfNCCH path type");
return false;
}
return true;
}
ArchiveBase* openArchive(FSPath& path) override {
if (path.type != PathType::Empty) {
printf("Invalid path type for SelfNCCH archive: %d\n", path.type);
return nullptr;
}
return this;
}
bool openFile(const FSPath& path) override;
ArchiveBase* openArchive(FSPath& path) override;
std::optional<u32> readFile(FileSession* file, u64 offset, u32 size, u32 dataPointer) override;
};

View file

@ -84,6 +84,7 @@ class Kernel {
MAKE_LOG_FUNCTION(logSVC, svcLogger)
MAKE_LOG_FUNCTION(logDebugString, debugStringLogger)
MAKE_LOG_FUNCTION(logError, errorLogger)
MAKE_LOG_FUNCTION(logFileIO, fileIOLogger)
// SVC implementations
void arbitrateAddress();
@ -110,6 +111,7 @@ class Kernel {
// File operations
void handleFileOperation(u32 messagePointer, Handle file);
void closeFile(u32 messagePointer, Handle file);
void readFile(u32 messagePointer, Handle file);
public:

View file

@ -93,15 +93,6 @@ struct Session {
Session(Handle portHandle) : portHandle(portHandle) {}
};
struct FileSession {
ArchiveBase* archive = nullptr;
FSPath path;
FileSession(ArchiveBase* archive, const FSPath& filePath) : archive(archive) {
path = filePath;
}
};
enum class ThreadStatus {
Running, // Currently running
Ready, // Ready to run

View file

@ -21,6 +21,7 @@ namespace Log {
static Logger<true> kernelLogger;
static Logger<true> debugStringLogger; // Enables output for the outputDebugString SVC
static Logger<true> errorLogger;
static Logger<true> fileIOLogger;
static Logger<true> svcLogger;
static Logger<true> gpuLogger;

View file

@ -139,6 +139,14 @@ public:
u32 getLinearHeapVaddr();
u8* getFCRAM() { return fcram; }
NCCH* getCXI() {
if (loadedCXI.has_value()) {
return &loadedCXI.value();
} else {
return nullptr;
}
}
// Returns whether "addr" is aligned to a page (4096 byte) boundary
static constexpr bool isAligned(u32 addr) {
return (addr & pageMask) == 0;
@ -165,4 +173,9 @@ public:
// TODO: Find out
// Returns a pointer to the FCRAM block used for the memory if allocation succeeded
u8* mapSharedMemory(Handle handle, u32 vaddr, u32 myPerms, u32 otherPerms);
// Backup of the game's CXI partition info, if any
std::optional<NCCH> loadedCXI = std::nullopt;
// File handle for reading the loaded ncch
IOFile CXIFile;
};