xip_fixup.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * XIP fixup macros, only useful in assembly.
  4. */
  5. #ifndef _ASM_RISCV_XIP_FIXUP_H
  6. #define _ASM_RISCV_XIP_FIXUP_H
  7. #include <linux/pgtable.h>
  8. #ifdef CONFIG_XIP_KERNEL
  9. .macro XIP_FIXUP_OFFSET reg
  10. /* Fix-up address in Flash into address in RAM early during boot before
  11. * MMU is up. Because generated code "thinks" data is in Flash, but it
  12. * is actually in RAM (actually data is also in Flash, but Flash is
  13. * read-only, thus we need to use the data residing in RAM).
  14. *
  15. * The start of data in Flash is _sdata and the start of data in RAM is
  16. * CONFIG_PHYS_RAM_BASE. So this fix-up essentially does this:
  17. * reg += CONFIG_PHYS_RAM_BASE - _start
  18. */
  19. li t0, CONFIG_PHYS_RAM_BASE
  20. add \reg, \reg, t0
  21. la t0, _sdata
  22. sub \reg, \reg, t0
  23. .endm
  24. .macro XIP_FIXUP_FLASH_OFFSET reg
  25. /* In linker script, at the transition from read-only section to
  26. * writable section, the VMA is increased while LMA remains the same.
  27. * (See in linker script how _sdata, __data_loc and LOAD_OFFSET is
  28. * changed)
  29. *
  30. * Consequently, early during boot before MMU is up, the generated code
  31. * reads the "writable" section at wrong addresses, because VMA is used
  32. * by compiler to generate code, but the data is located in Flash using
  33. * LMA.
  34. */
  35. la t0, _sdata
  36. sub \reg, \reg, t0
  37. la t0, __data_loc
  38. add \reg, \reg, t0
  39. .endm
  40. #else
  41. .macro XIP_FIXUP_OFFSET reg
  42. .endm
  43. .macro XIP_FIXUP_FLASH_OFFSET reg
  44. .endm
  45. #endif /* CONFIG_XIP_KERNEL */
  46. #endif