sim_def.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512
  1. // Copyright 2010 Tilera Corporation. All Rights Reserved.
  2. //
  3. // This program is free software; you can redistribute it and/or
  4. // modify it under the terms of the GNU General Public License
  5. // as published by the Free Software Foundation, version 2.
  6. //
  7. // This program is distributed in the hope that it will be useful, but
  8. // WITHOUT ANY WARRANTY; without even the implied warranty of
  9. // MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  10. // NON INFRINGEMENT. See the GNU General Public License for
  11. // more details.
  12. //! @file
  13. //!
  14. //! Some low-level simulator definitions.
  15. //!
  16. #ifndef __ARCH_SIM_DEF_H__
  17. #define __ARCH_SIM_DEF_H__
  18. //! Internal: the low bits of the SIM_CONTROL_* SPR values specify
  19. //! the operation to perform, and the remaining bits are
  20. //! an operation-specific parameter (often unused).
  21. //!
  22. #define _SIM_CONTROL_OPERATOR_BITS 8
  23. //== Values which can be written to SPR_SIM_CONTROL.
  24. //! If written to SPR_SIM_CONTROL, stops profiling.
  25. //!
  26. #define SIM_CONTROL_PROFILER_DISABLE 0
  27. //! If written to SPR_SIM_CONTROL, starts profiling.
  28. //!
  29. #define SIM_CONTROL_PROFILER_ENABLE 1
  30. //! If written to SPR_SIM_CONTROL, clears profiling counters.
  31. //!
  32. #define SIM_CONTROL_PROFILER_CLEAR 2
  33. //! If written to SPR_SIM_CONTROL, checkpoints the simulator.
  34. //!
  35. #define SIM_CONTROL_CHECKPOINT 3
  36. //! If written to SPR_SIM_CONTROL, combined with a mask (shifted by 8),
  37. //! sets the tracing mask to the given mask. See "sim_set_tracing()".
  38. //!
  39. #define SIM_CONTROL_SET_TRACING 4
  40. //! If written to SPR_SIM_CONTROL, combined with a mask (shifted by 8),
  41. //! dumps the requested items of machine state to the log.
  42. //!
  43. #define SIM_CONTROL_DUMP 5
  44. //! If written to SPR_SIM_CONTROL, clears chip-level profiling counters.
  45. //!
  46. #define SIM_CONTROL_PROFILER_CHIP_CLEAR 6
  47. //! If written to SPR_SIM_CONTROL, disables chip-level profiling.
  48. //!
  49. #define SIM_CONTROL_PROFILER_CHIP_DISABLE 7
  50. //! If written to SPR_SIM_CONTROL, enables chip-level profiling.
  51. //!
  52. #define SIM_CONTROL_PROFILER_CHIP_ENABLE 8
  53. //! If written to SPR_SIM_CONTROL, enables chip-level functional mode
  54. //!
  55. #define SIM_CONTROL_ENABLE_FUNCTIONAL 9
  56. //! If written to SPR_SIM_CONTROL, disables chip-level functional mode.
  57. //!
  58. #define SIM_CONTROL_DISABLE_FUNCTIONAL 10
  59. //! If written to SPR_SIM_CONTROL, enables chip-level functional mode.
  60. //! All tiles must perform this write for functional mode to be enabled.
  61. //! Ignored in naked boot mode unless --functional is specified.
  62. //! WARNING: Only the hypervisor startup code should use this!
  63. //!
  64. #define SIM_CONTROL_ENABLE_FUNCTIONAL_BARRIER 11
  65. //! If written to SPR_SIM_CONTROL, combined with a character (shifted by 8),
  66. //! writes a string directly to the simulator output. Written to once for
  67. //! each character in the string, plus a final NUL. Instead of NUL,
  68. //! you can also use "SIM_PUTC_FLUSH_STRING" or "SIM_PUTC_FLUSH_BINARY".
  69. //!
  70. // ISSUE: Document the meaning of "newline", and the handling of NUL.
  71. //
  72. #define SIM_CONTROL_PUTC 12
  73. //! If written to SPR_SIM_CONTROL, clears the --grind-coherence state for
  74. //! this core. This is intended to be used before a loop that will
  75. //! invalidate the cache by loading new data and evicting all current data.
  76. //! Generally speaking, this API should only be used by system code.
  77. //!
  78. #define SIM_CONTROL_GRINDER_CLEAR 13
  79. //! If written to SPR_SIM_CONTROL, shuts down the simulator.
  80. //!
  81. #define SIM_CONTROL_SHUTDOWN 14
  82. //! If written to SPR_SIM_CONTROL, combined with a pid (shifted by 8),
  83. //! indicates that a fork syscall just created the given process.
  84. //!
  85. #define SIM_CONTROL_OS_FORK 15
  86. //! If written to SPR_SIM_CONTROL, combined with a pid (shifted by 8),
  87. //! indicates that an exit syscall was just executed by the given process.
  88. //!
  89. #define SIM_CONTROL_OS_EXIT 16
  90. //! If written to SPR_SIM_CONTROL, combined with a pid (shifted by 8),
  91. //! indicates that the OS just switched to the given process.
  92. //!
  93. #define SIM_CONTROL_OS_SWITCH 17
  94. //! If written to SPR_SIM_CONTROL, combined with a character (shifted by 8),
  95. //! indicates that an exec syscall was just executed. Written to once for
  96. //! each character in the executable name, plus a final NUL.
  97. //!
  98. #define SIM_CONTROL_OS_EXEC 18
  99. //! If written to SPR_SIM_CONTROL, combined with a character (shifted by 8),
  100. //! indicates that an interpreter (PT_INTERP) was loaded. Written to once
  101. //! for each character in "ADDR:PATH", plus a final NUL, where "ADDR" is a
  102. //! hex load address starting with "0x", and "PATH" is the executable name.
  103. //!
  104. #define SIM_CONTROL_OS_INTERP 19
  105. //! If written to SPR_SIM_CONTROL, combined with a character (shifted by 8),
  106. //! indicates that a dll was loaded. Written to once for each character
  107. //! in "ADDR:PATH", plus a final NUL, where "ADDR" is a hexadecimal load
  108. //! address starting with "0x", and "PATH" is the executable name.
  109. //!
  110. #define SIM_CONTROL_DLOPEN 20
  111. //! If written to SPR_SIM_CONTROL, combined with a character (shifted by 8),
  112. //! indicates that a dll was unloaded. Written to once for each character
  113. //! in "ADDR", plus a final NUL, where "ADDR" is a hexadecimal load
  114. //! address starting with "0x".
  115. //!
  116. #define SIM_CONTROL_DLCLOSE 21
  117. //! If written to SPR_SIM_CONTROL, combined with a flag (shifted by 8),
  118. //! indicates whether to allow data reads to remotely-cached
  119. //! dirty cache lines to be cached locally without grinder warnings or
  120. //! assertions (used by Linux kernel fast memcpy).
  121. //!
  122. #define SIM_CONTROL_ALLOW_MULTIPLE_CACHING 22
  123. //! If written to SPR_SIM_CONTROL, enables memory tracing.
  124. //!
  125. #define SIM_CONTROL_ENABLE_MEM_LOGGING 23
  126. //! If written to SPR_SIM_CONTROL, disables memory tracing.
  127. //!
  128. #define SIM_CONTROL_DISABLE_MEM_LOGGING 24
  129. //! If written to SPR_SIM_CONTROL, changes the shaping parameters of one of
  130. //! the gbe or xgbe shims. Must specify the shim id, the type, the units, and
  131. //! the rate, as defined in SIM_SHAPING_SPR_ARG.
  132. //!
  133. #define SIM_CONTROL_SHAPING 25
  134. //! If written to SPR_SIM_CONTROL, combined with character (shifted by 8),
  135. //! requests that a simulator command be executed. Written to once for each
  136. //! character in the command, plus a final NUL.
  137. //!
  138. #define SIM_CONTROL_COMMAND 26
  139. //! If written to SPR_SIM_CONTROL, indicates that the simulated system
  140. //! is panicking, to allow debugging via --debug-on-panic.
  141. //!
  142. #define SIM_CONTROL_PANIC 27
  143. //! If written to SPR_SIM_CONTROL, triggers a simulator syscall.
  144. //! See "sim_syscall()" for more info.
  145. //!
  146. #define SIM_CONTROL_SYSCALL 32
  147. //! If written to SPR_SIM_CONTROL, combined with a pid (shifted by 8),
  148. //! provides the pid that subsequent SIM_CONTROL_OS_FORK writes should
  149. //! use as the pid, rather than the default previous SIM_CONTROL_OS_SWITCH.
  150. //!
  151. #define SIM_CONTROL_OS_FORK_PARENT 33
  152. //! If written to SPR_SIM_CONTROL, combined with a mPIPE shim number
  153. //! (shifted by 8), clears the pending magic data section. The cleared
  154. //! pending magic data section and any subsequently appended magic bytes
  155. //! will only take effect when the classifier blast programmer is run.
  156. #define SIM_CONTROL_CLEAR_MPIPE_MAGIC_BYTES 34
  157. //! If written to SPR_SIM_CONTROL, combined with a mPIPE shim number
  158. //! (shifted by 8) and a byte of data (shifted by 16), appends that byte
  159. //! to the shim's pending magic data section. The pending magic data
  160. //! section takes effect when the classifier blast programmer is run.
  161. #define SIM_CONTROL_APPEND_MPIPE_MAGIC_BYTE 35
  162. //! If written to SPR_SIM_CONTROL, combined with a mPIPE shim number
  163. //! (shifted by 8), an enable=1/disable=0 bit (shifted by 16), and a
  164. //! mask of links (shifted by 32), enable or disable the corresponding
  165. //! mPIPE links.
  166. #define SIM_CONTROL_ENABLE_MPIPE_LINK_MAGIC_BYTE 36
  167. //== Syscall numbers for use with "sim_syscall()".
  168. //! Syscall number for sim_add_watchpoint().
  169. //!
  170. #define SIM_SYSCALL_ADD_WATCHPOINT 2
  171. //! Syscall number for sim_remove_watchpoint().
  172. //!
  173. #define SIM_SYSCALL_REMOVE_WATCHPOINT 3
  174. //! Syscall number for sim_query_watchpoint().
  175. //!
  176. #define SIM_SYSCALL_QUERY_WATCHPOINT 4
  177. //! Syscall number that asserts that the cache lines whose 64-bit PA
  178. //! is passed as the second argument to sim_syscall(), and over a
  179. //! range passed as the third argument, are no longer in cache.
  180. //! The simulator raises an error if this is not the case.
  181. //!
  182. #define SIM_SYSCALL_VALIDATE_LINES_EVICTED 5
  183. //== Bit masks which can be shifted by 8, combined with
  184. //== SIM_CONTROL_SET_TRACING, and written to SPR_SIM_CONTROL.
  185. //! @addtogroup arch_sim
  186. //! @{
  187. //! Enable --trace-cycle when passed to simulator_set_tracing().
  188. //!
  189. #define SIM_TRACE_CYCLES 0x01
  190. //! Enable --trace-router when passed to simulator_set_tracing().
  191. //!
  192. #define SIM_TRACE_ROUTER 0x02
  193. //! Enable --trace-register-writes when passed to simulator_set_tracing().
  194. //!
  195. #define SIM_TRACE_REGISTER_WRITES 0x04
  196. //! Enable --trace-disasm when passed to simulator_set_tracing().
  197. //!
  198. #define SIM_TRACE_DISASM 0x08
  199. //! Enable --trace-stall-info when passed to simulator_set_tracing().
  200. //!
  201. #define SIM_TRACE_STALL_INFO 0x10
  202. //! Enable --trace-memory-controller when passed to simulator_set_tracing().
  203. //!
  204. #define SIM_TRACE_MEMORY_CONTROLLER 0x20
  205. //! Enable --trace-l2 when passed to simulator_set_tracing().
  206. //!
  207. #define SIM_TRACE_L2_CACHE 0x40
  208. //! Enable --trace-lines when passed to simulator_set_tracing().
  209. //!
  210. #define SIM_TRACE_LINES 0x80
  211. //! Turn off all tracing when passed to simulator_set_tracing().
  212. //!
  213. #define SIM_TRACE_NONE 0
  214. //! Turn on all tracing when passed to simulator_set_tracing().
  215. //!
  216. #define SIM_TRACE_ALL (-1)
  217. //! @}
  218. //! Computes the value to write to SPR_SIM_CONTROL to set tracing flags.
  219. //!
  220. #define SIM_TRACE_SPR_ARG(mask) \
  221. (SIM_CONTROL_SET_TRACING | ((mask) << _SIM_CONTROL_OPERATOR_BITS))
  222. //== Bit masks which can be shifted by 8, combined with
  223. //== SIM_CONTROL_DUMP, and written to SPR_SIM_CONTROL.
  224. //! @addtogroup arch_sim
  225. //! @{
  226. //! Dump the general-purpose registers.
  227. //!
  228. #define SIM_DUMP_REGS 0x001
  229. //! Dump the SPRs.
  230. //!
  231. #define SIM_DUMP_SPRS 0x002
  232. //! Dump the ITLB.
  233. //!
  234. #define SIM_DUMP_ITLB 0x004
  235. //! Dump the DTLB.
  236. //!
  237. #define SIM_DUMP_DTLB 0x008
  238. //! Dump the L1 I-cache.
  239. //!
  240. #define SIM_DUMP_L1I 0x010
  241. //! Dump the L1 D-cache.
  242. //!
  243. #define SIM_DUMP_L1D 0x020
  244. //! Dump the L2 cache.
  245. //!
  246. #define SIM_DUMP_L2 0x040
  247. //! Dump the switch registers.
  248. //!
  249. #define SIM_DUMP_SNREGS 0x080
  250. //! Dump the switch ITLB.
  251. //!
  252. #define SIM_DUMP_SNITLB 0x100
  253. //! Dump the switch L1 I-cache.
  254. //!
  255. #define SIM_DUMP_SNL1I 0x200
  256. //! Dump the current backtrace.
  257. //!
  258. #define SIM_DUMP_BACKTRACE 0x400
  259. //! Only dump valid lines in caches.
  260. //!
  261. #define SIM_DUMP_VALID_LINES 0x800
  262. //! Dump everything that is dumpable.
  263. //!
  264. #define SIM_DUMP_ALL (-1 & ~SIM_DUMP_VALID_LINES)
  265. // @}
  266. //! Computes the value to write to SPR_SIM_CONTROL to dump machine state.
  267. //!
  268. #define SIM_DUMP_SPR_ARG(mask) \
  269. (SIM_CONTROL_DUMP | ((mask) << _SIM_CONTROL_OPERATOR_BITS))
  270. //== Bit masks which can be shifted by 8, combined with
  271. //== SIM_CONTROL_PROFILER_CHIP_xxx, and written to SPR_SIM_CONTROL.
  272. //! @addtogroup arch_sim
  273. //! @{
  274. //! Use with with SIM_PROFILER_CHIP_xxx to control the memory controllers.
  275. //!
  276. #define SIM_CHIP_MEMCTL 0x001
  277. //! Use with with SIM_PROFILER_CHIP_xxx to control the XAUI interface.
  278. //!
  279. #define SIM_CHIP_XAUI 0x002
  280. //! Use with with SIM_PROFILER_CHIP_xxx to control the PCIe interface.
  281. //!
  282. #define SIM_CHIP_PCIE 0x004
  283. //! Use with with SIM_PROFILER_CHIP_xxx to control the MPIPE interface.
  284. //!
  285. #define SIM_CHIP_MPIPE 0x008
  286. //! Reference all chip devices.
  287. //!
  288. #define SIM_CHIP_ALL (-1)
  289. //! @}
  290. //! Computes the value to write to SPR_SIM_CONTROL to clear chip statistics.
  291. //!
  292. #define SIM_PROFILER_CHIP_CLEAR_SPR_ARG(mask) \
  293. (SIM_CONTROL_PROFILER_CHIP_CLEAR | ((mask) << _SIM_CONTROL_OPERATOR_BITS))
  294. //! Computes the value to write to SPR_SIM_CONTROL to disable chip statistics.
  295. //!
  296. #define SIM_PROFILER_CHIP_DISABLE_SPR_ARG(mask) \
  297. (SIM_CONTROL_PROFILER_CHIP_DISABLE | ((mask) << _SIM_CONTROL_OPERATOR_BITS))
  298. //! Computes the value to write to SPR_SIM_CONTROL to enable chip statistics.
  299. //!
  300. #define SIM_PROFILER_CHIP_ENABLE_SPR_ARG(mask) \
  301. (SIM_CONTROL_PROFILER_CHIP_ENABLE | ((mask) << _SIM_CONTROL_OPERATOR_BITS))
  302. // Shim bitrate controls.
  303. //! The number of bits used to store the shim id.
  304. //!
  305. #define SIM_CONTROL_SHAPING_SHIM_ID_BITS 3
  306. //! @addtogroup arch_sim
  307. //! @{
  308. //! Change the gbe 0 bitrate.
  309. //!
  310. #define SIM_CONTROL_SHAPING_GBE_0 0x0
  311. //! Change the gbe 1 bitrate.
  312. //!
  313. #define SIM_CONTROL_SHAPING_GBE_1 0x1
  314. //! Change the gbe 2 bitrate.
  315. //!
  316. #define SIM_CONTROL_SHAPING_GBE_2 0x2
  317. //! Change the gbe 3 bitrate.
  318. //!
  319. #define SIM_CONTROL_SHAPING_GBE_3 0x3
  320. //! Change the xgbe 0 bitrate.
  321. //!
  322. #define SIM_CONTROL_SHAPING_XGBE_0 0x4
  323. //! Change the xgbe 1 bitrate.
  324. //!
  325. #define SIM_CONTROL_SHAPING_XGBE_1 0x5
  326. //! The type of shaping to do.
  327. //!
  328. #define SIM_CONTROL_SHAPING_TYPE_BITS 2
  329. //! Control the multiplier.
  330. //!
  331. #define SIM_CONTROL_SHAPING_MULTIPLIER 0
  332. //! Control the PPS.
  333. //!
  334. #define SIM_CONTROL_SHAPING_PPS 1
  335. //! Control the BPS.
  336. //!
  337. #define SIM_CONTROL_SHAPING_BPS 2
  338. //! The number of bits for the units for the shaping parameter.
  339. //!
  340. #define SIM_CONTROL_SHAPING_UNITS_BITS 2
  341. //! Provide a number in single units.
  342. //!
  343. #define SIM_CONTROL_SHAPING_UNITS_SINGLE 0
  344. //! Provide a number in kilo units.
  345. //!
  346. #define SIM_CONTROL_SHAPING_UNITS_KILO 1
  347. //! Provide a number in mega units.
  348. //!
  349. #define SIM_CONTROL_SHAPING_UNITS_MEGA 2
  350. //! Provide a number in giga units.
  351. //!
  352. #define SIM_CONTROL_SHAPING_UNITS_GIGA 3
  353. // @}
  354. //! How many bits are available for the rate.
  355. //!
  356. #define SIM_CONTROL_SHAPING_RATE_BITS \
  357. (32 - (_SIM_CONTROL_OPERATOR_BITS + \
  358. SIM_CONTROL_SHAPING_SHIM_ID_BITS + \
  359. SIM_CONTROL_SHAPING_TYPE_BITS + \
  360. SIM_CONTROL_SHAPING_UNITS_BITS))
  361. //! Computes the value to write to SPR_SIM_CONTROL to change a bitrate.
  362. //!
  363. #define SIM_SHAPING_SPR_ARG(shim, type, units, rate) \
  364. (SIM_CONTROL_SHAPING | \
  365. ((shim) | \
  366. ((type) << (SIM_CONTROL_SHAPING_SHIM_ID_BITS)) | \
  367. ((units) << (SIM_CONTROL_SHAPING_SHIM_ID_BITS + \
  368. SIM_CONTROL_SHAPING_TYPE_BITS)) | \
  369. ((rate) << (SIM_CONTROL_SHAPING_SHIM_ID_BITS + \
  370. SIM_CONTROL_SHAPING_TYPE_BITS + \
  371. SIM_CONTROL_SHAPING_UNITS_BITS))) << _SIM_CONTROL_OPERATOR_BITS)
  372. //== Values returned when reading SPR_SIM_CONTROL.
  373. // ISSUE: These names should share a longer common prefix.
  374. //! When reading SPR_SIM_CONTROL, the mask of simulator tracing bits
  375. //! (SIM_TRACE_xxx values).
  376. //!
  377. #define SIM_TRACE_FLAG_MASK 0xFFFF
  378. //! When reading SPR_SIM_CONTROL, the mask for whether profiling is enabled.
  379. //!
  380. #define SIM_PROFILER_ENABLED_MASK 0x10000
  381. //== Special arguments for "SIM_CONTROL_PUTC".
  382. //! Flag value for forcing a PUTC string-flush, including
  383. //! coordinate/cycle prefix and newline.
  384. //!
  385. #define SIM_PUTC_FLUSH_STRING 0x100
  386. //! Flag value for forcing a PUTC binary-data-flush, which skips the
  387. //! prefix and does not append a newline.
  388. //!
  389. #define SIM_PUTC_FLUSH_BINARY 0x101
  390. #endif //__ARCH_SIM_DEF_H__