author | Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com> |
Thu, 07 Jan 2010 13:38:45 +0200 | |
changeset 33 | 0173bcd7697c |
parent 0 | a41df078684a |
child 62 | 4a8fed1c0ef6 |
permissions | -rw-r--r-- |
0 | 1 |
; Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies). |
2 |
; All rights reserved. |
|
3 |
; This component and the accompanying materials are made available |
|
4 |
; under the terms of the License "Eclipse Public License v1.0" |
|
5 |
; which accompanies this distribution, and is available |
|
6 |
; at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 |
; |
|
8 |
; Initial Contributors: |
|
9 |
; Nokia Corporation - initial contribution. |
|
10 |
; |
|
11 |
; Contributors: |
|
12 |
; |
|
13 |
; Description: |
|
14 |
; e32\kernel\arm\bootmain.s |
|
15 |
; Bootstrap main program |
|
16 |
; |
|
17 |
||
18 |
GBLL __BOOTMAIN_S__ |
|
19 |
||
20 |
INCLUDE bootcpu.inc |
|
21 |
||
22 |
; |
|
23 |
;******************************************************************************* |
|
24 |
; |
|
25 |
||
26 |
AREA |Boot$$Code|, CODE, READONLY, ALIGN=6 |
|
27 |
||
28 |
; |
|
29 |
;******************************************************************************* |
|
30 |
; |
|
31 |
||
32 |
EXPORT TheRomHeader |
|
33 |
TheRomHeader ; this label represents the base of the ROM header |
|
34 |
||
35 |
IF CFG_CustomVectors |
|
36 |
INCLUDE custom_vectors.inc |
|
37 |
ELSE |
|
38 |
||
39 |
; Reset vector |
|
40 |
B ResetEntry |
|
41 |
||
42 |
IF CFG_MMDirect :LAND: (:LNOT: CFG_MMUPresent :LOR: CFG_UseBootstrapVectors) |
|
43 |
B . + KernelCodeOffset ; undef |
|
44 |
B . + KernelCodeOffset ; swi |
|
45 |
B . + KernelCodeOffset ; prefetch |
|
46 |
B . + KernelCodeOffset ; data |
|
47 |
B . + KernelCodeOffset ; |
|
48 |
B . + KernelCodeOffset ; irq |
|
49 |
B . + KernelCodeOffset ; fiq |
|
50 |
||
51 |
ELSE |
|
52 |
IF CFG_DebugBootRom |
|
53 |
IMPORT HandleUndef |
|
54 |
IMPORT HandleSwi |
|
55 |
IMPORT HandleAbtPrefetch |
|
56 |
IMPORT HandleAbtData |
|
57 |
IMPORT HandleRsvdVector |
|
58 |
IMPORT HandleIrq |
|
59 |
IMPORT HandleFiq |
|
60 |
||
61 |
B HandleUndef |
|
62 |
B HandleSwi |
|
63 |
B HandleAbtPrefetch |
|
64 |
B HandleAbtData |
|
65 |
B HandleRsvdVector |
|
66 |
B HandleIrq |
|
67 |
B HandleFiq |
|
68 |
||
69 |
ELSE |
|
70 |
||
71 |
FAULT |
|
72 |
FAULT |
|
73 |
FAULT |
|
74 |
FAULT |
|
75 |
FAULT |
|
76 |
FAULT |
|
77 |
FAULT |
|
78 |
||
79 |
ENDIF |
|
80 |
ENDIF |
|
81 |
ENDIF |
|
82 |
||
83 |
RestartPadBegin |
|
84 |
% 124 - (RestartPadBegin - TheRomHeader) |
|
85 |
||
86 |
; Restart vector - called to reboot under software control |
|
87 |
IMPORT RestartEntry |
|
88 |
B RestartEntry |
|
89 |
||
90 |
; Leave additional space for the rest of the ROM header |
|
91 |
||
92 |
% TRomHeader_sz - 128 |
|
93 |
||
94 |
;*************************************************************************************** |
|
95 |
; MAIN ENTRY POINT |
|
96 |
; Called on hardware reset |
|
97 |
;*************************************************************************************** |
|
98 |
EXPORT ResetEntry |
|
99 |
ResetEntry |
|
100 |
||
101 |
GETCPSR r3 ; cpsr (r3) & r2 MUST be preserved for |
|
102 |
; entry into InitialiseHardware() to |
|
103 |
; allow pre-OS loaders to pass info to |
|
104 |
; bootstrap PSL |
|
105 |
||
106 |
IF :DEF: CFG_BootedInSecureState |
|
107 |
IMPORT SwitchToNonSecureState |
|
108 |
BL SwitchToNonSecureState ; corrupts r0,r1 |
|
109 |
ENDIF |
|
110 |
||
111 |
MOV r0, r3 |
|
112 |
BIC r0, r0, #0x1f |
|
113 |
ORR r0, r0, #0xd3 ; 32-bit SVC mode, no interrupts |
|
114 |
||
115 |
IF CFG_ARMV6 :LOR: CFG_ARMV7 |
|
116 |
ORR r0, r0, #0x100 ; on V6 disable imprecise aborts |
|
117 |
ENDIF |
|
118 |
||
119 |
SETCPSR r0 |
|
120 |
||
121 |
ADR r12, TheRomHeader |
|
122 |
; |
|
123 |
; The following call should, at a minimum |
|
124 |
; 1. Determine the hardware configuration |
|
125 |
; 2. Determine the reset reason. If it is wakeup from a low power mode, perform |
|
126 |
; whatever reentry sequence is required and jump back to the kernel. |
|
127 |
; 3. Set up the memory controller so that at least some RAM is available |
|
128 |
; 4. Set R10 to point to the super page or to a temporary version of the super page |
|
129 |
; with at least the following fields valid: |
|
130 |
; iBootTable, iCodeBase, iActiveVariant, iCpuId |
|
131 |
; and optionally: |
|
132 |
; iSmrData |
|
133 |
; 5. In debug builds initialise the debug serial port |
|
134 |
; |
|
135 |
; Enter with: |
|
136 |
; R2 = value as at entry to ResetEntry, preserved unmodified |
|
137 |
; R3 = value of cpsr on entry to ResetEntry |
|
138 |
; R12 = points to TRomHeader |
|
139 |
; NO STACK |
|
140 |
; R14 = return address (as usual) |
|
141 |
; |
|
142 |
; Leave with : |
|
143 |
; R10 = physical address of super page |
|
144 |
; |
|
145 |
; All registers may be modified by this call |
|
146 |
; |
|
147 |
IMPORT InitialiseHardware |
|
148 |
||
149 |
BL InitialiseHardware ; r0..r14 modified |
|
150 |
ADR r12, TheRomHeader |
|
151 |
||
152 |
ADD sp, r10, #CpuBootStackTop ; set up a boot stack |
|
153 |
LDR r0, [r12, #TRomHeader_iDebugPort] |
|
154 |
STR r0, [r10, #SSuperPageBase_iDebugPort] ; set the debug port in the super page |
|
155 |
DEBUG_INIT_STACKS ; r0..r2 modified (if) |
|
156 |
||
157 |
PRTLN "InitialiseHardware use of optional SuperPage fields:" |
|
158 |
IF :DEF: CFG_ENABLE_SMR_SUPPORT ; When defined the bootstrap PSL in InitialiseHardware() |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
159 |
LDR r0, [r10, #SSuperPageBase_iSmrData] ; must set this field to a valid address of the SMRIB or |
0 | 160 |
; KSuperPageAddressFieldUndefined if no SMRIB found. |
161 |
DWORD r0, " SMR_SUPPORT Enabled - iSmrData" |
|
162 |
ELSE |
|
163 |
MVN r0, #0 ; Set iSmrData field to KSuperPageAddressFieldUndefined (-1) |
|
164 |
STR r0, [r10, #SSuperPageBase_iSmrData] ; when SMR feature not supported in ROM image. This is |
|
165 |
DWORD r0, " SMR_SUPPORT Disabled - iSmrData" ; done to ensure kernel-side code can tell if SMRIB exists. |
|
166 |
ENDIF |
|
167 |
||
168 |
IF CFG_BootLoader :LOR: :DEF: CFG_CopyRomToAddress |
|
169 |
; Copy the code to RAM |
|
170 |
PRTLN "Copy code to RAM" |
|
171 |
LDR r0, [r10, #SSuperPageBase_iCodeBase] ; source |
|
172 |
||
173 |
; Two methods of obtaining the destination physical address: either the |
|
174 |
; config.inc can define CFG_CopyRomToAddress as a numeric constant or it |
|
175 |
; will use the romlinearbase for bootloaders. |
|
176 |
IF :DEF: CFG_CopyRomToAddress |
|
177 |
LDR r1, =CFG_CopyRomToAddress ; destination defined in config.inc (must be physical address) |
|
178 |
ELSE |
|
179 |
LDR r1, [r12, #TRomHeader_iRomBase] ; destination defined in header.iby (must be physical address) |
|
180 |
ENDIF |
|
181 |
IF :DEF: CFG_SupportEmulatedRomPaging |
|
182 |
LDR r2, [r12, #TRomHeader_iUncompressedSize]; size of rom |
|
183 |
ELSE |
|
184 |
LDR r2, [r12, #TRomHeader_iPageableRomStart]; size of unpaged part of ROM |
|
185 |
CMP r2, #0 |
|
186 |
LDREQ r2, [r12, #TRomHeader_iUncompressedSize]; size if not a pageable rom |
|
187 |
ENDIF |
|
188 |
ADD r2, r2, #0x3 |
|
189 |
BIC r2, r2, #0x3 ; make 4byte aligned |
|
190 |
||
191 |
SUB r4, r1, r0 ; save offset destination - source |
|
192 |
DWORD r0, "Source" |
|
193 |
DWORD r1, "Dest" |
|
194 |
DWORD r2, "Size" |
|
195 |
DWORD r4, "Offset" |
|
196 |
ADR lr, ReturnHereAfterCopy |
|
197 |
ADD lr, lr, r4 ; lr = return address in RAM |
|
198 |
B WordMove ; copy the code, return to RAM copy |
|
199 |
LTORG ; Required when CFG_DebugBootRom is enabled |
|
200 |
; WordMove returns to here in RAM |
|
201 |
ReturnHereAfterCopy |
|
202 |
LDR r0, [r10, #SSuperPageBase_iCodeBase] ; |
|
203 |
ADD r0, r0, r4 ; |
|
204 |
STR r0, [r10, #SSuperPageBase_iCodeBase] ; fix up iCodeBase |
|
205 |
LDR r1, [r10, #SSuperPageBase_iBootTable] ; |
|
206 |
ADD r1, r1, r4 ; |
|
207 |
STR r1, [r10, #SSuperPageBase_iBootTable] ; fix up iBootTable |
|
208 |
ADD r12, r12, r4 ; fix up R12 (points to TRomHeader) |
|
209 |
DWORD r0, "New iCodeBase" |
|
210 |
DWORD r1, "New iBootTable" |
|
211 |
DWORD r12, "R12" |
|
212 |
DWORD pc, "PC" |
|
213 |
ENDIF |
|
214 |
||
215 |
LDR r0, [r12, #TRomHeader_iRomRootDirectoryList] |
|
216 |
STR r0, [r10, #SSuperPageBase_iRootDirList] |
|
217 |
LDR r7, [r10, #SSuperPageBase_iBootFlags] ; get boot flags |
|
218 |
BIC r7, r7, #0xff000000 |
|
219 |
STR r7, [r10, #SSuperPageBase_iBootFlags] ; clear top 8 bits |
|
220 |
STR r12, [r10, #SSuperPageBase_iRomHeaderPhys] |
|
221 |
||
222 |
; Live registers here are R10, R12, R13 |
|
223 |
; Determine the machine RAM configuration |
|
224 |
||
225 |
PRTLN "Determine RAM config" |
|
226 |
ADD r11, r10, #CpuRamTableOffset |
|
227 |
STR r11, [r10, #SSuperPageBase_iRamBootData] |
|
228 |
ADD r0, r10, #CpuRomTableOffset |
|
229 |
STR r0, [r10, #SSuperPageBase_iRomBootData] |
|
230 |
||
231 |
MOV r1, #CpuRamTableTop-CpuRomTableOffset |
|
232 |
MOV r2, #0 |
|
233 |
BL WordFill ; zero-fill RAM boot data |
|
234 |
BOOTCALL BTF_RamBanks ; r0 points to list of possible RAM banks |
|
235 |
; in increasing physical address order |
|
236 |
MOV r9, r0 ; into r9 |
|
237 |
||
238 |
TestRamBank1 |
|
239 |
LDR r1, [r9], #4 ; r1 = physical address of bank |
|
240 |
LDR r8, [r9], #4 ; r8 = size of bank |
|
241 |
DWORD r1, "TRB Base" |
|
242 |
DWORD r8, "TRB Size" |
|
243 |
CMP r8, #0 ; reached end? |
|
244 |
BEQ TestRamBank_End ; branch if end |
|
245 |
TST r1, #RAM_VERBATIM ; if flag set, accept bank verbatim |
|
246 |
BIC r2, r1, #RAM_VERBATIM ; clear flag |
|
247 |
MOVNE r0, r11 |
|
248 |
STRNE r2, [r0], #4 ; store base |
|
249 |
STRNE r8, [r0], #4 ; store size |
|
250 |
BNE TestRamBank3 ; do PC check and then next bank |
|
251 |
MVN r3, #0 |
|
252 |
BOOTCALL BTF_SetupRamBank ; set width to 32 |
|
253 |
BL FindRamBankWidth ; test for presence of RAM |
|
254 |
DWORD r3, "TRB ByteLane" |
|
255 |
CMP r3, #0 ; |
|
256 |
BEQ TestRamBank1 ; if no RAM, try next |
|
257 |
BOOTCALL BTF_SetupRamBank ; set width |
|
258 |
TestRamBank3 |
|
259 |
MOV r0, pc ; check if PC is in RAM |
|
260 |
SUBS r0, r0, r1 ; PC - base |
|
261 |
CMPHS r8, r0 ; if PC>=base, check size>(PC-base) |
|
262 |
LDRHI r7, [r10, #SSuperPageBase_iBootFlags] ; |
|
263 |
ORRHI r7, r7, #KBootFlagRunFromRAM ; if so, we are running from RAM |
|
264 |
STRHI r7, [r10, #SSuperPageBase_iBootFlags] ; so set boot flag |
|
265 |
TST r1, #RAM_VERBATIM ; if flag set, accept bank verbatim |
|
266 |
ADDNE r0, r11, #8 |
|
267 |
BNE TestRamBank4 |
|
268 |
MOV r2, r8 ; r2 = max bank size |
|
269 |
MOV r0, r11 ; r0 = allocator data ptr |
|
270 |
BL FindRamBankConfig ; find blocks |
|
271 |
TestRamBank4 |
|
272 |
IF CFG_DebugBootRom |
|
273 |
TestRamBank2 |
|
274 |
LDR r1, [r11], #4 |
|
275 |
DWORD r1, "Block base" |
|
276 |
LDR r1, [r11], #4 |
|
277 |
DWORD r1, "Block size" |
|
278 |
CMP r11, r0 |
|
279 |
BLO TestRamBank2 |
|
280 |
ENDIF |
|
281 |
MOV r11, r0 ; save allocator data ptr |
|
282 |
B TestRamBank1 ; next bank |
|
283 |
||
284 |
TestRamBank_End |
|
285 |
||
286 |
||
287 |
; Determine the machine ROM configuration |
|
288 |
||
289 |
LDR r11, [r10, #SSuperPageBase_iRomBootData] |
|
290 |
LDR r0, [r10, #SSuperPageBase_iBootFlags] |
|
291 |
TST r0, #KBootFlagRunFromRAM |
|
292 |
BEQ TestRomBanks ; branch if running from ROM |
|
293 |
||
294 |
; ROM is actually in RAM |
|
295 |
||
296 |
PRTLN "Running from RAM" |
|
297 |
IF :DEF: CFG_SupportEmulatedRomPaging |
|
298 |
LDR r8, [r12, #TRomHeader_iUncompressedSize]; r8=size of ROM |
|
299 |
ELSE |
|
300 |
LDR r8, [r12, #TRomHeader_iPageableRomStart]; r8=size of unpaged part of ROM |
|
301 |
CMP r8, #0 |
|
302 |
LDREQ r8, [r12, #TRomHeader_iUncompressedSize]; r8=size of ROM if not a pageable rom |
|
303 |
ENDIF |
|
304 |
MVN r2, #0 ; round this up to 64k |
|
305 |
ADD r8, r8, r2, lsr #(32 - CFG_RomSizeAlign) |
|
306 |
BIC r8, r8, r2, lsr #(32 - CFG_RomSizeAlign) |
|
307 |
LDR r9, [r10, #SSuperPageBase_iRamBootData] |
|
308 |
LDR r0, [r10, #SSuperPageBase_iCodeBase] ; running from RAM - ROM base = code base |
|
309 |
LDR r2, [r12, #TRomHeader_iRomBase] ; r2=linear base of ROM block |
|
310 |
MOV r1, r8 ; size of area to excise |
|
311 |
BL ExciseRamArea ; remove RAM which holds image from free list |
|
312 |
LDR r0, [r9, #SRamBank_iSize] |
|
313 |
CMP r0, #0 |
|
314 |
BEQ RomInRam1 ; reached end of RAM list - no extension ROM |
|
315 |
LDR r0, [r9, #SRamBank_iBase] ; r0 = next RAM address after kernel ROM image |
|
316 |
BL CheckForExtensionRom ; check for extension ROM |
|
317 |
BEQ RomInRam1 ; skip if not present |
|
318 |
LDR r1, [r0, #TExtensionRomHeader_iUncompressedSize] ; else r1=extension ROM size |
|
319 |
MVN r2, #0 ; round this up to 64k |
|
320 |
ADD r1, r1, r2, lsr #(32 - CFG_RomSizeAlign) |
|
321 |
BIC r1, r1, r2, lsr #(32 - CFG_RomSizeAlign) |
|
322 |
ADD r8, r8, r1 ; accumulate ROM size |
|
323 |
LDR r2, [r0, #TExtensionRomHeader_iRomRootDirectoryList] |
|
324 |
STR r2, [r10, #SSuperPageBase_iRootDirList] ; and update root dir ptr |
|
325 |
LDR r2, [r0, #TExtensionRomHeader_iRomBase] ; r2=linear base of extension ROM block |
|
326 |
BL ExciseRamArea ; remove RAM which holds extension ROM image from free list |
|
327 |
RomInRam1 |
|
328 |
B DoneRomBanks ; finished with ROM |
|
329 |
||
330 |
; ROM is actually in ROM or FLASH |
|
331 |
TestRomBanks |
|
332 |
PRTLN "Running from ROM/FLASH" |
|
333 |
BOOTCALL BTF_RomBanks ; r0 points to list of possible ROM banks |
|
334 |
; in increasing physical address order |
|
335 |
MOV r9, r0 ; R9 -> bank list |
|
336 |
MOV r11, #0 |
|
337 |
BOOTCALL BTF_SetupRomBank ; do any setup prior to detection |
|
338 |
LDR r11, [r10, #SSuperPageBase_iRomBootData] |
|
339 |
||
340 |
; Walk through list of possible banks |
|
341 |
; Call a setup function for each one |
|
342 |
; This should set up width/wait states if not set by earlier initialisation. |
|
343 |
; It may also do detection of optional banks if required. |
|
344 |
TestRomBank1 |
|
345 |
LDMIA r9!, {r1-r4} |
|
346 |
STMIA r11, {r1-r4} |
|
347 |
DWORD r1, "TROMB Base" |
|
348 |
DWORD r2, "TROMB Size" |
|
349 |
DWORD r4, "TROMB LinB" |
|
350 |
CMP r2, #0 ; end of list? |
|
351 |
BEQ CalcRomLinBases ; branch if so |
|
352 |
BOOTCALL BTF_SetupRomBank ; do detection if needed (for optional ROMs) |
|
353 |
||
354 |
LDMIA r11, {r1-r4} |
|
355 |
IF CFG_DebugBootRom |
|
356 |
DWORD r1, "TROMB PostDet Base" |
|
357 |
DWORD r2, "TROMB PostDet Size" |
|
358 |
DWORD r4, "TROMB PostDet LinB" |
|
359 |
ENDIF |
|
360 |
||
361 |
CMP r2, #0 |
|
362 |
ADDNE r11, r11, #SRomBank_sz ; if bank present, increment r11 |
|
363 |
B TestRomBank1 |
|
364 |
||
365 |
CalcRomLinBases |
|
366 |
LDR r11, [r10, #SSuperPageBase_iRomBootData] |
|
367 |
MOV r8, #0 ; total ROM size |
|
368 |
CalcRomLinBases1 |
|
369 |
LDMIA r11!, {r0,r2-r4} ; r0=phys base, r2=size, r4=lin base |
|
370 |
DWORD r0, "CRLB Base" |
|
371 |
DWORD r2, "CRLB Size" |
|
372 |
DWORD r4, "CRLB LinB" |
|
373 |
CMP r2, #0 ; reached end? |
|
374 |
BEQ CalcRomLinBases_End |
|
375 |
ADD r8, r8, r2 ; accumulate size |
|
376 |
IF CFG_MMUPresent |
|
377 |
CMP r4, #0 ; lin addr override? |
|
378 |
MOVNE r9, r4 ; if so, take it |
|
379 |
ELSE |
|
380 |
MOV r9, r0 ; if no MMU, lin = phys |
|
381 |
ENDIF |
|
382 |
SUBS r1, r12, r0 ; check if this is boot block - R1=rom header phys-base |
|
383 |
CMPHS r2, r1 ; if rom hdr phys>=base, compare size with rom header phys-base |
|
384 |
IF CFG_MMUPresent |
|
385 |
LDRHI r9, [r12, #TRomHeader_iRomBase] ; linear base of boot ROM (= lin addr of rom header) |
|
386 |
SUBHI r9, r9, r1 ; calculate linear address corresponding to base of ROM block |
|
387 |
ENDIF |
|
388 |
BHI CalcRomLinBases2 ; skip if boot block |
|
389 |
BL CheckForExtensionRom ; else check if this is extension ROM |
|
390 |
BEQ CalcRomLinBases2 ; skip if not |
|
391 |
IF CFG_MMUPresent |
|
392 |
LDR r9, [r0, #TExtensionRomHeader_iRomBase] ; if it is, take linear address override |
|
393 |
ENDIF |
|
394 |
LDR r1, [r0, #TExtensionRomHeader_iRomRootDirectoryList] |
|
395 |
STR r1, [r10, #SSuperPageBase_iRootDirList] ; and update root dir ptr |
|
396 |
CalcRomLinBases2 |
|
397 |
DWORD r9, "CRLB Final Linear Base" |
|
398 |
STR r9, [r11, #-4] ; write final linear base |
|
399 |
IF CFG_MMUPresent |
|
400 |
ADD r9, r9, r2 ; and step on by size |
|
401 |
ENDIF |
|
402 |
B CalcRomLinBases1 ; do next bank |
|
403 |
CalcRomLinBases_End |
|
404 |
||
405 |
DoneRomBanks |
|
406 |
STR r8, [r10, #SSuperPageBase_iTotalRomSize] ; save total ROM size |
|
407 |
||
408 |
; Support for areas? |
|
409 |
; Put it here if needed. |
|
410 |
||
411 |
; RAM reservation/pre-allocation section |
|
412 |
; |
|
413 |
; SSuperPageBase_iRamBootData member points to two arrays/lists that are |
|
414 |
; used to initialise the kernel RAM Allocator. On entry to this section the |
|
415 |
; list contains the free RAM regions and no pre-allocations: |
|
416 |
; <free ram region><...><null entry><null entry> |
|
417 |
; |
|
418 |
; On exit from this section pre-allocated entries may have been added: |
|
419 |
; <free ram region><><null entry><pre-allocated ram region><><null entry> |
|
420 |
; |
|
421 |
; - Setup R11 to point to free entry after first null entry in iRamBootData list |
|
422 |
; - Reserve any SMRs in the SP SMRIB by adding them to the pre-allocation list |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
423 |
; - Call the bootstrap PSL to allow further platform-specific RAM reservation |
0 | 424 |
; |
425 |
||
426 |
; Point R11 to preallocated block list |
|
427 |
LDR r11, [r10, #SSuperPageBase_iRamBootData] |
|
428 |
3 |
|
429 |
LDMIA r11!, {r0,r1} |
|
430 |
CMP r1, #0 |
|
431 |
BNE %BT3 |
|
432 |
||
433 |
; At this point in bootstrap: |
|
434 |
; r10 = pointer to super page (SP) |
|
435 |
; r11 = address of first pre-alloc SRamBank after first terminator entry |
|
436 |
; r12 = pointer to ROM header |
|
437 |
; r13 = stack pointer |
|
438 |
||
439 |
; Reserve SMR memory blocks, if SMRIB valid in super page |
|
440 |
||
441 |
MOV r6, #0 ; Setup r6 to count SMRIB entries for trace |
|
442 |
LDR r5, [r10, #SSuperPageBase_iSmrData] |
|
443 |
CMN r5, #1 ; Compare to KSuperPageAddressFieldUndefined |
|
444 |
BCS NoSMRIB ; jump over if no SMRIB |
|
445 |
PRTLN "Processing (any) SMRIB..." |
|
446 |
4 |
|
447 |
LDMIA r5, {r0, r1} ; load iBase and iSize members |
|
448 |
ADD r5, r5, #SSmrBank_sz ; Skip the two other members, inc R5 to next entry |
|
449 |
CMP r1, #0 |
|
450 |
BEQ DoneSMRReservation ; Jump out of loop if no more SMRs |
|
451 |
||
452 |
MVN r3, #0 |
|
453 |
ANDS r2, r1, r3, LSR #20 |
|
454 |
FAULT NE ; Fault if SMR Size is not multiple of 4Kb |
|
455 |
||
456 |
STMIA r11!, {r0, r1} ; Add SMR to pre-alloc list |
|
457 |
ADD r6, r6, #1 |
|
458 |
B %BT4 |
|
459 |
; No need to add null entry as the |
|
460 |
DoneSMRReservation ; SRamBank area has been zero filled |
|
461 |
||
462 |
CMP r6, #0 |
|
463 |
BNE %FT5 |
|
464 |
PRTLN "PSL created SMRIB of zero size!" |
|
465 |
B NoSMRIB |
|
466 |
5 |
|
467 |
DWORD r6, "PSL created SMRIB of X entries" |
|
468 |
IF CFG_DebugBootRom |
|
469 |
PRTLN "SMRIB Memory Dump:" |
|
470 |
LDR r5, [r10, #SSuperPageBase_iSmrData] |
|
471 |
MOV r6, r6, LSL #4 |
|
472 |
MEMDUMP r5, r6 |
|
473 |
ENDIF |
|
474 |
||
475 |
NoSMRIB |
|
476 |
||
477 |
; Here r11 points to the null terminator of the preallocated block list |
|
478 |
||
479 |
; Reserve any platform-dependent extra physical memory here. |
|
480 |
; Two methods are available: |
|
481 |
; 1. ExciseRamArea - the kernel will then not treat the region as RAM |
|
482 |
; 2. Add preallocation regions to the RAM bank list. R11 has been set |
|
483 |
; to point to the first of these. List is terminated by a zero size. |
|
484 |
; The kernel will treat these regions as RAM. |
|
485 |
; |
|
486 |
BOOTCALL BTF_Reserve |
|
487 |
||
488 |
IF CFG_DebugBootRom |
|
489 |
; In debug, dump ROM and RAM bank config |
|
490 |
PRTLN "ROM and RAM config:" |
|
491 |
LDR r11, [r10, #SSuperPageBase_iRomBootData] |
|
492 |
MOV r1, #CpuRamTableTop-CpuRomTableOffset |
|
493 |
MEMDUMP r11, r1 |
|
494 |
ENDIF |
|
495 |
||
496 |
; Calculate total RAM size |
|
497 |
LDR r11, [r10, #SSuperPageBase_iRamBootData] |
|
498 |
MOV r9, #0 |
|
499 |
AccumulateRamSize |
|
500 |
LDMIA r11!, {r0,r1} |
|
501 |
ADD r9, r9, r1 |
|
502 |
CMP r1, #0 |
|
503 |
BNE AccumulateRamSize |
|
504 |
DWORD r9, "TotalRamSize" |
|
505 |
STR r9, [r10, #SSuperPageBase_iTotalRamSize] |
|
506 |
||
507 |
; RAM reservation/pre-allocation section end |
|
508 |
; |
|
509 |
||
510 |
; find the kernel image and point R11 to it |
|
511 |
PRTLN "Find primary" |
|
512 |
BL FindPrimary |
|
513 |
STR r11, [sp, #-4]! |
|
514 |
||
515 |
IF CFG_MMDirect |
|
516 |
; direct model - work out the end of the kernel memory area |
|
517 |
LDR r8, [r12, #TRomHeader_iKernelLimit] ; end of kernel heap, rounded up to 4K |
|
518 |
IF CFG_MMUPresent |
|
519 |
GETPARAM BPR_PageTableSpace, DefaultPTAlloc ; get reserved space for page tables |
|
520 |
ADD r8, r8, r0 ; add space for page tables |
|
521 |
IF :LNOT: :DEF: CFG_MinimiseKernelHeap |
|
522 |
MVN r1, #0 |
|
523 |
ADD r8, r8, r1, LSR #12 |
|
524 |
BIC r8, r8, r1, LSR #12 ; round up to 1Mb to give limit |
|
525 |
ENDIF |
|
526 |
ENDIF |
|
527 |
STR r8, [r10, #SSuperPageBase_iKernelLimit] |
|
528 |
DWORD r8, "Kernel Limit" |
|
529 |
||
530 |
GETPARAM BPR_KernDataOffset, SuperCpuSize ; get kernel data offset into R0 with default |
|
531 |
LDR r2, [r12, #TRomHeader_iKernDataAddress] ; |
|
532 |
SUB r0, r2, r0 ; r0 = super page linear address |
|
533 |
DWORD r0, "SuperPageLin" |
|
534 |
||
535 |
IF CFG_BootLoader |
|
536 |
||
537 |
; for bootloader calculate linear RAM base as: |
|
538 |
; 1. TRomHeader::iKernDataAddress - KernDataOffset if BootLdr_ImgAddr > physical RAM base |
|
539 |
; 2. TRomHeader::iKernDataAddress - KernDataOffset - X if BootLdr_ImgAddr = physical RAM base |
|
540 |
; where X = amount of physical RAM preceding the super page in physical address order |
|
541 |
; physical address of super page is chosen to allow BootLdr_ExtraRAM (usually 1Mb) of 'user' RAM |
|
542 |
||
543 |
MOV r2, r0 ; r2 = super page lin |
|
544 |
GETMPARAM BPR_BootLdrImgAddr ; R0 = image physical address |
|
545 |
LDR r8, [r10, #SSuperPageBase_iRamBootData] |
|
546 |
LDR r3, [r8, #0] ; r3 = physical RAM base |
|
547 |
CMP r0, r3 |
|
548 |
MOV r0, r2 ; |
|
549 |
BHI SuperPageAtBeginning ; if boot image not at RAM base, put super page there |
|
550 |
LDR r1, [r12, #TRomHeader_iUserDataAddress] ; 'user' linear address |
|
551 |
MOV r2, r0 ; r2 = super page lin |
|
552 |
GETPARAM BPR_BootLdrExtraRAM, 0x100000 ; get extra RAM size into R0, default to 1M |
|
553 |
ADD r1, r1, r0 ; linear top of RAM |
|
554 |
SUB r1, r1, r2 ; r1 = total amount of RAM reserved at top |
|
555 |
DWORD r1, "ReserveAtTop" |
|
556 |
LDR r0, [r10, #SSuperPageBase_iTotalRamSize] ; r0 = total physical RAM size |
|
557 |
SUB r0, r0, r1 ; r2 = physical RAM below super page |
|
558 |
DWORD r0, "RamBelowSuperPage" |
|
559 |
SUB r0, r2, r0 ; r0 = linear RAM base |
|
560 |
||
561 |
ENDIF ; CFG_BootLoader |
|
562 |
; for non-bootloader, iRamBase = TRomHeader::iKernDataAddress - KernDataOffset |
|
563 |
SuperPageAtBeginning |
|
564 |
STR r0, [r10, #SSuperPageBase_iRamBase] |
|
565 |
DWORD r0, "iRamBase" |
|
566 |
||
567 |
ENDIF |
|
568 |
||
569 |
; initialise the RAM allocator |
|
570 |
PRTLN "Init RAM allocator" |
|
571 |
MOV r2, #BMA_Init |
|
572 |
BOOTCALL BTF_Alloc |
|
573 |
||
574 |
; get the final super page physical address |
|
575 |
MOV r2, #BMA_SuperCPU |
|
576 |
BOOTCALL BTF_Alloc |
|
577 |
DWORD r0, "Final SuperPage Phys" |
|
578 |
||
579 |
; if super page has moved, relocate it |
|
580 |
CMP r0, r10 |
|
581 |
BLNE RelocateSuperPage |
|
582 |
LDR r11, [sp], #4 ; recover kernel image pointer |
|
583 |
||
584 |
IF CFG_MMUPresent |
|
585 |
||
586 |
; initialise the memory mapping system |
|
587 |
PRTLN "InitMemMapSystem" |
|
588 |
BL InitMemMapSystem |
|
589 |
||
590 |
; map the ROM |
|
591 |
PRTLN "Map ROM" |
|
592 |
LDR r9, [r10, #SSuperPageBase_iRomBootData] |
|
593 |
||
594 |
MapRomBlock |
|
595 |
LDR r0, [r9, #SRomBank_iLinBase] ; r0 = linear base |
|
596 |
LDR r1, [r9, #SRomBank_iBase] ; r1 = physical base |
|
597 |
LDR r3, [r9, #SRomBank_iSize] ; r3 = size |
|
598 |
MOV r2, #BTP_Rom ; r2 = access permissions |
|
599 |
MOV r4, #20 ; r4 = log2(max page size) |
|
600 |
CMP r3, #0 |
|
601 |
BEQ MapRomDone ; branch out if reached end of list |
|
602 |
BL MapContiguous |
|
603 |
ADD r9, r9, #SRomBank_sz |
|
604 |
B MapRomBlock |
|
605 |
MapRomDone |
|
606 |
||
607 |
||
608 |
IF CFG_MMDirect |
|
609 |
||
610 |
; direct model - map all RAM in one block, starting at SSuperPageBase::iRamBase |
|
611 |
; permissions are kernel up to the end of the kernel heap, user after |
|
612 |
; also map non-kernel RAM at its physical address, uncached |
|
613 |
PRTLN "Direct Map RAM" |
|
614 |
LDR r8, [r10, #SSuperPageBase_iKernelLimit] ; top of kernel area (linear) |
|
615 |
LDR r9, [r10, #SSuperPageBase_iRamBootData] |
|
616 |
MOV r2, #BTP_Kernel ; start with kernel access permissions |
|
617 |
MOV r4, #20 |
|
618 |
LDR r0, [r10, #SSuperPageBase_iRamBase] ; linear address |
|
619 |
DWORD r0, "Direct Map RAM Base" |
|
620 |
MapRamBlock |
|
621 |
LDMIA r9!, {r1,r5} ; r1 = bank physical base, r5 = bank size |
|
622 |
CMP r5, #0 ; reached end of list? |
|
623 |
BEQ MapRamBlock_End ; jump if end |
|
624 |
DWORD r1, "Bank base" |
|
625 |
DWORD r5, "Bank size" |
|
626 |
SUBS r3, r8, r0 ; r3 = kernel limit - base |
|
627 |
MOVLO r3, r5 ; if base>=kernel limit, size to map = bank size |
|
628 |
BLO MapUserRamBlock ; if base>=kernel limit, map user |
|
629 |
CMP r3, r5 ; kernel area >= size? |
|
630 |
MOVHS r3, r5 ; if so, size to map = bank size |
|
631 |
BHS MapKernelRamBlock ; and map kernel block |
|
632 |
BL MapContiguous ; else map size r3 as kernel |
|
633 |
ADD r0, r0, r3 ; increment linear address |
|
634 |
ADD r1, r1, r3 ; increment physical address |
|
635 |
SUB r3, r5, r3 ; remaining size of bank |
|
636 |
MapUserRamBlock |
|
637 |
MOV r2, #BTP_User ; change to user permissions |
|
638 |
BL MapContiguous ; Map bank |
|
639 |
ADD r0, r0, r3 ; increment linear address |
|
640 |
STMFD sp!, {r0} ; save linear address |
|
641 |
MOV r0, r1 ; linear = physical |
|
642 |
MOV r2, #BTP_Uncached ; map as uncached user |
|
643 |
BL MapContiguous |
|
644 |
LDMFD sp!, {r0} ; recover linear address |
|
645 |
B MapRamBlock |
|
646 |
MapKernelRamBlock |
|
647 |
BL MapContiguous ; Map bank |
|
648 |
ADD r0, r0, r3 ; increment linear address |
|
649 |
B MapRamBlock |
|
650 |
MapRamBlock_End |
|
651 |
||
652 |
ELSE |
|
653 |
||
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
654 |
; moving, multiple or flexible model |
0 | 655 |
|
656 |
; map super page + CPU page |
|
657 |
PRTLN "Map super/CPU pages" |
|
658 |
MOV r0, #KSuperPageLinAddr ; linear |
|
659 |
MOV r1, r10 ; physical |
|
660 |
MOV r2, #BTP_SuperCPU ; permissions |
|
661 |
MOV r3, #SuperCpuSize ; size |
|
662 |
MOV r4, #12 ; map size |
|
663 |
BL MapContiguous |
|
664 |
||
665 |
; allocate one page for page table info and map it |
|
666 |
PRTLN "Map PTINFO" |
|
667 |
LDR r0, =KPageTableInfoBase ; linear |
|
668 |
MOV r2, #BTP_PtInfo ; permissions |
|
669 |
MOV r3, #0x1000 ; size |
|
670 |
MOV r4, #12 ; map size |
|
671 |
BL AllocAndMap |
|
672 |
||
673 |
ENDIF ; CFG_MMDirect |
|
674 |
||
675 |
IF CFG_MMMultiple |
|
676 |
||
677 |
; on multiple model, map ASID info area |
|
678 |
PRTLN "Map ASID info" |
|
679 |
LDR r0, =KAsidInfoBase ; linear |
|
680 |
MOV r2, #BTP_PtInfo ; permissions |
|
681 |
MOV r3, #0x1000 ; size |
|
682 |
MOV r4, #12 ; map size |
|
683 |
BL AllocAndMap |
|
684 |
||
685 |
ENDIF |
|
686 |
||
687 |
IF CFG_MMFlexible |
|
688 |
||
689 |
; on flexible model, map page array segment area |
|
690 |
PRTLN "Map PageArrayGroup" |
|
691 |
LDR r0, =KPageArraySegmentBase ; linear |
|
692 |
MOV r2, #BTP_Kernel ; permissions |
|
693 |
MOV r3, #0x1000 ; size |
|
694 |
MOV r4, #12 ; map size |
|
695 |
BL AllocAndMap |
|
696 |
||
697 |
ENDIF |
|
698 |
||
699 |
; map hardware |
|
700 |
PRTLN "Map HW" |
|
701 |
BOOTCALL BTF_HwBanks ; get pointer to list of HW banks into r0 |
|
702 |
MOV r9, r0 ; into r9 |
|
703 |
IF :LNOT: CFG_MMDirect |
|
704 |
MOV r0, #KPrimaryIOBase ; linear address for HW |
|
705 |
ENDIF |
|
706 |
||
707 |
IF :DEF: CFG_HasL210Cache :LOR: :DEF: CFG_HasL220Cache :LOR: :DEF: CFG_HasPL310Cache |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
708 |
LDR r5, [r10, #SSuperPageBase_iArmL2CacheBase] ; r5 = PhysAddr of External Cache Controller. |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
709 |
MOV r7, #1 ; R7 != 0 => LinAddr of ExtCacheCtrl is not found yet. Set R7 to 0 when found. |
0 | 710 |
ENDIF |
711 |
MapHwBank |
|
712 |
LDR r1, [r9], #4 ; get phys addr / size |
|
713 |
DWORD r1, "HwBank Entry" |
|
714 |
MVN r14, #0 |
|
715 |
ANDS r3, r1, #HW_SIZE_MASK ; r3 = bottom 8 bits = #pages |
|
716 |
BEQ MapHwBank_End ; jump out if end of list (number of pages = 0) |
|
717 |
MOV r3, r3, LSL #12 ; pages -> bytes |
|
718 |
AND r4, r1, #HW_MULT_MASK |
|
719 |
CMP r4, #HW_MULT_64K |
|
720 |
MOVEQ r3, r3, LSL #4 ; if MULT_64K, multiply page count by 16 |
|
721 |
MOVEQ r4, #16 ; and use 64K pages |
|
722 |
MOVHI r3, r3, LSL #8 ; if MULT_1M, multiply page count by 256 |
|
723 |
MOVHI r4, #20 ; and use 1M pages |
|
724 |
MOVLO r4, #12 ; otherwise use 4K pages |
|
725 |
TST r1, #HW_MAP_EXT2 ; linear address specified? |
|
726 |
LDRNE r6, [r9], #4 ; if so get it from next descriptor word |
|
727 |
TST r1, #HW_MAP_EXT ; extended mapping? |
|
728 |
LDRNE r2, [r9], #4 ; if so, get permissions from next descriptor word |
|
729 |
MOVEQ r2, #BTP_Hw ; else use standard HW permissions |
|
730 |
TST r1, #HW_MAP_EXT2 ; linear address specified? |
|
731 |
AND r1, r1, r14, LSL #12 ; r1 = top 20 bits = physical address |
|
732 |
BNE MapHwBank2 ; branch if linear address specified |
|
733 |
IF CFG_MMDirect |
|
734 |
MOV r0, r1 ; linear = physical |
|
735 |
ELSE |
|
736 |
MVN r6, r14, LSL r4 ; r6 = 2^r4-1 |
|
737 |
ADD r0, r0, r6 |
|
738 |
BIC r0, r0, r6 ; round up linear address |
|
739 |
ENDIF |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
740 |
BL MapContiguous ; make mapping |
0 | 741 |
IF :DEF: CFG_HasL210Cache :LOR: :DEF: CFG_HasL220Cache :LOR: :DEF: CFG_HasPL310Cache |
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
742 |
MOV r4, r0 ; r4 = LinAddr of the current HwBank |
0 | 743 |
ENDIF |
744 |
ADD r0, r0, r3 ; increment linear address |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
745 |
IF :DEF: CFG_HasL210Cache :LOR: :DEF: CFG_HasL220Cache :LOR: :DEF: CFG_HasPL310Cache |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
746 |
B MapHwBank3 ; test whether the current HwBank contains ExtCacheCtrl |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
747 |
ELSE |
0 | 748 |
B MapHwBank ; next bank |
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
749 |
ENDIF |
0 | 750 |
MapHwBank2 |
751 |
STR r0, [sp, #-4]! ; save default linear address |
|
752 |
MOV r0, r6 ; r0 = specified linear address |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
753 |
BL MapContiguous ; make mapping |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
754 |
IF :DEF: CFG_HasL210Cache :LOR: :DEF: CFG_HasL220Cache :LOR: :DEF: CFG_HasPL310Cache |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
755 |
MOV r4, r0 ; r4 = LinAddr of the current HwBank |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
756 |
ENDIF |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
757 |
LDR r0, [sp], #4 ; restore default linear address |
0 | 758 |
|
759 |
IF :DEF: CFG_HasL210Cache :LOR: :DEF: CFG_HasL220Cache :LOR: :DEF: CFG_HasPL310Cache |
|
33
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
760 |
MapHwBank3 |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
761 |
; Check if the current HW bank contains External Cache Controller. |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
762 |
; If so, write down its virtual address into SSuperPageBase::iArmL2CacheBase. |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
763 |
; r5 = phys. address of the external cache controller |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
764 |
; r1 = physical address of the current HW bank |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
765 |
; r4 = virtual address of the current HW bank |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
766 |
; r3 = the size of the current bank |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
767 |
; r7 = 0 if we have already found cache controller in of the previous HW banks |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
768 |
CMP r7, #0 ; Still in search for linear address of external cache controller? |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
769 |
BEQ MapHwBank ; If no, go to the next HwBank |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
770 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
771 |
SUBS r7, r5, r1 ; r7 = PhysAddr of ExtCacheCtrl - PhysAddr of current HwBank |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
772 |
; i.e. offset of cache controller with respect to the current bank |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
773 |
BLO MapHwBank ; ofsset(in r7) is <0 so not in this bank (and r7 != 0) |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
774 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
775 |
CMP r7, r3 ; If 0 <= r7 < r3 then it's in this bank |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
776 |
BHS MapHwBank ; Not in this bank (and r7 != 0) |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
777 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
778 |
; The current HwBank holds External Cache Controller |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
779 |
ADD r5, r7, r4 ; r5 = LinAddr of ExtCacheCtrl |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
780 |
STR r5, [r10, #SSuperPageBase_iArmL2CacheBase] ; Set Linear Address of ExtCacheCtrl in super page |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
781 |
|
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
782 |
MOV r7, #0 ; Mark that Linear Address of ExtCacheCtrl is found |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
783 |
ENDIF ; IF :DEF: CFG_HasL210Cache :LOR: :DEF: CFG_HasL220Cache :LOR: :DEF: CFG_HasPL310Cache |
0173bcd7697c
Revision: 201001
Dremov Kirill (Nokia-D-MSW/Tampere) <kirill.dremov@nokia.com>
parents:
0
diff
changeset
|
784 |
|
0 | 785 |
B MapHwBank ; next bank |
786 |
||
787 |
MapHwBank_End |
|
788 |
||
789 |
; dummy uncached mapping |
|
790 |
PRTLN "Setup dummy uncached" |
|
791 |
IF CFG_MMDirect |
|
792 |
GETMPARAM BPR_UncachedLin ; linear address into R0 |
|
793 |
MOV r3, #0x1000 ; 4K |
|
794 |
MOV r4, #12 ; small page |
|
795 |
ADD r1, r10, #0x2000 ; physical |
|
796 |
ELSE |
|
797 |
LDR r0, =KDummyUncachedAddr ; linear address into R0 |
|
798 |
MOV r3, #0x1000 ; 4K |
|
799 |
MOV r4, #12 ; small page |
|
800 |
MOV r1, r10 ; physical = super page physical |
|
801 |
ENDIF |
|
802 |
MOV r2, #BTP_Uncached ; permissions |
|
803 |
STR r0, [r10, #SSuperPageBase_iUncachedAddress] |
|
804 |
IF CFG_MMUPresent :LAND: :LNOT: CFG_MMDirect |
|
805 |
BL AllocAndMap |
|
806 |
ELSE |
|
807 |
BL MapContiguous |
|
808 |
ENDIF |
|
809 |
||
810 |
IF CFG_MMDirect |
|
811 |
IF SMP |
|
812 |
||
813 |
; AP Boot Page |
|
814 |
GETMPARAM BPR_APBootLin ; linear address into R0 |
|
815 |
DWORD r0, "APBootPageLin" |
|
816 |
STR r0, [r10, #SSuperPageBase_iAPBootPageLin] |
|
817 |
MOV r3, #0x1000 ; 4K |
|
818 |
MOV r4, #12 ; small page |
|
819 |
ADD r1, r10, #0x3000 ; physical |
|
820 |
DWORD r1, "APBootPagePhys" |
|
821 |
STR r1, [r10, #SSuperPageBase_iAPBootPagePhys] |
|
822 |
MOV r2, #BTP_Uncached ; permissions |
|
823 |
BL MapContiguous |
|
824 |
MOV r0, r1 |
|
825 |
MOV r1, #0x1000 |
|
826 |
MOV r2, #0 |
|
827 |
BL WordFill ; clear AP Boot Page |
|
828 |
ENDIF |
|
829 |
ENDIF |
|
830 |
||
831 |
IF CFG_MMDirect :LAND: CFG_UseBootstrapVectors |
|
832 |
STR r12, [sp, #-4]! ; exc phys = ROM header phys |
|
833 |
ELSE |
|
834 |
LDR r0, [r11, #TRomImageHeader_iCodeAddress] ; r0 = kernel code base linear |
|
835 |
DWORD r0, "KernCodeLin" |
|
836 |
BL RomLinearToPhysical ; r0 = kernel code base physical |
|
837 |
DWORD r0, "KernCodePhys" |
|
838 |
STR r0, [sp, #-4]! ; save it |
|
839 |
ENDIF |
|
840 |
||
841 |
PRTLN "Switch to virtual" |
|
842 |
BL SwitchToVirtual ; SWITCH TO VIRTUAL ADDRESSES |
|
843 |
||
844 |
; map the exception vectors |
|
845 |
PRTLN "Map vectors" |
|
846 |
MRC p15, 0, r0, c1, c0, 0 ; R0 = MMUCR |
|
847 |
TST r0, #MMUCR_V ; HIVECS? |
|
848 |
MOV r0, #0 ; if not, linear = 0 |
|
849 |
SUBNE r0, r0, #0x10000 ; else linear = 0xFFFF0000 |
|
850 |
LDR r1, [sp], #4 ; physical |
|
851 |
IF CFG_MMDirect |
|
852 |
CMP r1, r0 ; in direct model, if lin = phys mapping is already there |
|
853 |
BEQ SkipMapExcVectors |
|
854 |
ENDIF |
|
855 |
MOV r2, #BTP_Vector ; permissions |
|
856 |
MOV r3, #0x1000 ; map size |
|
857 |
MOV r4, #12 ; page size |
|
858 |
BL MapContiguous |
|
859 |
SkipMapExcVectors |
|
860 |
||
861 |
ELSE ; CFG_MMUPresent |
|
862 |
||
863 |
GETMPARAM BPR_UncachedLin ; address into R0 |
|
864 |
STR r0, [r10, #SSuperPageBase_iUncachedAddress] |
|
865 |
||
866 |
ENDIF ; CFG_MMUPresent |
|
867 |
||
868 |
; get initial thread stack size |
|
869 |
MVN r9, #0 |
|
870 |
LDR r8, [r11, #TRomImageHeader_iStackSize] ; kernel stack size |
|
871 |
ADD r8, r8, r9, LSR #20 |
|
872 |
BIC r8, r8, r9, LSR #20 ; round up to 4K |
|
873 |
DWORD r8, "InitStackSize" |
|
874 |
||
875 |
IF :LNOT: CFG_MMDirect |
|
876 |
||
877 |
; calculate initial size of kernel heap, needs to be just enough to allow the device to |
|
878 |
; boot past the point where the kernel heap is mutated to be growable. |
|
879 |
LDR r3, [r10, #SSuperPageBase_iTotalRamSize] ; total RAM size |
|
880 |
LDR r2, [r11, #TRomImageHeader_iHeapSizeMin] ; kernel heap size min |
|
881 |
IF :DEF: CFG_MMFlexible |
|
882 |
; Flexible memory model requires approx. 2 bytes per RAM page. |
|
883 |
MOV r3, r3, LSR #11 ; Total RAM size in half pages |
|
884 |
ELSE |
|
885 |
; Other memory models require approx. 1 byte per RAM page. |
|
886 |
MOV r3, r3, LSR #12 ; Total RAM size in pages |
|
887 |
ENDIF |
|
888 |
IF :DEF: CFG_KernelHeapMultiplier |
|
889 |
LDR r0, =CFG_KernelHeapMultiplier ; multiplier * 16 |
|
890 |
MUL r3, r0, r3 |
|
891 |
MOV r3, r3, LSR #4 |
|
892 |
ENDIF |
|
893 |
IF :DEF: CFG_KernelHeapBaseSize |
|
894 |
LDR r0, =CFG_KernelHeapBaseSize |
|
895 |
ADD r3, r3, r0 ; add base size specified in config.inc |
|
896 |
ELSE |
|
897 |
ADD r3, r3, #48*1024 ; add default base size of 48K |
|
898 |
; was 24K on 15/07/09, increased after H2 test ROM exceed this |
|
899 |
ENDIF |
|
900 |
DWORD r3, "CalcInitHeap" |
|
901 |
DWORD r2, "SpecInitHeap" |
|
902 |
CMP r3, r2 |
|
903 |
MOVLS r3, r2 ; if ROMBUILD specified figure higher, use it |
|
904 |
ADD r3, r3, r9, LSR #20 |
|
905 |
BIC r3, r3, r9, LSR #20 ; round up to 4K |
|
906 |
DWORD r3, "preliminary InitHeap" |
|
907 |
||
908 |
; map kernel .data/.bss, initial thread stack and kernel heap |
|
909 |
LDR r7, [r12, #TRomHeader_iTotalSvDataSize] ; total size of kernel .data / .bss |
|
910 |
ADD r7, r7, r9, LSR #20 |
|
911 |
BIC r7, r7, r9, LSR #20 ; round up to 4K |
|
912 |
DWORD r7, "Rounded SvData" |
|
913 |
LDR r0, [r12, #TRomHeader_iKernDataAddress] ; linear address |
|
914 |
MOV r2, #BTP_Kernel ; permissions |
|
915 |
ADD r3, r3, r8 ; size = heap size + stack size + data/bss size |
|
916 |
ADD r3, r3, r7 |
|
917 |
IF :LNOT: :DEF: CFG_MinimiseKernelHeap |
|
918 |
ADD r3, r3, r9, LSR #16 |
|
919 |
BIC r3, r3, r9, LSR #16 ; round total up to 64K |
|
920 |
ENDIF |
|
921 |
DWORD r3, "Total SvHeap" |
|
922 |
SUB r4, r3, r8 ; subtract stack size |
|
923 |
SUB r4, r4, r7 ; subtract data/bss size |
|
924 |
STR r4, [r10, #SSuperPageBase_iInitialHeapSize] ; save in super page |
|
925 |
DWORD r4, "InitHeap" |
|
926 |
MOV r4, #16 ; use 64k pages, 1mb fails when converted to DChunk |
|
927 |
PRTLN "Map stack/heap" |
|
928 |
BL AllocAndMap |
|
929 |
||
930 |
ELSE ; CFG_MMDirect |
|
931 |
||
932 |
LDR r7, [r12, #TRomHeader_iTotalSvDataSize] ; total size of kernel .data / .bss |
|
933 |
ADD r7, r7, r9, LSR #20 |
|
934 |
BIC r7, r7, r9, LSR #20 ; round up to 4K |
|
935 |
DWORD r7, "Rounded SvData" |
|
936 |
LDR r3, [r11, #TRomImageHeader_iHeapSizeMax] ; kernel heap max |
|
937 |
STR r3, [r10, #SSuperPageBase_iInitialHeapSize] ; save in super page |
|
938 |
DWORD r3, "InitHeap" |
|
939 |
||
940 |
ENDIF ; CFG_MMDirect |
|
941 |
||
942 |
; fill initial thread stack with 0xff |
|
943 |
||
944 |
LDR r0, [r12, #TRomHeader_iKernDataAddress] ; linear address |
|
945 |
ADD r0, r0, r7 ; = data address + size of data/bss |
|
946 |
DWORD r0, "Initial stack base" |
|
947 |
MOV r1, r8 ; size |
|
948 |
MVN r2, #0 ; fill value |
|
949 |
BL WordFill |
|
950 |
||
951 |
; switch to initial thread stack |
|
952 |
||
953 |
DWORD r0, "Initial SP" |
|
954 |
MOV sp, r0 |
|
955 |
||
956 |
; initialise kernel .data and .bss |
|
957 |
||
958 |
PRTLN "Init .data/.bss" |
|
959 |
LDR r0, [r11, #TRomImageHeader_iDataAddress] ; source address |
|
960 |
DWORD r0, "Kernel .data source" |
|
961 |
LDR r1, [r12, #TRomHeader_iKernDataAddress] ; destination address |
|
962 |
DWORD r1, "Kernel .data dest" |
|
963 |
LDR r2, [r11, #TRomImageHeader_iDataSize] ; size of .data |
|
964 |
DWORD r2, "Kernel .data size" |
|
965 |
ADD r2, r2, #3 |
|
966 |
BIC r2, r2, #3 ; round to multiple of 4 |
|
967 |
ADD r4, r1, r2 ; base address of .bss |
|
968 |
DWORD r4, "Kernel .bss dest" |
|
969 |
DWORD r7, "TotalSvDataSize" ; total data/bss size rounded up to 4K |
|
970 |
SUB r5, r7, r2 ; size of .bss |
|
971 |
DWORD r5, "Kernel .bss size" |
|
972 |
BL WordMove ; initialise .data |
|
973 |
MOV r0, r4 |
|
974 |
MOV r1, r5 |
|
975 |
MOV r2, #0 |
|
976 |
BL WordFill ; initialise .bss |
|
977 |
||
978 |
IF :LNOT: CFG_MMDirect |
|
979 |
||
980 |
; allocate SPageInfo array |
|
981 |
||
982 |
PRTLN "Map SPageInfo array start" |
|
983 |
||
984 |
LDR r9, =KPageInfoMap |
|
985 |
MOV r0, r9 ; linear |
|
986 |
MOV r2, #BTP_Kernel ; permissions |
|
987 |
MOV r3, #0x1000 ; size |
|
988 |
MOV r4, #12 ; map size |
|
989 |
MOV r5, r3 |
|
990 |
BL AllocAndMap |
|
991 |
MOV r0, r9 |
|
992 |
MOV r1, r5 |
|
993 |
MOV r2, #0 |
|
994 |
BL WordFill ; zero memory |
|
995 |
||
996 |
LDR r4, [r10, #SSuperPageBase_iRamBootData] |
|
997 |
_page_info_map_make_outer |
|
998 |
LDMIA r4!, {r5,r6} ; r5 = bank physical base, r6 = bank size |
|
999 |
CMP r6, #0 ; reached end of list? |
|
1000 |
BEQ _page_info_map_make_end ; jump if end |
|
1001 |
ADD r6, r6, r5 |
|
1002 |
SUB r6, r6, #1 |
|
1003 |
MOV r5, r5, LSR #24-KPageInfoShift |
|
1004 |
MOV r6, r6, LSR #24-KPageInfoShift |
|
1005 |
CMP r5, r6 |
|
1006 |
BHI _page_info_map_make_outer |
|
1007 |
MOV r7, #1 |
|
1008 |
_page_info_map_make_inner |
|
1009 |
DWORD r5, "SPageInfo Page" |
|
1010 |
AND r1, r5, #7 |
|
1011 |
MOV r1, r7, LSL r1 |
|
1012 |
LDRB r0, [r9, r5, LSR #3] |
|
1013 |
ORR r0, r0, r1 |
|
1014 |
STRB r0, [r9, r5, LSR #3] |
|
1015 |
CMP r5, r6 |
|
1016 |
ADD r5, r5, #1 |
|
1017 |
BNE _page_info_map_make_inner |
|
1018 |
B _page_info_map_make_outer |
|
1019 |
_page_info_map_make_end |
|
1020 |
||
1021 |
MOV r5, #0 |
|
1022 |
_page_info_alloc_find_start |
|
1023 |
AND r1, r5, #7 |
|
1024 |
MOV r1, r7, LSL r1 |
|
1025 |
LDRB r0, [r9, r5, LSR #3] |
|
1026 |
TST r0, r1 |
|
1027 |
BNE _page_info_alloc_start_found |
|
1028 |
ADD r5, r5, #1 |
|
1029 |
MOVS r0, r5, LSL #24-KPageInfoShift |
|
1030 |
BNE _page_info_alloc_find_start |
|
1031 |
B _page_info_alloc_end |
|
1032 |
_page_info_alloc_start_found |
|
1033 |
MOV r6, r5 ; r6 = page offset for start of region |
|
1034 |
_page_info_alloc_find_end |
|
1035 |
AND r1, r5, #7 |
|
1036 |
MOV r1, r7, LSL r1 |
|
1037 |
LDRB r0, [r9, r5, LSR #3] |
|
1038 |
TST r0, r1 |
|
1039 |
BEQ _page_info_alloc_end_found |
|
1040 |
ADD r5, r5, #1 |
|
1041 |
MOVS r0, r5, LSL #24-KPageInfoShift |
|
1042 |
BNE _page_info_alloc_find_end |
|
1043 |
_page_info_alloc_end_found |
|
1044 |
; r6 = start page offset |
|
1045 |
; r5 = end page offset |
|
1046 |
SUB r0, r5, r6 ; r0 = number of pages to map |
|
1047 |
MOV r3, r0, LSL #12 ; r3 = size to map |
|
1048 |
LDR r0, =KPageInfoLinearBase |
|
1049 |
ADD r0, r0, r6, LSL #12 ; r0 = address to map at |
|
1050 |
MOV r2, #BTP_Kernel ; permissions |
|
1051 |
MOV r4, #20 ; map size |
|
1052 |
STMDB sp!, {r0,r3} |
|
1053 |
BL AllocAndMap |
|
1054 |
LDMIA sp!, {r0,r1} |
|
1055 |
MOV r2, #0 |
|
1056 |
BL WordFill ; zero memory |
|
1057 |
||
1058 |
MOVS r0, r5, LSL #24-KPageInfoShift |
|
1059 |
BNE _page_info_alloc_find_start |
|
1060 |
_page_info_alloc_end |
|
1061 |
PRTLN "Map SPageInfo array end" |
|
1062 |
||
1063 |
ENDIF ; CFG_MMDirect |
|
1064 |
||
1065 |
||
1066 |
; allocate memory for IRQ, FIQ, UND & ABT stacks |
|
1067 |
||
1068 |
PRTLN "Allocate IRQ, FIQ, UND & ABT stacks" |
|
1069 |
||
1070 |
IF CFG_MMDirect |
|
1071 |
ADD r5, r10, #SSuperPageBase_iStackInfo ; r5 <= offset SSuperPageBase_iStackInfo |
|
1072 |
ADD r0, r10, #0x3000 ; r0 = stack base |
|
1073 |
IF SMP |
|
1074 |
ADD r0, r0, #0x1000 ; r0 = stack base |
|
1075 |
ENDIF |
|
1076 |
MOV r3, #0x1000 ; stack size |
|
1077 |
DWORD r0, "IRQ stack base" |
|
1078 |
STR r0, [r5, #TStackInfo_iIrqStackBase] ; save stack base in super page |
|
1079 |
DWORD r3, "IRQ stack size" |
|
1080 |
STR r3, [r5, #TStackInfo_iIrqStackSize] ; save stack size in super page |
|
1081 |
ADD r0, r0, r3 |
|
1082 |
MOV r3, #0x400 ; stack size |
|
1083 |
DWORD r0, "FIQ stack base" |
|
1084 |
STR r0, [r5, #TStackInfo_iFiqStackBase] ; save in super page |
|
1085 |
DWORD r3, "FIQ stack size" |
|
1086 |
STR r3, [r5, #TStackInfo_iFiqStackSize] ; save in super page |
|
1087 |
ADD r0, r0, r3 |
|
1088 |
DWORD r0, "UND stack base" |
|
1089 |
STR r0, [r5, #TStackInfo_iUndStackBase] ; save in super page |
|
1090 |
DWORD r3, "UND stack size" |
|
1091 |
STR r3, [r5, #TStackInfo_iUndStackSize] ; save in super page |
|
1092 |
ADD r0, r0, r3 |
|
1093 |
DWORD r0, "ABT stack base" |
|
1094 |
STR r0, [r5, #TStackInfo_iAbtStackBase] ; save in super page |
|
1095 |
DWORD r3, "ABT stack size" |
|
1096 |
STR r3, [r5, #TStackInfo_iAbtStackSize] ; save in super page |
|
1097 |
ADD r0, r0, r3 |
|
1098 |
DWORD r0, "i_Regs" ; address of SFullArmRegSet |
|
1099 |
||
1100 |
ELSE |
|
1101 |
MOV r2, #BTP_Kernel ; permissions |
|
1102 |
MOV r4, #KPageShift ; page size |
|
1103 |
ADD r5, r10, #SSuperPageBase_iStackInfo ; r5 <= offset SSuperPageBase_iStackInfo |
|
1104 |
MVN r1, #0 ; fill value |
|
1105 |
||
1106 |
; IRQ stack |
|
1107 |
||
1108 |
LDR r0, =KExcptStacksLinearBase |
|
1109 |
ADD r0, r0, #KPageSize ; leave space for guard page |
|
1110 |
DWORD r0, "IRQ stack base" |
|
1111 |
STR r0, [r5, #TStackInfo_iIrqStackBase] ; save stack base in super page |
|
1112 |
LDR r3, =KIrqStackSize ; stack size |
|
1113 |
DWORD r3, "IRQ stack size" |
|
1114 |
STR r3, [r5, #TStackInfo_iIrqStackSize] ; save stack size in super page |
|
1115 |
BL AllocAndMap |
|
1116 |
||
1117 |
; FIQ stack |
|
1118 |
||
1119 |
ADD r0, r0, r3 ; ro += stack_size |
|
1120 |
ADD r0, r0, r1, LSR #32-KPageShift |
|
1121 |
BIC r0, r0, r1, LSR #32-KPageShift ; round up to PageSize |
|
1122 |
ADD r0, r0, #KPageSize ; ro += KPageSize |
|
1123 |
DWORD r0, "FIQ stack base" |
|
1124 |
STR r0, [r5, #TStackInfo_iFiqStackBase] ; save in super page |
|
1125 |
LDR r3, =KFiqStackSize ; stack size |
|
1126 |
DWORD r3, "FIQ stack size" |
|
1127 |
STR r3, [r5, #TStackInfo_iFiqStackSize] ; save in super page |
|
1128 |
BL AllocAndMap |
|
1129 |
||
1130 |
; UND stack |
|
1131 |
||
1132 |
ADD r0, r0, r3 ; ro += stack_size |
|
1133 |
ADD r0, r0, r1, LSR #32-KPageShift |
|
1134 |
BIC r0, r0, r1, LSR #32-KPageShift ; round up to PageSize |
|
1135 |
ADD r0, r0, #KPageSize ; ro += KPageSize |
|
1136 |
DWORD r0, "UND stack base" |
|
1137 |
STR r0, [r5, #TStackInfo_iUndStackBase] ; save in super page |
|
1138 |
LDR r3, =KUndStackSize ; stack size |
|
1139 |
DWORD r3, "UND stack size" |
|
1140 |
STR r3, [r5, #TStackInfo_iUndStackSize] ; save in super page |
|
1141 |
BL AllocAndMap |
|
1142 |
||
1143 |
; ABT stack |
|
1144 |
||
1145 |
ADD r0, r0, r3 ; ro += stack_size |
|
1146 |
ADD r0, r0, r1, LSR #32-KPageShift |
|
1147 |
BIC r0, r0, r1, LSR #32-KPageShift ; round up to PageSize |
|
1148 |
ADD r0, r0, #KPageSize ; ro += KPageSize |
|
1149 |
DWORD r0, "ABT stack base" |
|
1150 |
STR r0, [r5, #TStackInfo_iAbtStackBase] ; save in super page |
|
1151 |
LDR r3, =KAbtStackSize ; stack size |
|
1152 |
SUB r3, r3, #0x400 ; reserve 1KB for SFullArmRegSet |
|
1153 |
DWORD r3, "ABT stack size" |
|
1154 |
STR r3, [r5, #TStackInfo_iAbtStackSize] ; save in super page |
|
1155 |
BL AllocAndMap |
|
1156 |
||
1157 |
ENDIF |
|
1158 |
||
1159 |
; fill IRQ, FIQ, UND, ABT stacks and set up banked stack pointers |
|
1160 |
GETCPSR r4 |
|
1161 |
LDR r0, [r5, #TStackInfo_iIrqStackBase] ; |
|
1162 |
LDR r1, [r5, #TStackInfo_iIrqStackSize] ; |
|
1163 |
MOV r2, #0xAA |
|
1164 |
ADD r2, r2, r2, lsl #8 |
|
1165 |
ADD r2, r2, r2, lsl #16 |
|
1166 |
BL WordFill |
|
1167 |
BIC r3, r4, #0x1f |
|
1168 |
ORR r3, r3, #0xd2 ; mode_irq |
|
1169 |
SETCPSR r3 |
|
1170 |
MOV r13, r0 ; set up R13_irq |
|
1171 |
SETCPSR r4 |
|
1172 |
LDR r0, [r5, #TStackInfo_iFiqStackBase] ; |
|
1173 |
LDR r1, [r5, #TStackInfo_iFiqStackSize] ; |
|
1174 |
MOV r2, #0xBB |
|
1175 |
ADD r2, r2, r2, lsl #8 |
|
1176 |
ADD r2, r2, r2, lsl #16 |
|
1177 |
BL WordFill |
|
1178 |
BIC r3, r4, #0x1f |
|
1179 |
ORR r3, r3, #0xd1 ; mode_fiq |
|
1180 |
SETCPSR r3 |
|
1181 |
MOV r13, r0 ; set up R13_fiq |
|
1182 |
SETCPSR r4 |
|
1183 |
LDR r0, [r5, #TStackInfo_iUndStackBase] ; |
|
1184 |
LDR r1, [r5, #TStackInfo_iUndStackSize] ; |
|
1185 |
MOV r2, #0xDD |
|
1186 |
ADD r2, r2, r2, lsl #8 |
|
1187 |
ADD r2, r2, r2, lsl #16 |
|
1188 |
BL WordFill |
|
1189 |
BIC r3, r4, #0x1f |
|
1190 |
ORR r3, r3, #0xdb ; mode_und |
|
1191 |
SETCPSR r3 |
|
1192 |
MOV r13, r0 ; set up R13_und |
|
1193 |
SETCPSR r4 |
|
1194 |
LDR r0, [r5, #TStackInfo_iAbtStackBase] ; |
|
1195 |
LDR r1, [r5, #TStackInfo_iAbtStackSize] ; |
|
1196 |
MOV r2, #0xDD |
|
1197 |
ADD r2, r2, r2, lsl #8 |
|
1198 |
ADD r2, r2, r2, lsl #16 |
|
1199 |
BL WordFill |
|
1200 |
BIC r3, r4, #0x1f |
|
1201 |
ORR r3, r3, #0xd7 ; mode_abt |
|
1202 |
SETCPSR r3 |
|
1203 |
MOV r13, r0 ; set up R13_abt |
|
1204 |
SETCPSR r4 |
|
1205 |
MOV r1, #0x400 |
|
1206 |
MOV r2, #0 |
|
1207 |
BL WordFill ; zero fill SFullArmRegSet space |
|
1208 |
IF CFG_MMDirect |
|
1209 |
LDR r1, [r5, #TStackInfo_iIrqStackBase] ; |
|
1210 |
SETCPSR r3 |
|
1211 |
SUB r14, r0, r1 ; total size of exception mode stacks + SFullArmRegSet |
|
1212 |
SETCPSR r4 |
|
1213 |
ENDIF |
|
1214 |
||
1215 |
IF SMP |
|
1216 |
IF :LNOT: CFG_MMDirect |
|
1217 |
; Allocate and map uncached AP Boot Page |
|
1218 |
MOV r2, #BMA_Kernel ; type |
|
1219 |
MOV r4, #12 ; size = 1 page |
|
1220 |
BOOTCALL BTF_Alloc ; allocate page, physical address into R0 |
|
1221 |
DWORD r0, "APBootPagePhys" |
|
1222 |
STR r0, [r10, #SSuperPageBase_iAPBootPagePhys] |
|
1223 |
MOV r1, r0 ; physical |
|
1224 |
LDR r0, =KAPBootPageLin ; virtual |
|
1225 |
DWORD r0, "APBootPageLin" |
|
1226 |
STR r0, [r10, #SSuperPageBase_iAPBootPageLin] |
|
1227 |
MOV r2, #BTP_Uncached ; permissions |
|
1228 |
MOV r3, #KPageSize ; size |
|
1229 |
MOV r4, #12 |
|
1230 |
BL MapContiguous ; map the page |
|
1231 |
MOV r1, #0x1000 |
|
1232 |
MOV r2, #0 |
|
1233 |
BL WordFill ; clear AP Boot Page |
|
1234 |
ENDIF |
|
1235 |
ENDIF |
|
1236 |
||
1237 |
; do final hardware-dependent initialisation |
|
1238 |
||
1239 |
PRTLN "Final platform dependent initialisation" |
|
1240 |
BOOTCALL BTF_Final |
|
1241 |
||
1242 |
; for bootloader work out address where image should go |
|
1243 |
IF CFG_BootLoader |
|
1244 |
GETMPARAM BPR_BootLdrImgAddr ; R0 = image physical address |
|
1245 |
BL RamPhysicalToLinear |
|
1246 |
MOV r9, r0 ; save linear in R9 |
|
1247 |
DWORD r9, "ImgAddrLin" |
|
1248 |
ENDIF |
|
1249 |
||
1250 |
; final diagnostics |
|
1251 |
IF CFG_DebugBootRom |
|
1252 |
||
1253 |
PRTLN "Super page and CPU page:" |
|
1254 |
MOV r1, #SuperCpuSize |
|
1255 |
MEMDUMP r10, r1 ; dump super page + CPU page |
|
1256 |
||
1257 |
IF CFG_MMUPresent |
|
1258 |
PRTLN "Page directory:" |
|
1259 |
IF CFG_MMDirect |
|
1260 |
GETPARAM BPR_PageTableSpace, DefaultPTAlloc ; get reserved space for page tables |
|
1261 |
LDR r2, [r10, #SSuperPageBase_iPageDir] ; |
|
1262 |
MOV r1, r0 ; size |
|
1263 |
ADD r2, r2, #0x4000 ; end of page dir |
|
1264 |
IF SMP |
|
1265 |
ADD r2, r2, #0x4000 ; end of APBoot page dir |
|
1266 |
ENDIF |
|
1267 |
SUB r0, r2, r0 ; size includes page directory and tables |
|
1268 |
ELSE |
|
1269 |
LDR r0, [r10, #SSuperPageBase_iPageDir] ; page directory address |
|
1270 |
MOV r1, #0x4000 ; page directory size |
|
1271 |
ENDIF |
|
1272 |
MEMDUMP r0, r1 ; dump page directory |
|
1273 |
||
1274 |
IF :LNOT: CFG_MMDirect |
|
1275 |
LDR r0, =KPageTableBase ; page table linear base |
|
1276 |
SUB r2, r0, #4 |
|
1277 |
_CountPt |
|
1278 |
LDR r1, [r2, #4]! ; get next PT0 entry |
|
1279 |
CMP r1, #0 ; empty? |
|
1280 |
BNE _CountPt ; if not, next |
|
1281 |
SUB r1, r2, r0 ; 4*number of page tables |
|
1282 |
MOV r1, r1, LSL #10 ; 1K per page table |
|
1283 |
PRTLN "Page tables:" |
|
1284 |
MEMDUMP r0, r1 ; dump page tables |
|
1285 |
IF SMP |
|
1286 |
LDR r0, [r10, #SSuperPageBase_iAPBootPageDirPhys] |
|
1287 |
DWORD r0, "APBootPageDirPhys" |
|
1288 |
PRTLN "APBoot PageDir/Tables:" |
|
1289 |
LDR r0, =KAPBootPageDirLin ; r0 = page directory linear |
|
1290 |
MOV r1, #0x5000 ; 16K page directory + page tables |
|
1291 |
MEMDUMP r0, r1 ; dump page tables |
|
1292 |
PRTLN "APBootPage" |
|
1293 |
LDR r0, [r10, #SSuperPageBase_iAPBootPageLin] |
|
1294 |
MOV r1, #0x1000 |
|
1295 |
MEMDUMP r0, r1 ; dump AP Boot Page |
|
1296 |
ENDIF |
|
1297 |
ENDIF |
|
1298 |
||
1299 |
ENDIF ; CFG_MMUPresent |
|
1300 |
ENDIF ; CFG_DebugBootRom |
|
1301 |
||
1302 |
||
1303 |
IF :DEF: CFG_HasL210Cache |
|
1304 |
;Enable L2 cache. Enabling L220 & PL310 is baseport specific due to security extension (TrustZone). |
|
1305 |
LDR r0, [r10, #SSuperPageBase_iArmL2CacheBase] |
|
1306 |
MOV r1, #1 |
|
1307 |
STR r1, [r0, #0x100] |
|
1308 |
PRTLN "L2CACHE: Enabled" |
|
1309 |
ENDIF |
|
1310 |
||
1311 |
; boot the kernel |
|
1312 |
||
1313 |
LDR r14, [r11, #TRomImageHeader_iEntryPoint] ; kernel entry point |
|
1314 |
DWORD r14, "Jumping to OS at location" |
|
1315 |
MOV r0, r12 ; pass address of ROM header |
|
1316 |
MOV r1, r10 ; pass address of super page |
|
1317 |
DWORD r0, "R0" |
|
1318 |
DWORD r1, "R1" |
|
1319 |
IF CFG_BootLoader |
|
1320 |
STR r9, [r10, #SSuperPageBase_iCodeBase] ; for bootloader pass image address |
|
1321 |
ENDIF |
|
1322 |
IF CFG_DebugBootRom |
|
1323 |
; pause to let tracing finish |
|
1324 |
MOV r12, #0x00100000 |
|
1325 |
SUBS r12, r12, #1 |
|
1326 |
SUBNE pc, pc, #12 |
|
1327 |
ENDIF |
|
1328 |
MOV pc, r14 ; jump to kernel entry point |
|
1329 |
||
1330 |
||
1331 |
||
1332 |
||
1333 |
END |