2013-04-07 00:41:07 +00:00
|
|
|
/*
|
|
|
|
* GRUB -- GRand Unified Bootloader
|
|
|
|
* Copyright (C) 2013 Free Software Foundation, Inc.
|
|
|
|
*
|
|
|
|
* GRUB is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* GRUB is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with GRUB. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <grub/symbol.h>
|
|
|
|
|
|
|
|
.file "cache.S"
|
|
|
|
.text
|
|
|
|
.syntax unified
|
|
|
|
.arm
|
2013-05-16 23:33:22 +00:00
|
|
|
#if !defined (ARMV6) && !defined (ARMV7)
|
2013-05-03 12:41:08 +00:00
|
|
|
# error Unsupported architecture version!
|
2013-04-07 00:41:07 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
.align 2
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Simple cache maintenance functions
|
|
|
|
*/
|
|
|
|
|
|
|
|
@ r0 - *beg (inclusive)
|
2013-05-03 12:41:08 +00:00
|
|
|
@ r1 - *end (exclusive)
|
2013-04-07 00:41:07 +00:00
|
|
|
clean_dcache_range:
|
2013-05-03 12:41:08 +00:00
|
|
|
@ Clean data cache for range to point-of-unification
|
2013-05-16 23:33:22 +00:00
|
|
|
ldr r2, =EXT_C(grub_arch_cache_dlinesz)
|
2013-09-19 07:21:24 +00:00
|
|
|
ldr r2, [r2]
|
2013-05-03 12:41:08 +00:00
|
|
|
sub r3, r2, #1 @ align "beg" to start of line
|
|
|
|
mvn r3, r3
|
|
|
|
and r0, r0, r3
|
2013-04-07 00:41:07 +00:00
|
|
|
1: cmp r0, r1
|
|
|
|
bge 2f
|
2013-05-16 23:33:22 +00:00
|
|
|
#ifdef ARMV6
|
2013-05-16 14:23:31 +00:00
|
|
|
mcr p15, 0, r0, c7, c10, 1 @ Clean data cache line by MVA
|
|
|
|
#else
|
2013-04-07 00:41:07 +00:00
|
|
|
mcr p15, 0, r0, c7, c11, 1 @ DCCMVAU
|
2013-05-16 14:23:31 +00:00
|
|
|
#endif
|
2013-04-07 00:41:07 +00:00
|
|
|
add r0, r0, r2 @ Next line
|
|
|
|
b 1b
|
2013-05-03 12:41:08 +00:00
|
|
|
2: DSB
|
2013-04-07 00:41:07 +00:00
|
|
|
bx lr
|
|
|
|
|
|
|
|
@ r0 - *beg (inclusive)
|
2013-05-03 12:41:08 +00:00
|
|
|
@ r1 - *end (exclusive)
|
2013-04-07 00:41:07 +00:00
|
|
|
invalidate_icache_range:
|
|
|
|
@ Invalidate instruction cache for range to point-of-unification
|
2013-05-16 23:33:22 +00:00
|
|
|
ldr r2, =EXT_C(grub_arch_cache_ilinesz)
|
2013-09-19 07:21:24 +00:00
|
|
|
ldr r2, [r2]
|
2013-05-03 12:41:08 +00:00
|
|
|
sub r3, r2, #1 @ align "beg" to start of line
|
|
|
|
mvn r3, r3
|
|
|
|
and r0, r0, r3
|
2013-04-07 00:41:07 +00:00
|
|
|
1: cmp r0, r1
|
|
|
|
bge 2f
|
|
|
|
mcr p15, 0, r0, c7, c5, 1 @ ICIMVAU
|
|
|
|
add r0, r0, r2 @ Next line
|
|
|
|
b 1b
|
|
|
|
@ Branch predictor invalidate all
|
|
|
|
2: mcr p15, 0, r0, c7, c5, 6 @ BPIALL
|
2013-05-03 12:41:08 +00:00
|
|
|
DSB
|
|
|
|
ISB
|
2013-04-07 00:41:07 +00:00
|
|
|
bx lr
|
2013-05-03 12:41:08 +00:00
|
|
|
|
2013-05-16 23:33:22 +00:00
|
|
|
@void grub_arch_sync_caches (void *address, grub_size_t len)
|
|
|
|
#ifdef ARMV6
|
|
|
|
FUNCTION(grub_arch_sync_caches_armv6)
|
|
|
|
#else
|
|
|
|
FUNCTION(grub_arch_sync_caches_armv7)
|
|
|
|
#endif
|
2013-05-03 12:41:08 +00:00
|
|
|
DSB
|
2013-09-19 07:21:24 +00:00
|
|
|
add r1, r0, r1
|
|
|
|
push {r0-r2, lr}
|
2013-04-07 00:41:07 +00:00
|
|
|
bl clean_dcache_range
|
2013-05-16 14:23:31 +00:00
|
|
|
pop {r0, r1}
|
2013-04-07 00:41:07 +00:00
|
|
|
bl invalidate_icache_range
|
2013-09-19 07:21:24 +00:00
|
|
|
pop {r2, pc}
|
2013-04-07 00:41:07 +00:00
|
|
|
|
2013-05-16 23:33:22 +00:00
|
|
|
#ifdef ARMV6
|
|
|
|
FUNCTION(grub_arm_disable_caches_mmu_armv6)
|
2013-05-16 14:23:31 +00:00
|
|
|
#else
|
2013-05-16 23:33:22 +00:00
|
|
|
FUNCTION(grub_arm_disable_caches_mmu_armv7)
|
2013-05-16 14:23:31 +00:00
|
|
|
#endif
|
2013-04-07 00:41:07 +00:00
|
|
|
|
|
|
|
push {r4, lr}
|
|
|
|
|
|
|
|
@ disable D-cache
|
|
|
|
mrc p15, 0, r0, c1, c0, 0
|
|
|
|
bic r0, r0, #(1 << 2)
|
|
|
|
mcr p15, 0, r0, c1, c0, 0
|
2013-05-03 12:41:08 +00:00
|
|
|
DSB
|
|
|
|
ISB
|
2013-04-07 00:41:07 +00:00
|
|
|
|
|
|
|
@ clean/invalidate D-cache
|
|
|
|
bl clean_invalidate_dcache
|
|
|
|
|
|
|
|
@ disable I-cache
|
|
|
|
mrc p15, 0, r0, c1, c0, 0
|
|
|
|
bic r0, r0, #(1 << 12)
|
|
|
|
mcr p15, 0, r0, c1, c0, 0
|
2013-05-03 12:41:08 +00:00
|
|
|
DSB
|
|
|
|
ISB
|
2013-04-07 00:41:07 +00:00
|
|
|
|
|
|
|
@ invalidate I-cache (also invalidates branch predictors)
|
|
|
|
mcr p15, 0, r0, c7, c5, 0
|
2013-05-03 12:41:08 +00:00
|
|
|
DSB
|
|
|
|
ISB
|
|
|
|
|
2013-04-07 00:41:07 +00:00
|
|
|
@ clear SCTLR M bit
|
|
|
|
mrc p15, 0, r0, c1, c0, 0
|
|
|
|
bic r0, r0, #(1 << 0)
|
|
|
|
mcr p15, 0, r0, c1, c0, 0
|
|
|
|
|
|
|
|
mcr p15, 0, r0, c8, c7, 0 @ invalidate TLB
|
|
|
|
mcr p15, 0, r0, c7, c5, 6 @ invalidate branch predictor
|
2013-05-03 12:41:08 +00:00
|
|
|
DSB
|
|
|
|
ISB
|
2013-04-07 00:41:07 +00:00
|
|
|
|
|
|
|
pop {r4, pc}
|
|
|
|
|