Statistics
| Branch: | Revision:

root / target-lm32 / gdbstub.c @ 986a2998

History | View | Annotate | Download (2.4 kB)

1
/*
2
 * LM32 gdb server stub
3
 *
4
 * Copyright (c) 2003-2005 Fabrice Bellard
5
 * Copyright (c) 2013 SUSE LINUX Products GmbH
6
 *
7
 * This library is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU Lesser General Public
9
 * License as published by the Free Software Foundation; either
10
 * version 2 of the License, or (at your option) any later version.
11
 *
12
 * This library is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15
 * Lesser General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU Lesser General Public
18
 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
19
 */
20
#include "hw/lm32/lm32_pic.h"
21

    
22
static int cpu_gdb_read_register(CPULM32State *env, uint8_t *mem_buf, int n)
23
{
24
    if (n < 32) {
25
        return gdb_get_reg32(mem_buf, env->regs[n]);
26
    } else {
27
        switch (n) {
28
        case 32:
29
            return gdb_get_reg32(mem_buf, env->pc);
30
        /* FIXME: put in right exception ID */
31
        case 33:
32
            return gdb_get_reg32(mem_buf, 0);
33
        case 34:
34
            return gdb_get_reg32(mem_buf, env->eba);
35
        case 35:
36
            return gdb_get_reg32(mem_buf, env->deba);
37
        case 36:
38
            return gdb_get_reg32(mem_buf, env->ie);
39
        case 37:
40
            return gdb_get_reg32(mem_buf, lm32_pic_get_im(env->pic_state));
41
        case 38:
42
            return gdb_get_reg32(mem_buf, lm32_pic_get_ip(env->pic_state));
43
        }
44
    }
45
    return 0;
46
}
47

    
48
static int cpu_gdb_write_register(CPULM32State *env, uint8_t *mem_buf, int n)
49
{
50
    LM32CPU *cpu = lm32_env_get_cpu(env);
51
    CPUClass *cc = CPU_GET_CLASS(cpu);
52
    uint32_t tmp;
53

    
54
    if (n > cc->gdb_num_core_regs) {
55
        return 0;
56
    }
57

    
58
    tmp = ldl_p(mem_buf);
59

    
60
    if (n < 32) {
61
        env->regs[n] = tmp;
62
    } else {
63
        switch (n) {
64
        case 32:
65
            env->pc = tmp;
66
            break;
67
        case 34:
68
            env->eba = tmp;
69
            break;
70
        case 35:
71
            env->deba = tmp;
72
            break;
73
        case 36:
74
            env->ie = tmp;
75
            break;
76
        case 37:
77
            lm32_pic_set_im(env->pic_state, tmp);
78
            break;
79
        case 38:
80
            lm32_pic_set_ip(env->pic_state, tmp);
81
            break;
82
        }
83
    }
84
    return 4;
85
}