qemu/target/lm32/gdbstub.c
<<
>>
Prefs
   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 "qemu/osdep.h"
  21#include "cpu.h"
  22#include "exec/gdbstub.h"
  23#include "hw/lm32/lm32_pic.h"
  24
  25int lm32_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
  26{
  27    LM32CPU *cpu = LM32_CPU(cs);
  28    CPULM32State *env = &cpu->env;
  29
  30    if (n < 32) {
  31        return gdb_get_reg32(mem_buf, env->regs[n]);
  32    } else {
  33        switch (n) {
  34        case 32:
  35            return gdb_get_reg32(mem_buf, env->pc);
  36        /* FIXME: put in right exception ID */
  37        case 33:
  38            return gdb_get_reg32(mem_buf, 0);
  39        case 34:
  40            return gdb_get_reg32(mem_buf, env->eba);
  41        case 35:
  42            return gdb_get_reg32(mem_buf, env->deba);
  43        case 36:
  44            return gdb_get_reg32(mem_buf, env->ie);
  45        case 37:
  46            return gdb_get_reg32(mem_buf, lm32_pic_get_im(env->pic_state));
  47        case 38:
  48            return gdb_get_reg32(mem_buf, lm32_pic_get_ip(env->pic_state));
  49        }
  50    }
  51    return 0;
  52}
  53
  54int lm32_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
  55{
  56    LM32CPU *cpu = LM32_CPU(cs);
  57    CPUClass *cc = CPU_GET_CLASS(cs);
  58    CPULM32State *env = &cpu->env;
  59    uint32_t tmp;
  60
  61    if (n > cc->gdb_num_core_regs) {
  62        return 0;
  63    }
  64
  65    tmp = ldl_p(mem_buf);
  66
  67    if (n < 32) {
  68        env->regs[n] = tmp;
  69    } else {
  70        switch (n) {
  71        case 32:
  72            env->pc = tmp;
  73            break;
  74        case 34:
  75            env->eba = tmp;
  76            break;
  77        case 35:
  78            env->deba = tmp;
  79            break;
  80        case 36:
  81            env->ie = tmp;
  82            break;
  83        case 37:
  84            lm32_pic_set_im(env->pic_state, tmp);
  85            break;
  86        case 38:
  87            lm32_pic_set_ip(env->pic_state, tmp);
  88            break;
  89        }
  90    }
  91    return 4;
  92}
  93