Subversion Repositories HelenOS

Rev

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

Rev 2936 Rev 2941
Line 35... Line 35...
35
#include <stdio.h>
35
#include <stdio.h>
36
#include <stdlib.h>
36
#include <stdlib.h>
37
#include <sys/types.h>
37
#include <sys/types.h>
38
#include <udebug.h>
38
#include <udebug.h>
39
 
39
 
-
 
40
#include <kernel/arch/context_offset.h>
-
 
41
 
40
#include "../../../cons.h"
42
#include "../../../cons.h"
41
#include "../../../main.h"
43
#include "../../../main.h"
42
#include "../../../include/arch.h"
44
#include "../../../include/arch.h"
43
 
45
 
44
#define OPCODE_INT3     0xCC
46
#define OPCODE_INT3     0xCC
Line 70... Line 72...
70
 
72
 
71
    brk->addr = addr;
73
    brk->addr = addr;
72
    brk->set = 1;
74
    brk->set = 1;
73
}
75
}
74
 
76
 
75
static unsigned buffer[1024];
77
static istate_t istate;
76
static breakpoint_t *lifted_brkpt;
78
static breakpoint_t *lifted_brkpt;
77
 
79
 
78
void arch_event_breakpoint(thash_t thread_hash)
80
void arch_event_breakpoint(thash_t thread_hash)
79
{
81
{
80
    int rc;
82
    int rc;
81
 
83
 
82
    rc = udebug_regs_read(app_phone, thread_hash, buffer);
84
    rc = udebug_regs_read(app_phone, thread_hash, &istate);
83
    cons_printf("udebug_regs_read -> %d\n", rc);
85
    cons_printf("udebug_regs_read -> %d\n", rc);
84
    cons_printf("EIP was 0x%08x\n", buffer[ISTATE_OFF_EIP]);
86
    cons_printf("EIP was 0x%08x\n", istate.eip);
85
    int brk_addr = buffer[ISTATE_OFF_EIP] - 1;
87
    int brk_addr = istate.eip - 1;
86
    int bi;
88
    int bi;
87
    for (bi = 0; bi < MAX_BRKPTS; bi++) {
89
    for (bi = 0; bi < MAX_BRKPTS; bi++) {
88
        if (brk_list[bi].set && brk_list[bi].addr == brk_addr)
90
        if (brk_list[bi].set && brk_list[bi].addr == brk_addr)
89
            break;
91
            break;
90
    }
92
    }
91
 
93
 
92
    if (bi < MAX_BRKPTS) {
94
    if (bi < MAX_BRKPTS) {
93
        cons_printf("breakpoint %d hit\n", bi);
95
        cons_printf("breakpoint %d hit\n", bi);
94
        breakpoint_hit();
96
        breakpoint_hit();
95
 
97
 
96
        buffer[ISTATE_OFF_EIP] = brk_addr;
98
        istate.eip = brk_addr;
97
        buffer[ISTATE_OFF_EFLAGS] |= 0x0100; /* trap flag */
99
        istate.eflags |= 0x0100; /* trap flag */
98
        cons_printf("setting EIP to 0x%08x\n", buffer[ISTATE_OFF_EIP]);
100
        cons_printf("setting EIP to 0x%08x\n", istate.eip);
99
        rc = udebug_regs_write(app_phone, thread_hash, buffer);
101
        rc = udebug_regs_write(app_phone, thread_hash, &istate);
100
            rc = udebug_mem_write(app_phone, &brk_list[bi].arch.back, brk_addr, 1);
102
            rc = udebug_mem_write(app_phone, &brk_list[bi].arch.back, brk_addr, 1);
101
        cons_printf("udebug_mem_write(phone, 0x%x, 0x%02x, 1) -> %d\n", brk_addr, brk_list[bi].arch.back, rc);
103
        cons_printf("udebug_mem_write(phone, 0x%x, 0x%02x, 1) -> %d\n", brk_addr, brk_list[bi].arch.back, rc);
102
        lifted_brkpt = &brk_list[bi];
104
        lifted_brkpt = &brk_list[bi];
103
    } else {
105
    } else {
104
        cons_printf("unrecognized breakpoint at 0x%x\n", brk_addr);
106
        cons_printf("unrecognized breakpoint at 0x%x\n", brk_addr);
Line 115... Line 117...
115
    breakpoint_t *lb = lifted_brkpt;
117
    breakpoint_t *lb = lifted_brkpt;
116
    brkinstr[0] = OPCODE_INT3;
118
    brkinstr[0] = OPCODE_INT3;
117
    rc = udebug_mem_write(app_phone, brkinstr, lb->addr, 1);
119
    rc = udebug_mem_write(app_phone, brkinstr, lb->addr, 1);
118
    cons_printf("restore breakpoint -> %d\n", rc);
120
    cons_printf("restore breakpoint -> %d\n", rc);
119
 
121
 
120
    rc = udebug_regs_read(app_phone, thread_hash, buffer);
122
    rc = udebug_regs_read(app_phone, thread_hash, &istate);
121
    cons_printf("udebug_regs_read -> %d\n", rc);
123
    cons_printf("udebug_regs_read -> %d\n", rc);
122
    buffer[ISTATE_OFF_EFLAGS] &= ~0x0100; /* trap flag */
124
    istate.eflags &= ~0x0100; /* trap flag */
123
    rc = udebug_regs_write(app_phone, thread_hash, buffer);
125
    rc = udebug_regs_write(app_phone, thread_hash, &istate);
-
 
126
}
-
 
127
 
-
 
128
void arch_dump_regs(thash_t thash)
-
 
129
{
-
 
130
    int rc;
-
 
131
 
-
 
132
    printf("arch_dump_regs...\n");
-
 
133
 
-
 
134
    rc = udebug_regs_read(app_phone, thash, &istate);
-
 
135
    if (rc < 0) { cons_printf("Error reading regs\n"); return; }
-
 
136
 
-
 
137
    cons_printf(
-
 
138
        "eip:%08x eflags:%08x eax:%08x ebx:%08x ecx:%08x edx:%08x\n"
-
 
139
        "esi:%08x edi:%08x cs:%04x ds:%04x es:%04x fs:%04x gs:%04x\n",
-
 
140
        istate.eip, istate.eflags, istate.eax, istate.ebx,
-
 
141
        istate.ecx, istate.edx, istate.esi, istate.edi, istate.cs,
-
 
142
        istate.ds, istate.es, istate.fs, istate.gs);
124
}
143
}
125
 
144
 
126
/** @}
145
/** @}
127
 */
146
 */