Rev 2943 | Rev 3012 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 2924 | svoboda | 1 | /* |
| 2 | * Copyright (c) 2008 Jiri Svoboda |
||
| 3 | * All rights reserved. |
||
| 4 | * |
||
| 5 | * Redistribution and use in source and binary forms, with or without |
||
| 6 | * modification, are permitted provided that the following conditions |
||
| 7 | * are met: |
||
| 8 | * |
||
| 9 | * - Redistributions of source code must retain the above copyright |
||
| 10 | * notice, this list of conditions and the following disclaimer. |
||
| 11 | * - Redistributions in binary form must reproduce the above copyright |
||
| 12 | * notice, this list of conditions and the following disclaimer in the |
||
| 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 |
||
| 15 | * derived from this software without specific prior written permission. |
||
| 16 | * |
||
| 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 |
||
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
||
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
||
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
||
| 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 |
||
| 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 |
||
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
||
| 27 | */ |
||
| 28 | |||
| 29 | /** @addtogroup debug |
||
| 30 | * @{ |
||
| 31 | */ |
||
| 32 | /** @file |
||
| 33 | */ |
||
| 34 | |||
| 35 | #include <stdio.h> |
||
| 36 | #include <stdlib.h> |
||
| 37 | #include <sys/types.h> |
||
| 38 | #include <udebug.h> |
||
| 39 | #include <kernel/arch/context_offset.h> |
||
| 40 | |||
| 2936 | svoboda | 41 | #include "../../../cons.h" |
| 2924 | svoboda | 42 | #include "../../../main.h" |
| 3005 | svoboda | 43 | #include "../../../breakpoint.h" |
| 2924 | svoboda | 44 | #include "../../../include/arch.h" |
| 45 | |||
| 46 | #define OPCODE_BREAK 0x0000000d |
||
| 47 | |||
| 3005 | svoboda | 48 | static unsigned buffer[1024]; |
| 49 | |||
| 50 | int arch_breakpoint_set(breakpoint_t *b) |
||
| 2924 | svoboda | 51 | { |
| 52 | uint32_t brkp; |
||
| 53 | int rc; |
||
| 54 | |||
| 3005 | svoboda | 55 | rc = udebug_mem_read(app_phone, &b->arch.back, b->addr, |
| 56 | sizeof(b->arch.back)); |
||
| 57 | if (rc < 0) return rc; |
||
| 2924 | svoboda | 58 | |
| 2936 | svoboda | 59 | cons_printf("udebug_mem_read() -> %d\n", rc); |
| 2924 | svoboda | 60 | brkp = OPCODE_BREAK; |
| 3005 | svoboda | 61 | rc = udebug_mem_write(app_phone, &brkp, b->addr, sizeof(brkp)); |
| 2936 | svoboda | 62 | cons_printf("udebug_mem_write() -> %d\n", rc); |
| 3005 | svoboda | 63 | if (rc < 0) return rc; |
| 2924 | svoboda | 64 | |
| 3005 | svoboda | 65 | return 0; |
| 2924 | svoboda | 66 | } |
| 67 | |||
| 3005 | svoboda | 68 | int arch_breakpoint_remove(breakpoint_t *b) |
| 69 | { |
||
| 70 | int rc; |
||
| 2924 | svoboda | 71 | |
| 3005 | svoboda | 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 | } |
||
| 78 | active_bkpt = NULL; |
||
| 79 | } else { |
||
| 80 | rc = udebug_mem_write(app_phone, &b->arch.back, b->addr, 1); |
||
| 81 | if (rc < 0) { |
||
| 82 | cons_printf("error writing memory\n"); |
||
| 83 | return rc; |
||
| 84 | } |
||
| 85 | } |
||
| 86 | |||
| 87 | return 0; |
||
| 88 | |||
| 89 | } |
||
| 90 | |||
| 2924 | svoboda | 91 | void arch_event_breakpoint(thash_t thread_hash) |
| 92 | { |
||
| 3005 | svoboda | 93 | breakpoint_t *b; |
| 2924 | svoboda | 94 | int rc; |
| 95 | uint32_t epc; |
||
| 96 | int brk_addr; |
||
| 97 | uint32_t brkp; |
||
| 98 | |||
| 99 | brkp = OPCODE_BREAK; |
||
| 100 | |||
| 101 | rc = udebug_regs_read(app_phone, thread_hash, buffer); |
||
| 2936 | svoboda | 102 | cons_printf("udebug_regs_read -> %d\n", rc); |
| 2924 | svoboda | 103 | epc = buffer[EOFFSET_EPC/sizeof(unsigned)]; |
| 2936 | svoboda | 104 | cons_printf("EPC was 0x%08x\n", epc); |
| 2924 | svoboda | 105 | brk_addr = epc; |
| 106 | |||
| 3005 | svoboda | 107 | b = breakpoint_find_by_addr(brk_addr); |
| 108 | if (b != NULL) { |
||
| 109 | 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); |
||
| 112 | rc = udebug_mem_write(app_phone, &brkp, brk_addr + 4, 4); |
||
| 113 | active_bkpt = b; |
||
| 2935 | svoboda | 114 | |
| 3005 | svoboda | 115 | breakpoint_hit(b); |
| 2924 | svoboda | 116 | } |
| 117 | |||
| 3005 | svoboda | 118 | b = breakpoint_find_by_addr(brk_addr - 4); |
| 119 | if (b != NULL && b->active) { |
||
| 120 | cons_printf("restoring breakpoint %d\n", b->id); |
||
| 121 | 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); |
||
| 123 | rc = udebug_mem_write(app_phone, &brkp, brk_addr - 4, 4); |
||
| 124 | active_bkpt = NULL; |
||
| 2924 | svoboda | 125 | return; |
| 126 | } |
||
| 127 | |||
| 3005 | svoboda | 128 | cons_printf("Unrecognized breakpoint at 0x%lx\n", brk_addr); |
| 2924 | svoboda | 129 | } |
| 130 | |||
| 2942 | svoboda | 131 | void arch_event_trap(dthread_t *dt) |
| 2924 | svoboda | 132 | { |
| 133 | /* Unused */ |
||
| 2942 | svoboda | 134 | (void)dt; |
| 2924 | svoboda | 135 | } |
| 136 | |||
| 2941 | svoboda | 137 | void arch_dump_regs(thash_t thash) |
| 138 | { |
||
| 139 | } |
||
| 140 | |||
| 2942 | svoboda | 141 | void arch_set_singlestep(dthread_t *dt, int enable) |
| 142 | { |
||
| 143 | } |
||
| 144 | |||
| 2924 | svoboda | 145 | /** @} |
| 146 | */ |