flat.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * uClinux flat-format executables
  4. *
  5. * Copyright (C) 2005 John Williams <[email protected]>
  6. */
  7. #ifndef _ASM_MICROBLAZE_FLAT_H
  8. #define _ASM_MICROBLAZE_FLAT_H
  9. #include <asm/unaligned.h>
  10. /*
  11. * Microblaze works a little differently from other arches, because
  12. * of the MICROBLAZE_64 reloc type. Here, a 32 bit address is split
  13. * over two instructions, an 'imm' instruction which provides the top
  14. * 16 bits, then the instruction "proper" which provides the low 16
  15. * bits.
  16. */
  17. /*
  18. * Crack open a symbol reference and extract the address to be
  19. * relocated. rp is a potentially unaligned pointer to the
  20. * reference
  21. */
  22. static inline int flat_get_addr_from_rp(u32 __user *rp, u32 relval, u32 flags,
  23. u32 *addr)
  24. {
  25. u32 *p = (__force u32 *)rp;
  26. /* Is it a split 64/32 reference? */
  27. if (relval & 0x80000000) {
  28. /* Grab the two halves of the reference */
  29. u32 val_hi, val_lo;
  30. val_hi = get_unaligned(p);
  31. val_lo = get_unaligned(p+1);
  32. /* Crack the address out */
  33. *addr = ((val_hi & 0xffff) << 16) + (val_lo & 0xffff);
  34. } else {
  35. /* Get the address straight out */
  36. *addr = get_unaligned(p);
  37. }
  38. return 0;
  39. }
  40. /*
  41. * Insert an address into the symbol reference at rp. rp is potentially
  42. * unaligned.
  43. */
  44. static inline int
  45. flat_put_addr_at_rp(u32 __user *rp, u32 addr, u32 relval)
  46. {
  47. u32 *p = (__force u32 *)rp;
  48. /* Is this a split 64/32 reloc? */
  49. if (relval & 0x80000000) {
  50. /* Get the two "halves" */
  51. unsigned long val_hi = get_unaligned(p);
  52. unsigned long val_lo = get_unaligned(p + 1);
  53. /* insert the address */
  54. val_hi = (val_hi & 0xffff0000) | addr >> 16;
  55. val_lo = (val_lo & 0xffff0000) | (addr & 0xffff);
  56. /* store the two halves back into memory */
  57. put_unaligned(val_hi, p);
  58. put_unaligned(val_lo, p+1);
  59. } else {
  60. /* Put it straight in, no messing around */
  61. put_unaligned(addr, p);
  62. }
  63. return 0;
  64. }
  65. #define flat_get_relocate_addr(rel) (rel & 0x7fffffff)
  66. #endif /* _ASM_MICROBLAZE_FLAT_H */