Subversion Repositories HelenOS

Rev

Rev 2943 | Rev 3093 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  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 "../../../cons.h"
  42. #include "../../../main.h"
  43. #include "../../../breakpoint.h"
  44. #include "../../../include/arch.h"
  45.  
  46. #define OPCODE_BREAK        0x0000000d
  47.  
  48. static unsigned buffer[1024];
  49.  
  50. int arch_breakpoint_set(breakpoint_t *b)
  51. {
  52.     uint32_t brkp;
  53.     int rc;
  54.  
  55.     rc = udebug_mem_read(app_phone, &b->arch.back, b->addr,
  56.         sizeof(b->arch.back));
  57.     if (rc < 0) return rc;
  58.  
  59.     cons_printf("udebug_mem_read() -> %d\n", rc);
  60.     brkp = OPCODE_BREAK;
  61.     rc = udebug_mem_write(app_phone, &brkp, b->addr, sizeof(brkp));
  62.     cons_printf("udebug_mem_write() -> %d\n", rc);
  63.     if (rc < 0) return rc;
  64.  
  65.     return 0;
  66. }
  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.         }
  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.  
  91. void arch_event_breakpoint(thash_t thread_hash)
  92. {
  93.     breakpoint_t *b;
  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);
  102.     cons_printf("udebug_regs_read -> %d\n", rc);
  103.     epc = buffer[EOFFSET_EPC/sizeof(unsigned)];
  104.     cons_printf("EPC was 0x%08x\n", epc);
  105.     brk_addr = epc;
  106.  
  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;
  114.  
  115.         breakpoint_hit(b);
  116.     }
  117.  
  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;
  125.         return;
  126.     }
  127.  
  128.     cons_printf("Unrecognized breakpoint at 0x%lx\n", brk_addr);
  129. }
  130.  
  131. void arch_event_trap(dthread_t *dt)
  132. {
  133.     /* Unused */
  134.     (void)dt;
  135. }
  136.  
  137. void arch_dump_regs(thash_t thash)
  138. {
  139. }
  140.  
  141. void arch_set_singlestep(dthread_t *dt, int enable)
  142. {
  143. }
  144.  
  145. /** @}
  146.  */
  147.