ARM600 21 KB
Newer Older
Neil Turton's avatar
Neil Turton committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
; Copyright 1996 Acorn Computers Ltd
;
; Licensed under the Apache License, Version 2.0 (the "License");
; you may not use this file except in compliance with the License.
; You may obtain a copy of the License at
;
;     http://www.apache.org/licenses/LICENSE-2.0
;
; Unless required by applicable law or agreed to in writing, software
; distributed under the License is distributed on an "AS IS" BASIS,
; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
; See the License for the specific language governing permissions and
; limitations under the License.
;
; > ARM600

Jeffrey Lee's avatar
Jeffrey Lee committed
17 18 19
        ; Convert given page flags to the equivalent temp uncacheable L2PT flags
        ; n.b. temp not used here but included for VMSAv6 compatibility
        MACRO
20
        GetTempUncache_ShortDesc $out, $pageflags, $pcbtrans, $temp
Jeffrey Lee's avatar
Jeffrey Lee committed
21 22
        ASSERT  $out <> $pageflags ; For consistency with VMSAv6 version
        ASSERT  $out <> $pcbtrans
Jeffrey Lee's avatar
Jeffrey Lee committed
23
      [ "$temp" <> ""
Jeffrey Lee's avatar
Jeffrey Lee committed
24 25
        ASSERT  $out <> $temp      ; For consistency with VMSAv6 version
        ASSERT  $temp <> $pcbtrans ; For consistency with VMSAv6 version
Jeffrey Lee's avatar
Jeffrey Lee committed
26
      ]
Jeffrey Lee's avatar
Jeffrey Lee committed
27 28 29 30 31 32 33 34 35
        ASSERT  DynAreaFlags_CPBits = 7*XCB_P :SHL: 10
        ASSERT  DynAreaFlags_NotCacheable = XCB_NC :SHL: 4
        ASSERT  DynAreaFlags_NotBufferable = XCB_NB :SHL: 4
        AND     $out, $pageflags, #DynAreaFlags_NotCacheable + DynAreaFlags_NotBufferable
        ORR     $out, $out, #DynAreaFlags_NotCacheable      ; treat as temp uncache
        LDRB    $out, [$pcbtrans, $out, LSR #4]             ; convert to X, C and B bits for this CPU
        MEND

TempUncache_L2PTMask * L2_X+L2_C+L2_B
Neil Turton's avatar
Neil Turton committed
36 37 38

; MMU interface file - ARM600 version

39 40
        KEEP

Neil Turton's avatar
Neil Turton committed
41 42 43 44
; **************** CAM manipulation utility routines ***********************************

; **************************************************************************************
;
45
;       BangCamUpdate - Update CAM, MMU for page move, coping with page currently mapped in
Neil Turton's avatar
Neil Turton committed
46
;
47 48
; mjs Oct 2000
; reworked to use generic ARM ops (vectored to appropriate routines during boot)
Neil Turton's avatar
Neil Turton committed
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
;
; First look in the CamEntries table to find the logical address L this physical page is
; currently allocated to. Then check in the Level 2 page tables to see if page L is currently
; at page R2. If it is, then map page L to be inaccessible, otherwise leave page L alone.
; Then map logical page R3 to physical page R2.
;
; in:   r2 = physical page number
;       r3 = logical address (2nd copy if doubly mapped area)
;       r9 = offset from 1st to 2nd copy of doubly mapped area (either source or dest, but not both)
;       r11 = PPL + CB bits
;
; out:  r0, r1, r4, r6 corrupted
;       r2, r3, r5, r7-r12 preserved
;

64
BangCamUpdate_ShortDesc ROUT
Neil Turton's avatar
Neil Turton committed
65 66 67
        TST     r11, #DynAreaFlags_DoublyMapped ; if moving page to doubly mapped area
        SUBNE   r3, r3, r9                      ; then CAM soft copy holds ptr to 1st copy

Jeffrey Lee's avatar
Jeffrey Lee committed
68
        LDR     r1, =ZeroPage
Neil Turton's avatar
Neil Turton committed
69
        LDR     r1, [r1, #CamEntriesPointer]
70 71 72
        ADD     r1, r1, r2, LSL #CAM_EntrySizeLog2 ; point at cam entry (logaddr, PPL)
        ASSERT  CAM_LogAddr=0
        ASSERT  CAM_PageFlags=4
Neil Turton's avatar
Neil Turton committed
73
        LDMIA   r1, {r0, r6}                    ; r0 = current logaddress, r6 = current PPL
74
        Push    "r0, r6"                        ; save old logical address, PPL
75
        BIC     r4, r11, #PageFlags_Unsafe
76 77 78
        BIC     r4, r4, #StickyPageFlags
        AND     r6, r6, #StickyPageFlags
        ORR     r4, r4, r6
79
        STMIA   r1, {r3, r4}                    ; store new address, PPL
80

Jeffrey Lee's avatar
Jeffrey Lee committed
81
        LDR     r1, =ZeroPage+PhysRamTable      ; go through phys RAM table
Neil Turton's avatar
Neil Turton committed
82 83 84 85 86 87 88
        MOV     r6, r2                          ; make copy of r2 (since that must be preserved)
10
        LDMIA   r1!, {r0, r4}                   ; load next address, size
        SUBS    r6, r6, r4, LSR #12             ; subtract off that many pages
        BCS     %BT10                           ; if more than that, go onto next bank

        ADD     r6, r6, r4, LSR #12             ; put back the ones which were too many
89
        ADD     r0, r0, r6                      ; move on address by the number of pages left
Robert Sprowson's avatar
Robert Sprowson committed
90
        LDR     r6, [sp]                        ; reload old logical address
91
        MOV     r0, r0, LSL #12                 ; convert from page units to bytes
Neil Turton's avatar
Neil Turton committed
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109

; now we have r6 = old logical address, r2 = physical page number, r0 = physical address

        TEQ     r6, r3                          ; TMD 19-Jan-94: if old logaddr = new logaddr, then
        BEQ     %FT20                           ; don't remove page from where it is, to avoid window
                                                ; where page is nowhere.
        LDR     r1, =L2PT
        ADD     r6, r1, r6, LSR #10             ; r6 -> L2PT entry for old log.addr
        MOV     r4, r6, LSR #12                 ; r4 = word offset into L2 for address r6
        LDR     r4, [r1, r4, LSL #2]            ; r4 = L2PT entry for L2PT entry for old log.addr
        TST     r4, #3                          ; if page not there
        BEQ     %FT20                           ; then no point in trying to remove it

        LDR     r4, [r6]                        ; r4 = L2PT entry for old log.addr
        MOV     r4, r4, LSR #12                 ; r4 = physical address for old log.addr
        TEQ     r4, r0, LSR #12                 ; if equal to physical address of page being moved
        BNE     %FT20                           ; if not there, then just put in new page

110
        AND     r4, r11, #PageFlags_Unsafe
Neil Turton's avatar
Neil Turton committed
111 112 113
        Push    "r0, r3, r11, r14"              ; save phys.addr, new log.addr, new PPL, lr
        ADD     r3, sp, #4*4
        LDMIA   r3, {r3, r11}                   ; reload old logical address, old PPL
114 115 116
        LDR     r0, =DuffEntry                  ; Nothing to do if wasn't mapped in
        ORR     r11, r11, r4
        TEQ     r3, r0
Neil Turton's avatar
Neil Turton committed
117
        MOV     r0, #0                          ; cause translation fault
118
        BLNE    BangL2PT                        ; map page out
Neil Turton's avatar
Neil Turton committed
119 120 121
        Pull    "r0, r3, r11, r14"
20
        ADD     sp, sp, #8                      ; junk old logical address, PPL
122 123 124
        LDR     r4, =DuffEntry          ; check for requests to map a page to nowhere
        TEQ     r4, r3                  ; don't actually map anything to nowhere
        MOVEQ   pc, lr
125
        GetPTE  r0, 4K, r0, r11, ShortDesc
Neil Turton's avatar
Neil Turton committed
126 127 128

        LDR     r1, =L2PT               ; point to level 2 page tables

129 130
        ;fall through to BangL2PT

Neil Turton's avatar
Neil Turton committed
131 132 133 134 135 136 137
;internal entry point for updating L2PT entry
;
; entry: r0 = new L2PT value, r1 -> L2PT, r3 = logical address (4k aligned), r11 = PPL
;
; exit: r0,r1,r4,r6 corrupted
;
BangL2PT                                        ; internal entry point used only by BangCamUpdate
138 139 140
        Push    "lr"
        MOV     r6, r0

141
        TST     r11, #PageFlags_Unsafe
142
        BNE     BangL2PT_unsafe
Neil Turton's avatar
Neil Turton committed
143

Jeffrey Lee's avatar
Jeffrey Lee committed
144 145 146 147 148 149 150 151
        ;In order to safely map out a cacheable page and remove it from the
        ;cache, we need to perform the following process:
        ;* Make the page uncacheable
        ;* Flush TLB
        ;* Clean+invalidate cache
        ;* Write new mapping (r6)
        ;* Flush TLB
        ;For uncacheable pages we can just do the last two steps
152 153
        ;
        TEQ     r6, #0                          ;EQ if mapping out
Kevin Bracey's avatar
Kevin Bracey committed
154
        TSTEQ   r11, #DynAreaFlags_NotCacheable ;EQ if also cacheable (overcautious for temp uncache+illegal PCB combos)
Jeffrey Lee's avatar
Jeffrey Lee committed
155
        LDR     r4, =ZeroPage
Jeffrey Lee's avatar
Jeffrey Lee committed
156 157
        BNE     %FT20
        LDR     lr, [r4, #MMU_PCBTrans]
158
        GetTempUncache_ShortDesc r0, r11, lr
Jeffrey Lee's avatar
Jeffrey Lee committed
159 160 161
        LDR     lr, [r1, r3, LSR #10]           ;get current L2PT entry
        BIC     lr, lr, #TempUncache_L2PTMask   ;remove current attributes
        ORR     lr, lr, r0
162 163 164 165 166
        STR     lr, [r1, r3, LSR #10]!          ;Make uncacheable
        TST     r11, #DynAreaFlags_DoublyMapped
        BEQ     %FT19
        STR     lr, [r1, r9, LSR #10]           ;Update 2nd mapping too if required
        ADD     r0, r3, r9
167
        ARMop   MMU_ChangingEntry,,, r4
168
19
Jeffrey Lee's avatar
Jeffrey Lee committed
169
        MOV     r0, r3
170
        ARMop   MMU_ChangingEntry,,, r4
Jeffrey Lee's avatar
Jeffrey Lee committed
171
        LDR     r1, =L2PT
Neil Turton's avatar
Neil Turton committed
172

173 174 175 176 177 178 179 180
20      STR     r6, [r1, r3, LSR #10]!          ;update L2PT entry
        TST     r11, #DynAreaFlags_DoublyMapped
        BEQ     %FT21
        STR     r6, [r1, r9, LSR #10]           ;Update 2nd mapping
        MOV     r0, r3
        ARMop   MMU_ChangingUncachedEntry,,, r4 ; TLB flush for 1st mapping
        ADD     r3, r3, r9                      ;restore r3 back to 2nd copy
21
Jeffrey Lee's avatar
Jeffrey Lee committed
181 182 183
        Pull    "lr"
        MOV     r0, r3
        ARMop   MMU_ChangingUncachedEntry,,tailcall,r4
Neil Turton's avatar
Neil Turton committed
184

185 186
BangL2PT_unsafe
        STR     r6, [r1, r3, LSR #10]!          ; update level 2 page table (and update pointer so we can use bank-to-bank offset
Neil Turton's avatar
Neil Turton committed
187
        TST     r11, #DynAreaFlags_DoublyMapped ; if area doubly mapped
188 189 190
        STRNE   r6, [r1, r9, LSR #10]           ; then store entry for 2nd copy as well
        ADDNE   r3, r3, r9                      ; and point logical address back at 2nd copy
        Pull    "pc"
Neil Turton's avatar
Neil Turton committed
191

192 193 194 195 196 197
 [ ARM6support
PPLTransARM6
        &       (AP_Full * L2_APMult) + L2_SmallPage      ; R any W any
        &       (AP_Read * L2_APMult) + L2_SmallPage      ; R any W sup
        &       (AP_None * L2_APMult) + L2_SmallPage      ; R sup W sup
        &       (AP_Read * L2_APMult) + L2_SmallPage      ; R any W sup
Neil Turton's avatar
Neil Turton committed
198

199 200 201 202 203 204 205 206
PPLAccessARM6        ; EL1EL0
                     ; RWXRWX
        GenPPLAccess 2_111111
        GenPPLAccess 2_111101
        GenPPLAccess 2_111000
        GenPPLAccess 2_111101
        DCD     -1
 ]
207

208
PPLTrans_ShortDesc
Neil Turton's avatar
Neil Turton committed
209 210 211
        &       (AP_Full * L2_APMult) + L2_SmallPage      ; R any W any
        &       (AP_Read * L2_APMult) + L2_SmallPage      ; R any W sup
        &       (AP_None * L2_APMult) + L2_SmallPage      ; R sup W sup
212
        &       (AP_ROM  * L2_APMult) + L2_SmallPage      ; R any W none
Neil Turton's avatar
Neil Turton committed
213

214
PPLTransX_ShortDesc
Kevin Bracey's avatar
Kevin Bracey committed
215 216 217 218 219
        &       (AP_Full * L2X_APMult) + L2_ExtPage       ; R any W any
        &       (AP_Read * L2X_APMult) + L2_ExtPage       ; R any W sup
        &       (AP_None * L2X_APMult) + L2_ExtPage       ; R sup W sup
        &       (AP_ROM  * L2X_APMult) + L2_ExtPage       ; R any W none

220
PPLAccess_ShortDesc  ; EL1EL0
221 222 223 224 225 226
                     ; RWXRWX
        GenPPLAccess 2_111111
        GenPPLAccess 2_111101
        GenPPLAccess 2_111000
        GenPPLAccess 2_101101
        DCD     -1
Neil Turton's avatar
Neil Turton committed
227

Jeffrey Lee's avatar
Jeffrey Lee committed
228
        =       0                       ; So PageShifts-1 is word aligned
Neil Turton's avatar
Neil Turton committed
229 230 231
PageShifts
        =       12, 13, 0, 14           ; 1 2 3 4
        =       0,  0,  0, 15           ; 5 6 7 8
Jeffrey Lee's avatar
Jeffrey Lee committed
232
        ALIGN
Neil Turton's avatar
Neil Turton committed
233

Jeffrey Lee's avatar
Jeffrey Lee committed
234
        LTORG
Neil Turton's avatar
Neil Turton committed
235 236 237

; +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
;
Jeffrey Lee's avatar
Jeffrey Lee committed
238
; "ARM600"-specific OS_MMUControl code
Neil Turton's avatar
Neil Turton committed
239
;
Jeffrey Lee's avatar
Jeffrey Lee committed
240

Neil Turton's avatar
Neil Turton committed
241
; in:   r0 = 0 (reason code 0, for modify control register)
Neil Turton's avatar
Neil Turton committed
242 243 244 245 246 247 248
;       r1 = EOR mask
;       r2 = AND mask
;
;       new control = ((old control AND r2) EOR r1)
;
; out:  r1 = old value
;       r2 = new value
Neil Turton's avatar
Neil Turton committed
249
MMUControl_ModifyControl ROUT
250
        Push    "r0,r3,r4,r5"
Neil Turton's avatar
Neil Turton committed
251 252 253
        CMP     r1,#0
        CMPEQ   r2,#&FFFFFFFF
        BEQ     MMUC_modcon_readonly
Jeffrey Lee's avatar
Jeffrey Lee committed
254
        LDR     r3,=ZeroPage
255 256 257 258
        LDRB    r5,[r3, #ProcessorArch]
        PHPSEI  r4                      ; disable IRQs while we modify soft copy (and possibly switch caches off/on)

        CMP     r5,#ARMv4
259
        LDRLO   lr, [r3, #MMUControlSoftCopy]
260
        ARM_read_control lr,HS          ; if ARMv4 or later, we can read control reg. - trust this more than soft copy
Neil Turton's avatar
Neil Turton committed
261 262 263 264 265
        AND     r2, r2, lr
        EOR     r2, r2, r1
        MOV     r1, lr
        STR     r2, [r3, #MMUControlSoftCopy]
        BIC     lr, r2, r1              ; lr = bits going from 0->1
Neil Turton's avatar
Neil Turton committed
266
        TST     lr, #MMUC_C             ; if cache turning on then flush cache before we do it
267 268 269 270 271 272 273 274
        BEQ     %FT05

        ARMop   Cache_InvalidateAll,,,r3 ; D-cache turning on, I-cache invalidate is either necessary (both turning on) or a safe side-effect
        B       %FT10

05
        TST     lr, #MMUC_I
        ARMop   IMB_Full,NE,,r3         ; I-cache turning on, Cache_InvalidateAll could be unsafe
275

Neil Turton's avatar
Neil Turton committed
276
10
277
        BIC     lr, r1, r2              ; lr = bits going from 1->0
278 279
        TST     lr, #MMUC_C             ; if cache turning off then clean data cache first
        BEQ     %FT15
Jeffrey Lee's avatar
Jeffrey Lee committed
280
        ARMop   Cache_CleanAll,,,r3
Neil Turton's avatar
Neil Turton committed
281 282 283 284
15
        ARM_write_control r2
        BIC     lr, r1, r2              ; lr = bits going from 1->0
        TST     lr, #MMUC_C             ; if cache turning off then flush cache afterwards
285 286 287 288 289 290
        BEQ     %FT17
        LDR     r3,=ZeroPage
        ARMop   Cache_InvalidateAll,,,r3 ; D-cache turned off, can safely invalidate I+D
        B       %FT20
17
        TST     lr, #MMUC_I
Neil Turton's avatar
Neil Turton committed
291
        BEQ     %FT20
292 293
        LDR     r3,=ZeroPage
        ARMop   IMB_Full,,,r3           ; Only I-cache which turned off, clean D-cache & invalidate I-cache
Neil Turton's avatar
Neil Turton committed
294
20
Kevin Bracey's avatar
Kevin Bracey committed
295
        PLP     r4                      ; restore IRQ state
296
        Pull    "r0,r3,r4,r5,pc"
Neil Turton's avatar
Neil Turton committed
297 298

MMUC_modcon_readonly
Jeffrey Lee's avatar
Jeffrey Lee committed
299
        LDR     r3, =ZeroPage
300 301
        LDRB    r5, [r3, #ProcessorArch]
        CMP     r5, #ARMv4
302
        LDRLO   lr, [r3, #MMUControlSoftCopy]
303
        ARM_read_control lr,HS          ; if ARMv4 or later, we can read control reg. - trust this more than soft copy
304
        STRHS   lr, [r3, #MMUControlSoftCopy]
Neil Turton's avatar
Neil Turton committed
305 306
        MOV     r1, lr
        MOV     r2, lr
307
        Pull    "r0,r3,r4,r5,pc"
Neil Turton's avatar
Neil Turton committed
308

309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327
; If extended pages are supported:
; PPLTrans should contain L2X_AP + L2_ExtPage
; PCBTrans should contain L2_C+L2_B+L2_TEX (for an extended page)
; If extended pages aren't supported:
; PPLTrans should contain L2_AP + L2_SmallPage
; PCBTrans should contain L2_C+L2_B

; In:
; r0 = phys addr (aligned)
; r1 = page flags:
;      DynAreaFlags_APBits
;      DynAreaFlags_NotBufferable
;      DynAreaFlags_NotCacheable
;      DynAreaFlags_CPBits
;      PageFlags_TempUncacheableBits
; r2 -> PPLTrans
; r3 -> PCBTrans
; Out:
; r0 = PTE for 4K page ("small page" or "extended page" depending on PPLTrans)
328
Get4KPTE_ShortDesc ROUT
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350
        Entry   "r4"
        AND     lr, r1, #DynAreaFlags_APBits
        LDR     lr, [r2, lr, LSL #2]
        ; Insert AP bits, page type/size
        ORR     r0, r0, lr
        ; Insert CB+TEX bits
        ASSERT  DynAreaFlags_CPBits = 7*XCB_P :SHL: 10
        ASSERT  DynAreaFlags_NotCacheable = XCB_NC :SHL: 4
        ASSERT  DynAreaFlags_NotBufferable = XCB_NB :SHL: 4
        TST     r1, #PageFlags_TempUncacheableBits
        AND     r4, r1, #DynAreaFlags_NotCacheable + DynAreaFlags_NotBufferable
        AND     lr, r1, #DynAreaFlags_CPBits
        ORRNE   r4, r4, #DynAreaFlags_NotCacheable      ; if temp uncache, set NC bit, ignore P
        ORREQ   r4, r4, lr, LSR #10-4                   ; else use NC, NB and P bits
        LDRB    r4, [r3, r4, LSR #4]                    ; convert to X, C and B bits for this CPU
        ORR     r0, r0, r4
        EXIT

; In:
; As per Get4KPTE
; Out:
; r0 = PTE for 64K page ("large page")
351
Get64KPTE_ShortDesc ROUT
352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382
        Entry   "r4"
        AND     lr, r1, #DynAreaFlags_APBits
        LDR     lr, [r2, lr, LSL #2]
        ; Force to large page
        ORR     r0, r0, #L2_LargePage
        ; Insert AP bits
        AND     lr, lr, #L2X_AP ; If extended pages are supported, we need to expand L2X_AP to L2_AP
        MOV     r4, #L2_APMult/L2X_APMult
        MLA     r0, r4, lr, r0
50
        ; Insert CB+TEX bits
        ; Shared with Get1MPTE
        ASSERT  DynAreaFlags_CPBits = 7*XCB_P :SHL: 10
        ASSERT  DynAreaFlags_NotCacheable = XCB_NC :SHL: 4
        ASSERT  DynAreaFlags_NotBufferable = XCB_NB :SHL: 4
        TST     r1, #PageFlags_TempUncacheableBits
        AND     r4, r1, #DynAreaFlags_NotCacheable + DynAreaFlags_NotBufferable
        AND     lr, r1, #DynAreaFlags_CPBits
        ORRNE   r4, r4, #DynAreaFlags_NotCacheable      ; if temp uncache, set NC bit, ignore P
        ORREQ   r4, r4, lr, LSR #10-4                   ; else use NC, NB and P bits
        LDRB    r4, [r3, r4, LSR #4]                    ; convert to X, C and B bits for this CPU
        ; Move TEX field up
        ORR     r4, r4, r4, LSL #L2L_TEXShift-L2_TEXShift
        BIC     r4, r4, #L2_TEX :OR: ((L2_C+L2_B) :SHL: (L2L_TEXShift-L2_TEXShift))
        ORR     r0, r0, r4
        EXIT

; In:
; As per Get4KPTE
; Out:
; r0 = PTE for 1M page ("section")
383
Get1MPTE_ShortDesc
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409
        ALTENTRY
        AND     lr, r1, #DynAreaFlags_APBits
      [ ARM6support
        ; Set U bit if cacheable and not ROM access
        ; (Because ROM access isn't supported, it'll get mapped to AP_Read.
        ;  Writes to ROM will presumably be ignored by the bus, but if we have
        ;  U set it will update the cache, effectively giving people the power
        ;  to temporarily overwrite ROM)
        CMP     lr, #2
        TSTLS   r1, #DynAreaFlags_NotCacheable
        ORREQ   r0, r0, #L1_U
      ]
        LDR     lr, [r2, lr, LSL #2]
        ; Force to section map
        ORR     r0, r0, #L1_Section
        ; Insert AP bits
        ASSERT  L1_AP = L2X_AP :SHL: 6
        AND     lr, lr, #L2X_AP
        ORR     r0, r0, lr, LSL #6
        ; Insert CB+TEX bits
        ASSERT  L1_C = L2_C
        ASSERT  L1_B = L2_B
        ASSERT  L1_TEXShift = L2L_TEXShift
        B       %BT50

; In:
410
; r0 = page-aligned logical addr
411
; Out:
412 413
; r0,r1 = phys addr
; r2 = page flags
414
;      or -1 if fault
415
; r3 = entry size/alignment (bytes)
416
LoadAndDecodeL2Entry_ShortDesc   ROUT
417 418
        LDR     r1, =L2PT
        LDR     r0, [r1, r0, LSR #10]
419 420
        ANDS    r3, r0, #3
        MOVEQ   r2, #-1
421
        MOVEQ   r3, #4096
422
        MOVEQ   pc, lr
423
        Entry   "r4-r6"
424 425
        ; Get AP bits in low bits
        ASSERT  L2X_APMult = 1:SHL:4
426
        MOV     r2, r0, LSR #4
427 428 429
        ; Remap TEX+CB so that they're in the same position as an extended page entry
        ASSERT  L2_LargePage < L2_SmallPage
        ASSERT  L2_SmallPage < L2_ExtPage
430
        CMP     r3, #L2_SmallPage
431 432 433 434 435
        AND     r4, r0, #L2_C+L2_B
        ANDLT   lr, r0, #L2L_TEX
        ORRLT   r4, r4, lr, LSR #L2L_TEXShift-L2_TEXShift
        ANDGT   lr, r0, #L2_TEX
        ORRGT   r4, r4, lr
436
        ; Align phys addr to page size and set up r3
437 438 439
        MOV     r0, r0, LSR #12
        BICLT   r0, r0, #15
        MOV     r0, r0, LSL #12
440 441 442
        MOV     r1, #0
        MOVLT   r3, #65536
        MOVGE   r3, #4096
443
20
444
        ; Common code shared with LoadAndDecodeL1Entry
445 446 447 448
        ; Only four PPL possibilities, so just directly decode it
        ; ARM access goes 0 => all R/O, 1 => user none, 2 => user R/O, 3  => user R/W
        ; PPL access goes 0 => user R/W, 1 => user R/O, 2 => user none, 3 => all R/0
        ; i.e. just invert the bits
449 450 451
        AND     r2, r2, #3
        LDR     r6, =ZeroPage
        EOR     r2, r2, #3
452 453
        ; Search through PCBTrans for a match on TEX+CB
        ; Funny order is used so that NCNB is preferred over other variants (since NCNB is common fallback)
454
        LDR     r6, [r6, #MMU_PCBTrans]
455 456
        MOV     lr, #3
30
457
        LDRB    r5, [r6, lr]
458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
        CMP     r5, r4
        BEQ     %FT40
        TST     lr, #2_11
        SUBNE   lr, lr, #1                      ; loop goes 3,2,1,0,7,6,5,4,...,31,30,29,28
        ADDEQ   lr, lr, #7
        TEQ     lr, #35
        BNE     %BT30                           ; Give up if end of table reached
40
        ; Decode index back into page flags
        ; n.b. temp uncache is ignored (no way we can differentiate between real uncached)
        ASSERT  DynAreaFlags_CPBits = 7*XCB_P :SHL: 10
        ASSERT  DynAreaFlags_NotCacheable = XCB_NC :SHL: 4
        ASSERT  DynAreaFlags_NotBufferable = XCB_NB :SHL: 4
        AND     r4, lr, #XCB_NC+XCB_NB
        AND     lr, lr, #7*XCB_P
473 474
        ORR     r2, r2, r4, LSL #4
        ORR     r2, r2, lr, LSL #10
475 476 477
        EXIT

; In:
478
; r0 = MB-aligned logical addr
479
; Out:
480
; r0,r1 = phys addr of start of section or L2PT entry
481
; r2 = page flags if 1MB page
482 483
;      or -1 if fault
;      or -2 if page table ptr
484
; r3 = entry size/alignment (bytes)
485
LoadAndDecodeL1Entry_ShortDesc
486
        ALTENTRY
487 488
        LDR     r1, =L1PT
        LDR     r0, [r1, r0, LSR #20-2]
489
        MOV     r3, #1048576
490
        AND     r2, r0, #3
491 492
        ASSERT  L1_Fault < L1_Page
        ASSERT  L1_Page < L1_Section
493
        CMP     r2, #L1_Page
494
        BGT     %FT50
495 496
        MOVLT   r2, #-1
        MOVEQ   r2, #-2
497 498
        MOVEQ   r0, r0, LSR #10
        MOVEQ   r0, r0, LSL #10
499
        MOVEQ   r1, #0
500 501 502 503
        EXIT
50
        ; Get AP bits in low bits
        ASSERT  L1_APMult = 1:SHL:10
504
        MOV     r2, r0, LSR #10
505 506 507 508 509 510
        ; Remap TEX+CB so that they're in the same position as an extended page entry
        ASSERT  L1_C = L2_C
        ASSERT  L1_B = L2_B
        AND     r4, r0, #L1_C+L1_B
        AND     lr, r0, #L1_TEX
        ORR     r4, r4, lr, LSR #L1_TEXShift-L2_TEXShift
511
        ; Align phys addr to page size and set up r3
512 513
        MOV     r0, r0, LSR #20
        MOV     r0, r0, LSL #20
514
        MOV     r1, #0
515 516 517
        ; Jump to common code to do AP decode + PCBTrans search
        B       %BT20

518 519 520 521 522 523 524
; In:
; r0 = phys addr (aligned)
; r1 -> ZeroPage
; Out:
; TTBR and any other related registers updated
; If MMU is currently on, it's assumed the mapping of ROM+stack will not be
; affected by this change
525
SetTTBR_ShortDesc ROUT
526 527 528 529 530 531 532 533 534 535 536 537
        ARM_MMU_transbase r0
        MOV     pc, lr

 [ CacheablePageTables
; Out: R0 = desired page flags for the page tables
GetPageFlagsForCacheablePageTables ROUT
        ; For ARMv5 and below the MMU can't read from the L1 cache, so the
        ; best we can do is a write-through cache policy
        LDR     r0, =AreaFlags_PageTablesAccess :OR: (CP_CB_Writethrough :SHL: DynAreaFlags_CPShift)
        MOV     pc, lr
 ]

Jeffrey Lee's avatar
Jeffrey Lee committed
538 539
        GET     s.ShortDesc

Neil Turton's avatar
Neil Turton committed
540
        END