flat.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * uClinux flat-format executables
  3. *
  4. * Copyright (C) 2005 John Williams <jwilliams@itee.uq.edu.au>
  5. *
  6. * This file is subject to the terms and conditions of the GNU General
  7. * Public License. See the file COPYING in the main directory of this
  8. * archive for more details.
  9. */
  10. #ifndef _ASM_MICROBLAZE_FLAT_H
  11. #define _ASM_MICROBLAZE_FLAT_H
  12. #include <asm/unaligned.h>
  13. #define flat_stack_align(sp) /* nothing needed */
  14. #define flat_argvp_envp_on_stack() 0
  15. #define flat_old_ram_flag(flags) (flags)
  16. #define flat_reloc_valid(reloc, size) ((reloc) <= (size))
  17. #define flat_set_persistent(relval, p) 0
  18. /*
  19. * Microblaze works a little differently from other arches, because
  20. * of the MICROBLAZE_64 reloc type. Here, a 32 bit address is split
  21. * over two instructions, an 'imm' instruction which provides the top
  22. * 16 bits, then the instruction "proper" which provides the low 16
  23. * bits.
  24. */
  25. /*
  26. * Crack open a symbol reference and extract the address to be
  27. * relocated. rp is a potentially unaligned pointer to the
  28. * reference
  29. */
  30. static inline unsigned long
  31. flat_get_addr_from_rp(unsigned long *rp, unsigned long relval,
  32. unsigned long flags, unsigned long *persistent)
  33. {
  34. unsigned long addr;
  35. (void)flags;
  36. /* Is it a split 64/32 reference? */
  37. if (relval & 0x80000000) {
  38. /* Grab the two halves of the reference */
  39. unsigned long val_hi, val_lo;
  40. val_hi = get_unaligned(rp);
  41. val_lo = get_unaligned(rp+1);
  42. /* Crack the address out */
  43. addr = ((val_hi & 0xffff) << 16) + (val_lo & 0xffff);
  44. } else {
  45. /* Get the address straight out */
  46. addr = get_unaligned(rp);
  47. }
  48. return addr;
  49. }
  50. /*
  51. * Insert an address into the symbol reference at rp. rp is potentially
  52. * unaligned.
  53. */
  54. static inline void
  55. flat_put_addr_at_rp(unsigned long *rp, unsigned long addr, unsigned long relval)
  56. {
  57. /* Is this a split 64/32 reloc? */
  58. if (relval & 0x80000000) {
  59. /* Get the two "halves" */
  60. unsigned long val_hi = get_unaligned(rp);
  61. unsigned long val_lo = get_unaligned(rp + 1);
  62. /* insert the address */
  63. val_hi = (val_hi & 0xffff0000) | addr >> 16;
  64. val_lo = (val_lo & 0xffff0000) | (addr & 0xffff);
  65. /* store the two halves back into memory */
  66. put_unaligned(val_hi, rp);
  67. put_unaligned(val_lo, rp+1);
  68. } else {
  69. /* Put it straight in, no messing around */
  70. put_unaligned(addr, rp);
  71. }
  72. }
  73. #define flat_get_relocate_addr(rel) (rel & 0x7fffffff)
  74. #endif /* _ASM_MICROBLAZE_FLAT_H */