cpu.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. /* This file is part of the program psim.
  2. Copyright (C) 1994-1997, 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 _CPU_H_
  15. #define _CPU_H_
  16. #include "basics.h"
  17. #include "registers.h"
  18. #include "device.h"
  19. #include "corefile.h"
  20. #include "vm.h"
  21. #include "events.h"
  22. #include "interrupts.h"
  23. #include "psim.h"
  24. #include "idecode.h"
  25. #include "itable.h"
  26. #include "os_emul.h"
  27. #include "mon.h"
  28. #include "model.h"
  29. #include "ansidecl.h"
  30. #include "libiberty.h"
  31. #ifndef CONST_ATTRIBUTE
  32. #define CONST_ATTRIBUTE __attribute__((__const__))
  33. #endif
  34. /* typedef struct _cpu cpu;
  35. Declared in basics.h because it is used opaquely throughout the
  36. code */
  37. /* Create a cpu object */
  38. INLINE_CPU\
  39. (cpu *) cpu_create
  40. (psim *system,
  41. core *memory,
  42. cpu_mon *monitor,
  43. os_emul *cpu_emulation,
  44. int cpu_nr);
  45. INLINE_CPU\
  46. (void) cpu_init
  47. (cpu *processor);
  48. /* Find our way home */
  49. INLINE_CPU\
  50. (psim *) cpu_system
  51. (cpu *processor) CONST_ATTRIBUTE;
  52. INLINE_CPU\
  53. (cpu_mon *) cpu_monitor
  54. (cpu *processor) CONST_ATTRIBUTE;
  55. INLINE_CPU\
  56. (os_emul *) cpu_os_emulation
  57. (cpu *processor);
  58. INLINE_CPU\
  59. (int) cpu_nr
  60. (cpu *processor) CONST_ATTRIBUTE;
  61. /* manipulate the processors program counter and execution state.
  62. The program counter is not included in the register file. Instead
  63. it is extracted and then later restored (set, reset, halt). This
  64. is to give the user of the cpu (and the compiler) the chance to
  65. minimize the need to load/store the cpu's PC value. (Especially in
  66. the case of a single processor) */
  67. INLINE_CPU\
  68. (void) cpu_set_program_counter
  69. (cpu *processor,
  70. unsigned_word new_program_counter);
  71. INLINE_CPU\
  72. (unsigned_word) cpu_get_program_counter
  73. (cpu *processor);
  74. INLINE_CPU\
  75. (void) cpu_restart
  76. (cpu *processor,
  77. unsigned_word nia);
  78. INLINE_CPU\
  79. (void) cpu_halt
  80. (cpu *processor,
  81. unsigned_word nia,
  82. stop_reason reason,
  83. int signal);
  84. EXTERN_CPU\
  85. (void) cpu_error
  86. (cpu *processor,
  87. unsigned_word cia,
  88. const char *fmt,
  89. ...) ATTRIBUTE_PRINTF_3;
  90. /* The processors local concept of time */
  91. INLINE_CPU\
  92. (int64_t) cpu_get_time_base
  93. (cpu *processor);
  94. INLINE_CPU\
  95. (void) cpu_set_time_base
  96. (cpu *processor,
  97. int64_t time_base);
  98. INLINE_CPU\
  99. (int32_t) cpu_get_decrementer
  100. (cpu *processor);
  101. INLINE_CPU\
  102. (void) cpu_set_decrementer
  103. (cpu *processor,
  104. int32_t decrementer);
  105. #if WITH_IDECODE_CACHE_SIZE
  106. /* Return the cache entry that matches the given CIA. No guarentee
  107. that the cache entry actually contains the instruction for that
  108. address */
  109. INLINE_CPU\
  110. (idecode_cache) *cpu_icache_entry
  111. (cpu *processor,
  112. unsigned_word cia);
  113. INLINE_CPU\
  114. (void) cpu_flush_icache
  115. (cpu *processor);
  116. #endif
  117. /* reveal the processors VM:
  118. At first sight it may seem better to, instead of exposing the cpu's
  119. inner vm maps, to have the cpu its self provide memory manipulation
  120. functions. (eg cpu_instruction_fetch() cpu_data_read_4())
  121. Unfortunatly in addition to these functions is the need (for the
  122. debugger) to be able to read/write to memory in ways that violate
  123. the vm protection (eg store breakpoint instruction in the
  124. instruction map). */
  125. INLINE_CPU\
  126. (vm_data_map *) cpu_data_map
  127. (cpu *processor);
  128. INLINE_CPU\
  129. (vm_instruction_map *) cpu_instruction_map
  130. (cpu *processor);
  131. INLINE_CPU\
  132. (void) cpu_page_tlb_invalidate_entry
  133. (cpu *processor,
  134. unsigned_word ea);
  135. INLINE_CPU\
  136. (void) cpu_page_tlb_invalidate_all
  137. (cpu *processor);
  138. /* reveal the processors interrupt state */
  139. INLINE_CPU\
  140. (interrupts *) cpu_interrupts
  141. (cpu *processor);
  142. /* grant access to the reservation information */
  143. typedef struct _memory_reservation {
  144. int valid;
  145. unsigned_word addr;
  146. unsigned_word data;
  147. } memory_reservation;
  148. INLINE_CPU\
  149. (memory_reservation *) cpu_reservation
  150. (cpu *processor);
  151. /* Registers:
  152. This model exploits the PowerPC's requirement for a synchronization
  153. to occure after (or before) the update of any context controlling
  154. register. All context sync points must call the sync function
  155. below to when ever a synchronization point is reached */
  156. INLINE_CPU\
  157. (registers *) cpu_registers
  158. (cpu *processor) CONST_ATTRIBUTE;
  159. INLINE_CPU\
  160. (void) cpu_synchronize_context
  161. (cpu *processor,
  162. unsigned_word cia);
  163. #define IS_PROBLEM_STATE(PROCESSOR) \
  164. (CURRENT_ENVIRONMENT == OPERATING_ENVIRONMENT \
  165. ? (cpu_registers(PROCESSOR)->msr & msr_problem_state) \
  166. : 1)
  167. #define IS_64BIT_MODE(PROCESSOR) \
  168. (WITH_TARGET_WORD_BITSIZE == 64 \
  169. ? (CURRENT_ENVIRONMENT == OPERATING_ENVIRONMENT \
  170. ? (cpu_registers(PROCESSOR)->msr & msr_64bit_mode) \
  171. : 1) \
  172. : 0)
  173. #define IS_FP_AVAILABLE(PROCESSOR) \
  174. (CURRENT_ENVIRONMENT == OPERATING_ENVIRONMENT \
  175. ? (cpu_registers(PROCESSOR)->msr & msr_floating_point_available) \
  176. : 1)
  177. INLINE_CPU\
  178. (void) cpu_print_info
  179. (cpu *processor,
  180. int verbose);
  181. INLINE_CPU\
  182. (model_data *) cpu_model
  183. (cpu *processor) CONST_ATTRIBUTE;
  184. #if (CPU_INLINE & INCLUDE_MODULE)
  185. # include "cpu.c"
  186. #endif
  187. #endif