c3cc6e9918b0bd628f2402dc945662b4de169abc
[fw/openocd] / src / target / esirisc_trace.h
1 /***************************************************************************
2  *   Copyright (C) 2018 by Square, Inc.                                    *
3  *   Steven Stallion <stallion@squareup.com>                               *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) any later version.                                   *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
17  ***************************************************************************/
18
19 #ifndef OPENOCD_TARGET_ESIRISC_TRACE_H
20 #define OPENOCD_TARGET_ESIRISC_TRACE_H
21
22 #include <helper/command.h>
23 #include <helper/types.h>
24 #include <target/target.h>
25
26 enum esirisc_trace_delay {
27         ESIRISC_TRACE_DELAY_NONE,
28         ESIRISC_TRACE_DELAY_START,
29         ESIRISC_TRACE_DELAY_STOP,
30         ESIRISC_TRACE_DELAY_BOTH,
31 };
32
33 enum esirisc_trace_format {
34         ESIRISC_TRACE_FORMAT_FULL,
35         ESIRISC_TRACE_FORMAT_BRANCH,
36         ESIRISC_TRACE_FORMAT_ICACHE,
37 };
38
39 enum esirisc_trace_id {
40         ESIRISC_TRACE_ID_EXECUTE,
41         ESIRISC_TRACE_ID_STALL,
42         ESIRISC_TRACE_ID_BRANCH,
43         ESIRISC_TRACE_ID_EXTENDED,
44 };
45
46 enum esirisc_trace_ext_id {
47         ESIRISC_TRACE_EXT_ID_EXCEPTION = 1,
48         ESIRISC_TRACE_EXT_ID_ERET,
49         ESIRISC_TRACE_EXT_ID_STOP,
50         ESIRISC_TRACE_EXT_ID_WAIT,
51         ESIRISC_TRACE_EXT_ID_MULTICYCLE,
52         ESIRISC_TRACE_EXT_ID_COUNT,
53         ESIRISC_TRACE_EXT_ID_PC,
54         ESIRISC_TRACE_EXT_ID_INDIRECT,
55         ESIRISC_TRACE_EXT_ID_END,
56         ESIRISC_TRACE_EXT_ID_END_PC,
57 };
58
59 enum esirisc_trace_trigger {
60         ESIRISC_TRACE_TRIGGER_NONE,
61         ESIRISC_TRACE_TRIGGER_PC,
62         ESIRISC_TRACE_TRIGGER_LOAD,
63         ESIRISC_TRACE_TRIGGER_STORE,
64         ESIRISC_TRACE_TRIGGER_EXCEPTION,
65         ESIRISC_TRACE_TRIGGER_ERET,
66         ESIRISC_TRACE_TRIGGER_WAIT,
67         ESIRISC_TRACE_TRIGGER_STOP,
68         ESIRISC_TRACE_TRIGGER_HIGH,
69         ESIRISC_TRACE_TRIGGER_LOW,
70 };
71
72 struct esirisc_trace {
73         target_addr_t buffer_start;
74         target_addr_t buffer_end;
75         bool buffer_wrap;
76         bool flow_control;
77
78         enum esirisc_trace_format format;
79         int pc_bits;
80
81         enum esirisc_trace_trigger start_trigger;
82         uint32_t start_data;
83         uint32_t start_mask;
84
85         enum esirisc_trace_trigger stop_trigger;
86         uint32_t stop_data;
87         uint32_t stop_mask;
88
89         enum esirisc_trace_delay delay;
90         uint32_t delay_cycles;
91 };
92
93 extern const struct command_registration esirisc_trace_command_handlers[];
94
95 static inline uint32_t esirisc_trace_buffer_size(struct esirisc_trace *trace_info)
96 {
97         return trace_info->buffer_end - trace_info->buffer_start;
98 }
99
100 static inline bool esirisc_trace_is_fifo(struct esirisc_trace *trace_info)
101 {
102         return trace_info->buffer_start == trace_info->buffer_end;
103 }
104
105 #endif /* OPENOCD_TARGET_ESIRISC_TRACE_H */