diff --git a/configs/targets/loongarch64-softmmu.mak b/configs/targets/loongarch64-softmmu.mak
index 483474ba93..9abc99056f 100644
--- a/configs/targets/loongarch64-softmmu.mak
+++ b/configs/targets/loongarch64-softmmu.mak
@@ -1,5 +1,5 @@
TARGET_ARCH=loongarch64
TARGET_BASE_ARCH=loongarch
TARGET_SUPPORTS_MTTCG=y
-TARGET_XML_FILES= gdb-xml/loongarch-base64.xml gdb-xml/loongarch-fpu64.xml
+TARGET_XML_FILES= gdb-xml/loongarch-base64.xml gdb-xml/loongarch-fpu.xml
TARGET_NEED_FDT=y
diff --git a/gdb-xml/loongarch-base64.xml b/gdb-xml/loongarch-base64.xml
index 4962bdbd28..2d8a1f6b73 100644
--- a/gdb-xml/loongarch-base64.xml
+++ b/gdb-xml/loongarch-base64.xml
@@ -1,5 +1,5 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/gdb-xml/loongarch-fpu64.xml b/gdb-xml/loongarch-fpu64.xml
deleted file mode 100644
index e52cf89fbc..0000000000
--- a/gdb-xml/loongarch-fpu64.xml
+++ /dev/null
@@ -1,57 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/hw/loongarch/acpi-build.c b/hw/loongarch/acpi-build.c
index 4b4529a3fb..d0f01a6485 100644
--- a/hw/loongarch/acpi-build.c
+++ b/hw/loongarch/acpi-build.c
@@ -411,9 +411,8 @@ static void acpi_build(AcpiBuildTables *tables, MachineState *machine)
LoongArchMachineState *lams = LOONGARCH_MACHINE(machine);
GArray *table_offsets;
AcpiFadtData fadt_data;
- unsigned facs, rsdt, fadt, dsdt;
+ unsigned facs, rsdt, dsdt;
uint8_t *u;
- size_t aml_len = 0;
GArray *tables_blob = tables->table_data;
init_common_fadt_data(&fadt_data);
@@ -437,21 +436,13 @@ static void acpi_build(AcpiBuildTables *tables, MachineState *machine)
dsdt = tables_blob->len;
build_dsdt(tables_blob, tables->linker, machine);
- /*
- * Count the size of the DSDT, we will need it for
- * legacy sizing of ACPI tables.
- */
- aml_len += tables_blob->len - dsdt;
-
/* ACPI tables pointed to by RSDT */
- fadt = tables_blob->len;
acpi_add_table(table_offsets, tables_blob);
fadt_data.facs_tbl_offset = &facs;
fadt_data.dsdt_tbl_offset = &dsdt;
fadt_data.xdsdt_tbl_offset = &dsdt;
build_fadt(tables_blob, tables->linker, &fadt_data,
lams->oem_id, lams->oem_table_id);
- aml_len += tables_blob->len - fadt;
acpi_add_table(table_offsets, tables_blob);
build_madt(tables_blob, tables->linker, lams);
diff --git a/linux-user/loongarch64/signal.c b/linux-user/loongarch64/signal.c
index 65fd5f3857..7c7afb652e 100644
--- a/linux-user/loongarch64/signal.c
+++ b/linux-user/loongarch64/signal.c
@@ -71,26 +71,6 @@ struct extctx_layout {
struct ctx_layout end;
};
-/* The kernel's sc_save_fcc macro is a sequence of MOVCF2GR+BSTRINS. */
-static uint64_t read_all_fcc(CPULoongArchState *env)
-{
- uint64_t ret = 0;
-
- for (int i = 0; i < 8; ++i) {
- ret |= (uint64_t)env->cf[i] << (i * 8);
- }
-
- return ret;
-}
-
-/* The kernel's sc_restore_fcc macro is a sequence of BSTRPICK+MOVGR2CF. */
-static void write_all_fcc(CPULoongArchState *env, uint64_t val)
-{
- for (int i = 0; i < 8; ++i) {
- env->cf[i] = (val >> (i * 8)) & 1;
- }
-}
-
static abi_ptr extframe_alloc(struct extctx_layout *extctx,
struct ctx_layout *sctx, unsigned size,
unsigned align, abi_ptr orig_sp)
@@ -150,7 +130,7 @@ static void setup_sigframe(CPULoongArchState *env,
for (i = 0; i < 32; ++i) {
__put_user(env->fpr[i], &fpu_ctx->regs[i]);
}
- __put_user(read_all_fcc(env), &fpu_ctx->fcc);
+ __put_user(read_fcc(env), &fpu_ctx->fcc);
__put_user(env->fcsr0, &fpu_ctx->fcsr);
/*
@@ -216,7 +196,7 @@ static void restore_sigframe(CPULoongArchState *env,
__get_user(env->fpr[i], &fpu_ctx->regs[i]);
}
__get_user(fcc, &fpu_ctx->fcc);
- write_all_fcc(env, fcc);
+ write_fcc(env, fcc);
__get_user(env->fcsr0, &fpu_ctx->fcsr);
restore_fp_status(env);
}
diff --git a/target/loongarch/cpu.c b/target/loongarch/cpu.c
index 1c69a76f2b..941e2772bc 100644
--- a/target/loongarch/cpu.c
+++ b/target/loongarch/cpu.c
@@ -661,6 +661,11 @@ static const struct SysemuCPUOps loongarch_sysemu_ops = {
};
#endif
+static gchar *loongarch_gdb_arch_name(CPUState *cs)
+{
+ return g_strdup("loongarch64");
+}
+
static void loongarch_cpu_class_init(ObjectClass *c, void *data)
{
LoongArchCPUClass *lacc = LOONGARCH_CPU_CLASS(c);
@@ -683,9 +688,10 @@ static void loongarch_cpu_class_init(ObjectClass *c, void *data)
cc->gdb_read_register = loongarch_cpu_gdb_read_register;
cc->gdb_write_register = loongarch_cpu_gdb_write_register;
cc->disas_set_info = loongarch_cpu_disas_set_info;
- cc->gdb_num_core_regs = 34;
+ cc->gdb_num_core_regs = 35;
cc->gdb_core_xml_file = "loongarch-base64.xml";
cc->gdb_stop_before_watchpoint = true;
+ cc->gdb_arch_name = loongarch_gdb_arch_name;
#ifdef CONFIG_TCG
cc->tcg_ops = &loongarch_tcg_ops;
diff --git a/target/loongarch/cpu.h b/target/loongarch/cpu.h
index a36349df83..dce999aaac 100644
--- a/target/loongarch/cpu.h
+++ b/target/loongarch/cpu.h
@@ -47,11 +47,23 @@ FIELD(FCSR0, FLAGS, 16, 5)
FIELD(FCSR0, CAUSE, 24, 5)
#define GET_FP_CAUSE(REG) FIELD_EX32(REG, FCSR0, CAUSE)
-#define SET_FP_CAUSE(REG, V) FIELD_DP32(REG, FCSR0, CAUSE, V)
+#define SET_FP_CAUSE(REG, V) \
+ do { \
+ (REG) = FIELD_DP32(REG, FCSR0, CAUSE, V); \
+ } while (0)
+
#define GET_FP_ENABLES(REG) FIELD_EX32(REG, FCSR0, ENABLES)
-#define SET_FP_ENABLES(REG, V) FIELD_DP32(REG, FCSR0, ENABLES, V)
+#define SET_FP_ENABLES(REG, V) \
+ do { \
+ (REG) = FIELD_DP32(REG, FCSR0, ENABLES, V); \
+ } while (0)
+
#define GET_FP_FLAGS(REG) FIELD_EX32(REG, FCSR0, FLAGS)
-#define SET_FP_FLAGS(REG, V) FIELD_DP32(REG, FCSR0, FLAGS, V)
+#define SET_FP_FLAGS(REG, V) \
+ do { \
+ (REG) = FIELD_DP32(REG, FCSR0, FLAGS, V); \
+ } while (0)
+
#define UPDATE_FP_FLAGS(REG, V) \
do { \
(REG) |= FIELD_DP32(0, FCSR0, FLAGS, V); \
diff --git a/target/loongarch/gdbstub.c b/target/loongarch/gdbstub.c
index 24e126fb2d..a4d1e28e36 100644
--- a/target/loongarch/gdbstub.c
+++ b/target/loongarch/gdbstub.c
@@ -11,6 +11,24 @@
#include "internals.h"
#include "exec/gdbstub.h"
+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;
+ }
+}
+
int loongarch_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
{
LoongArchCPU *cpu = LOONGARCH_CPU(cs);
@@ -19,8 +37,11 @@ int loongarch_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n)
if (0 <= n && n < 32) {
return gdb_get_regl(mem_buf, env->gpr[n]);
} else if (n == 32) {
- return gdb_get_regl(mem_buf, env->pc);
+ /* orig_a0 */
+ return gdb_get_regl(mem_buf, 0);
} else if (n == 33) {
+ return gdb_get_regl(mem_buf, env->pc);
+ } else if (n == 34) {
return gdb_get_regl(mem_buf, env->CSR_BADV);
}
return 0;
@@ -36,7 +57,7 @@ int loongarch_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n)
if (0 <= n && n < 32) {
env->gpr[n] = tmp;
length = sizeof(target_ulong);
- } else if (n == 32) {
+ } else if (n == 33) {
env->pc = tmp;
length = sizeof(target_ulong);
}
@@ -48,9 +69,10 @@ static int loongarch_gdb_get_fpu(CPULoongArchState *env,
{
if (0 <= n && n < 32) {
return gdb_get_reg64(mem_buf, env->fpr[n]);
- } else if (32 <= n && n < 40) {
- return gdb_get_reg8(mem_buf, env->cf[n - 32]);
- } else if (n == 40) {
+ } else if (n == 32) {
+ uint64_t val = read_fcc(env);
+ return gdb_get_reg64(mem_buf, val);
+ } else if (n == 33) {
return gdb_get_reg32(mem_buf, env->fcsr0);
}
return 0;
@@ -64,10 +86,11 @@ static int loongarch_gdb_set_fpu(CPULoongArchState *env,
if (0 <= n && n < 32) {
env->fpr[n] = ldq_p(mem_buf);
length = 8;
- } else if (32 <= n && n < 40) {
- env->cf[n - 32] = ldub_p(mem_buf);
- length = 1;
- } else if (n == 40) {
+ } else if (n == 32) {
+ uint64_t val = ldq_p(mem_buf);
+ write_fcc(env, val);
+ length = 8;
+ } else if (n == 33) {
env->fcsr0 = ldl_p(mem_buf);
length = 4;
}
@@ -77,5 +100,5 @@ static int loongarch_gdb_set_fpu(CPULoongArchState *env,
void loongarch_cpu_register_gdb_regs_for_features(CPUState *cs)
{
gdb_register_coprocessor(cs, loongarch_gdb_get_fpu, loongarch_gdb_set_fpu,
- 41, "loongarch-fpu64.xml", 0);
+ 41, "loongarch-fpu.xml", 0);
}
diff --git a/target/loongarch/internals.h b/target/loongarch/internals.h
index ea227362b6..f01635aed6 100644
--- a/target/loongarch/internals.h
+++ b/target/loongarch/internals.h
@@ -51,6 +51,9 @@ bool loongarch_cpu_tlb_fill(CPUState *cs, vaddr address, int size,
hwaddr loongarch_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr);
#endif /* !CONFIG_USER_ONLY */
+uint64_t read_fcc(CPULoongArchState *env);
+void write_fcc(CPULoongArchState *env, uint64_t val);
+
int loongarch_cpu_gdb_read_register(CPUState *cs, GByteArray *mem_buf, int n);
int loongarch_cpu_gdb_write_register(CPUState *cs, uint8_t *mem_buf, int n);
void loongarch_cpu_register_gdb_regs_for_features(CPUState *cs);