162306a36Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci#include <sys/ucontext.h>
362306a36Sopenharmony_ci#define __FRAME_OFFSETS
462306a36Sopenharmony_ci#include <asm/ptrace.h>
562306a36Sopenharmony_ci#include <sysdep/ptrace.h>
662306a36Sopenharmony_ci
762306a36Sopenharmony_civoid get_regs_from_mc(struct uml_pt_regs *regs, mcontext_t *mc)
862306a36Sopenharmony_ci{
962306a36Sopenharmony_ci#ifdef __i386__
1062306a36Sopenharmony_ci#define COPY2(X,Y) regs->gp[X] = mc->gregs[REG_##Y]
1162306a36Sopenharmony_ci#define COPY(X) regs->gp[X] = mc->gregs[REG_##X]
1262306a36Sopenharmony_ci#define COPY_SEG(X) regs->gp[X] = mc->gregs[REG_##X] & 0xffff;
1362306a36Sopenharmony_ci#define COPY_SEG_CPL3(X) regs->gp[X] = (mc->gregs[REG_##X] & 0xffff) | 3;
1462306a36Sopenharmony_ci	COPY_SEG(GS); COPY_SEG(FS); COPY_SEG(ES); COPY_SEG(DS);
1562306a36Sopenharmony_ci	COPY(EDI); COPY(ESI); COPY(EBP);
1662306a36Sopenharmony_ci	COPY2(UESP, ESP); /* sic */
1762306a36Sopenharmony_ci	COPY(EBX); COPY(EDX); COPY(ECX); COPY(EAX);
1862306a36Sopenharmony_ci	COPY(EIP); COPY_SEG_CPL3(CS); COPY(EFL); COPY_SEG_CPL3(SS);
1962306a36Sopenharmony_ci#else
2062306a36Sopenharmony_ci#define COPY2(X,Y) regs->gp[X/sizeof(unsigned long)] = mc->gregs[REG_##Y]
2162306a36Sopenharmony_ci#define COPY(X) regs->gp[X/sizeof(unsigned long)] = mc->gregs[REG_##X]
2262306a36Sopenharmony_ci	COPY(R8); COPY(R9); COPY(R10); COPY(R11);
2362306a36Sopenharmony_ci	COPY(R12); COPY(R13); COPY(R14); COPY(R15);
2462306a36Sopenharmony_ci	COPY(RDI); COPY(RSI); COPY(RBP); COPY(RBX);
2562306a36Sopenharmony_ci	COPY(RDX); COPY(RAX); COPY(RCX); COPY(RSP);
2662306a36Sopenharmony_ci	COPY(RIP);
2762306a36Sopenharmony_ci	COPY2(EFLAGS, EFL);
2862306a36Sopenharmony_ci	COPY2(CS, CSGSFS);
2962306a36Sopenharmony_ci	regs->gp[CS / sizeof(unsigned long)] &= 0xffff;
3062306a36Sopenharmony_ci	regs->gp[CS / sizeof(unsigned long)] |= 3;
3162306a36Sopenharmony_ci#endif
3262306a36Sopenharmony_ci}
33