Index: sys/arm64/arm64/locore.S =================================================================== --- sys/arm64/arm64/locore.S +++ sys/arm64/arm64/locore.S @@ -361,18 +361,40 @@ mov x5, x30 /* Clean the page table */ - adrp x6, pagetable - add x6, x6, :lo12:pagetable - mov x26, x6 + adrp x26, pagetable + add x26, x26, :lo12:pagetable adrp x27, pagetable_end add x27, x27, :lo12:pagetable_end + + mrs x7, ctr_el0 + /* Extract the DminLine field */ + ubfm x7, x7, #16, #19 + /* DminLine is log2(dcacheline size) in 4-byte words */ + mov x8, #4 + lsl x7, x8, x7 + + /* + * Invalidate cachelines holding the page tables. We are about to + * write to them with the cache disabled. Any data in the cache + * needs to be invalidated so it doesn't later overwrite them. + */ + mov x6, x26 1: + dc civac, x6 + add x6, x6, x7 + cmp x6, x27 + b.lo 1b + dsb sy + + /* Zero the page tables */ + mov x6, x26 +2: stp xzr, xzr, [x6], #16 stp xzr, xzr, [x6], #16 stp xzr, xzr, [x6], #16 stp xzr, xzr, [x6], #16 cmp x6, x27 - b.lo 1b + b.lo 2b /* * Build the TTBR1 maps.