SoftCPU.cpp 51 KB

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