21 #ifndef BM_BM_SIM_DEBUGGER_H_
22 #define BM_BM_SIM_DEBUGGER_H_
24 #include <bm/config.h>
32 using device_id_t = uint64_t;
33 using s_device_id_t = device_id_t;
42 #define DBG_CTR_PARSER (1 << 24)
43 #define DBG_CTR_PARSE_STATE (2 << 24)
44 #define DBG_CTR_CONTROL (3 << 24)
45 #define DBG_CTR_TABLE (4 << 24)
46 #define DBG_CTR_CONDITION (5 << 24)
47 #define DBG_CTR_ACTION (6 << 24)
48 #define DBG_CTR_DEPARSER (7 << 24)
50 #define DBG_CTR_EXIT(x) (x | (0x80 << 24))
54 static constexpr uint64_t FIELD_COND =
55 std::numeric_limits<uint64_t>::max() - 1;
57 static constexpr uint64_t FIELD_ACTION =
58 std::numeric_limits<uint64_t>::max() - 2;
64 bool operator==(
const PacketId& other)
const {
65 return packet_id == other.packet_id && copy_id == other.copy_id;
68 bool operator!=(
const PacketId& other)
const {
69 return !(*
this == other);
72 static PacketId make(uint64_t packet_id, uint64_t copy_id) {
73 return {packet_id, copy_id};
77 static void init_debugger(
const std::string &addr, device_id_t device_id);
79 static DebuggerIface *get() {
84 static std::string get_addr();
86 static DebuggerIface *debugger;
88 static constexpr PacketId dummy_PacketId{0u, 0u};
96 using PacketId = Debugger::PacketId;
98 void notify_update(
const PacketId &packet_id,
99 uint64_t
id,
const char *bytes,
int nbits) {
100 notify_update_(packet_id,
id, bytes, nbits);
103 void notify_update(
const PacketId &packet_id,
104 uint64_t
id, uint32_t v) {
105 notify_update_(packet_id,
id, v);
108 void notify_ctr(
const PacketId &packet_id, uint32_t ctr) {
109 notify_ctr_(packet_id, ctr);
112 void packet_in(
const PacketId &packet_id,
int port) {
113 packet_in_(packet_id, port);
116 void packet_out(
const PacketId &packet_id,
int port) {
117 packet_out_(packet_id, port);
120 void config_change() {
124 std::string get_addr()
const {
132 virtual void notify_update_(
const PacketId &packet_id, uint64_t
id,
133 const char *bytes,
int nbits) = 0;
135 virtual void notify_update_(
const PacketId &packet_id, uint64_t
id,
138 virtual void notify_ctr_(
const PacketId &packet_id, uint32_t ctr) = 0;
140 virtual void packet_in_(
const PacketId &packet_id,
int port) = 0;
142 virtual void packet_out_(
const PacketId &packet_id,
int port) = 0;
144 virtual void config_change_() = 0;
146 virtual std::string get_addr_()
const = 0;
150 #define DEBUGGER_NOTIFY_UPDATE(packet_id, id, bytes, nbits) \
151 Debugger::get()->notify_update(packet_id, id, bytes, nbits);
152 #define DEBUGGER_NOTIFY_UPDATE_V(packet_id, id, v) \
153 Debugger::get()->notify_update(packet_id, id, v);
154 #define DEBUGGER_NOTIFY_CTR(packet_id, ctr) \
155 Debugger::get()->notify_ctr(packet_id, ctr);
156 #define DEBUGGER_PACKET_IN(packet_id, port) \
157 Debugger::get()->packet_in(packet_id, port);
158 #define DEBUGGER_PACKET_OUT(packet_id, port) \
159 Debugger::get()->packet_out(packet_id, port);
161 #define DEBUGGER_NOTIFY_UPDATE(packet_id, id, bytes, nbits)
162 #define DEBUGGER_NOTIFY_UPDATE_V(packet_id, id, v)
163 #define DEBUGGER_NOTIFY_CTR(packet_id, ctr)
164 #define DEBUGGER_PACKET_IN(packet_id, port)
165 #define DEBUGGER_PACKET_OUT(packet_id, port)
170 #endif // BM_BM_SIM_DEBUGGER_H_