Skip to content

Commit 426a369

Browse files
committed
added cache handling functions
1 parent b5759ab commit 426a369

5 files changed

Lines changed: 235 additions & 25 deletions

File tree

‎Makefile.arm9‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,7 @@ $(LIBDIR)/libnds9.a: $(ARM9OBJS)
77

88
-include $(DEVKITARM)/base_rules
99
-include $(DEPSDIR)/*.d
10+
11+
%.o : %.bin
12+
@echo $(notdir $<)
13+
@$(bin2o)

‎include/nds.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ extern "C" {
5353
#include "nds/arm9/CP15.h"
5454
#include "nds/arm9/trig_lut.h"
5555
#include "nds/arm9/math.h"
56+
#include "nds/arm9/cache.h"
5657

5758
#endif
5859

‎include/nds/arm9/cache.h‎

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*---------------------------------------------------------------------------------
2+
Copyright (C) 2005
3+
Michael Noland (joat)
4+
Jason Rogers (dovoto)
5+
Dave Murphy (WinterMute)
6+
7+
This software is provided 'as-is', without any express or implied
8+
warranty. In no event will the authors be held liable for any
9+
damages arising from the use of this software.
10+
11+
Permission is granted to anyone to use this software for any
12+
purpose, including commercial applications, and to alter it and
13+
redistribute it freely, subject to the following restrictions:
14+
15+
1. The origin of this software must not be misrepresented; you
16+
must not claim that you wrote the original software. If you use
17+
this software in a product, an acknowledgment in the product
18+
documentation would be appreciated but is not required.
19+
2. Altered source versions must be plainly marked as such, and
20+
must not be misrepresented as being the original software.
21+
3. This notice may not be removed or altered from any source
22+
distribution.
23+
24+
---------------------------------------------------------------------------------*/
25+
#ifndef _cache_h_
26+
#define _cache_h_
27+
28+
#ifdef __cplusplus
29+
extern "C" {
30+
#endif
31+
32+
#include "nds/jtypes.h"
33+
34+
void DC_FlushAll();
35+
void DC_FlushRange(void *base, u32 size);
36+
void DC_InvalidateAll();
37+
void DC_InvalidateRange(void *base, u32 size);
38+
#ifdef __cplusplus
39+
}
40+
#endif
41+
42+
#endif

‎libnds.prj‎

Lines changed: 96 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,37 +14,108 @@ Include Sub Directories=1
1414
[Open Files]
1515
Open File0=
1616
Active File Display Mode=-1
17-
Open File Pos0=2206
18-
Open File Line0=433
19-
Active File Index=0
20-
Open File Window Pos0=2,3,-1,-1,-4,-23,0,0,774,515
21-
Open File1=C:\projects\devkitPro\libgba\include\gba_base.h
22-
Open File Pos1=1875
23-
Open File Line1=1109
24-
Open File Window Pos1=0,1,-1,-1,-4,-23,22,22,800,541
25-
Open File2=
17+
Open File Pos0=2064
18+
Open File Line0=772
19+
Active File Index=17
20+
Open File Window Pos0=0,1,-1,-1,-4,-23,0,0,873,440
21+
Open File1=C:\Dave's Documents\docs\nitro\SDK\include\nitro\os\ARM9\cache.h
22+
Open File Pos1=0
23+
Open File Line1=1787
24+
Open File Window Pos1=0,1,-1,-1,-4,-23,22,22,899,466
25+
Open File2=C:\Dave's Documents\docs\nitro\SDK\include\nitro\os\ARM9\protectionRegion.h
2626
Open File Pos2=0
27-
Open File Line2=0
28-
Open File Window Pos2=0,1,-1,-1,-4,-23,88,88,866,607
29-
Open File3=C:\projects\devkitPro\libnds\rules
30-
Open File Pos3=377
27+
Open File Line2=7199
28+
Open File Window Pos2=0,1,-1,-1,-4,-23,44,44,921,488
29+
Open File3=C:\Dave's Documents\docs\nitro\SDK\include\nitro\os\ARM9\protectionUnit.h
30+
Open File Pos3=0
3131
Open File Line3=0
32-
Open File Window Pos3=0,1,-1,-1,-4,-23,110,110,888,629
33-
Open File4=C:\projects\devkitPro\examples\gba\PCXView\Makefile
34-
Open File Pos4=7651
35-
Open File Line4=2708
36-
Open File Window Pos4=0,1,-1,-1,-4,-23,132,132,910,651
37-
Open File5=
32+
Open File Window Pos3=0,1,-1,-1,-4,-23,66,66,943,510
33+
Open File4=C:\Dave's Documents\docs\nitro\SDK\build\libraries\os\ARM9\src\os_cache.c
34+
Open File Pos4=4084
35+
Open File Line4=3635
36+
Open File Window Pos4=0,1,-1,-1,-4,-23,88,88,965,532
37+
Open File5=C:\Dave's Documents\docs\nitro\SDK\include\nitro\code32.h
38+
Open File Pos5=0
39+
Open File Line5=0
40+
Open File Window Pos5=0,1,-1,-1,-4,-23,110,110,987,554
41+
Open File6=C:\Dave's Documents\docs\nitro\SDK\include\nitro\os.h
42+
Open File Pos6=0
43+
Open File Line6=2698
44+
Open File Window Pos6=0,1,-1,-1,-4,-23,132,132,1009,576
45+
Open File7=C:\Dave's Documents\docs\nitro\SDK\include\nitro\os\common\system.h
46+
Open File Pos7=0
47+
Open File Line7=3074
48+
Open File Window Pos7=0,1,-1,-1,-4,-23,154,154,1031,598
49+
Open File8=C:\projects\devkitPro\buildscripts\tools\nds\ndstool\changelog
50+
Open File Pos8=0
51+
Open File Line8=0
52+
Open File Window Pos8=0,1,-1,-1,-4,-23,198,198,1075,642
53+
Open File9=C:\projects\devkitPro\buildscripts\dka-scripts\build-gcc.sh
54+
Open File Pos9=2215
55+
Open File Line9=0
56+
Open File Window Pos9=0,1,-1,-1,-4,-23,0,0,877,444
57+
Open File10=C:\projects\devkitPro\buildscripts\build-devkit.sh
58+
Open File Pos10=0
59+
Open File Line10=3742
60+
Open File Window Pos10=0,1,-1,-1,-4,-23,22,22,899,466
61+
Open File11=C:\Neo Power Kit\USB_Driver\XUSBWindow.INF
62+
Open File Pos11=0
63+
Open File Line11=319
64+
Open File Window Pos11=0,1,-1,-1,-4,-23,44,44,921,488
65+
Open File12=C:\projects\devkitPro\libnds\include\nds\arm9\CP15.h
66+
Open File Pos12=0
67+
Open File Line12=3563
68+
Open File Window Pos12=0,1,-1,-1,-4,-23,66,66,943,510
69+
Open File13=C:\projects\devkitPro\buildscripts\dka-crtls\ds_arm9.ld
70+
Open File Pos13=2452
71+
Open File Line13=2931
72+
Open File Window Pos13=0,1,-1,-1,-4,-23,176,176,1053,620
73+
Open File14=C:\projects\devkitPro\buildscripts\dka-crtls\gba_cart.ld
74+
Open File Pos14=0
75+
Open File Line14=5037
76+
Open File Window Pos14=0,1,-1,-1,-4,-23,198,198,1075,642
77+
Open File15=C:\projects\devkitPro\buildscripts\dka-crtls\ds_arm9_crt0.s
78+
Open File Pos15=0
79+
Open File Line15=5610
80+
Open File Window Pos15=0,1,-1,-1,-4,-23,0,0,877,444
81+
Open File16=C:\Neo Power Kit\Neo Power Kit.ini
82+
Open File Pos16=0
83+
Open File Line16=0
84+
Open File Window Pos16=0,1,-1,-1,-4,-23,22,22,899,466
85+
Open File17=C:\projects\devkitPro\buildscripts\dka-scripts\build-tools.sh
86+
Open File Pos17=548
87+
Open File Line17=0
88+
Open File Window Pos17=2,3,-1,-1,-4,-23,44,44,921,488
89+
Open File18=C:\projects\devkitPro\buildscripts\tools\gba\Makefile
90+
Open File Pos18=321
91+
Open File Line18=0
92+
Open File Window Pos18=0,1,-1,-1,-4,-23,66,66,943,510
93+
Open File19=C:\projects\devkitPro\buildscripts\tools\general\raw2c.c
94+
Open File Pos19=0
95+
Open File Line19=0
96+
Open File Window Pos19=0,1,-1,-1,-4,-23,88,88,965,532
97+
Open File20=C:\projects\devkitPro\buildscripts\tools\general\Makefile
98+
Open File Pos20=343
99+
Open File Line20=0
100+
Open File Window Pos20=0,1,-1,-1,-4,-23,110,110,987,554
101+
Open File21=C:\projects\devkitPro\buildscripts\tools\nds\dsbuild\Makefile
102+
Open File Pos21=5273
103+
Open File Line21=4353
104+
Open File Window Pos21=0,1,-1,-1,-4,-23,132,132,1009,576
105+
Open File22=C:\projects\devkitPro\buildscripts\tools\nds\ndstool\Makefile
106+
Open File Pos22=5160
107+
Open File Line22=4362
108+
Open File Window Pos22=0,1,-1,-1,-4,-23,154,154,1031,598
109+
Open File23=
38110
[File View]
39-
Current Select=Project Files
111+
Current Select=Project Files\include\nds\\
40112
Scroll Position=0
41113
[Files]
42114
0=include\
43-
1=license.txt
44-
2=source\arm7\
45-
3=source\arm9\
46-
4=source\common\
115+
1=source\arm7\
116+
2=source\arm9\
117+
3=source\common\
118+
4=license.txt
47119
5=Makefile
48120
6=Makefile.arm7
49121
7=Makefile.arm9
50-
8=rules

‎source/arm9/cache.s‎

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
/*---------------------------------------------------------------------------------
2+
Copyright (C) 2005
3+
Michael Noland (joat)
4+
Jason Rogers (dovoto)
5+
Dave Murphy (WinterMute)
6+
7+
This software is provided 'as-is', without any express or implied
8+
warranty. In no event will the authors be held liable for any
9+
damages arising from the use of this software.
10+
11+
Permission is granted to anyone to use this software for any
12+
purpose, including commercial applications, and to alter it and
13+
redistribute it freely, subject to the following restrictions:
14+
15+
1. The origin of this software must not be misrepresented; you
16+
must not claim that you wrote the original software. If you use
17+
this software in a product, an acknowledgment in the product
18+
documentation would be appreciated but is not required.
19+
2. Altered source versions must be plainly marked as such, and
20+
must not be misrepresented as being the original software.
21+
3. This notice may not be removed or altered from any source
22+
distribution.
23+
24+
---------------------------------------------------------------------------------*/
25+
#define ICACHE_SIZE 0x2000
26+
#define DCACHE_SIZE 0x1000
27+
#define CACHE_LINE_SIZE 32
28+
//---------------------------------------------------------------------------------
29+
.arm
30+
//---------------------------------------------------------------------------------
31+
.global DC_FlushAll
32+
//---------------------------------------------------------------------------------
33+
DC_FlushAll:
34+
/*---------------------------------------------------------------------------------
35+
Clean and invalidate entire data cache
36+
---------------------------------------------------------------------------------*/
37+
mov r1, #0
38+
outer_loop:
39+
mov r0, #0
40+
inner_loop:
41+
orr r2, r1, r0 @ generate segment and line address
42+
mcr p15, 0, r2, c7, c14 @ clean and flush the line
43+
add r0, r0, #CACHE_LINE_SIZE
44+
cmp r0, #DCACHE_SIZE/4
45+
bne inner_loop
46+
add r1, r1, #0x40000000
47+
cmp r1, #0
48+
bne outer_loop
49+
bx lr
50+
51+
//---------------------------------------------------------------------------------
52+
.global DC_FlushRange
53+
//---------------------------------------------------------------------------------
54+
DC_FlushRange:
55+
/*---------------------------------------------------------------------------------
56+
Clean and invalidate a range
57+
---------------------------------------------------------------------------------*/
58+
add r1, r1, r0
59+
bic r0, r0, #CACHE_LINE_SIZE - 1
60+
.flush:
61+
mcr p15, 0, r0, c7, c14, 1
62+
add r0, r0, #CACHE_LINE_SIZE
63+
cmp r0, r1
64+
blt .flush
65+
bx lr
66+
67+
//---------------------------------------------------------------------------------
68+
.global DC_InvalidateAll
69+
//---------------------------------------------------------------------------------
70+
DC_InvalidateAll:
71+
/*---------------------------------------------------------------------------------
72+
Clean and invalidate entire data cache
73+
---------------------------------------------------------------------------------*/
74+
mov r0, #0
75+
mcr p15, 0, r0, c7, c6, 0
76+
bx lr
77+
78+
//---------------------------------------------------------------------------------
79+
.global DC_InvalidateRange
80+
//---------------------------------------------------------------------------------
81+
DC_InvalidateRange:
82+
/*---------------------------------------------------------------------------------
83+
Clean and invalidate a range
84+
---------------------------------------------------------------------------------*/
85+
add r1, r1, r0
86+
bic r0, r0, #CACHE_LINE_SIZE - 1
87+
.invalidate:
88+
mcr p15, 0, r0, c7, c6, 1
89+
add r0, r0, #CACHE_LINE_SIZE
90+
cmp r0, r1
91+
blt .invalidate
92+
bx lr

0 commit comments

Comments
 (0)