Rev 3005 | Rev 3108 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3005 | Rev 3093 | ||
---|---|---|---|
Line 33... | Line 33... | ||
33 | */ |
33 | */ |
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 <bool.h> |
|
38 | #include <udebug.h> |
39 | #include <udebug.h> |
39 | 40 | ||
40 | #include <kernel/arch/context_offset.h> |
41 | #include <kernel/arch/context_offset.h> |
41 | 42 | ||
42 | #include "../../../cons.h" |
43 | #include "../../../cons.h" |
43 | #include "../../../main.h" |
44 | #include "../../../main.h" |
44 | #include "../../../include/arch.h" |
45 | #include "../../../include/arch.h" |
45 | 46 | ||
46 | #define OPCODE_INT3 0xCC |
47 | #define OPCODE_INT3 0xCC |
47 | 48 | ||
- | 49 | static int _set_trap_flag(dthread_t *dt, bool enable) |
|
- | 50 | { |
|
- | 51 | static istate_t istate; |
|
- | 52 | int rc; |
|
- | 53 | ||
- | 54 | rc = udebug_regs_read(app_phone, dt->hash, &istate); |
|
- | 55 | if (rc < 0) { printf("regs read failed\n"); return; } |
|
- | 56 | ||
- | 57 | if (enable) istate.eflags |= 0x0100; /* trap flag */ |
|
- | 58 | else if (!active_bkpt) istate.eflags &= ~0x0100; /* trap flag */ |
|
- | 59 | ||
- | 60 | rc = udebug_regs_write(app_phone, dt->hash, &istate); |
|
- | 61 | if (rc < 0) { printf("regs write failed\n"); return; } |
|
- | 62 | ||
- | 63 | return 0; |
|
- | 64 | } |
|
- | 65 | ||
48 | int arch_breakpoint_set(breakpoint_t *b) |
66 | int arch_breakpoint_set(breakpoint_t *b) |
49 | { |
67 | { |
50 | char brkp[1]; |
68 | char brkp[1]; |
51 | int rc; |
69 | int rc; |
52 | 70 | ||
Line 126... | Line 144... | ||
126 | rc = udebug_mem_write(app_phone, brkinstr, b->addr, 1); |
144 | rc = udebug_mem_write(app_phone, brkinstr, b->addr, 1); |
127 | // cons_printf("restore breakpoint -> %d\n", rc); |
145 | // cons_printf("restore breakpoint -> %d\n", rc); |
128 | active_bkpt = NULL; |
146 | active_bkpt = NULL; |
129 | } |
147 | } |
130 | 148 | ||
131 | if (!dt->arch.singlestep) { |
- | |
132 | rc = udebug_regs_read(app_phone, dt->hash, &istate); |
149 | rc = _set_trap_flag(dt, false); |
133 | // cons_printf("udebug_regs_read -> %d\n", rc); |
- | |
134 | istate.eflags &= ~0x0100; /* trap flag */ |
150 | dt->arch.singlestep = false; |
135 | rc = udebug_regs_write(app_phone, dt->hash, &istate); |
- | |
136 | } else { |
151 | |
137 | // printf("ss-hit\n"); |
- | |
138 | singlestep_hit(); |
152 | singlestep_hit(); |
139 | } |
- | |
140 | } |
153 | } |
141 | 154 | ||
142 | void arch_dump_regs(thash_t thash) |
155 | void arch_dump_regs(thash_t thash) |
143 | { |
156 | { |
144 | static istate_t istate; |
157 | static istate_t istate; |
Line 153... | Line 166... | ||
153 | istate.eip, istate.eflags, istate.eax, istate.ebx, |
166 | istate.eip, istate.eflags, istate.eax, istate.ebx, |
154 | istate.ecx, istate.edx, istate.esi, istate.edi, istate.cs, |
167 | istate.ecx, istate.edx, istate.esi, istate.edi, istate.cs, |
155 | istate.ds, istate.es, istate.fs, istate.gs); |
168 | istate.ds, istate.es, istate.fs, istate.gs); |
156 | } |
169 | } |
157 | 170 | ||
158 | void arch_set_singlestep(dthread_t *dt, int enable) |
171 | void arch_singlestep(dthread_t *dt) |
159 | { |
172 | { |
160 | static istate_t istate; |
- | |
161 | int rc; |
173 | int rc; |
162 | 174 | ||
163 | rc = udebug_regs_read(app_phone, dt->hash, &istate); |
175 | rc = _set_trap_flag(dt, true); |
164 | if (rc < 0) { printf("regs read failed\n"); return; } |
176 | if (rc != 0) return; |
165 | - | ||
166 | if (enable) istate.eflags |= 0x0100; /* trap flag */ |
- | |
167 | else if (!active_bkpt) istate.eflags &= ~0x0100; /* trap flag */ |
- | |
168 | - | ||
169 | rc = udebug_regs_write(app_phone, dt->hash, &istate); |
- | |
170 | if (rc < 0) { printf("regs write failed\n"); return; } |
- | |
171 | 177 | ||
172 | dt->arch.singlestep = enable; |
178 | dthread_resume(dt); |
173 | } |
179 | } |
174 | 180 | ||
175 | /** @} |
181 | /** @} |
176 | */ |
182 | */ |