| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
#include <exception.h> |
| 16 |
#include <gdb.h> |
| 17 |
#include <libpayload.h> |
| 18 |
|
| 19 |
struct gdb_regs |
| 20 |
{ |
| 21 |
u32 r[16]; |
| 22 |
struct fp_reg |
| 23 |
{ |
| 24 |
u8 byte[12]; |
| 25 |
} __packed f[8]; |
| 26 |
u32 fps; |
| 27 |
u32 cpsr; |
| 28 |
} __packed; |
| 29 |
|
| 30 |
static const u8 type_to_signal[] = { |
| 31 |
[EXC_UNDEF] = GDB_SIGILL, |
| 32 |
[EXC_SWI] = GDB_SIGTRAP, |
| 33 |
[EXC_PABORT] = GDB_SIGSEGV, |
| 34 |
[EXC_DABORT] = GDB_SIGSEGV, |
| 35 |
}; |
| 36 |
|
| 37 |
|
| 38 |
static struct exception_state sentinel_exception_state; |
| 39 |
|
| 40 |
static int gdb_exception_hook(u32 type) |
| 41 |
{ |
| 42 |
if (!gdb_handle_reentrant_exception()) { |
| 43 |
if (type >= ARRAY_SIZE(type_to_signal) || !type_to_signal[type]) |
| 44 |
return 0; |
| 45 |
exception_state_ptr = &sentinel_exception_state; |
| 46 |
gdb_command_loop(type_to_signal[type]); |
| 47 |
} |
| 48 |
|
| 49 |
exception_state_ptr = &exception_state; |
| 50 |
return 1; |
| 51 |
} |
| 52 |
|
| 53 |
void gdb_arch_init(void) |
| 54 |
{ |
| 55 |
exception_install_hook(&gdb_exception_hook); |
| 56 |
} |
| 57 |
|
| 58 |
void gdb_arch_enter(void) |
| 59 |
{ |
| 60 |
u32 *sp; |
| 61 |
|
| 62 |
asm volatile ("mov %0, %%sp" : "=r"(sp) ); |
| 63 |
|
| 64 |
|
| 65 |
if (sp >= exception_stack && sp <= exception_stack_end) |
| 66 |
gdb_exception_hook(EXC_SWI); |
| 67 |
else |
| 68 |
asm volatile ("svc #0"); |
| 69 |
} |
| 70 |
|
| 71 |
int gdb_arch_set_single_step(int on) |
| 72 |
{ |
| 73 |
|
| 74 |
return -1; |
| 75 |
} |
| 76 |
|
| 77 |
void gdb_arch_encode_regs(struct gdb_message *message) |
| 78 |
{ |
| 79 |
gdb_message_encode_bytes(message, exception_state.regs, |
| 80 |
sizeof(exception_state.regs)); |
| 81 |
gdb_message_encode_zero_bytes(message, |
| 82 |
offsetof(struct gdb_regs, cpsr) - offsetof(struct gdb_regs, f)); |
| 83 |
gdb_message_encode_bytes(message, &exception_state.cpsr, |
| 84 |
sizeof(exception_state.cpsr)); |
| 85 |
} |
| 86 |
|
| 87 |
void gdb_arch_decode_regs(int offset, struct gdb_message *message) |
| 88 |
{ |
| 89 |
const int cpsr_hex_offset = offsetof(struct gdb_regs, cpsr) * 2; |
| 90 |
gdb_message_decode_bytes(message, offset, |
| 91 |
exception_state.regs, sizeof(exception_state.regs)); |
| 92 |
gdb_message_decode_bytes(message, offset + cpsr_hex_offset, |
| 93 |
&exception_state.cpsr, sizeof(exception_state.cpsr)); |
| 94 |
} |