Massive dump of xenia-info required code.
This is a working xenia-info for xex files (no gdfs files yet).
This commit is contained in:
85
src/core/file.cc
Normal file
85
src/core/file.cc
Normal file
@@ -0,0 +1,85 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* 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/core/file.h>
|
||||
|
||||
|
||||
typedef struct xe_file {
|
||||
xe_ref_t ref;
|
||||
|
||||
void* handle;
|
||||
} xe_file_t;
|
||||
|
||||
|
||||
#if XE_LIKE(WIN32)
|
||||
#define fseeko _fseeki64
|
||||
#define ftello _ftelli64
|
||||
#endif // WIN32
|
||||
|
||||
|
||||
xe_file_ref xe_file_open(xe_pal_ref pal, const xe_file_mode mode,
|
||||
const xechar_t *path) {
|
||||
xe_file_ref file = (xe_file_ref)xe_calloc(sizeof(xe_file_t));
|
||||
xe_ref_init((xe_ref)file);
|
||||
|
||||
xechar_t mode_string[10];
|
||||
mode_string[0] = 0;
|
||||
if (mode & kXEFileModeRead) {
|
||||
XEIGNORE(xestrcat(mode_string, XECOUNT(mode_string), XT("r")));
|
||||
}
|
||||
if (mode & kXEFileModeWrite) {
|
||||
XEIGNORE(xestrcat(mode_string, XECOUNT(mode_string), XT("w")));
|
||||
}
|
||||
XEIGNORE(xestrcat(mode_string, XECOUNT(mode_string), XT("b")));
|
||||
|
||||
#if XE_LIKE(WIN32)
|
||||
XEEXPECTZERO(_wfopen_s((FILE**)&file->handle, path, mode_string));
|
||||
#else
|
||||
file->handle = fopen(path, mode_string);
|
||||
XEEXPECTNOTNULL(file->handle);
|
||||
#endif // WIN32
|
||||
|
||||
return file;
|
||||
|
||||
XECLEANUP:
|
||||
xe_file_release(file);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void xe_file_dealloc(xe_file_ref file) {
|
||||
FILE* handle = (FILE*)file->handle;
|
||||
fclose(handle);
|
||||
file->handle = NULL;
|
||||
}
|
||||
|
||||
xe_file_ref xe_file_retain(xe_file_ref file) {
|
||||
xe_ref_retain((xe_ref)file);
|
||||
return file;
|
||||
}
|
||||
|
||||
void xe_file_release(xe_file_ref file) {
|
||||
xe_ref_release((xe_ref)file, (xe_ref_dealloc_t)xe_file_dealloc);
|
||||
}
|
||||
|
||||
size_t xe_file_get_length(xe_file_ref file) {
|
||||
FILE* handle = (FILE*)file->handle;
|
||||
|
||||
fseeko(handle, 0, SEEK_END);
|
||||
return ftello(handle);
|
||||
}
|
||||
|
||||
size_t xe_file_read(xe_file_ref file, const size_t offset,
|
||||
uint8_t *buffer, const size_t buffer_size) {
|
||||
FILE* handle = (FILE*)file->handle;
|
||||
if (fseeko(handle, offset, SEEK_SET) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return fread(buffer, 1, buffer_size, handle);
|
||||
}
|
||||
74
src/core/memory.cc
Normal file
74
src/core/memory.cc
Normal file
@@ -0,0 +1,74 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* 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/core/memory.h>
|
||||
|
||||
#include <sys/mman.h>
|
||||
|
||||
|
||||
/**
|
||||
* Memory map:
|
||||
* 0x00000000 - 0x40000000 (1024mb) - virtual 4k pages
|
||||
* 0x40000000 - 0x80000000 (1024mb) - virtual 64k pages
|
||||
* 0x80000000 - 0x8C000000 ( 192mb) - xex 64k pages
|
||||
* 0x8C000000 - 0x90000000 ( 64mb) - xex 64k pages (encrypted)
|
||||
* 0x90000000 - 0xA0000000 ( 256mb) - xex 4k pages
|
||||
* 0xA0000000 - 0xC0000000 ( 512mb) - physical 64k pages
|
||||
*
|
||||
* We use the host OS to create an entire addressable range for this. That way
|
||||
* we don't have to emulate a TLB. It'd be really cool to pass through page
|
||||
* sizes or use madvice to let the OS know what to expect.
|
||||
*/
|
||||
|
||||
|
||||
struct xe_memory {
|
||||
xe_ref_t ref;
|
||||
|
||||
size_t length;
|
||||
void *ptr;
|
||||
};
|
||||
|
||||
|
||||
xe_memory_ref xe_memory_create(xe_pal_ref pal, xe_memory_options_t options) {
|
||||
xe_memory_ref memory = (xe_memory_ref)xe_calloc(sizeof(xe_memory));
|
||||
xe_ref_init((xe_ref)memory);
|
||||
|
||||
memory->length = 0xC0000000;
|
||||
memory->ptr = mmap(0, memory->length, PROT_READ | PROT_WRITE,
|
||||
MAP_PRIVATE | MAP_ANON, -1, 0);
|
||||
XEEXPECTNOTNULL(memory->ptr);
|
||||
XEEXPECT(memory->ptr != MAP_FAILED);
|
||||
|
||||
return memory;
|
||||
|
||||
XECLEANUP:
|
||||
xe_memory_release(memory);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void xe_memory_dealloc(xe_memory_ref memory) {
|
||||
munmap(memory->ptr, memory->length);
|
||||
}
|
||||
|
||||
xe_memory_ref xe_memory_retain(xe_memory_ref memory) {
|
||||
xe_ref_retain((xe_ref)memory);
|
||||
return memory;
|
||||
}
|
||||
|
||||
void xe_memory_release(xe_memory_ref memory) {
|
||||
xe_ref_release((xe_ref)memory, (xe_ref_dealloc_t)xe_memory_dealloc);
|
||||
}
|
||||
|
||||
size_t xe_memory_get_length(xe_memory_ref memory) {
|
||||
return memory->length;
|
||||
}
|
||||
|
||||
void* xe_memory_addr(xe_memory_ref memory, uint32_t guest_addr) {
|
||||
return (uint8_t*)memory->ptr + guest_addr;
|
||||
}
|
||||
101
src/core/mmap_posix.cc
Normal file
101
src/core/mmap_posix.cc
Normal file
@@ -0,0 +1,101 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* 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/core/mmap.h>
|
||||
|
||||
#include <sys/mman.h>
|
||||
|
||||
|
||||
typedef struct xe_mmap {
|
||||
xe_ref_t ref;
|
||||
|
||||
void* file_handle;
|
||||
void* mmap_handle;
|
||||
|
||||
void* addr;
|
||||
size_t length;
|
||||
} xe_mmap_t;
|
||||
|
||||
|
||||
xe_mmap_ref xe_mmap_open(xe_pal_ref pal, const xe_file_mode mode,
|
||||
const xechar_t *path,
|
||||
const size_t offset, const size_t length) {
|
||||
xe_mmap_ref mmap = (xe_mmap_ref)xe_calloc(sizeof(xe_mmap_t));
|
||||
xe_ref_init((xe_ref)mmap);
|
||||
|
||||
xechar_t mode_string[10];
|
||||
mode_string[0] = 0;
|
||||
if (mode & kXEFileModeRead) {
|
||||
XEIGNORE(xestrcat(mode_string, XECOUNT(mode_string), XT("r")));
|
||||
}
|
||||
if (mode & kXEFileModeWrite) {
|
||||
XEIGNORE(xestrcat(mode_string, XECOUNT(mode_string), XT("w")));
|
||||
}
|
||||
XEIGNORE(xestrcat(mode_string, XECOUNT(mode_string), XT("b")));
|
||||
|
||||
int prot = 0;
|
||||
if (mode & kXEFileModeRead) {
|
||||
prot |= PROT_READ;
|
||||
}
|
||||
if (mode & kXEFileModeWrite) {
|
||||
prot |= PROT_WRITE;
|
||||
}
|
||||
|
||||
FILE* file_handle = fopen(path, mode_string);
|
||||
mmap->file_handle = file_handle;
|
||||
XEEXPECTNOTNULL(mmap->file_handle);
|
||||
|
||||
size_t map_length;
|
||||
map_length = length;
|
||||
if (!length) {
|
||||
fseeko(file_handle, 0, SEEK_END);
|
||||
map_length = ftello(file_handle);
|
||||
}
|
||||
mmap->length = map_length;
|
||||
|
||||
mmap->addr = ::mmap(0, map_length, prot, MAP_SHARED, fileno(file_handle),
|
||||
offset);
|
||||
XEEXPECTNOTNULL(mmap->addr);
|
||||
|
||||
return mmap;
|
||||
|
||||
XECLEANUP:
|
||||
xe_mmap_release(mmap);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void xe_mmap_dealloc(xe_mmap_ref mmap) {
|
||||
if (mmap->addr) {
|
||||
munmap(mmap->addr, mmap->length);
|
||||
mmap->addr = NULL;
|
||||
}
|
||||
|
||||
FILE* file_handle = (FILE*)mmap->file_handle;
|
||||
if (file_handle) {
|
||||
fclose(file_handle);
|
||||
mmap->file_handle = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
xe_mmap_ref xe_mmap_retain(xe_mmap_ref mmap) {
|
||||
xe_ref_retain((xe_ref)mmap);
|
||||
return mmap;
|
||||
}
|
||||
|
||||
void xe_mmap_release(xe_mmap_ref mmap) {
|
||||
xe_ref_release((xe_ref)mmap, (xe_ref_dealloc_t)xe_mmap_dealloc);
|
||||
}
|
||||
|
||||
void* xe_mmap_get_addr(xe_mmap_ref mmap) {
|
||||
return mmap->addr;
|
||||
}
|
||||
|
||||
size_t xe_mmap_get_length(xe_mmap_ref mmap) {
|
||||
return mmap->length;
|
||||
}
|
||||
39
src/core/pal.cc
Normal file
39
src/core/pal.cc
Normal file
@@ -0,0 +1,39 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* 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/core/pal.h>
|
||||
|
||||
|
||||
typedef struct xe_pal {
|
||||
xe_ref_t ref;
|
||||
|
||||
} xe_pal_t;
|
||||
|
||||
|
||||
xe_pal_ref xe_pal_create(xe_pal_options_t options) {
|
||||
xe_pal_ref pal = (xe_pal_ref)xe_calloc(sizeof(xe_pal_t));
|
||||
xe_ref_init((xe_ref)pal);
|
||||
|
||||
//
|
||||
|
||||
return pal;
|
||||
}
|
||||
|
||||
void xe_pal_dealloc(xe_pal_ref pal) {
|
||||
//
|
||||
}
|
||||
|
||||
xe_pal_ref xe_pal_retain(xe_pal_ref pal) {
|
||||
xe_ref_retain((xe_ref)pal);
|
||||
return pal;
|
||||
}
|
||||
|
||||
void xe_pal_release(xe_pal_ref pal) {
|
||||
xe_ref_release((xe_ref)pal, (xe_ref_dealloc_t)xe_pal_dealloc);
|
||||
}
|
||||
31
src/core/ref.cc
Normal file
31
src/core/ref.cc
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* 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/core/ref.h>
|
||||
|
||||
|
||||
void xe_ref_init(xe_ref_t* ref) {
|
||||
ref->count = 1;
|
||||
}
|
||||
|
||||
void xe_ref_retain(xe_ref_t* ref) {
|
||||
xe_atomic_inc_32(&ref->count);
|
||||
}
|
||||
|
||||
void xe_ref_release(xe_ref_t* ref, xe_ref_dealloc_t dealloc) {
|
||||
if (!ref) {
|
||||
return;
|
||||
}
|
||||
if (!xe_atomic_dec_32(&ref->count)) {
|
||||
if (dealloc) {
|
||||
dealloc(ref);
|
||||
}
|
||||
xe_free(ref);
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
/**
|
||||
******************************************************************************
|
||||
* 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/xenia.h>
|
||||
|
||||
#include <llvm/IR/DerivedTypes.h>
|
||||
#include <llvm/IR/IRBuilder.h>
|
||||
#include <llvm/IR/LLVMContext.h>
|
||||
#include <llvm/IR/Module.h>
|
||||
|
||||
using namespace llvm;
|
||||
|
||||
int some_function(int xx) {
|
||||
LLVMContext &context = getGlobalContext();
|
||||
//IRBuilder<> builder(context);
|
||||
Module *module = new Module("my cool jit", context);
|
||||
|
||||
Constant* c = module->getOrInsertFunction("mul_add",
|
||||
/*ret type*/ IntegerType::get(context, 32),
|
||||
/*args*/ IntegerType::get(context, 32),
|
||||
IntegerType::get(context, 32),
|
||||
IntegerType::get(context, 32),
|
||||
/*varargs terminated with null*/ NULL);
|
||||
|
||||
Function* mul_add = cast<Function>(c);
|
||||
mul_add->setCallingConv(CallingConv::C);
|
||||
|
||||
Function::arg_iterator args = mul_add->arg_begin();
|
||||
Value* x = args++;
|
||||
x->setName("x");
|
||||
Value* y = args++;
|
||||
y->setName("y");
|
||||
Value* z = args++;
|
||||
z->setName("z");
|
||||
|
||||
BasicBlock* block = BasicBlock::Create(getGlobalContext(), "entry", mul_add);
|
||||
IRBuilder<> builder(block);
|
||||
|
||||
Value* tmp = builder.CreateBinOp(Instruction::Mul,
|
||||
x, y, "tmp");
|
||||
Value* tmp2 = builder.CreateBinOp(Instruction::Add,
|
||||
tmp, z, "tmp2");
|
||||
|
||||
builder.CreateRet(tmp2);
|
||||
|
||||
module->dump();
|
||||
delete module;
|
||||
return xx + 4;
|
||||
}
|
||||
@@ -1,6 +1,21 @@
|
||||
# Copyright 2013 Ben Vanik. All Rights Reserved.
|
||||
{
|
||||
'sources': [
|
||||
'something.cc',
|
||||
'file.cc',
|
||||
'memory.cc',
|
||||
'pal.cc',
|
||||
'ref.cc',
|
||||
],
|
||||
|
||||
'conditions': [
|
||||
['OS == "mac" or OS == "linux"', {
|
||||
'sources': [
|
||||
'mmap_posix.cc',
|
||||
],
|
||||
}],
|
||||
['OS == "win"', {
|
||||
'sources': [
|
||||
],
|
||||
}],
|
||||
],
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user