descriptor-pa32-hpux.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. /* descriptor-pa32-hpux.h - Given a function pointer, extract and return the
  2. actual code address of the corresponding function.
  3. This is done by checking if the plabel bit is set. If it's not set,
  4. return the function pointer. If it's set, mask it off and extract
  5. the address from the function descriptor. This address may point
  6. to an export stub. If so, extract the branch target from the stub
  7. and return it. Otherwise, the address from the function descriptor
  8. is returned.
  9. Copyright (C) 2006 Free Software Foundation
  10. This file is part of libgcj.
  11. This software is copyrighted work licensed under the terms of the
  12. Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
  13. details. */
  14. #define UNWRAP_FUNCTION_DESCRIPTOR pa_unwrap_function_descriptor
  15. #ifdef __cplusplus
  16. extern "C" {
  17. #endif
  18. /* Extract bit field from word using HP's numbering (MSB = 0). */
  19. #define GET_FIELD(X, FROM, TO) \
  20. ((X) >> (31 - (TO)) & ((1 << ((TO) - (FROM) + 1)) - 1))
  21. static inline int
  22. sign_extend (int x, int len)
  23. {
  24. int signbit = (1 << (len - 1));
  25. int mask = (signbit << 1) - 1;
  26. return ((x & mask) ^ signbit) - signbit;
  27. }
  28. /* Extract a 17-bit signed constant from branch instructions. */
  29. static inline int
  30. extract_17 (unsigned word)
  31. {
  32. return sign_extend (GET_FIELD (word, 19, 28)
  33. | GET_FIELD (word, 29, 29) << 10
  34. | GET_FIELD (word, 11, 15) << 11
  35. | (word & 0x1) << 16, 17);
  36. }
  37. /* Extract a 22-bit signed constant from branch instructions. */
  38. static inline int
  39. extract_22 (unsigned word)
  40. {
  41. return sign_extend (GET_FIELD (word, 19, 28)
  42. | GET_FIELD (word, 29, 29) << 10
  43. | GET_FIELD (word, 11, 15) << 11
  44. | GET_FIELD (word, 6, 10) << 16
  45. | (word & 0x1) << 21, 22);
  46. }
  47. static void *
  48. pa_unwrap_function_descriptor (void *addr)
  49. {
  50. unsigned int *tmp_addr;
  51. /* Check if plabel bit is set in function pointer. */
  52. if (!((unsigned int) addr & 2))
  53. return addr;
  54. tmp_addr = *(unsigned int **) ((unsigned int) addr & ~3);
  55. /* If TMP_ADDR points to an export stub, adjust it so that it points
  56. to the branch target of the stub. */
  57. if ((*tmp_addr & 0xffe0e002) == 0xe8400000 /* bl x,r2 */
  58. && *(tmp_addr + 1) == 0x08000240 /* nop */
  59. && *(tmp_addr + 2) == 0x4bc23fd1 /* ldw -18(sp),rp */
  60. && *(tmp_addr + 3) == 0x004010a1 /* ldsid (rp),r1 */
  61. && *(tmp_addr + 4) == 0x00011820 /* mtsp r1,sr0 */
  62. && *(tmp_addr + 5) == 0xe0400002) /* be,n 0(sr0,rp) */
  63. /* Extract target address from PA 1.x 17-bit branch. */
  64. tmp_addr += extract_17 (*tmp_addr) + 2;
  65. else if ((*tmp_addr & 0xfc00e002) == 0xe800a000 /* b,l x,r2 */
  66. && *(tmp_addr + 1) == 0x08000240 /* nop */
  67. && *(tmp_addr + 2) == 0x4bc23fd1 /* ldw -18(sp),rp */
  68. && *(tmp_addr + 3) == 0xe840d002) /* bve,n (rp) */
  69. /* Extract target address from PA 2.0 22-bit branch. */
  70. tmp_addr += extract_22 (*tmp_addr) + 2;
  71. return (void *) tmp_addr;
  72. }
  73. #ifdef __cplusplus
  74. }
  75. #endif