2013-04-21 19:34:20 +00:00
|
|
|
/**
|
|
|
|
******************************************************************************
|
|
|
|
* 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/global_exports.h>
|
|
|
|
|
|
|
|
#include <xenia/cpu/sdb.h>
|
|
|
|
#include <xenia/cpu/ppc/instr.h>
|
|
|
|
#include <xenia/cpu/ppc/state.h>
|
|
|
|
#include <xenia/kernel/export.h>
|
|
|
|
|
|
|
|
|
|
|
|
using namespace xe;
|
|
|
|
using namespace xe::cpu;
|
|
|
|
using namespace xe::cpu::sdb;
|
|
|
|
using namespace xe::kernel;
|
|
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
2013-05-21 22:36:58 +00:00
|
|
|
void _cdecl XeTrap(
|
2013-05-22 18:30:53 +00:00
|
|
|
xe_ppc_state_t* state, uint64_t cia) {
|
2013-04-21 19:34:20 +00:00
|
|
|
XELOGE("TRAP");
|
|
|
|
XEASSERTALWAYS();
|
|
|
|
}
|
|
|
|
|
2013-05-21 22:36:58 +00:00
|
|
|
void _cdecl XeIndirectBranch(
|
2013-05-22 18:30:53 +00:00
|
|
|
xe_ppc_state_t* state, uint64_t target, uint64_t br_ia) {
|
2013-04-21 19:34:20 +00:00
|
|
|
XELOGCPU("INDIRECT BRANCH %.8X -> %.8X",
|
|
|
|
(uint32_t)br_ia, (uint32_t)target);
|
|
|
|
XEASSERTALWAYS();
|
|
|
|
}
|
|
|
|
|
2013-05-21 22:36:58 +00:00
|
|
|
void _cdecl XeInvalidInstruction(
|
2013-05-22 18:30:53 +00:00
|
|
|
xe_ppc_state_t* state, uint64_t cia, uint64_t data) {
|
2013-04-21 19:34:20 +00:00
|
|
|
ppc::InstrData i;
|
2013-05-21 23:19:11 +00:00
|
|
|
i.address = (uint32_t)cia;
|
|
|
|
i.code = (uint32_t)data;
|
2013-04-21 19:34:20 +00:00
|
|
|
i.type = ppc::GetInstrType(i.code);
|
|
|
|
|
|
|
|
if (!i.type) {
|
|
|
|
XELOGCPU("INVALID INSTRUCTION %.8X: %.8X ???",
|
|
|
|
i.address, i.code);
|
|
|
|
} else if (i.type->disassemble) {
|
|
|
|
ppc::InstrDisasm d;
|
|
|
|
i.type->disassemble(i, d);
|
|
|
|
std::string disasm;
|
|
|
|
d.Dump(disasm);
|
|
|
|
XELOGCPU("INVALID INSTRUCTION %.8X: %.8X %s",
|
|
|
|
i.address, i.code, disasm.c_str());
|
|
|
|
} else {
|
|
|
|
XELOGCPU("INVALID INSTRUCTION %.8X: %.8X %s",
|
|
|
|
i.address, i.code, i.type->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-21 22:36:58 +00:00
|
|
|
void _cdecl XeAccessViolation(
|
2013-05-22 18:30:53 +00:00
|
|
|
xe_ppc_state_t* state, uint64_t cia, uint64_t ea) {
|
2013-04-21 19:34:20 +00:00
|
|
|
XELOGE("INVALID ACCESS %.8X: tried to touch %.8X",
|
|
|
|
cia, (uint32_t)ea);
|
|
|
|
XEASSERTALWAYS();
|
|
|
|
}
|
|
|
|
|
2013-05-21 22:36:58 +00:00
|
|
|
void _cdecl XeTraceKernelCall(
|
|
|
|
xe_ppc_state_t* state, uint64_t cia, uint64_t call_ia,
|
|
|
|
KernelExport* kernel_export) {
|
2013-04-21 19:34:20 +00:00
|
|
|
XELOGCPU("TRACE: %.8X -> k.%.8X (%s)",
|
|
|
|
(uint32_t)call_ia - 4, (uint32_t)cia,
|
|
|
|
kernel_export ? kernel_export->name : "unknown");
|
|
|
|
}
|
|
|
|
|
2013-05-21 22:36:58 +00:00
|
|
|
void _cdecl XeTraceUserCall(
|
|
|
|
xe_ppc_state_t* state, uint64_t cia, uint64_t call_ia,
|
|
|
|
FunctionSymbol* fn) {
|
2013-04-21 19:34:20 +00:00
|
|
|
XELOGCPU("TRACE: %.8X -> u.%.8X (%s)",
|
|
|
|
(uint32_t)call_ia - 4, (uint32_t)cia, fn->name());
|
|
|
|
}
|
|
|
|
|
2013-05-23 08:31:41 +00:00
|
|
|
void _cdecl XeTraceBranch(
|
|
|
|
xe_ppc_state_t* state, uint64_t cia, uint64_t target_ia) {
|
|
|
|
switch (target_ia) {
|
|
|
|
case kXEPPCRegLR:
|
|
|
|
target_ia = state->lr;
|
|
|
|
break;
|
|
|
|
case kXEPPCRegCTR:
|
|
|
|
target_ia = state->ctr;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
XELOGCPU("TRACE: %.8X -> b.%.8X",
|
|
|
|
(uint32_t)cia, (uint32_t)target_ia);
|
|
|
|
}
|
|
|
|
|
2013-05-21 22:36:58 +00:00
|
|
|
void _cdecl XeTraceInstruction(
|
2013-05-22 18:30:53 +00:00
|
|
|
xe_ppc_state_t* state, uint64_t cia, uint64_t data) {
|
2013-05-24 23:53:27 +00:00
|
|
|
XELOGCPU(
|
|
|
|
"\n"
|
2013-05-25 05:03:57 +00:00
|
|
|
" lr=%.16llX ctr=%.16llX cr=%.4X xer=%.16llX\n"
|
2013-05-24 23:53:27 +00:00
|
|
|
" r0=%.16llX r1=%.16llX r2=%.16llX r3=%.16llX\n"
|
|
|
|
" r4=%.16llX r5=%.16llX r6=%.16llX r7=%.16llX\n"
|
|
|
|
" r8=%.16llX r9=%.16llX r10=%.16llX r11=%.16llX\n"
|
|
|
|
"r12=%.16llX r13=%.16llX r14=%.16llX r15=%.16llX\n"
|
|
|
|
"r16=%.16llX r17=%.16llX r18=%.16llX r19=%.16llX\n"
|
|
|
|
"r20=%.16llX r21=%.16llX r22=%.16llX r23=%.16llX\n"
|
|
|
|
"r24=%.16llX r25=%.16llX r26=%.16llX r27=%.16llX\n"
|
|
|
|
"r28=%.16llX r29=%.16llX r30=%.16llX r31=%.16llX\n",
|
2013-05-25 05:03:57 +00:00
|
|
|
state->lr, state->ctr, state->cr.value, state->xer,
|
2013-05-24 23:53:27 +00:00
|
|
|
state->r[0], state->r[1], state->r[2], state->r[3],
|
|
|
|
state->r[4], state->r[5], state->r[6], state->r[7],
|
|
|
|
state->r[8], state->r[9], state->r[10], state->r[11],
|
|
|
|
state->r[12], state->r[13], state->r[14], state->r[15],
|
|
|
|
state->r[16], state->r[17], state->r[18], state->r[19],
|
|
|
|
state->r[20], state->r[21], state->r[22], state->r[23],
|
|
|
|
state->r[24], state->r[25], state->r[26], state->r[27],
|
|
|
|
state->r[28], state->r[29], state->r[30], state->r[31]);
|
|
|
|
|
2013-05-23 18:39:29 +00:00
|
|
|
ppc::InstrData i;
|
|
|
|
i.address = (uint32_t)cia;
|
|
|
|
i.code = (uint32_t)data;
|
|
|
|
i.type = ppc::GetInstrType(i.code);
|
|
|
|
if (i.type && i.type->disassemble) {
|
|
|
|
ppc::InstrDisasm d;
|
|
|
|
i.type->disassemble(i, d);
|
|
|
|
std::string disasm;
|
|
|
|
d.Dump(disasm);
|
|
|
|
XELOGCPU("TRACE: %.8X %.8X %s %s",
|
|
|
|
i.address, i.code,
|
|
|
|
i.type && i.type->emit ? " " : "X",
|
|
|
|
disasm.c_str());
|
|
|
|
} else {
|
|
|
|
XELOGCPU("TRACE: %.8X %.8X %s %s",
|
|
|
|
i.address, i.code,
|
|
|
|
i.type && i.type->emit ? " " : "X",
|
|
|
|
i.type ? i.type->name : "<unknown>");
|
|
|
|
}
|
2013-04-21 19:34:20 +00:00
|
|
|
|
2013-05-23 18:39:29 +00:00
|
|
|
// if (cia == 0x82012074) {
|
2013-04-21 19:34:20 +00:00
|
|
|
// printf("BREAKBREAKBREAK\n");
|
|
|
|
// }
|
|
|
|
|
|
|
|
// TODO(benvanik): better disassembly, printing of current register values/etc
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void xe::cpu::GetGlobalExports(GlobalExports* global_exports) {
|
|
|
|
global_exports->XeTrap = XeTrap;
|
|
|
|
global_exports->XeIndirectBranch = XeIndirectBranch;
|
|
|
|
global_exports->XeInvalidInstruction = XeInvalidInstruction;
|
|
|
|
global_exports->XeAccessViolation = XeAccessViolation;
|
|
|
|
global_exports->XeTraceKernelCall = XeTraceKernelCall;
|
|
|
|
global_exports->XeTraceUserCall = XeTraceUserCall;
|
2013-05-23 08:31:41 +00:00
|
|
|
global_exports->XeTraceBranch = XeTraceBranch;
|
2013-04-21 19:34:20 +00:00
|
|
|
global_exports->XeTraceInstruction = XeTraceInstruction;
|
|
|
|
}
|