flat.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * arch/blackfin/kernel/flat.c
  3. *
  4. * Copyright (C) 2007 Analog Devices, Inc.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  19. */
  20. #include <linux/module.h>
  21. #include <linux/sched.h>
  22. #include <linux/flat.h>
  23. #define FLAT_BFIN_RELOC_TYPE_16_BIT 0
  24. #define FLAT_BFIN_RELOC_TYPE_16H_BIT 1
  25. #define FLAT_BFIN_RELOC_TYPE_32_BIT 2
  26. unsigned long bfin_get_addr_from_rp(unsigned long *ptr,
  27. unsigned long relval,
  28. unsigned long flags,
  29. unsigned long *persistent)
  30. {
  31. unsigned short *usptr = (unsigned short *)ptr;
  32. int type = (relval >> 26) & 7;
  33. unsigned long val;
  34. switch (type) {
  35. case FLAT_BFIN_RELOC_TYPE_16_BIT:
  36. case FLAT_BFIN_RELOC_TYPE_16H_BIT:
  37. usptr = (unsigned short *)ptr;
  38. pr_debug("*usptr = %x", get_unaligned(usptr));
  39. val = get_unaligned(usptr);
  40. val += *persistent;
  41. break;
  42. case FLAT_BFIN_RELOC_TYPE_32_BIT:
  43. pr_debug("*ptr = %lx", get_unaligned(ptr));
  44. val = get_unaligned(ptr);
  45. break;
  46. default:
  47. pr_debug("BINFMT_FLAT: Unknown relocation type %x\n",
  48. type);
  49. return 0;
  50. }
  51. /*
  52. * Stack-relative relocs contain the offset into the stack, we
  53. * have to add the stack's start address here and return 1 from
  54. * flat_addr_absolute to prevent the normal address calculations
  55. */
  56. if (relval & (1 << 29))
  57. return val + current->mm->context.end_brk;
  58. if ((flags & FLAT_FLAG_GOTPIC) == 0)
  59. val = htonl(val);
  60. return val;
  61. }
  62. EXPORT_SYMBOL(bfin_get_addr_from_rp);
  63. /*
  64. * Insert the address ADDR into the symbol reference at RP;
  65. * RELVAL is the raw relocation-table entry from which RP is derived
  66. */
  67. void bfin_put_addr_at_rp(unsigned long *ptr, unsigned long addr,
  68. unsigned long relval)
  69. {
  70. unsigned short *usptr = (unsigned short *)ptr;
  71. int type = (relval >> 26) & 7;
  72. switch (type) {
  73. case FLAT_BFIN_RELOC_TYPE_16_BIT:
  74. put_unaligned(addr, usptr);
  75. pr_debug("new value %x at %p", get_unaligned(usptr),
  76. usptr);
  77. break;
  78. case FLAT_BFIN_RELOC_TYPE_16H_BIT:
  79. put_unaligned(addr >> 16, usptr);
  80. pr_debug("new value %x", get_unaligned(usptr));
  81. break;
  82. case FLAT_BFIN_RELOC_TYPE_32_BIT:
  83. put_unaligned(addr, ptr);
  84. pr_debug("new ptr =%lx", get_unaligned(ptr));
  85. break;
  86. }
  87. }
  88. EXPORT_SYMBOL(bfin_put_addr_at_rp);