Rev 2942 | Rev 3012 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2942 | Rev 2943 | ||
---|---|---|---|
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 "../../../include/arch.h" |
43 | #include "../../../include/arch.h" |
44 | 44 | ||
45 | #define OPCODE_BREAK 0x0000000d |
45 | #define OPCODE_BREAK 0x0000000d |
46 | 46 | ||
47 | void arch_breakpoint_add(uintptr_t addr) |
47 | void arch_breakpoint_add(uintptr_t addr) |
48 | { |
48 | { |
49 | uint32_t brkp; |
49 | uint32_t brkp; |
50 | int rc; |
50 | int rc; |
51 | breakpoint_t *brk; |
51 | breakpoint_t *brk; |
52 | int i; |
52 | int i; |
53 | 53 | ||
54 | brk = NULL; |
54 | brk = NULL; |
55 | for (i = 0; i < MAX_BRKPTS; i++) |
55 | for (i = 0; i < MAX_BRKPTS; i++) |
56 | if (brk_list[i].set == 0) { |
56 | if (brk_list[i].set == 0) { |
57 | brk = brk_list+i; |
57 | brk = brk_list+i; |
58 | break; |
58 | break; |
59 | } |
59 | } |
60 | 60 | ||
61 | if (!brk) { |
61 | if (!brk) { |
62 | cons_printf("too many breakpoints\n"); |
62 | cons_printf("too many breakpoints\n"); |
63 | return; |
63 | return; |
64 | } |
64 | } |
65 | 65 | ||
66 | rc = udebug_mem_read(app_phone, &brk->arch.back, addr, sizeof(&brk->arch.back)); |
66 | rc = udebug_mem_read(app_phone, &brk->arch.back, addr, sizeof(&brk->arch.back)); |
67 | cons_printf("udebug_mem_read() -> %d\n", rc); |
67 | cons_printf("udebug_mem_read() -> %d\n", rc); |
68 | brkp = OPCODE_BREAK; |
68 | brkp = OPCODE_BREAK; |
69 | rc = udebug_mem_write(app_phone, &brkp, addr, sizeof(brkp)); |
69 | rc = udebug_mem_write(app_phone, &brkp, addr, sizeof(brkp)); |
70 | // for (i=0; i<256; i++) rc = udebug_mem_write(app_phone, &brkp, addr+4*i, 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); |
71 | cons_printf("udebug_mem_write() -> %d\n", rc); |
72 | 72 | ||
73 | brk->addr = addr; |
73 | brk->addr = addr; |
74 | brk->set = 1; |
74 | brk->set = 1; |
75 | } |
75 | } |
76 | 76 | ||
77 | static unsigned buffer[1024]; |
77 | static unsigned buffer[1024]; |
78 | static breakpoint_t *lifted_brkpt; |
78 | static breakpoint_t *lifted_brkpt; |
79 | 79 | ||
80 | void arch_event_breakpoint(thash_t thread_hash) |
80 | void arch_event_breakpoint(thash_t thread_hash) |
81 | { |
81 | { |
82 | int rc; |
82 | int rc; |
83 | uint32_t epc; |
83 | uint32_t epc; |
84 | int brk_addr; |
84 | int brk_addr; |
85 | uint32_t brkp; |
85 | uint32_t brkp; |
86 | 86 | ||
87 | brkp = OPCODE_BREAK; |
87 | brkp = OPCODE_BREAK; |
88 | 88 | ||
89 | rc = udebug_regs_read(app_phone, thread_hash, buffer); |
89 | rc = udebug_regs_read(app_phone, thread_hash, buffer); |
90 | cons_printf("udebug_regs_read -> %d\n", rc); |
90 | cons_printf("udebug_regs_read -> %d\n", rc); |
91 | epc = buffer[EOFFSET_EPC/sizeof(unsigned)]; |
91 | epc = buffer[EOFFSET_EPC/sizeof(unsigned)]; |
92 | cons_printf("EPC was 0x%08x\n", epc); |
92 | cons_printf("EPC was 0x%08x\n", epc); |
93 | brk_addr = epc; |
93 | brk_addr = epc; |
94 | 94 | ||
95 | int bi; |
95 | int bi; |
96 | for (bi = 0; bi < MAX_BRKPTS; bi++) { |
96 | for (bi = 0; bi < MAX_BRKPTS; bi++) { |
97 | if (brk_list[bi].set && brk_list[bi].addr == brk_addr) |
97 | if (brk_list[bi].set && brk_list[bi].addr == brk_addr) |
98 | break; |
98 | break; |
99 | } |
99 | } |
100 | if (bi < MAX_BRKPTS) { |
100 | if (bi < MAX_BRKPTS) { |
101 | cons_printf("breakpoint %d hit\n", bi); |
101 | cons_printf("breakpoint %d hit\n", bi); |
102 | breakpoint_hit(); |
102 | breakpoint_hit(); |
103 | 103 | ||
104 | rc = udebug_mem_write(app_phone, &brk_list[bi].arch.back, brk_addr, 4); |
104 | rc = udebug_mem_write(app_phone, &brk_list[bi].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); |
105 | cons_printf("udebug_mem_write(phone, 0x%x, 0x%02x, 1) -> %d\n", brk_addr, brk_list[bi].arch.back, rc); |
106 | rc = udebug_mem_read(app_phone, &brk_list[bi].arch.back, brk_addr+4, 4); |
106 | rc = udebug_mem_read(app_phone, &brk_list[bi].arch.back, brk_addr+4, 4); |
107 | rc = udebug_mem_write(app_phone, &brkp, brk_addr+4, 4); |
107 | rc = udebug_mem_write(app_phone, &brkp, brk_addr+4, 4); |
108 | lifted_brkpt = &brk_list[bi]; |
108 | lifted_brkpt = &brk_list[bi]; |
109 | return; |
109 | return; |
110 | } |
110 | } |
111 | 111 | ||
112 | for (bi = 0; bi < MAX_BRKPTS; bi++) { |
112 | for (bi = 0; bi < MAX_BRKPTS; bi++) { |
113 | if (brk_list[bi].set && brk_list[bi].addr + 4 == brk_addr) |
113 | if (brk_list[bi].set && brk_list[bi].addr + 4 == brk_addr) |
114 | break; |
114 | break; |
115 | } |
115 | } |
116 | if (bi < MAX_BRKPTS) { |
116 | if (bi < MAX_BRKPTS) { |
117 | cons_printf("restoring breakpoint %d\n", bi); |
117 | cons_printf("restoring breakpoint %d\n", bi); |
118 | rc = udebug_mem_write(app_phone, &brk_list[bi].arch.back, brk_addr, 4); |
118 | rc = udebug_mem_write(app_phone, &brk_list[bi].arch.back, brk_addr, 4); |
119 | rc = udebug_mem_read(app_phone, &brk_list[bi].arch.back, brk_addr-4, 4); |
119 | rc = udebug_mem_read(app_phone, &brk_list[bi].arch.back, brk_addr-4, 4); |
120 | rc = udebug_mem_write(app_phone, &brkp, brk_addr-4, 4); |
120 | rc = udebug_mem_write(app_phone, &brkp, brk_addr-4, 4); |
121 | lifted_brkpt = NULL; |
121 | lifted_brkpt = NULL; |
122 | return; |
122 | return; |
123 | } |
123 | } |
124 | 124 | ||
125 | cons_printf("unrecognized breakpoint at 0x%x\n", brk_addr); |
125 | cons_printf("unrecognized breakpoint at 0x%x\n", brk_addr); |
126 | } |
126 | } |
127 | 127 | ||
128 | void arch_event_trap(dthread_t *dt) |
128 | void arch_event_trap(dthread_t *dt) |
129 | { |
129 | { |
130 | /* Unused */ |
130 | /* Unused */ |
131 | (void)dt; |
131 | (void)dt; |
132 | } |
132 | } |
133 | 133 | ||
134 | void arch_dump_regs(thash_t thash) |
134 | void arch_dump_regs(thash_t thash) |
135 | { |
135 | { |
136 | } |
136 | } |
137 | 137 | ||
138 | void arch_set_singlestep(dthread_t *dt, int enable) |
138 | void arch_set_singlestep(dthread_t *dt, int enable) |
139 | { |
139 | { |
140 | } |
140 | } |
141 | 141 | ||
- | 142 | void arch_breakpoint_remove(int id) |
|
- | 143 | { |
|
- | 144 | } |
|
- | 145 | ||
- | 146 | void arch_breakpoint_list(void) |
|
- | 147 | { |
|
- | 148 | } |
|
- | 149 | ||
142 | /** @} |
150 | /** @} |
143 | */ |
151 | */ |
144 | 152 |