diff --git a/bin/.gitignore b/bin/.gitignore index cbc35af..dc4f40b 100644 --- a/bin/.gitignore +++ b/bin/.gitignore @@ -10,3 +10,10 @@ keys.xml # Logs *.log + +# IDA Pro +*.id0 +*.id1 +*.id2 +*.nam +*.til diff --git a/nucleus/core/core.vcxitems b/nucleus/core/core.vcxitems index cf01b69..4b609e4 100644 --- a/nucleus/core/core.vcxitems +++ b/nucleus/core/core.vcxitems @@ -18,10 +18,6 @@ - - - - @@ -37,10 +33,6 @@ - - - - diff --git a/nucleus/core/core.vcxitems.filters b/nucleus/core/core.vcxitems.filters index 32e4735..f9d1f43 100644 --- a/nucleus/core/core.vcxitems.filters +++ b/nucleus/core/core.vcxitems.filters @@ -8,18 +8,6 @@ externals - - loader - - - loader - - - loader - - - loader - @@ -33,18 +21,6 @@ externals - - loader - - - loader - - - loader - - - loader - @@ -55,18 +31,15 @@ - - + + {e809ab99-fe03-4cdd-bb7b-b5f8c53f32a4} - - {2babb73a-fe6f-43bb-acfc-ef94369243b5} - diff --git a/nucleus/emulator.cpp b/nucleus/emulator.cpp index 3e96bd2..91c02d7 100644 --- a/nucleus/emulator.cpp +++ b/nucleus/emulator.cpp @@ -13,14 +13,76 @@ #include "nucleus/cpu/cell.h" #include "nucleus/gpu/list.h" #include "nucleus/filesystem/utils.h" -#include "nucleus/loader/self.h" #include "nucleus/logger/logger.h" #include "nucleus/memory/memory.h" -#include "nucleus/system/scei/cellos/lv2.h" +#include "nucleus/system/loader.h" +#include "nucleus/system/scei/self.h" +#include "nucleus/system/list.h" // Global emulator object Emulator nucleus; +/** + * Load specific platform + */ +bool Emulator::load_ps3(const std::string& path) { + // Initialize hardware + memory = std::make_shared(); + cpu = std::make_shared(memory); + gpu = std::make_shared(memory, graphics); + sys = std::make_shared(memory, sys::LV2_DEX); + + // Initialize application filesystem devices + const fs::Path& processPath = fs::getProcessPath(path); + sys->vfs.registerDevice(new fs::HostPathDevice("/app_home/", processPath)); + + // Load ELF/SELF file + SELFLoader self; + auto file = fs::HostFileSystem::openFile(path, fs::Read); + if (!self.open(file.get())) { + logger.error(LOG_COMMON, "Invalid file given."); + return false; + } + + self.load_elf(static_cast(sys.get())->proc); + if (self.getMachine() != EM_PPC64) { + logger.error(LOG_COMMON, "Only PPC64 executables are allowed"); + return false; + } + + auto entry = self.getEntry(); + static_cast(sys.get())->init(entry); + return true; +} + +bool Emulator::load_ps4(const std::string& path) { + // Initialize hardware + gpu = std::make_shared(graphics); + sys = std::make_shared(); + + // Initialize application filesystem devices + const fs::Path& processPath = fs::getProcessPath(path); + sys->vfs.registerDevice(new fs::HostPathDevice("/app0/", processPath)); + + // Load ELF/SELF file + SELFLoader self; + auto file = fs::HostFileSystem::openFile(path, fs::Read); + if (!self.open(file.get())) { + logger.error(LOG_COMMON, "Invalid file given."); + return false; + } + + self.load_elf(static_cast(sys.get())->proc); + if (self.getMachine() != EM_X86_64) { + logger.error(LOG_COMMON, "Only PPC64 executables are allowed"); + return false; + } + + auto entry = self.getEntry(); + static_cast(sys.get())->init(entry); + return true; +} + bool Emulator::initialize(const gfx::BackendParameters& params) { // Select graphics backend switch (config.graphicsBackend) { @@ -93,33 +155,29 @@ bool Emulator::initialize(const gfx::BackendParameters& params) { } bool Emulator::load(const std::string& filepath) { - // Initialize hardware - memory = std::make_shared(); - cpu = std::make_shared(memory); - gpu = std::make_shared(memory, graphics); - sys = std::make_shared(memory, sys::LV2_DEX); - - // Initialize application filesystem devices - const fs::Path& processPath = fs::getProcessPath(filepath); - sys->vfs.registerDevice(new fs::HostPathDevice("/app_home/", processPath)); - - // Load ELF/SELF file - SELFLoader self; - auto file = fs::HostFileSystem::openFile(filepath, fs::Read); - if (!self.open(file.get())) { - logger.error(LOG_COMMON, "Invalid file given."); + // TODO: This is not a good way of detecting a platform + core::Platform platform; + switch (detectFiletype(filepath)) { + case FILETYPE_SELF: + platform = core::PLATFORM_PS3; + break; + case FILETYPE_ELF: + platform = core::PLATFORM_PS4; + break; + default: + logger.error(LOG_COMMON, "Unsupported file"); return false; } - self.load_elf(static_cast(sys.get())->proc); - if (self.getMachine() != EM_PPC64) { - logger.error(LOG_COMMON, "Only PPC64 executables are allowed"); + switch (platform) { + case core::PLATFORM_PS3: + return load_ps3(filepath); + case core::PLATFORM_PS4: + return load_ps4(filepath); + default: + logger.error(LOG_COMMON, "Unsupported platform"); return false; } - - auto entry = self.getEntry(); - static_cast(sys.get())->init(entry); - return true; } void Emulator::run() { diff --git a/nucleus/emulator.h b/nucleus/emulator.h index d0abf80..23ecfd4 100644 --- a/nucleus/emulator.h +++ b/nucleus/emulator.h @@ -27,6 +27,10 @@ class Emulator { EmulatorEvent m_event; EmulatorStatus m_status; + // Load specific platform + bool load_ps3(const std::string& path); + bool load_ps4(const std::string& path); + public: std::shared_ptr audio; std::shared_ptr graphics; diff --git a/nucleus/gpu/gpu.h b/nucleus/gpu/gpu.h index 7ba6cd8..10f0666 100644 --- a/nucleus/gpu/gpu.h +++ b/nucleus/gpu/gpu.h @@ -7,6 +7,7 @@ // Forward declarations namespace gfx { class Texture; } +namespace gfx { class IBackend; } namespace gpu { diff --git a/nucleus/gpu/gpu.vcxitems b/nucleus/gpu/gpu.vcxitems index 16c6640..7e54df5 100644 --- a/nucleus/gpu/gpu.vcxitems +++ b/nucleus/gpu/gpu.vcxitems @@ -15,6 +15,7 @@ + @@ -26,6 +27,7 @@ + diff --git a/nucleus/gpu/gpu.vcxitems.filters b/nucleus/gpu/gpu.vcxitems.filters index 8491877..a4a8690 100644 --- a/nucleus/gpu/gpu.vcxitems.filters +++ b/nucleus/gpu/gpu.vcxitems.filters @@ -42,6 +42,9 @@ rsx + + r10xx + @@ -63,6 +66,9 @@ rsx + + r10xx + diff --git a/nucleus/gpu/list.h b/nucleus/gpu/list.h index cc92fbd..e53aa74 100644 --- a/nucleus/gpu/list.h +++ b/nucleus/gpu/list.h @@ -11,7 +11,7 @@ #include "nucleus/gpu/rsx/rsx.h" #endif #ifdef NUCLEUS_PLATFORM_PS4 -//#include "nucleus/gpu/r10xx/r10xx.h" +#include "nucleus/gpu/r10xx/r10xx.h" #endif namespace gpu { @@ -21,7 +21,7 @@ namespace gpu { using RSX = rsx::RSX; #endif #ifdef NUCLEUS_PLATFORM_PS4 -//using R10XX = r10xx::R10XX; +using R10XX = r10xx::R10XX; #endif } // namespace gpu diff --git a/nucleus/gpu/r10xx/r10xx.cpp b/nucleus/gpu/r10xx/r10xx.cpp new file mode 100644 index 0000000..162ebea --- /dev/null +++ b/nucleus/gpu/r10xx/r10xx.cpp @@ -0,0 +1,19 @@ +/** + * (c) 2014-2016 Alexandro Sanchez Bach. All rights reserved. + * Released under GPL v2 license. Read LICENSE for more details. + */ + +#include "r10xx.h" + +namespace gpu { +namespace r10xx { + +R10XX::R10XX(std::shared_ptr graphics) { +} + +gfx::Texture* R10XX::getFrontBuffer() { + return nullptr; +} + +} // namespace r10xx +} // namespace gpu diff --git a/nucleus/gpu/r10xx/r10xx.h b/nucleus/gpu/r10xx/r10xx.h new file mode 100644 index 0000000..ac4cbb2 --- /dev/null +++ b/nucleus/gpu/r10xx/r10xx.h @@ -0,0 +1,23 @@ +/** + * (c) 2014-2016 Alexandro Sanchez Bach. All rights reserved. + * Released under GPL v2 license. Read LICENSE for more details. + */ + +#pragma once + +#include "nucleus/gpu/gpu.h" + +#include + +namespace gpu { +namespace r10xx { + +class R10XX : public GPU { +public: + R10XX(std::shared_ptr graphics); + + virtual gfx::Texture* getFrontBuffer() override; +}; + +} // namespace r10xx +} // namespace gpu diff --git a/nucleus/nucleus.cpp b/nucleus/nucleus.cpp index 742004d..9ca29d7 100644 --- a/nucleus/nucleus.cpp +++ b/nucleus/nucleus.cpp @@ -58,7 +58,6 @@ int nucleusInitialize(int argc, char **argv) { // Start emulator if (!config.boot.empty()) { - nucleus.load(config.boot); nucleus.run(); nucleus.idle(); diff --git a/nucleus/platform.h b/nucleus/platform.h index c34b4b6..add31e5 100644 --- a/nucleus/platform.h +++ b/nucleus/platform.h @@ -24,6 +24,8 @@ namespace core { enum Platform { + PLATFORM_UNKNOWN = 0, + PLATFORM_PS3, PLATFORM_PS4, PLATFORM_PSP, diff --git a/nucleus/loader/keys.cpp b/nucleus/system/keys.cpp similarity index 100% rename from nucleus/loader/keys.cpp rename to nucleus/system/keys.cpp diff --git a/nucleus/loader/keys.h b/nucleus/system/keys.h similarity index 100% rename from nucleus/loader/keys.h rename to nucleus/system/keys.h diff --git a/nucleus/system/list.h b/nucleus/system/list.h new file mode 100644 index 0000000..bc355de --- /dev/null +++ b/nucleus/system/list.h @@ -0,0 +1,28 @@ +/** + * (c) 2014-2016 Alexandro Sanchez Bach. All rights reserved. + * Released under GPL v2 license. Read LICENSE for more details. + */ + +#pragma once + +#include "nucleus/common.h" + +#ifdef NUCLEUS_PLATFORM_PS3 +#include "nucleus/system/scei/cellos/lv1.h" +#include "nucleus/system/scei/cellos/lv2.h" +#endif +#ifdef NUCLEUS_PLATFORM_PS4 +#include "nucleus/system/scei/orbisos/orbisos.h" +#endif + +namespace sys { + +// Shorthands +#ifdef NUCLEUS_PLATFORM_PS3 +using LV2 = sys::LV2; +#endif +#ifdef NUCLEUS_PLATFORM_PS4 +using OrbisOS = sys::scei::orbis::OrbisOS; +#endif + +} // namespace sys diff --git a/nucleus/loader/loader.cpp b/nucleus/system/loader.cpp similarity index 100% rename from nucleus/loader/loader.cpp rename to nucleus/system/loader.cpp diff --git a/nucleus/loader/loader.h b/nucleus/system/loader.h similarity index 100% rename from nucleus/loader/loader.h rename to nucleus/system/loader.h diff --git a/nucleus/system/scei/cellos/lv2/sys_prx.cpp b/nucleus/system/scei/cellos/lv2/sys_prx.cpp index 504e84f..5e54c93 100644 --- a/nucleus/system/scei/cellos/lv2/sys_prx.cpp +++ b/nucleus/system/scei/cellos/lv2/sys_prx.cpp @@ -10,7 +10,7 @@ #include "nucleus/system/scei/cellos/callback.h" #include "nucleus/system/scei/cellos/lv2.h" #include "nucleus/system/scei/cellos/lv2/sys_process.h" -#include "nucleus/loader/self.h" +#include "nucleus/system/scei/self.h" namespace sys { diff --git a/nucleus/system/scei/orbisos/orbisos.cpp b/nucleus/system/scei/orbisos/orbisos.cpp index 8f5b19f..6833cb8 100644 --- a/nucleus/system/scei/orbisos/orbisos.cpp +++ b/nucleus/system/scei/orbisos/orbisos.cpp @@ -4,19 +4,26 @@ */ #include "orbisos.h" -#include "nucleus/system/system.h" namespace sys { namespace scei { namespace orbis { -struct OrbisSyscall { - const char* name; -}; +OrbisOS::OrbisOS() { + // Initialize sandbox directories + vfs.registerDevice(new fs::HostPathDevice("/host/", "")); +} + +bool OrbisOS::init(U64 entry) { + // TODO: Load /system/common/lib/libkernel.sprx + + // TODO: Run libkernel.sprx start function + + // TODO: Jump to executable entry point + + return true; +} -class OrbisOS : public System { -}; - } // namespace orbis } // namespace scei } // namespace sys diff --git a/nucleus/system/scei/orbisos/orbisos.h b/nucleus/system/scei/orbisos/orbisos.h index 8821ff1..7afa740 100644 --- a/nucleus/system/scei/orbisos/orbisos.h +++ b/nucleus/system/scei/orbisos/orbisos.h @@ -5,10 +5,32 @@ #pragma once +#include "nucleus/common.h" +#include "nucleus/system/system.h" +#include "nucleus/system/scei/cellos/lv2/sys_process.h" // TODO: Just for sys_process_t + namespace sys { namespace scei { namespace orbis { - + +struct OrbisSyscall { + const char* name; +}; + +class OrbisOS : public System { +public: + // Kernel information + sys_process_t proc; // TODO: Is this really necessary + + OrbisOS(); + + /** + * Start the process at the given entry point + * @param[in] entry Module entry point + */ + bool init(U64 entry); +}; + } // namespace orbis } // namespace scei } // namespace sys diff --git a/nucleus/loader/psf.cpp b/nucleus/system/scei/psf.cpp similarity index 98% rename from nucleus/loader/psf.cpp rename to nucleus/system/scei/psf.cpp index 0b0360d..81a7930 100644 --- a/nucleus/loader/psf.cpp +++ b/nucleus/system/scei/psf.cpp @@ -8,7 +8,7 @@ #include "nucleus/system/system.h" #include "nucleus/format.h" #include "nucleus/filesystem/filesystem_virtual.h" -#include "nucleus/loader/loader.h" +#include "nucleus/system/loader.h" #include "nucleus/logger/logger.h" bool PSFLoader::open(const std::string& path) diff --git a/nucleus/loader/psf.h b/nucleus/system/scei/psf.h similarity index 100% rename from nucleus/loader/psf.h rename to nucleus/system/scei/psf.h diff --git a/nucleus/loader/self.cpp b/nucleus/system/scei/self.cpp similarity index 99% rename from nucleus/loader/self.cpp rename to nucleus/system/scei/self.cpp index 40a2bcc..c20f538 100644 --- a/nucleus/loader/self.cpp +++ b/nucleus/system/scei/self.cpp @@ -10,8 +10,8 @@ #include "nucleus/cpu/cell.h" #include "nucleus/system/scei/cellos/lv2.h" #include "nucleus/cpu/frontend/ppu/ppu_decoder.h" -#include "nucleus/loader/keys.h" -#include "nucleus/loader/loader.h" +#include "nucleus/system/keys.h" +#include "nucleus/system/loader.h" #include "nucleus/logger/logger.h" #include "externals/aes.h" diff --git a/nucleus/loader/self.h b/nucleus/system/scei/self.h similarity index 99% rename from nucleus/loader/self.h rename to nucleus/system/scei/self.h index 17fc99a..948147f 100644 --- a/nucleus/loader/self.h +++ b/nucleus/system/scei/self.h @@ -30,6 +30,7 @@ enum ELFMachine { EM_PPC64 = 0x15, EM_SPU = 0x17, EM_ARM = 0x28, + EM_X86_64 = 0x3E, }; // Segment types diff --git a/nucleus/system/system.vcxitems b/nucleus/system/system.vcxitems index bb9cb9f..0cfe19e 100644 --- a/nucleus/system/system.vcxitems +++ b/nucleus/system/system.vcxitems @@ -14,6 +14,9 @@ + + + @@ -46,9 +49,13 @@ + + + + @@ -76,5 +83,7 @@ + + \ No newline at end of file diff --git a/nucleus/system/system.vcxitems.filters b/nucleus/system/system.vcxitems.filters index d004130..7bd6e34 100644 --- a/nucleus/system/system.vcxitems.filters +++ b/nucleus/system/system.vcxitems.filters @@ -116,6 +116,15 @@ scei\orbisos + + + + scei + + + scei + + @@ -199,5 +208,13 @@ scei\orbisos + + + + scei + + + scei + \ No newline at end of file diff --git a/wrappers/android/nucleus-android-native.vcxproj b/wrappers/android/nucleus-android-native.vcxproj index dc22286..8c21923 100644 --- a/wrappers/android/nucleus-android-native.vcxproj +++ b/wrappers/android/nucleus-android-native.vcxproj @@ -204,6 +204,7 @@ Enabled $(SolutionDir);$(Sysroot)\usr\include;$(StlIncludeDirectories);%(AdditionalIncludeDirectories) c++1y + _NUCLEUS_FEATURE_AUDIOBACKEND_XAUDIO2;_NUCLEUS_FEATURE_GFXBACKEND_VULKAN; %(LibraryDependencies);GLESv2;EGL;m @@ -215,6 +216,7 @@ Enabled $(SolutionDir);$(Sysroot)\usr\include;$(StlIncludeDirectories);%(AdditionalIncludeDirectories) c++1y + _NUCLEUS_FEATURE_AUDIOBACKEND_XAUDIO2;_NUCLEUS_FEATURE_GFXBACKEND_VULKAN;NDEBUG;%(PreprocessorDefinitions) %(LibraryDependencies);GLESv2;EGL;m diff --git a/wrappers/windows/nucleus-windows.vcxproj b/wrappers/windows/nucleus-windows.vcxproj index e25b55e..fa0b8e9 100644 --- a/wrappers/windows/nucleus-windows.vcxproj +++ b/wrappers/windows/nucleus-windows.vcxproj @@ -71,7 +71,7 @@ true $(SolutionDir); $(IntDir)\%(Directory)\ - _NUCLEUS_FEATURE_AUDIOBACKEND_XAUDIO2;_NUCLEUS_FEATURE_GFXBACKEND_DIRECT3D12;_NUCLEUS_FEATURE_GFXBACKEND_VULKAN;_MBCS;%(PreprocessorDefinitions) + _NUCLEUS_FEATURE_AUDIOBACKEND_XAUDIO2;_NUCLEUS_FEATURE_AUDIOBACKEND_XAUDIO2;_NUCLEUS_FEATURE_GFXBACKEND_DIRECT3D12;_NUCLEUS_FEATURE_GFXBACKEND_VULKAN;_MBCS;%(PreprocessorDefinitions) true @@ -88,7 +88,7 @@ true $(SolutionDir); $(IntDir)\%(Directory)\ - _NUCLEUS_FEATURE_GFXBACKEND_DIRECT3D12;_NUCLEUS_FEATURE_GFXBACKEND_VULKAN;_MBCS;%(PreprocessorDefinitions) + _NUCLEUS_FEATURE_AUDIOBACKEND_XAUDIO2;_NUCLEUS_FEATURE_AUDIOBACKEND_XAUDIO2;_NUCLEUS_FEATURE_GFXBACKEND_DIRECT3D12;_NUCLEUS_FEATURE_GFXBACKEND_VULKAN;_MBCS;%(PreprocessorDefinitions) true