cache.S 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 2013 Free Software Foundation, Inc.
  4. *
  5. * GRUB is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * GRUB is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include <grub/symbol.h>
  19. .file "cache.S"
  20. .text
  21. .syntax unified
  22. #if !defined (__thumb2__) || !defined (ARMV7)
  23. .arm
  24. #else
  25. .thumb
  26. #endif
  27. #if !defined (ARMV6) && !defined (ARMV7)
  28. # error Unsupported architecture version!
  29. #endif
  30. .align 2
  31. /*
  32. * Simple cache maintenance functions
  33. */
  34. @ r0 - *beg (inclusive)
  35. @ r1 - *end (exclusive)
  36. @void grub_arm_clean_dcache_range (grub_addr_t start, grub_addr_t end, grub_addr_t dlinesz)
  37. #ifdef ARMV6
  38. FUNCTION(grub_arm_clean_dcache_range_armv6)
  39. #else
  40. FUNCTION(grub_arm_clean_dcache_range_armv7)
  41. #endif
  42. DSB
  43. @ Clean data cache for range to point-of-unification
  44. 1: cmp r0, r1
  45. bge 2f
  46. #ifdef ARMV6
  47. mcr p15, 0, r0, c7, c10, 1 @ Clean data cache line by MVA
  48. #else
  49. mcr p15, 0, r0, c7, c11, 1 @ DCCMVAU
  50. #endif
  51. add r0, r0, r2 @ Next line
  52. b 1b
  53. 2: DSB
  54. bx lr
  55. @ r0 - *beg (inclusive)
  56. @ r1 - *end (exclusive)
  57. #ifdef ARMV6
  58. FUNCTION(grub_arm_invalidate_icache_range_armv6)
  59. #else
  60. FUNCTION(grub_arm_invalidate_icache_range_armv7)
  61. #endif
  62. @ Invalidate instruction cache for range to point-of-unification
  63. 1: cmp r0, r1
  64. bge 2f
  65. mcr p15, 0, r0, c7, c5, 1 @ ICIMVAU
  66. add r0, r0, r2 @ Next line
  67. b 1b
  68. @ Branch predictor invalidate all
  69. 2: mcr p15, 0, r0, c7, c5, 6 @ BPIALL
  70. DSB
  71. ISB
  72. bx lr
  73. #ifdef ARMV6
  74. FUNCTION(grub_arm_disable_caches_mmu_armv6)
  75. #else
  76. FUNCTION(grub_arm_disable_caches_mmu_armv7)
  77. #endif
  78. push {r4, lr}
  79. @ disable D-cache
  80. mrc p15, 0, r0, c1, c0, 0
  81. bic r0, r0, #(1 << 2)
  82. mcr p15, 0, r0, c1, c0, 0
  83. DSB
  84. ISB
  85. @ clean/invalidate D-cache
  86. bl clean_invalidate_dcache
  87. @ disable I-cache
  88. mrc p15, 0, r0, c1, c0, 0
  89. bic r0, r0, #(1 << 12)
  90. mcr p15, 0, r0, c1, c0, 0
  91. DSB
  92. ISB
  93. @ invalidate I-cache (also invalidates branch predictors)
  94. mcr p15, 0, r0, c7, c5, 0
  95. DSB
  96. ISB
  97. @ clear SCTLR M bit
  98. mrc p15, 0, r0, c1, c0, 0
  99. bic r0, r0, #(1 << 0)
  100. mcr p15, 0, r0, c1, c0, 0
  101. mcr p15, 0, r0, c8, c7, 0 @ invalidate TLB
  102. mcr p15, 0, r0, c7, c5, 6 @ invalidate branch predictor
  103. DSB
  104. ISB
  105. pop {r4, lr}
  106. bx lr