armsupp.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638
  1. /* armsupp.c -- ARMulator support code: ARM6 Instruction Emulator.
  2. Copyright (C) 1994 Advanced RISC Machines Ltd.
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  14. #include "common/logging/log.h"
  15. #include "core/mem_map.h"
  16. #include "core/arm/skyeye_common/arm_regformat.h"
  17. #include "core/arm/skyeye_common/armstate.h"
  18. #include "core/arm/skyeye_common/armsupp.h"
  19. // Unsigned sum of absolute difference
  20. u8 ARMul_UnsignedAbsoluteDifference(u8 left, u8 right)
  21. {
  22. if (left > right)
  23. return left - right;
  24. return right - left;
  25. }
  26. // Add with carry, indicates if a carry-out or signed overflow occurred.
  27. u32 AddWithCarry(u32 left, u32 right, u32 carry_in, bool* carry_out_occurred, bool* overflow_occurred)
  28. {
  29. u64 unsigned_sum = (u64)left + (u64)right + (u64)carry_in;
  30. s64 signed_sum = (s64)(s32)left + (s64)(s32)right + (s64)carry_in;
  31. u64 result = (unsigned_sum & 0xFFFFFFFF);
  32. if (carry_out_occurred)
  33. *carry_out_occurred = (result != unsigned_sum);
  34. if (overflow_occurred)
  35. *overflow_occurred = ((s64)(s32)result != signed_sum);
  36. return (u32)result;
  37. }
  38. // Compute whether an addition of A and B, giving RESULT, overflowed.
  39. bool AddOverflow(u32 a, u32 b, u32 result)
  40. {
  41. return ((NEG(a) && NEG(b) && POS(result)) ||
  42. (POS(a) && POS(b) && NEG(result)));
  43. }
  44. // Compute whether a subtraction of A and B, giving RESULT, overflowed.
  45. bool SubOverflow(u32 a, u32 b, u32 result)
  46. {
  47. return ((NEG(a) && POS(b) && POS(result)) ||
  48. (POS(a) && NEG(b) && NEG(result)));
  49. }
  50. // Returns true if the Q flag should be set as a result of overflow.
  51. bool ARMul_AddOverflowQ(u32 a, u32 b)
  52. {
  53. u32 result = a + b;
  54. if (((result ^ a) & (u32)0x80000000) && ((a ^ b) & (u32)0x80000000) == 0)
  55. return true;
  56. return false;
  57. }
  58. // 8-bit signed saturated addition
  59. u8 ARMul_SignedSaturatedAdd8(u8 left, u8 right)
  60. {
  61. u8 result = left + right;
  62. if (((result ^ left) & 0x80) && ((left ^ right) & 0x80) == 0) {
  63. if (left & 0x80)
  64. result = 0x80;
  65. else
  66. result = 0x7F;
  67. }
  68. return result;
  69. }
  70. // 8-bit signed saturated subtraction
  71. u8 ARMul_SignedSaturatedSub8(u8 left, u8 right)
  72. {
  73. u8 result = left - right;
  74. if (((result ^ left) & 0x80) && ((left ^ right) & 0x80) != 0) {
  75. if (left & 0x80)
  76. result = 0x80;
  77. else
  78. result = 0x7F;
  79. }
  80. return result;
  81. }
  82. // 16-bit signed saturated addition
  83. u16 ARMul_SignedSaturatedAdd16(u16 left, u16 right)
  84. {
  85. u16 result = left + right;
  86. if (((result ^ left) & 0x8000) && ((left ^ right) & 0x8000) == 0) {
  87. if (left & 0x8000)
  88. result = 0x8000;
  89. else
  90. result = 0x7FFF;
  91. }
  92. return result;
  93. }
  94. // 16-bit signed saturated subtraction
  95. u16 ARMul_SignedSaturatedSub16(u16 left, u16 right)
  96. {
  97. u16 result = left - right;
  98. if (((result ^ left) & 0x8000) && ((left ^ right) & 0x8000) != 0) {
  99. if (left & 0x8000)
  100. result = 0x8000;
  101. else
  102. result = 0x7FFF;
  103. }
  104. return result;
  105. }
  106. // 8-bit unsigned saturated addition
  107. u8 ARMul_UnsignedSaturatedAdd8(u8 left, u8 right)
  108. {
  109. u8 result = left + right;
  110. if (result < left)
  111. result = 0xFF;
  112. return result;
  113. }
  114. // 16-bit unsigned saturated addition
  115. u16 ARMul_UnsignedSaturatedAdd16(u16 left, u16 right)
  116. {
  117. u16 result = left + right;
  118. if (result < left)
  119. result = 0xFFFF;
  120. return result;
  121. }
  122. // 8-bit unsigned saturated subtraction
  123. u8 ARMul_UnsignedSaturatedSub8(u8 left, u8 right)
  124. {
  125. if (left <= right)
  126. return 0;
  127. return left - right;
  128. }
  129. // 16-bit unsigned saturated subtraction
  130. u16 ARMul_UnsignedSaturatedSub16(u16 left, u16 right)
  131. {
  132. if (left <= right)
  133. return 0;
  134. return left - right;
  135. }
  136. // Signed saturation.
  137. u32 ARMul_SignedSatQ(s32 value, u8 shift, bool* saturation_occurred)
  138. {
  139. const u32 max = (1 << shift) - 1;
  140. const s32 top = (value >> shift);
  141. if (top > 0) {
  142. *saturation_occurred = true;
  143. return max;
  144. }
  145. else if (top < -1) {
  146. *saturation_occurred = true;
  147. return ~max;
  148. }
  149. *saturation_occurred = false;
  150. return (u32)value;
  151. }
  152. // Unsigned saturation
  153. u32 ARMul_UnsignedSatQ(s32 value, u8 shift, bool* saturation_occurred)
  154. {
  155. const u32 max = (1 << shift) - 1;
  156. if (value < 0) {
  157. *saturation_occurred = true;
  158. return 0;
  159. } else if ((u32)value > max) {
  160. *saturation_occurred = true;
  161. return max;
  162. }
  163. *saturation_occurred = false;
  164. return (u32)value;
  165. }
  166. // Whether or not the given CPU is in big endian mode (E bit is set)
  167. bool InBigEndianMode(ARMul_State* cpu)
  168. {
  169. return (cpu->Cpsr & (1 << 9)) != 0;
  170. }
  171. // Whether or not the given CPU is in a mode other than user mode.
  172. bool InAPrivilegedMode(ARMul_State* cpu)
  173. {
  174. return (cpu->Mode != USER32MODE);
  175. }
  176. // Reads from the CP15 registers. Used with implementation of the MRC instruction.
  177. // Note that since the 3DS does not have the hypervisor extensions, these registers
  178. // are not implemented.
  179. u32 ReadCP15Register(ARMul_State* cpu, u32 crn, u32 opcode_1, u32 crm, u32 opcode_2)
  180. {
  181. // Unprivileged registers
  182. if (crn == 13 && opcode_1 == 0 && crm == 0)
  183. {
  184. if (opcode_2 == 2)
  185. return cpu->CP15[CP15_THREAD_UPRW];
  186. if (opcode_2 == 3)
  187. return cpu->CP15[CP15_THREAD_URO];
  188. }
  189. if (InAPrivilegedMode(cpu))
  190. {
  191. if (crn == 0 && opcode_1 == 0)
  192. {
  193. if (crm == 0)
  194. {
  195. if (opcode_2 == 0)
  196. return cpu->CP15[CP15_MAIN_ID];
  197. if (opcode_2 == 1)
  198. return cpu->CP15[CP15_CACHE_TYPE];
  199. if (opcode_2 == 3)
  200. return cpu->CP15[CP15_TLB_TYPE];
  201. if (opcode_2 == 5)
  202. return cpu->CP15[CP15_CPU_ID];
  203. }
  204. else if (crm == 1)
  205. {
  206. if (opcode_2 == 0)
  207. return cpu->CP15[CP15_PROCESSOR_FEATURE_0];
  208. if (opcode_2 == 1)
  209. return cpu->CP15[CP15_PROCESSOR_FEATURE_1];
  210. if (opcode_2 == 2)
  211. return cpu->CP15[CP15_DEBUG_FEATURE_0];
  212. if (opcode_2 == 4)
  213. return cpu->CP15[CP15_MEMORY_MODEL_FEATURE_0];
  214. if (opcode_2 == 5)
  215. return cpu->CP15[CP15_MEMORY_MODEL_FEATURE_1];
  216. if (opcode_2 == 6)
  217. return cpu->CP15[CP15_MEMORY_MODEL_FEATURE_2];
  218. if (opcode_2 == 7)
  219. return cpu->CP15[CP15_MEMORY_MODEL_FEATURE_3];
  220. }
  221. else if (crm == 2)
  222. {
  223. if (opcode_2 == 0)
  224. return cpu->CP15[CP15_ISA_FEATURE_0];
  225. if (opcode_2 == 1)
  226. return cpu->CP15[CP15_ISA_FEATURE_1];
  227. if (opcode_2 == 2)
  228. return cpu->CP15[CP15_ISA_FEATURE_2];
  229. if (opcode_2 == 3)
  230. return cpu->CP15[CP15_ISA_FEATURE_3];
  231. if (opcode_2 == 4)
  232. return cpu->CP15[CP15_ISA_FEATURE_4];
  233. }
  234. }
  235. if (crn == 1 && opcode_1 == 0 && crm == 0)
  236. {
  237. if (opcode_2 == 0)
  238. return cpu->CP15[CP15_CONTROL];
  239. if (opcode_2 == 1)
  240. return cpu->CP15[CP15_AUXILIARY_CONTROL];
  241. if (opcode_2 == 2)
  242. return cpu->CP15[CP15_COPROCESSOR_ACCESS_CONTROL];
  243. }
  244. if (crn == 2 && opcode_1 == 0 && crm == 0)
  245. {
  246. if (opcode_2 == 0)
  247. return cpu->CP15[CP15_TRANSLATION_BASE_TABLE_0];
  248. if (opcode_2 == 1)
  249. return cpu->CP15[CP15_TRANSLATION_BASE_TABLE_1];
  250. if (opcode_2 == 2)
  251. return cpu->CP15[CP15_TRANSLATION_BASE_CONTROL];
  252. }
  253. if (crn == 3 && opcode_1 == 0 && crm == 0 && opcode_2 == 0)
  254. return cpu->CP15[CP15_DOMAIN_ACCESS_CONTROL];
  255. if (crn == 5 && opcode_1 == 0 && crm == 0)
  256. {
  257. if (opcode_2 == 0)
  258. return cpu->CP15[CP15_FAULT_STATUS];
  259. if (opcode_2 == 1)
  260. return cpu->CP15[CP15_INSTR_FAULT_STATUS];
  261. }
  262. if (crn == 6 && opcode_1 == 0 && crm == 0)
  263. {
  264. if (opcode_2 == 0)
  265. return cpu->CP15[CP15_FAULT_ADDRESS];
  266. if (opcode_2 == 1)
  267. return cpu->CP15[CP15_WFAR];
  268. }
  269. if (crn == 7 && opcode_1 == 0 && crm == 4 && opcode_2 == 0)
  270. return cpu->CP15[CP15_PHYS_ADDRESS];
  271. if (crn == 9 && opcode_1 == 0 && crm == 0 && opcode_2 == 0)
  272. return cpu->CP15[CP15_DATA_CACHE_LOCKDOWN];
  273. if (crn == 10 && opcode_1 == 0)
  274. {
  275. if (crm == 0 && opcode_2 == 0)
  276. return cpu->CP15[CP15_TLB_LOCKDOWN];
  277. if (crm == 2)
  278. {
  279. if (opcode_2 == 0)
  280. return cpu->CP15[CP15_PRIMARY_REGION_REMAP];
  281. if (opcode_2 == 1)
  282. return cpu->CP15[CP15_NORMAL_REGION_REMAP];
  283. }
  284. }
  285. if (crn == 13 && crm == 0)
  286. {
  287. if (opcode_2 == 0)
  288. return cpu->CP15[CP15_PID];
  289. if (opcode_2 == 1)
  290. return cpu->CP15[CP15_CONTEXT_ID];
  291. if (opcode_2 == 4)
  292. return cpu->CP15[CP15_THREAD_PRW];
  293. }
  294. if (crn == 15)
  295. {
  296. if (opcode_1 == 0 && crm == 12)
  297. {
  298. if (opcode_2 == 0)
  299. return cpu->CP15[CP15_PERFORMANCE_MONITOR_CONTROL];
  300. if (opcode_2 == 1)
  301. return cpu->CP15[CP15_CYCLE_COUNTER];
  302. if (opcode_2 == 2)
  303. return cpu->CP15[CP15_COUNT_0];
  304. if (opcode_2 == 3)
  305. return cpu->CP15[CP15_COUNT_1];
  306. }
  307. if (opcode_1 == 5 && opcode_2 == 2)
  308. {
  309. if (crm == 5)
  310. return cpu->CP15[CP15_MAIN_TLB_LOCKDOWN_VIRT_ADDRESS];
  311. if (crm == 6)
  312. return cpu->CP15[CP15_MAIN_TLB_LOCKDOWN_PHYS_ADDRESS];
  313. if (crm == 7)
  314. return cpu->CP15[CP15_MAIN_TLB_LOCKDOWN_ATTRIBUTE];
  315. }
  316. if (opcode_1 == 7 && crm == 1 && opcode_2 == 0)
  317. return cpu->CP15[CP15_TLB_DEBUG_CONTROL];
  318. }
  319. }
  320. LOG_ERROR(Core_ARM11, "MRC CRn=%u, CRm=%u, OP1=%u OP2=%u is not implemented. Returning zero.", crn, crm, opcode_1, opcode_2);
  321. return 0;
  322. }
  323. // Write to the CP15 registers. Used with implementation of the MCR instruction.
  324. // Note that since the 3DS does not have the hypervisor extensions, these registers
  325. // are not implemented.
  326. void WriteCP15Register(ARMul_State* cpu, u32 value, u32 crn, u32 opcode_1, u32 crm, u32 opcode_2)
  327. {
  328. if (InAPrivilegedMode(cpu))
  329. {
  330. if (crn == 1 && opcode_1 == 0 && crm == 0)
  331. {
  332. if (opcode_2 == 0)
  333. cpu->CP15[CP15_CONTROL] = value;
  334. else if (opcode_2 == 1)
  335. cpu->CP15[CP15_AUXILIARY_CONTROL] = value;
  336. else if (opcode_2 == 2)
  337. cpu->CP15[CP15_COPROCESSOR_ACCESS_CONTROL] = value;
  338. }
  339. else if (crn == 2 && opcode_1 == 0 && crm == 0)
  340. {
  341. if (opcode_2 == 0)
  342. cpu->CP15[CP15_TRANSLATION_BASE_TABLE_0] = value;
  343. else if (opcode_2 == 1)
  344. cpu->CP15[CP15_TRANSLATION_BASE_TABLE_1] = value;
  345. else if (opcode_2 == 2)
  346. cpu->CP15[CP15_TRANSLATION_BASE_CONTROL] = value;
  347. }
  348. else if (crn == 3 && opcode_1 == 0 && crm == 0 && opcode_2 == 0)
  349. {
  350. cpu->CP15[CP15_DOMAIN_ACCESS_CONTROL] = value;
  351. }
  352. else if (crn == 5 && opcode_1 == 0 && crm == 0)
  353. {
  354. if (opcode_2 == 0)
  355. cpu->CP15[CP15_FAULT_STATUS] = value;
  356. else if (opcode_2 == 1)
  357. cpu->CP15[CP15_INSTR_FAULT_STATUS] = value;
  358. }
  359. else if (crn == 6 && opcode_1 == 0 && crm == 0)
  360. {
  361. if (opcode_2 == 0)
  362. cpu->CP15[CP15_FAULT_ADDRESS] = value;
  363. else if (opcode_2 == 1)
  364. cpu->CP15[CP15_WFAR] = value;
  365. }
  366. else if (crn == 7 && opcode_1 == 0)
  367. {
  368. if (crm == 0 && opcode_2 == 4)
  369. {
  370. cpu->CP15[CP15_WAIT_FOR_INTERRUPT] = value;
  371. }
  372. else if (crm == 4 && opcode_2 == 0)
  373. {
  374. // NOTE: Not entirely accurate. This should do permission checks.
  375. cpu->CP15[CP15_PHYS_ADDRESS] = Memory::VirtualToPhysicalAddress(value);
  376. }
  377. else if (crm == 5)
  378. {
  379. if (opcode_2 == 0)
  380. cpu->CP15[CP15_INVALIDATE_INSTR_CACHE] = value;
  381. else if (opcode_2 == 1)
  382. cpu->CP15[CP15_INVALIDATE_INSTR_CACHE_USING_MVA] = value;
  383. else if (opcode_2 == 2)
  384. cpu->CP15[CP15_INVALIDATE_INSTR_CACHE_USING_INDEX] = value;
  385. else if (opcode_2 == 6)
  386. cpu->CP15[CP15_FLUSH_BRANCH_TARGET_CACHE] = value;
  387. else if (opcode_2 == 7)
  388. cpu->CP15[CP15_FLUSH_BRANCH_TARGET_CACHE_ENTRY] = value;
  389. }
  390. else if (crm == 6)
  391. {
  392. if (opcode_2 == 0)
  393. cpu->CP15[CP15_INVALIDATE_DATA_CACHE] = value;
  394. else if (opcode_2 == 1)
  395. cpu->CP15[CP15_INVALIDATE_DATA_CACHE_LINE_USING_MVA] = value;
  396. else if (opcode_2 == 2)
  397. cpu->CP15[CP15_INVALIDATE_DATA_CACHE_LINE_USING_INDEX] = value;
  398. }
  399. else if (crm == 7 && opcode_2 == 0)
  400. {
  401. cpu->CP15[CP15_INVALIDATE_DATA_AND_INSTR_CACHE] = value;
  402. }
  403. else if (crm == 10)
  404. {
  405. if (opcode_2 == 0)
  406. cpu->CP15[CP15_CLEAN_DATA_CACHE] = value;
  407. else if (opcode_2 == 1)
  408. cpu->CP15[CP15_CLEAN_DATA_CACHE_LINE_USING_MVA] = value;
  409. else if (opcode_2 == 2)
  410. cpu->CP15[CP15_CLEAN_DATA_CACHE_LINE_USING_INDEX] = value;
  411. }
  412. else if (crm == 14)
  413. {
  414. if (opcode_2 == 0)
  415. cpu->CP15[CP15_CLEAN_AND_INVALIDATE_DATA_CACHE] = value;
  416. else if (opcode_2 == 1)
  417. cpu->CP15[CP15_CLEAN_AND_INVALIDATE_DATA_CACHE_LINE_USING_MVA] = value;
  418. else if (opcode_2 == 2)
  419. cpu->CP15[CP15_CLEAN_AND_INVALIDATE_DATA_CACHE_LINE_USING_INDEX] = value;
  420. }
  421. }
  422. else if (crn == 8 && opcode_1 == 0)
  423. {
  424. LOG_WARNING(Core_ARM11, "TLB operations not fully implemented.");
  425. if (crm == 5)
  426. {
  427. if (opcode_2 == 0)
  428. cpu->CP15[CP15_INVALIDATE_ITLB] = value;
  429. else if (opcode_2 == 1)
  430. cpu->CP15[CP15_INVALIDATE_ITLB_SINGLE_ENTRY] = value;
  431. else if (opcode_2 == 2)
  432. cpu->CP15[CP15_INVALIDATE_ITLB_ENTRY_ON_ASID_MATCH] = value;
  433. else if (opcode_2 == 3)
  434. cpu->CP15[CP15_INVALIDATE_ITLB_ENTRY_ON_MVA] = value;
  435. }
  436. else if (crm == 6)
  437. {
  438. if (opcode_2 == 0)
  439. cpu->CP15[CP15_INVALIDATE_DTLB] = value;
  440. else if (opcode_2 == 1)
  441. cpu->CP15[CP15_INVALIDATE_DTLB_SINGLE_ENTRY] = value;
  442. else if (opcode_2 == 2)
  443. cpu->CP15[CP15_INVALIDATE_DTLB_ENTRY_ON_ASID_MATCH] = value;
  444. else if (opcode_2 == 3)
  445. cpu->CP15[CP15_INVALIDATE_DTLB_ENTRY_ON_MVA] = value;
  446. }
  447. else if (crm == 7)
  448. {
  449. if (opcode_2 == 0)
  450. cpu->CP15[CP15_INVALIDATE_UTLB] = value;
  451. else if (opcode_2 == 1)
  452. cpu->CP15[CP15_INVALIDATE_UTLB_SINGLE_ENTRY] = value;
  453. else if (opcode_2 == 2)
  454. cpu->CP15[CP15_INVALIDATE_UTLB_ENTRY_ON_ASID_MATCH] = value;
  455. else if (opcode_2 == 3)
  456. cpu->CP15[CP15_INVALIDATE_UTLB_ENTRY_ON_MVA] = value;
  457. }
  458. }
  459. else if (crn == 9 && opcode_1 == 0 && crm == 0 && opcode_2 == 0)
  460. {
  461. cpu->CP15[CP15_DATA_CACHE_LOCKDOWN] = value;
  462. }
  463. else if (crn == 10 && opcode_1 == 0)
  464. {
  465. if (crm == 0 && opcode_2 == 0)
  466. {
  467. cpu->CP15[CP15_TLB_LOCKDOWN] = value;
  468. }
  469. else if (crm == 2)
  470. {
  471. if (opcode_2 == 0)
  472. cpu->CP15[CP15_PRIMARY_REGION_REMAP] = value;
  473. else if (opcode_2 == 1)
  474. cpu->CP15[CP15_NORMAL_REGION_REMAP] = value;
  475. }
  476. }
  477. else if (crn == 13 && opcode_1 == 0 && crm == 0)
  478. {
  479. if (opcode_2 == 0)
  480. cpu->CP15[CP15_PID] = value;
  481. else if (opcode_2 == 1)
  482. cpu->CP15[CP15_CONTEXT_ID] = value;
  483. else if (opcode_2 == 3)
  484. cpu->CP15[CP15_THREAD_URO] = value;
  485. else if (opcode_2 == 4)
  486. cpu->CP15[CP15_THREAD_PRW] = value;
  487. }
  488. else if (crn == 15)
  489. {
  490. if (opcode_1 == 0 && crm == 12)
  491. {
  492. if (opcode_2 == 0)
  493. cpu->CP15[CP15_PERFORMANCE_MONITOR_CONTROL] = value;
  494. else if (opcode_2 == 1)
  495. cpu->CP15[CP15_CYCLE_COUNTER] = value;
  496. else if (opcode_2 == 2)
  497. cpu->CP15[CP15_COUNT_0] = value;
  498. else if (opcode_2 == 3)
  499. cpu->CP15[CP15_COUNT_1] = value;
  500. }
  501. else if (opcode_1 == 5)
  502. {
  503. if (crm == 4)
  504. {
  505. if (opcode_2 == 2)
  506. cpu->CP15[CP15_READ_MAIN_TLB_LOCKDOWN_ENTRY] = value;
  507. else if (opcode_2 == 4)
  508. cpu->CP15[CP15_WRITE_MAIN_TLB_LOCKDOWN_ENTRY] = value;
  509. }
  510. else if (crm == 5 && opcode_2 == 2)
  511. {
  512. cpu->CP15[CP15_MAIN_TLB_LOCKDOWN_VIRT_ADDRESS] = value;
  513. }
  514. else if (crm == 6 && opcode_2 == 2)
  515. {
  516. cpu->CP15[CP15_MAIN_TLB_LOCKDOWN_PHYS_ADDRESS] = value;
  517. }
  518. else if (crm == 7 && opcode_2 == 2)
  519. {
  520. cpu->CP15[CP15_MAIN_TLB_LOCKDOWN_ATTRIBUTE] = value;
  521. }
  522. }
  523. else if (opcode_1 == 7 && crm == 1 && opcode_2 == 0)
  524. {
  525. cpu->CP15[CP15_TLB_DEBUG_CONTROL] = value;
  526. }
  527. }
  528. }
  529. // Unprivileged registers
  530. if (crn == 7 && opcode_1 == 0 && crm == 5 && opcode_2 == 4)
  531. {
  532. cpu->CP15[CP15_FLUSH_PREFETCH_BUFFER] = value;
  533. }
  534. else if (crn == 7 && opcode_1 == 0 && crm == 10)
  535. {
  536. if (opcode_2 == 4)
  537. cpu->CP15[CP15_DATA_SYNC_BARRIER] = value;
  538. else if (opcode_2 == 5)
  539. cpu->CP15[CP15_DATA_MEMORY_BARRIER] = value;
  540. }
  541. else if (crn == 13 && opcode_1 == 0 && crm == 0 && opcode_2 == 2)
  542. {
  543. cpu->CP15[CP15_THREAD_UPRW] = value;
  544. }
  545. }