Rev 3005 | Rev 3093 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 3005 | Rev 3012 | ||
|---|---|---|---|
| Line 34... | Line 34... | ||
| 34 | 34 | ||
| 35 | #include <stdio.h> |
35 | #include <stdio.h> |
| 36 | #include <stdlib.h> |
36 | #include <stdlib.h> |
| 37 | #include <sys/types.h> |
37 | #include <sys/types.h> |
| 38 | #include <udebug.h> |
38 | #include <udebug.h> |
| 39 | #include <kernel/arch/context_offset.h> |
- | |
| 40 | 39 | ||
| 41 | #include "../../../cons.h" |
40 | #include "../../../cons.h" |
| 42 | #include "../../../main.h" |
41 | #include "../../../main.h" |
| 43 | #include "../../../breakpoint.h" |
42 | #include "../../../breakpoint.h" |
| 44 | #include "../../../include/arch.h" |
43 | #include "../../../include/arch.h" |
| 45 | 44 | ||
| 46 | #define OPCODE_BREAK 0x0000000d |
45 | #define OPCODE_BREAK 0x0000000d |
| 47 | 46 | ||
| 48 | static unsigned buffer[1024]; |
47 | static istate_t istate; |
| 49 | 48 | ||
| 50 | int arch_breakpoint_set(breakpoint_t *b) |
49 | int arch_breakpoint_set(breakpoint_t *b) |
| 51 | { |
50 | { |
| 52 | uint32_t brkp; |
51 | uint32_t brkp; |
| 53 | int rc; |
52 | int rc; |
| Line 68... | Line 67... | ||
| 68 | int arch_breakpoint_remove(breakpoint_t *b) |
67 | int arch_breakpoint_remove(breakpoint_t *b) |
| 69 | { |
68 | { |
| 70 | int rc; |
69 | int rc; |
| 71 | 70 | ||
| 72 | if (b->active) { |
71 | if (b->active) { |
| 73 | rc = udebug_mem_write(app_phone, &b->arch.back, b->addr + 4, 1); |
72 | rc = udebug_mem_write(app_phone, &b->arch.back, b->addr + 4, 4); |
| 74 | if (rc < 0) { |
73 | if (rc < 0) { |
| 75 | cons_printf("error writing memory\n"); |
74 | cons_printf("error writing memory\n"); |
| 76 | return rc; |
75 | return rc; |
| 77 | } |
76 | } |
| 78 | active_bkpt = NULL; |
77 | active_bkpt = NULL; |
| 79 | } else { |
78 | } else { |
| 80 | rc = udebug_mem_write(app_phone, &b->arch.back, b->addr, 1); |
79 | rc = udebug_mem_write(app_phone, &b->arch.back, b->addr, 4); |
| 81 | if (rc < 0) { |
80 | if (rc < 0) { |
| 82 | cons_printf("error writing memory\n"); |
81 | cons_printf("error writing memory\n"); |
| 83 | return rc; |
82 | return rc; |
| 84 | } |
83 | } |
| 85 | } |
84 | } |
| Line 89... | Line 88... | ||
| 89 | } |
88 | } |
| 90 | 89 | ||
| 91 | void arch_event_breakpoint(thash_t thread_hash) |
90 | void arch_event_breakpoint(thash_t thread_hash) |
| 92 | { |
91 | { |
| 93 | breakpoint_t *b; |
92 | breakpoint_t *b; |
| - | 93 | dthread_t *dt; |
|
| 94 | int rc; |
94 | int rc; |
| 95 | uint32_t epc; |
95 | uint32_t epc; |
| 96 | int brk_addr; |
96 | int brk_addr; |
| 97 | uint32_t brkp; |
97 | uint32_t brkp; |
| 98 | 98 | ||
| 99 | brkp = OPCODE_BREAK; |
99 | brkp = OPCODE_BREAK; |
| 100 | 100 | ||
| - | 101 | cons_printf("arch_event_breakpoint\n"); |
|
| - | 102 | ||
| 101 | rc = udebug_regs_read(app_phone, thread_hash, buffer); |
103 | rc = udebug_regs_read(app_phone, thread_hash, &istate); |
| 102 | cons_printf("udebug_regs_read -> %d\n", rc); |
104 | cons_printf("udebug_regs_read -> %d\n", rc); |
| 103 | epc = buffer[EOFFSET_EPC/sizeof(unsigned)]; |
105 | epc = istate_get_pc(&istate); |
| 104 | cons_printf("EPC was 0x%08x\n", epc); |
106 | cons_printf("EPC was 0x%08x\n", epc); |
| 105 | brk_addr = epc; |
107 | brk_addr = epc; |
| 106 | 108 | ||
| 107 | b = breakpoint_find_by_addr(brk_addr); |
109 | b = breakpoint_find_by_addr(brk_addr); |
| 108 | if (b != NULL) { |
110 | if (b != NULL) { |
| - | 111 | cons_printf("move breakpoint\b"); |
|
| 109 | rc = udebug_mem_write(app_phone, &b->arch.back, brk_addr, 4); |
112 | rc = udebug_mem_write(app_phone, &b->arch.back, brk_addr, 4); |
| 110 | cons_printf("udebug_mem_write(phone, 0x%x, 0x%02x, 1) -> %d\n", brk_addr, b->arch.back, rc); |
- | |
| 111 | rc = udebug_mem_read(app_phone, &b->arch.back, brk_addr + 4, 4); |
113 | rc = udebug_mem_read(app_phone, &b->arch.back, brk_addr + 4, 4); |
| 112 | rc = udebug_mem_write(app_phone, &brkp, brk_addr + 4, 4); |
114 | rc = udebug_mem_write(app_phone, &brkp, brk_addr + 4, 4); |
| 113 | active_bkpt = b; |
115 | active_bkpt = b; |
| - | 116 | b->active = true; |
|
| 114 | 117 | ||
| - | 118 | cons_printf("breakpoint_hit...\n"); |
|
| 115 | breakpoint_hit(b); |
119 | breakpoint_hit(b); |
| - | 120 | cons_printf("end_hit...\n"); |
|
| - | 121 | return; |
|
| 116 | } |
122 | } |
| 117 | 123 | ||
| 118 | b = breakpoint_find_by_addr(brk_addr - 4); |
124 | b = breakpoint_find_by_addr(brk_addr - 4); |
| 119 | if (b != NULL && b->active) { |
125 | if (b != NULL && b->active) { |
| 120 | cons_printf("restoring breakpoint %d\n", b->id); |
126 | cons_printf("restoring breakpoint %d\n", b->id); |
| 121 | rc = udebug_mem_write(app_phone, &b->arch.back, brk_addr, 4); |
127 | rc = udebug_mem_write(app_phone, &b->arch.back, brk_addr, 4); |
| 122 | rc = udebug_mem_read(app_phone, &b->arch.back, brk_addr - 4, 4); |
128 | rc = udebug_mem_read(app_phone, &b->arch.back, brk_addr - 4, 4); |
| 123 | rc = udebug_mem_write(app_phone, &brkp, brk_addr - 4, 4); |
129 | rc = udebug_mem_write(app_phone, &brkp, brk_addr - 4, 4); |
| 124 | active_bkpt = NULL; |
130 | active_bkpt = NULL; |
| - | 131 | ||
| - | 132 | if (dt->arch.singlestep) { |
|
| - | 133 | singlestep_hit(); |
|
| - | 134 | ||
| - | 135 | rc = udebug_mem_read(app_phone, &dt->arch.sstep_back, brk_addr + 4, 4); |
|
| - | 136 | rc = udebug_mem_write(app_phone, &brkp, brk_addr + 4, 4); |
|
| - | 137 | } |
|
| 125 | return; |
138 | return; |
| 126 | } |
139 | } |
| 127 | 140 | ||
| - | 141 | dt = dthread_get(); |
|
| - | 142 | ||
| - | 143 | if (dt->arch.singlestep) { |
|
| - | 144 | cons_printf("advance singlestep\n"); |
|
| - | 145 | rc = udebug_mem_write(app_phone, &dt->arch.sstep_back, brk_addr, 4); |
|
| - | 146 | rc = udebug_mem_read(app_phone, &dt->arch.sstep_back, brk_addr + 4, 4); |
|
| - | 147 | rc = udebug_mem_write(app_phone, &brkp, brk_addr + 4, 4); |
|
| - | 148 | ||
| - | 149 | singlestep_hit(); |
|
| - | 150 | ||
| - | 151 | return; |
|
| - | 152 | } |
|
| - | 153 | ||
| 128 | cons_printf("Unrecognized breakpoint at 0x%lx\n", brk_addr); |
154 | cons_printf("Unrecognized breakpoint at 0x%lx\n", brk_addr); |
| 129 | } |
155 | } |
| 130 | 156 | ||
| 131 | void arch_event_trap(dthread_t *dt) |
157 | void arch_event_trap(dthread_t *dt) |
| 132 | { |
158 | { |
| Line 138... | Line 164... | ||
| 138 | { |
164 | { |
| 139 | } |
165 | } |
| 140 | 166 | ||
| 141 | void arch_set_singlestep(dthread_t *dt, int enable) |
167 | void arch_set_singlestep(dthread_t *dt, int enable) |
| 142 | { |
168 | { |
| - | 169 | int rc; |
|
| - | 170 | uint32_t epc; |
|
| - | 171 | uint32_t brk; |
|
| - | 172 | breakpoint_t *b1, *b2; |
|
| - | 173 | ||
| - | 174 | brk = OPCODE_BREAK; |
|
| - | 175 | ||
| - | 176 | cons_printf("arch_set_singlestep(dt, %d)\n", enable); |
|
| - | 177 | rc = udebug_regs_read(app_phone, dt->hash, &istate); |
|
| - | 178 | cons_printf("udebug_regs_read -> %d\n", rc); |
|
| - | 179 | epc = istate_get_pc(&istate); |
|
| - | 180 | cons_printf("EPC was 0x%08x\n", epc); |
|
| - | 181 | ||
| - | 182 | b1 = breakpoint_find_by_addr(epc - 4); |
|
| - | 183 | b2 = breakpoint_find_by_addr(epc); |
|
| - | 184 | ||
| - | 185 | if (enable && !dt->arch.singlestep) { |
|
| - | 186 | if (b1 && b1->active) { |
|
| - | 187 | dt->arch.sstep_back = b1->arch.back; |
|
| - | 188 | } else if (b2) { |
|
| - | 189 | dt->arch.sstep_back = b2->arch.back; |
|
| - | 190 | } else { |
|
| - | 191 | cons_printf("initial set singlestep\b"); |
|
| - | 192 | rc = udebug_mem_read(app_phone, &dt->arch.sstep_back, epc + 4, 4); |
|
| - | 193 | rc = udebug_mem_write(app_phone, &brk, epc + 4, 4); |
|
| - | 194 | if (rc < 0) { cons_printf("error writing mem\n"); return; } |
|
| - | 195 | } |
|
| - | 196 | } else if (!enable && dt->arch.singlestep) { |
|
| - | 197 | if ((b1 && b1->active) || b2) { |
|
| - | 198 | /* Do not remove BRK instruction */ |
|
| - | 199 | } else { |
|
| - | 200 | cons_printf("remove singlestep\b"); |
|
| - | 201 | rc = udebug_mem_write(app_phone, &dt->arch.sstep_back, epc + 4, 4); |
|
| - | 202 | } |
|
| - | 203 | } |
|
| - | 204 | dt->arch.singlestep = enable; |
|
| 143 | } |
205 | } |
| 144 | 206 | ||
| 145 | /** @} |
207 | /** @} |
| 146 | */ |
208 | */ |