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