Revision 3dd3a2b9 target-lm32/helper.c

b/target-lm32/helper.c
49 49
    }
50 50
}
51 51

  
52
void lm32_breakpoint_insert(CPULM32State *env, int idx, target_ulong address)
53
{
54
    cpu_breakpoint_insert(env, address, BP_CPU, &env->cpu_breakpoint[idx]);
55
}
56

  
57
void lm32_breakpoint_remove(CPULM32State *env, int idx)
58
{
59
    if (!env->cpu_breakpoint[idx]) {
60
        return;
61
    }
62

  
63
    cpu_breakpoint_remove_by_ref(env, env->cpu_breakpoint[idx]);
64
    env->cpu_breakpoint[idx] = NULL;
65
}
66

  
67
void lm32_watchpoint_insert(CPULM32State *env, int idx, target_ulong address,
68
                            lm32_wp_t wp_type)
69
{
70
    int flags = 0;
71

  
72
    switch (wp_type) {
73
    case LM32_WP_DISABLED:
74
        /* nothing to to */
75
        break;
76
    case LM32_WP_READ:
77
        flags = BP_CPU | BP_STOP_BEFORE_ACCESS | BP_MEM_READ;
78
        break;
79
    case LM32_WP_WRITE:
80
        flags = BP_CPU | BP_STOP_BEFORE_ACCESS | BP_MEM_WRITE;
81
        break;
82
    case LM32_WP_READ_WRITE:
83
        flags = BP_CPU | BP_STOP_BEFORE_ACCESS | BP_MEM_ACCESS;
84
        break;
85
    }
86

  
87
    if (flags != 0) {
88
        cpu_watchpoint_insert(env, address, 1, flags,
89
                &env->cpu_watchpoint[idx]);
90
    }
91
}
92

  
93
void lm32_watchpoint_remove(CPULM32State *env, int idx)
94
{
95
    if (!env->cpu_watchpoint[idx]) {
96
        return;
97
    }
98

  
99
    cpu_watchpoint_remove_by_ref(env, env->cpu_watchpoint[idx]);
100
    env->cpu_watchpoint[idx] = NULL;
101
}
102

  
103
static bool check_watchpoints(CPULM32State *env)
104
{
105
    LM32CPU *cpu = lm32_env_get_cpu(env);
106
    int i;
107

  
108
    for (i = 0; i < cpu->num_watchpoints; i++) {
109
        if (env->cpu_watchpoint[i] &&
110
                env->cpu_watchpoint[i]->flags & BP_WATCHPOINT_HIT) {
111
            return true;
112
        }
113
    }
114
    return false;
115
}
116

  
117
void lm32_debug_excp_handler(CPULM32State *env)
118
{
119
    CPUBreakpoint *bp;
120

  
121
    if (env->watchpoint_hit) {
122
        if (env->watchpoint_hit->flags & BP_CPU) {
123
            env->watchpoint_hit = NULL;
124
            if (check_watchpoints(env)) {
125
                raise_exception(env, EXCP_WATCHPOINT);
126
            } else {
127
                cpu_resume_from_signal(env, NULL);
128
            }
129
        }
130
    } else {
131
        QTAILQ_FOREACH(bp, &env->breakpoints, entry) {
132
            if (bp->pc == env->pc) {
133
                if (bp->flags & BP_CPU) {
134
                    raise_exception(env, EXCP_BREAKPOINT);
135
                }
136
                break;
137
            }
138
        }
139
    }
140
}
141

  
52 142
void lm32_cpu_do_interrupt(CPUState *cs)
53 143
{
54 144
    LM32CPU *cpu = LM32_CPU(cs);

Also available in: Unified diff