Converting everything to C++ cause I'm a masochist.
This commit is contained in:
@@ -10,14 +10,18 @@
|
||||
#include <xenia/xenia.h>
|
||||
|
||||
|
||||
using namespace xe;
|
||||
using namespace xe::cpu;
|
||||
using namespace xe::kernel;
|
||||
|
||||
|
||||
int xenia_info(int argc, xechar_t **argv) {
|
||||
int result_code = 1;
|
||||
|
||||
xe_pal_ref pal = NULL;
|
||||
xe_memory_ref memory = NULL;
|
||||
xe_cpu_ref cpu = NULL;
|
||||
xe_kernel_ref kernel = NULL;
|
||||
xe_module_ref module = NULL;
|
||||
shared_ptr<Processor> processor;
|
||||
shared_ptr<Runtime> runtime;
|
||||
|
||||
// TODO(benvanik): real command line parsing.
|
||||
if (argc < 2) {
|
||||
@@ -36,26 +40,15 @@ int xenia_info(int argc, xechar_t **argv) {
|
||||
memory = xe_memory_create(pal, memory_options);
|
||||
XEEXPECTNOTNULL(memory);
|
||||
|
||||
xe_cpu_options_t cpu_options;
|
||||
xe_zero_struct(&cpu_options, sizeof(cpu_options));
|
||||
cpu = xe_cpu_create(pal, memory, cpu_options);
|
||||
XEEXPECTNOTNULL(cpu);
|
||||
processor = shared_ptr<Processor>(new Processor(pal, memory));
|
||||
XEEXPECTZERO(processor->Setup());
|
||||
|
||||
xe_kernel_options_t kernel_options;
|
||||
xe_zero_struct(&kernel_options, sizeof(kernel_options));
|
||||
kernel = xe_kernel_create(pal, cpu, kernel_options);
|
||||
XEEXPECTNOTNULL(kernel);
|
||||
runtime = shared_ptr<Runtime>(new Runtime(pal, processor, XT("")));
|
||||
|
||||
module = xe_kernel_load_module(kernel, path);
|
||||
XEEXPECTNOTNULL(module);
|
||||
|
||||
xe_module_dump(module);
|
||||
XEEXPECTZERO(runtime->LoadModule(path));
|
||||
|
||||
result_code = 0;
|
||||
XECLEANUP:
|
||||
xe_module_release(module);
|
||||
xe_kernel_release(kernel);
|
||||
xe_cpu_release(cpu);
|
||||
xe_memory_release(memory);
|
||||
xe_pal_release(pal);
|
||||
return result_code;
|
||||
|
||||
@@ -10,52 +10,63 @@
|
||||
#include <xenia/xenia.h>
|
||||
|
||||
|
||||
typedef struct {
|
||||
xe_pal_ref pal;
|
||||
xe_memory_ref memory;
|
||||
xe_cpu_ref cpu;
|
||||
xe_kernel_ref kernel;
|
||||
xe_module_ref module;
|
||||
} xenia_run_t;
|
||||
using namespace xe;
|
||||
using namespace xe::cpu;
|
||||
using namespace xe::kernel;
|
||||
|
||||
|
||||
int setup_run(xenia_run_t *run, const xechar_t *path) {
|
||||
xe_pal_options_t pal_options;
|
||||
class Run {
|
||||
public:
|
||||
Run();
|
||||
~Run();
|
||||
|
||||
int Setup(const xechar_t* path);
|
||||
int Launch();
|
||||
|
||||
private:
|
||||
xe_pal_ref pal_;
|
||||
xe_memory_ref memory_;
|
||||
shared_ptr<Processor> processor_;
|
||||
shared_ptr<Runtime> runtime_;
|
||||
UserModule* module_;
|
||||
};
|
||||
|
||||
Run::Run() {
|
||||
}
|
||||
|
||||
Run::~Run() {
|
||||
xe_memory_release(memory_);
|
||||
xe_pal_release(pal_);
|
||||
}
|
||||
|
||||
int Run::Setup(const xechar_t* path) {
|
||||
xe_pal_options_t pal_options;
|
||||
xe_zero_struct(&pal_options, sizeof(pal_options));
|
||||
run->pal = xe_pal_create(pal_options);
|
||||
XEEXPECTNOTNULL(run->pal);
|
||||
pal_ = xe_pal_create(pal_options);
|
||||
XEEXPECTNOTNULL(pal_);
|
||||
|
||||
xe_memory_options_t memory_options;
|
||||
xe_zero_struct(&memory_options, sizeof(memory_options));
|
||||
run->memory = xe_memory_create(run->pal, memory_options);
|
||||
XEEXPECTNOTNULL(run->memory);
|
||||
memory_ = xe_memory_create(pal_, memory_options);
|
||||
XEEXPECTNOTNULL(memory_);
|
||||
|
||||
xe_cpu_options_t cpu_options;
|
||||
xe_zero_struct(&cpu_options, sizeof(cpu_options));
|
||||
run->cpu = xe_cpu_create(run->pal, run->memory, cpu_options);
|
||||
XEEXPECTNOTNULL(run->cpu);
|
||||
processor_ = shared_ptr<Processor>(new Processor(pal_, memory_));
|
||||
XEEXPECTZERO(processor_->Setup());
|
||||
|
||||
xe_kernel_options_t kernel_options;
|
||||
xe_zero_struct(&kernel_options, sizeof(kernel_options));
|
||||
run->kernel = xe_kernel_create(run->pal, run->cpu, kernel_options);
|
||||
XEEXPECTNOTNULL(run->kernel);
|
||||
runtime_ = shared_ptr<Runtime>(new Runtime(pal_, processor_, XT("")));
|
||||
|
||||
run->module = xe_kernel_load_module(run->kernel, path);
|
||||
XEEXPECTNOTNULL(run->module);
|
||||
XEEXPECTZERO(runtime_->LoadModule(path));
|
||||
module_ = runtime_->GetModule(path);
|
||||
|
||||
return 0;
|
||||
|
||||
XECLEANUP:
|
||||
return 1;
|
||||
}
|
||||
|
||||
void destroy_run(xenia_run_t *run) {
|
||||
xe_module_release(run->module);
|
||||
xe_kernel_release(run->kernel);
|
||||
xe_cpu_release(run->cpu);
|
||||
xe_memory_release(run->memory);
|
||||
xe_pal_release(run->pal);
|
||||
xe_free(run);
|
||||
int Run::Launch() {
|
||||
// TODO(benvanik): wait until the module thread exits
|
||||
runtime_->LaunchModule(module_);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int xenia_run(int argc, xechar_t **argv) {
|
||||
@@ -71,24 +82,18 @@ int xenia_run(int argc, xechar_t **argv) {
|
||||
}
|
||||
const xechar_t *path = argv[1];
|
||||
|
||||
xenia_run_t *run = (xenia_run_t*)xe_calloc(sizeof(xenia_run_t));
|
||||
XEEXPECTNOTNULL(run);
|
||||
auto_ptr<Run> run = auto_ptr<Run>(new Run());
|
||||
|
||||
result_code = setup_run(run, path);
|
||||
result_code = run->Setup(path);
|
||||
XEEXPECTZERO(result_code);
|
||||
|
||||
xe_module_dump(run->module);
|
||||
//xe_module_dump(run->module);
|
||||
|
||||
xe_kernel_launch_module(run->kernel, run->module);
|
||||
run->Launch();
|
||||
|
||||
// TODO(benvanik): wait until the module thread exits
|
||||
destroy_run(run);
|
||||
return 0;
|
||||
|
||||
XECLEANUP:
|
||||
if (run) {
|
||||
destroy_run(run);
|
||||
}
|
||||
return result_code;
|
||||
}
|
||||
XE_MAIN_THUNK(xenia_run);
|
||||
|
||||
Reference in New Issue
Block a user