X-Git-Url: http://v3vee.org/palacios/gitweb/gitweb.cgi?a=blobdiff_plain;f=palacios%2Finclude%2Fpalacios%2Fvmm_instr_emulator.h;h=aef325ace0b450bf8b7a25b3a0213c8c552c688a;hb=debabd511ff9dc2d0e6cd608045ac44295fe7319;hp=132970b08668a08017789a24b4aa403850259bd5;hpb=757000c47f1ce82cba12d1a9a06cd3b5e8b0b505;p=palacios.git diff --git a/palacios/include/palacios/vmm_instr_emulator.h b/palacios/include/palacios/vmm_instr_emulator.h index 132970b..aef325a 100644 --- a/palacios/include/palacios/vmm_instr_emulator.h +++ b/palacios/include/palacios/vmm_instr_emulator.h @@ -21,7 +21,7 @@ -#define MAKE_1OP_8FLAGS_WINST(iname) static inline void iname##8(addr_t * dst, addr_t * flags) { \ +#define MAKE_1OP_8FLAGS_INST(iname) static inline void iname##8(addr_t * dst, addr_t * flags) { \ uchar_t tmp_dst = *dst; \ \ /* Some of the flags values are not copied out in a pushf, we save them here */ \ @@ -43,7 +43,7 @@ \ } -#define MAKE_1OP_16FLAGS_WINST(iname) static inline void iname##16(addr_t * dst, addr_t * flags) { \ +#define MAKE_1OP_16FLAGS_INST(iname) static inline void iname##16(addr_t * dst, addr_t * flags) { \ ushort_t tmp_dst = *dst; \ \ /* Some of the flags values are not copied out in a pushf, we save them here */ \ @@ -65,7 +65,7 @@ \ } -#define MAKE_1OP_32FLAGS_WINST(iname) static inline void iname##32(addr_t * dst, addr_t * flags) { \ +#define MAKE_1OP_32FLAGS_INST(iname) static inline void iname##32(addr_t * dst, addr_t * flags) { \ uint_t tmp_dst = *dst; \ \ /* Some of the flags values are not copied out in a pushf, we save them here */ \ @@ -87,7 +87,7 @@ \ } -#define MAKE_1OP_64FLAGS_WINST(iname) static inline void iname##64(addr_t * dst, addr_t * flags) { \ +#define MAKE_1OP_64FLAGS_INST(iname) static inline void iname##64(addr_t * dst, addr_t * flags) { \ ullong_t tmp_dst = *dst; \ \ /* Some of the flags values are not copied out in a pushf, we save them here */ \ @@ -111,7 +111,7 @@ -#define MAKE_1OP_8_WINST(iname) static inline void iname##8(addr_t * dst) { \ +#define MAKE_1OP_8_INST(iname) static inline void iname##8(addr_t * dst) { \ uchar_t tmp_dst = *dst; \ \ asm volatile ( \ @@ -122,7 +122,7 @@ *dst = tmp_dst; \ } -#define MAKE_1OP_16_WINST(iname) static inline void iname##16(addr_t * dst) { \ +#define MAKE_1OP_16_INST(iname) static inline void iname##16(addr_t * dst) { \ ushort_t tmp_dst = *dst; \ \ asm volatile ( \ @@ -133,7 +133,7 @@ *dst = tmp_dst; \ } -#define MAKE_1OP_32_WINST(iname) static inline void iname##32(addr_t * dst) { \ +#define MAKE_1OP_32_INST(iname) static inline void iname##32(addr_t * dst) { \ uint_t tmp_dst = *dst; \ \ asm volatile ( \ @@ -144,7 +144,7 @@ *dst = tmp_dst; \ } -#define MAKE_1OP_64_WINST(iname) static inline void iname##64(addr_t * dst) { \ +#define MAKE_1OP_64_INST(iname) static inline void iname##64(addr_t * dst) { \ ullong_t tmp_dst = *dst; \ \ asm volatile ( \ @@ -156,7 +156,7 @@ } -#define MAKE_2OP_64FLAGS_WINST(iname) static inline void iname##64(addr_t * dst, addr_t * src, addr_t * flags) { \ +#define MAKE_2OP_64FLAGS_INST(iname) static inline void iname##64(addr_t * dst, addr_t * src, addr_t * flags) { \ uint64_t tmp_dst = *dst, tmp_src = *src; \ addr_t tmp_flags = *flags; \ \ @@ -184,7 +184,7 @@ -#define MAKE_2OP_32FLAGS_WINST(iname) static inline void iname##32(addr_t * dst, addr_t * src, addr_t * flags) { \ +#define MAKE_2OP_32FLAGS_INST(iname) static inline void iname##32(addr_t * dst, addr_t * src, addr_t * flags) { \ uint32_t tmp_dst = *dst, tmp_src = *src; \ \ /* Some of the flags values are not copied out in a pushf, we save them here */ \ @@ -207,7 +207,7 @@ } -#define MAKE_2OP_16FLAGS_WINST(iname) static inline void iname##16(addr_t * dst, addr_t * src, addr_t * flags) { \ +#define MAKE_2OP_16FLAGS_INST(iname) static inline void iname##16(addr_t * dst, addr_t * src, addr_t * flags) { \ ushort_t tmp_dst = *dst, tmp_src = *src; \ \ /* Some of the flags values are not copied out in a pushf, we save them here */ \ @@ -229,7 +229,7 @@ \ } -#define MAKE_2OP_8FLAGS_WINST(iname) static inline void iname##8(addr_t * dst, addr_t * src, addr_t * flags) { \ +#define MAKE_2OP_8FLAGS_INST(iname) static inline void iname##8(addr_t * dst, addr_t * src, addr_t * flags) { \ uchar_t tmp_dst = *dst, tmp_src = *src; \ \ /* Some of the flags values are not copied out in a pushf, we save them here */ \ @@ -255,9 +255,9 @@ -#define MAKE_2OP_64STR_WINST(iname) static inline void iname##64(addr_t * dst, \ - addr_t * src, \ - addr_t * ecx, addr_t * flags) { \ +#define MAKE_2OP_64STR_INST(iname) static inline void iname##64(addr_t * dst, \ + addr_t * src, \ + addr_t * ecx, addr_t * flags) { \ /* Some of the flags values are not copied out in a pushf, we save them here */ \ addr_t flags_rsvd = *flags & ~0xfffe7fff; \ \ @@ -279,7 +279,7 @@ } -#define MAKE_2OP_32STR_WINST(iname) static inline void iname##32(addr_t * dst, \ +#define MAKE_2OP_32STR_INST(iname) static inline void iname##32(addr_t * dst, \ addr_t * src, \ addr_t * ecx, addr_t * flags) { \ /* Some of the flags values are not copied out in a pushf, we save them here */ \ @@ -302,7 +302,7 @@ *flags |= flags_rsvd; \ } -#define MAKE_2OP_16STR_WINST(iname) static inline void iname##16(addr_t * dst, \ +#define MAKE_2OP_16STR_INST(iname) static inline void iname##16(addr_t * dst, \ addr_t * src, \ addr_t * ecx, addr_t * flags) { \ /* Some of the flags values are not copied out in a pushf, we save them here */ \ @@ -325,7 +325,7 @@ -#define MAKE_2OP_8STR_WINST(iname) static inline void iname##8(addr_t * dst, \ +#define MAKE_2OP_8STR_INST(iname) static inline void iname##8(addr_t * dst, \ addr_t * src, \ addr_t * ecx, addr_t * flags) { \ /* Some of the flags values are not copied out in a pushf, we save them here */ \ @@ -349,8 +349,8 @@ -#define MAKE_2OP_64_WINST(iname) static inline void iname##64(addr_t * dst, addr_t * src) { \ - uint32_t tmp_dst = *dst, tmp_src = *src; \ +#define MAKE_2OP_64_INST(iname) static inline void iname##64(addr_t * dst, addr_t * src) { \ + uint64_t tmp_dst = *dst, tmp_src = *src; \ \ asm volatile ( \ #iname"q %1, %0; " \ @@ -360,7 +360,7 @@ *dst = tmp_dst; \ } -#define MAKE_2OP_32_WINST(iname) static inline void iname##32(addr_t * dst, addr_t * src) { \ +#define MAKE_2OP_32_INST(iname) static inline void iname##32(addr_t * dst, addr_t * src) { \ uint32_t tmp_dst = *dst, tmp_src = *src; \ \ asm volatile ( \ @@ -371,7 +371,7 @@ *dst = tmp_dst; \ } -#define MAKE_2OP_16_WINST(iname) static inline void iname##16(addr_t * dst, addr_t * src) { \ +#define MAKE_2OP_16_INST(iname) static inline void iname##16(addr_t * dst, addr_t * src) { \ ushort_t tmp_dst = *dst, tmp_src = *src; \ \ asm volatile ( \ @@ -382,7 +382,7 @@ *dst = tmp_dst; \ } -#define MAKE_2OP_8_WINST(iname) static inline void iname##8(addr_t * dst, addr_t * src) { \ +#define MAKE_2OP_8_INST(iname) static inline void iname##8(addr_t * dst, addr_t * src) { \ uchar_t tmp_dst = *dst, tmp_src = *src; \ \ asm volatile ( \ @@ -397,82 +397,165 @@ +#define MAKE_2OP_8EXT_INST(iname) static inline void iname##8(addr_t * dst, addr_t * src, uint_t dst_len) { \ + if (dst_len == 2) { \ + asm volatile ( \ + #iname" %1, %0; " \ + : "=q"(*(uint16_t *)dst) \ + : "q"(*(uint8_t *)src), "0"(*(uint16_t *)dst) \ + ); \ + } else if (dst_len == 4) { \ + asm volatile ( \ + #iname" %1, %0; " \ + : "=q"(*(uint32_t *)dst) \ + : "q"(*(uint8_t *)src), "0"(*(uint32_t *)dst) \ + ); \ + } else if (dst_len == 8) { \ + asm volatile ( \ + #iname" %1, %0; " \ + : "=q"(*(uint64_t *)dst) \ + : "q"(*(uint8_t *)src), "0"(*(uint64_t *)dst) \ + ); \ + } \ + } + +#define MAKE_2OP_16EXT_INST(iname) static inline void iname##16(addr_t * dst, addr_t * src, uint_t dst_len) { \ + if (dst_len == 4) { \ + asm volatile ( \ + #iname" %1, %0; " \ + : "=q"(*(uint32_t *)dst) \ + : "q"(*(uint16_t *)src), "0"(*(uint32_t *)dst) \ + ); \ + } else if (dst_len == 8) { \ + asm volatile ( \ + #iname" %1, %0; " \ + : "=q"(*(uint64_t *)dst) \ + : "q"(*(uint16_t *)src), "0"(*(uint64_t *)dst) \ + ); \ + } \ + } + + + + + + +/****************************/ +/* 8 Bit instruction forms */ +/****************************/ + +MAKE_2OP_8FLAGS_INST(adc); +MAKE_2OP_8FLAGS_INST(add); +MAKE_2OP_8FLAGS_INST(and); +MAKE_2OP_8FLAGS_INST(or); +MAKE_2OP_8FLAGS_INST(xor); +MAKE_2OP_8FLAGS_INST(sub); + + +MAKE_1OP_8FLAGS_INST(inc); +MAKE_1OP_8FLAGS_INST(dec); +MAKE_1OP_8FLAGS_INST(neg); +MAKE_1OP_8FLAGS_INST(setb); +MAKE_1OP_8FLAGS_INST(setbe); +MAKE_1OP_8FLAGS_INST(setl); +MAKE_1OP_8FLAGS_INST(setle); +MAKE_1OP_8FLAGS_INST(setnb); +MAKE_1OP_8FLAGS_INST(setnbe); +MAKE_1OP_8FLAGS_INST(setnl); +MAKE_1OP_8FLAGS_INST(setnle); +MAKE_1OP_8FLAGS_INST(setno); +MAKE_1OP_8FLAGS_INST(setnp); +MAKE_1OP_8FLAGS_INST(setns); +MAKE_1OP_8FLAGS_INST(setnz); +MAKE_1OP_8FLAGS_INST(seto); +MAKE_1OP_8FLAGS_INST(setp); +MAKE_1OP_8FLAGS_INST(sets); +MAKE_1OP_8FLAGS_INST(setz); + + +MAKE_1OP_8_INST(not); + +MAKE_2OP_8_INST(mov); +MAKE_2OP_8EXT_INST(movzx); +MAKE_2OP_8EXT_INST(movsx); + +MAKE_2OP_8_INST(xchg); + +MAKE_2OP_8STR_INST(movs); + + +/****************************/ +/* 16 Bit instruction forms */ +/****************************/ +MAKE_2OP_16FLAGS_INST(adc); +MAKE_2OP_16FLAGS_INST(add); +MAKE_2OP_16FLAGS_INST(and); +MAKE_2OP_16FLAGS_INST(or); +MAKE_2OP_16FLAGS_INST(xor); +MAKE_2OP_16FLAGS_INST(sub); -MAKE_2OP_8FLAGS_WINST(adc); -MAKE_2OP_8FLAGS_WINST(add); -MAKE_2OP_8FLAGS_WINST(and); -MAKE_2OP_8FLAGS_WINST(or); -MAKE_2OP_8FLAGS_WINST(xor); -MAKE_2OP_8FLAGS_WINST(sub); +MAKE_1OP_16FLAGS_INST(inc); +MAKE_1OP_16FLAGS_INST(dec); +MAKE_1OP_16FLAGS_INST(neg); +MAKE_1OP_16_INST(not); -MAKE_1OP_8FLAGS_WINST(inc); -MAKE_1OP_8FLAGS_WINST(dec); -MAKE_1OP_8FLAGS_WINST(neg); -MAKE_1OP_8FLAGS_WINST(setb); -MAKE_1OP_8FLAGS_WINST(setbe); -MAKE_1OP_8FLAGS_WINST(setl); -MAKE_1OP_8FLAGS_WINST(setle); -MAKE_1OP_8FLAGS_WINST(setnb); -MAKE_1OP_8FLAGS_WINST(setnbe); -MAKE_1OP_8FLAGS_WINST(setnl); -MAKE_1OP_8FLAGS_WINST(setnle); -MAKE_1OP_8FLAGS_WINST(setno); -MAKE_1OP_8FLAGS_WINST(setnp); -MAKE_1OP_8FLAGS_WINST(setns); -MAKE_1OP_8FLAGS_WINST(setnz); -MAKE_1OP_8FLAGS_WINST(seto); -MAKE_1OP_8FLAGS_WINST(setp); -MAKE_1OP_8FLAGS_WINST(sets); -MAKE_1OP_8FLAGS_WINST(setz); +MAKE_2OP_16_INST(mov); +MAKE_2OP_16EXT_INST(movzx); +MAKE_2OP_16EXT_INST(movsx); +MAKE_2OP_16_INST(xchg); +MAKE_2OP_16STR_INST(movs); -MAKE_1OP_8_WINST(not); +/****************************/ +/* 32 Bit instruction forms */ +/****************************/ +MAKE_2OP_32FLAGS_INST(adc); +MAKE_2OP_32FLAGS_INST(add); +MAKE_2OP_32FLAGS_INST(and); +MAKE_2OP_32FLAGS_INST(or); +MAKE_2OP_32FLAGS_INST(xor); +MAKE_2OP_32FLAGS_INST(sub); -MAKE_2OP_8_WINST(mov); -MAKE_2OP_8_WINST(xchg); +MAKE_1OP_32FLAGS_INST(inc); +MAKE_1OP_32FLAGS_INST(dec); +MAKE_1OP_32FLAGS_INST(neg); +MAKE_1OP_32_INST(not); -MAKE_2OP_16FLAGS_WINST(adc); -MAKE_2OP_16FLAGS_WINST(add); -MAKE_2OP_16FLAGS_WINST(and); -MAKE_2OP_16FLAGS_WINST(or); -MAKE_2OP_16FLAGS_WINST(xor); -MAKE_2OP_16FLAGS_WINST(sub); +MAKE_2OP_32_INST(mov); +MAKE_2OP_32_INST(xchg); -MAKE_1OP_16FLAGS_WINST(inc); -MAKE_1OP_16FLAGS_WINST(dec); -MAKE_1OP_16FLAGS_WINST(neg); -MAKE_1OP_16_WINST(not); -MAKE_2OP_16_WINST(mov); -MAKE_2OP_16_WINST(xchg); +MAKE_2OP_32STR_INST(movs); +#ifdef __V3_64BIT__ +/****************************/ +/* 64 Bit instruction forms */ +/****************************/ +MAKE_2OP_64FLAGS_INST(adc); +MAKE_2OP_64FLAGS_INST(add); +MAKE_2OP_64FLAGS_INST(and); +MAKE_2OP_64FLAGS_INST(or); +MAKE_2OP_64FLAGS_INST(xor); +MAKE_2OP_64FLAGS_INST(sub); +MAKE_1OP_64FLAGS_INST(inc); +MAKE_1OP_64FLAGS_INST(dec); +MAKE_1OP_64FLAGS_INST(neg); +MAKE_1OP_64_INST(not); -MAKE_2OP_32FLAGS_WINST(adc); -MAKE_2OP_32FLAGS_WINST(add); -MAKE_2OP_32FLAGS_WINST(and); -MAKE_2OP_32FLAGS_WINST(or); -MAKE_2OP_32FLAGS_WINST(xor); -MAKE_2OP_32FLAGS_WINST(sub); +MAKE_2OP_64_INST(mov); -MAKE_1OP_32FLAGS_WINST(inc); -MAKE_1OP_32FLAGS_WINST(dec); -MAKE_1OP_32FLAGS_WINST(neg); -MAKE_1OP_32_WINST(not); +MAKE_2OP_64_INST(xchg); -MAKE_2OP_32_WINST(mov); -MAKE_2OP_32_WINST(xchg); -MAKE_2OP_8STR_WINST(movs); -MAKE_2OP_16STR_WINST(movs); -MAKE_2OP_32STR_WINST(movs); +#endif