C++ Device API Reference Manual
Reference documentation for the Simics C++ Device API.
 
Loading...
Searching...
No Matches
callback_overlay.h
Go to the documentation of this file.
1/*
2 © 2023 Intel Corporation
3
4 This software and the related documents are Intel copyrighted materials, and
5 your use of them is governed by the express license under which they were
6 provided to you ("License"). Unless the License provides otherwise, you may
7 not use, modify, copy, publish, distribute, disclose or transmit this software
8 or the related documents without Intel's prior written permission.
9
10 This software and the related documents are provided as is, with no express or
11 implied warranties, other than those that are expressly stated in the License.
12*/
13
14//-*- C++ -*-
15
16#ifndef CPP_API_EXTENSIONS_SRC_SME_OVERLAYS_CALLBACK_OVERLAY_H
17#define CPP_API_EXTENSIONS_SRC_SME_OVERLAYS_CALLBACK_OVERLAY_H
18
19#include <stdarg.h>
20#include <iostream>
21
23
26
34
35namespace sme
36{
37
42struct stage {
43 enum E {
48 };
49};
50
55struct type {
56 enum E {
57 NOTIFY = 0,
65 };
66};
67
73public:
79 : m_pre_read( nullptr)
80 , m_post_read( nullptr)
81 , m_pre_write( nullptr)
82 , m_post_write( nullptr)
83 {;}
84
90 if( m_pre_read != nullptr) delete m_pre_read;
91 if( m_post_read != nullptr) delete m_post_read;
92 if( m_pre_write != nullptr) delete m_pre_write;
93 if( m_post_write != nullptr) delete m_post_write;
94 }
95
103 switch( _stage) {
104 case stage::PRE_READ:
105 if( m_pre_read == nullptr) m_pre_read = new pattern_rule_container();
106 return( m_pre_read);
107 break;
108 case stage::POST_READ:
109 if( m_post_read == nullptr) m_post_read = new pattern_rule_container();
110 return( m_post_read);
111 break;
112 case stage::PRE_WRITE:
113 if( m_pre_write == nullptr) m_pre_write = new pattern_rule_container();
114 return( m_pre_write);
115 break;
117 if( m_post_write == nullptr) m_post_write = new pattern_rule_container();
118 return( m_post_write);
119 break;
120 default:
121 std::cerr << "[ERROR][get_rule_container]: Invalid stage for rule container! (" << _stage << ")" << std::endl;
122 break;
123 }
124 return( NULL);
125 }
126
133 void deactivate_rule( stage::E _stage, std::string _name) {
134 get_rule_container( _stage)->deactivate_rule( _name);
135 }
136
143 void activate_rule( stage::E _stage, std::string _name) {
144 get_rule_container( _stage)->activate_rule( _name);
145 }
146
153 void process_pre_read_rules( uint64_t _old_value, uint64_t _new_value) {
154 if( this->m_pre_read != nullptr) {
155 this->m_pre_read->process_active_rules( _old_value, _new_value);
156 }
157 }
158
165 void process_post_read_rules( uint64_t _old_value, uint64_t _new_value) {
166 if( this->m_post_read != nullptr) {
167 this->m_post_read->process_active_rules( _old_value, _new_value);
168 }
169 }
170
177 void process_pre_write_rules( uint64_t _old_value, uint64_t _new_value) {
178 if( this->m_pre_write != nullptr) {
179 this->m_pre_write->process_active_rules( _old_value, _new_value);
180 }
181 }
182
189 void process_post_write_rules( uint64_t _old_value, uint64_t _new_value) {
190 if( this->m_post_write != nullptr) {
191 this->m_post_write->process_active_rules( _old_value, _new_value);
192 }
193 }
194
208 I_pattern_rule * add_rule( std::function< void()> _func, stage::E _stage, type::E _type, std::string _name, ...) {
209 va_list args;
210 va_start( args, _name);
211 I_pattern_rule * retval = this->__add_rule( _func, _stage, _type, _name, args);
212 va_end( args);
213 return( retval);
214 }
215
216protected:
227 _keep_hot I_pattern_rule * __add_rule( std::function< void()> _func, stage::E _stage, type::E _type, std::string _name, va_list & args) {
228
229 I_pattern_rule * rule = 0;
231
232 if( rules != 0)
233 {
234 switch( _type)
235 {
236 case type::NOTIFY:
237 rule = new sme::rules::notify();
238 break;
239 case type::MASKED:
240 rule = new sme::rules::masked( va_arg( args, uint64_t));
241 break;
242 case type::PATTERN:
243 rule = new sme::rules::pattern( va_arg( args, uint64_t), va_arg( args, uint64_t), va_arg( args, uint64_t));
244 break;
245 case type::RISING_BIT:
246 rule = new sme::rules::rising_bit( uint8_t( va_arg( args, uint32_t)));
247 break;
249 rule = new sme::rules::falling_bit( uint8_t( va_arg( args, uint32_t)));
250 break;
251 default:
252 std::cerr << "[ERROR][__add_rule]: Invalid stage for rule container! (" << _stage << ")" << std::endl;
253 break;
254 }
255
256 if( rule != 0) {
257 rules->add_rule( _name, rule);
258 rule->action( _func);
259 }
260 }
261
262 return( rule);
263 }
264
265
271
277
283
289
290};
291
292}
293
294#endif
#define _keep_hot
Definition: _inline.h:32
#define NULL
Definition: _null.h:24
Interface and base class for all notification rule types.
Definition: I_pattern_rule.h:32
void action(std::function< void()> _action)
Binds a void(void) lambda as the callback action to this rule.
Definition: I_pattern_rule.h:71
class which houses all four rule containers, only allocated if utilized.
Definition: callback_overlay.h:72
callback_overlay()
Construct a new callback overlay object.
Definition: callback_overlay.h:78
pattern_rule_container * m_post_read
post_read rule container (ptr).
Definition: callback_overlay.h:276
~callback_overlay()
Destroy the callback overlay object.
Definition: callback_overlay.h:89
I_pattern_rule * add_rule(std::function< void()> _func, stage::E _stage, type::E _type, std::string _name,...)
add a rule to this entity.
Definition: callback_overlay.h:208
void process_pre_write_rules(uint64_t _old_value, uint64_t _new_value)
processes pre_write_rules.
Definition: callback_overlay.h:177
pattern_rule_container * m_pre_write
pre_write rule container (ptr).
Definition: callback_overlay.h:282
void deactivate_rule(stage::E _stage, std::string _name)
deactivates rule by name at stage.
Definition: callback_overlay.h:133
void process_post_write_rules(uint64_t _old_value, uint64_t _new_value)
processes post_write_rules.
Definition: callback_overlay.h:189
pattern_rule_container * get_rule_container(stage::E _stage)
Get the rule container object.
Definition: callback_overlay.h:102
_keep_hot I_pattern_rule * __add_rule(std::function< void()> _func, stage::E _stage, type::E _type, std::string _name, va_list &args)
real implementation of add a rule to this entity (decompressed va_list).
Definition: callback_overlay.h:227
void process_pre_read_rules(uint64_t _old_value, uint64_t _new_value)
processes pre_read_rules.
Definition: callback_overlay.h:153
pattern_rule_container * m_pre_read
pre_read rule container (ptr).
Definition: callback_overlay.h:270
void process_post_read_rules(uint64_t _old_value, uint64_t _new_value)
processes post_read_rules.
Definition: callback_overlay.h:165
void activate_rule(stage::E _stage, std::string _name)
activates rule by name at stage.
Definition: callback_overlay.h:143
pattern_rule_container * m_post_write
post_write rule container (ptr).
Definition: callback_overlay.h:288
tracks all rules of a single type for a particular target.
Definition: pattern_rule_container.h:38
void activate_rule(std::string _name)
activate rule by name.
Definition: pattern_rule_container.h:107
bool add_rule(std::string _name, I_pattern_rule *_rule, bool _active=true)
Adds a descendant of I_pattern_rule by name to this container.
Definition: pattern_rule_container.h:64
void deactivate_rule(std::string _name)
deactivate rule by name.
Definition: pattern_rule_container.h:87
void process_active_rules(uint64_t _old_value, uint64_t _new_value)
processes all active rules.
Definition: pattern_rule_container.h:128
rule specifically to monitor a single bit for falling edge.
Definition: falling_bit.h:31
rule executes if anything "masked" changes between the old and new value.
Definition: masked.h:30
Basic rule executes with access (no change required).
Definition: notify.h:30
rule executes if the masked pattern matches the start (old) and end (new) values.
Definition: pattern.h:31
rule specifically to monitor a single bit for rising edge.
Definition: rising_bit.h:31
Definition: expression_vector.h:25
point of a register/field read or write a rule executes on
Definition: callback_overlay.h:42
E
Definition: callback_overlay.h:43
@ POST_WRITE
Definition: callback_overlay.h:47
@ POST_READ
Definition: callback_overlay.h:45
@ PRE_READ
Definition: callback_overlay.h:44
@ PRE_WRITE
Definition: callback_overlay.h:46
type of rule to be applied
Definition: callback_overlay.h:55
E
Definition: callback_overlay.h:56
@ NOTIFY
Definition: callback_overlay.h:57
@ PATTERN
Definition: callback_overlay.h:59
@ FALLING_BIT
Definition: callback_overlay.h:61
@ ANY_RISE
Definition: callback_overlay.h:62
@ RISING_BIT
Definition: callback_overlay.h:60
@ MASKED
Definition: callback_overlay.h:58
@ NOT_IMPLEMENTED
Definition: callback_overlay.h:64
@ ALL_FALL
Definition: callback_overlay.h:63