emul_generic.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. /* This file is part of the program psim.
  2. Copyright (C) 1994-1996, Andrew Cagney <cagney@highland.com.au>
  3. This program is free software; you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation; either version 3 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #ifndef _EMUL_GENERIC_H_
  15. #define _EMUL_GENERIC_H_
  16. #include "cpu.h"
  17. #include "idecode.h"
  18. #include "os_emul.h"
  19. #include "tree.h"
  20. #include "bfd.h"
  21. #include "libiberty.h"
  22. #ifndef INLINE_EMUL_GENERIC
  23. #define INLINE_EMUL_GENERIC
  24. #endif
  25. /* various PowerPC instructions for writing into memory */
  26. enum {
  27. emul_call_instruction = 0x1,
  28. emul_loop_instruction = 0x48000000, /* branch to . */
  29. emul_rfi_instruction = 0x4c000064,
  30. emul_blr_instruction = 0x4e800020,
  31. };
  32. /* emulation specific data */
  33. typedef struct _os_emul_data os_emul_data;
  34. typedef os_emul_data *(os_emul_create_handler)
  35. (device *tree,
  36. bfd *image,
  37. const char *emul_name);
  38. typedef void (os_emul_init_handler)
  39. (os_emul_data *emul_data,
  40. int nr_cpus);
  41. typedef void (os_emul_system_call_handler)
  42. (cpu *processor,
  43. unsigned_word cia,
  44. os_emul_data *emul_data);
  45. typedef int (os_emul_instruction_call_handler)
  46. (cpu *processor,
  47. unsigned_word cia,
  48. unsigned_word ra,
  49. os_emul_data *emul_data);
  50. struct _os_emul {
  51. const char *name;
  52. os_emul_create_handler *create;
  53. os_emul_init_handler *init;
  54. os_emul_system_call_handler *system_call;
  55. os_emul_instruction_call_handler *instruction_call;
  56. os_emul_data *data;
  57. };
  58. /* One class of emulation - system call is pretty general, provide a
  59. common template for implementing this */
  60. typedef struct _emul_syscall emul_syscall;
  61. typedef struct _emul_syscall_descriptor emul_syscall_descriptor;
  62. typedef void (emul_syscall_handler)
  63. (os_emul_data *emul_data,
  64. unsigned call,
  65. const int arg0,
  66. cpu *processor,
  67. unsigned_word cia);
  68. struct _emul_syscall_descriptor {
  69. emul_syscall_handler *handler;
  70. const char *name;
  71. };
  72. struct _emul_syscall {
  73. emul_syscall_descriptor *syscall_descriptor;
  74. int nr_system_calls;
  75. char **error_names;
  76. int nr_error_names;
  77. char **signal_names;
  78. int nr_signal_names;
  79. };
  80. INLINE_EMUL_GENERIC void emul_do_system_call
  81. (os_emul_data *emul_data,
  82. emul_syscall *syscall,
  83. unsigned call,
  84. const int arg0,
  85. cpu *processor,
  86. unsigned_word cia);
  87. INLINE_EMUL_GENERIC uint64_t emul_read_gpr64
  88. (cpu *processor,
  89. int g);
  90. INLINE_EMUL_GENERIC void emul_write_gpr64
  91. (cpu *processor,
  92. int g,
  93. uint64_t val);
  94. INLINE_EMUL_GENERIC void emul_write_status
  95. (cpu *processor,
  96. int status,
  97. int err);
  98. INLINE_EMUL_GENERIC void emul_write2_status
  99. (cpu *processor,
  100. int status1,
  101. int status2,
  102. int err);
  103. INLINE_EMUL_GENERIC char *emul_read_string
  104. (char *dest,
  105. unsigned_word addr,
  106. unsigned nr_bytes,
  107. cpu *processor,
  108. unsigned_word cia);
  109. INLINE_EMUL_GENERIC unsigned_word emul_read_word
  110. (unsigned_word addr,
  111. cpu *processor,
  112. unsigned_word cia);
  113. INLINE_EMUL_GENERIC void emul_write_word
  114. (unsigned_word addr,
  115. unsigned_word buf,
  116. cpu *processor,
  117. unsigned_word cia);
  118. INLINE_EMUL_GENERIC void emul_read_buffer
  119. (void *dest,
  120. unsigned_word addr,
  121. unsigned nr_bytes,
  122. cpu *processor,
  123. unsigned_word cia);
  124. INLINE_EMUL_GENERIC void emul_write_buffer
  125. (const void *source,
  126. unsigned_word addr,
  127. unsigned nr_bytes,
  128. cpu *processor,
  129. unsigned_word cia);
  130. /* Simplify the construction of device trees */
  131. INLINE_EMUL_GENERIC void emul_add_tree_options
  132. (device *tree,
  133. bfd *image,
  134. const char *emul,
  135. const char *env,
  136. int oea_interrupt_prefix);
  137. INLINE_EMUL_GENERIC void emul_add_tree_hardware
  138. (device *tree);
  139. #endif /* _EMUL_GENERIC_H_ */