flat.c 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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", type);
  48. return 0;
  49. }
  50. /*
  51. * Stack-relative relocs contain the offset into the stack, we
  52. * have to add the stack's start address here and return 1 from
  53. * flat_addr_absolute to prevent the normal address calculations
  54. */
  55. if (relval & (1 << 29))
  56. return val + current->mm->context.end_brk;
  57. if ((flags & FLAT_FLAG_GOTPIC) == 0)
  58. val = htonl(val);
  59. return val;
  60. }
  61. EXPORT_SYMBOL(bfin_get_addr_from_rp);
  62. /*
  63. * Insert the address ADDR into the symbol reference at RP;
  64. * RELVAL is the raw relocation-table entry from which RP is derived
  65. */
  66. void bfin_put_addr_at_rp(unsigned long *ptr, unsigned long addr,
  67. unsigned long relval)
  68. {
  69. unsigned short *usptr = (unsigned short *)ptr;
  70. int type = (relval >> 26) & 7;
  71. switch (type) {
  72. case FLAT_BFIN_RELOC_TYPE_16_BIT:
  73. put_unaligned(addr, usptr);
  74. pr_debug("new value %x at %p", get_unaligned(usptr), usptr);
  75. break;
  76. case FLAT_BFIN_RELOC_TYPE_16H_BIT:
  77. put_unaligned(addr >> 16, usptr);
  78. pr_debug("new value %x", get_unaligned(usptr));
  79. break;
  80. case FLAT_BFIN_RELOC_TYPE_32_BIT:
  81. put_unaligned(addr, ptr);
  82. pr_debug("new ptr =%lx", get_unaligned(ptr));
  83. break;
  84. }
  85. }
  86. EXPORT_SYMBOL(bfin_put_addr_at_rp);