+ state = (x86_thread_state64_t *) tstate;
+
+ saved_state = saved_state64(int_state);
+ /*
+ * General registers.
+ */
+ state->rax = saved_state->rax;
+ state->rbx = saved_state->rbx;
+ state->rcx = saved_state->rcx;
+ state->rdx = saved_state->rdx;
+ state->rdi = saved_state->rdi;
+ state->rsi = saved_state->rsi;
+ state->rbp = saved_state->rbp;
+ state->rsp = saved_state->isf.rsp;
+ state->r8 = saved_state->r8;
+ state->r9 = saved_state->r9;
+ state->r10 = saved_state->r10;
+ state->r11 = saved_state->r11;
+ state->r12 = saved_state->r12;
+ state->r13 = saved_state->r13;
+ state->r14 = saved_state->r14;
+ state->r15 = saved_state->r15;
+
+ state->rip = saved_state->isf.rip;
+ state->rflags = saved_state->isf.rflags;
+ state->cs = saved_state->isf.cs;
+ state->fs = saved_state->fs & 0xffff;
+ state->gs = saved_state->gs & 0xffff;
+ *count = x86_THREAD_STATE64_COUNT;
+
+ return KERN_SUCCESS;
+ }
+
+ case x86_THREAD_STATE: {
+ x86_thread_state_t *state = NULL;
+
+ if (*count < x86_THREAD_STATE_COUNT)
+ return (KERN_INVALID_ARGUMENT);
+
+ state = (x86_thread_state_t *) tstate;
+
+ if (is_saved_state32(int_state)) {
+ x86_saved_state32_t *saved_state = saved_state32(int_state);
+
+ state->tsh.flavor = x86_THREAD_STATE32;
+ state->tsh.count = x86_THREAD_STATE32_COUNT;
+
+ /*
+ * General registers.
+ */
+ state->uts.ts32.eax = saved_state->eax;
+ state->uts.ts32.ebx = saved_state->ebx;
+ state->uts.ts32.ecx = saved_state->ecx;
+ state->uts.ts32.edx = saved_state->edx;
+ state->uts.ts32.edi = saved_state->edi;
+ state->uts.ts32.esi = saved_state->esi;
+ state->uts.ts32.ebp = saved_state->ebp;
+ state->uts.ts32.esp = saved_state->uesp;
+ state->uts.ts32.eflags = saved_state->efl;
+ state->uts.ts32.eip = saved_state->eip;
+ state->uts.ts32.cs = saved_state->cs;
+ state->uts.ts32.ss = saved_state->ss;
+ state->uts.ts32.ds = saved_state->ds & 0xffff;
+ state->uts.ts32.es = saved_state->es & 0xffff;
+ state->uts.ts32.fs = saved_state->fs & 0xffff;
+ state->uts.ts32.gs = saved_state->gs & 0xffff;
+ } else if (is_saved_state64(int_state)) {
+ x86_saved_state64_t *saved_state = saved_state64(int_state);
+
+ state->tsh.flavor = x86_THREAD_STATE64;
+ state->tsh.count = x86_THREAD_STATE64_COUNT;
+
+ /*
+ * General registers.
+ */
+ state->uts.ts64.rax = saved_state->rax;
+ state->uts.ts64.rbx = saved_state->rbx;
+ state->uts.ts64.rcx = saved_state->rcx;
+ state->uts.ts64.rdx = saved_state->rdx;
+ state->uts.ts64.rdi = saved_state->rdi;
+ state->uts.ts64.rsi = saved_state->rsi;
+ state->uts.ts64.rbp = saved_state->rbp;
+ state->uts.ts64.rsp = saved_state->isf.rsp;
+ state->uts.ts64.r8 = saved_state->r8;
+ state->uts.ts64.r9 = saved_state->r9;
+ state->uts.ts64.r10 = saved_state->r10;
+ state->uts.ts64.r11 = saved_state->r11;
+ state->uts.ts64.r12 = saved_state->r12;
+ state->uts.ts64.r13 = saved_state->r13;
+ state->uts.ts64.r14 = saved_state->r14;
+ state->uts.ts64.r15 = saved_state->r15;
+
+ state->uts.ts64.rip = saved_state->isf.rip;
+ state->uts.ts64.rflags = saved_state->isf.rflags;
+ state->uts.ts64.cs = saved_state->isf.cs;
+ state->uts.ts64.fs = saved_state->fs & 0xffff;
+ state->uts.ts64.gs = saved_state->gs & 0xffff;
+ } else {
+ panic("unknown thread state");
+ }