corefile.h 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  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 _CORE_H_
  15. #define _CORE_H_
  16. /* Introduction:
  17. The core device, positioned at the top of the device tree that
  18. models the architecure being simulated, acts as an interface
  19. between the processor engines and the modeled devices.
  20. On the one side the processor engines issue read and write requests
  21. to the core (each request further catagorised as being for an
  22. instruction or data subunit) while on the other side, the core is
  23. receiving address configuration and DMA requests from child
  24. devices.
  25. In the below a synopsis of the core object and device in PSIM is
  26. given, details of the object can be found in the files
  27. <<corefile.h>> and <<corefile.c>>.
  28. */
  29. /* Core::
  30. At the heart of the interface between devices and processor engines
  31. is a single core object. This object, in turn, has two children:
  32. o a core device which exists in the device tree and provides
  33. an interface to the core object to child devices.
  34. o a set of access maps which provide an efficient
  35. interface to the core object for the processor engines.
  36. */
  37. /* basic types */
  38. typedef struct _core core;
  39. typedef struct _core_map core_map;
  40. /* constructor */
  41. INLINE_CORE\
  42. (core *) core_create
  43. (void);
  44. INLINE_CORE\
  45. (core *) core_from_device
  46. (device *root);
  47. INLINE_CORE\
  48. (void) core_init
  49. (core *memory);
  50. /* Core map management:::
  51. The core ojbect manages two different types of address maps:
  52. o raw-memory - the address range can be implemented using
  53. a simple byte array. No device needs to be notifed of
  54. any accesses to the specified memory range.
  55. o callback - Any access to the specified address range
  56. should be passed on to the associated device. That device
  57. can in turn resolve the access - handling or aborting or
  58. restarting it.
  59. For callback maps it is possible to further order them by
  60. specifiying specifying a callback level (eg callback + 1).
  61. When the core is resolving an access it searches each of the maps
  62. in order. First raw-memory and then callback maps (in assending
  63. order of level). This search order makes it possible for latter
  64. maps to overlap earlier ones. For instance, a device that wants to
  65. be notified of all accesses that are not covered by raw-memory maps
  66. could attach its self with an address range of the entire address
  67. space.
  68. In addition, each attached address map as an associated set of
  69. access attributes (readable, writeable, executable) which are
  70. verified as part of resolving each access.
  71. */
  72. INLINE_CORE\
  73. (void) core_attach
  74. (core *map,
  75. attach_type attach,
  76. int address_space,
  77. access_type access,
  78. unsigned_word addr,
  79. unsigned nr_bytes, /* host limited */
  80. device *device); /*callback/default*/
  81. /* Bugs:::
  82. At present there is no method for removing address maps. That will
  83. be implemented in a future release.
  84. The operation of mapping between an address and its destination
  85. device or memory array is currently implemented using a simple
  86. linked list. The posibility of replacing this list with a more
  87. powerfull data structure exists.
  88. */
  89. /* Device::
  90. The device that corresponds to the core object is described
  91. separatly in the devices section.
  92. */
  93. /* Access maps::
  94. Providing an interface between the processor engines and the core
  95. object are the access maps (core_map). Three access maps are
  96. provided, one for each of the possible access requests that can be
  97. generated by a processor.
  98. o read
  99. o write
  100. o execute
  101. A processor being able to request a read (or write) or write
  102. operation to any of the maps. Those operations can either be
  103. highly efficient (by specifying a specific transfer size) or
  104. generic (specifying a parameterized number of bytes).
  105. Internally the core object takes the request, determines the
  106. approperiate attached address space that it should handle it passes
  107. it on.
  108. */
  109. INLINE_CORE\
  110. (core_map *) core_readable
  111. (core *memory);
  112. INLINE_CORE\
  113. (core_map *) core_writeable
  114. (core *memory);
  115. INLINE_CORE\
  116. (core_map *) core_executable
  117. (core *memory);
  118. /* Variable sized read/write
  119. Transfer (zero) a variable size block of data between the host and
  120. target (possibly byte swapping it). Should any problems occure,
  121. the number of bytes actually transfered is returned. */
  122. INLINE_CORE\
  123. (unsigned) core_map_read_buffer
  124. (core_map *map,
  125. void *buffer,
  126. unsigned_word addr,
  127. unsigned nr_bytes);
  128. INLINE_CORE\
  129. (unsigned) core_map_write_buffer
  130. (core_map *map,
  131. const void *buffer,
  132. unsigned_word addr,
  133. unsigned nr_bytes);
  134. /* Fixed sized read/write
  135. Transfer a fixed amout of memory between the host and target. The
  136. memory always being translated and the operation always aborting
  137. should a problem occure */
  138. #define DECLARE_CORE_WRITE_N(N) \
  139. INLINE_CORE\
  140. (void) core_map_write_##N \
  141. (core_map *map, \
  142. unsigned_word addr, \
  143. unsigned_##N val, \
  144. cpu *processor, \
  145. unsigned_word cia);
  146. DECLARE_CORE_WRITE_N(1)
  147. DECLARE_CORE_WRITE_N(2)
  148. DECLARE_CORE_WRITE_N(4)
  149. DECLARE_CORE_WRITE_N(8)
  150. DECLARE_CORE_WRITE_N(word)
  151. #define DECLARE_CORE_READ_N(N) \
  152. INLINE_CORE\
  153. (unsigned_##N) core_map_read_##N \
  154. (core_map *map, \
  155. unsigned_word addr, \
  156. cpu *processor, \
  157. unsigned_word cia);
  158. DECLARE_CORE_READ_N(1)
  159. DECLARE_CORE_READ_N(2)
  160. DECLARE_CORE_READ_N(4)
  161. DECLARE_CORE_READ_N(8)
  162. DECLARE_CORE_READ_N(word)
  163. #endif