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 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
43 .global pending_exception
57 .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
146 interrupt = cycle + 4
147 .type interrupt, %object
149 intCycle = interrupt + 4
150 .type intCycle, %object
152 psxRegs_end = intCycle + 128
154 psxHLEt_addr = psxRegs_end
155 .type psxHLEt_addr, %object
156 .size psxHLEt_addr, 4
157 align0 = psxHLEt_addr + 4 /* just for alignment */
158 .type align0, %object
160 branch_target = align0 + 4
161 .type branch_target, %object
162 .size branch_target, 4
163 mini_ht = branch_target + 4
164 .type mini_ht, %object
166 restore_candidate = mini_ht + 256
167 .type restore_candidate, %object
168 .size restore_candidate, 512
169 memory_map = restore_candidate + 512
170 .type memory_map, %object
171 .size memory_map, 4194304
172 dynarec_local_end = memory_map + 4194304
177 .type dyna_linker, %function
179 /* r0 = virtual target address */
180 /* r1 = instruction to patch */
187 eor r2, r2, r12, lsr #12
188 and r6, r6, r12, lsr #12
192 ldr r5, [r3, r2, lsl #2]
208 add r1, r1, r12, asr #6
210 moveq pc, r4 /* Stale i-cache */
213 and r1, r7, #0xff000000
216 add r1, r1, r2, lsr #8
220 /* hash_table lookup */
223 eor r4, r0, r0, lsl #16
229 ldr r5, [r3, r2, lsl #2]
236 /* jump_dirty lookup */
246 /* hash_table insert */
257 bl new_recompile_block
265 .size dyna_linker, .-dyna_linker
266 .global exec_pagefault
267 .type exec_pagefault, %function
269 /* r0 = instruction pointer */
270 /* r1 = fault address */
272 ldr r3, [fp, #reg_cop0+48-dynarec_local] /* Status */
274 ldr r4, [fp, #reg_cop0+16-dynarec_local] /* Context */
275 bic r6, r6, #0x0F800000
276 str r0, [fp, #reg_cop0+56-dynarec_local] /* EPC */
278 str r1, [fp, #reg_cop0+32-dynarec_local] /* BadVAddr */
280 str r3, [fp, #reg_cop0+48-dynarec_local] /* Status */
281 and r5, r6, r1, lsr #9
282 str r2, [fp, #reg_cop0+52-dynarec_local] /* Cause */
283 and r1, r1, r6, lsl #9
284 str r1, [fp, #reg_cop0+40-dynarec_local] /* EntryHi */
286 str r4, [fp, #reg_cop0+16-dynarec_local] /* Context */
290 .size exec_pagefault, .-exec_pagefault
292 /* Special dynamic linker for the case where a page fault
293 may occur in a branch delay slot */
294 .global dyna_linker_ds
295 .type dyna_linker_ds, %function
297 /* r0 = virtual target address */
298 /* r1 = instruction to patch */
305 eor r2, r2, r12, lsr #12
306 and r6, r6, r12, lsr #12
310 ldr r5, [r3, r2, lsl #2]
326 add r1, r1, r12, asr #6
328 moveq pc, r4 /* Stale i-cache */
331 and r1, r7, #0xff000000
334 add r1, r1, r2, lsr #8
338 /* hash_table lookup */
341 eor r4, r0, r0, lsl #16
347 ldr r5, [r3, r2, lsl #2]
354 /* jump_dirty lookup */
364 /* hash_table insert */
377 bl new_recompile_block
384 mov r2, #0x80000008 /* High bit set indicates pagefault in delay slot */
387 .size dyna_linker_ds, .-dyna_linker_ds
396 .global jump_vaddr_r0
397 .type jump_vaddr_r0, %function
399 eor r2, r0, r0, lsl #16
401 .size jump_vaddr_r0, .-jump_vaddr_r0
402 .global jump_vaddr_r1
403 .type jump_vaddr_r1, %function
405 eor r2, r1, r1, lsl #16
408 .size jump_vaddr_r1, .-jump_vaddr_r1
409 .global jump_vaddr_r2
410 .type jump_vaddr_r2, %function
413 eor r2, r2, r2, lsl #16
415 .size jump_vaddr_r2, .-jump_vaddr_r2
416 .global jump_vaddr_r3
417 .type jump_vaddr_r3, %function
419 eor r2, r3, r3, lsl #16
422 .size jump_vaddr_r3, .-jump_vaddr_r3
423 .global jump_vaddr_r4
424 .type jump_vaddr_r4, %function
426 eor r2, r4, r4, lsl #16
429 .size jump_vaddr_r4, .-jump_vaddr_r4
430 .global jump_vaddr_r5
431 .type jump_vaddr_r5, %function
433 eor r2, r5, r5, lsl #16
436 .size jump_vaddr_r5, .-jump_vaddr_r5
437 .global jump_vaddr_r6
438 .type jump_vaddr_r6, %function
440 eor r2, r6, r6, lsl #16
443 .size jump_vaddr_r6, .-jump_vaddr_r6
444 .global jump_vaddr_r8
445 .type jump_vaddr_r8, %function
447 eor r2, r8, r8, lsl #16
450 .size jump_vaddr_r8, .-jump_vaddr_r8
451 .global jump_vaddr_r9
452 .type jump_vaddr_r9, %function
454 eor r2, r9, r9, lsl #16
457 .size jump_vaddr_r9, .-jump_vaddr_r9
458 .global jump_vaddr_r10
459 .type jump_vaddr_r10, %function
461 eor r2, r10, r10, lsl #16
464 .size jump_vaddr_r10, .-jump_vaddr_r10
465 .global jump_vaddr_r12
466 .type jump_vaddr_r12, %function
468 eor r2, r12, r12, lsl #16
471 .size jump_vaddr_r12, .-jump_vaddr_r12
472 .global jump_vaddr_r7
473 .type jump_vaddr_r7, %function
475 eor r2, r7, r7, lsl #16
477 .size jump_vaddr_r7, .-jump_vaddr_r7
479 .type jump_vaddr, %function
483 and r2, r3, r2, lsr #12
490 str r10, [fp, #cycle_count-dynarec_local]
492 ldr r10, [fp, #cycle_count-dynarec_local]
494 .size jump_vaddr, .-jump_vaddr
497 .global verify_code_ds
498 .type verify_code_ds, %function
500 str r8, [fp, #branch_target-dynarec_local]
501 .size verify_code_ds, .-verify_code_ds
502 .global verify_code_vm
503 .type verify_code_vm, %function
506 .type verify_code, %function
535 ldr r8, [fp, #branch_target-dynarec_local]
540 .size verify_code, .-verify_code
541 .size verify_code_vm, .-verify_code_vm
545 .type cc_interrupt, %function
547 ldr r0, [fp, #last_count-dynarec_local]
551 str r1, [fp, #pending_exception-dynarec_local]
552 and r2, r2, r10, lsr #17
553 add r3, fp, #restore_candidate-dynarec_local
554 str r10, [fp, #cycle-dynarec_local] /* PCSX cycles */
555 @@ str r10, [fp, #reg_cop0+36-dynarec_local] /* Count */
563 ldr r10, [fp, #cycle-dynarec_local]
564 ldr r0, [fp, #next_interupt-dynarec_local]
565 ldr r1, [fp, #pending_exception-dynarec_local]
566 ldr r2, [fp, #stop-dynarec_local]
567 str r0, [fp, #last_count-dynarec_local]
574 ldr r0, [fp, #pcaddr-dynarec_local]
579 ldmia r12, {r4, r5, r6, r7, r8, r9, sl, fp, pc}
581 /* Move 'dirty' blocks to the 'clean' list */
592 .size cc_interrupt, .-cc_interrupt
596 .type do_interrupt, %function
598 ldr r0, [fp, #pcaddr-dynarec_local]
600 ldr r1, [fp, #next_interupt-dynarec_local]
601 ldr r10, [fp, #cycle-dynarec_local]
602 str r1, [fp, #last_count-dynarec_local]
606 .size do_interrupt, .-do_interrupt
609 .type fp_exception, %function
613 ldr r1, [fp, #reg_cop0+48-dynarec_local] /* Status */
615 str r0, [fp, #reg_cop0+56-dynarec_local] /* EPC */
618 str r1, [fp, #reg_cop0+48-dynarec_local] /* Status */
619 str r2, [fp, #reg_cop0+52-dynarec_local] /* Cause */
623 .size fp_exception, .-fp_exception
625 .global fp_exception_ds
626 .type fp_exception_ds, %function
628 mov r2, #0x90000000 /* Set high bit if delay slot */
630 .size fp_exception_ds, .-fp_exception_ds
634 .type jump_syscall, %function
636 ldr r1, [fp, #reg_cop0+48-dynarec_local] /* Status */
638 str r0, [fp, #reg_cop0+56-dynarec_local] /* EPC */
641 str r1, [fp, #reg_cop0+48-dynarec_local] /* Status */
642 str r2, [fp, #reg_cop0+52-dynarec_local] /* Cause */
646 .size jump_syscall, .-jump_syscall
650 .global jump_syscall_hle
651 .type jump_syscall_hle, %function
653 str r0, [fp, #pcaddr-dynarec_local] /* PC must be set to EPC for psxException */
654 ldr r2, [fp, #last_count-dynarec_local]
655 mov r1, #0 /* in delay slot */
657 mov r0, #0x20 /* cause */
658 str r2, [fp, #cycle-dynarec_local] /* PCSX cycle counter */
661 /* note: psxException might do recorsive recompiler call from it's HLE code,
662 * so be ready for this */
664 ldr r1, [fp, #next_interupt-dynarec_local]
665 ldr r10, [fp, #cycle-dynarec_local]
666 ldr r0, [fp, #pcaddr-dynarec_local]
668 str r1, [fp, #last_count-dynarec_local]
671 .size jump_syscall_hle, .-jump_syscall_hle
675 .type jump_hlecall, %function
677 ldr r2, [fp, #last_count-dynarec_local]
678 str r0, [fp, #pcaddr-dynarec_local]
681 ldr r3, [fp, #psxHLEt_addr-dynarec_local] /* psxHLEt */
682 str r2, [fp, #cycle-dynarec_local] /* PCSX cycle counter */
684 ldr pc, [r3, r1, lsl #2]
685 .size jump_hlecall, .-jump_hlecall
689 .global new_dyna_leave
690 .type new_dyna_leave, %function
691 ldr r0, [fp, #last_count-dynarec_local]
694 str r10, [fp, #cycle-dynarec_local]
695 ldmia r12, {r4, r5, r6, r7, r8, r9, sl, fp, pc}
696 .size new_dyna_leave, .-new_dyna_leave
698 /* these are used to call memhandlers */
700 .global indirect_jump_indexed
701 .type indirect_jump_indexed, %function
702 indirect_jump_indexed:
703 ldr r0, [r0, r1, lsl #2]
704 .global indirect_jump
705 .type indirect_jump, %function
707 ldr r12, [fp, #last_count-dynarec_local]
709 str r2, [fp, #cycle-dynarec_local]
711 .size indirect_jump, .-indirect_jump
712 .size indirect_jump_indexed, .-indirect_jump_indexed
716 .type jump_eret, %function
718 ldr r1, [fp, #reg_cop0+48-dynarec_local] /* Status */
719 ldr r0, [fp, #last_count-dynarec_local]
722 str r1, [fp, #reg_cop0+48-dynarec_local] /* Status */
723 str r10, [fp, #cycle-dynarec_local]
725 ldr r1, [fp, #next_interupt-dynarec_local]
726 ldr r0, [fp, #reg_cop0+56-dynarec_local] /* EPC */
727 str r1, [fp, #last_count-dynarec_local]
734 str r0, [fp, #pcaddr-dynarec_local]
736 ldr r0, [fp, #pcaddr-dynarec_local]
738 .size jump_eret, .-jump_eret
741 .global new_dyna_start
742 .type new_dyna_start, %function
745 stmia r12, {r4, r5, r6, r7, r8, r9, sl, fp, lr}
747 ldr r0, [fp, #pcaddr-dynarec_local]
748 /*bl new_recompile_block*/
750 ldr r1, [fp, #next_interupt-dynarec_local]
751 ldr r10, [fp, #cycle-dynarec_local]
752 str r1, [fp, #last_count-dynarec_local]
756 .word dynarec_local+28
757 .size new_dyna_start, .-new_dyna_start
760 .global write_rdram_new
761 .type write_rdram_new, %function
763 ldr r2, [fp, #address-dynarec_local]
764 ldr r0, [fp, #word-dynarec_local]
767 .size write_rdram_new, .-write_rdram_new
769 .global write_rdramb_new
770 .type write_rdramb_new, %function
772 ldr r2, [fp, #address-dynarec_local]
773 ldrb r0, [fp, #byte-dynarec_local]
777 .size write_rdramb_new, .-write_rdramb_new
779 .global write_rdramh_new
780 .type write_rdramh_new, %function
782 ldr r2, [fp, #address-dynarec_local]
783 ldrh r0, [fp, #hword-dynarec_local]
787 .size write_rdramh_new, .-write_rdramh_new
790 .global do_invalidate
791 .type do_invalidate, %function
793 ldr r2, [fp, #address-dynarec_local]
795 ldr r1, [fp, #invc_ptr-dynarec_local]
801 .size do_invalidate, .-do_invalidate
804 .global read_nomem_new
805 .type read_nomem_new, %function
810 /* should never happen */
813 ldr r2, [fp, #address-dynarec_local]
814 add r12, fp, #memory_map-dynarec_local
816 ldr r12, [r12, r0, lsl #2]
820 ldr r0, [r2, r12, lsl #2]
821 str r0, [fp, #readmem_dword-dynarec_local]
824 .size read_nomem_new, .-read_nomem_new
827 .global read_nomemb_new
828 .type read_nomemb_new, %function
833 ldr r2, [fp, #address-dynarec_local]
834 add r12, fp, #memory_map-dynarec_local
838 ldr r12, [r12, r0, lsl #2]
842 ldr r0, [fp, #word-dynarec_local]
843 str r0, [r2, r12, lsl #2]
845 .size write_nomem_new, .-write_nomem_new
848 .global write_nomemb_new
849 .type write_nomemb_new, %function
854 ldr r2, [fp, #address-dynarec_local]
855 add r12, fp, #memory_map-dynarec_local
859 ldr r12, [r12, r0, lsl #2]
864 ldrb r0, [fp, #byte-dynarec_local]
865 strb r0, [r2, r12, lsl #2]
867 .size write_nomemb_new, .-write_nomemb_new
870 .global write_nomemh_new
871 .type write_nomemh_new, %function
876 ldr r2, [fp, #address-dynarec_local]
877 add r12, fp, #memory_map-dynarec_local
881 ldr r12, [r12, r0, lsl #2]
886 ldrh r0, [fp, #hword-dynarec_local]
889 .size write_nomemh_new, .-write_nomemh_new
893 .type breakpoint, %function
895 /* Set breakpoint here for debugging */
897 .size breakpoint, .-breakpoint
898 .section .note.GNU-stack,"",%progbits