1
+ @ This file is part of open_agb_firm
2
+ @ Copyright (C) 2024 profi200
3
+ @
4
+ @ This program is free software: you can redistribute it and / or modify
5
+ @ it under the terms of the GNU General Public License as published by
6
+ @ the Free Software Foundation , either version 3 of the License , or
7
+ @ ( at your option) any later version.
8
+ @
9
+ @ This program is distributed in the hope th at it will be useful ,
10
+ @ but WITHOUT ANY WARRANTY ; without even the implied warranty of
11
+ @ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
+ @ GNU General Public License for more details.
13
+ @
14
+ @ You should have received a copy of the GNU General Public License
15
+ @ along with this program. If not , see <http://www.gnu.org/licenses/>.
16
+
17
+ #include "asm_macros.h"
18
+
19
+ .syntax unified
20
+ . cpu mpcore
21
+ .fpu vfpv2
22
+
23
+
24
+
25
+ @ void makeOpenBusPaddingFast(u32 * romEnd) ;
26
+ BEGIN_ASM_FUNC makeOpenBusPaddingFast
27
+ @ Save registers and calculate size from start and highest ROM address.
28
+ stmfd sp ! , {r4 , lr} @ Save registers.
29
+ rsb r1 , r0 , # 0x22000000 @ r1 = 0x22000000 - r0 ;
30
+
31
+ @ Generate pattern halves from address.
32
+ lsr r2 , r0 , # 1 @ r2 = r0>> 1 ;
33
+ add r3 , r2 , # 1 @ r3 = r2 + 1 ;
34
+
35
+ @ Generate constant for incrementing the pattern halves.
36
+ mov r12 , # 2 @ r12 = 2 ;
37
+ add r12 , r12 , # 0x20000 @ r12 + = 0x20000 ;
38
+
39
+ @ Join pattern halves and precalculate the next 3 patterns.
40
+ pkhbt r2 , r2 , r3 , lsl # 16 @ r2 = (r2 & 0xFFFF ) | r3<< 16 ;
41
+ uadd16 r3 , r2 , r12 @ r3 = ((r2 + 0x20000 ) & 0xFFFF0000 ) | ((r2 + 2 ) & 0xFFFF ) ; // r12 is 0x20002.
42
+ uadd16 r4 , r3 , r12 @ r4 = ((r3 + 0x20000 ) & 0xFFFF0000 ) | ((r3 + 2 ) & 0xFFFF ) ; // r12 is 0x20002.
43
+ uadd16 lr , r4 , r12 @ lr = ((r4 + 0x20000 ) & 0xFFFF0000 ) | ((r4 + 2 ) & 0xFFFF ) ; // r12 is 0x20002.
44
+
45
+ @ Adjust constant for unrolled loop . 0x20002 -- > 0x80008 .
46
+ lsl r12 , r12 , # 2 @ r12 <<= 2 ;
47
+ makeOpenBusPaddingFast_blk_lp:
48
+ @ Store 16 pattern bytes at a time and decrement size.
49
+ stmia r0! , {r2 - r4 , lr} @ * ((_16BytesBlock * )r0) = r2_to_r4_lr ; r0 += 16;
50
+ subs r1 , r1 , # 16 @ r1 - = 16 ; // Updates flags.
51
+
52
+ @ Increment patterns and jump back if we are not done yet.
53
+ uadd16 r2 , r2 , r12 @ r2 = ((r2 + 0x80000 ) & 0xFFFF0000 ) | ((r2 + 8 ) & 0xFFFF ) ; // r12 is 0x80008.
54
+ uadd16 r3 , r3 , r12 @ r3 = ((r3 + 0x80000 ) & 0xFFFF0000 ) | ((r3 + 8 ) & 0xFFFF ) ; // r12 is 0x80008.
55
+ uadd16 r4 , r4 , r12 @ r3 = ((r4 + 0x80000 ) & 0xFFFF0000 ) | ((r4 + 8 ) & 0xFFFF ) ; // r12 is 0x80008.
56
+ uadd16 lr , lr , r12 @ lr = ((lr + 0x80000 ) & 0xFFFF0000 ) | ((lr + 8 ) & 0xFFFF ) ; // r12 is 0x80008.
57
+ bne makeOpenBusPaddingFast_blk_lp @ if(r1 != 0 ) goto makeOpenBusPaddingFast_blk_lp ;
58
+
59
+ ldmfd sp ! , {r4 , pc} @ Restore registers and return.
60
+ END_ASM_FUNC
0 commit comments