PageRenderTime 58ms CodeModel.GetById 31ms RepoModel.GetById 0ms app.codeStats 1ms

/src/pistachio/kernel/kdb/arch/ia64/ia64-dis.c

https://github.com/gz/aos10
C | 177 lines | 100 code | 35 blank | 42 comment | 6 complexity | bc5c06b40244b4e718dbc3bd9e4895ab MD5 | raw file
  1. /*********************************************************************
  2. *
  3. * Copyright (C) 2002, Karlsruhe University
  4. *
  5. * File path: kdb/arch/ia64/ia64-dis.c
  6. * Description: Wrapper for IA-64 disassembler
  7. *
  8. * Redistribution and use in source and binary forms, with or without
  9. * modification, are permitted provided that the following conditions
  10. * are met:
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in the
  15. * documentation and/or other materials provided with the distribution.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  21. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27. * SUCH DAMAGE.
  28. *
  29. * $Id: ia64-dis.c,v 1.8 2003/09/24 19:05:06 skoglund Exp $
  30. *
  31. ********************************************************************/
  32. #define SEC_KDEBUG ".kdebug"
  33. /* define stuff needed by the disassembler */
  34. #define PARAMS(x) x SECTION(SEC_KDEBUG)
  35. #define ATTRIBUTE_UNUSED
  36. #define abort() do { } while (0)
  37. #define BFD_HOST_64_BIT u64_t
  38. #define BFD_HOST_U_64_BIT u64_t
  39. typedef u64_t bfd_vma;
  40. typedef u8_t bfd_byte;
  41. int printf(const char * format, ...);
  42. int sprintf(char* obuf, const char* format, ...);
  43. int fprintf(char* f, const char* format, ...);
  44. typedef int (*fprintf_ftype) (char*, const char*, ...);
  45. typedef struct disassemble_info {
  46. void* stream;
  47. int (*read_memory_func)(bfd_vma memaddr,
  48. bfd_byte *myaddr, word_t length,
  49. struct disassemble_info *info);
  50. void (*memory_error_func)(int status,
  51. bfd_vma memaddr,
  52. struct disassemble_info *info);
  53. int bytes_per_line;
  54. int display_endian;
  55. int endian;
  56. fprintf_ftype fprintf_func;
  57. void (*print_address_func)(bfd_vma addr, struct disassemble_info *info);
  58. } disassemble_info;
  59. /*
  60. * functions that the disassembler calls
  61. */
  62. /* load with enforced little endian */
  63. bfd_vma SECTION(SEC_KDEBUG) bfd_getl64 (bfd_byte* addr)
  64. {
  65. return (((bfd_vma) addr[7] << 56) | ((bfd_vma) addr[6] << 48) |
  66. ((bfd_vma) addr[5] << 40) | ((bfd_vma) addr[4] << 32) |
  67. ((bfd_vma) addr[3] << 24) | ((bfd_vma) addr[2] << 16) |
  68. ((bfd_vma) addr[1] << 8) | ((bfd_vma) addr[0] ));
  69. }
  70. /* read memory */
  71. int SECTION(SEC_KDEBUG) rmf(bfd_vma memaddr,
  72. bfd_byte *myaddr, word_t length,
  73. struct disassemble_info *info)
  74. {
  75. int readmem (addr_t vaddr, addr_t contents, word_t size);
  76. char* d = (char*) myaddr;
  77. char* s = (char*) memaddr;
  78. int len = length;
  79. while (len--)
  80. {
  81. #if 1
  82. if (! readmem ((addr_t) s, (addr_t) d, sizeof (char)))
  83. return 1;
  84. #else
  85. *d = *s;
  86. #endif
  87. d++; s++;
  88. };
  89. return 0;
  90. };
  91. /* respond to memory read error */
  92. void SECTION(SEC_KDEBUG) mef(int status,
  93. bfd_vma memaddr,
  94. struct disassemble_info *info)
  95. {
  96. //printf("%s(%x,%x,%x)\n", __FUNCTION__, status, memaddr, info);
  97. printf("##");
  98. };
  99. /* print address */
  100. void SECTION(SEC_KDEBUG) paf(bfd_vma addr, struct disassemble_info *info)
  101. {
  102. printf("%p", addr);
  103. };
  104. char SECTION(SEC_KDEBUG) *strcpy(char *dest, const char *src)
  105. {
  106. char* d = dest;
  107. const char* s = src;
  108. do { *d++ = *s; } while (*s++);
  109. return dest;
  110. };
  111. char SECTION(SEC_KDEBUG) *strcat(char *dest, const char *src)
  112. {
  113. char* d = dest;
  114. char* s = (char*) src;
  115. /* scan for trailing \0 */
  116. while (*d)
  117. d++;
  118. /* copy until end of s, including the \0 */
  119. while ( (*d++ = *s++) );
  120. return dest;
  121. };
  122. int print_insn_ia64 (bfd_vma pc, disassemble_info *info) SECTION(SEC_KDEBUG);
  123. int SECTION(SEC_KDEBUG) disas(addr_t pc)
  124. {
  125. disassemble_info info =
  126. {
  127. NULL,
  128. rmf,
  129. mef,
  130. 6,
  131. 0,
  132. 0,
  133. fprintf,
  134. paf
  135. };
  136. return print_insn_ia64((u64_t)pc, &info);
  137. }
  138. #include <../../contrib/disas/cpu-ia64-opc.c>
  139. #include <../../contrib/disas/ia64-dis.c>
  140. #undef PARAMS
  141. #define PARAMS(x) x SECTION(SEC_KDEBUG)
  142. #include <../../contrib/disas/ia64-opc.c>