summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorGravatar bunnei2015-04-02 20:21:11 -0400
committerGravatar bunnei2015-04-02 20:21:11 -0400
commite25ffaba86c5b5a79256faf80c39f7e37343701d (patch)
treee65dfe42e08d9cb1fab735c8a62ec414fabee31e /src
parentMerge pull request #678 from lioncash/disasm (diff)
parentdyncom: Move CP15 register writing into its own function. (diff)
downloadyuzu-e25ffaba86c5b5a79256faf80c39f7e37343701d.tar.gz
yuzu-e25ffaba86c5b5a79256faf80c39f7e37343701d.tar.xz
yuzu-e25ffaba86c5b5a79256faf80c39f7e37343701d.zip
Merge pull request #677 from lioncash/cp15
dyncom: Isolate CP15 register reading and writing
Diffstat (limited to 'src')
-rw-r--r--src/core/arm/dyncom/arm_dyncom_interpreter.cpp141
-rw-r--r--src/core/arm/interpreter/armsupp.cpp431
-rw-r--r--src/core/arm/skyeye_common/arm_regformat.h90
-rw-r--r--src/core/arm/skyeye_common/armdefs.h4
4 files changed, 525 insertions, 141 deletions
diff --git a/src/core/arm/dyncom/arm_dyncom_interpreter.cpp b/src/core/arm/dyncom/arm_dyncom_interpreter.cpp
index 2765cb36e..b0efd7194 100644
--- a/src/core/arm/dyncom/arm_dyncom_interpreter.cpp
+++ b/src/core/arm/dyncom/arm_dyncom_interpreter.cpp
@@ -3690,10 +3690,6 @@ static int clz(unsigned int x) {
3690 return n; 3690 return n;
3691} 3691}
3692 3692
3693static bool InAPrivilegedMode(ARMul_State* core) {
3694 return (core->Mode != USER32MODE);
3695}
3696
3697unsigned InterpreterMainLoop(ARMul_State* state) { 3693unsigned InterpreterMainLoop(ARMul_State* state) {
3698 Common::Profiling::ScopeTimer timer_execute(profile_execute); 3694 Common::Profiling::ScopeTimer timer_execute(profile_execute);
3699 3695
@@ -3701,6 +3697,7 @@ unsigned InterpreterMainLoop(ARMul_State* state) {
3701 #undef RS 3697 #undef RS
3702 3698
3703 #define CRn inst_cream->crn 3699 #define CRn inst_cream->crn
3700 #define OPCODE_1 inst_cream->opcode_1
3704 #define OPCODE_2 inst_cream->opcode_2 3701 #define OPCODE_2 inst_cream->opcode_2
3705 #define CRm inst_cream->crm 3702 #define CRm inst_cream->crm
3706 #define CP15_REG(n) cpu->CP15[CP15(n)] 3703 #define CP15_REG(n) cpu->CP15[CP15(n)]
@@ -4764,94 +4761,8 @@ unsigned InterpreterMainLoop(ARMul_State* state) {
4764 if (inst_cream->Rd == 15) { 4761 if (inst_cream->Rd == 15) {
4765 DEBUG_MSG; 4762 DEBUG_MSG;
4766 } else { 4763 } else {
4767 if (inst_cream->cp_num == 15) { 4764 if (inst_cream->cp_num == 15)
4768 if (CRn == 1 && CRm == 0 && OPCODE_2 == 0) { 4765 WriteCP15Register(cpu, RD, CRn, OPCODE_1, CRm, OPCODE_2);
4769 CP15_REG(CP15_CONTROL) = RD;
4770 } else if (CRn == 1 && CRm == 0 && OPCODE_2 == 1) {
4771 CP15_REG(CP15_AUXILIARY_CONTROL) = RD;
4772 } else if (CRn == 1 && CRm == 0 && OPCODE_2 == 2) {
4773 CP15_REG(CP15_COPROCESSOR_ACCESS_CONTROL) = RD;
4774 } else if (CRn == 2 && CRm == 0 && OPCODE_2 == 0) {
4775 CP15_REG(CP15_TRANSLATION_BASE_TABLE_0) = RD;
4776 } else if (CRn == 2 && CRm == 0 && OPCODE_2 == 1) {
4777 CP15_REG(CP15_TRANSLATION_BASE_TABLE_1) = RD;
4778 } else if (CRn == 2 && CRm == 0 && OPCODE_2 == 2) {
4779 CP15_REG(CP15_TRANSLATION_BASE_CONTROL) = RD;
4780 } else if (CRn == 3 && CRm == 0 && OPCODE_2 == 0) {
4781 CP15_REG(CP15_DOMAIN_ACCESS_CONTROL) = RD;
4782 } else if(CRn == MMU_CACHE_OPS){
4783 //LOG_WARNING(Core_ARM11, "cache operations have not implemented.");
4784 } else if(CRn == MMU_TLB_OPS){
4785 switch (CRm) {
4786 case 5: // ITLB
4787 switch(OPCODE_2) {
4788 case 0: // Invalidate all
4789 LOG_DEBUG(Core_ARM11, "{TLB} [INSN] invalidate all");
4790 break;
4791 case 1: // Invalidate by MVA
4792 LOG_DEBUG(Core_ARM11, "{TLB} [INSN] invalidate by mva");
4793 break;
4794 case 2: // Invalidate by asid
4795 LOG_DEBUG(Core_ARM11, "{TLB} [INSN] invalidate by asid");
4796 break;
4797 default:
4798 break;
4799 }
4800
4801 break;
4802 case 6: // DTLB
4803 switch(OPCODE_2){
4804 case 0: // Invalidate all
4805 LOG_DEBUG(Core_ARM11, "{TLB} [DATA] invalidate all");
4806 break;
4807 case 1: // Invalidate by MVA
4808 LOG_DEBUG(Core_ARM11, "{TLB} [DATA] invalidate by mva");
4809 break;
4810 case 2: // Invalidate by asid
4811 LOG_DEBUG(Core_ARM11, "{TLB} [DATA] invalidate by asid");
4812 break;
4813 default:
4814 break;
4815 }
4816 break;
4817 case 7: // UNIFILED TLB
4818 switch(OPCODE_2){
4819 case 0: // invalidate all
4820 LOG_DEBUG(Core_ARM11, "{TLB} [UNIFILED] invalidate all");
4821 break;
4822 case 1: // Invalidate by MVA
4823 LOG_DEBUG(Core_ARM11, "{TLB} [UNIFILED] invalidate by mva");
4824 break;
4825 case 2: // Invalidate by asid
4826 LOG_DEBUG(Core_ARM11, "{TLB} [UNIFILED] invalidate by asid");
4827 break;
4828 default:
4829 break;
4830 }
4831 break;
4832 default:
4833 break;
4834 }
4835 } else if(CRn == MMU_PID) {
4836 if(OPCODE_2 == 0) {
4837 CP15_REG(CP15_PID) = RD;
4838 } else if(OPCODE_2 == 1) {
4839 CP15_REG(CP15_CONTEXT_ID) = RD;
4840 } else if (OPCODE_2 == 2) {
4841 CP15_REG(CP15_THREAD_UPRW) = RD;
4842 } else if(OPCODE_2 == 3) {
4843 if (InAPrivilegedMode(cpu))
4844 CP15_REG(CP15_THREAD_URO) = RD;
4845 } else if (OPCODE_2 == 4) {
4846 if (InAPrivilegedMode(cpu))
4847 CP15_REG(CP15_THREAD_PRW) = RD;
4848 } else {
4849 LOG_ERROR(Core_ARM11, "mmu_mcr wrote UNKNOWN - reg %d", CRn);
4850 }
4851 } else {
4852 LOG_ERROR(Core_ARM11, "mcr CRn=%d, CRm=%d OP2=%d is not implemented", CRn, CRm, OPCODE_2);
4853 }
4854 }
4855 } 4766 }
4856 } 4767 }
4857 cpu->Reg[15] += GET_INST_SIZE(cpu); 4768 cpu->Reg[15] += GET_INST_SIZE(cpu);
@@ -4926,50 +4837,8 @@ unsigned InterpreterMainLoop(ARMul_State* state) {
4926 CITRA_IGNORE_EXIT(-1); 4837 CITRA_IGNORE_EXIT(-1);
4927 goto END; 4838 goto END;
4928 } else { 4839 } else {
4929 if (inst_cream->cp_num == 15) { 4840 if (inst_cream->cp_num == 15)
4930 if(CRn == 0 && OPCODE_2 == 0 && CRm == 0) { 4841 RD = ReadCP15Register(cpu, CRn, OPCODE_1, CRm, OPCODE_2);
4931 RD = cpu->CP15[CP15(CP15_MAIN_ID)];
4932 } else if (CRn == 0 && CRm == 0 && OPCODE_2 == 1) {
4933 RD = cpu->CP15[CP15(CP15_CACHE_TYPE)];
4934 } else if (CRn == 1 && CRm == 0 && OPCODE_2 == 0) {
4935 RD = cpu->CP15[CP15(CP15_CONTROL)];
4936 } else if (CRn == 1 && CRm == 0 && OPCODE_2 == 1) {
4937 RD = cpu->CP15[CP15(CP15_AUXILIARY_CONTROL)];
4938 } else if (CRn == 1 && CRm == 0 && OPCODE_2 == 2) {
4939 RD = cpu->CP15[CP15(CP15_COPROCESSOR_ACCESS_CONTROL)];
4940 } else if (CRn == 2 && CRm == 0 && OPCODE_2 == 0) {
4941 RD = cpu->CP15[CP15(CP15_TRANSLATION_BASE_TABLE_0)];
4942 } else if (CRn == 2 && CRm == 0 && OPCODE_2 == 1) {
4943 RD = cpu->CP15[CP15(CP15_TRANSLATION_BASE_TABLE_1)];
4944 } else if (CRn == 2 && CRm == 0 && OPCODE_2 == 2) {
4945 RD = cpu->CP15[CP15(CP15_TRANSLATION_BASE_CONTROL)];
4946 } else if (CRn == 3 && CRm == 0 && OPCODE_2 == 0) {
4947 RD = cpu->CP15[CP15(CP15_DOMAIN_ACCESS_CONTROL)];
4948 } else if (CRn == 5 && CRm == 0 && OPCODE_2 == 0) {
4949 RD = cpu->CP15[CP15(CP15_FAULT_STATUS)];
4950 } else if (CRn == 5 && CRm == 0 && OPCODE_2 == 1) {
4951 RD = cpu->CP15[CP15(CP15_INSTR_FAULT_STATUS)];
4952 } else if (CRn == 6 && CRm == 0 && OPCODE_2 == 0) {
4953 RD = cpu->CP15[CP15(CP15_FAULT_ADDRESS)];
4954 } else if (CRn == 13) {
4955 if(OPCODE_2 == 0) {
4956 RD = CP15_REG(CP15_PID);
4957 } else if(OPCODE_2 == 1) {
4958 RD = CP15_REG(CP15_CONTEXT_ID);
4959 } else if (OPCODE_2 == 2) {
4960 RD = CP15_REG(CP15_THREAD_UPRW);
4961 } else if(OPCODE_2 == 3) {
4962 RD = Memory::KERNEL_MEMORY_VADDR;
4963 } else if (OPCODE_2 == 4) {
4964 if (InAPrivilegedMode(cpu))
4965 RD = CP15_REG(CP15_THREAD_PRW);
4966 } else {
4967 LOG_ERROR(Core_ARM11, "mmu_mrr wrote UNKNOWN - reg %d", CRn);
4968 }
4969 } else {
4970 LOG_ERROR(Core_ARM11, "mrc CRn=%d, CRm=%d, OP2=%d is not implemented", CRn, CRm, OPCODE_2);
4971 }
4972 }
4973 } 4842 }
4974 } 4843 }
4975 cpu->Reg[15] += GET_INST_SIZE(cpu); 4844 cpu->Reg[15] += GET_INST_SIZE(cpu);
diff --git a/src/core/arm/interpreter/armsupp.cpp b/src/core/arm/interpreter/armsupp.cpp
index aca2bfbbd..6a11a5804 100644
--- a/src/core/arm/interpreter/armsupp.cpp
+++ b/src/core/arm/interpreter/armsupp.cpp
@@ -15,7 +15,9 @@
15 along with this program; if not, write to the Free Software 15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ 16 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
17 17
18#include "core/mem_map.h"
18#include "core/arm/skyeye_common/armdefs.h" 19#include "core/arm/skyeye_common/armdefs.h"
20#include "core/arm/skyeye_common/arm_regformat.h"
19 21
20// Unsigned sum of absolute difference 22// Unsigned sum of absolute difference
21u8 ARMul_UnsignedAbsoluteDifference(u8 left, u8 right) 23u8 ARMul_UnsignedAbsoluteDifference(u8 left, u8 right)
@@ -207,3 +209,432 @@ bool InBigEndianMode(ARMul_State* cpu)
207{ 209{
208 return (cpu->Cpsr & (1 << 9)) != 0; 210 return (cpu->Cpsr & (1 << 9)) != 0;
209} 211}
212
213// Whether or not the given CPU is in a mode other than user mode.
214bool InAPrivilegedMode(ARMul_State* cpu)
215{
216 return (cpu->Mode != USER32MODE);
217}
218
219// Reads from the CP15 registers. Used with implementation of the MRC instruction.
220// Note that since the 3DS does not have the hypervisor extensions, these registers
221// are not implemented.
222u32 ReadCP15Register(ARMul_State* cpu, u32 crn, u32 opcode_1, u32 crm, u32 opcode_2)
223{
224 // Unprivileged registers
225 if (crn == 13 && opcode_1 == 0 && crm == 0)
226 {
227 if (opcode_2 == 2)
228 return cpu->CP15[CP15(CP15_THREAD_UPRW)];
229
230 // TODO: Whenever TLS is implemented, this should return
231 // "cpu->CP15[CP15(CP15_THREAD_URO)];"
232 // which contains the address of the 0x200-byte TLS
233 if (opcode_2 == 3)
234 return Memory::KERNEL_MEMORY_VADDR;
235 }
236
237 if (InAPrivilegedMode(cpu))
238 {
239 if (crn == 0 && opcode_1 == 0)
240 {
241 if (crm == 0)
242 {
243 if (opcode_2 == 0)
244 return cpu->CP15[CP15(CP15_MAIN_ID)];
245
246 if (opcode_2 == 1)
247 return cpu->CP15[CP15(CP15_CACHE_TYPE)];
248
249 if (opcode_2 == 3)
250 return cpu->CP15[CP15(CP15_TLB_TYPE)];
251
252 if (opcode_2 == 5)
253 return cpu->CP15[CP15(CP15_CPU_ID)];
254 }
255 else if (crm == 1)
256 {
257 if (opcode_2 == 0)
258 return cpu->CP15[CP15(CP15_PROCESSOR_FEATURE_0)];
259
260 if (opcode_2 == 1)
261 return cpu->CP15[CP15(CP15_PROCESSOR_FEATURE_1)];
262
263 if (opcode_2 == 2)
264 return cpu->CP15[CP15(CP15_DEBUG_FEATURE_0)];
265
266 if (opcode_2 == 4)
267 return cpu->CP15[CP15(CP15_MEMORY_MODEL_FEATURE_0)];
268
269 if (opcode_2 == 5)
270 return cpu->CP15[CP15(CP15_MEMORY_MODEL_FEATURE_1)];
271
272 if (opcode_2 == 6)
273 return cpu->CP15[CP15(CP15_MEMORY_MODEL_FEATURE_2)];
274
275 if (opcode_2 == 7)
276 return cpu->CP15[CP15(CP15_MEMORY_MODEL_FEATURE_3)];
277 }
278 else if (crm == 2)
279 {
280 if (opcode_2 == 0)
281 return cpu->CP15[CP15(CP15_ISA_FEATURE_0)];
282
283 if (opcode_2 == 1)
284 return cpu->CP15[CP15(CP15_ISA_FEATURE_1)];
285
286 if (opcode_2 == 2)
287 return cpu->CP15[CP15(CP15_ISA_FEATURE_2)];
288
289 if (opcode_2 == 3)
290 return cpu->CP15[CP15(CP15_ISA_FEATURE_3)];
291
292 if (opcode_2 == 4)
293 return cpu->CP15[CP15(CP15_ISA_FEATURE_4)];
294 }
295 }
296
297 if (crn == 1 && opcode_1 == 0 && crm == 0)
298 {
299 if (opcode_2 == 0)
300 return cpu->CP15[CP15(CP15_CONTROL)];
301
302 if (opcode_2 == 1)
303 return cpu->CP15[CP15(CP15_AUXILIARY_CONTROL)];
304
305 if (opcode_2 == 2)
306 return cpu->CP15[CP15(CP15_COPROCESSOR_ACCESS_CONTROL)];
307 }
308
309 if (crn == 2 && opcode_1 == 0 && crm == 0)
310 {
311 if (opcode_2 == 0)
312 return cpu->CP15[CP15(CP15_TRANSLATION_BASE_TABLE_0)];
313
314 if (opcode_2 == 1)
315 return cpu->CP15[CP15(CP15_TRANSLATION_BASE_TABLE_1)];
316
317 if (opcode_2 == 2)
318 return cpu->CP15[CP15(CP15_TRANSLATION_BASE_CONTROL)];
319 }
320
321 if (crn == 3 && opcode_1 == 0 && crm == 0 && opcode_2 == 0)
322 return cpu->CP15[CP15(CP15_DOMAIN_ACCESS_CONTROL)];
323
324 if (crn == 5 && opcode_1 == 0 && crm == 0)
325 {
326 if (opcode_2 == 0)
327 return cpu->CP15[CP15(CP15_FAULT_STATUS)];
328
329 if (opcode_2 == 1)
330 return cpu->CP15[CP15(CP15_INSTR_FAULT_STATUS)];
331 }
332
333 if (crn == 6 && opcode_1 == 0 && crm == 0)
334 {
335 if (opcode_2 == 0)
336 return cpu->CP15[CP15(CP15_FAULT_ADDRESS)];
337
338 if (opcode_2 == 1)
339 return cpu->CP15[CP15(CP15_WFAR)];
340 }
341
342 if (crn == 7 && opcode_1 == 0 && crm == 4 && opcode_2 == 0)
343 return cpu->CP15[CP15(CP15_PHYS_ADDRESS)];
344
345 if (crn == 9 && opcode_1 == 0 && crm == 0 && opcode_2 == 0)
346 return cpu->CP15[CP15(CP15_DATA_CACHE_LOCKDOWN)];
347
348 if (crn == 10 && opcode_1 == 0)
349 {
350 if (crm == 0 && opcode_2 == 0)
351 return cpu->CP15[CP15(CP15_TLB_LOCKDOWN)];
352
353 if (crm == 2)
354 {
355 if (opcode_2 == 0)
356 return cpu->CP15[CP15(CP15_PRIMARY_REGION_REMAP)];
357
358 if (opcode_2 == 1)
359 return cpu->CP15[CP15(CP15_NORMAL_REGION_REMAP)];
360 }
361 }
362
363 if (crn == 13 && crm == 0)
364 {
365 if (opcode_2 == 0)
366 return cpu->CP15[CP15(CP15_PID)];
367
368 if (opcode_2 == 1)
369 return cpu->CP15[CP15(CP15_CONTEXT_ID)];
370
371 if (opcode_2 == 4)
372 return cpu->CP15[CP15(CP15_THREAD_PRW)];
373 }
374
375 if (crn == 15)
376 {
377 if (opcode_1 == 0 && crm == 12)
378 {
379 if (opcode_2 == 0)
380 return cpu->CP15[CP15(CP15_PERFORMANCE_MONITOR_CONTROL)];
381
382 if (opcode_2 == 1)
383 return cpu->CP15[CP15(CP15_CYCLE_COUNTER)];
384
385 if (opcode_2 == 2)
386 return cpu->CP15[CP15(CP15_COUNT_0)];
387
388 if (opcode_2 == 3)
389 return cpu->CP15[CP15(CP15_COUNT_1)];
390 }
391
392 if (opcode_1 == 5 && opcode_2 == 2)
393 {
394 if (crm == 5)
395 return cpu->CP15[CP15(CP15_MAIN_TLB_LOCKDOWN_VIRT_ADDRESS)];
396
397 if (crm == 6)
398 return cpu->CP15[CP15(CP15_MAIN_TLB_LOCKDOWN_PHYS_ADDRESS)];
399
400 if (crm == 7)
401 return cpu->CP15[CP15(CP15_MAIN_TLB_LOCKDOWN_ATTRIBUTE)];
402 }
403
404 if (opcode_1 == 7 && crm == 1 && opcode_2 == 0)
405 return cpu->CP15[CP15(CP15_TLB_DEBUG_CONTROL)];
406 }
407 }
408
409 LOG_ERROR(Core_ARM11, "MRC CRn=%u, CRm=%u, OP1=%u OP2=%u is not implemented. Returning zero.", crn, crm, opcode_1, opcode_2);
410 return 0;
411}
412
413// Write to the CP15 registers. Used with implementation of the MCR instruction.
414// Note that since the 3DS does not have the hypervisor extensions, these registers
415// are not implemented.
416void WriteCP15Register(ARMul_State* cpu, u32 value, u32 crn, u32 opcode_1, u32 crm, u32 opcode_2)
417{
418 if (InAPrivilegedMode(cpu))
419 {
420 if (crn == 1 && opcode_1 == 0 && crm == 0)
421 {
422 if (opcode_2 == 0)
423 cpu->CP15[CP15(CP15_CONTROL)] = value;
424 else if (opcode_2 == 1)
425 cpu->CP15[CP15(CP15_AUXILIARY_CONTROL)] = value;
426 else if (opcode_2 == 2)
427 cpu->CP15[CP15(CP15_COPROCESSOR_ACCESS_CONTROL)] = value;
428 }
429 else if (crn == 2 && opcode_1 == 0 && crm == 0)
430 {
431 if (opcode_2 == 0)
432 cpu->CP15[CP15(CP15_TRANSLATION_BASE_TABLE_0)] = value;
433 else if (opcode_2 == 1)
434 cpu->CP15[CP15(CP15_TRANSLATION_BASE_TABLE_1)] = value;
435 else if (opcode_2 == 2)
436 cpu->CP15[CP15(CP15_TRANSLATION_BASE_CONTROL)] = value;
437 }
438 else if (crn == 3 && opcode_1 == 0 && crm == 0 && opcode_2 == 0)
439 {
440 cpu->CP15[CP15(CP15_DOMAIN_ACCESS_CONTROL)] = value;
441 }
442 else if (crn == 5 && opcode_1 == 0 && crm == 0)
443 {
444 if (opcode_2 == 0)
445 cpu->CP15[CP15(CP15_FAULT_STATUS)] = value;
446 else if (opcode_2 == 1)
447 cpu->CP15[CP15(CP15_INSTR_FAULT_STATUS)] = value;
448 }
449 else if (crn == 6 && opcode_1 == 0 && crm == 0)
450 {
451 if (opcode_2 == 0)
452 cpu->CP15[CP15(CP15_FAULT_ADDRESS)] = value;
453 else if (opcode_2 == 1)
454 cpu->CP15[CP15(CP15_WFAR)] = value;
455 }
456 else if (crn == 7 && opcode_1 == 0)
457 {
458 LOG_WARNING(Core_ARM11, "Cache operations are not fully implemented.");
459
460 if (crm == 0 && opcode_2 == 4)
461 {
462 cpu->CP15[CP15(CP15_WAIT_FOR_INTERRUPT)] = value;
463 }
464 else if (crm == 4 && opcode_2 == 0)
465 {
466 // NOTE: Not entirely accurate. This should do permission checks.
467 cpu->CP15[CP15(CP15_PHYS_ADDRESS)] = Memory::VirtualToPhysicalAddress(value);
468 }
469 else if (crm == 5)
470 {
471 if (opcode_2 == 0)
472 cpu->CP15[CP15(CP15_INVALIDATE_INSTR_CACHE)] = value;
473 else if (opcode_2 == 1)
474 cpu->CP15[CP15(CP15_INVALIDATE_INSTR_CACHE_USING_MVA)] = value;
475 else if (opcode_2 == 2)
476 cpu->CP15[CP15(CP15_INVALIDATE_INSTR_CACHE_USING_INDEX)] = value;
477 else if (opcode_2 == 6)
478 cpu->CP15[CP15(CP15_FLUSH_BRANCH_TARGET_CACHE)] = value;
479 else if (opcode_2 == 7)
480 cpu->CP15[CP15(CP15_FLUSH_BRANCH_TARGET_CACHE_ENTRY)] = value;
481 }
482 else if (crm == 6)
483 {
484 if (opcode_2 == 0)
485 cpu->CP15[CP15(CP15_INVALIDATE_DATA_CACHE)] = value;
486 else if (opcode_2 == 1)
487 cpu->CP15[CP15(CP15_INVALIDATE_DATA_CACHE_LINE_USING_MVA)] = value;
488 else if (opcode_2 == 2)
489 cpu->CP15[CP15(CP15_INVALIDATE_DATA_CACHE_LINE_USING_INDEX)] = value;
490 }
491 else if (crm == 7 && opcode_2 == 0)
492 {
493 cpu->CP15[CP15(CP15_INVALIDATE_DATA_AND_INSTR_CACHE)] = value;
494 }
495 else if (crm == 10)
496 {
497 if (opcode_2 == 0)
498 cpu->CP15[CP15(CP15_CLEAN_DATA_CACHE)] = value;
499 else if (opcode_2 == 1)
500 cpu->CP15[CP15(CP15_CLEAN_DATA_CACHE_LINE_USING_MVA)] = value;
501 else if (opcode_2 == 2)
502 cpu->CP15[CP15(CP15_CLEAN_DATA_CACHE_LINE_USING_INDEX)] = value;
503 }
504 else if (crm == 14)
505 {
506 if (opcode_2 == 0)
507 cpu->CP15[CP15(CP15_CLEAN_AND_INVALIDATE_DATA_CACHE)] = value;
508 else if (opcode_2 == 1)
509 cpu->CP15[CP15(CP15_CLEAN_AND_INVALIDATE_DATA_CACHE_LINE_USING_MVA)] = value;
510 else if (opcode_2 == 2)
511 cpu->CP15[CP15(CP15_CLEAN_AND_INVALIDATE_DATA_CACHE_LINE_USING_INDEX)] = value;
512 }
513 }
514 else if (crn == 8 && opcode_1 == 0)
515 {
516 LOG_WARNING(Core_ARM11, "TLB operations not fully implemented.");
517
518 if (crm == 5)
519 {
520 if (opcode_2 == 0)
521 cpu->CP15[CP15(CP15_INVALIDATE_ITLB)] = value;
522 else if (opcode_2 == 1)
523 cpu->CP15[CP15(CP15_INVALIDATE_ITLB_SINGLE_ENTRY)] = value;
524 else if (opcode_2 == 2)
525 cpu->CP15[CP15(CP15_INVALIDATE_ITLB_ENTRY_ON_ASID_MATCH)] = value;
526 else if (opcode_2 == 3)
527 cpu->CP15[CP15(CP15_INVALIDATE_ITLB_ENTRY_ON_MVA)] = value;
528 }
529 else if (crm == 6)
530 {
531 if (opcode_2 == 0)
532 cpu->CP15[CP15(CP15_INVALIDATE_DTLB)] = value;
533 else if (opcode_2 == 1)
534 cpu->CP15[CP15(CP15_INVALIDATE_DTLB_SINGLE_ENTRY)] = value;
535 else if (opcode_2 == 2)
536 cpu->CP15[CP15(CP15_INVALIDATE_DTLB_ENTRY_ON_ASID_MATCH)] = value;
537 else if (opcode_2 == 3)
538 cpu->CP15[CP15(CP15_INVALIDATE_DTLB_ENTRY_ON_MVA)] = value;
539 }
540 else if (crm == 7)
541 {
542 if (opcode_2 == 0)
543 cpu->CP15[CP15(CP15_INVALIDATE_UTLB)] = value;
544 else if (opcode_2 == 1)
545 cpu->CP15[CP15(CP15_INVALIDATE_UTLB_SINGLE_ENTRY)] = value;
546 else if (opcode_2 == 2)
547 cpu->CP15[CP15(CP15_INVALIDATE_UTLB_ENTRY_ON_ASID_MATCH)] = value;
548 else if (opcode_2 == 3)
549 cpu->CP15[CP15(CP15_INVALIDATE_UTLB_ENTRY_ON_MVA)] = value;
550 }
551 }
552 else if (crn == 9 && opcode_1 == 0 && crm == 0 && opcode_2 == 0)
553 {
554 cpu->CP15[CP15(CP15_DATA_CACHE_LOCKDOWN)] = value;
555 }
556 else if (crn == 10 && opcode_1 == 0)
557 {
558 if (crm == 0 && opcode_2 == 0)
559 {
560 cpu->CP15[CP15(CP15_TLB_LOCKDOWN)] = value;
561 }
562 else if (crm == 2)
563 {
564 if (opcode_2 == 0)
565 cpu->CP15[CP15(CP15_PRIMARY_REGION_REMAP)] = value;
566 else if (opcode_2 == 1)
567 cpu->CP15[CP15(CP15_NORMAL_REGION_REMAP)] = value;
568 }
569 }
570 else if (crn == 13 && opcode_1 == 0 && crm == 0)
571 {
572 if (opcode_2 == 0)
573 cpu->CP15[CP15(CP15_PID)] = value;
574 else if (opcode_2 == 1)
575 cpu->CP15[CP15(CP15_CONTEXT_ID)] = value;
576 else if (opcode_2 == 3)
577 cpu->CP15[CP15(CP15_THREAD_URO)] = value;
578 else if (opcode_2 == 4)
579 cpu->CP15[CP15(CP15_THREAD_PRW)] = value;
580 }
581 else if (crn == 15)
582 {
583 if (opcode_1 == 0 && crm == 12)
584 {
585 if (opcode_2 == 0)
586 cpu->CP15[CP15(CP15_PERFORMANCE_MONITOR_CONTROL)] = value;
587 else if (opcode_2 == 1)
588 cpu->CP15[CP15(CP15_CYCLE_COUNTER)] = value;
589 else if (opcode_2 == 2)
590 cpu->CP15[CP15(CP15_COUNT_0)] = value;
591 else if (opcode_2 == 3)
592 cpu->CP15[CP15(CP15_COUNT_1)] = value;
593 }
594 else if (opcode_1 == 5)
595 {
596 if (crm == 4)
597 {
598 if (opcode_2 == 2)
599 cpu->CP15[CP15(CP15_READ_MAIN_TLB_LOCKDOWN_ENTRY)] = value;
600 else if (opcode_2 == 4)
601 cpu->CP15[CP15(CP15_WRITE_MAIN_TLB_LOCKDOWN_ENTRY)] = value;
602 }
603 else if (crm == 5 && opcode_2 == 2)
604 {
605 cpu->CP15[CP15(CP15_MAIN_TLB_LOCKDOWN_VIRT_ADDRESS)] = value;
606 }
607 else if (crm == 6 && opcode_2 == 2)
608 {
609 cpu->CP15[CP15(CP15_MAIN_TLB_LOCKDOWN_PHYS_ADDRESS)] = value;
610 }
611 else if (crm == 7 && opcode_2 == 2)
612 {
613 cpu->CP15[CP15(CP15_MAIN_TLB_LOCKDOWN_ATTRIBUTE)] = value;
614 }
615 }
616 else if (opcode_1 == 7 && crm == 1 && opcode_2 == 0)
617 {
618 cpu->CP15[CP15(CP15_TLB_DEBUG_CONTROL)] = value;
619 }
620 }
621 }
622
623 // Unprivileged registers
624 if (crn == 7 && opcode_1 == 0 && crm == 5 && opcode_2 == 4)
625 {
626 cpu->CP15[CP15(CP15_FLUSH_PREFETCH_BUFFER)] = value;
627 }
628 else if (crn == 7 && opcode_1 == 0 && crm == 10)
629 {
630 if (opcode_2 == 4)
631 cpu->CP15[CP15(CP15_DATA_SYNC_BARRIER)] = value;
632 else if (opcode_2 == 5)
633 cpu->CP15[CP15(CP15_DATA_MEMORY_BARRIER)] = value;
634
635 }
636 else if (crn == 13 && opcode_1 == 0 && crm == 0 && opcode_2 == 2)
637 {
638 cpu->CP15[CP15(CP15_THREAD_UPRW)] = value;
639 }
640}
diff --git a/src/core/arm/skyeye_common/arm_regformat.h b/src/core/arm/skyeye_common/arm_regformat.h
index 5be3a561f..c232376e0 100644
--- a/src/core/arm/skyeye_common/arm_regformat.h
+++ b/src/core/arm/skyeye_common/arm_regformat.h
@@ -50,6 +50,8 @@ enum {
50 EXCLUSIVE_TAG, 50 EXCLUSIVE_TAG,
51 EXCLUSIVE_STATE, 51 EXCLUSIVE_STATE,
52 EXCLUSIVE_RESULT, 52 EXCLUSIVE_RESULT,
53
54 // c0 - Information registers
53 CP15_BASE, 55 CP15_BASE,
54 CP15_C0 = CP15_BASE, 56 CP15_C0 = CP15_BASE,
55 CP15_C0_C0 = CP15_C0, 57 CP15_C0_C0 = CP15_C0,
@@ -57,15 +59,30 @@ enum {
57 CP15_CACHE_TYPE, 59 CP15_CACHE_TYPE,
58 CP15_TCM_STATUS, 60 CP15_TCM_STATUS,
59 CP15_TLB_TYPE, 61 CP15_TLB_TYPE,
62 CP15_CPU_ID,
60 CP15_C0_C1, 63 CP15_C0_C1,
61 CP15_PROCESSOR_FEATURE_0 = CP15_C0_C1, 64 CP15_PROCESSOR_FEATURE_0 = CP15_C0_C1,
62 CP15_PROCESSOR_FEATURE_1, 65 CP15_PROCESSOR_FEATURE_1,
63 CP15_DEBUG_FEATURE_0, 66 CP15_DEBUG_FEATURE_0,
64 CP15_AUXILIARY_FEATURE_0, 67 CP15_AUXILIARY_FEATURE_0,
68 CP15_MEMORY_MODEL_FEATURE_0,
69 CP15_MEMORY_MODEL_FEATURE_1,
70 CP15_MEMORY_MODEL_FEATURE_2,
71 CP15_MEMORY_MODEL_FEATURE_3,
72 CP15_C0_C2,
73 CP15_ISA_FEATURE_0 = CP15_C0_C2,
74 CP15_ISA_FEATURE_1,
75 CP15_ISA_FEATURE_2,
76 CP15_ISA_FEATURE_3,
77 CP15_ISA_FEATURE_4,
78
79 // c1 - Control registers
65 CP15_C1_C0, 80 CP15_C1_C0,
66 CP15_CONTROL = CP15_C1_C0, 81 CP15_CONTROL = CP15_C1_C0,
67 CP15_AUXILIARY_CONTROL, 82 CP15_AUXILIARY_CONTROL,
68 CP15_COPROCESSOR_ACCESS_CONTROL, 83 CP15_COPROCESSOR_ACCESS_CONTROL,
84
85 // c2 - Translation table registers
69 CP15_C2, 86 CP15_C2,
70 CP15_C2_C0 = CP15_C2, 87 CP15_C2_C0 = CP15_C2,
71 CP15_TRANSLATION_BASE = CP15_C2_C0, 88 CP15_TRANSLATION_BASE = CP15_C2_C0,
@@ -74,24 +91,87 @@ enum {
74 CP15_TRANSLATION_BASE_CONTROL, 91 CP15_TRANSLATION_BASE_CONTROL,
75 CP15_DOMAIN_ACCESS_CONTROL, 92 CP15_DOMAIN_ACCESS_CONTROL,
76 CP15_RESERVED, 93 CP15_RESERVED,
77 /* Fault status */ 94
95 // c5 - Fault status registers
78 CP15_FAULT_STATUS, 96 CP15_FAULT_STATUS,
79 CP15_INSTR_FAULT_STATUS, 97 CP15_INSTR_FAULT_STATUS,
80 CP15_COMBINED_DATA_FSR = CP15_FAULT_STATUS, 98 CP15_COMBINED_DATA_FSR = CP15_FAULT_STATUS,
81 CP15_INST_FSR, 99 CP15_INST_FSR,
82 /* Fault Address register */ 100
101 // c6 - Fault Address registers
83 CP15_FAULT_ADDRESS, 102 CP15_FAULT_ADDRESS,
84 CP15_COMBINED_DATA_FAR = CP15_FAULT_ADDRESS, 103 CP15_COMBINED_DATA_FAR = CP15_FAULT_ADDRESS,
85 CP15_WFAR, 104 CP15_WFAR,
86 CP15_IFAR, 105 CP15_IFAR,
106
107 // c7 - Cache operation registers
108 CP15_WAIT_FOR_INTERRUPT,
109 CP15_PHYS_ADDRESS,
110 CP15_INVALIDATE_INSTR_CACHE,
111 CP15_INVALIDATE_INSTR_CACHE_USING_MVA,
112 CP15_INVALIDATE_INSTR_CACHE_USING_INDEX,
113 CP15_FLUSH_PREFETCH_BUFFER,
114 CP15_FLUSH_BRANCH_TARGET_CACHE,
115 CP15_FLUSH_BRANCH_TARGET_CACHE_ENTRY,
116 CP15_INVALIDATE_DATA_CACHE,
117 CP15_INVALIDATE_DATA_CACHE_LINE_USING_MVA,
118 CP15_INVALIDATE_DATA_CACHE_LINE_USING_INDEX,
119 CP15_INVALIDATE_DATA_AND_INSTR_CACHE,
120 CP15_CLEAN_DATA_CACHE,
121 CP15_CLEAN_DATA_CACHE_LINE_USING_MVA,
122 CP15_CLEAN_DATA_CACHE_LINE_USING_INDEX,
123 CP15_DATA_SYNC_BARRIER,
124 CP15_DATA_MEMORY_BARRIER,
125 CP15_CLEAN_AND_INVALIDATE_DATA_CACHE,
126 CP15_CLEAN_AND_INVALIDATE_DATA_CACHE_LINE_USING_MVA,
127 CP15_CLEAN_AND_INVALIDATE_DATA_CACHE_LINE_USING_INDEX,
128
129 // c8 - TLB operations
130 CP15_INVALIDATE_ITLB,
131 CP15_INVALIDATE_ITLB_SINGLE_ENTRY,
132 CP15_INVALIDATE_ITLB_ENTRY_ON_ASID_MATCH,
133 CP15_INVALIDATE_ITLB_ENTRY_ON_MVA,
134 CP15_INVALIDATE_DTLB,
135 CP15_INVALIDATE_DTLB_SINGLE_ENTRY,
136 CP15_INVALIDATE_DTLB_ENTRY_ON_ASID_MATCH,
137 CP15_INVALIDATE_DTLB_ENTRY_ON_MVA,
138 CP15_INVALIDATE_UTLB,
139 CP15_INVALIDATE_UTLB_SINGLE_ENTRY,
140 CP15_INVALIDATE_UTLB_ENTRY_ON_ASID_MATCH,
141 CP15_INVALIDATE_UTLB_ENTRY_ON_MVA,
142
143 // c9 - Data cache lockdown register
144 CP15_DATA_CACHE_LOCKDOWN,
145
146 // c10 - TLB/Memory map registers
147 CP15_TLB_LOCKDOWN,
148 CP15_PRIMARY_REGION_REMAP,
149 CP15_NORMAL_REGION_REMAP,
150
151 // c13 - Thread related registers
87 CP15_PID, 152 CP15_PID,
88 CP15_CONTEXT_ID, 153 CP15_CONTEXT_ID,
89 CP15_THREAD_UPRW, // Thread ID register - User/Privileged Read/Write 154 CP15_THREAD_UPRW, // Thread ID register - User/Privileged Read/Write
90 CP15_THREAD_URO, // Thread ID register - User Read Only (Privileged R/W) 155 CP15_THREAD_URO, // Thread ID register - User Read Only (Privileged R/W)
91 CP15_THREAD_PRW, // Thread ID register - Privileged R/W only. 156 CP15_THREAD_PRW, // Thread ID register - Privileged R/W only.
92 CP15_TLB_FAULT_ADDR, /* defined by SkyEye */ 157
93 CP15_TLB_FAULT_STATUS, /* defined by SkyEye */ 158 // c15 - Performance and TLB lockdown registers
94 /* VFP registers */ 159 CP15_PERFORMANCE_MONITOR_CONTROL,
160 CP15_CYCLE_COUNTER,
161 CP15_COUNT_0,
162 CP15_COUNT_1,
163 CP15_READ_MAIN_TLB_LOCKDOWN_ENTRY,
164 CP15_WRITE_MAIN_TLB_LOCKDOWN_ENTRY,
165 CP15_MAIN_TLB_LOCKDOWN_VIRT_ADDRESS,
166 CP15_MAIN_TLB_LOCKDOWN_PHYS_ADDRESS,
167 CP15_MAIN_TLB_LOCKDOWN_ATTRIBUTE,
168 CP15_TLB_DEBUG_CONTROL,
169
170 // Skyeye defined
171 CP15_TLB_FAULT_ADDR,
172 CP15_TLB_FAULT_STATUS,
173
174 // VFP registers
95 VFP_BASE, 175 VFP_BASE,
96 VFP_FPSID = VFP_BASE, 176 VFP_FPSID = VFP_BASE,
97 VFP_FPSCR, 177 VFP_FPSCR,
diff --git a/src/core/arm/skyeye_common/armdefs.h b/src/core/arm/skyeye_common/armdefs.h
index c1a19fecc..d5b0242c3 100644
--- a/src/core/arm/skyeye_common/armdefs.h
+++ b/src/core/arm/skyeye_common/armdefs.h
@@ -357,3 +357,7 @@ extern u32 ARMul_SignedSatQ(s32, u8, bool*);
357extern u32 ARMul_UnsignedSatQ(s32, u8, bool*); 357extern u32 ARMul_UnsignedSatQ(s32, u8, bool*);
358 358
359extern bool InBigEndianMode(ARMul_State*); 359extern bool InBigEndianMode(ARMul_State*);
360extern bool InAPrivilegedMode(ARMul_State*);
361
362extern u32 ReadCP15Register(ARMul_State* cpu, u32 crn, u32 opcode_1, u32 crm, u32 opcode_2);
363extern void WriteCP15Register(ARMul_State* cpu, u32 value, u32 crn, u32 opcode_1, u32 crm, u32 opcode_2);