3 @ Compiler helper functions and some SVP HLE code
5 @ (c) Copyright 2008, Grazvydas "notaz" Ignotas
6 @ Free for non-commercial use.
13 .global ssp_block_table
14 .global ssp_block_table_iram
18 .global ssp_drc_next_patch
22 .global ssp_hle_07_030
23 .global ssp_hle_07_036
24 .global ssp_hle_07_6d6
25 .global ssp_hle_11_12c
26 .global ssp_hle_11_384
27 .global ssp_hle_11_38a
29 @ translation cache buffer + pointer table
32 @.size tcache, SSP_TCACHE_SIZE
33 @.size ssp_block_table, SSP_BLOCKTAB_SIZE
34 @.size ssp_block_table_iram, SSP_BLOCKTAB_IRAM_SIZE
36 .space SSP_TCACHE_SIZE
38 .space SSP_BLOCKTAB_SIZE
40 .space SSP_BLOCKTAB_IRAM_SIZE
41 .space SSP_BLOCKTAB_ALIGN_SIZE
47 @ SSP_GR0, SSP_X, SSP_Y, SSP_A,
48 @ SSP_ST, SSP_STACK, SSP_PC, SSP_P,
49 @ SSP_PM0, SSP_PM1, SSP_PM2, SSP_XST,
50 @ SSP_PM4, SSP_gr13, SSP_PMC, SSP_AL
55 @ r6: STACK and emu flags: sss0 * .uu. .lll NZCV (NZCV is PSR bits from ARM)
64 #define SSP_OFFS_GR 0x400
69 #define SSP_OFFS_PM_WRITE 0x46c // pmac_write[]
70 #define SSP_OFFS_EMUSTAT 0x484 // emu_status
71 #define SSP_OFFS_IRAM_ROM 0x48c // ptr_iram_rom
72 #define SSP_OFFS_DRAM 0x490 // ptr_dram
73 #define SSP_OFFS_IRAM_DIRTY 0x494
74 #define SSP_OFFS_IRAM_CTX 0x498 // iram_context
75 #define SSP_OFFS_BLTAB 0x49c // block_table
76 #define SSP_OFFS_BLTAB_IRAM 0x4a0
77 #define SSP_OFFS_TMP0 0x4a4 // for entry PC
78 #define SSP_OFFS_TMP1 0x4a8
79 #define SSP_OFFS_TMP2 0x4ac
80 #define SSP_WAIT_PM0 0x2000
83 .macro ssp_drc_do_next patch_jump=0
85 str lr, [r7, #SSP_OFFS_TMP2] @ jump instr. (actually call) address + 4
89 str r0, [r7, #SSP_OFFS_TMP0]
93 ldr r2, [r7, #SSP_OFFS_BLTAB]
94 ldr r2, [r2, r0, lsl #2]
101 bl ssp_translate_block
103 ldr r0, [r7, #SSP_OFFS_TMP0] @ entry PC
104 ldr r1, [r7, #SSP_OFFS_BLTAB]
105 str r2, [r1, r0, lsl #2]
113 ldr r1, [r7, #SSP_OFFS_IRAM_DIRTY]
115 ldreq r1, [r7, #SSP_OFFS_IRAM_CTX]
116 beq 1f @ ssp_de_iram_ctx
118 bl ssp_get_iram_context
120 str r1, [r7, #SSP_OFFS_IRAM_DIRTY]
122 str r1, [r7, #SSP_OFFS_IRAM_CTX]
123 ldr r0, [r7, #SSP_OFFS_TMP0] @ entry PC
125 1: @ ssp_de_iram_ctx:
126 ldr r2, [r7, #SSP_OFFS_BLTAB_IRAM]
127 add r2, r2, r1, lsl #12 @ block_tab_iram + iram_context * 0x800/2*4
128 add r1, r2, r0, lsl #2
136 str r1, [r7, #SSP_OFFS_TMP1]
137 bl ssp_translate_block
139 ldr r0, [r7, #SSP_OFFS_TMP0] @ entry PC
140 ldr r1, [r7, #SSP_OFFS_TMP1] @ &block_table_iram[iram_context][rPC]
147 .endm @ ssp_drc_do_next
151 stmfd sp!, {r4-r11, lr}
158 ldmia r2, {r3,r4,r5,r6,r8}
161 orr r4, r3, r4, lsr #16 @ XXYY
163 and r8, r8, #0x0f0000
164 mov r8, r8, lsl #13 @ sss0 *
165 and r9, r6, #0x670000
169 orrne r8, r8, #0x4 @ sss0 * NZ..
170 orr r6, r8, r9, lsr #12 @ sss0 * .uu. .lll NZ..
172 ldr r8, [r7, #0x440] @ r0-r2
173 ldr r9, [r7, #0x444] @ r4-r6
174 ldr r10,[r7, #(0x400+SSP_P*4)] @ P
176 ldr r0, [r7, #(SSP_OFFS_GR+SSP_PC*4)]
188 ldr r1, [r7, #SSP_OFFS_TMP2] @ jump instr. (actually call) address + 4
190 moveq r3, #0xe1000000
191 orreq r3, r3, #0x00a00000 @ nop
198 streq r3, [r1, #-4] @ move the other cond up
199 moveq r3, #0xe1000000
200 orreq r3, r3, #0x00a00000
201 streq r3, [r1] @ fill it's place with nop
207 bic r3, r3, #1 @ L bit
208 orr r3, r3, r12,lsl #6
209 mov r3, r3, ror #8 @ patched branch instruction
210 str r3, [r1, #-4] @ patch the bl/b to jump directly to another handler
213 str r2, [r7, #SSP_OFFS_TMP1]
216 bl cache_flush_d_inval_i
217 ldr r2, [r7, #SSP_OFFS_TMP1]
218 ldr r0, [r7, #SSP_OFFS_TMP0]
224 str r0, [r7, #(SSP_OFFS_GR+SSP_PC*4)]
227 str r10,[r7, #(0x400+SSP_P*4)] @ P
228 str r8, [r7, #0x440] @ r0-r2
229 str r9, [r7, #0x444] @ r4-r6
232 and r9, r9, #(7<<16) @ STACK
234 msr cpsr_flg, r3 @ to to ARM PSR
237 orrmi r6, r6, #0x80000000 @ N
238 orreq r6, r6, #0x20000000 @ Z
240 mov r3, r4, lsl #16 @ Y
242 mov r2, r2, lsl #16 @ X
245 stmia r8, {r2,r3,r5,r6,r9}
248 ldmfd sp!, {r4-r11, lr}
257 ldr r0, [r7, #(SSP_OFFS_GR+SSP_PM0*4)]
258 ldr r1, [r7, #SSP_OFFS_EMUSTAT]
260 orreq r1, r1, #SSP_WAIT_PM0
262 streq r1, [r7, #SSP_OFFS_EMUSTAT]
269 .macro hle_flushflags
272 orr r6, r6, r1, lsr #28
276 sub r6, r6, #0x20000000
278 add r1, r1, #0x048 @ stack
279 add r1, r1, r6, lsr #28
289 ldr r3, [r7, #SSP_OFFS_IRAM_ROM]
290 add r2, r3, r0, lsl #1 @ (r7|00)
295 add r3, r3, r0, lsl #1 @ IRAM dest
296 ldrh r12,[r2], #2 @ length
297 bic r3, r3, #3 @ always seen aligned
298 @ orr r5, r5, #0x08000000
299 @ orr r5, r5, #0x00880000
300 @ sub r5, r5, r12, lsl #16
304 str r0, [r7, #SSP_OFFS_IRAM_DIRTY]
305 sub r11,r11,r12,lsl #1
306 sub r11,r11,r12 @ -= length*3
312 orr r0, r0, r1, lsl #16
320 ldr r0, [r7, #SSP_OFFS_IRAM_ROM]
324 strh r2, [r1] @ (r7|00)
328 orr r0, r0, #0x08000000
329 orr r0, r0, #0x001c8000
330 str r0, [r7, #(SSP_OFFS_GR+SSP_PMC*4)]
331 str r0, [r7, #(SSP_OFFS_PM_WRITE+4*4)]
334 subs r11,r11,#16 @ timeslice is likely to end
339 @ this one is car rendering related
340 .macro hle_11_12c_mla offs_in
341 ldrsh r5, [r7, #(\offs_in+0)]
342 ldrsh r0, [r7, #(\offs_in+2)]
343 ldrsh r1, [r7, #(\offs_in+4)]
345 ldrsh r12,[r7, #(\offs_in+6)]
348 add r5, r5, r12,lsl #11
351 add r1, r7, r8, lsr #23
372 mov r2, r2, asr #15 @ (r7|00) << 1
374 mov r3, r3, asr #15 @ (r7|01) << 1
376 mov r4, r4, asr #15 @ (r7|10) << 1
404 mov r2, #0 @ EFh, EEh
406 add r0, r7, #0x1c0 @ r0 (based)
412 eor r5, r5, r5, asr #31
413 add r5, r5, r5, lsr #31 @ abs(r5)
415 orrpl r2, r2, r1,lsl #16 @ EFh |= r4
420 orrpl r2, r2, r1,lsl #16 @ EFh |= r4
430 bpl ssp_hle_11_38x_loop
435 orr r8, r8, r0, lsr #1
441 sub r11,r11,#(9+30*4)
450 and r0, r8, #0xff @ assuming alignment
451 add r0, r7, r0, lsl #1
453 mov r1, r1, lsl #16 @ 106h << 16
454 mov r2, r2, lsl #16 @ 107h << 16
459 bmi ssp_hle_07_6d6_end
465 bmi ssp_hle_07_6d6_loop
467 b ssp_hle_07_6d6_loop
474 orr r1, r2, r1, lsr #16
484 orr r0, r0, r0, lsr #16
489 ldr r1, [r7, #0x1e0] @ F1h F0h
490 rsb r5, r1, r1, lsr #16
491 mov r5, r5, lsl #16 @ AL not needed
494 bmi hle_07_036_ending2
495 ldr r1, [r7, #0x1dc] @ EEh
502 strh r0, [r1, #0xea] @ F5h
503 ldr r0, [r7, #0x1e0] @ F0h
505 strh r0, [r1, #0xf0] @ F8h
506 add r2, r0, #0xc0 @ r2
507 add r2, r7, r2, lsl #1
513 @ will handle PMC later
514 ldr r0, [r7, #0x1e8] @ F5h << 16
515 ldr r1, [r7, #0x1f0] @ F8h
516 ldr r2, [r7, #0x1d4] @ EAh
518 add r0, r0, r1, lsl #16
519 sub r0, r2, r0, asr #18
521 rsbs r0, r0, #0x78 @ length
522 ble hle_07_036_ending1
527 ldr r1, [r7, #(SSP_OFFS_GR+SSP_PMC*4)]
528 ldr r2, [r7, #SSP_OFFS_DRAM]
530 add r1, r2, r1, lsr #15 @ addr (based)
531 ldrh r2, [r7, #0] @ pattern
532 ldrh r3, [r7, #6] @ mode
537 subnes r12,r12,#0x0400
540 orr r2, r2, r2, lsl #16
546 strneh r2, [r1], #0x3e @ align
559 strne r2, [r1], #0x40
562 b hle_07_036_end_copy
566 orreq r12,r12,#0x000f
568 orreq r12,r12,#0x00f0
570 orreq r12,r12,#0x0f00
572 orreq r12,r12,#0xf000
573 orrs r12,r12,r12,lsl #16
574 beq hle_07_036_no_ovrwr
581 strh r3, [r1], #0x3e @ align
604 ldr r2, [r7, #SSP_OFFS_DRAM]
606 sub r0, r1, r2 @ new addr
608 strh r0, [r3, #(0x6c+4*4)] @ SSP_OFFS_PM_WRITE+4*4 (low)
611 ldr r0, [r7, #0x1e0] @ F1h << 16
614 add r0, r0, #(0xc4<<16)
615 bic r8, r8, #0xff0000
617 add r0, r7, r0, lsr #15
623 ldr r1, [r7, #4] @ new mode
625 strh r1, [r2, #(0x6c+4*4+2)] @ SSP_OFFS_PM_WRITE+4*4 (high)
639 b ssp_drc_next @ let the dispatcher finish this