trax.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. /* Header file for TRAX control Library */
  2. /*
  3. * Copyright (c) 2012-2013 Tensilica Inc.
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining
  6. * a copy of this software and associated documentation files (the
  7. * "Software"), to deal in the Software without restriction, including
  8. * without limitation the rights to use, copy, modify, merge, publish,
  9. * distribute, sublicense, and/or sell copies of the Software, and to
  10. * permit persons to whom the Software is furnished to do so, subject to
  11. * the following conditions:
  12. *
  13. * The above copyright notice and this permission notice shall be included
  14. * in all copies or substantial portions of the Software.
  15. *
  16. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  17. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  18. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  19. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
  20. * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  21. * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  22. * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  23. */
  24. #ifndef _TRAX_H
  25. #define _TRAX_H
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. #define TRAX_STOP_HALT 0x0001
  30. #define TRAX_STOP_QUIET 0x0002
  31. /* Flag values to indicate if the user wanted to reverse the pcstop
  32. * parameters */
  33. #define TRAX_PCSTOP_REVERSE 0x0001
  34. #define TRAX_PCSTOP_NO_REVERSE 0x0000
  35. /* Indicating whether postsize should be in terms of bytes, instructions
  36. * or percentage of trace size captured */
  37. #define TRAX_POSTSIZE_BYTES 0x0000
  38. #define TRAX_POSTSIZE_INSTR 0x0001
  39. #define TRAX_POSTSIZE_PERCENT 0x0002
  40. /* Size of the header inside the trace file */
  41. #define TRAX_HEADER_SIZE 256
  42. /* Minimum size between start and end addresses */
  43. #define TRAX_MIN_TRACEMEM 64
  44. /* For basic debugging */
  45. #define DEBUG 0
  46. #include <stdbool.h>
  47. #define ffs(i) __builtin_ffs(i)
  48. /* Data structures */
  49. /* Represents the context of the TRAX unit and the current TRAX session.
  50. * To be used by set and show function calls to set and show appropriate
  51. * parameters of appropriate TRAX unit.
  52. */
  53. typedef struct {
  54. int trax_version; /* TRAX PC version information */
  55. unsigned long trax_tram_size; /* If trace RAM is present,size of it */
  56. int hflags; /* Flags that can be used to debug,
  57. print info, etc. */
  58. int address_read_last; /* During saving of the trace, this
  59. indicates the address from which
  60. the current trace reading must
  61. resume */
  62. unsigned long bytes_read; /* bytes read uptil now */
  63. unsigned long total_memlen; /* Total bytes to be read based on the
  64. trace collected in the trace RAM */
  65. bool get_trace_started; /* indicates that the first chunk of
  66. bytes (which include the header) has
  67. been read */
  68. } trax_context;
  69. /* -----------------------TRAX Initialization ------------------------------*/
  70. /* Initializing the trax context. Reads registers and sets values for version,
  71. * trace RAM size, total memory length, etc. Most of the other values are
  72. * initialized to their default case.
  73. *
  74. * context : pointer to structure which contains information about the
  75. * current TRAX session
  76. *
  77. * returns : 0 if successful, -1 if unsuccessful, -2 if ram_size if
  78. * incorrect
  79. */
  80. int trax_context_init_eri (trax_context *context);
  81. /* -----------------Starting/Stopping TRAX session -------------------------*/
  82. /* Start tracing with current parameter setting. If tracing is already in
  83. * progress, an error is reported. Otherwise, tracing starts and any unsaved
  84. * contents of the TraceRAM is discarded
  85. *
  86. * context : pointer to structure which contains information about the
  87. * current TRAX session
  88. * returns : 0 if successful, 1 if trace is already active,
  89. * -1 if unsuccessful
  90. */
  91. int trax_start (trax_context *context);
  92. /* This command initiates a stop trigger or halts a trace session based of the
  93. * value of the flag parameter passed. In case stop trigger is initiated, any
  94. * selected post-stop-trigger capture proceeds normally.
  95. * If trace capture was not in progress, or a stop was already triggered, the
  96. * return value indicates appropriately.
  97. *
  98. * context : pointer to structure which contains information about the
  99. * current TRAX session
  100. * flags : To differentiate between stopping trace without any
  101. * post-size-trigger capture (trax_halt) or with that.
  102. * A zero value would stop the trace based on trigger and a
  103. * value of one would halt it
  104. *
  105. * returns : 0 if successful, 1 if already stopped, -1 if unsuccessful
  106. */
  107. int trax_stop_halt (trax_context *context, int flags);
  108. /* Resets the TRAX parameters to their default values which would internally
  109. * involve resetting the TRAX registers. To invoke another trace session or
  110. * reset the current tracing mechanism, this function needs to be called as
  111. * it resets parameters of the context that deal with tracing information
  112. *
  113. * context : pointer to structure which contains information about the
  114. * current TRAX session
  115. *
  116. * returns : 0 if successful, -1 if unsuccessful
  117. */
  118. int trax_reset (trax_context *context);
  119. /* ---------------Set/Get several TRAX parameters --------------------------*/
  120. /* Sets the start address and end address (word aligned) of the trace in the
  121. * TraceRAM. Care must be taken to ensure that the difference between the
  122. * start and the end addresses is atleast TRAX_MIN_TRACEMEM bytes. If not,
  123. * the values are reset to default, which is 0 for startaddr and
  124. * traceRAM_words -1 for endaddr
  125. *
  126. * context : pointer to structure which contains information about the
  127. * current TRAX session
  128. * startaddr : value to which the start address must be set. Can be
  129. * any value between 0 - (traceRAM_words - 1)
  130. * endaddr : value to which the end address must be set. Can be any value
  131. * between 0 - (traceRAM_words - 1)
  132. *
  133. * returns : 0 if successful, -1 if unsuccessful, -2 if the difference
  134. * between the start and end addresses is less than
  135. * TRAX_MIN_TRACEMEM bytes or if they are passed incorrect
  136. * values, -3 if memory shared option is not configured, in
  137. * which case, start and end addresses are set to default
  138. * values instead of those passed by the user
  139. */
  140. int trax_set_ram_boundaries (trax_context *context, unsigned startaddr,
  141. unsigned endaddr);
  142. /* Shows the start address and end address(word aligned) of the trace in the
  143. * TraceRAM. If incorrect, the startaddress and the endaddress values are
  144. * set to default, i.e. 0 for startaddr and traceRAM_words - 1 for endaddr
  145. *
  146. * context : pointer to structure which contains information about the
  147. * current TRAX session
  148. * startaddr : pointer to value which will contain the start address
  149. * endaddr : pointer to value which will contain the end address
  150. *
  151. * returns : 0 if successful, -1 if unsuccessful
  152. *
  153. */
  154. int trax_get_ram_boundaries (trax_context *context, unsigned *startaddr,
  155. unsigned *endaddr);
  156. /* Selects stop trigger via cross-trigger input
  157. *
  158. * context : pointer to structure which contains information about the
  159. * current TRAX session
  160. * value : 0 = off (reset value), 1 = on
  161. *
  162. * returns : 0 if successful, -1 if unsuccessful
  163. */
  164. int trax_set_ctistop (trax_context *context, unsigned value);
  165. /* Shows if stop-trigger via cross-trigger input is off or on
  166. *
  167. * context : pointer to structure which contains information about the
  168. * current TRAX session
  169. * returns : 0 if off, 1 if on, -1 if unsuccessful
  170. */
  171. int trax_get_ctistop (trax_context *context);
  172. /* Selects stop trigger via processor-trigger input
  173. *
  174. * context : pointer to structure which contains information about the
  175. * current TRAX session
  176. * value : 0 = off (reset value), 1 = on
  177. *
  178. * returns : 0 if successful, -1 if unsuccessful
  179. */
  180. int trax_set_ptistop (trax_context *context, unsigned value);
  181. /* Shows if stop trigger visa processor-trigger input is off or on
  182. *
  183. * context : pointer to structure which contains information about the
  184. * current TRAX session
  185. * returns : 0 if off, 1 if on, -1 if unsuccessful
  186. */
  187. int trax_get_ptistop (trax_context *context);
  188. /* Reports cross trigger output state
  189. *
  190. * context : pointer to structure which contains information about the
  191. * current TRAX session
  192. * returns : 0 if CTO bit is reset, 1 if CTO bit is set
  193. */
  194. int trax_get_cto (trax_context *context);
  195. /* Reports processor trigger output state
  196. *
  197. * context : pointer to structure which contains information about the
  198. * current TRAX session
  199. * returns : 0 if PTO bit is reset, 1 if PTO bit is set
  200. */
  201. int trax_get_pto (trax_context *context);
  202. /* Selects condition that asserts cross trigger output
  203. *
  204. * context : pointer to structure which contains information about the
  205. * current TRAX session
  206. * option : 0 = off(reset value)/1 = ontrig/2 = onhalt
  207. *
  208. * returns : 0 if successful, -1 if unsuccessful
  209. */
  210. int trax_set_ctowhen (trax_context *context, int option);
  211. /* Shows condition that asserted cross trigger output. It can be
  212. * any of: ontrig or onhalt or even off
  213. *
  214. * context : pointer to structure which contains information about the
  215. * current TRAX session
  216. *
  217. * returns : 0 if off, 1 if ontrig, 2 if onhalt, -1 if unsuccessful
  218. */
  219. int trax_get_ctowhen (trax_context *context);
  220. /* Selects condition that asserts processor trigger output
  221. *
  222. * context : pointer to structure which contains information about the
  223. * current TRAX session
  224. * option : 0 = off(reset value)/1 = ontrig/2 = onhalt
  225. *
  226. * returns : 0 if successful, -1 if unsuccessful
  227. */
  228. int trax_set_ptowhen (trax_context *context, int option);
  229. /* Shows condition that asserted processor trigger output. It can be
  230. * any of: ontrig or onhalt or even off
  231. *
  232. * context : pointer to structure which contains information about the
  233. * current TRAX session
  234. * returns : 0 if off, 1 if ontrig, 2 if onhalt, -1 if unsuccessful
  235. */
  236. int trax_get_ptowhen (trax_context *context);
  237. /* Selects the trace synchronization message period.
  238. * If ATEN enabled, we cannot allow syncper to be off, set it to reset value.
  239. * Also, if no trace RAM, and ATEN enabled, set syncper to be reset value
  240. * i.e. 256. A value of 1 i.e. on indicates that internally the message
  241. * frequency is set to an optimal value. This option should be preferred
  242. * if the user is not sure what message frequency option to set for the
  243. * trace session.
  244. *
  245. * context : pointer to structure which contains information about the
  246. * current TRAX session
  247. * option : 0 = off, 1 = on, -1 = auto, 8, 16, 32, 64, 128,
  248. * 256 (reset value)
  249. *
  250. * returns : 0 if successful, -1 if unsuccessful, -2 if incorrect
  251. * arguments
  252. */
  253. int trax_set_syncper (trax_context *context, int option);
  254. /* Shows trace synchronization message period. Can be one of:
  255. * off, on, auto, 8, 16, 32, 64, 128, 256 (reset value)
  256. *
  257. * context : pointer to structure which contains information about the
  258. * current TRAX session
  259. * returns : value of sync period, 0 if off, -1 if unsuccessful
  260. */
  261. int trax_get_syncper (trax_context *context);
  262. /* Selects stop trigger via PC match. Specifies the address or
  263. * address range to match against program counter. Trace stops when the
  264. * processor executes an instruction matching the specified address
  265. * or range.
  266. *
  267. * context : pointer to structure which contains information about the
  268. * current TRAX session
  269. * index : indicates the number of stop trigger (currently there is
  270. * only one i.e. index = 0)
  271. * startaddress : start range of the address at which the stop trigger
  272. * should be activated
  273. * enaddress : end range of the address at which the stop trigger should
  274. * be activated
  275. * flags : If non-zero, this inverts the range. i.e. trace stops
  276. * when the processor executes an instruction that does not
  277. * match the specified address or range
  278. *
  279. * returns : 0 if successful, -1 if unsuccessful, -2 if incorrect
  280. * arguments (unaligned)
  281. *
  282. * Note : For the current version of TRAX library, the endaddress and
  283. * startaddress can differ by at most 31 bytes and the total
  284. * range i.e. (endaddress - startaddress + 1) has to be a power
  285. * of two
  286. */
  287. int trax_set_pcstop (trax_context *context, int index, unsigned long startaddress,
  288. unsigned long endaddress, int flags);
  289. /* Shows the stop trigger via PC match
  290. *
  291. * context : pointer to structure which contains information about the
  292. * current TRAX session
  293. * index : container of information about the number of stop triggers
  294. * startaddress : container of start range of stop trigger
  295. * endaddress : container of end range of stop trigger
  296. * flags : container of information whcih indicates whether the
  297. * pc stop range is inverted or not.
  298. *
  299. * returns : 0 if successful, -1 if unsuccessful
  300. */
  301. int trax_get_pcstop (trax_context *context, int *index,
  302. unsigned long *startaddress,
  303. unsigned long *endaddress, int *flags);
  304. /* This function is used to set the amount of trace to be captured past
  305. * the stop trigger.
  306. *
  307. * context : pointer to structure which contains information about the
  308. * current TRAX session
  309. * count_unit : contains the count of units (instructions or bytes) to be
  310. * captured post trigger. If 0, it implies that this is off
  311. * unit : unit of measuring the count. 0 is bytes, 1 is instructions
  312. * 2 is percentage of trace
  313. *
  314. * returns : 0 if successful, -1 if unsuccessful, -2 if incorrect
  315. * arguments
  316. *
  317. */
  318. int trax_set_postsize (trax_context *context, int count_unit, int unit);
  319. /* This function shows the amount of TraceRAM in terms of the number of
  320. * instructions or bytes, captured post the stop trigger
  321. *
  322. * context : pointer to structure which contains information about the
  323. * current TRAX session
  324. * count_unit : will contain the count of units(instructions or bytes) post
  325. * trigger
  326. * unit : will contain information about the events that are counted
  327. * 0 implies that the traceRAM words consumed are counted and
  328. * 1 implies that the target processor instructions executed and
  329. * excpetions/interrupts taken are counted
  330. *
  331. * returns : 0 if postsize was got successfully, -1 if unsuccessful
  332. */
  333. int trax_get_postsize (trax_context *context, int *count_unit, int *unit);
  334. /* -------------------------- TRAX save routines ---------------------------*/
  335. /* This function should be called by the user to return a chunk of
  336. * bytes in buf. It can be a lower layer function of save, or can be
  337. * called by the user explicitly. If bytes_actually_read contains a 0
  338. * after a call to this function has been made, it implies that the entire
  339. * trace has been read successfully.
  340. *
  341. * context : pointer to structure which contains information about
  342. * the current TRAX session
  343. * buf : Buffer that is allocated by the user, all the trace
  344. * data read would be put in this buffer, which can then
  345. * be used to generate a tracefile.
  346. * The first TRAX_HEADER_SIZE of the buffer will always
  347. * contain the header information.
  348. * bytes_to_be_read : Indicates the bytes the user wants to read. The first
  349. * invocation would need this parameter to be
  350. * TRAX_HEADER_SIZE at least.
  351. *
  352. * returns : bytes actually read during the call to this function.
  353. * 0 implies that all the bytes in the trace have been
  354. * read, -1 if unsuccessful read/write of
  355. * registers or memory, -2 if trace was active while
  356. * this function was called, -3 if user enters
  357. * bytes_to_be_read < TRAX_HEADER_SIZE in the first
  358. * pass
  359. */
  360. int trax_get_trace (trax_context *context, void *buf,
  361. int bytes_to_be_read);
  362. #ifdef __cplusplus
  363. }
  364. #endif
  365. #endif /* _TRAX_H */