SoftCPU.cpp 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions are met:
  7. *
  8. * 1. Redistributions of source code must retain the above copyright notice, this
  9. * list of conditions and the following disclaimer.
  10. *
  11. * 2. Redistributions in binary form must reproduce the above copyright notice,
  12. * this list of conditions and the following disclaimer in the documentation
  13. * and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  16. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  18. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  19. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  20. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  21. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  22. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  23. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #include "SoftCPU.h"
  27. #include "Emulator.h"
  28. #include <AK/Assertions.h>
  29. #include <stdio.h>
  30. #include <string.h>
  31. //#define MEMORY_DEBUG
  32. namespace UserspaceEmulator {
  33. template<typename T, typename U>
  34. inline constexpr T sign_extended_to(U value)
  35. {
  36. if (!(value & X86::TypeTrivia<U>::sign_bit))
  37. return value;
  38. return (X86::TypeTrivia<T>::mask & ~X86::TypeTrivia<U>::mask) | value;
  39. }
  40. SoftCPU::SoftCPU(Emulator& emulator)
  41. : m_emulator(emulator)
  42. {
  43. memset(m_gpr, 0, sizeof(m_gpr));
  44. m_segment[(int)X86::SegmentRegister::CS] = 0x18;
  45. m_segment[(int)X86::SegmentRegister::DS] = 0x20;
  46. m_segment[(int)X86::SegmentRegister::ES] = 0x20;
  47. m_segment[(int)X86::SegmentRegister::SS] = 0x20;
  48. m_segment[(int)X86::SegmentRegister::GS] = 0x28;
  49. }
  50. void SoftCPU::dump() const
  51. {
  52. printf("eax=%08x ebx=%08x ecx=%08x edx=%08x ", eax(), ebx(), ecx(), edx());
  53. printf("ebp=%08x esp=%08x esi=%08x edi=%08x ", ebp(), esp(), esi(), edi());
  54. printf("o=%u s=%u z=%u a=%u p=%u c=%u\n", of(), sf(), zf(), af(), pf(), cf());
  55. }
  56. u8 SoftCPU::read8()
  57. {
  58. auto value = read_memory8({ cs(), eip() });
  59. m_eip += 1;
  60. return value;
  61. }
  62. u16 SoftCPU::read16()
  63. {
  64. auto value = read_memory16({ cs(), eip() });
  65. m_eip += 2;
  66. return value;
  67. }
  68. u32 SoftCPU::read32()
  69. {
  70. auto value = read_memory32({ cs(), eip() });
  71. m_eip += 4;
  72. return value;
  73. }
  74. u8 SoftCPU::read_memory8(X86::LogicalAddress address)
  75. {
  76. ASSERT(address.selector() == 0x18 || address.selector() == 0x20 || address.selector() == 0x28);
  77. auto value = m_emulator.mmu().read8(address);
  78. #ifdef MEMORY_DEBUG
  79. printf("\033[36;1mread_memory8: @%08x:%08x -> %02x\033[0m\n", address.selector(), address.offset(), value);
  80. #endif
  81. return value;
  82. }
  83. u16 SoftCPU::read_memory16(X86::LogicalAddress address)
  84. {
  85. ASSERT(address.selector() == 0x18 || address.selector() == 0x20 || address.selector() == 0x28);
  86. auto value = m_emulator.mmu().read16(address);
  87. #ifdef MEMORY_DEBUG
  88. printf("\033[36;1mread_memory16: @%04x:%08x -> %04x\033[0m\n", address.selector(), address.offset(), value);
  89. #endif
  90. return value;
  91. }
  92. u32 SoftCPU::read_memory32(X86::LogicalAddress address)
  93. {
  94. ASSERT(address.selector() == 0x18 || address.selector() == 0x20 || address.selector() == 0x28);
  95. auto value = m_emulator.mmu().read32(address);
  96. #ifdef MEMORY_DEBUG
  97. printf("\033[36;1mread_memory32: @%04x:%08x -> %08x\033[0m\n", address.selector(), address.offset(), value);
  98. #endif
  99. return value;
  100. }
  101. void SoftCPU::write_memory8(X86::LogicalAddress address, u8 value)
  102. {
  103. ASSERT(address.selector() == 0x20 || address.selector() == 0x28);
  104. #ifdef MEMORY_DEBUG
  105. printf("\033[35;1mwrite_memory8: @%04x:%08x <- %02x\033[0m\n", address.selector(), address.offset(), value);
  106. #endif
  107. m_emulator.mmu().write8(address, value);
  108. }
  109. void SoftCPU::write_memory16(X86::LogicalAddress address, u16 value)
  110. {
  111. ASSERT(address.selector() == 0x20 || address.selector() == 0x28);
  112. #ifdef MEMORY_DEBUG
  113. printf("\033[35;1mwrite_memory16: @%04x:%08x <- %04x\033[0m\n", address.selector(), address.offset(), value);
  114. #endif
  115. m_emulator.mmu().write16(address, value);
  116. }
  117. void SoftCPU::write_memory32(X86::LogicalAddress address, u32 value)
  118. {
  119. ASSERT(address.selector() == 0x20 || address.selector() == 0x28);
  120. #ifdef MEMORY_DEBUG
  121. printf("\033[35;1mwrite_memory32: @%04x:%08x <- %08x\033[0m\n", address.selector(), address.offset(), value);
  122. #endif
  123. m_emulator.mmu().write32(address, value);
  124. }
  125. void SoftCPU::push32(u32 value)
  126. {
  127. set_esp(esp() - sizeof(value));
  128. write_memory32({ ss(), esp() }, value);
  129. }
  130. u32 SoftCPU::pop32()
  131. {
  132. auto value = read_memory32({ ss(), esp() });
  133. set_esp(esp() + sizeof(value));
  134. return value;
  135. }
  136. template<bool check_zf, typename Callback>
  137. void SoftCPU::do_once_or_repeat(const X86::Instruction& insn, Callback callback)
  138. {
  139. if (!insn.has_rep_prefix())
  140. return callback();
  141. if (insn.has_address_size_override_prefix()) {
  142. while (cx()) {
  143. callback();
  144. set_cx(cx() - 1);
  145. if constexpr (check_zf) {
  146. if (insn.rep_prefix() == X86::Prefix::REPZ && !zf())
  147. break;
  148. if (insn.rep_prefix() == X86::Prefix::REPNZ && zf())
  149. break;
  150. }
  151. }
  152. return;
  153. }
  154. while (ecx()) {
  155. callback();
  156. set_ecx(ecx() - 1);
  157. if constexpr (check_zf) {
  158. if (insn.rep_prefix() == X86::Prefix::REPZ && !zf())
  159. break;
  160. if (insn.rep_prefix() == X86::Prefix::REPNZ && zf())
  161. break;
  162. }
  163. }
  164. }
  165. template<typename T>
  166. static T op_inc(SoftCPU& cpu, T data)
  167. {
  168. T result = 0;
  169. u32 new_flags = 0;
  170. if constexpr (sizeof(T) == 4) {
  171. asm volatile("incl %%eax\n"
  172. : "=a"(result)
  173. : "a"(data));
  174. } else if constexpr (sizeof(T) == 2) {
  175. asm volatile("incw %%ax\n"
  176. : "=a"(result)
  177. : "a"(data));
  178. } else if constexpr (sizeof(T) == 1) {
  179. asm volatile("incb %%al\n"
  180. : "=a"(result)
  181. : "a"(data));
  182. }
  183. asm volatile(
  184. "pushf\n"
  185. "pop %%ebx"
  186. : "=b"(new_flags));
  187. cpu.set_flags_oszap(new_flags);
  188. return result;
  189. }
  190. template<typename T>
  191. static T op_dec(SoftCPU& cpu, T data)
  192. {
  193. T result = 0;
  194. u32 new_flags = 0;
  195. if constexpr (sizeof(T) == 4) {
  196. asm volatile("decl %%eax\n"
  197. : "=a"(result)
  198. : "a"(data));
  199. } else if constexpr (sizeof(T) == 2) {
  200. asm volatile("decw %%ax\n"
  201. : "=a"(result)
  202. : "a"(data));
  203. } else if constexpr (sizeof(T) == 1) {
  204. asm volatile("decb %%al\n"
  205. : "=a"(result)
  206. : "a"(data));
  207. }
  208. asm volatile(
  209. "pushf\n"
  210. "pop %%ebx"
  211. : "=b"(new_flags));
  212. cpu.set_flags_oszap(new_flags);
  213. return result;
  214. }
  215. template<typename T>
  216. static T op_xor(SoftCPU& cpu, const T& dest, const T& src)
  217. {
  218. T result = 0;
  219. u32 new_flags = 0;
  220. if constexpr (sizeof(T) == 4) {
  221. asm volatile("xorl %%ecx, %%eax\n"
  222. : "=a"(result)
  223. : "a"(dest), "c"((u32)src));
  224. } else if constexpr (sizeof(T) == 2) {
  225. asm volatile("xor %%cx, %%ax\n"
  226. : "=a"(result)
  227. : "a"(dest), "c"((u16)src));
  228. } else if constexpr (sizeof(T) == 1) {
  229. asm volatile("xorb %%cl, %%al\n"
  230. : "=a"(result)
  231. : "a"(dest), "c"((u8)src));
  232. } else {
  233. ASSERT_NOT_REACHED();
  234. }
  235. asm volatile(
  236. "pushf\n"
  237. "pop %%ebx"
  238. : "=b"(new_flags));
  239. cpu.set_flags_oszpc(new_flags);
  240. return result;
  241. }
  242. template<typename T>
  243. static T op_or(SoftCPU& cpu, const T& dest, const T& src)
  244. {
  245. T result = 0;
  246. u32 new_flags = 0;
  247. if constexpr (sizeof(T) == 4) {
  248. asm volatile("orl %%ecx, %%eax\n"
  249. : "=a"(result)
  250. : "a"(dest), "c"((u32)src));
  251. } else if constexpr (sizeof(T) == 2) {
  252. asm volatile("or %%cx, %%ax\n"
  253. : "=a"(result)
  254. : "a"(dest), "c"((u16)src));
  255. } else if constexpr (sizeof(T) == 1) {
  256. asm volatile("orb %%cl, %%al\n"
  257. : "=a"(result)
  258. : "a"(dest), "c"((u8)src));
  259. } else {
  260. ASSERT_NOT_REACHED();
  261. }
  262. asm volatile(
  263. "pushf\n"
  264. "pop %%ebx"
  265. : "=b"(new_flags));
  266. cpu.set_flags_oszpc(new_flags);
  267. return result;
  268. }
  269. template<typename T>
  270. static T op_sub(SoftCPU& cpu, const T& dest, const T& src)
  271. {
  272. T result = 0;
  273. u32 new_flags = 0;
  274. if constexpr (sizeof(T) == 4) {
  275. asm volatile("subl %%ecx, %%eax\n"
  276. : "=a"(result)
  277. : "a"(dest), "c"((u32)src));
  278. } else if constexpr (sizeof(T) == 2) {
  279. asm volatile("subw %%cx, %%ax\n"
  280. : "=a"(result)
  281. : "a"(dest), "c"((u16)src));
  282. } else if constexpr (sizeof(T) == 1) {
  283. asm volatile("subb %%cl, %%al\n"
  284. : "=a"(result)
  285. : "a"(dest), "c"((u8)src));
  286. } else {
  287. ASSERT_NOT_REACHED();
  288. }
  289. asm volatile(
  290. "pushf\n"
  291. "pop %%ebx"
  292. : "=b"(new_flags));
  293. cpu.set_flags_oszapc(new_flags);
  294. return result;
  295. }
  296. template<typename T>
  297. static T op_add(SoftCPU& cpu, T& dest, const T& src)
  298. {
  299. T result = 0;
  300. u32 new_flags = 0;
  301. if constexpr (sizeof(T) == 4) {
  302. asm volatile("addl %%ecx, %%eax\n"
  303. : "=a"(result)
  304. : "a"(dest), "c"((u32)src));
  305. } else if constexpr (sizeof(T) == 2) {
  306. asm volatile("addw %%cx, %%ax\n"
  307. : "=a"(result)
  308. : "a"(dest), "c"((u16)src));
  309. } else if constexpr (sizeof(T) == 1) {
  310. asm volatile("addb %%cl, %%al\n"
  311. : "=a"(result)
  312. : "a"(dest), "c"((u8)src));
  313. } else {
  314. ASSERT_NOT_REACHED();
  315. }
  316. asm volatile(
  317. "pushf\n"
  318. "pop %%ebx"
  319. : "=b"(new_flags));
  320. cpu.set_flags_oszapc(new_flags);
  321. return result;
  322. }
  323. template<typename T>
  324. static T op_and(SoftCPU& cpu, const T& dest, const T& src)
  325. {
  326. T result = 0;
  327. u32 new_flags = 0;
  328. if constexpr (sizeof(T) == 4) {
  329. asm volatile("andl %%ecx, %%eax\n"
  330. : "=a"(result)
  331. : "a"(dest), "c"((u32)src));
  332. } else if constexpr (sizeof(T) == 2) {
  333. asm volatile("andw %%cx, %%ax\n"
  334. : "=a"(result)
  335. : "a"(dest), "c"((u16)src));
  336. } else if constexpr (sizeof(T) == 1) {
  337. asm volatile("andb %%cl, %%al\n"
  338. : "=a"(result)
  339. : "a"(dest), "c"((u8)src));
  340. } else {
  341. ASSERT_NOT_REACHED();
  342. }
  343. asm volatile(
  344. "pushf\n"
  345. "pop %%ebx"
  346. : "=b"(new_flags));
  347. cpu.set_flags_oszpc(new_flags);
  348. return result;
  349. }
  350. template<typename T>
  351. static T op_imul(SoftCPU& cpu, const T& dest, const T& src)
  352. {
  353. T result = 0;
  354. u32 new_flags = 0;
  355. if constexpr (sizeof(T) == 4) {
  356. asm volatile("imull %%ecx, %%eax\n"
  357. : "=a"(result)
  358. : "a"(dest), "c"((i32)src));
  359. } else if constexpr (sizeof(T) == 2) {
  360. asm volatile("imulw %%cx, %%ax\n"
  361. : "=a"(result)
  362. : "a"(dest), "c"((i16)src));
  363. } else {
  364. ASSERT_NOT_REACHED();
  365. }
  366. asm volatile(
  367. "pushf\n"
  368. "pop %%ebx"
  369. : "=b"(new_flags));
  370. cpu.set_flags_oszapc(new_flags);
  371. return result;
  372. }
  373. template<typename T>
  374. static T op_shr(SoftCPU& cpu, T data, u8 steps)
  375. {
  376. if (steps == 0)
  377. return data;
  378. u32 result = 0;
  379. u32 new_flags = 0;
  380. if constexpr (sizeof(T) == 4)
  381. asm volatile("shrl %%cl, %%eax\n" ::"a"(data), "c"(steps));
  382. else if constexpr (sizeof(T) == 2)
  383. asm volatile("shrw %%cl, %%ax\n" ::"a"(data), "c"(steps));
  384. else if constexpr (sizeof(T) == 1)
  385. asm volatile("shrb %%cl, %%al\n" ::"a"(data), "c"(steps));
  386. asm volatile(
  387. "mov %%eax, %%ebx\n"
  388. : "=b"(result));
  389. asm volatile(
  390. "pushf\n"
  391. "pop %%eax"
  392. : "=a"(new_flags));
  393. cpu.set_flags_oszapc(new_flags);
  394. return result;
  395. }
  396. template<typename T>
  397. static T op_shl(SoftCPU& cpu, T data, u8 steps)
  398. {
  399. if (steps == 0)
  400. return data;
  401. u32 result = 0;
  402. u32 new_flags = 0;
  403. if constexpr (sizeof(T) == 4)
  404. asm volatile("shll %%cl, %%eax\n" ::"a"(data), "c"(steps));
  405. else if constexpr (sizeof(T) == 2)
  406. asm volatile("shlw %%cl, %%ax\n" ::"a"(data), "c"(steps));
  407. else if constexpr (sizeof(T) == 1)
  408. asm volatile("shlb %%cl, %%al\n" ::"a"(data), "c"(steps));
  409. asm volatile(
  410. "mov %%eax, %%ebx\n"
  411. : "=b"(result));
  412. asm volatile(
  413. "pushf\n"
  414. "pop %%eax"
  415. : "=a"(new_flags));
  416. cpu.set_flags_oszapc(new_flags);
  417. return result;
  418. }
  419. template<bool update_dest, typename Op>
  420. void SoftCPU::generic_AL_imm8(Op op, const X86::Instruction& insn)
  421. {
  422. auto dest = al();
  423. auto src = insn.imm8();
  424. auto result = op(*this, dest, src);
  425. if (update_dest)
  426. set_al(result);
  427. }
  428. template<bool update_dest, typename Op>
  429. void SoftCPU::generic_AX_imm16(Op op, const X86::Instruction& insn)
  430. {
  431. auto dest = ax();
  432. auto src = insn.imm16();
  433. auto result = op(*this, dest, src);
  434. if (update_dest)
  435. set_ax(result);
  436. }
  437. template<bool update_dest, typename Op>
  438. void SoftCPU::generic_EAX_imm32(Op op, const X86::Instruction& insn)
  439. {
  440. auto dest = eax();
  441. auto src = insn.imm32();
  442. auto result = op(*this, dest, src);
  443. if (update_dest)
  444. set_eax(result);
  445. }
  446. template<bool update_dest, typename Op>
  447. void SoftCPU::generic_RM16_imm16(Op op, const X86::Instruction& insn)
  448. {
  449. auto dest = insn.modrm().read16(*this, insn);
  450. auto src = insn.imm16();
  451. auto result = op(*this, dest, src);
  452. if (update_dest)
  453. insn.modrm().write16(*this, insn, result);
  454. }
  455. template<bool update_dest, typename Op>
  456. void SoftCPU::generic_RM16_imm8(Op op, const X86::Instruction& insn)
  457. {
  458. auto dest = insn.modrm().read16(*this, insn);
  459. auto src = sign_extended_to<u16>(insn.imm8());
  460. auto result = op(*this, dest, src);
  461. if (update_dest)
  462. insn.modrm().write16(*this, insn, result);
  463. }
  464. template<bool update_dest, typename Op>
  465. void SoftCPU::generic_RM16_reg16(Op op, const X86::Instruction& insn)
  466. {
  467. auto dest = insn.modrm().read16(*this, insn);
  468. auto src = gpr16(insn.reg16());
  469. auto result = op(*this, dest, src);
  470. if (update_dest)
  471. insn.modrm().write16(*this, insn, result);
  472. }
  473. template<bool update_dest, typename Op>
  474. void SoftCPU::generic_RM32_imm32(Op op, const X86::Instruction& insn)
  475. {
  476. auto dest = insn.modrm().read32(*this, insn);
  477. auto src = insn.imm32();
  478. auto result = op(*this, dest, src);
  479. if (update_dest)
  480. insn.modrm().write32(*this, insn, result);
  481. }
  482. template<bool update_dest, typename Op>
  483. void SoftCPU::generic_RM32_imm8(Op op, const X86::Instruction& insn)
  484. {
  485. auto dest = insn.modrm().read32(*this, insn);
  486. auto src = sign_extended_to<u32>(insn.imm8());
  487. auto result = op(*this, dest, src);
  488. if (update_dest)
  489. insn.modrm().write32(*this, insn, result);
  490. }
  491. template<bool update_dest, typename Op>
  492. void SoftCPU::generic_RM32_reg32(Op op, const X86::Instruction& insn)
  493. {
  494. auto dest = insn.modrm().read32(*this, insn);
  495. auto src = gpr32(insn.reg32());
  496. auto result = op(*this, dest, src);
  497. if (update_dest)
  498. insn.modrm().write32(*this, insn, result);
  499. }
  500. template<bool update_dest, typename Op>
  501. void SoftCPU::generic_RM8_imm8(Op op, const X86::Instruction& insn)
  502. {
  503. auto dest = insn.modrm().read8(*this, insn);
  504. auto src = insn.imm8();
  505. auto result = op(*this, dest, src);
  506. if (update_dest)
  507. insn.modrm().write8(*this, insn, result);
  508. }
  509. template<bool update_dest, typename Op>
  510. void SoftCPU::generic_RM8_reg8(Op op, const X86::Instruction& insn)
  511. {
  512. auto dest = insn.modrm().read8(*this, insn);
  513. auto src = gpr8(insn.reg8());
  514. auto result = op(*this, dest, src);
  515. if (update_dest)
  516. insn.modrm().write8(*this, insn, result);
  517. }
  518. template<bool update_dest, typename Op>
  519. void SoftCPU::generic_reg16_RM16(Op op, const X86::Instruction& insn)
  520. {
  521. auto dest = gpr16(insn.reg16());
  522. auto src = insn.modrm().read16(*this, insn);
  523. auto result = op(*this, dest, src);
  524. if (update_dest)
  525. gpr16(insn.reg16()) = result;
  526. }
  527. template<bool update_dest, typename Op>
  528. void SoftCPU::generic_reg32_RM32(Op op, const X86::Instruction& insn)
  529. {
  530. auto dest = gpr32(insn.reg32());
  531. auto src = insn.modrm().read32(*this, insn);
  532. auto result = op(*this, dest, src);
  533. if (update_dest)
  534. gpr32(insn.reg32()) = result;
  535. }
  536. template<bool update_dest, typename Op>
  537. void SoftCPU::generic_reg8_RM8(Op op, const X86::Instruction& insn)
  538. {
  539. auto dest = gpr8(insn.reg8());
  540. auto src = insn.modrm().read8(*this, insn);
  541. auto result = op(*this, dest, src);
  542. if (update_dest)
  543. gpr8(insn.reg8()) = result;
  544. }
  545. void SoftCPU::AAA(const X86::Instruction&) { TODO(); }
  546. void SoftCPU::AAD(const X86::Instruction&) { TODO(); }
  547. void SoftCPU::AAM(const X86::Instruction&) { TODO(); }
  548. void SoftCPU::AAS(const X86::Instruction&) { TODO(); }
  549. void SoftCPU::ADC_AL_imm8(const X86::Instruction&) { TODO(); }
  550. void SoftCPU::ADC_AX_imm16(const X86::Instruction&) { TODO(); }
  551. void SoftCPU::ADC_EAX_imm32(const X86::Instruction&) { TODO(); }
  552. void SoftCPU::ADC_RM16_imm16(const X86::Instruction&) { TODO(); }
  553. void SoftCPU::ADC_RM16_imm8(const X86::Instruction&) { TODO(); }
  554. void SoftCPU::ADC_RM16_reg16(const X86::Instruction&) { TODO(); }
  555. void SoftCPU::ADC_RM32_imm32(const X86::Instruction&) { TODO(); }
  556. void SoftCPU::ADC_RM32_imm8(const X86::Instruction&) { TODO(); }
  557. void SoftCPU::ADC_RM32_reg32(const X86::Instruction&) { TODO(); }
  558. void SoftCPU::ADC_RM8_imm8(const X86::Instruction&) { TODO(); }
  559. void SoftCPU::ADC_RM8_reg8(const X86::Instruction&) { TODO(); }
  560. void SoftCPU::ADC_reg16_RM16(const X86::Instruction&) { TODO(); }
  561. void SoftCPU::ADC_reg32_RM32(const X86::Instruction&) { TODO(); }
  562. void SoftCPU::ADC_reg8_RM8(const X86::Instruction&) { TODO(); }
  563. void SoftCPU::ARPL(const X86::Instruction&) { TODO(); }
  564. void SoftCPU::BOUND(const X86::Instruction&) { TODO(); }
  565. void SoftCPU::BSF_reg16_RM16(const X86::Instruction&) { TODO(); }
  566. void SoftCPU::BSF_reg32_RM32(const X86::Instruction&) { TODO(); }
  567. void SoftCPU::BSR_reg16_RM16(const X86::Instruction&) { TODO(); }
  568. void SoftCPU::BSR_reg32_RM32(const X86::Instruction&) { TODO(); }
  569. void SoftCPU::BSWAP_reg32(const X86::Instruction&) { TODO(); }
  570. void SoftCPU::BTC_RM16_imm8(const X86::Instruction&) { TODO(); }
  571. void SoftCPU::BTC_RM16_reg16(const X86::Instruction&) { TODO(); }
  572. void SoftCPU::BTC_RM32_imm8(const X86::Instruction&) { TODO(); }
  573. void SoftCPU::BTC_RM32_reg32(const X86::Instruction&) { TODO(); }
  574. void SoftCPU::BTR_RM16_imm8(const X86::Instruction&) { TODO(); }
  575. void SoftCPU::BTR_RM16_reg16(const X86::Instruction&) { TODO(); }
  576. void SoftCPU::BTR_RM32_imm8(const X86::Instruction&) { TODO(); }
  577. void SoftCPU::BTR_RM32_reg32(const X86::Instruction&) { TODO(); }
  578. void SoftCPU::BTS_RM16_imm8(const X86::Instruction&) { TODO(); }
  579. void SoftCPU::BTS_RM16_reg16(const X86::Instruction&) { TODO(); }
  580. void SoftCPU::BTS_RM32_imm8(const X86::Instruction&) { TODO(); }
  581. void SoftCPU::BTS_RM32_reg32(const X86::Instruction&) { TODO(); }
  582. void SoftCPU::BT_RM16_imm8(const X86::Instruction&) { TODO(); }
  583. void SoftCPU::BT_RM16_reg16(const X86::Instruction&) { TODO(); }
  584. void SoftCPU::BT_RM32_imm8(const X86::Instruction&) { TODO(); }
  585. void SoftCPU::BT_RM32_reg32(const X86::Instruction&) { TODO(); }
  586. void SoftCPU::CALL_FAR_mem16(const X86::Instruction&) { TODO(); }
  587. void SoftCPU::CALL_FAR_mem32(const X86::Instruction&) { TODO(); }
  588. void SoftCPU::CALL_RM16(const X86::Instruction&) { TODO(); }
  589. void SoftCPU::CALL_RM32(const X86::Instruction& insn)
  590. {
  591. push32(eip());
  592. set_eip(insn.modrm().read32(*this, insn));
  593. }
  594. void SoftCPU::CALL_imm16(const X86::Instruction&) { TODO(); }
  595. void SoftCPU::CALL_imm16_imm16(const X86::Instruction&) { TODO(); }
  596. void SoftCPU::CALL_imm16_imm32(const X86::Instruction&) { TODO(); }
  597. void SoftCPU::CALL_imm32(const X86::Instruction& insn)
  598. {
  599. push32(eip());
  600. set_eip(eip() + (i32)insn.imm32());
  601. }
  602. void SoftCPU::CBW(const X86::Instruction&) { TODO(); }
  603. void SoftCPU::CDQ(const X86::Instruction&) { TODO(); }
  604. void SoftCPU::CLC(const X86::Instruction&) { TODO(); }
  605. void SoftCPU::CLD(const X86::Instruction&) { TODO(); }
  606. void SoftCPU::CLI(const X86::Instruction&) { TODO(); }
  607. void SoftCPU::CLTS(const X86::Instruction&) { TODO(); }
  608. void SoftCPU::CMC(const X86::Instruction&) { TODO(); }
  609. void SoftCPU::CMOVcc_reg16_RM16(const X86::Instruction&) { TODO(); }
  610. void SoftCPU::CMOVcc_reg32_RM32(const X86::Instruction&) { TODO(); }
  611. void SoftCPU::CMPSB(const X86::Instruction&) { TODO(); }
  612. void SoftCPU::CMPSD(const X86::Instruction&) { TODO(); }
  613. void SoftCPU::CMPSW(const X86::Instruction&) { TODO(); }
  614. void SoftCPU::CMPXCHG_RM16_reg16(const X86::Instruction&) { TODO(); }
  615. void SoftCPU::CMPXCHG_RM32_reg32(const X86::Instruction&) { TODO(); }
  616. void SoftCPU::CMPXCHG_RM8_reg8(const X86::Instruction&) { TODO(); }
  617. void SoftCPU::CPUID(const X86::Instruction&) { TODO(); }
  618. void SoftCPU::CWD(const X86::Instruction&) { TODO(); }
  619. void SoftCPU::CWDE(const X86::Instruction&) { TODO(); }
  620. void SoftCPU::DAA(const X86::Instruction&) { TODO(); }
  621. void SoftCPU::DAS(const X86::Instruction&) { TODO(); }
  622. void SoftCPU::DEC_RM16(const X86::Instruction& insn)
  623. {
  624. insn.modrm().write16(*this, insn, op_dec(*this, insn.modrm().read16(*this, insn)));
  625. }
  626. void SoftCPU::DEC_RM32(const X86::Instruction& insn)
  627. {
  628. insn.modrm().write32(*this, insn, op_dec(*this, insn.modrm().read32(*this, insn)));
  629. }
  630. void SoftCPU::DEC_RM8(const X86::Instruction& insn)
  631. {
  632. insn.modrm().write8(*this, insn, op_dec(*this, insn.modrm().read8(*this, insn)));
  633. }
  634. void SoftCPU::DEC_reg16(const X86::Instruction& insn)
  635. {
  636. gpr16(insn.reg16()) = op_dec(*this, gpr16(insn.reg16()));
  637. }
  638. void SoftCPU::DEC_reg32(const X86::Instruction& insn)
  639. {
  640. gpr32(insn.reg32()) = op_dec(*this, gpr32(insn.reg32()));
  641. }
  642. void SoftCPU::DIV_RM16(const X86::Instruction&) { TODO(); }
  643. void SoftCPU::DIV_RM32(const X86::Instruction&) { TODO(); }
  644. void SoftCPU::DIV_RM8(const X86::Instruction&) { TODO(); }
  645. void SoftCPU::ENTER16(const X86::Instruction&) { TODO(); }
  646. void SoftCPU::ENTER32(const X86::Instruction&) { TODO(); }
  647. void SoftCPU::ESCAPE(const X86::Instruction&) { TODO(); }
  648. void SoftCPU::HLT(const X86::Instruction&) { TODO(); }
  649. void SoftCPU::IDIV_RM16(const X86::Instruction&) { TODO(); }
  650. void SoftCPU::IDIV_RM32(const X86::Instruction&) { TODO(); }
  651. void SoftCPU::IDIV_RM8(const X86::Instruction&) { TODO(); }
  652. void SoftCPU::IMUL_RM16(const X86::Instruction&) { TODO(); }
  653. void SoftCPU::IMUL_RM32(const X86::Instruction&) { TODO(); }
  654. void SoftCPU::IMUL_RM8(const X86::Instruction&) { TODO(); }
  655. void SoftCPU::IMUL_reg16_RM16(const X86::Instruction& insn)
  656. {
  657. gpr16(insn.reg16()) = op_imul<i16>(*this, gpr16(insn.reg16()), insn.modrm().read16(*this, insn));
  658. }
  659. void SoftCPU::IMUL_reg16_RM16_imm16(const X86::Instruction& insn)
  660. {
  661. gpr16(insn.reg16()) = op_imul<i16>(*this, insn.modrm().read16(*this, insn), insn.imm16());
  662. }
  663. void SoftCPU::IMUL_reg16_RM16_imm8(const X86::Instruction& insn)
  664. {
  665. gpr16(insn.reg16()) = op_imul<i16>(*this, insn.modrm().read16(*this, insn), sign_extended_to<i16>(insn.imm8()));
  666. }
  667. void SoftCPU::IMUL_reg32_RM32(const X86::Instruction& insn)
  668. {
  669. gpr32(insn.reg32()) = op_imul<i32>(*this, gpr32(insn.reg32()), insn.modrm().read32(*this, insn));
  670. }
  671. void SoftCPU::IMUL_reg32_RM32_imm32(const X86::Instruction& insn)
  672. {
  673. gpr32(insn.reg32()) = op_imul<i32>(*this, insn.modrm().read32(*this, insn), insn.imm32());
  674. }
  675. void SoftCPU::IMUL_reg32_RM32_imm8(const X86::Instruction& insn)
  676. {
  677. gpr32(insn.reg32()) = op_imul<i32>(*this, insn.modrm().read32(*this, insn), sign_extended_to<i32>(insn.imm8()));
  678. }
  679. void SoftCPU::INC_RM16(const X86::Instruction& insn)
  680. {
  681. insn.modrm().write16(*this, insn, op_inc(*this, insn.modrm().read16(*this, insn)));
  682. }
  683. void SoftCPU::INC_RM32(const X86::Instruction& insn)
  684. {
  685. insn.modrm().write32(*this, insn, op_inc(*this, insn.modrm().read32(*this, insn)));
  686. }
  687. void SoftCPU::INC_RM8(const X86::Instruction& insn)
  688. {
  689. insn.modrm().write8(*this, insn, op_inc(*this, insn.modrm().read8(*this, insn)));
  690. }
  691. void SoftCPU::INC_reg16(const X86::Instruction& insn)
  692. {
  693. gpr16(insn.reg16()) = op_inc(*this, gpr16(insn.reg16()));
  694. }
  695. void SoftCPU::INC_reg32(const X86::Instruction& insn)
  696. {
  697. gpr32(insn.reg32()) = op_inc(*this, gpr32(insn.reg32()));
  698. }
  699. void SoftCPU::INSB(const X86::Instruction&) { TODO(); }
  700. void SoftCPU::INSD(const X86::Instruction&) { TODO(); }
  701. void SoftCPU::INSW(const X86::Instruction&) { TODO(); }
  702. void SoftCPU::INT3(const X86::Instruction&) { TODO(); }
  703. void SoftCPU::INTO(const X86::Instruction&) { TODO(); }
  704. void SoftCPU::INT_imm8(const X86::Instruction& insn)
  705. {
  706. ASSERT(insn.imm8() == 0x82);
  707. set_eax(m_emulator.virt_syscall(eax(), edx(), ecx(), ebx()));
  708. }
  709. void SoftCPU::INVLPG(const X86::Instruction&) { TODO(); }
  710. void SoftCPU::IN_AL_DX(const X86::Instruction&) { TODO(); }
  711. void SoftCPU::IN_AL_imm8(const X86::Instruction&) { TODO(); }
  712. void SoftCPU::IN_AX_DX(const X86::Instruction&) { TODO(); }
  713. void SoftCPU::IN_AX_imm8(const X86::Instruction&) { TODO(); }
  714. void SoftCPU::IN_EAX_DX(const X86::Instruction&) { TODO(); }
  715. void SoftCPU::IN_EAX_imm8(const X86::Instruction&) { TODO(); }
  716. void SoftCPU::IRET(const X86::Instruction&) { TODO(); }
  717. void SoftCPU::JCXZ_imm8(const X86::Instruction&) { TODO(); }
  718. void SoftCPU::JMP_FAR_mem16(const X86::Instruction&) { TODO(); }
  719. void SoftCPU::JMP_FAR_mem32(const X86::Instruction&) { TODO(); }
  720. void SoftCPU::JMP_RM16(const X86::Instruction&) { TODO(); }
  721. void SoftCPU::JMP_RM32(const X86::Instruction&) { TODO(); }
  722. void SoftCPU::JMP_imm16(const X86::Instruction& insn)
  723. {
  724. set_eip(eip() + (i16)insn.imm16());
  725. }
  726. void SoftCPU::JMP_imm16_imm16(const X86::Instruction&) { TODO(); }
  727. void SoftCPU::JMP_imm16_imm32(const X86::Instruction&) { TODO(); }
  728. void SoftCPU::JMP_imm32(const X86::Instruction& insn)
  729. {
  730. set_eip(eip() + (i32)insn.imm32());
  731. }
  732. void SoftCPU::JMP_short_imm8(const X86::Instruction& insn)
  733. {
  734. set_eip(eip() + (i8)insn.imm8());
  735. }
  736. void SoftCPU::Jcc_NEAR_imm(const X86::Instruction&) { TODO(); }
  737. void SoftCPU::Jcc_imm8(const X86::Instruction& insn)
  738. {
  739. if (evaluate_condition(insn.cc()))
  740. set_eip(eip() + (i8)insn.imm8());
  741. }
  742. void SoftCPU::LAHF(const X86::Instruction&) { TODO(); }
  743. void SoftCPU::LAR_reg16_RM16(const X86::Instruction&) { TODO(); }
  744. void SoftCPU::LAR_reg32_RM32(const X86::Instruction&) { TODO(); }
  745. void SoftCPU::LDS_reg16_mem16(const X86::Instruction&) { TODO(); }
  746. void SoftCPU::LDS_reg32_mem32(const X86::Instruction&) { TODO(); }
  747. void SoftCPU::LEAVE16(const X86::Instruction&) { TODO(); }
  748. void SoftCPU::LEAVE32(const X86::Instruction&)
  749. {
  750. u32 new_ebp = read_memory32({ ss(), ebp() });
  751. set_esp(ebp() + 4);
  752. set_ebp(new_ebp);
  753. }
  754. void SoftCPU::LEA_reg16_mem16(const X86::Instruction& insn)
  755. {
  756. gpr16(insn.reg16()) = insn.modrm().resolve(*this, insn.segment_prefix()).offset();
  757. }
  758. void SoftCPU::LEA_reg32_mem32(const X86::Instruction& insn)
  759. {
  760. gpr32(insn.reg32()) = insn.modrm().resolve(*this, insn.segment_prefix()).offset();
  761. }
  762. void SoftCPU::LES_reg16_mem16(const X86::Instruction&) { TODO(); }
  763. void SoftCPU::LES_reg32_mem32(const X86::Instruction&) { TODO(); }
  764. void SoftCPU::LFS_reg16_mem16(const X86::Instruction&) { TODO(); }
  765. void SoftCPU::LFS_reg32_mem32(const X86::Instruction&) { TODO(); }
  766. void SoftCPU::LGDT(const X86::Instruction&) { TODO(); }
  767. void SoftCPU::LGS_reg16_mem16(const X86::Instruction&) { TODO(); }
  768. void SoftCPU::LGS_reg32_mem32(const X86::Instruction&) { TODO(); }
  769. void SoftCPU::LIDT(const X86::Instruction&) { TODO(); }
  770. void SoftCPU::LLDT_RM16(const X86::Instruction&) { TODO(); }
  771. void SoftCPU::LMSW_RM16(const X86::Instruction&) { TODO(); }
  772. void SoftCPU::LODSB(const X86::Instruction&) { TODO(); }
  773. void SoftCPU::LODSD(const X86::Instruction&) { TODO(); }
  774. void SoftCPU::LODSW(const X86::Instruction&) { TODO(); }
  775. void SoftCPU::LOOPNZ_imm8(const X86::Instruction&) { TODO(); }
  776. void SoftCPU::LOOPZ_imm8(const X86::Instruction&) { TODO(); }
  777. void SoftCPU::LOOP_imm8(const X86::Instruction&) { TODO(); }
  778. void SoftCPU::LSL_reg16_RM16(const X86::Instruction&) { TODO(); }
  779. void SoftCPU::LSL_reg32_RM32(const X86::Instruction&) { TODO(); }
  780. void SoftCPU::LSS_reg16_mem16(const X86::Instruction&) { TODO(); }
  781. void SoftCPU::LSS_reg32_mem32(const X86::Instruction&) { TODO(); }
  782. void SoftCPU::LTR_RM16(const X86::Instruction&) { TODO(); }
  783. void SoftCPU::MOVSB(const X86::Instruction&) { TODO(); }
  784. void SoftCPU::MOVSD(const X86::Instruction&) { TODO(); }
  785. void SoftCPU::MOVSW(const X86::Instruction&) { TODO(); }
  786. void SoftCPU::MOVSX_reg16_RM8(const X86::Instruction&) { TODO(); }
  787. void SoftCPU::MOVSX_reg32_RM16(const X86::Instruction&) { TODO(); }
  788. void SoftCPU::MOVSX_reg32_RM8(const X86::Instruction&) { TODO(); }
  789. void SoftCPU::MOVZX_reg16_RM8(const X86::Instruction& insn)
  790. {
  791. gpr16(insn.reg16()) = insn.modrm().read8(*this, insn);
  792. }
  793. void SoftCPU::MOVZX_reg32_RM16(const X86::Instruction& insn)
  794. {
  795. gpr32(insn.reg32()) = insn.modrm().read16(*this, insn);
  796. }
  797. void SoftCPU::MOVZX_reg32_RM8(const X86::Instruction& insn)
  798. {
  799. gpr32(insn.reg32()) = insn.modrm().read8(*this, insn);
  800. }
  801. void SoftCPU::MOV_AL_moff8(const X86::Instruction&) { TODO(); }
  802. void SoftCPU::MOV_AX_moff16(const X86::Instruction&) { TODO(); }
  803. void SoftCPU::MOV_CR_reg32(const X86::Instruction&) { TODO(); }
  804. void SoftCPU::MOV_DR_reg32(const X86::Instruction&) { TODO(); }
  805. void SoftCPU::MOV_EAX_moff32(const X86::Instruction& insn)
  806. {
  807. set_eax(read_memory32({ segment(insn.segment_prefix().value_or(X86::SegmentRegister::DS)), insn.imm_address() }));
  808. }
  809. void SoftCPU::MOV_RM16_imm16(const X86::Instruction& insn)
  810. {
  811. insn.modrm().write16(*this, insn, insn.imm16());
  812. }
  813. void SoftCPU::MOV_RM16_reg16(const X86::Instruction& insn)
  814. {
  815. insn.modrm().write16(*this, insn, gpr16(insn.reg16()));
  816. }
  817. void SoftCPU::MOV_RM16_seg(const X86::Instruction&) { TODO(); }
  818. void SoftCPU::MOV_RM32_imm32(const X86::Instruction& insn)
  819. {
  820. insn.modrm().write32(*this, insn, insn.imm32());
  821. }
  822. void SoftCPU::MOV_RM32_reg32(const X86::Instruction& insn)
  823. {
  824. insn.modrm().write32(*this, insn, gpr32(insn.reg32()));
  825. }
  826. void SoftCPU::MOV_RM8_imm8(const X86::Instruction& insn)
  827. {
  828. insn.modrm().write8(*this, insn, insn.imm8());
  829. }
  830. void SoftCPU::MOV_RM8_reg8(const X86::Instruction& insn)
  831. {
  832. insn.modrm().write8(*this, insn, insn.modrm().read8(*this, insn));
  833. }
  834. void SoftCPU::MOV_moff16_AX(const X86::Instruction&) { TODO(); }
  835. void SoftCPU::MOV_moff32_EAX(const X86::Instruction&) { TODO(); }
  836. void SoftCPU::MOV_moff8_AL(const X86::Instruction&) { TODO(); }
  837. void SoftCPU::MOV_reg16_RM16(const X86::Instruction& insn)
  838. {
  839. gpr16(insn.reg16()) = insn.modrm().read16(*this, insn);
  840. }
  841. void SoftCPU::MOV_reg16_imm16(const X86::Instruction& insn)
  842. {
  843. gpr16(insn.reg16()) = insn.imm16();
  844. }
  845. void SoftCPU::MOV_reg32_CR(const X86::Instruction&) { TODO(); }
  846. void SoftCPU::MOV_reg32_DR(const X86::Instruction&) { TODO(); }
  847. void SoftCPU::MOV_reg32_RM32(const X86::Instruction& insn)
  848. {
  849. gpr32(insn.reg32()) = insn.modrm().read32(*this, insn);
  850. }
  851. void SoftCPU::MOV_reg32_imm32(const X86::Instruction& insn)
  852. {
  853. gpr32(insn.reg32()) = insn.imm32();
  854. }
  855. void SoftCPU::MOV_reg8_RM8(const X86::Instruction& insn)
  856. {
  857. gpr8(insn.reg8()) = insn.modrm().read8(*this, insn);
  858. }
  859. void SoftCPU::MOV_reg8_imm8(const X86::Instruction& insn)
  860. {
  861. gpr8(insn.reg8()) = insn.imm8();
  862. }
  863. void SoftCPU::MOV_seg_RM16(const X86::Instruction&) { TODO(); }
  864. void SoftCPU::MOV_seg_RM32(const X86::Instruction&) { TODO(); }
  865. void SoftCPU::MUL_RM16(const X86::Instruction&) { TODO(); }
  866. void SoftCPU::MUL_RM32(const X86::Instruction&) { TODO(); }
  867. void SoftCPU::MUL_RM8(const X86::Instruction&) { TODO(); }
  868. void SoftCPU::NEG_RM16(const X86::Instruction& insn)
  869. {
  870. insn.modrm().write16(*this, insn, op_sub<u16>(*this, 0, insn.modrm().read16(*this, insn)));
  871. }
  872. void SoftCPU::NEG_RM32(const X86::Instruction& insn)
  873. {
  874. insn.modrm().write32(*this, insn, op_sub<u32>(*this, 0, insn.modrm().read32(*this, insn)));
  875. }
  876. void SoftCPU::NEG_RM8(const X86::Instruction& insn)
  877. {
  878. insn.modrm().write8(*this, insn, op_sub<u8>(*this, 0, insn.modrm().read8(*this, insn)));
  879. }
  880. void SoftCPU::NOP(const X86::Instruction&) { TODO(); }
  881. void SoftCPU::NOT_RM16(const X86::Instruction&) { TODO(); }
  882. void SoftCPU::NOT_RM32(const X86::Instruction&) { TODO(); }
  883. void SoftCPU::NOT_RM8(const X86::Instruction&) { TODO(); }
  884. void SoftCPU::OUTSB(const X86::Instruction&) { TODO(); }
  885. void SoftCPU::OUTSD(const X86::Instruction&) { TODO(); }
  886. void SoftCPU::OUTSW(const X86::Instruction&) { TODO(); }
  887. void SoftCPU::OUT_DX_AL(const X86::Instruction&) { TODO(); }
  888. void SoftCPU::OUT_DX_AX(const X86::Instruction&) { TODO(); }
  889. void SoftCPU::OUT_DX_EAX(const X86::Instruction&) { TODO(); }
  890. void SoftCPU::OUT_imm8_AL(const X86::Instruction&) { TODO(); }
  891. void SoftCPU::OUT_imm8_AX(const X86::Instruction&) { TODO(); }
  892. void SoftCPU::OUT_imm8_EAX(const X86::Instruction&) { TODO(); }
  893. void SoftCPU::PADDB_mm1_mm2m64(const X86::Instruction&) { TODO(); }
  894. void SoftCPU::PADDW_mm1_mm2m64(const X86::Instruction&) { TODO(); }
  895. void SoftCPU::PADDD_mm1_mm2m64(const X86::Instruction&) { TODO(); }
  896. void SoftCPU::POPA(const X86::Instruction&) { TODO(); }
  897. void SoftCPU::POPAD(const X86::Instruction&) { TODO(); }
  898. void SoftCPU::POPF(const X86::Instruction&) { TODO(); }
  899. void SoftCPU::POPFD(const X86::Instruction&) { TODO(); }
  900. void SoftCPU::POP_DS(const X86::Instruction&) { TODO(); }
  901. void SoftCPU::POP_ES(const X86::Instruction&) { TODO(); }
  902. void SoftCPU::POP_FS(const X86::Instruction&) { TODO(); }
  903. void SoftCPU::POP_GS(const X86::Instruction&) { TODO(); }
  904. void SoftCPU::POP_RM16(const X86::Instruction&) { TODO(); }
  905. void SoftCPU::POP_RM32(const X86::Instruction&) { TODO(); }
  906. void SoftCPU::POP_SS(const X86::Instruction&) { TODO(); }
  907. void SoftCPU::POP_reg16(const X86::Instruction&) { TODO(); }
  908. void SoftCPU::POP_reg32(const X86::Instruction& insn)
  909. {
  910. gpr32(insn.reg32()) = pop32();
  911. }
  912. void SoftCPU::PUSHA(const X86::Instruction&) { TODO(); }
  913. void SoftCPU::PUSHAD(const X86::Instruction&) { TODO(); }
  914. void SoftCPU::PUSHF(const X86::Instruction&) { TODO(); }
  915. void SoftCPU::PUSHFD(const X86::Instruction&) { TODO(); }
  916. void SoftCPU::PUSH_CS(const X86::Instruction&) { TODO(); }
  917. void SoftCPU::PUSH_DS(const X86::Instruction&) { TODO(); }
  918. void SoftCPU::PUSH_ES(const X86::Instruction&) { TODO(); }
  919. void SoftCPU::PUSH_FS(const X86::Instruction&) { TODO(); }
  920. void SoftCPU::PUSH_GS(const X86::Instruction&) { TODO(); }
  921. void SoftCPU::PUSH_RM16(const X86::Instruction&) { TODO(); }
  922. void SoftCPU::PUSH_RM32(const X86::Instruction& insn)
  923. {
  924. push32(insn.modrm().read32(*this, insn));
  925. }
  926. void SoftCPU::PUSH_SP_8086_80186(const X86::Instruction&) { TODO(); }
  927. void SoftCPU::PUSH_SS(const X86::Instruction&) { TODO(); }
  928. void SoftCPU::PUSH_imm16(const X86::Instruction&) { TODO(); }
  929. void SoftCPU::PUSH_imm32(const X86::Instruction& insn)
  930. {
  931. push32(insn.imm32());
  932. }
  933. void SoftCPU::PUSH_imm8(const X86::Instruction& insn)
  934. {
  935. ASSERT(!insn.has_operand_size_override_prefix());
  936. push32((i32)insn.imm8());
  937. }
  938. void SoftCPU::PUSH_reg16(const X86::Instruction&) { TODO(); }
  939. void SoftCPU::PUSH_reg32(const X86::Instruction& insn)
  940. {
  941. push32(gpr32(insn.reg32()));
  942. }
  943. void SoftCPU::RCL_RM16_1(const X86::Instruction&) { TODO(); }
  944. void SoftCPU::RCL_RM16_CL(const X86::Instruction&) { TODO(); }
  945. void SoftCPU::RCL_RM16_imm8(const X86::Instruction&) { TODO(); }
  946. void SoftCPU::RCL_RM32_1(const X86::Instruction&) { TODO(); }
  947. void SoftCPU::RCL_RM32_CL(const X86::Instruction&) { TODO(); }
  948. void SoftCPU::RCL_RM32_imm8(const X86::Instruction&) { TODO(); }
  949. void SoftCPU::RCL_RM8_1(const X86::Instruction&) { TODO(); }
  950. void SoftCPU::RCL_RM8_CL(const X86::Instruction&) { TODO(); }
  951. void SoftCPU::RCL_RM8_imm8(const X86::Instruction&) { TODO(); }
  952. void SoftCPU::RCR_RM16_1(const X86::Instruction&) { TODO(); }
  953. void SoftCPU::RCR_RM16_CL(const X86::Instruction&) { TODO(); }
  954. void SoftCPU::RCR_RM16_imm8(const X86::Instruction&) { TODO(); }
  955. void SoftCPU::RCR_RM32_1(const X86::Instruction&) { TODO(); }
  956. void SoftCPU::RCR_RM32_CL(const X86::Instruction&) { TODO(); }
  957. void SoftCPU::RCR_RM32_imm8(const X86::Instruction&) { TODO(); }
  958. void SoftCPU::RCR_RM8_1(const X86::Instruction&) { TODO(); }
  959. void SoftCPU::RCR_RM8_CL(const X86::Instruction&) { TODO(); }
  960. void SoftCPU::RCR_RM8_imm8(const X86::Instruction&) { TODO(); }
  961. void SoftCPU::RDTSC(const X86::Instruction&) { TODO(); }
  962. void SoftCPU::RET(const X86::Instruction& insn)
  963. {
  964. ASSERT(!insn.has_operand_size_override_prefix());
  965. set_eip(pop32());
  966. }
  967. void SoftCPU::RETF(const X86::Instruction&) { TODO(); }
  968. void SoftCPU::RETF_imm16(const X86::Instruction&) { TODO(); }
  969. void SoftCPU::RET_imm16(const X86::Instruction& insn)
  970. {
  971. ASSERT(!insn.has_operand_size_override_prefix());
  972. set_eip(pop32());
  973. set_esp(esp() + insn.imm16());
  974. }
  975. void SoftCPU::ROL_RM16_1(const X86::Instruction&) { TODO(); }
  976. void SoftCPU::ROL_RM16_CL(const X86::Instruction&) { TODO(); }
  977. void SoftCPU::ROL_RM16_imm8(const X86::Instruction&) { TODO(); }
  978. void SoftCPU::ROL_RM32_1(const X86::Instruction&) { TODO(); }
  979. void SoftCPU::ROL_RM32_CL(const X86::Instruction&) { TODO(); }
  980. void SoftCPU::ROL_RM32_imm8(const X86::Instruction&) { TODO(); }
  981. void SoftCPU::ROL_RM8_1(const X86::Instruction&) { TODO(); }
  982. void SoftCPU::ROL_RM8_CL(const X86::Instruction&) { TODO(); }
  983. void SoftCPU::ROL_RM8_imm8(const X86::Instruction&) { TODO(); }
  984. void SoftCPU::ROR_RM16_1(const X86::Instruction&) { TODO(); }
  985. void SoftCPU::ROR_RM16_CL(const X86::Instruction&) { TODO(); }
  986. void SoftCPU::ROR_RM16_imm8(const X86::Instruction&) { TODO(); }
  987. void SoftCPU::ROR_RM32_1(const X86::Instruction&) { TODO(); }
  988. void SoftCPU::ROR_RM32_CL(const X86::Instruction&) { TODO(); }
  989. void SoftCPU::ROR_RM32_imm8(const X86::Instruction&) { TODO(); }
  990. void SoftCPU::ROR_RM8_1(const X86::Instruction&) { TODO(); }
  991. void SoftCPU::ROR_RM8_CL(const X86::Instruction&) { TODO(); }
  992. void SoftCPU::ROR_RM8_imm8(const X86::Instruction&) { TODO(); }
  993. void SoftCPU::SAHF(const X86::Instruction&) { TODO(); }
  994. void SoftCPU::SALC(const X86::Instruction&) { TODO(); }
  995. template<typename T>
  996. static T op_sar(SoftCPU& cpu, T data, u8 steps)
  997. {
  998. if (steps == 0)
  999. return data;
  1000. u32 result = 0;
  1001. u32 new_flags = 0;
  1002. if constexpr (sizeof(T) == 4)
  1003. asm volatile("sarl %%cl, %%eax\n" ::"a"(data), "c"(steps));
  1004. else if constexpr (sizeof(T) == 2)
  1005. asm volatile("sarw %%cl, %%ax\n" ::"a"(data), "c"(steps));
  1006. else if constexpr (sizeof(T) == 1)
  1007. asm volatile("sarb %%cl, %%al\n" ::"a"(data), "c"(steps));
  1008. asm volatile(
  1009. "mov %%eax, %%ebx\n"
  1010. : "=b"(result));
  1011. asm volatile(
  1012. "pushf\n"
  1013. "pop %%eax"
  1014. : "=a"(new_flags));
  1015. cpu.set_flags_oszapc(new_flags);
  1016. return result;
  1017. }
  1018. void SoftCPU::SAR_RM16_1(const X86::Instruction& insn)
  1019. {
  1020. auto data = insn.modrm().read16(*this, insn);
  1021. insn.modrm().write16(*this, insn, op_sar(*this, data, 1));
  1022. }
  1023. void SoftCPU::SAR_RM16_CL(const X86::Instruction& insn)
  1024. {
  1025. auto data = insn.modrm().read16(*this, insn);
  1026. insn.modrm().write16(*this, insn, op_sar(*this, data, cl()));
  1027. }
  1028. void SoftCPU::SAR_RM16_imm8(const X86::Instruction& insn)
  1029. {
  1030. auto data = insn.modrm().read16(*this, insn);
  1031. insn.modrm().write16(*this, insn, op_sar(*this, data, insn.imm8()));
  1032. }
  1033. void SoftCPU::SAR_RM32_1(const X86::Instruction& insn)
  1034. {
  1035. auto data = insn.modrm().read32(*this, insn);
  1036. insn.modrm().write32(*this, insn, op_sar(*this, data, 1));
  1037. }
  1038. void SoftCPU::SAR_RM32_CL(const X86::Instruction& insn)
  1039. {
  1040. auto data = insn.modrm().read32(*this, insn);
  1041. insn.modrm().write32(*this, insn, op_sar(*this, data, cl()));
  1042. }
  1043. void SoftCPU::SAR_RM32_imm8(const X86::Instruction& insn)
  1044. {
  1045. auto data = insn.modrm().read32(*this, insn);
  1046. insn.modrm().write32(*this, insn, op_sar(*this, data, insn.imm8()));
  1047. }
  1048. void SoftCPU::SAR_RM8_1(const X86::Instruction& insn)
  1049. {
  1050. auto data = insn.modrm().read8(*this, insn);
  1051. insn.modrm().write8(*this, insn, op_sar(*this, data, 1));
  1052. }
  1053. void SoftCPU::SAR_RM8_CL(const X86::Instruction& insn)
  1054. {
  1055. auto data = insn.modrm().read8(*this, insn);
  1056. insn.modrm().write8(*this, insn, op_sar(*this, data, cl()));
  1057. }
  1058. void SoftCPU::SAR_RM8_imm8(const X86::Instruction& insn)
  1059. {
  1060. auto data = insn.modrm().read8(*this, insn);
  1061. insn.modrm().write8(*this, insn, op_sar(*this, data, insn.imm8()));
  1062. }
  1063. void SoftCPU::SBB_AL_imm8(const X86::Instruction&) { TODO(); }
  1064. void SoftCPU::SBB_AX_imm16(const X86::Instruction&) { TODO(); }
  1065. void SoftCPU::SBB_EAX_imm32(const X86::Instruction&) { TODO(); }
  1066. void SoftCPU::SBB_RM16_imm16(const X86::Instruction&) { TODO(); }
  1067. void SoftCPU::SBB_RM16_imm8(const X86::Instruction&) { TODO(); }
  1068. void SoftCPU::SBB_RM16_reg16(const X86::Instruction&) { TODO(); }
  1069. void SoftCPU::SBB_RM32_imm32(const X86::Instruction&) { TODO(); }
  1070. void SoftCPU::SBB_RM32_imm8(const X86::Instruction&) { TODO(); }
  1071. void SoftCPU::SBB_RM32_reg32(const X86::Instruction&) { TODO(); }
  1072. void SoftCPU::SBB_RM8_imm8(const X86::Instruction&) { TODO(); }
  1073. void SoftCPU::SBB_RM8_reg8(const X86::Instruction&) { TODO(); }
  1074. void SoftCPU::SBB_reg16_RM16(const X86::Instruction&) { TODO(); }
  1075. void SoftCPU::SBB_reg32_RM32(const X86::Instruction&) { TODO(); }
  1076. void SoftCPU::SBB_reg8_RM8(const X86::Instruction&) { TODO(); }
  1077. void SoftCPU::SCASB(const X86::Instruction&) { TODO(); }
  1078. void SoftCPU::SCASD(const X86::Instruction&) { TODO(); }
  1079. void SoftCPU::SCASW(const X86::Instruction&) { TODO(); }
  1080. void SoftCPU::SETcc_RM8(const X86::Instruction& insn)
  1081. {
  1082. insn.modrm().write8(*this, insn, evaluate_condition(insn.cc()));
  1083. }
  1084. void SoftCPU::SGDT(const X86::Instruction&) { TODO(); }
  1085. void SoftCPU::SHLD_RM16_reg16_CL(const X86::Instruction&) { TODO(); }
  1086. void SoftCPU::SHLD_RM16_reg16_imm8(const X86::Instruction&) { TODO(); }
  1087. void SoftCPU::SHLD_RM32_reg32_CL(const X86::Instruction&) { TODO(); }
  1088. void SoftCPU::SHLD_RM32_reg32_imm8(const X86::Instruction&) { TODO(); }
  1089. void SoftCPU::SHL_RM16_1(const X86::Instruction& insn)
  1090. {
  1091. auto data = insn.modrm().read16(*this, insn);
  1092. insn.modrm().write16(*this, insn, op_shl(*this, data, 1));
  1093. }
  1094. void SoftCPU::SHL_RM16_CL(const X86::Instruction& insn)
  1095. {
  1096. auto data = insn.modrm().read16(*this, insn);
  1097. insn.modrm().write16(*this, insn, op_shl(*this, data, cl()));
  1098. }
  1099. void SoftCPU::SHL_RM16_imm8(const X86::Instruction& insn)
  1100. {
  1101. auto data = insn.modrm().read16(*this, insn);
  1102. insn.modrm().write16(*this, insn, op_shl(*this, data, insn.imm8()));
  1103. }
  1104. void SoftCPU::SHL_RM32_1(const X86::Instruction& insn)
  1105. {
  1106. auto data = insn.modrm().read32(*this, insn);
  1107. insn.modrm().write32(*this, insn, op_shl(*this, data, 1));
  1108. }
  1109. void SoftCPU::SHL_RM32_CL(const X86::Instruction& insn)
  1110. {
  1111. auto data = insn.modrm().read32(*this, insn);
  1112. insn.modrm().write32(*this, insn, op_shl(*this, data, cl()));
  1113. }
  1114. void SoftCPU::SHL_RM32_imm8(const X86::Instruction& insn)
  1115. {
  1116. auto data = insn.modrm().read32(*this, insn);
  1117. insn.modrm().write32(*this, insn, op_shl(*this, data, insn.imm8()));
  1118. }
  1119. void SoftCPU::SHL_RM8_1(const X86::Instruction& insn)
  1120. {
  1121. auto data = insn.modrm().read8(*this, insn);
  1122. insn.modrm().write8(*this, insn, op_shl(*this, data, 1));
  1123. }
  1124. void SoftCPU::SHL_RM8_CL(const X86::Instruction& insn)
  1125. {
  1126. auto data = insn.modrm().read8(*this, insn);
  1127. insn.modrm().write8(*this, insn, op_shl(*this, data, cl()));
  1128. }
  1129. void SoftCPU::SHL_RM8_imm8(const X86::Instruction& insn)
  1130. {
  1131. auto data = insn.modrm().read8(*this, insn);
  1132. insn.modrm().write8(*this, insn, op_shl(*this, data, insn.imm8()));
  1133. }
  1134. void SoftCPU::SHRD_RM16_reg16_CL(const X86::Instruction&) { TODO(); }
  1135. void SoftCPU::SHRD_RM16_reg16_imm8(const X86::Instruction&) { TODO(); }
  1136. void SoftCPU::SHRD_RM32_reg32_CL(const X86::Instruction&) { TODO(); }
  1137. void SoftCPU::SHRD_RM32_reg32_imm8(const X86::Instruction&) { TODO(); }
  1138. void SoftCPU::SHR_RM16_1(const X86::Instruction& insn)
  1139. {
  1140. auto data = insn.modrm().read16(*this, insn);
  1141. insn.modrm().write16(*this, insn, op_shr(*this, data, 1));
  1142. }
  1143. void SoftCPU::SHR_RM16_CL(const X86::Instruction& insn)
  1144. {
  1145. auto data = insn.modrm().read16(*this, insn);
  1146. insn.modrm().write16(*this, insn, op_shr(*this, data, cl()));
  1147. }
  1148. void SoftCPU::SHR_RM16_imm8(const X86::Instruction& insn)
  1149. {
  1150. auto data = insn.modrm().read16(*this, insn);
  1151. insn.modrm().write16(*this, insn, op_shr(*this, data, insn.imm8()));
  1152. }
  1153. void SoftCPU::SHR_RM32_1(const X86::Instruction& insn)
  1154. {
  1155. auto data = insn.modrm().read32(*this, insn);
  1156. insn.modrm().write32(*this, insn, op_shr(*this, data, 1));
  1157. }
  1158. void SoftCPU::SHR_RM32_CL(const X86::Instruction& insn)
  1159. {
  1160. auto data = insn.modrm().read32(*this, insn);
  1161. insn.modrm().write32(*this, insn, op_shr(*this, data, cl()));
  1162. }
  1163. void SoftCPU::SHR_RM32_imm8(const X86::Instruction& insn)
  1164. {
  1165. auto data = insn.modrm().read32(*this, insn);
  1166. insn.modrm().write32(*this, insn, op_shr(*this, data, insn.imm8()));
  1167. }
  1168. void SoftCPU::SHR_RM8_1(const X86::Instruction& insn)
  1169. {
  1170. auto data = insn.modrm().read8(*this, insn);
  1171. insn.modrm().write8(*this, insn, op_shr(*this, data, 1));
  1172. }
  1173. void SoftCPU::SHR_RM8_CL(const X86::Instruction& insn)
  1174. {
  1175. auto data = insn.modrm().read8(*this, insn);
  1176. insn.modrm().write8(*this, insn, op_shr(*this, data, cl()));
  1177. }
  1178. void SoftCPU::SHR_RM8_imm8(const X86::Instruction& insn)
  1179. {
  1180. auto data = insn.modrm().read8(*this, insn);
  1181. insn.modrm().write8(*this, insn, op_shr(*this, data, insn.imm8()));
  1182. }
  1183. void SoftCPU::SIDT(const X86::Instruction&) { TODO(); }
  1184. void SoftCPU::SLDT_RM16(const X86::Instruction&) { TODO(); }
  1185. void SoftCPU::SMSW_RM16(const X86::Instruction&) { TODO(); }
  1186. void SoftCPU::STC(const X86::Instruction&) { TODO(); }
  1187. void SoftCPU::STD(const X86::Instruction&) { TODO(); }
  1188. void SoftCPU::STI(const X86::Instruction&) { TODO(); }
  1189. void SoftCPU::STOSB(const X86::Instruction& insn)
  1190. {
  1191. if (insn.has_address_size_override_prefix()) {
  1192. do_once_or_repeat<false>(insn, [&] {
  1193. write_memory8({ es(), di() }, al());
  1194. set_di(di() + (df() ? -1 : 1));
  1195. });
  1196. } else {
  1197. do_once_or_repeat<false>(insn, [&] {
  1198. write_memory8({ es(), edi() }, al());
  1199. set_edi(edi() + (df() ? -1 : 1));
  1200. });
  1201. }
  1202. }
  1203. void SoftCPU::STOSD(const X86::Instruction& insn)
  1204. {
  1205. if (insn.has_address_size_override_prefix()) {
  1206. do_once_or_repeat<false>(insn, [&] {
  1207. write_memory32({ es(), di() }, eax());
  1208. set_di(di() + (df() ? -4 : 4));
  1209. });
  1210. } else {
  1211. do_once_or_repeat<false>(insn, [&] {
  1212. write_memory32({ es(), edi() }, eax());
  1213. set_edi(edi() + (df() ? -4 : 4));
  1214. });
  1215. }
  1216. }
  1217. void SoftCPU::STOSW(const X86::Instruction& insn)
  1218. {
  1219. if (insn.has_address_size_override_prefix()) {
  1220. do_once_or_repeat<false>(insn, [&] {
  1221. write_memory16({ es(), di() }, ax());
  1222. set_di(di() + (df() ? -2 : 2));
  1223. });
  1224. } else {
  1225. do_once_or_repeat<false>(insn, [&] {
  1226. write_memory16({ es(), edi() }, ax());
  1227. set_edi(edi() + (df() ? -2 : 2));
  1228. });
  1229. }
  1230. }
  1231. void SoftCPU::STR_RM16(const X86::Instruction&) { TODO(); }
  1232. void SoftCPU::UD0(const X86::Instruction&) { TODO(); }
  1233. void SoftCPU::UD1(const X86::Instruction&) { TODO(); }
  1234. void SoftCPU::UD2(const X86::Instruction&) { TODO(); }
  1235. void SoftCPU::VERR_RM16(const X86::Instruction&) { TODO(); }
  1236. void SoftCPU::VERW_RM16(const X86::Instruction&) { TODO(); }
  1237. void SoftCPU::WAIT(const X86::Instruction&) { TODO(); }
  1238. void SoftCPU::WBINVD(const X86::Instruction&) { TODO(); }
  1239. void SoftCPU::XADD_RM16_reg16(const X86::Instruction&) { TODO(); }
  1240. void SoftCPU::XADD_RM32_reg32(const X86::Instruction&) { TODO(); }
  1241. void SoftCPU::XADD_RM8_reg8(const X86::Instruction&) { TODO(); }
  1242. void SoftCPU::XCHG_AX_reg16(const X86::Instruction&) { TODO(); }
  1243. void SoftCPU::XCHG_EAX_reg32(const X86::Instruction&) { TODO(); }
  1244. void SoftCPU::XCHG_reg16_RM16(const X86::Instruction&) { TODO(); }
  1245. void SoftCPU::XCHG_reg32_RM32(const X86::Instruction&) { TODO(); }
  1246. void SoftCPU::XCHG_reg8_RM8(const X86::Instruction&) { TODO(); }
  1247. void SoftCPU::XLAT(const X86::Instruction&) { TODO(); }
  1248. #define DEFINE_GENERIC_INSN_HANDLERS_PARTIAL(mnemonic, op, update_dest) \
  1249. void SoftCPU::mnemonic##_AL_imm8(const X86::Instruction& insn) { generic_AL_imm8<update_dest>(op<u8>, insn); } \
  1250. void SoftCPU::mnemonic##_AX_imm16(const X86::Instruction& insn) { generic_AX_imm16<update_dest>(op<u16>, insn); } \
  1251. void SoftCPU::mnemonic##_EAX_imm32(const X86::Instruction& insn) { generic_EAX_imm32<update_dest>(op<u32>, insn); } \
  1252. void SoftCPU::mnemonic##_RM16_imm16(const X86::Instruction& insn) { generic_RM16_imm16<update_dest>(op<u16>, insn); } \
  1253. void SoftCPU::mnemonic##_RM16_reg16(const X86::Instruction& insn) { generic_RM16_reg16<update_dest>(op<u16>, insn); } \
  1254. void SoftCPU::mnemonic##_RM32_imm32(const X86::Instruction& insn) { generic_RM32_imm32<update_dest>(op<u32>, insn); } \
  1255. void SoftCPU::mnemonic##_RM32_reg32(const X86::Instruction& insn) { generic_RM32_reg32<update_dest>(op<u32>, insn); } \
  1256. void SoftCPU::mnemonic##_RM8_imm8(const X86::Instruction& insn) { generic_RM8_imm8<update_dest>(op<u8>, insn); } \
  1257. void SoftCPU::mnemonic##_RM8_reg8(const X86::Instruction& insn) { generic_RM8_reg8<update_dest>(op<u8>, insn); }
  1258. #define DEFINE_GENERIC_INSN_HANDLERS(mnemonic, op, update_dest) \
  1259. DEFINE_GENERIC_INSN_HANDLERS_PARTIAL(mnemonic, op, update_dest) \
  1260. void SoftCPU::mnemonic##_RM16_imm8(const X86::Instruction& insn) { generic_RM16_imm8<update_dest>(op<u16>, insn); } \
  1261. void SoftCPU::mnemonic##_RM32_imm8(const X86::Instruction& insn) { generic_RM32_imm8<update_dest>(op<u32>, insn); } \
  1262. void SoftCPU::mnemonic##_reg16_RM16(const X86::Instruction& insn) { generic_reg16_RM16<update_dest>(op<u16>, insn); } \
  1263. void SoftCPU::mnemonic##_reg32_RM32(const X86::Instruction& insn) { generic_reg32_RM32<update_dest>(op<u32>, insn); } \
  1264. void SoftCPU::mnemonic##_reg8_RM8(const X86::Instruction& insn) { generic_reg8_RM8<update_dest>(op<u8>, insn); }
  1265. DEFINE_GENERIC_INSN_HANDLERS(XOR, op_xor, true)
  1266. DEFINE_GENERIC_INSN_HANDLERS(OR, op_or, true)
  1267. DEFINE_GENERIC_INSN_HANDLERS(ADD, op_add, true)
  1268. DEFINE_GENERIC_INSN_HANDLERS(SUB, op_sub, true)
  1269. DEFINE_GENERIC_INSN_HANDLERS(AND, op_and, true)
  1270. DEFINE_GENERIC_INSN_HANDLERS(CMP, op_sub, false)
  1271. DEFINE_GENERIC_INSN_HANDLERS_PARTIAL(TEST, op_and, false)
  1272. void SoftCPU::MOVQ_mm1_mm2m64(const X86::Instruction&) { TODO(); }
  1273. void SoftCPU::EMMS(const X86::Instruction&) { TODO(); }
  1274. void SoftCPU::MOVQ_mm1_m64_mm2(const X86::Instruction&) { TODO(); }
  1275. void SoftCPU::wrap_0xC0(const X86::Instruction&) { TODO(); }
  1276. void SoftCPU::wrap_0xC1_16(const X86::Instruction&) { TODO(); }
  1277. void SoftCPU::wrap_0xC1_32(const X86::Instruction&) { TODO(); }
  1278. void SoftCPU::wrap_0xD0(const X86::Instruction&) { TODO(); }
  1279. void SoftCPU::wrap_0xD1_16(const X86::Instruction&) { TODO(); }
  1280. void SoftCPU::wrap_0xD1_32(const X86::Instruction&) { TODO(); }
  1281. void SoftCPU::wrap_0xD2(const X86::Instruction&) { TODO(); }
  1282. void SoftCPU::wrap_0xD3_16(const X86::Instruction&) { TODO(); }
  1283. void SoftCPU::wrap_0xD3_32(const X86::Instruction&) { TODO(); }
  1284. }