CPU skeleton.

This commit is contained in:
Ben Vanik
2013-01-13 00:34:08 -08:00
parent bcd575f9b0
commit 2f4bc598e5
6 changed files with 230 additions and 23 deletions

View File

@@ -15,6 +15,7 @@ int xenia_info(int argc, xechar_t **argv) {
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;
@@ -26,16 +27,23 @@ int xenia_info(int argc, xechar_t **argv) {
const xechar_t *path = argv[1];
xe_pal_options_t pal_options;
xe_zero_struct(&pal_options, sizeof(pal_options));
pal = xe_pal_create(pal_options);
XEEXPECTNOTNULL(pal);
xe_memory_options_t memory_options;
xe_zero_struct(&memory_options, sizeof(memory_options));
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);
xe_kernel_options_t kernel_options;
xe_zero_struct(&kernel_options, sizeof(kernel_options));
kernel = xe_kernel_create(pal, memory, kernel_options);
kernel = xe_kernel_create(pal, cpu, kernel_options);
XEEXPECTNOTNULL(kernel);
module = xe_kernel_load_module(kernel, path);
@@ -47,6 +55,7 @@ int xenia_info(int argc, xechar_t **argv) {
XECLEANUP:
xe_module_release(module);
xe_kernel_release(kernel);
xe_cpu_release(cpu);
xe_memory_release(memory);
xe_pal_release(pal);
return result_code;

View File

@@ -10,9 +10,85 @@
#include <xenia/xenia.h>
int xenia_run(int argc, xechar_t **argv) {
do_cpu_stuff();
do_gpu_stuff();
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;
int setup_run(xenia_run_t *run, 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);
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);
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);
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);
run->module = xe_kernel_load_module(run->kernel, path);
XEEXPECTNOTNULL(run->module);
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 xenia_run(int argc, xechar_t **argv) {
// Dummy call to keep the GPU code linking in to ensure it's working.
do_gpu_stuff();
int result_code = 1;
// TODO(benvanik): real command line parsing.
if (argc < 2) {
printf("usage: xenia-run some.xex\n");
return 1;
}
const xechar_t *path = argv[1];
xenia_run_t *run = (xenia_run_t*)xe_calloc(sizeof(xenia_run_t));
XEEXPECTNOTNULL(run);
result_code = setup_run(run, path);
XEEXPECTZERO(result_code);
xe_module_dump(run->module);
xe_kernel_launch_module(run->kernel, run->module);
// 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);