Symbol database skeleton.

This commit is contained in:
Ben Vanik
2013-01-14 00:02:24 -08:00
parent bfec194533
commit 6c5432eb45
5 changed files with 179 additions and 0 deletions

View File

@@ -49,6 +49,7 @@ typedef struct xe_cpu {
xe_pal_ref pal;
xe_memory_ref memory;
xe_sdb_ref sdb;
std::vector<xe_cpu_module_entry_t> entries;
@@ -70,6 +71,7 @@ xe_cpu_ref xe_cpu_create(xe_pal_ref pal, xe_memory_ref memory,
cpu->pal = xe_pal_retain(pal);
cpu->memory = xe_memory_retain(memory);
cpu->sdb = xe_sdb_create(memory);
LLVMLinkInInterpreter();
LLVMLinkInJIT();
@@ -97,6 +99,7 @@ void xe_cpu_dealloc(xe_cpu_ref cpu) {
delete cpu->engine;
llvm_shutdown();
xe_sdb_release(cpu->sdb);
xe_memory_release(cpu->memory);
xe_pal_release(cpu->pal);
}
@@ -118,6 +121,10 @@ xe_memory_ref xe_cpu_get_memory(xe_cpu_ref cpu) {
return xe_memory_retain(cpu->memory);
}
xe_sdb_ref xe_cpu_get_sdb(xe_cpu_ref cpu) {
return xe_sdb_retain(cpu->sdb);
}
int xe_cpu_setup_engine(xe_cpu_ref cpu, Module *gen_module) {
if (cpu->engine) {
// Engine already initialized - just add the module.

88
src/cpu/sdb.cc Normal file
View File

@@ -0,0 +1,88 @@
/**
******************************************************************************
* Xenia : Xbox 360 Emulator Research Project *
******************************************************************************
* Copyright 2013 Ben Vanik. All rights reserved. *
* Released under the BSD license - see LICENSE in the root for more details. *
******************************************************************************
*/
#include <xenia/cpu/sdb.h>
struct xe_sdb {
xe_ref_t ref;
xe_memory_ref memory;
};
xe_sdb_ref xe_sdb_create(xe_memory_ref memory) {
xe_sdb_ref sdb = (xe_sdb_ref)xe_calloc(sizeof(xe_sdb));
xe_ref_init((xe_ref)sdb);
sdb->memory = xe_memory_retain(memory);
return sdb;
}
void xe_sdb_dealloc(xe_sdb_ref sdb) {
xe_memory_release(sdb->memory);
}
xe_sdb_ref xe_sdb_retain(xe_sdb_ref sdb) {
xe_ref_retain((xe_ref)sdb);
return sdb;
}
void xe_sdb_release(xe_sdb_ref sdb) {
xe_ref_release((xe_ref)sdb, (xe_ref_dealloc_t)xe_sdb_dealloc);
}
xe_sdb_function_t* xe_sdb_insert_function(xe_sdb_ref sdb, uint32_t address) {
return NULL;
}
xe_sdb_variable_t* xe_sdb_insert_variable(xe_sdb_ref sdb, uint32_t address) {
return NULL;
}
xe_sdb_function_t* xe_sdb_get_function(xe_sdb_ref sdb, uint32_t address) {
return NULL;
}
xe_sdb_variable_t* xe_sdb_get_variable(xe_sdb_ref sdb, uint32_t address) {
return NULL;
}
void xe_sdb_dump(xe_sdb_ref sdb) {
// TODO(benvanik): dump all functions and symbols
}
int xe_sdb_analyze_function(xe_sdb_ref sdb, xe_sdb_function_t *fn) {
// Ignore functions already analyzed.
if (fn->type != kXESDBFunctionUnknown) {
return 0;
}
// TODO(benvanik): analysis.
// Search forward from start address to find the end address.
// Use branch tracking to figure that out.
return 0;
}
int xe_sdb_analyze_module(xe_sdb_ref sdb, xe_module_ref module) {
// TODO(benvanik): analysis.
// Iteratively run passes over the db:
// - for each import:
// - insert fn and setup as a thunk
// - for each export
// - insert fn or variable
// - queue fn
// - insert entry point
// - queue entry point
// - while (process_queue.length()):
// - fn = shift()
// - analyze_function(fn)
return 0;
}

View File

@@ -3,6 +3,7 @@
'sources': [
'codegen.cc',
'cpu.cc',
'sdb.cc',
],
'includes': [