1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * Mupen64plus - linkage_arm.s *
3 * Copyright (C) 2009-2010 Ari64 *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. *
19 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
45 .global pending_exception
59 .global restore_candidate
66 .type dynarec_local, %object
67 .size dynarec_local, dynarec_local_end-dynarec_local
69 .space dynarec_local_end-dynarec_local /*0x400630*/
70 next_interupt = dynarec_local + 64
71 .type next_interupt, %object
72 .size next_interupt, 4
73 cycle_count = next_interupt + 4
74 .type cycle_count, %object
76 last_count = cycle_count + 4
77 .type last_count, %object
79 pending_exception = last_count + 4
80 .type pending_exception, %object
81 .size pending_exception, 4
82 stop = pending_exception + 4
86 .type invc_ptr, %object
88 address = invc_ptr + 4
89 .type address, %object
91 readmem_dword = address + 4
92 readmem_word = readmem_dword
93 .type readmem_dword, %object
94 .size readmem_dword, 8
95 dword = readmem_dword + 8
106 .size byte, 1 /* 1 byte free */
119 .size psxRegs, psxRegs_end-psxRegs
127 .type reg_cop0, %object
129 reg_cop2d = reg_cop0 + 128
130 .type reg_cop2d, %object
132 reg_cop2c = reg_cop2d + 128
133 .type reg_cop2c, %object
145 interrupt = cycle + 4
146 .type interrupt, %object
148 intCycle = interrupt + 4
149 .type intCycle, %object
151 psxRegs_end = intCycle + 128
153 align0 = psxRegs_end /* just for alignment */
154 .type align0, %object
156 branch_target = align0 + 8
157 .type branch_target, %object
158 .size branch_target, 4
159 mini_ht = branch_target + 4
160 .type mini_ht, %object
162 restore_candidate = mini_ht + 256
163 .type restore_candidate, %object
164 .size restore_candidate, 512
165 memory_map = restore_candidate + 512
166 .type memory_map, %object
167 .size memory_map, 4194304
168 dynarec_local_end = memory_map + 4194304
173 .type dyna_linker, %function
175 /* r0 = virtual target address */
176 /* r1 = instruction to patch */
183 eor r2, r2, r12, lsr #12
184 and r6, r6, r12, lsr #12
188 ldr r5, [r3, r2, lsl #2]
204 add r1, r1, r12, asr #6
206 moveq pc, r4 /* Stale i-cache */
209 and r1, r7, #0xff000000
212 add r1, r1, r2, lsr #8
216 /* hash_table lookup */
219 eor r4, r0, r0, lsl #16
225 ldr r5, [r3, r2, lsl #2]
232 /* jump_dirty lookup */
242 /* hash_table insert */
253 bl new_recompile_block
261 .size dyna_linker, .-dyna_linker
262 .global exec_pagefault
263 .type exec_pagefault, %function
265 /* r0 = instruction pointer */
266 /* r1 = fault address */
268 ldr r3, [fp, #reg_cop0+48-dynarec_local] /* Status */
270 ldr r4, [fp, #reg_cop0+16-dynarec_local] /* Context */
271 bic r6, r6, #0x0F800000
272 str r0, [fp, #reg_cop0+56-dynarec_local] /* EPC */
274 str r1, [fp, #reg_cop0+32-dynarec_local] /* BadVAddr */
276 str r3, [fp, #reg_cop0+48-dynarec_local] /* Status */
277 and r5, r6, r1, lsr #9
278 str r2, [fp, #reg_cop0+52-dynarec_local] /* Cause */
279 and r1, r1, r6, lsl #9
280 str r1, [fp, #reg_cop0+40-dynarec_local] /* EntryHi */
282 str r4, [fp, #reg_cop0+16-dynarec_local] /* Context */
286 .size exec_pagefault, .-exec_pagefault
288 /* Special dynamic linker for the case where a page fault
289 may occur in a branch delay slot */
290 .global dyna_linker_ds
291 .type dyna_linker_ds, %function
293 /* r0 = virtual target address */
294 /* r1 = instruction to patch */
301 eor r2, r2, r12, lsr #12
302 and r6, r6, r12, lsr #12
306 ldr r5, [r3, r2, lsl #2]
322 add r1, r1, r12, asr #6
324 moveq pc, r4 /* Stale i-cache */
327 and r1, r7, #0xff000000
330 add r1, r1, r2, lsr #8
334 /* hash_table lookup */
337 eor r4, r0, r0, lsl #16
343 ldr r5, [r3, r2, lsl #2]
350 /* jump_dirty lookup */
360 /* hash_table insert */
373 bl new_recompile_block
380 mov r2, #0x80000008 /* High bit set indicates pagefault in delay slot */
383 .size dyna_linker_ds, .-dyna_linker_ds
392 .global jump_vaddr_r0
393 .type jump_vaddr_r0, %function
395 eor r2, r0, r0, lsl #16
397 .size jump_vaddr_r0, .-jump_vaddr_r0
398 .global jump_vaddr_r1
399 .type jump_vaddr_r1, %function
401 eor r2, r1, r1, lsl #16
404 .size jump_vaddr_r1, .-jump_vaddr_r1
405 .global jump_vaddr_r2
406 .type jump_vaddr_r2, %function
409 eor r2, r2, r2, lsl #16
411 .size jump_vaddr_r2, .-jump_vaddr_r2
412 .global jump_vaddr_r3
413 .type jump_vaddr_r3, %function
415 eor r2, r3, r3, lsl #16
418 .size jump_vaddr_r3, .-jump_vaddr_r3
419 .global jump_vaddr_r4
420 .type jump_vaddr_r4, %function
422 eor r2, r4, r4, lsl #16
425 .size jump_vaddr_r4, .-jump_vaddr_r4
426 .global jump_vaddr_r5
427 .type jump_vaddr_r5, %function
429 eor r2, r5, r5, lsl #16
432 .size jump_vaddr_r5, .-jump_vaddr_r5
433 .global jump_vaddr_r6
434 .type jump_vaddr_r6, %function
436 eor r2, r6, r6, lsl #16
439 .size jump_vaddr_r6, .-jump_vaddr_r6
440 .global jump_vaddr_r8
441 .type jump_vaddr_r8, %function
443 eor r2, r8, r8, lsl #16
446 .size jump_vaddr_r8, .-jump_vaddr_r8
447 .global jump_vaddr_r9
448 .type jump_vaddr_r9, %function
450 eor r2, r9, r9, lsl #16
453 .size jump_vaddr_r9, .-jump_vaddr_r9
454 .global jump_vaddr_r10
455 .type jump_vaddr_r10, %function
457 eor r2, r10, r10, lsl #16
460 .size jump_vaddr_r10, .-jump_vaddr_r10
461 .global jump_vaddr_r12
462 .type jump_vaddr_r12, %function
464 eor r2, r12, r12, lsl #16
467 .size jump_vaddr_r12, .-jump_vaddr_r12
468 .global jump_vaddr_r7
469 .type jump_vaddr_r7, %function
471 eor r2, r7, r7, lsl #16
473 .size jump_vaddr_r7, .-jump_vaddr_r7
475 .type jump_vaddr, %function
479 and r2, r3, r2, lsr #12
486 str r10, [fp, #cycle_count-dynarec_local]
488 ldr r10, [fp, #cycle_count-dynarec_local]
490 .size jump_vaddr, .-jump_vaddr
493 .global verify_code_ds
494 .type verify_code_ds, %function
496 str r8, [fp, #branch_target-dynarec_local]
497 .size verify_code_ds, .-verify_code_ds
498 .global verify_code_vm
499 .type verify_code_vm, %function
502 .type verify_code, %function
531 ldr r8, [fp, #branch_target-dynarec_local]
536 .size verify_code, .-verify_code
537 .size verify_code_vm, .-verify_code_vm
541 .type cc_interrupt, %function
543 ldr r0, [fp, #last_count-dynarec_local]
547 str r1, [fp, #pending_exception-dynarec_local]
548 and r2, r2, r10, lsr #17
549 add r3, fp, #restore_candidate-dynarec_local
550 str r10, [fp, #cycle-dynarec_local] /* PCSX cycles */
551 @@ str r10, [fp, #reg_cop0+36-dynarec_local] /* Count */
559 ldr r10, [fp, #cycle-dynarec_local]
560 ldr r0, [fp, #next_interupt-dynarec_local]
561 ldr r1, [fp, #pending_exception-dynarec_local]
562 ldr r2, [fp, #stop-dynarec_local]
563 str r0, [fp, #last_count-dynarec_local]
570 ldr r0, [fp, #pcaddr-dynarec_local]
575 ldmia r12, {r4, r5, r6, r7, r8, r9, sl, fp, pc}
577 /* Move 'dirty' blocks to the 'clean' list */
588 .size cc_interrupt, .-cc_interrupt
592 .type do_interrupt, %function
594 ldr r0, [fp, #pcaddr-dynarec_local]
596 ldr r1, [fp, #next_interupt-dynarec_local]
597 ldr r10, [fp, #cycle-dynarec_local]
598 str r1, [fp, #last_count-dynarec_local]
602 .size do_interrupt, .-do_interrupt
605 .type fp_exception, %function
609 ldr r1, [fp, #reg_cop0+48-dynarec_local] /* Status */
611 str r0, [fp, #reg_cop0+56-dynarec_local] /* EPC */
614 str r1, [fp, #reg_cop0+48-dynarec_local] /* Status */
615 str r2, [fp, #reg_cop0+52-dynarec_local] /* Cause */
619 .size fp_exception, .-fp_exception
621 .global fp_exception_ds
622 .type fp_exception_ds, %function
624 mov r2, #0x90000000 /* Set high bit if delay slot */
626 .size fp_exception_ds, .-fp_exception_ds
630 .type jump_syscall, %function
632 ldr r1, [fp, #reg_cop0+48-dynarec_local] /* Status */
634 str r0, [fp, #reg_cop0+56-dynarec_local] /* EPC */
637 str r1, [fp, #reg_cop0+48-dynarec_local] /* Status */
638 str r2, [fp, #reg_cop0+52-dynarec_local] /* Cause */
642 .size jump_syscall, .-jump_syscall
646 .global jump_syscall_hle
647 .type jump_syscall_hle, %function
649 str r0, [fp, #pcaddr-dynarec_local] /* PC must be set to EPC for psxException */
650 ldr r2, [fp, #last_count-dynarec_local]
651 mov r1, #0 /* in delay slot */
653 mov r0, #0x20 /* cause */
654 str r2, [fp, #cycle-dynarec_local] /* PCSX cycle counter */
657 /* note: psxException might do recorsive recompiler call from it's HLE code,
658 * so be ready for this */
660 ldr r1, [fp, #next_interupt-dynarec_local]
661 ldr r10, [fp, #cycle-dynarec_local]
662 ldr r0, [fp, #pcaddr-dynarec_local]
664 str r1, [fp, #last_count-dynarec_local]
667 .size jump_syscall_hle, .-jump_syscall_hle
671 .type jump_hlecall, %function
673 ldr r2, [fp, #last_count-dynarec_local]
674 str r0, [fp, #pcaddr-dynarec_local]
676 str r2, [fp, #cycle-dynarec_local] /* PCSX cycle counter */
679 .size jump_hlecall, .-jump_hlecall
683 .global new_dyna_leave
684 .type new_dyna_leave, %function
685 ldr r0, [fp, #last_count-dynarec_local]
688 str r10, [fp, #cycle-dynarec_local]
689 ldmia r12, {r4, r5, r6, r7, r8, r9, sl, fp, pc}
690 .size new_dyna_leave, .-new_dyna_leave
692 /* these are used to call memhandlers */
694 .global indirect_jump_indexed
695 .type indirect_jump_indexed, %function
696 indirect_jump_indexed:
697 ldr r0, [r0, r1, lsl #2]
698 .global indirect_jump
699 .type indirect_jump, %function
701 ldr r12, [fp, #last_count-dynarec_local]
703 str r2, [fp, #cycle-dynarec_local]
705 .size indirect_jump, .-indirect_jump
706 .size indirect_jump_indexed, .-indirect_jump_indexed
710 .type jump_eret, %function
712 ldr r1, [fp, #reg_cop0+48-dynarec_local] /* Status */
713 ldr r0, [fp, #last_count-dynarec_local]
716 str r1, [fp, #reg_cop0+48-dynarec_local] /* Status */
717 str r10, [fp, #cycle-dynarec_local]
719 ldr r1, [fp, #next_interupt-dynarec_local]
720 ldr r0, [fp, #reg_cop0+56-dynarec_local] /* EPC */
721 str r1, [fp, #last_count-dynarec_local]
728 str r0, [fp, #pcaddr-dynarec_local]
730 ldr r0, [fp, #pcaddr-dynarec_local]
732 .size jump_eret, .-jump_eret
735 .global new_dyna_start
736 .type new_dyna_start, %function
739 stmia r12, {r4, r5, r6, r7, r8, r9, sl, fp, lr}
741 ldr r0, [fp, #pcaddr-dynarec_local]
742 /*bl new_recompile_block*/
744 ldr r1, [fp, #next_interupt-dynarec_local]
745 ldr r10, [fp, #cycle-dynarec_local]
746 str r1, [fp, #last_count-dynarec_local]
750 .word dynarec_local+28
751 .size new_dyna_start, .-new_dyna_start
754 .global write_rdram_new
755 .type write_rdram_new, %function
757 ldr r2, [fp, #address-dynarec_local]
758 ldr r0, [fp, #word-dynarec_local]
761 .size write_rdram_new, .-write_rdram_new
763 .global write_rdramb_new
764 .type write_rdramb_new, %function
766 ldr r2, [fp, #address-dynarec_local]
767 ldrb r0, [fp, #byte-dynarec_local]
771 .size write_rdramb_new, .-write_rdramb_new
773 .global write_rdramh_new
774 .type write_rdramh_new, %function
776 ldr r2, [fp, #address-dynarec_local]
777 ldrh r0, [fp, #hword-dynarec_local]
781 .size write_rdramh_new, .-write_rdramh_new
784 .global do_invalidate
785 .type do_invalidate, %function
787 ldr r2, [fp, #address-dynarec_local]
789 ldr r1, [fp, #invc_ptr-dynarec_local]
795 .size do_invalidate, .-do_invalidate
798 .global read_nomem_new
799 .type read_nomem_new, %function
804 /* should never happen */
807 ldr r2, [fp, #address-dynarec_local]
808 add r12, fp, #memory_map-dynarec_local
810 ldr r12, [r12, r0, lsl #2]
814 ldr r0, [r2, r12, lsl #2]
815 str r0, [fp, #readmem_dword-dynarec_local]
818 .size read_nomem_new, .-read_nomem_new
821 .global read_nomemb_new
822 .type read_nomemb_new, %function
827 ldr r2, [fp, #address-dynarec_local]
828 add r12, fp, #memory_map-dynarec_local
832 ldr r12, [r12, r0, lsl #2]
836 ldr r0, [fp, #word-dynarec_local]
837 str r0, [r2, r12, lsl #2]
839 .size write_nomem_new, .-write_nomem_new
842 .global write_nomemb_new
843 .type write_nomemb_new, %function
848 ldr r2, [fp, #address-dynarec_local]
849 add r12, fp, #memory_map-dynarec_local
853 ldr r12, [r12, r0, lsl #2]
858 ldrb r0, [fp, #byte-dynarec_local]
859 strb r0, [r2, r12, lsl #2]
861 .size write_nomemb_new, .-write_nomemb_new
864 .global write_nomemh_new
865 .type write_nomemh_new, %function
870 ldr r2, [fp, #address-dynarec_local]
871 add r12, fp, #memory_map-dynarec_local
875 ldr r12, [r12, r0, lsl #2]
880 ldrh r0, [fp, #hword-dynarec_local]
883 .size write_nomemh_new, .-write_nomemh_new
887 .type breakpoint, %function
889 /* Set breakpoint here for debugging */
891 .size breakpoint, .-breakpoint
892 .section .note.GNU-stack,"",%progbits