1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
Index: bootloader/sansa_as3525.c
===================================================================
--- bootloader/sansa_as3525.c	(Revision 19800)
+++ bootloader/sansa_as3525.c	(Arbeitskopie)
@@ -95,6 +95,7 @@
     {
         kernel_entry = (void*) loadbuffer;
         printf("Executing");
+        invalidate_icache();
         kernel_entry();
         printf("ERR: Failed to boot");
     }
Index: apps/plugins/plugin.lds
===================================================================
--- apps/plugins/plugin.lds	(Revision 19800)
+++ apps/plugins/plugin.lds	(Arbeitskopie)
@@ -1,4 +1,5 @@
 #include "config.h"
+#include "cpu.h"

 /* These output formats should be in the config-files */

@@ -38,9 +39,9 @@
 /* Reserve 1mb for LCD buffer/TTB as in app.lds */
 #define DRAMSIZE (MEMORYSIZE * 0x100000 - 0x100000) - PLUGIN_BUFFER_SIZE - STUBOFFSET - CODEC_SIZE
 #elif CONFIG_CPU==AS3525 && MEMORYSIZE <= 2
-#define DRAMSIZE (MEMORYSIZE * 0x100000) - PLUGIN_BUFFER_SIZE - STUBOFFSET
+#define DRAMSIZE (MEMORYSIZE * 0x100000) - PLUGIN_BUFFER_SIZE - STUBOFFSET - TTB_SIZE
 #else
-#define DRAMSIZE (MEMORYSIZE * 0x100000) - PLUGIN_BUFFER_SIZE - STUBOFFSET - CODEC_SIZE
+#define DRAMSIZE (MEMORYSIZE * 0x100000) - PLUGIN_BUFFER_SIZE - STUBOFFSET - CODEC_SIZE - TTB_SIZE
 #endif

 #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300)
@@ -89,6 +90,7 @@
 #define IRAM DRAM
 #define IRAMSIZE 0
 #elif CONFIG_CPU==AS3525
+#define DRAMORIG 0x30000000
 #if MEMORYSIZE <= 2
 #define IRAMSIZE 0  /* simulates no IRAM since codec is already entirely in IRAM */
 #define CODEC_ORIGIN (0x50000 - CODEC_SIZE)
@@ -97,7 +99,6 @@
 #define IRAMORIG 0x0
 #define IRAMSIZE 0x50000
 #endif
-#define DRAMORIG 0x30000000

 #else
 #define DRAMORIG 0x09000000 + STUBOFFSET
Index: apps/plugins/SOURCES
===================================================================
--- apps/plugins/SOURCES	(Revision 19800)
+++ apps/plugins/SOURCES	(Arbeitskopie)
@@ -1,4 +1,5 @@
 /* plugins common to all models */
+test_boost.c
 battery_bench.c
 chessclock.c
 credits.c
Index: firmware/export/as3525.h
===================================================================
--- firmware/export/as3525.h	(Revision 19800)
+++ firmware/export/as3525.h	(Arbeitskopie)
@@ -26,7 +26,12 @@
 #define ECCSIZE 512
 #define ECCBYTES 3

+#define IRAM_SIZE (0x50000)
+#define TTB_SIZE (0x4000)
+/* must be 16Kb (0x4000) aligned */
+#define TTB_BASE   ((unsigned long *)(0x30000000 + (MEM*1024*1024) - TTB_SIZE)) /* End of memory */

+
 /* AS352X device base addresses */


Index: firmware/SOURCES
===================================================================
--- firmware/SOURCES	(Revision 19800)
+++ firmware/SOURCES	(Arbeitskopie)
@@ -343,6 +343,7 @@
 #endif

 #if CONFIG_CPU == AS3525
+target/arm/mmu-arm.c
 target/arm/as3525/system-as3525.c
 target/arm/as3525/kernel-as3525.c
 target/arm/as3525/ata_sd_as3525.c
Index: firmware/target/arm/crt0.S
===================================================================
--- firmware/target/arm/crt0.S	(Revision 19800)
+++ firmware/target/arm/crt0.S	(Arbeitskopie)
@@ -87,25 +87,51 @@
     ldrhi   r5, [r2], #4
     strhi   r5, [r3], #4
     bhi     1b
+#if 0
+    /* Setup the MMU, start by disabling */
+    mcr     p15, 0, r0, c7, c7, 0 /* invalidate i and dcache */
+    nop
+    mrc     p15, 0, r0, c1, c0, 0  
+    bic     r0, r0, #0x1        /* disable mmu */
+    bic     r0, r0, #0x1<<2     /* disable dcache */
+    bic     r0, r0, #0x1<<12    /* disable icache */
+    mcr     p15, 0, r0, c1, c0, 0
+    bl      ttb_init
+
+    ldr     r0, =0x0
+    ldr     r1, =0x0
+    ldr     r2, =0x1000
+    mov     r3, #0
+    bl      map_section
+
+    ldr     r0, =0x30000000
+    ldr     r1, =0x30000000
+    mov     r2, #8
+    mov     r3, #12
+    bl      map_section
+    
+    bl      enable_mmu
 #endif
+#endif /* CONFIG_CPU == AS3525 */

     /* Initialise bss section to zero */
     ldr     r2, =_edata
     ldr     r3, =_end
     mov     r4, #0
-1:
+bsszero:
     cmp     r3, r2
     strhi   r4, [r2], #4
-    bhi     1b
+    bhi     bsszero

     /* Set up some stack and munge it with 0xdeadbeef */
     ldr     sp, =stackend
+    mov     r3, sp
     ldr     r2, =stackbegin
-    ldr     r3, =0xdeadbeef
-1:
-    cmp     sp, r2
-    strhi   r3, [r2], #4
-    bhi     1b
+    ldr     r4, =0xdeadbeef
+stackmunge:
+    cmp     r3, r2
+    strhi   r4, [r2], #4
+    bhi     stackmunge

     /* Set up stack for IRQ mode */ 
     msr     cpsr_c, #0xd2
@@ -121,12 +147,14 @@
     msr     cpsr_c, #0xdb
     ldr     sp, =irq_stack

-    /* Switch back to supervisor mode */
+    /* Switch to supervisor mode */
     msr     cpsr_c, #0xd3
+#if CONFIG_CPU == AS3525
+    ldr     sp, =stackend
+#endif

     bl      main

-
 /* All illegal exceptions call into UIE with exception address as first
  * parameter. This is calculated differently depending on which exception
  * we're in. Second parameter is exception number, used for a string lookup
Index: firmware/target/arm/as3525/system-as3525.c
===================================================================
--- firmware/target/arm/as3525/system-as3525.c	(Revision 19800)
+++ firmware/target/arm/as3525/system-as3525.c	(Arbeitskopie)
@@ -212,6 +212,19 @@

     MPMC_DYNAMIC_CONFIG_0 |= (1<<19); /* buffer enable */
 }
+#else
+static void set_page_tables(void)
+{
+    map_section(0, 0, 0x1000, CACHE_NONE); /* map every memory region to itself */
+    map_section(0x30000000, 0x30000000, MEM, CACHE_ALL); /* map RAM to 0 and enable caching for it */
+}
+
+void memory_init(void)
+{
+    ttb_init();
+    set_page_tables();
+    enable_mmu();
+}
 #endif

 void system_init(void)
@@ -259,6 +272,8 @@
     dma_init();

 #ifndef BOOTLOADER
+    invalidate_icache();
+    memory_init();
     /* Disable fast hardware power-off, to use power button normally
      * We don't need the power button in the bootloader. */
     ascodec_init();
Index: firmware/target/arm/as3525/system-target.h
===================================================================
--- firmware/target/arm/as3525/system-target.h	(Revision 19800)
+++ firmware/target/arm/as3525/system-target.h	(Arbeitskopie)
@@ -22,7 +22,20 @@
 #define SYSTEM_TARGET_H

 #include "system-arm.h"
+#include "mmu-arm.h"

 #include "clock-target.h" /* CPUFREQ_* are defined here */

+
+#define HAVE_INVALIDATE_ICACHE
+static inline void invalidate_icache(void)
+{
+    clean_dcache();
+    asm volatile(
+        "mov r0, #0 \n"
+		"mcr p15, 0, r0, c7, c7, 0 \n" /* invalidate i and dcache */
+        : : : "r0"
+    );
+}
+
 #endif /* SYSTEM_TARGET_H */
Index: firmware/target/arm/as3525/app.lds
===================================================================
--- firmware/target/arm/as3525/app.lds	(Revision 19800)
+++ firmware/target/arm/as3525/app.lds	(Arbeitskopie)
@@ -25,10 +25,10 @@
 #define IRAMSIZE 0x50000

 #ifdef LOWMEM
-#define DRAMSIZE (MEMORYSIZE * 0x100000) - STUBOFFSET - PLUGINSIZE
+#define DRAMSIZE (MEMORYSIZE * 0x100000) - STUBOFFSET - PLUGINSIZE - TTB_SIZE
 #define CODECORIG (IRAMORIG + IRAMSIZE - CODEC_SIZE)
 #else
-#define DRAMSIZE (MEMORYSIZE * 0x100000) - STUBOFFSET - PLUGINSIZE - CODECSIZE
+#define DRAMSIZE (MEMORYSIZE * 0x100000) - STUBOFFSET - PLUGINSIZE - CODECSIZE - TTB_SIZE
 #define CODECORIG (ENDAUDIOADDR)
 #endif