Fixing some misc bugs.

This commit is contained in:
Ben Vanik
2015-03-28 15:45:39 -07:00
parent ea28c563ad
commit 71eabf7f2b
4 changed files with 24 additions and 12 deletions

View File

@@ -364,11 +364,22 @@ void X64Emitter::DebugBreak() {
db(0xCC);
}
uint64_t TrapDebugPrint(void* raw_context, uint64_t address) {
auto thread_state = *reinterpret_cast<ThreadState**>(raw_context);
uint32_t str_ptr = uint32_t(thread_state->context()->r[3]);
uint16_t str_len = uint16_t(thread_state->context()->r[4]);
const char* str =
reinterpret_cast<const char*>(thread_state->memory()->Translate(str_ptr));
// TODO(benvanik): truncate to length?
PLOGD("(DebugPrint) %s", str);
return 0;
}
void X64Emitter::Trap(uint16_t trap_type) {
switch (trap_type) {
case 20:
case 26:
// 0x0FE00014 is a 'debug print' where r3 = buffer r4 = length
// TODO(benvanik): debug print at runtime.
CallNative(TrapDebugPrint, 0);
break;
case 0:
case 22:
@@ -378,6 +389,9 @@ void X64Emitter::Trap(uint16_t trap_type) {
db(0xCC);
}
break;
case 25:
// ?
break;
default:
PLOGW("Unknown trap type %d", trap_type);
db(0xCC);