18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci#include <sys/ucontext.h>
38c2ecf20Sopenharmony_ci#define __FRAME_OFFSETS
48c2ecf20Sopenharmony_ci#include <asm/ptrace.h>
58c2ecf20Sopenharmony_ci#include <sysdep/ptrace.h>
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_civoid get_regs_from_mc(struct uml_pt_regs *regs, mcontext_t *mc)
88c2ecf20Sopenharmony_ci{
98c2ecf20Sopenharmony_ci#ifdef __i386__
108c2ecf20Sopenharmony_ci#define COPY2(X,Y) regs->gp[X] = mc->gregs[REG_##Y]
118c2ecf20Sopenharmony_ci#define COPY(X) regs->gp[X] = mc->gregs[REG_##X]
128c2ecf20Sopenharmony_ci#define COPY_SEG(X) regs->gp[X] = mc->gregs[REG_##X] & 0xffff;
138c2ecf20Sopenharmony_ci#define COPY_SEG_CPL3(X) regs->gp[X] = (mc->gregs[REG_##X] & 0xffff) | 3;
148c2ecf20Sopenharmony_ci	COPY_SEG(GS); COPY_SEG(FS); COPY_SEG(ES); COPY_SEG(DS);
158c2ecf20Sopenharmony_ci	COPY(EDI); COPY(ESI); COPY(EBP);
168c2ecf20Sopenharmony_ci	COPY2(UESP, ESP); /* sic */
178c2ecf20Sopenharmony_ci	COPY(EBX); COPY(EDX); COPY(ECX); COPY(EAX);
188c2ecf20Sopenharmony_ci	COPY(EIP); COPY_SEG_CPL3(CS); COPY(EFL); COPY_SEG_CPL3(SS);
198c2ecf20Sopenharmony_ci#else
208c2ecf20Sopenharmony_ci#define COPY2(X,Y) regs->gp[X/sizeof(unsigned long)] = mc->gregs[REG_##Y]
218c2ecf20Sopenharmony_ci#define COPY(X) regs->gp[X/sizeof(unsigned long)] = mc->gregs[REG_##X]
228c2ecf20Sopenharmony_ci	COPY(R8); COPY(R9); COPY(R10); COPY(R11);
238c2ecf20Sopenharmony_ci	COPY(R12); COPY(R13); COPY(R14); COPY(R15);
248c2ecf20Sopenharmony_ci	COPY(RDI); COPY(RSI); COPY(RBP); COPY(RBX);
258c2ecf20Sopenharmony_ci	COPY(RDX); COPY(RAX); COPY(RCX); COPY(RSP);
268c2ecf20Sopenharmony_ci	COPY(RIP);
278c2ecf20Sopenharmony_ci	COPY2(EFLAGS, EFL);
288c2ecf20Sopenharmony_ci	COPY2(CS, CSGSFS);
298c2ecf20Sopenharmony_ci	regs->gp[CS / sizeof(unsigned long)] &= 0xffff;
308c2ecf20Sopenharmony_ci	regs->gp[CS / sizeof(unsigned long)] |= 3;
318c2ecf20Sopenharmony_ci#endif
328c2ecf20Sopenharmony_ci}
33