sim_def.h 15 KB

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