Rev 2943 | Rev 3012 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2943 | Rev 3005 | ||
---|---|---|---|
1 | /* |
1 | /* |
2 | * Copyright (c) 2008 Jiri Svoboda |
2 | * Copyright (c) 2008 Jiri Svoboda |
3 | * All rights reserved. |
3 | * All rights reserved. |
4 | * |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
7 | * are met: |
8 | * |
8 | * |
9 | * - Redistributions of source code must retain the above copyright |
9 | * - Redistributions of source code must retain the above copyright |
10 | * notice, this list of conditions and the following disclaimer. |
10 | * notice, this list of conditions and the following disclaimer. |
11 | * - Redistributions in binary form must reproduce the above copyright |
11 | * - Redistributions in binary form must reproduce the above copyright |
12 | * notice, this list of conditions and the following disclaimer in the |
12 | * notice, this list of conditions and the following disclaimer in the |
13 | * documentation and/or other materials provided with the distribution. |
13 | * documentation and/or other materials provided with the distribution. |
14 | * - The name of the author may not be used to endorse or promote products |
14 | * - The name of the author may not be used to endorse or promote products |
15 | * derived from this software without specific prior written permission. |
15 | * derived from this software without specific prior written permission. |
16 | * |
16 | * |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
27 | */ |
27 | */ |
28 | 28 | ||
29 | /** @addtogroup debug |
29 | /** @addtogroup debug |
30 | * @{ |
30 | * @{ |
31 | */ |
31 | */ |
32 | /** @file |
32 | /** @file |
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 <udebug.h> |
38 | #include <udebug.h> |
39 | #include <kernel/arch/context_offset.h> |
39 | #include <kernel/arch/context_offset.h> |
40 | 40 | ||
41 | #include "../../../cons.h" |
41 | #include "../../../cons.h" |
42 | #include "../../../main.h" |
42 | #include "../../../main.h" |
- | 43 | #include "../../../breakpoint.h" |
|
43 | #include "../../../include/arch.h" |
44 | #include "../../../include/arch.h" |
44 | 45 | ||
45 | #define OPCODE_BREAK 0x0000000d |
46 | #define OPCODE_BREAK 0x0000000d |
46 | 47 | ||
- | 48 | static unsigned buffer[1024]; |
|
- | 49 | ||
47 | void arch_breakpoint_add(uintptr_t addr) |
50 | int arch_breakpoint_set(breakpoint_t *b) |
48 | { |
51 | { |
49 | uint32_t brkp; |
52 | uint32_t brkp; |
50 | int rc; |
53 | int rc; |
51 | breakpoint_t *brk; |
- | |
52 | int i; |
- | |
53 | - | ||
54 | brk = NULL; |
- | |
55 | for (i = 0; i < MAX_BRKPTS; i++) |
- | |
56 | if (brk_list[i].set == 0) { |
- | |
57 | brk = brk_list+i; |
- | |
58 | break; |
- | |
59 | } |
- | |
60 | 54 | ||
61 | if (!brk) { |
55 | rc = udebug_mem_read(app_phone, &b->arch.back, b->addr, |
62 | cons_printf("too many breakpoints\n"); |
56 | sizeof(b->arch.back)); |
63 | return; |
57 | if (rc < 0) return rc; |
64 | } |
- | |
65 | 58 | ||
66 | rc = udebug_mem_read(app_phone, &brk->arch.back, addr, sizeof(&brk->arch.back)); |
- | |
67 | cons_printf("udebug_mem_read() -> %d\n", rc); |
59 | cons_printf("udebug_mem_read() -> %d\n", rc); |
68 | brkp = OPCODE_BREAK; |
60 | brkp = OPCODE_BREAK; |
69 | rc = udebug_mem_write(app_phone, &brkp, addr, sizeof(brkp)); |
61 | rc = udebug_mem_write(app_phone, &brkp, b->addr, sizeof(brkp)); |
70 | // for (i=0; i<256; i++) rc = udebug_mem_write(app_phone, &brkp, addr+4*i, sizeof(brkp)); |
- | |
71 | cons_printf("udebug_mem_write() -> %d\n", rc); |
62 | cons_printf("udebug_mem_write() -> %d\n", rc); |
- | 63 | if (rc < 0) return rc; |
|
72 | 64 | ||
73 | brk->addr = addr; |
- | |
74 | brk->set = 1; |
65 | return 0; |
75 | } |
66 | } |
76 | 67 | ||
- | 68 | int arch_breakpoint_remove(breakpoint_t *b) |
|
- | 69 | { |
|
- | 70 | int rc; |
|
- | 71 | ||
- | 72 | if (b->active) { |
|
- | 73 | rc = udebug_mem_write(app_phone, &b->arch.back, b->addr + 4, 1); |
|
- | 74 | if (rc < 0) { |
|
- | 75 | cons_printf("error writing memory\n"); |
|
- | 76 | return rc; |
|
- | 77 | } |
|
77 | static unsigned buffer[1024]; |
78 | active_bkpt = NULL; |
- | 79 | } else { |
|
- | 80 | rc = udebug_mem_write(app_phone, &b->arch.back, b->addr, 1); |
|
- | 81 | if (rc < 0) { |
|
78 | static breakpoint_t *lifted_brkpt; |
82 | cons_printf("error writing memory\n"); |
- | 83 | return rc; |
|
- | 84 | } |
|
- | 85 | } |
|
- | 86 | ||
- | 87 | return 0; |
|
- | 88 | ||
- | 89 | } |
|
79 | 90 | ||
80 | void arch_event_breakpoint(thash_t thread_hash) |
91 | void arch_event_breakpoint(thash_t thread_hash) |
81 | { |
92 | { |
- | 93 | breakpoint_t *b; |
|
82 | int rc; |
94 | int rc; |
83 | uint32_t epc; |
95 | uint32_t epc; |
84 | int brk_addr; |
96 | int brk_addr; |
85 | uint32_t brkp; |
97 | uint32_t brkp; |
86 | 98 | ||
87 | brkp = OPCODE_BREAK; |
99 | brkp = OPCODE_BREAK; |
88 | 100 | ||
89 | rc = udebug_regs_read(app_phone, thread_hash, buffer); |
101 | rc = udebug_regs_read(app_phone, thread_hash, buffer); |
90 | cons_printf("udebug_regs_read -> %d\n", rc); |
102 | cons_printf("udebug_regs_read -> %d\n", rc); |
91 | epc = buffer[EOFFSET_EPC/sizeof(unsigned)]; |
103 | epc = buffer[EOFFSET_EPC/sizeof(unsigned)]; |
92 | cons_printf("EPC was 0x%08x\n", epc); |
104 | cons_printf("EPC was 0x%08x\n", epc); |
93 | brk_addr = epc; |
105 | brk_addr = epc; |
94 | 106 | ||
95 | int bi; |
- | |
96 | for (bi = 0; bi < MAX_BRKPTS; bi++) { |
- | |
97 | if (brk_list[bi].set && brk_list[bi].addr == brk_addr) |
107 | b = breakpoint_find_by_addr(brk_addr); |
98 | break; |
- | |
99 | } |
- | |
100 | if (bi < MAX_BRKPTS) { |
108 | if (b != NULL) { |
101 | cons_printf("breakpoint %d hit\n", bi); |
- | |
102 | breakpoint_hit(); |
- | |
103 | - | ||
104 | rc = udebug_mem_write(app_phone, &brk_list[bi].arch.back, brk_addr, 4); |
109 | rc = udebug_mem_write(app_phone, &b->arch.back, brk_addr, 4); |
105 | cons_printf("udebug_mem_write(phone, 0x%x, 0x%02x, 1) -> %d\n", brk_addr, brk_list[bi].arch.back, rc); |
110 | cons_printf("udebug_mem_write(phone, 0x%x, 0x%02x, 1) -> %d\n", brk_addr, b->arch.back, rc); |
106 | rc = udebug_mem_read(app_phone, &brk_list[bi].arch.back, brk_addr+4, 4); |
111 | rc = udebug_mem_read(app_phone, &b->arch.back, brk_addr + 4, 4); |
107 | rc = udebug_mem_write(app_phone, &brkp, brk_addr+4, 4); |
112 | rc = udebug_mem_write(app_phone, &brkp, brk_addr + 4, 4); |
108 | lifted_brkpt = &brk_list[bi]; |
113 | active_bkpt = b; |
- | 114 | ||
109 | return; |
115 | breakpoint_hit(b); |
110 | } |
116 | } |
111 | 117 | ||
112 | for (bi = 0; bi < MAX_BRKPTS; bi++) { |
- | |
113 | if (brk_list[bi].set && brk_list[bi].addr + 4 == brk_addr) |
118 | b = breakpoint_find_by_addr(brk_addr - 4); |
114 | break; |
- | |
115 | } |
- | |
116 | if (bi < MAX_BRKPTS) { |
119 | if (b != NULL && b->active) { |
117 | cons_printf("restoring breakpoint %d\n", bi); |
120 | cons_printf("restoring breakpoint %d\n", b->id); |
118 | rc = udebug_mem_write(app_phone, &brk_list[bi].arch.back, brk_addr, 4); |
121 | rc = udebug_mem_write(app_phone, &b->arch.back, brk_addr, 4); |
119 | rc = udebug_mem_read(app_phone, &brk_list[bi].arch.back, brk_addr-4, 4); |
122 | rc = udebug_mem_read(app_phone, &b->arch.back, brk_addr - 4, 4); |
120 | rc = udebug_mem_write(app_phone, &brkp, brk_addr-4, 4); |
123 | rc = udebug_mem_write(app_phone, &brkp, brk_addr - 4, 4); |
121 | lifted_brkpt = NULL; |
124 | active_bkpt = NULL; |
122 | return; |
125 | return; |
123 | } |
126 | } |
124 | 127 | ||
125 | cons_printf("unrecognized breakpoint at 0x%x\n", brk_addr); |
128 | cons_printf("Unrecognized breakpoint at 0x%lx\n", brk_addr); |
126 | } |
129 | } |
127 | 130 | ||
128 | void arch_event_trap(dthread_t *dt) |
131 | void arch_event_trap(dthread_t *dt) |
129 | { |
132 | { |
130 | /* Unused */ |
133 | /* Unused */ |
131 | (void)dt; |
134 | (void)dt; |
132 | } |
135 | } |
133 | 136 | ||
134 | void arch_dump_regs(thash_t thash) |
137 | void arch_dump_regs(thash_t thash) |
135 | { |
138 | { |
136 | } |
139 | } |
137 | 140 | ||
138 | void arch_set_singlestep(dthread_t *dt, int enable) |
141 | void arch_set_singlestep(dthread_t *dt, int enable) |
139 | { |
142 | { |
140 | } |
- | |
141 | - | ||
142 | void arch_breakpoint_remove(int id) |
- | |
143 | { |
- | |
144 | } |
- | |
145 | - | ||
146 | void arch_breakpoint_list(void) |
- | |
147 | { |
- | |
148 | } |
143 | } |
149 | 144 | ||
150 | /** @} |
145 | /** @} |
151 | */ |
146 | */ |
152 | 147 |