Subversion Repositories HelenOS

Rev

Rev 2943 | Rev 3093 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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