um: take arch/um/sys-x86 to arch/x86/um
[pandora-kernel.git] / arch / x86 / um / os-Linux / mcontext.c
1 #include <sys/ucontext.h>
2 #define __FRAME_OFFSETS
3 #include <asm/ptrace.h>
4 #include <sysdep/ptrace.h>
5
6 void get_regs_from_mc(struct uml_pt_regs *regs, mcontext_t *mc)
7 {
8 #ifdef __i386__
9 #define COPY2(X,Y) regs->gp[X] = mc->gregs[REG_##Y]
10 #define COPY(X) regs->gp[X] = mc->gregs[REG_##X]
11 #define COPY_SEG(X) regs->gp[X] = mc->gregs[REG_##X] & 0xffff;
12 #define COPY_SEG_CPL3(X) regs->gp[X] = (mc->gregs[REG_##X] & 0xffff) | 3;
13         COPY_SEG(GS); COPY_SEG(FS); COPY_SEG(ES); COPY_SEG(DS);
14         COPY(EDI); COPY(ESI); COPY(EBP);
15         COPY2(UESP, ESP); /* sic */
16         COPY(EBX); COPY(EDX); COPY(ECX); COPY(EAX);
17         COPY(EIP); COPY_SEG_CPL3(CS); COPY(EFL); COPY_SEG_CPL3(SS);
18 #else
19 #define COPY2(X,Y) regs->gp[X/sizeof(unsigned long)] = mc->gregs[REG_##Y]
20 #define COPY(X) regs->gp[X/sizeof(unsigned long)] = mc->gregs[REG_##X]
21         COPY(R8); COPY(R9); COPY(R10); COPY(R11);
22         COPY(R12); COPY(R13); COPY(R14); COPY(R15);
23         COPY(RDI); COPY(RSI); COPY(RBP); COPY(RBX);
24         COPY(RDX); COPY(RAX); COPY(RCX); COPY(RSP);
25         COPY(RIP);
26         COPY2(EFLAGS, EFL);
27         COPY2(CS, CSGSFS);
28         regs->gp[CS / sizeof(unsigned long)] &= 0xffff;
29         regs->gp[CS / sizeof(unsigned long)] |= 3;
30 #endif
31 }