qemu/target/avr/gdbstub.c
Philippe Mathieu-Daudé 186f19cf46 target/avr: Use explicit little-endian LD/ST API
The AVR architecture uses little endianness. Directly use
the little-endian LD/ST API.

Mechanical change using:

  $ end=le; \
    for acc in uw w l q tul; do \
      sed -i -e "s/ld${acc}_p(/ld${acc}_${end}_p(/" \
             -e "s/st${acc}_p(/st${acc}_${end}_p(/" \
        $(git grep -wlE '(ld|st)t?u?[wlq]_p' target/avr/); \
    done

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Richard Henderson <richard.henderson@linaro.org>
Message-Id: <20241004163042.85922-11-philmd@linaro.org>
2024-10-15 12:13:59 -03:00

97 lines
2.2 KiB
C

/*
* QEMU AVR gdbstub
*
* Copyright (c) 2016-2020 Michael Rolnik
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see
* <http://www.gnu.org/licenses/lgpl-2.1.html>
*/
#include "qemu/osdep.h"
#include "gdbstub/helpers.h"
#include "cpu.h"
int avr_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
{
CPUAVRState *env = cpu_env(cs);
/* R */
if (n < 32) {
return gdb_get_reg8(mem_buf, env->r[n]);
}
/* SREG */
if (n == 32) {
uint8_t sreg = cpu_get_sreg(env);
return gdb_get_reg8(mem_buf, sreg);
}
/* SP */
if (n == 33) {
return gdb_get_reg16(mem_buf, env->sp & 0x0000ffff);
}
/* PC */
if (n == 34) {
return gdb_get_reg32(mem_buf, env->pc_w * 2);
}
return 0;
}
int avr_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
{
CPUAVRState *env = cpu_env(cs);
/* R */
if (n < 32) {
env->r[n] = *mem_buf;
return 1;
}
/* SREG */
if (n == 32) {
cpu_set_sreg(env, *mem_buf);
return 1;
}
/* SP */
if (n == 33) {
env->sp = lduw_le_p(mem_buf);
return 2;
}
/* PC */
if (n == 34) {
env->pc_w = ldl_le_p(mem_buf) / 2;
return 4;
}
return 0;
}
vaddr avr_cpu_gdb_adjust_breakpoint(CPUState *cpu, vaddr addr)
{
/*
* This is due to some strange GDB behavior
* Let's assume main has address 0x100:
* b main - sets breakpoint at address 0x00000100 (code)
* b *0x100 - sets breakpoint at address 0x00800100 (data)
*
* Force all breakpoints into code space.
*/
return addr % OFFSET_DATA;
}