Rev 2941 | Rev 2943 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 2941 | Rev 2942 | ||
|---|---|---|---|
| Line 43... | Line 43... | ||
| 43 | #include "../../../main.h" |
43 | #include "../../../main.h" |
| 44 | #include "../../../include/arch.h" |
44 | #include "../../../include/arch.h" |
| 45 | 45 | ||
| 46 | #define OPCODE_INT3 0xCC |
46 | #define OPCODE_INT3 0xCC |
| 47 | 47 | ||
| 48 | #define ISTATE_OFF_EIP 12 |
- | |
| 49 | #define ISTATE_OFF_EFLAGS 14 |
- | |
| 50 | - | ||
| 51 | void arch_breakpoint_add(uintptr_t addr) |
48 | void arch_breakpoint_add(uintptr_t addr) |
| 52 | { |
49 | { |
| 53 | char brkp[1]; |
50 | char brkp[1]; |
| 54 | int rc; |
51 | int rc; |
| 55 | breakpoint_t *brk; |
52 | breakpoint_t *brk; |
| 56 | int i; |
53 | int i; |
| 57 | 54 | ||
| 58 | brk = NULL; |
55 | brk = NULL; |
| 59 | for (i = 0; i < MAX_BRKPTS; i++) |
56 | for (i = 0; i < MAX_BRKPTS; i++) |
| 60 | if (brk_list[i].set == 0) brk = brk_list+i; |
57 | if (brk_list[i].set == 0) { brk = brk_list+i; break; } |
| 61 | 58 | ||
| 62 | if (!brk) { |
59 | if (!brk) { |
| 63 | cons_printf("too many breakpoints\n"); |
60 | cons_printf("too many breakpoints\n"); |
| 64 | return; |
61 | return; |
| 65 | } |
62 | } |
| Line 72... | Line 69... | ||
| 72 | 69 | ||
| 73 | brk->addr = addr; |
70 | brk->addr = addr; |
| 74 | brk->set = 1; |
71 | brk->set = 1; |
| 75 | } |
72 | } |
| 76 | 73 | ||
| 77 | static istate_t istate; |
- | |
| 78 | static breakpoint_t *lifted_brkpt; |
74 | static breakpoint_t *lifted_brkpt; |
| 79 | 75 | ||
| 80 | void arch_event_breakpoint(thash_t thread_hash) |
76 | void arch_event_breakpoint(thash_t thread_hash) |
| 81 | { |
77 | { |
| - | 78 | static istate_t istate; |
|
| 82 | int rc; |
79 | int rc; |
| 83 | 80 | ||
| 84 | rc = udebug_regs_read(app_phone, thread_hash, &istate); |
81 | rc = udebug_regs_read(app_phone, thread_hash, &istate); |
| 85 | cons_printf("udebug_regs_read -> %d\n", rc); |
82 | // cons_printf("udebug_regs_read -> %d\n", rc); |
| 86 | cons_printf("EIP was 0x%08x\n", istate.eip); |
83 | // cons_printf("EIP was 0x%08x\n", istate.eip); |
| 87 | int brk_addr = istate.eip - 1; |
84 | int brk_addr = istate.eip - 1; |
| 88 | int bi; |
85 | int bi; |
| 89 | for (bi = 0; bi < MAX_BRKPTS; bi++) { |
86 | for (bi = 0; bi < MAX_BRKPTS; bi++) { |
| 90 | if (brk_list[bi].set && brk_list[bi].addr == brk_addr) |
87 | if (brk_list[bi].set && brk_list[bi].addr == brk_addr) |
| 91 | break; |
88 | break; |
| 92 | } |
89 | } |
| 93 | 90 | ||
| 94 | if (bi < MAX_BRKPTS) { |
91 | if (bi < MAX_BRKPTS) { |
| 95 | cons_printf("breakpoint %d hit\n", bi); |
92 | cons_printf("breakpoint %d hit\n", bi); |
| 96 | breakpoint_hit(); |
- | |
| 97 | 93 | ||
| 98 | istate.eip = brk_addr; |
94 | istate.eip = brk_addr; |
| 99 | istate.eflags |= 0x0100; /* trap flag */ |
95 | istate.eflags |= 0x0100; /* trap flag */ |
| 100 | cons_printf("setting EIP to 0x%08x\n", istate.eip); |
96 | // cons_printf("setting EIP to 0x%08x\n", istate.eip); |
| 101 | rc = udebug_regs_write(app_phone, thread_hash, &istate); |
97 | rc = udebug_regs_write(app_phone, thread_hash, &istate); |
| - | 98 | if (rc < 0) { printf("error writing regs\n"); return; } |
|
| 102 | rc = udebug_mem_write(app_phone, &brk_list[bi].arch.back, brk_addr, 1); |
99 | rc = udebug_mem_write(app_phone, &brk_list[bi].arch.back, brk_addr, 1); |
| - | 100 | if (rc < 0) { printf("error writing mem\n"); return; } |
|
| 103 | cons_printf("udebug_mem_write(phone, 0x%x, 0x%02x, 1) -> %d\n", brk_addr, brk_list[bi].arch.back, rc); |
101 | // cons_printf("udebug_mem_write(phone, 0x%x, 0x%02x, 1) -> %d\n", brk_addr, brk_list[bi].arch.back, rc); |
| 104 | lifted_brkpt = &brk_list[bi]; |
102 | lifted_brkpt = &brk_list[bi]; |
| - | 103 | ||
| - | 104 | breakpoint_hit(); |
|
| 105 | } else { |
105 | } else { |
| 106 | cons_printf("unrecognized breakpoint at 0x%x\n", brk_addr); |
106 | cons_printf("unrecognized breakpoint at 0x%x\n", brk_addr); |
| 107 | } |
107 | } |
| 108 | } |
108 | } |
| 109 | 109 | ||
| 110 | void arch_event_trap(thash_t thread_hash) |
110 | void arch_event_trap(dthread_t *dt) |
| 111 | { |
111 | { |
| - | 112 | static istate_t istate; |
|
| 112 | unsigned char brkinstr[1]; |
113 | unsigned char brkinstr[1]; |
| 113 | int rc; |
114 | int rc; |
| 114 | 115 | ||
| 115 | cons_printf("trap event\n"); |
116 | // cons_printf("trap event\n"); |
| 116 | 117 | ||
| 117 | breakpoint_t *lb = lifted_brkpt; |
118 | breakpoint_t *lb = lifted_brkpt; |
| - | 119 | if (lb) { |
|
| 118 | brkinstr[0] = OPCODE_INT3; |
120 | brkinstr[0] = OPCODE_INT3; |
| 119 | rc = udebug_mem_write(app_phone, brkinstr, lb->addr, 1); |
121 | rc = udebug_mem_write(app_phone, brkinstr, lb->addr, 1); |
| 120 | cons_printf("restore breakpoint -> %d\n", rc); |
122 | // cons_printf("restore breakpoint -> %d\n", rc); |
| - | 123 | lifted_brkpt = NULL; |
|
| - | 124 | } |
|
| 121 | 125 | ||
| - | 126 | if (!dt->arch.singlestep) { |
|
| 122 | rc = udebug_regs_read(app_phone, thread_hash, &istate); |
127 | rc = udebug_regs_read(app_phone, dt->hash, &istate); |
| 123 | cons_printf("udebug_regs_read -> %d\n", rc); |
128 | // cons_printf("udebug_regs_read -> %d\n", rc); |
| 124 | istate.eflags &= ~0x0100; /* trap flag */ |
129 | istate.eflags &= ~0x0100; /* trap flag */ |
| 125 | rc = udebug_regs_write(app_phone, thread_hash, &istate); |
130 | rc = udebug_regs_write(app_phone, dt->hash, &istate); |
| - | 131 | } else { |
|
| - | 132 | // printf("ss-hit\n"); |
|
| - | 133 | singlestep_hit(); |
|
| - | 134 | } |
|
| 126 | } |
135 | } |
| 127 | 136 | ||
| 128 | void arch_dump_regs(thash_t thash) |
137 | void arch_dump_regs(thash_t thash) |
| 129 | { |
138 | { |
| - | 139 | static istate_t istate; |
|
| 130 | int rc; |
140 | int rc; |
| 131 | 141 | ||
| 132 | printf("arch_dump_regs...\n"); |
142 | printf("arch_dump_regs...\n"); |
| 133 | 143 | ||
| 134 | rc = udebug_regs_read(app_phone, thash, &istate); |
144 | rc = udebug_regs_read(app_phone, thash, &istate); |
| Line 140... | Line 150... | ||
| 140 | istate.eip, istate.eflags, istate.eax, istate.ebx, |
150 | istate.eip, istate.eflags, istate.eax, istate.ebx, |
| 141 | istate.ecx, istate.edx, istate.esi, istate.edi, istate.cs, |
151 | istate.ecx, istate.edx, istate.esi, istate.edi, istate.cs, |
| 142 | istate.ds, istate.es, istate.fs, istate.gs); |
152 | istate.ds, istate.es, istate.fs, istate.gs); |
| 143 | } |
153 | } |
| 144 | 154 | ||
| - | 155 | void arch_set_singlestep(dthread_t *dt, int enable) |
|
| - | 156 | { |
|
| - | 157 | static istate_t istate; |
|
| - | 158 | int rc; |
|
| - | 159 | ||
| - | 160 | rc = udebug_regs_read(app_phone, dt->hash, &istate); |
|
| - | 161 | if (rc < 0) { printf("regs read failed\n"); return; } |
|
| - | 162 | ||
| - | 163 | if (enable) istate.eflags |= 0x0100; /* trap flag */ |
|
| - | 164 | else istate.eflags &= ~0x0100; /* trap flag */ |
|
| - | 165 | ||
| - | 166 | rc = udebug_regs_write(app_phone, dt->hash, &istate); |
|
| - | 167 | if (rc < 0) { printf("regs write failed\n"); return; } |
|
| - | 168 | ||
| - | 169 | dt->arch.singlestep = enable; |
|
| - | 170 | } |
|
| - | 171 | ||
| 145 | /** @} |
172 | /** @} |
| 146 | */ |
173 | */ |