[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 2 25/39] windbg: [de]serialization cpu spec register
From: |
Mikhail Abakumov |
Subject: |
[Qemu-devel] [PATCH 2 25/39] windbg: [de]serialization cpu spec registers |
Date: |
Wed, 05 Dec 2018 15:54:23 +0300 |
User-agent: |
StGit/0.17.1-dirty |
Signed-off-by: Mikhail Abakumov <address@hidden>
Signed-off-by: Pavel Dovgalyuk <address@hidden>
---
target/i386/windbgstub.c | 123 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 123 insertions(+)
diff --git a/target/i386/windbgstub.c b/target/i386/windbgstub.c
index 7a091e1dee..a1d27b8aca 100644
--- a/target/i386/windbgstub.c
+++ b/target/i386/windbgstub.c
@@ -767,12 +767,135 @@ static int fun_name(CPUState *cs, uint8_t *buf, int
buf_size, \
return 0;
\
}
+#define GEN_WINDBG_KSPEC_REGS_RW(fun_name, is_read)
\
+static int fun_name(CPUState *cs, uint8_t *buf, int buf_size,
\
+ int offset, int len)
\
+{
\
+ X86CPU *cpu = X86_CPU(cs);
\
+ CPUX86State *env = &cpu->env;
\
+ uint32_t f_size = 0;
\
+
\
+ if (len < 0 || len > buf_size) {
\
+ WINDBG_ERROR("" #fun_name ": incorrect length %d", len);
\
+ return 1;
\
+ }
\
+
\
+ if (offset < 0 || offset + len > sizeof(CPU_KSPECIAL_REGISTERS)) {
\
+ WINDBG_ERROR("" #fun_name ": incorrect offset %d", f_size);
\
+ return 2;
\
+ }
\
+
\
+ len = MIN(len, sizeof(CPU_KSPECIAL_REGISTERS) - offset);
\
+
\
+ while (offset < len) {
\
+ switch (offset) {
\
+ CASE_FIELD(CPU_KSPECIAL_REGISTERS, Cr0, f_size, {
\
+ RW_CR(buf, cs, 0, is_read);
\
+ });
\
+ CASE_FIELD(CPU_KSPECIAL_REGISTERS, Cr2, f_size, {
\
+ if (is_read) {
\
+ env->cr[2] = (int32_t) ldtul_p(buf);
\
+ } else {
\
+ sttul_p(buf, (target_ulong) env->cr[2]);
\
+ }
\
+ });
\
+ CASE_FIELD(CPU_KSPECIAL_REGISTERS, Cr3, f_size, {
\
+ RW_CR(buf, cs, 3, is_read);
\
+ });
\
+ CASE_FIELD(CPU_KSPECIAL_REGISTERS, Cr4, f_size, {
\
+ RW_CR(buf, cs, 4, is_read);
\
+ });
\
+ CASE_FIELD(CPU_KSPECIAL_REGISTERS, KernelDr0, f_size, {
\
+ RW_DR(buf, cs, 0, is_read);
\
+ });
\
+ CASE_FIELD(CPU_KSPECIAL_REGISTERS, KernelDr1, f_size, {
\
+ RW_DR(buf, cs, 1, is_read);
\
+ });
\
+ CASE_FIELD(CPU_KSPECIAL_REGISTERS, KernelDr2, f_size, {
\
+ RW_DR(buf, cs, 2, is_read);
\
+ });
\
+ CASE_FIELD(CPU_KSPECIAL_REGISTERS, KernelDr3, f_size, {
\
+ RW_DR(buf, cs, 3, is_read);
\
+ });
\
+ CASE_FIELD(CPU_KSPECIAL_REGISTERS, KernelDr6, f_size, {
\
+ RW_DR(buf, cs, 6, is_read);
\
+ });
\
+ CASE_FIELD(CPU_KSPECIAL_REGISTERS, KernelDr7, f_size, {
\
+ RW_DR(buf, cs, 7, is_read);
\
+ });
\
+ CASE_FIELD(CPU_KSPECIAL_REGISTERS, Gdtr.Pad, f_size, {});
\
+ CASE_FIELD(CPU_KSPECIAL_REGISTERS, Gdtr.Limit, f_size, {
\
+ rwuw_p(buf, env->gdt.limit, is_read);
\
+ });
\
+ CASE_FIELD(CPU_KSPECIAL_REGISTERS, Gdtr.Base, f_size, {
\
+ rwtul_p(buf, env->gdt.base, is_read);
\
+ });
\
+ CASE_FIELD(CPU_KSPECIAL_REGISTERS, Idtr.Pad, f_size, {});
\
+ CASE_FIELD(CPU_KSPECIAL_REGISTERS, Idtr.Limit, f_size, {
\
+ rwuw_p(buf, env->idt.limit, is_read);
\
+ });
\
+ CASE_FIELD(CPU_KSPECIAL_REGISTERS, Idtr.Base, f_size, {
\
+ rwtul_p(buf, env->idt.base, is_read);
\
+ });
\
+ CASE_FIELD(CPU_KSPECIAL_REGISTERS, Tr, f_size, {
\
+ rwuw_p(buf, env->tr.selector, is_read);
\
+ });
\
+ CASE_FIELD(CPU_KSPECIAL_REGISTERS, Ldtr, f_size, {
\
+ rwuw_p(buf, env->tr.selector, is_read);
\
+ });
\
+ CASE_FIELD_X32(CPU_KSPECIAL_REGISTERS, Reserved, f_size, {});
\
+ CASE_FIELD_X64(CPU_KSPECIAL_REGISTERS, MxCsr, f_size, {
\
+ rwl_p(buf, env->mxcsr, is_read);
\
+ });
\
+ CASE_FIELD_X64(CPU_KSPECIAL_REGISTERS, DebugControl, f_size, {});
\
+ CASE_FIELD_X64(CPU_KSPECIAL_REGISTERS, LastBranchToRip, f_size, {});
\
+ CASE_FIELD_X64(CPU_KSPECIAL_REGISTERS, LastBranchFromRip, f_size, {});
\
+ CASE_FIELD_X64(CPU_KSPECIAL_REGISTERS, LastExceptionToRip, f_size,
{});\
+ CASE_FIELD_X64(CPU_KSPECIAL_REGISTERS, LastExceptionFromRip, f_size, {
\
+ });
\
+ CASE_FIELD_X64(CPU_KSPECIAL_REGISTERS, Cr8, f_size, {});
\
+ CASE_FIELD_X64(CPU_KSPECIAL_REGISTERS, MsrGsBase, f_size, {
\
+ rwtul_p(buf, env->segs[R_GS].base, is_read);
\
+ });
\
+ CASE_FIELD_X64(CPU_KSPECIAL_REGISTERS, MsrGsSwap, f_size, {
\
+ rwtul_p(buf, env->kernelgsbase, is_read);
\
+ });
\
+ CASE_FIELD_X64(CPU_KSPECIAL_REGISTERS, MsrStar, f_size, {
\
+ rwtul_p(buf, env->star, is_read);
\
+ });
\
+ CASE_FIELD_X64(CPU_KSPECIAL_REGISTERS, MsrLStar, f_size, {
\
+ rwtul_p(buf, env->lstar, is_read);
\
+ });
\
+ CASE_FIELD_X64(CPU_KSPECIAL_REGISTERS, MsrCStar, f_size, {
\
+ rwtul_p(buf, env->cstar, is_read);
\
+ });
\
+ CASE_FIELD_X64(CPU_KSPECIAL_REGISTERS, MsrSyscallMask, f_size, {
\
+ /* NOTE: Unimplemented in qemu: msr MSR_SFMASK */
\
+ });
\
+ CASE_FIELD_X64(CPU_KSPECIAL_REGISTERS, Xcr0, f_size, {
\
+ rwtul_p(buf, env->xcr0, is_read);
\
+ });
\
+ default:
\
+ f_size = 1;
\
+ }
\
+ offset += f_size;
\
+ buf += f_size;
\
+ }
\
+ return 0;
\
+}
+
__attribute__ ((unused)) /* unused yet */
GEN_WINDBG_CONTEXT_RW(windbg_read_context, false)
__attribute__ ((unused)) /* unused yet */
GEN_WINDBG_CONTEXT_RW(windbg_write_context, true)
+__attribute__ ((unused)) /* unused yet */
+GEN_WINDBG_KSPEC_REGS_RW(windbg_read_ks_regs, false)
+
+__attribute__ ((unused)) /* unused yet */
+GEN_WINDBG_KSPEC_REGS_RW(windbg_write_ks_regs, true)
+
static bool find_KPCR(CPUState *cs)
{
X86CPU *cpu = X86_CPU(cs);
- [Qemu-devel] [PATCH 2 15/39] windbg: handler of parsing context, (continued)
- [Qemu-devel] [PATCH 2 15/39] windbg: handler of parsing context, Mikhail Abakumov, 2018/12/05
- [Qemu-devel] [PATCH 2 16/39] windbg: init DBGKD_ANY_WAIT_STATE_CHANGE, Mikhail Abakumov, 2018/12/05
- [Qemu-devel] [PATCH 2 17/39] windbg: generate ExceptionStateChange and LoadSymbolsStateChange, Mikhail Abakumov, 2018/12/05
- [Qemu-devel] [PATCH 2 18/39] windbg: implement windbg_process_control_packet, Mikhail Abakumov, 2018/12/05
- [Qemu-devel] [PATCH 2 19/39] windbg: implement windbg_process_data_packet, Mikhail Abakumov, 2018/12/05
- [Qemu-devel] [PATCH 2 21/39] windbg: implement kd_api_read_virtual_memory and kd_api_write_virtual_memory, Mikhail Abakumov, 2018/12/05
- [Qemu-devel] [PATCH 2 20/39] windbg: implement windbg_process_manipulate_packet, Mikhail Abakumov, 2018/12/05
- [Qemu-devel] [PATCH 2 22/39] windbg: some kernel structures, Mikhail Abakumov, 2018/12/05
- [Qemu-devel] [PATCH 2 23/39] windbg: add helper functions, Mikhail Abakumov, 2018/12/05
- [Qemu-devel] [PATCH 2 24/39] windbg: [de]serialization cpu context, Mikhail Abakumov, 2018/12/05
- [Qemu-devel] [PATCH 2 25/39] windbg: [de]serialization cpu spec registers,
Mikhail Abakumov <=
- [Qemu-devel] [PATCH 2 26/39] windbg: implement kd_api_get_context and kd_api_set_context, Mikhail Abakumov, 2018/12/05
- [Qemu-devel] [PATCH 2 27/39] windbg: implement kd_api_get_context_ex and kd_api_set_context_ex, Mikhail Abakumov, 2018/12/05
- [Qemu-devel] [PATCH 2 28/39] windbg: implement kd_api_read_control_space and kd_api_write_control_space, Mikhail Abakumov, 2018/12/05
- [Qemu-devel] [PATCH 2 29/39] windbg: implement kd_api_write_breakpoint and kd_api_restore_breakpoint, Mikhail Abakumov, 2018/12/05
- [Qemu-devel] [PATCH 2 30/39] windbg: debug exception subscribing, Mikhail Abakumov, 2018/12/05
- [Qemu-devel] [PATCH 2 31/39] windbg: implement kd_api_continue, Mikhail Abakumov, 2018/12/05
- [Qemu-devel] [PATCH 2 33/39] windbg: implement kd_api_read_physical_memory and kd_api_write_physical_memory, Mikhail Abakumov, 2018/12/05
- [Qemu-devel] [PATCH 2 32/39] windbg: implement kd_api_read_io_space and kd_api_write_io_space, Mikhail Abakumov, 2018/12/05
- [Qemu-devel] [PATCH 2 34/39] windbg: implement kd_api_get_version, Mikhail Abakumov, 2018/12/05