2022-06-06 14:43:31 +02:00
|
|
|
/*
|
|
|
|
* LOONGARCH gdb server stub
|
|
|
|
*
|
|
|
|
* Copyright (c) 2021 Loongson Technology Corporation Limited
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: LGPL-2.1+
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "qemu/osdep.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "internals.h"
|
|
|
|
#include "exec/gdbstub.h"
|
2023-03-03 03:57:56 +01:00
|
|
|
#include "gdbstub/helpers.h"
|
2023-09-14 04:25:59 +02:00
|
|
|
#include "vec.h"
|
2022-06-06 14:43:31 +02:00
|
|
|
|
2022-08-05 05:35:23 +02:00
|
|
|
uint64_t read_fcc(CPULoongArchState *env)
|
|
|
|
{
|
|
|
|
uint64_t ret = 0;
|
|
|
|
|
|
|
|
for (int i = 0; i < 8; ++i) {
|
|
|
|
ret |= (uint64_t)env->cf[i] << (i * 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void write_fcc(CPULoongArchState *env, uint64_t val)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < 8; ++i) {
|
|
|
|
env->cf[i] = (val >> (i * 8)) & 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-06 14:43:31 +02:00
|
|
|
int loongarch_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
|
|
|
|
{
|
|
|
|
LoongArchCPU *cpu = LOONGARCH_CPU(cs);
|
|
|
|
CPULoongArchState *env = &cpu->env;
|
2023-08-21 14:59:59 +02:00
|
|
|
uint64_t val;
|
2022-06-06 14:43:31 +02:00
|
|
|
|
|
|
|
if (0 <= n && n < 32) {
|
2023-08-21 14:59:59 +02:00
|
|
|
val = env->gpr[n];
|
2022-06-06 14:43:31 +02:00
|
|
|
} else if (n == 32) {
|
2022-08-05 05:35:19 +02:00
|
|
|
/* orig_a0 */
|
2023-08-21 14:59:59 +02:00
|
|
|
val = 0;
|
2022-06-06 14:43:31 +02:00
|
|
|
} else if (n == 33) {
|
2023-08-21 14:59:59 +02:00
|
|
|
val = env->pc;
|
2022-08-05 05:35:19 +02:00
|
|
|
} else if (n == 34) {
|
2023-08-21 14:59:59 +02:00
|
|
|
val = env->CSR_BADV;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (0 <= n && n <= 34) {
|
|
|
|
if (is_la64(env)) {
|
|
|
|
return gdb_get_reg64(mem_buf, val);
|
|
|
|
} else {
|
|
|
|
return gdb_get_reg32(mem_buf, val);
|
|
|
|
}
|
2022-06-06 14:43:31 +02:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int loongarch_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
|
|
|
|
{
|
|
|
|
LoongArchCPU *cpu = LOONGARCH_CPU(cs);
|
|
|
|
CPULoongArchState *env = &cpu->env;
|
2023-08-21 14:59:59 +02:00
|
|
|
target_ulong tmp;
|
|
|
|
int read_length;
|
2022-06-06 14:43:31 +02:00
|
|
|
int length = 0;
|
|
|
|
|
2023-08-21 14:59:59 +02:00
|
|
|
if (is_la64(env)) {
|
|
|
|
tmp = ldq_p(mem_buf);
|
|
|
|
read_length = 8;
|
|
|
|
} else {
|
|
|
|
tmp = ldl_p(mem_buf);
|
|
|
|
read_length = 4;
|
|
|
|
}
|
|
|
|
|
2022-06-06 14:43:31 +02:00
|
|
|
if (0 <= n && n < 32) {
|
|
|
|
env->gpr[n] = tmp;
|
2023-08-21 14:59:59 +02:00
|
|
|
length = read_length;
|
2022-08-05 05:35:19 +02:00
|
|
|
} else if (n == 33) {
|
2023-08-22 09:13:54 +02:00
|
|
|
set_pc(env, tmp);
|
2023-08-21 14:59:59 +02:00
|
|
|
length = read_length;
|
2022-06-06 14:43:31 +02:00
|
|
|
}
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int loongarch_gdb_get_fpu(CPULoongArchState *env,
|
|
|
|
GByteArray *mem_buf, int n)
|
|
|
|
{
|
|
|
|
if (0 <= n && n < 32) {
|
2023-05-04 14:27:27 +02:00
|
|
|
return gdb_get_reg64(mem_buf, env->fpr[n].vreg.D(0));
|
2023-08-08 07:42:47 +02:00
|
|
|
} else if (32 <= n && n < 40) {
|
|
|
|
return gdb_get_reg8(mem_buf, env->cf[n - 32]);
|
|
|
|
} else if (n == 40) {
|
2022-06-06 14:43:31 +02:00
|
|
|
return gdb_get_reg32(mem_buf, env->fcsr0);
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int loongarch_gdb_set_fpu(CPULoongArchState *env,
|
|
|
|
uint8_t *mem_buf, int n)
|
|
|
|
{
|
|
|
|
int length = 0;
|
|
|
|
|
|
|
|
if (0 <= n && n < 32) {
|
2023-05-04 14:27:27 +02:00
|
|
|
env->fpr[n].vreg.D(0) = ldq_p(mem_buf);
|
2022-06-06 14:43:31 +02:00
|
|
|
length = 8;
|
2023-08-08 07:42:47 +02:00
|
|
|
} else if (32 <= n && n < 40) {
|
|
|
|
env->cf[n - 32] = ldub_p(mem_buf);
|
|
|
|
length = 1;
|
|
|
|
} else if (n == 40) {
|
2022-06-06 14:43:31 +02:00
|
|
|
env->fcsr0 = ldl_p(mem_buf);
|
|
|
|
length = 4;
|
|
|
|
}
|
|
|
|
return length;
|
|
|
|
}
|
|
|
|
|
|
|
|
void loongarch_cpu_register_gdb_regs_for_features(CPUState *cs)
|
|
|
|
{
|
|
|
|
gdb_register_coprocessor(cs, loongarch_gdb_get_fpu, loongarch_gdb_set_fpu,
|
2022-08-05 05:35:22 +02:00
|
|
|
41, "loongarch-fpu.xml", 0);
|
2022-06-06 14:43:31 +02:00
|
|
|
}
|