summaryrefslogtreecommitdiffstats
path: root/src/core/loader/loader.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/core/loader/loader.cpp')
-rw-r--r--src/core/loader/loader.cpp39
1 files changed, 22 insertions, 17 deletions
diff --git a/src/core/loader/loader.cpp b/src/core/loader/loader.cpp
index de0ab540a..505e2d280 100644
--- a/src/core/loader/loader.cpp
+++ b/src/core/loader/loader.cpp
@@ -8,16 +8,23 @@
#include "common/make_unique.h"
#include "core/file_sys/archive_romfs.h"
+#include "core/hle/kernel/process.h"
+#include "core/hle/service/fs/archive.h"
#include "core/loader/3dsx.h"
#include "core/loader/elf.h"
#include "core/loader/ncch.h"
-#include "core/hle/service/fs/archive.h"
#include "core/mem_map.h"
////////////////////////////////////////////////////////////////////////////////////////////////////
namespace Loader {
+const std::initializer_list<Kernel::AddressMapping> default_address_mappings = {
+ { 0x1FF50000, 0x8000, true }, // part of DSP RAM
+ { 0x1FF70000, 0x8000, true }, // part of DSP RAM
+ { 0x1F000000, 0x600000, false }, // entire VRAM
+};
+
/**
* Identifies the type of a bootable file
* @param file open file
@@ -42,19 +49,11 @@ static FileType IdentifyFile(FileUtil::IOFile& file) {
/**
* Guess the type of a bootable file from its extension
- * @param filename String filename of bootable file
+ * @param extension String extension of bootable file
* @return FileType of file
*/
-static FileType GuessFromFilename(const std::string& filename) {
- if (filename.size() == 0) {
- LOG_ERROR(Loader, "invalid filename %s", filename.c_str());
- return FileType::Error;
- }
-
- size_t extension_loc = filename.find_last_of('.');
- if (extension_loc == std::string::npos)
- return FileType::Unknown;
- std::string extension = Common::ToLower(filename.substr(extension_loc));
+static FileType GuessFromExtension(const std::string& extension_) {
+ std::string extension = Common::ToLower(extension_);
if (extension == ".elf")
return FileType::ELF;
@@ -100,8 +99,11 @@ ResultStatus LoadFile(const std::string& filename) {
return ResultStatus::Error;
}
+ std::string filename_filename, filename_extension;
+ Common::SplitPath(filename, nullptr, &filename_filename, &filename_extension);
+
FileType type = IdentifyFile(*file);
- FileType filename_type = GuessFromFilename(filename);
+ FileType filename_type = GuessFromExtension(filename_extension);
if (type != filename_type) {
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) {
//3DSX file format...
case FileType::THREEDSX:
- return AppLoader_THREEDSX(std::move(file)).Load();
+ return AppLoader_THREEDSX(std::move(file), filename_filename).Load();
// Standard ELF file format...
case FileType::ELF:
- return AppLoader_ELF(std::move(file)).Load();
+ return AppLoader_ELF(std::move(file), filename_filename).Load();
// NCCH/NCSD container formats...
case FileType::CXI:
@@ -129,7 +131,6 @@ ResultStatus LoadFile(const std::string& filename) {
// Load application and RomFS
if (ResultStatus::Success == app_loader.Load()) {
- Kernel::g_program_id = app_loader.GetProgramId();
Service::FS::RegisterArchiveType(Common::make_unique<FileSys::ArchiveFactory_RomFS>(app_loader), Service::FS::ArchiveIdCode::RomFS);
return ResultStatus::Success;
}
@@ -139,11 +140,15 @@ ResultStatus LoadFile(const std::string& filename) {
// Raw BIN file format...
case FileType::BIN:
{
+ Kernel::g_current_process = Kernel::Process::Create(filename_filename, 0);
+ Kernel::g_current_process->svc_access_mask.set();
+ Kernel::g_current_process->address_mappings = default_address_mappings;
+
size_t size = (size_t)file->GetSize();
if (file->ReadBytes(Memory::GetPointer(Memory::EXEFS_CODE_VADDR), size) != size)
return ResultStatus::Error;
- Kernel::LoadExec(Memory::EXEFS_CODE_VADDR);
+ Kernel::g_current_process->Run(Memory::EXEFS_CODE_VADDR, 0x30, Kernel::DEFAULT_STACK_SIZE);
return ResultStatus::Success;
}