Rev 2941 | Rev 2943 | 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" |
| 43 | #include "../../../include/arch.h" |
||
| 44 | |||
| 45 | #define OPCODE_BREAK 0x0000000d |
||
| 46 | |||
| 47 | void arch_breakpoint_add(uintptr_t addr) |
||
| 48 | { |
||
| 49 | uint32_t brkp; |
||
| 50 | 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 | |||
| 61 | if (!brk) { |
||
| 2936 | svoboda | 62 | cons_printf("too many breakpoints\n"); |
| 2924 | svoboda | 63 | return; |
| 64 | } |
||
| 65 | |||
| 66 | rc = udebug_mem_read(app_phone, &brk->arch.back, addr, sizeof(&brk->arch.back)); |
||
| 2936 | svoboda | 67 | cons_printf("udebug_mem_read() -> %d\n", rc); |
| 2924 | svoboda | 68 | brkp = OPCODE_BREAK; |
| 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)); |
||
| 2936 | svoboda | 71 | cons_printf("udebug_mem_write() -> %d\n", rc); |
| 2924 | svoboda | 72 | |
| 73 | brk->addr = addr; |
||
| 74 | brk->set = 1; |
||
| 75 | } |
||
| 76 | |||
| 77 | static unsigned buffer[1024]; |
||
| 78 | static breakpoint_t *lifted_brkpt; |
||
| 79 | |||
| 80 | void arch_event_breakpoint(thash_t thread_hash) |
||
| 81 | { |
||
| 82 | int rc; |
||
| 83 | uint32_t epc; |
||
| 84 | int brk_addr; |
||
| 85 | uint32_t brkp; |
||
| 86 | |||
| 87 | brkp = OPCODE_BREAK; |
||
| 88 | |||
| 89 | rc = udebug_regs_read(app_phone, thread_hash, buffer); |
||
| 2936 | svoboda | 90 | cons_printf("udebug_regs_read -> %d\n", rc); |
| 2924 | svoboda | 91 | epc = buffer[EOFFSET_EPC/sizeof(unsigned)]; |
| 2936 | svoboda | 92 | cons_printf("EPC was 0x%08x\n", epc); |
| 2924 | svoboda | 93 | brk_addr = epc; |
| 94 | |||
| 95 | int bi; |
||
| 96 | for (bi = 0; bi < MAX_BRKPTS; bi++) { |
||
| 97 | if (brk_list[bi].set && brk_list[bi].addr == brk_addr) |
||
| 98 | break; |
||
| 99 | } |
||
| 100 | if (bi < MAX_BRKPTS) { |
||
| 2936 | svoboda | 101 | cons_printf("breakpoint %d hit\n", bi); |
| 2935 | svoboda | 102 | breakpoint_hit(); |
| 103 | |||
| 2924 | svoboda | 104 | rc = udebug_mem_write(app_phone, &brk_list[bi].arch.back, brk_addr, 4); |
| 2936 | svoboda | 105 | cons_printf("udebug_mem_write(phone, 0x%x, 0x%02x, 1) -> %d\n", brk_addr, brk_list[bi].arch.back, rc); |
| 2924 | svoboda | 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); |
||
| 108 | lifted_brkpt = &brk_list[bi]; |
||
| 109 | return; |
||
| 110 | } |
||
| 111 | |||
| 112 | for (bi = 0; bi < MAX_BRKPTS; bi++) { |
||
| 113 | if (brk_list[bi].set && brk_list[bi].addr + 4 == brk_addr) |
||
| 114 | break; |
||
| 115 | } |
||
| 116 | if (bi < MAX_BRKPTS) { |
||
| 2936 | svoboda | 117 | cons_printf("restoring breakpoint %d\n", bi); |
| 2924 | svoboda | 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); |
||
| 120 | rc = udebug_mem_write(app_phone, &brkp, brk_addr-4, 4); |
||
| 121 | lifted_brkpt = NULL; |
||
| 122 | return; |
||
| 123 | } |
||
| 124 | |||
| 2936 | svoboda | 125 | cons_printf("unrecognized breakpoint at 0x%x\n", brk_addr); |
| 2924 | svoboda | 126 | } |
| 127 | |||
| 2942 | svoboda | 128 | void arch_event_trap(dthread_t *dt) |
| 2924 | svoboda | 129 | { |
| 130 | /* Unused */ |
||
| 2942 | svoboda | 131 | (void)dt; |
| 2924 | svoboda | 132 | } |
| 133 | |||
| 2941 | svoboda | 134 | void arch_dump_regs(thash_t thash) |
| 135 | { |
||
| 136 | } |
||
| 137 | |||
| 2942 | svoboda | 138 | void arch_set_singlestep(dthread_t *dt, int enable) |
| 139 | { |
||
| 140 | } |
||
| 141 | |||
| 2924 | svoboda | 142 | /** @} |
| 143 | */ |