cache.S 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* cache.S - Flush the processor cache for a specific region. */
  2. /*
  3. * GRUB -- GRand Unified Bootloader
  4. * Copyright (C) 2004,2007 Free Software Foundation, Inc.
  5. *
  6. * GRUB is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * GRUB is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with GRUB. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. #define CACHE_LINE_BYTES 32
  20. .text
  21. .align 2
  22. .globl grub_arch_sync_caches
  23. grub_arch_sync_caches:
  24. #ifdef APPLE_CC
  25. /* `address' may not be CACHE_LINE_BYTES-aligned. */
  26. andi. r6, r3, CACHE_LINE_BYTES - 1 /* Find the misalignment. */
  27. add r4, r4, r6 /* Adjust `size' to compensate. */
  28. /* Force the dcache lines to memory. */
  29. li r5, 0
  30. 1: dcbst r5, r3
  31. addi r5, r5, CACHE_LINE_BYTES
  32. cmpw r5, r4
  33. blt 1b
  34. sync /* Force all dcbsts to complete. */
  35. /* Invalidate the icache lines. */
  36. li r5, 0
  37. 1: icbi r5, r3
  38. addi r5, r5, CACHE_LINE_BYTES
  39. cmpw r5, r4
  40. blt 1b
  41. sync /* Force all icbis to complete. */
  42. isync /* Discard partially executed instructions that were
  43. loaded from the invalid icache. */
  44. blr
  45. #else
  46. /* `address' may not be CACHE_LINE_BYTES-aligned. */
  47. andi. 6, 3, CACHE_LINE_BYTES - 1 /* Find the misalignment. */
  48. add 4, 4, 6 /* Adjust `size' to compensate. */
  49. /* Force the dcache lines to memory. */
  50. li 5, 0
  51. 1: dcbst 5, 3
  52. addi 5, 5, CACHE_LINE_BYTES
  53. cmpw 5, 4
  54. blt 1b
  55. sync /* Force all dcbsts to complete. */
  56. /* Invalidate the icache lines. */
  57. li 5, 0
  58. 1: icbi 5, 3
  59. addi 5, 5, CACHE_LINE_BYTES
  60. cmpw 5, 4
  61. blt 1b
  62. sync /* Force all icbis to complete. */
  63. isync /* Discard partially executed instructions that were
  64. loaded from the invalid icache. */
  65. blr
  66. #endif