git: 5e728af444b1 - main - bhyve: Simplify register definitions a bit
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 23 Jan 2024 16:45:31 UTC
The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=5e728af444b16f480ec0f43803ca2a7a3e6e2e48 commit 5e728af444b16f480ec0f43803ca2a7a3e6e2e48 Author: Mark Johnston <markj@FreeBSD.org> AuthorDate: 2024-01-23 16:40:52 +0000 Commit: Mark Johnston <markj@FreeBSD.org> CommitDate: 2024-01-23 16:40:52 +0000 bhyve: Simplify register definitions a bit It's awkward to have separate tables for information which is logically connected. Merge the gdb_regset[] and gdb_regsize[] arrays and update gdb_read_regs() to cope with the result. This makes the addition of arm64 support a bit cleaner. No functional change intended. Reviewed by: corvink, jhb MFC after: 1 week Sponsored by: Innovate UK Differential Revision: https://reviews.freebsd.org/D43481 --- usr.sbin/bhyve/gdb.c | 89 ++++++++++++++++++++-------------------------------- 1 file changed, 34 insertions(+), 55 deletions(-) diff --git a/usr.sbin/bhyve/gdb.c b/usr.sbin/bhyve/gdb.c index f1aabbde43fd..2ef684e82c4b 100644 --- a/usr.sbin/bhyve/gdb.c +++ b/usr.sbin/bhyve/gdb.c @@ -134,58 +134,34 @@ static struct vcpu **vcpus; static int cur_vcpu, stopped_vcpu; static bool gdb_active = false; -static const int gdb_regset[] = { - VM_REG_GUEST_RAX, - VM_REG_GUEST_RBX, - VM_REG_GUEST_RCX, - VM_REG_GUEST_RDX, - VM_REG_GUEST_RSI, - VM_REG_GUEST_RDI, - VM_REG_GUEST_RBP, - VM_REG_GUEST_RSP, - VM_REG_GUEST_R8, - VM_REG_GUEST_R9, - VM_REG_GUEST_R10, - VM_REG_GUEST_R11, - VM_REG_GUEST_R12, - VM_REG_GUEST_R13, - VM_REG_GUEST_R14, - VM_REG_GUEST_R15, - VM_REG_GUEST_RIP, - VM_REG_GUEST_RFLAGS, - VM_REG_GUEST_CS, - VM_REG_GUEST_SS, - VM_REG_GUEST_DS, - VM_REG_GUEST_ES, - VM_REG_GUEST_FS, - VM_REG_GUEST_GS -}; - -static const int gdb_regsize[] = { - 8, - 8, - 8, - 8, - 8, - 8, - 8, - 8, - 8, - 8, - 8, - 8, - 8, - 8, - 8, - 8, - 8, - 4, - 4, - 4, - 4, - 4, - 4, - 4 +static const struct gdb_reg { + enum vm_reg_name id; + int size; +} gdb_regset[] = { + { .id = VM_REG_GUEST_RAX, .size = 8 }, + { .id = VM_REG_GUEST_RBX, .size = 8 }, + { .id = VM_REG_GUEST_RCX, .size = 8 }, + { .id = VM_REG_GUEST_RDX, .size = 8 }, + { .id = VM_REG_GUEST_RSI, .size = 8 }, + { .id = VM_REG_GUEST_RDI, .size = 8 }, + { .id = VM_REG_GUEST_RBP, .size = 8 }, + { .id = VM_REG_GUEST_RSP, .size = 8 }, + { .id = VM_REG_GUEST_R8, .size = 8 }, + { .id = VM_REG_GUEST_R9, .size = 8 }, + { .id = VM_REG_GUEST_R10, .size = 8 }, + { .id = VM_REG_GUEST_R11, .size = 8 }, + { .id = VM_REG_GUEST_R12, .size = 8 }, + { .id = VM_REG_GUEST_R13, .size = 8 }, + { .id = VM_REG_GUEST_R14, .size = 8 }, + { .id = VM_REG_GUEST_R15, .size = 8 }, + { .id = VM_REG_GUEST_RIP, .size = 8 }, + { .id = VM_REG_GUEST_RFLAGS, .size = 4 }, + { .id = VM_REG_GUEST_CS, .size = 4 }, + { .id = VM_REG_GUEST_SS, .size = 4 }, + { .id = VM_REG_GUEST_DS, .size = 4 }, + { .id = VM_REG_GUEST_ES, .size = 4 }, + { .id = VM_REG_GUEST_FS, .size = 4 }, + { .id = VM_REG_GUEST_GS, .size = 4 }, }; #ifdef GDB_LOG @@ -1031,15 +1007,18 @@ static void gdb_read_regs(void) { uint64_t regvals[nitems(gdb_regset)]; + int regnums[nitems(gdb_regset)]; + for (size_t i = 0; i < nitems(gdb_regset); i++) + regnums[i] = gdb_regset[i].id; if (vm_get_register_set(vcpus[cur_vcpu], nitems(gdb_regset), - gdb_regset, regvals) == -1) { + regnums, regvals) == -1) { send_error(errno); return; } start_packet(); - for (size_t i = 0; i < nitems(regvals); i++) - append_unsigned_native(regvals[i], gdb_regsize[i]); + for (size_t i = 0; i < nitems(gdb_regset); i++) + append_unsigned_native(regvals[i], gdb_regset[i].size); finish_packet(); }