flat.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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_argvp_envp_on_stack() 0
  14. #define flat_old_ram_flag(flags) (flags)
  15. #define flat_reloc_valid(reloc, size) ((reloc) <= (size))
  16. #define flat_set_persistent(relval, p) 0
  17. /*
  18. * Microblaze works a little differently from other arches, because
  19. * of the MICROBLAZE_64 reloc type. Here, a 32 bit address is split
  20. * over two instructions, an 'imm' instruction which provides the top
  21. * 16 bits, then the instruction "proper" which provides the low 16
  22. * bits.
  23. */
  24. /*
  25. * Crack open a symbol reference and extract the address to be
  26. * relocated. rp is a potentially unaligned pointer to the
  27. * reference
  28. */
  29. static inline unsigned long
  30. flat_get_addr_from_rp(unsigned long *rp, unsigned long relval,
  31. unsigned long flags, unsigned long *persistent)
  32. {
  33. unsigned long addr;
  34. (void)flags;
  35. /* Is it a split 64/32 reference? */
  36. if (relval & 0x80000000) {
  37. /* Grab the two halves of the reference */
  38. unsigned long val_hi, val_lo;
  39. val_hi = get_unaligned(rp);
  40. val_lo = get_unaligned(rp+1);
  41. /* Crack the address out */
  42. addr = ((val_hi & 0xffff) << 16) + (val_lo & 0xffff);
  43. } else {
  44. /* Get the address straight out */
  45. addr = get_unaligned(rp);
  46. }
  47. return addr;
  48. }
  49. /*
  50. * Insert an address into the symbol reference at rp. rp is potentially
  51. * unaligned.
  52. */
  53. static inline void
  54. flat_put_addr_at_rp(unsigned long *rp, unsigned long addr, unsigned long relval)
  55. {
  56. /* Is this a split 64/32 reloc? */
  57. if (relval & 0x80000000) {
  58. /* Get the two "halves" */
  59. unsigned long val_hi = get_unaligned(rp);
  60. unsigned long val_lo = get_unaligned(rp + 1);
  61. /* insert the address */
  62. val_hi = (val_hi & 0xffff0000) | addr >> 16;
  63. val_lo = (val_lo & 0xffff0000) | (addr & 0xffff);
  64. /* store the two halves back into memory */
  65. put_unaligned(val_hi, rp);
  66. put_unaligned(val_lo, rp+1);
  67. } else {
  68. /* Put it straight in, no messing around */
  69. put_unaligned(addr, rp);
  70. }
  71. }
  72. #define flat_get_relocate_addr(rel) (rel & 0x7fffffff)
  73. #endif /* _ASM_MICROBLAZE_FLAT_H */