15#include "DebugServer2/Architecture/CPUState.h"
18namespace Architecture {
22#define _PASTE(A, B) A##B
23#define PASTE(A, B) _PASTE(A, B)
29#define DO_COPY_GPR_32() \
43#define DO_COPY_GPR_64() \
59 DO_COPY_SS_REG(cs, Cs); \
60 DO_COPY_SS_REG(ss, Ss); \
61 DO_COPY_SS_REG(ds, Ds); \
62 DO_COPY_SS_REG(es, Es); \
63 DO_COPY_SS_REG(fs, Fs); \
64 DO_COPY_SS_REG(gs, Gs); \
69 DO_COPY_SS_REG(cs, cs); \
70 DO_COPY_SS_REG(ss, ss); \
71 DO_COPY_SS_REG(ds, ds); \
72 DO_COPY_SS_REG(es, es); \
73 DO_COPY_SS_REG(fs, fs); \
74 DO_COPY_SS_REG(gs, gs); \
79#define DO_COPY_EXTRA_32() \
81 DO_COPY_REG(state.linux_gp.PASTE(orig_, STATE_GP_REG(ax)), \
82 user.PASTE(orig_, USER_GP_REG(ax)), 0); \
84#define DO_COPY_EXTRA_64() \
87 DO_COPY_REG(state.linux_gp.fs_base, user.fs_base, 0); \
88 DO_COPY_REG(state.linux_gp.gs_base, user.gs_base, 0); \
91#define DO_COPY_EXTRA_32() DO_EMPTY()
92#define DO_COPY_EXTRA_64() DO_EMPTY()
95#if defined(OS_LINUX) && defined(ARCH_X86)
96#define USER_GP_REG(NAME) e##NAME
97#define USER_SS_REG(NAME) x##NAME
98#define USER_FLAGS_REG() eflags
99#elif defined(OS_LINUX) && defined(ARCH_X86_64)
100#define USER_GP_REG(NAME) r##NAME
101#define USER_SS_REG(NAME) NAME
102#define USER_FLAGS_REG() eflags
103#elif defined(OS_FREEBSD) && defined(ARCH_X86_64)
104#define USER_GP_REG(NAME) r_r##NAME
105#define USER_SS_REG(NAME) r_##NAME
106#define USER_FLAGS_REG() r_rflags
107#elif defined(OS_WIN32) && defined(ARCH_X86)
108#define USER_GP_REG(NAME) E##NAME
109#define USER_SS_REG(NAME) Seg##NAME
110#define USER_FLAGS_REG() EFlags
111#elif defined(OS_WIN32) && defined(ARCH_X86_64)
112#define USER_GP_REG(NAME) R##NAME
113#define USER_SS_REG(NAME) Seg##NAME
114#define USER_FLAGS_REG() EFlags
117#define DO_COPY_GP_REG(NAME) \
118 DO_COPY_REG(state.gp.STATE_GP_REG(NAME), user.USER_GP_REG(NAME), 0)
119#define DO_COPY_SS_REG(S, U) \
120 DO_COPY_REG(state.gp.S, user.USER_SS_REG(U), 0xffff)
121#define DO_COPY_FLAGS() DO_COPY_REG(state.gp.eflags, user.USER_FLAGS_REG(), 0)
123#define STATE_GP_REG(NAME) e##NAME
124#define DO_COPY_REG(S, U, M) S = (M ? U & M : U)
125template <
typename StateType,
typename UserStructType>
126static inline void user_to_state32(StateType &state,
127 UserStructType
const &user) {
134#define DO_COPY_REG(S, U, M) U = (M ? S & M : S)
135template <
typename UserStructType,
typename StateType>
136static inline void state32_to_user(UserStructType &user,
137 StateType
const &state) {
145#define STATE_GP_REG(NAME) r##NAME
146#define DO_COPY_REG(S, U, M) S = (M ? U & M : U)
147template <
typename StateType,
typename UserStructType>
148static inline void user_to_state64(StateType &state,
149 UserStructType
const &user) {
156#define DO_COPY_REG(S, U, M) U = (M ? S & M : S)
157template <
typename UserStructType,
typename StateType>
158static inline void state64_to_user(UserStructType &user,
159 StateType
const &state) {