flat.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. /*
  2. * Copyright 2007 Analog Devices Inc.
  3. *
  4. * Licensed under the GPL-2.
  5. */
  6. #include <linux/module.h>
  7. #include <linux/sched.h>
  8. #include <linux/flat.h>
  9. #define FLAT_BFIN_RELOC_TYPE_16_BIT 0
  10. #define FLAT_BFIN_RELOC_TYPE_16H_BIT 1
  11. #define FLAT_BFIN_RELOC_TYPE_32_BIT 2
  12. unsigned long bfin_get_addr_from_rp(unsigned long *ptr,
  13. unsigned long relval,
  14. unsigned long flags,
  15. unsigned long *persistent)
  16. {
  17. unsigned short *usptr = (unsigned short *)ptr;
  18. int type = (relval >> 26) & 7;
  19. unsigned long val;
  20. switch (type) {
  21. case FLAT_BFIN_RELOC_TYPE_16_BIT:
  22. case FLAT_BFIN_RELOC_TYPE_16H_BIT:
  23. usptr = (unsigned short *)ptr;
  24. pr_debug("*usptr = %x", get_unaligned(usptr));
  25. val = get_unaligned(usptr);
  26. val += *persistent;
  27. break;
  28. case FLAT_BFIN_RELOC_TYPE_32_BIT:
  29. pr_debug("*ptr = %lx", get_unaligned(ptr));
  30. val = get_unaligned(ptr);
  31. break;
  32. default:
  33. pr_debug("BINFMT_FLAT: Unknown relocation type %x\n", type);
  34. return 0;
  35. }
  36. /*
  37. * Stack-relative relocs contain the offset into the stack, we
  38. * have to add the stack's start address here and return 1 from
  39. * flat_addr_absolute to prevent the normal address calculations
  40. */
  41. if (relval & (1 << 29))
  42. return val + current->mm->context.end_brk;
  43. if ((flags & FLAT_FLAG_GOTPIC) == 0)
  44. val = htonl(val);
  45. return val;
  46. }
  47. EXPORT_SYMBOL(bfin_get_addr_from_rp);
  48. /*
  49. * Insert the address ADDR into the symbol reference at RP;
  50. * RELVAL is the raw relocation-table entry from which RP is derived
  51. */
  52. void bfin_put_addr_at_rp(unsigned long *ptr, unsigned long addr,
  53. unsigned long relval)
  54. {
  55. unsigned short *usptr = (unsigned short *)ptr;
  56. int type = (relval >> 26) & 7;
  57. switch (type) {
  58. case FLAT_BFIN_RELOC_TYPE_16_BIT:
  59. put_unaligned(addr, usptr);
  60. pr_debug("new value %x at %p", get_unaligned(usptr), usptr);
  61. break;
  62. case FLAT_BFIN_RELOC_TYPE_16H_BIT:
  63. put_unaligned(addr >> 16, usptr);
  64. pr_debug("new value %x", get_unaligned(usptr));
  65. break;
  66. case FLAT_BFIN_RELOC_TYPE_32_BIT:
  67. put_unaligned(addr, ptr);
  68. pr_debug("new ptr =%lx", get_unaligned(ptr));
  69. break;
  70. }
  71. }
  72. EXPORT_SYMBOL(bfin_put_addr_at_rp);