Add a bunch of #ifdefs to keep things working as expected on linux

This commit is contained in:
Tyler Wilding
2020-09-03 22:24:50 -04:00
parent f68f220e5b
commit ef09eb12c8
26 changed files with 336 additions and 419 deletions
+56 -51
View File
@@ -3,10 +3,15 @@
* Setup and launcher for the runtime.
*/
#ifdef __linux__
#include <unistd.h>
#include <sys/mman.h>
#elif _WIN32
#include <io.h>
#include <third-party/mman/mman.h>
#include <cstring>
#include <Windows.h>
#endif
#include <cstring>
#include "runtime.h"
#include "system/SystemThread.h"
@@ -40,8 +45,9 @@
u8* g_ee_main_mem = nullptr;
/*!
* runtime.cpp - Deci2Listener has been disabled for now, pending rewriting for Windows.
*/
* TODO-WINDOWS
* runtime.cpp - Deci2Listener has been disabled for now, pending rewriting for Windows.
*/
namespace {
@@ -49,49 +55,45 @@ namespace {
* SystemThread function for running the DECI2 communication with the GOAL compiler.
*/
void deci2_runner(SystemThreadInterface& interfaces) {
interfaces.initialization_complete();
while (true) {
// TODO-WINDOWS
#ifdef __linux__
// callback function so the server knows when to give up and shutdown
std::function<bool()> shutdown_callback = [&]() { return interface.get_want_exit(); };
// create and register server
Deci2Server server(shutdown_callback);
ee::LIBRARY_sceDeci2_register(&server);
// now its ok to continue with initialization
interface.initialization_complete();
// in our own thread, wait for the EE to register the first protocol driver
printf("[DECI2] waiting for EE to register protos\n");
server.wait_for_protos_ready();
// then allow the server to accept connections
if (!server.init()) {
throw std::runtime_error("DECI2 server init failed");
}
// // callback function so the server knows when to give up and shutdown
// std::function<bool()> shutdown_callback = [&]() { return interfaces.get_want_exit(); };
//
// // create and register server
//// Deci2Server server(shutdown_callback);
//// ee::LIBRARY_sceDeci2_register(&server);
//
// // now its ok to continue with initialization
// interfaces.initialization_complete();
//
// // in our own thread, wait for the EE to register the first protocol driver
// printf("[DECI2] waiting for EE to register protos\n");
// server.wait_for_protos_ready();
// // then allow the server to accept connections
// if (!server.init()) {
// throw std::runtime_error("DECI2 server init failed");
// }
//
// printf("[DECI2] waiting for listener...\n");
// bool saw_listener = false;
// while (!interfaces.get_want_exit()) {
// if (server.check_for_listener()) {
// if (!saw_listener) {
// printf("[DECI2] Connected!\n");
// }
// saw_listener = true;
// // we have a listener, run!
// server.run();
// } else {
// // no connection yet. Do a sleep so we don't spam checking the listener.
// Sleep(1000);
// }
// }
printf("[DECI2] waiting for listener...\n");
bool saw_listener = false;
while (!interface.get_want_exit()) {
if (server.check_for_listener()) {
if (!saw_listener) {
printf("[DECI2] Connected!\n");
}
saw_listener = true;
// we have a listener, run!
server.run();
} else {
// no connection yet. Do a sleep so we don't spam checking the listener.
usleep(50000);
}
}
#endif
}
// EE System
constexpr int EE_MAIN_MEM_SIZE = 128 * (1 << 20); // 128 MB, same as PS2 TOOL
constexpr u64 EE_MAIN_MEM_MAP = 0x2000000000; // intentionally > 32-bit to catch pointer bugs
@@ -108,7 +110,7 @@ constexpr int GOAL_ARGC = 4;
/*!
* SystemThread Function for the EE (PS2 Main CPU)
*/
void ee_runner(SystemThreadInterface& interfaces) {
void ee_runner(SystemThreadInterface& iface) {
// Allocate Main RAM. Must have execute enabled.
if (EE_MEM_LOW_MAP) {
g_ee_main_mem =
@@ -122,7 +124,7 @@ void ee_runner(SystemThreadInterface& interfaces) {
if (g_ee_main_mem == (u8*)(-1)) {
printf(" Failed to initialize main memory! %s\n", strerror(errno));
interfaces.initialization_complete();
iface.initialization_complete();
return;
}
@@ -131,7 +133,7 @@ void ee_runner(SystemThreadInterface& interfaces) {
(double)EE_MAIN_MEM_SIZE / (1 << 20));
printf("[EE] Initialization complete!\n");
interfaces.initialization_complete();
iface.initialization_complete();
printf("[EE] Run!\n");
memset((void*)g_ee_main_mem, 0, EE_MAIN_MEM_SIZE);
@@ -158,13 +160,13 @@ void ee_runner(SystemThreadInterface& interfaces) {
munmap(g_ee_main_mem, EE_MAIN_MEM_SIZE);
// after main returns, trigger a shutdown.
interfaces.trigger_shutdown();
iface.trigger_shutdown();
}
/*!
* SystemThread function for running the IOP (separate I/O Processor)
*/
void iop_runner(SystemThreadInterface& interfaces) {
void iop_runner(SystemThreadInterface& iface) {
IOP iop;
printf("\n\n\n[IOP] Restart!\n");
iop.reset_allocator();
@@ -187,7 +189,7 @@ void iop_runner(SystemThreadInterface& interfaces) {
// ssound
// stream
interfaces.initialization_complete();
iface.initialization_complete();
printf("[IOP] Wait for OVERLORD to be started...\n");
iop.wait_for_overlord_start_cmd();
@@ -208,7 +210,7 @@ void iop_runner(SystemThreadInterface& interfaces) {
iop.signal_overlord_init_finish();
// IOP Kernel loop
while (!interfaces.get_want_exit() && !iop.want_exit) {
while (!iface.get_want_exit() && !iop.want_exit) {
// the IOP kernel just runs at full blast, so we only run the IOP when the EE is waiting on the
// IOP. Each time the EE is waiting on the IOP, it will run an iteration of the IOP kernel.
iop.wait_run_iop();
@@ -233,7 +235,10 @@ void exec_runtime(int argc, char** argv) {
// step 1: sce library prep
iop::LIBRARY_INIT();
ee::LIBRARY_INIT_sceCd();
//ee::LIBRARY_INIT_sceDeci2();
// TODO-WINDOWS
#ifdef __linux__
ee::LIBRARY_INIT_sceDeci2();
#endif
ee::LIBRARY_INIT_sceSif();
// step 2: system prep
@@ -246,7 +251,7 @@ void exec_runtime(int argc, char** argv) {
iop_thread.start(iop_runner);
ee_thread.start(ee_runner);
deci_thread.start(deci2_runner);
// step 4: wait for EE to signal a shutdown, which will cause the DECI thread to join.
deci_thread.join();
// DECI has been killed, shutdown!
@@ -257,4 +262,4 @@ void exec_runtime(int argc, char** argv) {
// join and exit
tm.join();
printf("GOAL Runtime Shutdown\n");
}
}