diff --git a/CMakeLists.txt b/CMakeLists.txt index 715065dc..f986a8d5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,9 +9,9 @@ endforeach() foreach(target ${GVSOC_TARGETS}) set(GAPY_TARGETS_OPT ${GAPY_TARGETS_OPT} --target=${target}) if(NOT DEFINED GAPY_TARGETS_NAME) - set(GAPY_TARGETS_NAME ${target}) + set(GAPY_TARGETS_NAME ${target}) else() - set(GAPY_TARGETS_NAME ${GAPY_TARGETS_NAME}_${target}) + set(GAPY_TARGETS_NAME ${GAPY_TARGETS_NAME}_${target}) endif() endforeach() @@ -116,7 +116,8 @@ option(BUILD_OPTIMIZED_M32 "build GVSOC with optimizations in 32bits mode" O option(BUILD_DEBUG_M32 "build GVSOC with debug information in 32bits mode" OFF) option(SKIP_DPI "Do not build DPI" OFF) -set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -O3") +SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib") +set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-g -O3 -std=c++17") set(CMAKE_CC_FLAGS_RELWITHDEBINFO "-g -O3") @@ -142,9 +143,9 @@ add_subdirectory(models) foreach(subdir ${GVSOC_MODULES}) if(IS_DIRECTORY ${subdir}) - if (NOT ${subdir} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) - get_filename_component(name ${subdir} NAME) - add_subdirectory(${subdir} ${CMAKE_CURRENT_BINARY_DIR}/${name}) - endif() + if (NOT ${subdir} STREQUAL ${CMAKE_CURRENT_SOURCE_DIR}) + get_filename_component(name ${subdir} NAME) + add_subdirectory(${subdir} ${CMAKE_CURRENT_BINARY_DIR}/${name}) + endif() endif() endforeach() diff --git a/engine/src/proxy.cpp b/engine/src/proxy.cpp index 56e34e77..c4dd4ad6 100644 --- a/engine/src/proxy.cpp +++ b/engine/src/proxy.cpp @@ -43,7 +43,6 @@ #include #include #include -#include #include #include @@ -317,7 +316,7 @@ int Gv_proxy::open(int port, int *out_port) return -1; } - if (bind(this->telnet_socket, (struct sockaddr *)&addr, sizeof(addr)) == -1) { + if (::bind(this->telnet_socket, (struct sockaddr *)&addr, sizeof(addr)) == -1) { fprintf(stderr, "Unable to bind the socket: %s\n", strerror(errno)); return -1; } diff --git a/engine/src/vp.cpp b/engine/src/vp.cpp index aef3d3f6..05490584 100644 --- a/engine/src/vp.cpp +++ b/engine/src/vp.cpp @@ -43,7 +43,6 @@ #include #include #include -#include #include #include #include @@ -77,30 +76,30 @@ static Gv_proxy *proxy = NULL; void vp::component::get_trace(std::vector &traces, std::string path) { if (this->get_path() != "" && path.find(this->get_path()) != 0) - { - return; - } + { + return; + } for (vp::component *component: this->get_childs()) - { - component->get_trace(traces, path); - } + { + component->get_trace(traces, path); + } for (auto x: this->traces.traces) - { - if (x.second->get_full_path().find(path) == 0) - { - traces.push_back(x.second); - } - } + { + if (x.second->get_full_path().find(path) == 0) + { + traces.push_back(x.second); + } + } for (auto x: this->traces.trace_events) - { - if (x.second->get_full_path().find(path) == 0) - { - traces.push_back(x.second); - } - } + { + if (x.second->get_full_path().find(path) == 0) + { + traces.push_back(x.second); + } + } } void vp::component::reg_step_pre_start(std::function callback) @@ -121,19 +120,19 @@ void vp::component::post_post_build() void vp::component::final_bind() { for (auto port : this->slave_ports) - { - port.second->final_bind(); - } + { + port.second->final_bind(); + } for (auto port : this->master_ports) - { - port.second->final_bind(); - } + { + port.second->final_bind(); + } for (auto &x : this->childs) - { - x->final_bind(); - } + { + x->final_bind(); + } } @@ -148,14 +147,14 @@ void vp::component::set_vp_config(js::config *config) void vp::component::set_gv_conf(struct gv_conf *gv_conf) { if (gv_conf) - { - memcpy(&this->gv_conf, gv_conf, sizeof(struct gv_conf)); - } + { + memcpy(&this->gv_conf, gv_conf, sizeof(struct gv_conf)); + } else - { - memset(&this->gv_conf, 0, sizeof(struct gv_conf)); - gv_init(&this->gv_conf); - } + { + memset(&this->gv_conf, 0, sizeof(struct gv_conf)); + gv_init(&this->gv_conf); + } } @@ -163,12 +162,12 @@ void vp::component::set_gv_conf(struct gv_conf *gv_conf) js::config *vp::component::get_vp_config() { if (this->vp_config == NULL) - { - if (this->parent != NULL) - { - this->vp_config = this->parent->get_vp_config(); - } - } + { + if (this->parent != NULL) + { + this->vp_config = this->parent->get_vp_config(); + } + } vp_assert_always(this->vp_config != NULL, NULL, "No VP config found\n"); @@ -180,9 +179,9 @@ js::config *vp::component::get_vp_config() void vp::component::load_all() { for (auto &x : this->childs) - { - x->load_all(); - } + { + x->load_all(); + } this->load(); } @@ -209,9 +208,9 @@ int vp::component::build_new() void vp::component::post_post_build_all() { for (auto &x : this->childs) - { - x->post_post_build_all(); - } + { + x->post_post_build_all(); + } this->post_post_build(); } @@ -221,9 +220,9 @@ void vp::component::post_post_build_all() void vp::component::start_all() { for (auto &x : this->childs) - { - x->start_all(); - } + { + x->start_all(); + } this->start(); } @@ -233,9 +232,9 @@ void vp::component::start_all() void vp::component::stop_all() { for (auto &x : this->childs) - { - x->stop_all(); - } + { + x->stop_all(); + } this->stop(); } @@ -244,9 +243,9 @@ void vp::component::stop_all() void vp::component::flush_all() { for (auto &x : this->childs) - { - x->flush_all(); - } + { + x->flush_all(); + } this->flush(); } @@ -256,15 +255,15 @@ void vp::component::flush_all() void vp::component::pre_start_all() { for (auto &x : this->childs) - { - x->pre_start_all(); - } + { + x->pre_start_all(); + } this->pre_start(); for (auto x : pre_start_callbacks) - { - x(); - } + { + x(); + } } @@ -273,13 +272,13 @@ void vp::component_clock::clk_reg(component *_this, component *clock) { _this->clock = (clock_engine *)clock; for (auto &x : _this->childs) - { - x->clk_reg(x, clock); - } + { + x->clk_reg(x, clock); + } for (clock_event *event: _this->events) - { - event->set_clock(_this->clock); - } + { + event->set_clock(_this->clock); + } } @@ -292,31 +291,31 @@ void vp::component::reset_all(bool active, bool from_itf) this->reset_done_from_itf |= from_itf; if (from_itf || !this->reset_done_from_itf) - { - this->get_trace()->msg("Reset\n"); - - this->pre_reset(); - - for (auto reg : this->regs) - { - reg->reset(active); - } - - this->block::reset_all(active); - - if (active) - { - for (clock_event *event: this->events) - { - this->event_cancel(event); - } - } - - for (auto &x : this->childs) - { - x->reset_all(active); - } - } + { + this->get_trace()->msg("Reset\n"); + + this->pre_reset(); + + for (auto reg : this->regs) + { + reg->reset(active); + } + + this->block::reset_all(active); + + if (active) + { + for (clock_event *event: this->events) + { + this->event_cancel(event); + } + } + + for (auto &x : this->childs) + { + x->reset_all(active); + } + } } @@ -344,9 +343,9 @@ void vp::component_clock::pre_build(component *comp) int64_t vp::time_engine::get_next_event_time() { if (this->first_client) - { - return this->first_client->next_event_time; - } + { + return this->first_client->next_event_time; + } return this->time; } @@ -355,20 +354,20 @@ int64_t vp::time_engine::get_next_event_time() bool vp::time_engine::dequeue(time_engine_client *client) { if (!client->is_enqueued) - return false; + return false; client->is_enqueued = false; time_engine_client *current = this->first_client, *prev = NULL; while (current && current != client) - { - prev = current; - current = current->next; - } + { + prev = current; + current = current->next; + } if (prev) - prev->next = client->next; + prev->next = client->next; else - this->first_client = client->next; + this->first_client = client->next; return true; } @@ -383,7 +382,7 @@ bool vp::time_engine::enqueue(time_engine_client *client, int64_t time) // Notify to the engine that something has been pushed in case it is done // by an external systemC component and the engine needs to be waken up if (started) - sync_event.notify(); + sync_event.notify(); #endif #ifdef __VP_USE_SYSTEMV @@ -391,28 +390,28 @@ bool vp::time_engine::enqueue(time_engine_client *client, int64_t time) #endif if (client->is_running()) - return false; + return false; if (client->is_enqueued) - { - if (client->next_event_time <= full_time) - return false; - this->dequeue(client); - } + { + if (client->next_event_time <= full_time) + return false; + this->dequeue(client); + } client->is_enqueued = true; time_engine_client *current = first_client, *prev = NULL; client->next_event_time = full_time; while (current && current->next_event_time < client->next_event_time) - { - prev = current; - current = current->next; - } + { + prev = current; + current = current->next; + } if (prev) - prev->next = client; + prev->next = client; else - first_client = client; + first_client = client; client->next = current; return true; @@ -421,7 +420,7 @@ bool vp::time_engine::enqueue(time_engine_client *client, int64_t time) bool vp::clock_engine::dequeue_from_engine() { if (this->is_running() || !this->is_enqueued) - return false; + return false; this->engine->dequeue(this); @@ -436,58 +435,58 @@ void vp::clock_engine::reenqueue_to_engine() void vp::clock_engine::apply_frequency(int frequency) { if (frequency > 0) - { - bool reenqueue = this->dequeue_from_engine(); - int64_t period = this->period; - - this->freq = frequency; - this->period = 1e12 / this->freq; - if (reenqueue && period > 0) - { - int64_t cycles = (this->next_event_time - this->get_time()) / period; - this->next_event_time = cycles * this->period; - this->reenqueue_to_engine(); - } - else if (period == 0) - { - // Case where the clock engine was clock-gated - // We need to reenqueue the engine in case it has pending events - if (this->has_events()) - { - // Compute the time of the next event based on the new frequency - this->next_event_time = (this->get_next_event()->get_cycle() - this->get_cycles()) * this->period; - - this->reenqueue_to_engine(); - } - } - } + { + bool reenqueue = this->dequeue_from_engine(); + int64_t period = this->period; + + this->freq = frequency; + this->period = 1e12 / this->freq; + if (reenqueue && period > 0) + { + int64_t cycles = (this->next_event_time - this->get_time()) / period; + this->next_event_time = cycles * this->period; + this->reenqueue_to_engine(); + } + else if (period == 0) + { + // Case where the clock engine was clock-gated + // We need to reenqueue the engine in case it has pending events + if (this->has_events()) + { + // Compute the time of the next event based on the new frequency + this->next_event_time = (this->get_next_event()->get_cycle() - this->get_cycles()) * this->period; + + this->reenqueue_to_engine(); + } + } + } else if (frequency == 0) - { - this->dequeue_from_engine(); - this->period = 0; - } + { + this->dequeue_from_engine(); + this->period = 0; + } } void vp::clock_engine::update() { if (this->period == 0) - return; + return; int64_t diff = this->get_time() - this->stop_time; #ifdef __VP_USE_SYSTEMC if ((int64_t)sc_time_stamp().to_double() > this->get_time()) - diff = (int64_t)sc_time_stamp().to_double() - this->stop_time; + diff = (int64_t)sc_time_stamp().to_double() - this->stop_time; engine->update((int64_t)sc_time_stamp().to_double()); #endif if (diff > 0) - { - int64_t cycles = (diff + this->period - 1) / this->period; - this->stop_time += cycles * this->period; - this->cycles += cycles; - } + { + int64_t cycles = (diff + this->period - 1) / this->period; + this->stop_time += cycles * this->period; + this->cycles += cycles; + } } vp::clock_event *vp::clock_engine::enqueue_other(vp::clock_event *event, int64_t cycle) @@ -503,40 +502,40 @@ vp::clock_event *vp::clock_engine::enqueue_other(vp::clock_event *event, int64_t bool can_enqueue_to_cycle = false; if (!this->is_running()) - { - //this->current_cycle = (this->get_cycles() + 1) & CLOCK_EVENT_QUEUE_MASK; - //can_enqueue_to_cycle = this->current_cycle + cycle - 1 < CLOCK_EVENT_QUEUE_SIZE; - } + { + //this->current_cycle = (this->get_cycles() + 1) & CLOCK_EVENT_QUEUE_MASK; + //can_enqueue_to_cycle = this->current_cycle + cycle - 1 < CLOCK_EVENT_QUEUE_SIZE; + } if (can_enqueue_to_cycle) - { - //this->current_cycle = (this->get_cycles() + cycle) & CLOCK_EVENT_QUEUE_MASK; - this->enqueue_to_cycle(event, cycle - 1); - if (this->period != 0) - enqueue_to_engine(period); - } + { + //this->current_cycle = (this->get_cycles() + cycle) & CLOCK_EVENT_QUEUE_MASK; + this->enqueue_to_cycle(event, cycle - 1); + if (this->period != 0) + enqueue_to_engine(period); + } else - { - this->must_flush_delayed_queue = true; - if (this->period != 0) - { - enqueue_to_engine(cycle * period); - } - - vp::clock_event *current = delayed_queue, *prev = NULL; - int64_t full_cycle = cycle + get_cycles(); - while (current && current->cycle < full_cycle) - { - prev = current; - current = current->next; - } - if (prev) - prev->next = event; - else - delayed_queue = event; - event->next = current; - event->cycle = full_cycle; - } + { + this->must_flush_delayed_queue = true; + if (this->period != 0) + { + enqueue_to_engine(cycle * period); + } + + vp::clock_event *current = delayed_queue, *prev = NULL; + int64_t full_cycle = cycle + get_cycles(); + while (current && current->cycle < full_cycle) + { + prev = current; + current = current->next; + } + if (prev) + prev->next = event; + else + delayed_queue = event; + event->next = current; + event->cycle = full_cycle; + } return event; } @@ -547,18 +546,18 @@ vp::clock_event *vp::clock_engine::get_next_event() // and if not in the delayed queue if (this->nb_enqueued_to_cycle) - { - for (int i = 0; i < CLOCK_EVENT_QUEUE_SIZE; i++) - { - int cycle = (current_cycle + i) & CLOCK_EVENT_QUEUE_MASK; - vp::clock_event *event = event_queue[cycle]; - if (event) - { - return event; - } - } - vp_assert(false, 0, "Didn't find any event in circular buffer while it is not empty\n"); - } + { + for (int i = 0; i < CLOCK_EVENT_QUEUE_SIZE; i++) + { + int cycle = (current_cycle + i) & CLOCK_EVENT_QUEUE_MASK; + vp::clock_event *event = event_queue[cycle]; + if (event) + { + return event; + } + } + vp_assert(false, 0, "Didn't find any event in circular buffer while it is not empty\n"); + } return this->delayed_queue; } @@ -566,7 +565,7 @@ vp::clock_event *vp::clock_engine::get_next_event() void vp::clock_engine::cancel(vp::clock_event *event) { if (!event->is_enqueued()) - return; + return; // There is no way to know if the event is enqueued into the circular buffer // or in the delayed queue so first go through the delayed queue and if it is @@ -575,51 +574,51 @@ void vp::clock_engine::cancel(vp::clock_event *event) // First the delayed queue vp::clock_event *current = delayed_queue, *prev = NULL; while (current) - { - if (current == event) - { - if (prev) - prev->next = event->next; - else - delayed_queue = event->next; - - goto end; - } - - prev = current; - current = current->next; - } + { + if (current == event) + { + if (prev) + prev->next = event->next; + else + delayed_queue = event->next; + + goto end; + } + + prev = current; + current = current->next; + } // Then in the circular buffer for (int i = 0; i < CLOCK_EVENT_QUEUE_SIZE; i++) - { - vp::clock_event *current = event_queue[i], *prev = NULL; - while (current) - { - if (current == event) - { - if (prev) - prev->next = event->next; - else - event_queue[i] = event->next; - - this->nb_enqueued_to_cycle--; - - goto end; - } - - prev = current; - current = current->next; - } - } + { + vp::clock_event *current = event_queue[i], *prev = NULL; + while (current) + { + if (current == event) + { + if (prev) + prev->next = event->next; + else + event_queue[i] = event->next; + + this->nb_enqueued_to_cycle--; + + goto end; + } + + prev = current; + current = current->next; + } + } vp_assert(0, NULL, "Didn't find event in any queue while canceling event\n"); -end: + end: event->enqueued = false; if (!this->has_events()) - this->dequeue_from_engine(); + this->dequeue_from_engine(); } void vp::clock_engine::flush_delayed_queue() @@ -627,21 +626,21 @@ void vp::clock_engine::flush_delayed_queue() clock_event *event = delayed_queue; this->must_flush_delayed_queue = false; while (event) - { - if (nb_enqueued_to_cycle == 0) - cycles = event->cycle; + { + if (nb_enqueued_to_cycle == 0) + cycles = event->cycle; - uint64_t cycle_diff = event->cycle - get_cycles(); - if (cycle_diff >= CLOCK_EVENT_QUEUE_SIZE) - break; + uint64_t cycle_diff = event->cycle - get_cycles(); + if (cycle_diff >= CLOCK_EVENT_QUEUE_SIZE) + break; - clock_event *next = event->next; + clock_event *next = event->next; - enqueue_to_cycle(event, cycle_diff); + enqueue_to_cycle(event, cycle_diff); - event = next; - delayed_queue = event; - } + event = next; + delayed_queue = event; + } } int64_t vp::clock_engine::exec() @@ -657,9 +656,9 @@ int64_t vp::clock_engine::exec() // to check if events must be enqueued from the queue to the buffer // in case they fit the window. if (unlikely(this->must_flush_delayed_queue)) - { - this->flush_delayed_queue(); - } + { + this->flush_delayed_queue(); + } vp_assert(this->get_next_event(), NULL, "Executing clock engine while it has no next event\n"); @@ -668,14 +667,14 @@ int64_t vp::clock_engine::exec() clock_event *current = event_queue[current_cycle]; while (likely(current != NULL)) - { - event_queue[current_cycle] = current->next; - current->enqueued = false; - nb_enqueued_to_cycle--; + { + event_queue[current_cycle] = current->next; + current->enqueued = false; + nb_enqueued_to_cycle--; - current->meth(current->_this, current); - current = event_queue[current_cycle]; - } + current->meth(current->_this, current); + current = event_queue[current_cycle]; + } // Now we need to tell the time engine when is the next event. // The most likely is that there is an event in the circular buffer, @@ -683,37 +682,37 @@ int64_t vp::clock_engine::exec() // each element of the circular buffer, even if the next event is further in // the buffer. if (likely(nb_enqueued_to_cycle)) - { - cycles++; - current_cycle = (current_cycle + 1) & CLOCK_EVENT_QUEUE_MASK; - if (unlikely(current_cycle == 0)) - this->must_flush_delayed_queue = true; - - return period; - } + { + cycles++; + current_cycle = (current_cycle + 1) & CLOCK_EVENT_QUEUE_MASK; + if (unlikely(current_cycle == 0)) + this->must_flush_delayed_queue = true; + + return period; + } else - { - // Otherwise if there is an event in the delayed queue, return the time - // to this event. - // In both cases, force the delayed queue flush so that the next event to be - // executed is moved to the circular buffer. - this->must_flush_delayed_queue = true; - - // Also remember the current time in order to resynchronize the clock engine - // in case we enqueue and event from another engine. - this->stop_time = this->get_time(); - - if (delayed_queue) - { - return (delayed_queue->cycle - get_cycles()) * period; - } - else - { - // In case there is no more event to execute, returns -1 to tell the time - // engine we are done. - return -1; - } - } + { + // Otherwise if there is an event in the delayed queue, return the time + // to this event. + // In both cases, force the delayed queue flush so that the next event to be + // executed is moved to the circular buffer. + this->must_flush_delayed_queue = true; + + // Also remember the current time in order to resynchronize the clock engine + // in case we enqueue and event from another engine. + this->stop_time = this->get_time(); + + if (delayed_queue) + { + return (delayed_queue->cycle - get_cycles()) * period; + } + else + { + // In case there is no more event to execute, returns -1 to tell the time + // engine we are done. + return -1; + } + } } vp::clock_event::clock_event(component_clock *comp, clock_event_meth_t *meth) @@ -731,9 +730,9 @@ void vp::component_clock::add_clock_event(clock_event *event) vp::time_engine *vp::component::get_time_engine() { if (this->time_engine_ptr == NULL) - { - this->time_engine_ptr = (vp::time_engine*)this->get_service("time"); - } + { + this->time_engine_ptr = (vp::time_engine*)this->get_service("time"); + } return this->time_engine_ptr; } @@ -816,9 +815,9 @@ void vp::component::new_slave_port(void *comp, std::string name, vp::slave_port void vp::component::add_service(std::string name, void *service) { if (this->parent) - this->parent->add_service(name, service); + this->parent->add_service(name, service); else if (all_services[name] == NULL) - all_services[name] = service; + all_services[name] = service; } @@ -828,7 +827,7 @@ void vp::component::new_service(std::string name, void *service) this->get_trace()->msg(vp::trace::LEVEL_DEBUG, "New service (name: %s, service: %p)\n", name.c_str(), service); if (this->parent) - this->parent->add_service(name, service); + this->parent->add_service(name, service); all_services[name] = service; } @@ -836,10 +835,10 @@ void vp::component::new_service(std::string name, void *service) void *vp::component::get_service(string name) { if (all_services[name]) - return all_services[name]; + return all_services[name]; if (this->parent) - return this->parent->get_service(name); + return this->parent->get_service(name); return NULL; } @@ -850,9 +849,9 @@ std::vector split_name(const std::string &s, char delimiter) std::string token; std::istringstream tokenStream(s); while (std::getline(tokenStream, token, delimiter)) - { - tokens.push_back(token); - } + { + tokens.push_back(token); + } return tokens; } @@ -862,48 +861,48 @@ vp::config *vp::config::create_config(jsmntok_t *tokens, int *_size) config *config = NULL; switch (current->type) - { - case JSMN_PRIMITIVE: - if (strcmp(current->str, "True") == 0 || strcmp(current->str, "False") == 0 || strcmp(current->str, "true") == 0 || strcmp(current->str, "false") == 0) - { - config = new config_bool(current); - } - else - { - config = new config_number(current); - } - current++; - break; - - case JSMN_OBJECT: - { - int size; - config = new config_object(current, &size); - current += size; - break; - } - - case JSMN_ARRAY: - { - int size; - config = new config_array(current, &size); - current += size; - break; - } - - case JSMN_STRING: - config = new config_string(current); - current++; - break; - - case JSMN_UNDEFINED: - break; - } + { + case JSMN_PRIMITIVE: + if (strcmp(current->str, "True") == 0 || strcmp(current->str, "False") == 0 || strcmp(current->str, "true") == 0 || strcmp(current->str, "false") == 0) + { + config = new config_bool(current); + } + else + { + config = new config_number(current); + } + current++; + break; + + case JSMN_OBJECT: + { + int size; + config = new config_object(current, &size); + current += size; + break; + } + + case JSMN_ARRAY: + { + int size; + config = new config_array(current, &size); + current += size; + break; + } + + case JSMN_STRING: + config = new config_string(current); + current++; + break; + + case JSMN_UNDEFINED: + break; + } if (_size) - { - *_size = current - tokens; - } + { + *_size = current - tokens; + } return config; } @@ -911,72 +910,72 @@ vp::config *vp::config::create_config(jsmntok_t *tokens, int *_size) vp::config *vp::config_string::get_from_list(std::vector name_list) { if (name_list.size() == 0) - return this; + return this; return NULL; } vp::config *vp::config_number::get_from_list(std::vector name_list) { if (name_list.size() == 0) - return this; + return this; return NULL; } vp::config *vp::config_bool::get_from_list(std::vector name_list) { if (name_list.size() == 0) - return this; + return this; return NULL; } vp::config *vp::config_array::get_from_list(std::vector name_list) { if (name_list.size() == 0) - return this; + return this; return NULL; } vp::config *vp::config_object::get_from_list(std::vector name_list) { if (name_list.size() == 0) - return this; + return this; vp::config *result = NULL; std::string name; int name_pos = 0; for (auto &x : name_list) - { - if (x != "*" && x != "**") - { - name = x; - break; - } - name_pos++; - } + { + if (x != "*" && x != "**") + { + name = x; + break; + } + name_pos++; + } for (auto &x : childs) - { - - if (name == x.first) - { - result = x.second->get_from_list(std::vector(name_list.begin() + name_pos + 1, name_list.begin() + name_list.size())); - if (name_pos == 0 || result != NULL) - return result; - } - else if (name_list[0] == "*") - { - result = x.second->get_from_list(std::vector(name_list.begin() + 1, name_list.begin() + name_list.size())); - if (result != NULL) - return result; - } - else if (name_list[0] == "**") - { - result = x.second->get_from_list(name_list); - if (result != NULL) - return result; - } - } + { + + if (name == x.first) + { + result = x.second->get_from_list(std::vector(name_list.begin() + name_pos + 1, name_list.begin() + name_list.size())); + if (name_pos == 0 || result != NULL) + return result; + } + else if (name_list[0] == "*") + { + result = x.second->get_from_list(std::vector(name_list.begin() + 1, name_list.begin() + name_list.size())); + if (result != NULL) + return result; + } + else if (name_list[0] == "**") + { + result = x.second->get_from_list(name_list); + if (result != NULL) + return result; + } + } return result; } @@ -1007,16 +1006,16 @@ vp::config_array::config_array(jsmntok_t *tokens, int *_size) jsmntok_t *top = current++; for (int i = 0; i < top->size; i++) - { - int child_size; - elems.push_back(create_config(current, &child_size)); - current += child_size; - } + { + int child_size; + elems.push_back(create_config(current, &child_size)); + current += child_size; + } if (_size) - { - *_size = current - tokens; - } + { + *_size = current - tokens; + } } vp::config_object::config_object(jsmntok_t *tokens, int *_size) @@ -1025,28 +1024,28 @@ vp::config_object::config_object(jsmntok_t *tokens, int *_size) jsmntok_t *t = current++; for (int i = 0; i < t->size; i++) - { - jsmntok_t *child_name = current++; - int child_size; - config *child_config = create_config(current, &child_size); - current += child_size; - - if (child_config != NULL) - { - childs[child_name->str] = child_config; - } - } + { + jsmntok_t *child_name = current++; + int child_size; + config *child_config = create_config(current, &child_size); + current += child_size; + + if (child_config != NULL) + { + childs[child_name->str] = child_config; + } + } if (_size) - { - *_size = current - tokens; - } + { + *_size = current - tokens; + } } vp::config *vp::component::import_config(const char *config_string) { if (config_string == NULL) - return NULL; + return NULL; jsmn_parser parser; @@ -1060,11 +1059,11 @@ vp::config *vp::component::import_config(const char *config_string) char *str = strdup(config_string); for (int i = 0; i < nb_tokens; i++) - { - jsmntok_t *tok = &tokens[i]; - tok->str = &str[tok->start]; - str[tok->end] = 0; - } + { + jsmntok_t *tok = &tokens[i]; + tok->str = &str[tok->start]; + str[tok->end] = 0; + } return new vp::config_object(tokens); } @@ -1075,9 +1074,9 @@ void vp::component::conf(string name, string path, vp::component *parent) this->parent = parent; this->path = path; if (parent != NULL) - { - parent->add_child(name, this); - } + { + parent->add_child(name, this); + } } void vp::component::add_child(std::string name, vp::component *child) @@ -1092,42 +1091,42 @@ void vp::component::add_child(std::string name, vp::component *child) vp::component *vp::component::get_component(std::vector path_list) { if (path_list.size() == 0) - { - return this; - } + { + return this; + } std::string name = ""; unsigned int name_pos= 0; for (auto x: path_list) - { - if (x != "*" && x != "**") - { - name = x; - break; - } - name_pos += 1; - } + { + if (x != "*" && x != "**") + { + name = x; + break; + } + name_pos += 1; + } for (auto x:this->childs) - { - vp::component *comp; - if (name == x->get_name()) - { - comp = x->get_component({ path_list.begin() + name_pos + 1, path_list.end() }); - } - else if (path_list[0] == "**") - { - comp = x->get_component(path_list); - } - else if (path_list[0] == "*") - { - comp = x->get_component({ path_list.begin() + 1, path_list.end() }); - } - if (comp) - { - return comp; - } - } + { + vp::component *comp; + if (name == x->get_name()) + { + comp = x->get_component({ path_list.begin() + name_pos + 1, path_list.end() }); + } + else if (path_list[0] == "**") + { + comp = x->get_component(path_list); + } + else if (path_list[0] == "*") + { + comp = x->get_component({ path_list.begin() + 1, path_list.end() }); + } + if (comp) + { + return comp; + } + } return NULL; } @@ -1135,16 +1134,16 @@ vp::component *vp::component::get_component(std::vector path_list) void vp::component::elab() { for (auto &x : this->childs) - { - x->elab(); - } + { + x->elab(); + } } void vp::component::new_reg(std::string name, vp::reg_1 *reg, uint8_t reset_val, bool reset) { this->get_trace()->msg(vp::trace::LEVEL_DEBUG, "New register (name: %s, width: %d, reset_val: 0x%x, reset: %d)\n", - name.c_str(), 1, reset_val, reset - ); + name.c_str(), 1, reset_val, reset + ); reg->init(this, name, reset ? (uint8_t *)&reset_val : NULL); this->regs.push_back(reg); @@ -1153,8 +1152,8 @@ void vp::component::new_reg(std::string name, vp::reg_1 *reg, uint8_t reset_val, void vp::component::new_reg(std::string name, vp::reg_8 *reg, uint8_t reset_val, bool reset) { this->get_trace()->msg(vp::trace::LEVEL_DEBUG, "New register (name: %s, width: %d, reset_val: 0x%x, reset: %d)\n", - name.c_str(), 8, reset_val, reset - ); + name.c_str(), 8, reset_val, reset + ); reg->init(this, name, reset ? (uint8_t *)&reset_val : NULL); this->regs.push_back(reg); @@ -1163,8 +1162,8 @@ void vp::component::new_reg(std::string name, vp::reg_8 *reg, uint8_t reset_val, void vp::component::new_reg(std::string name, vp::reg_16 *reg, uint16_t reset_val, bool reset) { this->get_trace()->msg(vp::trace::LEVEL_DEBUG, "New register (name: %s, width: %d, reset_val: 0x%x, reset: %d)\n", - name.c_str(), 16, reset_val, reset - ); + name.c_str(), 16, reset_val, reset + ); reg->init(this, name, reset ? (uint8_t *)&reset_val : NULL); this->regs.push_back(reg); @@ -1173,8 +1172,8 @@ void vp::component::new_reg(std::string name, vp::reg_16 *reg, uint16_t reset_va void vp::component::new_reg(std::string name, vp::reg_32 *reg, uint32_t reset_val, bool reset) { this->get_trace()->msg(vp::trace::LEVEL_DEBUG, "New register (name: %s, width: %d, reset_val: 0x%x, reset: %d)\n", - name.c_str(), 32, reset_val, reset - ); + name.c_str(), 32, reset_val, reset + ); reg->init(this, name, reset ? (uint8_t *)&reset_val : NULL); this->regs.push_back(reg); @@ -1183,8 +1182,8 @@ void vp::component::new_reg(std::string name, vp::reg_32 *reg, uint32_t reset_va void vp::component::new_reg(std::string name, vp::reg_64 *reg, uint64_t reset_val, bool reset) { this->get_trace()->msg(vp::trace::LEVEL_DEBUG, "New register (name: %s, width: %d, reset_val: 0x%x, reset: %d)\n", - name.c_str(), 64, reset_val, reset - ); + name.c_str(), 64, reset_val, reset + ); reg->init(this, name, reset ? (uint8_t *)&reset_val : NULL); this->regs.push_back(reg); @@ -1193,15 +1192,15 @@ void vp::component::new_reg(std::string name, vp::reg_64 *reg, uint64_t reset_va void vp::master_port::final_bind() { if (this->is_bound) - { - this->finalize(); - } + { + this->finalize(); + } } void vp::slave_port::final_bind() { if (this->is_bound) - this->finalize(); + this->finalize(); } extern "C" char *vp_get_error() @@ -1216,9 +1215,9 @@ extern "C" void vp_port_bind_to(void *_master, void *_slave, const char *config_ vp::config *config = NULL; if (config_str != NULL) - { - config = master->get_comp()->import_config(config_str); - } + { + config = master->get_comp()->import_config(config_str); + } master->bind_to(slave, config); slave->bind_to(master, config); @@ -1242,46 +1241,46 @@ void vp::component::build_instance(std::string name, vp::component *parent) this->power.build(); for (auto x : build_callbacks) - { - x(); - } + { + x(); + } } vp::component *vp::component::new_component(std::string name, js::config *config, std::string module_name) { if (module_name == "") - { - module_name = config->get_child_str("vp_component"); + { + module_name = config->get_child_str("vp_component"); - if (module_name == "") - { - module_name = "utils.composite_impl"; - } - } + if (module_name == "") + { + module_name = "utils.composite_impl"; + } + } #ifdef __M32_MODE__ if (this->get_vp_config()->get_child_bool("sv-mode")) - { - module_name = "sv_m32." + module_name; - } + { + module_name = "sv_m32." + module_name; + } else if (this->get_vp_config()->get_child_bool("debug-mode")) - { - module_name = "debug_m32." + module_name; - } + { + module_name = "debug_m32." + module_name; + } else - { - module_name = "m32." + module_name; - } + { + module_name = "m32." + module_name; + } #else if (this->get_vp_config()->get_child_bool("sv-mode")) - { - module_name = "sv." + module_name; - } + { + module_name = "sv." + module_name; + } else if (this->get_vp_config()->get_child_bool("debug-mode")) - { - module_name = "debug." + module_name; - } + { + module_name = "debug." + module_name; + } #endif this->get_trace()->msg(vp::trace::LEVEL_DEBUG, "New component (name: %s, module: %s)\n", name.c_str(), module_name.c_str()); @@ -1290,17 +1289,21 @@ vp::component *vp::component::new_component(std::string name, js::config *config std::string path = __gv_get_component_path(this->get_vp_config(), module_name); +#if (!__APPLE__) void *module = dlopen(path.c_str(), RTLD_NOW | RTLD_GLOBAL | RTLD_DEEPBIND); +#else + void *module = dlopen(path.c_str(), RTLD_NOW | RTLD_GLOBAL); +#endif if (module == NULL) - { - this->throw_error("ERROR, Failed to open periph model (module: " + module_name + ", error: " + std::string(dlerror()) + ")"); - } + { + this->throw_error("ERROR, Failed to open periph model (module: " + module_name + ", error: " + std::string(dlerror()) + ")"); + } vp::component *(*constructor)(js::config *) = (vp::component * (*)(js::config *)) dlsym(module, "vp_constructor"); if (constructor == NULL) - { - this->throw_error("ERROR, couldn't find vp_constructor in loaded module (module: " + module_name + ")"); - } + { + this->throw_error("ERROR, couldn't find vp_constructor in loaded module (module: " + module_name + ")"); + } vp::component *instance = constructor(config); @@ -1322,24 +1325,24 @@ void vp::component::create_ports() js::config *config = this->get_js_config(); js::config *ports = config->get("vp_ports"); if (ports == NULL) - { - ports = config->get("ports"); - } + { + ports = config->get("ports"); + } if (ports != NULL) - { - this->get_trace()->msg(vp::trace::LEVEL_DEBUG, "Creating ports\n"); + { + this->get_trace()->msg(vp::trace::LEVEL_DEBUG, "Creating ports\n"); - for (auto x : ports->get_elems()) - { - std::string port_name = x->get_str(); + for (auto x : ports->get_elems()) + { + std::string port_name = x->get_str(); - this->get_trace()->msg(vp::trace::LEVEL_DEBUG, "Creating port (name: %s)\n", port_name.c_str()); + this->get_trace()->msg(vp::trace::LEVEL_DEBUG, "Creating port (name: %s)\n", port_name.c_str()); - if (this->get_master_port(port_name) == NULL && this->get_slave_port(port_name) == NULL) - this->add_master_port(port_name, new vp::virtual_port(this)); - } - } + if (this->get_master_port(port_name) == NULL && this->get_slave_port(port_name) == NULL) + this->add_master_port(port_name, new vp::virtual_port(this)); + } + } } void vp::component::create_bindings() @@ -1347,59 +1350,59 @@ void vp::component::create_bindings() js::config *config = this->get_js_config(); js::config *bindings = config->get("vp_bindings"); if (bindings == NULL) - { - bindings = config->get("bindings"); - } + { + bindings = config->get("bindings"); + } if (bindings != NULL) - { - this->get_trace()->msg(vp::trace::LEVEL_DEBUG, "Creating bindings\n"); - - for (auto x : bindings->get_elems()) - { - std::string master_binding = x->get_elem(0)->get_str(); - std::string slave_binding = x->get_elem(1)->get_str(); - int pos = master_binding.find_first_of("->"); - std::string master_comp_name = master_binding.substr(0, pos); - std::string master_port_name = master_binding.substr(pos + 2); - pos = slave_binding.find_first_of("->"); - std::string slave_comp_name = slave_binding.substr(0, pos); - std::string slave_port_name = slave_binding.substr(pos + 2); - - this->get_trace()->msg(vp::trace::LEVEL_DEBUG, "Creating binding (%s:%s -> %s:%s)\n", - master_comp_name.c_str(), master_port_name.c_str(), - slave_comp_name.c_str(), slave_port_name.c_str() - ); - - vp::component *master_comp = master_comp_name == "self" ? this : this->get_childs_dict()[master_comp_name]; - vp::component *slave_comp = slave_comp_name == "self" ? this : this->get_childs_dict()[slave_comp_name]; - - vp_assert_always(master_comp != NULL, this->get_trace(), - "Binding from invalid master (master: %s / %s, slave: %s / %s)\n", - master_comp_name.c_str(), master_port_name.c_str(), - slave_comp_name.c_str(), slave_port_name.c_str()); - - vp_assert_always(slave_comp != NULL, this->get_trace(), - "Binding from invalid slave (master: %s / %s, slave: %s / %s)\n", - master_comp_name.c_str(), master_port_name.c_str(), - slave_comp_name.c_str(), slave_port_name.c_str()); - - vp::port *master_port = master_comp->get_master_port(master_port_name); - vp::port *slave_port = slave_comp->get_slave_port(slave_port_name); - - vp_assert_always(master_port != NULL, this->get_trace(), - "Binding from invalid master port (master: %s / %s, slave: %s / %s)\n", - master_comp_name.c_str(), master_port_name.c_str(), - slave_comp_name.c_str(), slave_port_name.c_str()); - - vp_assert_always(slave_port != NULL, this->get_trace(), - "Binding from invalid slave port (master: %s / %s, slave: %s / %s)\n", - master_comp_name.c_str(), master_port_name.c_str(), - slave_comp_name.c_str(), slave_port_name.c_str()); - - master_port->bind_to_virtual(slave_port); - } - } + { + this->get_trace()->msg(vp::trace::LEVEL_DEBUG, "Creating bindings\n"); + + for (auto x : bindings->get_elems()) + { + std::string master_binding = x->get_elem(0)->get_str(); + std::string slave_binding = x->get_elem(1)->get_str(); + int pos = master_binding.find_first_of("->"); + std::string master_comp_name = master_binding.substr(0, pos); + std::string master_port_name = master_binding.substr(pos + 2); + pos = slave_binding.find_first_of("->"); + std::string slave_comp_name = slave_binding.substr(0, pos); + std::string slave_port_name = slave_binding.substr(pos + 2); + + this->get_trace()->msg(vp::trace::LEVEL_DEBUG, "Creating binding (%s:%s -> %s:%s)\n", + master_comp_name.c_str(), master_port_name.c_str(), + slave_comp_name.c_str(), slave_port_name.c_str() + ); + + vp::component *master_comp = master_comp_name == "self" ? this : this->get_childs_dict()[master_comp_name]; + vp::component *slave_comp = slave_comp_name == "self" ? this : this->get_childs_dict()[slave_comp_name]; + + vp_assert_always(master_comp != NULL, this->get_trace(), + "Binding from invalid master (master: %s / %s, slave: %s / %s)\n", + master_comp_name.c_str(), master_port_name.c_str(), + slave_comp_name.c_str(), slave_port_name.c_str()); + + vp_assert_always(slave_comp != NULL, this->get_trace(), + "Binding from invalid slave (master: %s / %s, slave: %s / %s)\n", + master_comp_name.c_str(), master_port_name.c_str(), + slave_comp_name.c_str(), slave_port_name.c_str()); + + vp::port *master_port = master_comp->get_master_port(master_port_name); + vp::port *slave_port = slave_comp->get_slave_port(slave_port_name); + + vp_assert_always(master_port != NULL, this->get_trace(), + "Binding from invalid master port (master: %s / %s, slave: %s / %s)\n", + master_comp_name.c_str(), master_port_name.c_str(), + slave_comp_name.c_str(), slave_port_name.c_str()); + + vp_assert_always(slave_port != NULL, this->get_trace(), + "Binding from invalid slave port (master: %s / %s, slave: %s / %s)\n", + master_comp_name.c_str(), master_port_name.c_str(), + slave_comp_name.c_str(), slave_port_name.c_str()); + + master_port->bind_to_virtual(slave_port); + } + } } @@ -1416,10 +1419,10 @@ std::vector vp::master_port::get_final_ports() std::vector result; for (auto x : this->slave_ports) - { - std::vector slave_ports = x->get_final_ports(); - result.insert(result.end(), slave_ports.begin(), slave_ports.end()); - } + { + std::vector slave_ports = x->get_final_ports(); + result.insert(result.end(), slave_ports.begin(), slave_ports.end()); + } return result; } @@ -1429,18 +1432,18 @@ std::vector vp::master_port::get_final_ports() void vp::master_port::bind_to_slaves() { for (auto x : this->slave_ports) - { - for (auto y : x->get_final_ports()) - { - this->get_owner()->get_trace()->msg(vp::trace::LEVEL_DEBUG, "Creating final binding (%s:%s -> %s:%s)\n", - this->get_owner()->get_path().c_str(), this->get_name().c_str(), - y->get_owner()->get_path().c_str(), y->get_name().c_str() - ); - - this->bind_to(y, NULL); - y->bind_to(this, NULL); - } - } + { + for (auto y : x->get_final_ports()) + { + this->get_owner()->get_trace()->msg(vp::trace::LEVEL_DEBUG, "Creating final binding (%s:%s -> %s:%s)\n", + this->get_owner()->get_path().c_str(), this->get_name().c_str(), + y->get_owner()->get_path().c_str(), y->get_name().c_str() + ); + + this->bind_to(y, NULL); + y->bind_to(this, NULL); + } + } } void vp::component::bind_comps() @@ -1448,28 +1451,28 @@ void vp::component::bind_comps() this->get_trace()->msg(vp::trace::LEVEL_DEBUG, "Creating final bindings\n"); for (auto x : this->get_childs()) - { - x->bind_comps(); - } + { + x->bind_comps(); + } for (auto x : this->master_ports) - { - if (!x.second->is_virtual()) - { - x.second->bind_to_slaves(); - } - } + { + if (!x.second->is_virtual()) + { + x.second->bind_to_slaves(); + } + } } void *vp::component::external_bind(std::string comp_name, std::string itf_name, void *handle) { for (auto &x : this->childs) - { - void *result = x->external_bind(comp_name, itf_name, handle); - if (result != NULL) - return result; - } + { + void *result = x->external_bind(comp_name, itf_name, handle); + if (result != NULL) + return result; + } return NULL; } @@ -1486,28 +1489,28 @@ void vp::component::create_comps() js::config *config = this->get_js_config(); js::config *comps = config->get("vp_comps"); if (comps == NULL) - { - comps = config->get("components"); - } + { + comps = config->get("components"); + } if (comps != NULL) - { - this->get_trace()->msg(vp::trace::LEVEL_DEBUG, "Creating components\n"); + { + this->get_trace()->msg(vp::trace::LEVEL_DEBUG, "Creating components\n"); - for (auto x : comps->get_elems()) - { - std::string comp_name = x->get_str(); + for (auto x : comps->get_elems()) + { + std::string comp_name = x->get_str(); - js::config *comp_config = config->get(comp_name); + js::config *comp_config = config->get(comp_name); - std::string vp_component = comp_config->get_child_str("vp_component"); + std::string vp_component = comp_config->get_child_str("vp_component"); - if (vp_component == "") - vp_component = "utils.composite_impl"; + if (vp_component == "") + vp_component = "utils.composite_impl"; - this->new_component(comp_name, comp_config, vp_component); - } - } + this->new_component(comp_name, comp_config, vp_component); + } + } } @@ -1517,9 +1520,9 @@ void vp::component::dump_traces_recursive(FILE *file) this->dump_traces(file); for (auto& x: this->get_childs()) - { - x->dump_traces_recursive(file); - } + { + x->dump_traces_recursive(file); + } } std::string vp::__gv_get_component_path(js::config *gv_config, std::string relpath) @@ -1527,17 +1530,28 @@ std::string vp::__gv_get_component_path(js::config *gv_config, std::string relpa js::config *inc_dirs = gv_config->get("include_dirs"); std::string inc_dirs_str = ""; for (auto x: inc_dirs->get_elems()) - { - std::string inc_dir = x->get_str(); - std::string path = inc_dir + "/" + relpath + ".so"; - inc_dirs_str += inc_dirs_str == "" ? inc_dir : ":" + inc_dir; - if (std::filesystem::exists(path)) - { - return path; - } - } + { + std::string inc_dir = x->get_str(); +#if !(__APPLE__) + std::string path = inc_dir + "/" + relpath + ".so"; +#else + std::string path = inc_dir + "/" + relpath + ".dylib"; +#endif + inc_dirs_str += inc_dirs_str == "" ? inc_dir : ":" + inc_dir; +#if !(__APPLE__) + if (std::filesystem::exists(path)) + { + return path; + } +#else + if (std::__fs::filesystem::exists(path)) + { + return path; + } +#endif + } - throw std::invalid_argument("Couldn't find component (name: " + relpath + ", inc_dirs: " + inc_dirs_str ); + throw std::invalid_argument("Couldn't find component (name: " + relpath + ", inc_dirs: " + inc_dirs_str ); } @@ -1547,10 +1561,10 @@ vp::component *vp::__gv_create(std::string config_path, struct gv_conf *gv_conf) js::config *js_config = js::import_config_from_file(config_path); if (js_config == NULL) - { - fprintf(stderr, "Invalid configuration."); - return NULL; - } + { + fprintf(stderr, "Invalid configuration."); + return NULL; + } js::config *gv_config = js_config->get("target/gvsoc"); @@ -1558,44 +1572,47 @@ vp::component *vp::__gv_create(std::string config_path, struct gv_conf *gv_conf) #ifdef __M32_MODE__ if (gv_config->get_child_bool("sv-mode")) - { - module_name = "sv_m32." + module_name; - } + { + module_name = "sv_m32." + module_name; + } else if (gv_config->get_child_bool("debug-mode")) - { - module_name = "debug_m32." + module_name; - } + { + module_name = "debug_m32." + module_name; + } else - { - module_name = "m32." + module_name; - } + { + module_name = "m32." + module_name; + } #else if (gv_config->get_child_bool("sv-mode")) - { - module_name = "sv." + module_name; - } + { + module_name = "sv." + module_name; + } else if (gv_config->get_child_bool("debug-mode")) - { - module_name = "debug." + module_name; - } + { + module_name = "debug." + module_name; + } #endif std::replace(module_name.begin(), module_name.end(), '.', '/'); - std::string path = __gv_get_component_path(gv_config, module_name); - +#if (!__APPLE__) void *module = dlopen(path.c_str(), RTLD_NOW | RTLD_GLOBAL | RTLD_DEEPBIND); +#else + void *module = dlopen(path.c_str(), RTLD_NOW | RTLD_GLOBAL); +#endif + if (module == NULL) - { - throw std::invalid_argument("ERROR, Failed to open periph model (module: " + module_name + ", error: " + std::string(dlerror()) + ")"); - } + { + throw std::invalid_argument("ERROR, Failed to open periph model (module: " + module_name + ", error: " + std::string(dlerror()) + ")"); + } vp::component *(*constructor)(js::config *) = (vp::component * (*)(js::config *)) dlsym(module, "vp_constructor"); if (constructor == NULL) - { - throw std::invalid_argument("ERROR, couldn't find vp_constructor in loaded module (module: " + module_name + ")"); - } + { + throw std::invalid_argument("ERROR, couldn't find vp_constructor in loaded module (module: " + module_name + ")"); + } vp::component *instance = constructor(js_config); @@ -1636,20 +1653,20 @@ extern "C" void gv_start(void *arg) instance->build_new(); if (instance->gv_conf.open_proxy || instance->get_vp_config()->get_child_bool("proxy/enabled")) - { - int in_port = instance->gv_conf.open_proxy ? 0 : instance->get_vp_config()->get_child_int("proxy/port"); - int out_port; - proxy = new Gv_proxy(instance, instance->gv_conf.req_pipe, instance->gv_conf.reply_pipe); - if (proxy->open(in_port, &out_port)) - { - instance->throw_error("Failed to start proxy"); - } - - if (instance->gv_conf.proxy_socket) - { - *instance->gv_conf.proxy_socket = out_port; - } - } + { + int in_port = instance->gv_conf.open_proxy ? 0 : instance->get_vp_config()->get_child_int("proxy/port"); + int out_port; + proxy = new Gv_proxy(instance, instance->gv_conf.req_pipe, instance->gv_conf.reply_pipe); + if (proxy->open(in_port, &out_port)) + { + instance->throw_error("Failed to start proxy"); + } + + if (instance->gv_conf.proxy_socket) + { + *instance->gv_conf.proxy_socket = out_port; + } + } } @@ -1691,7 +1708,7 @@ extern "C" void *gv_open(const char *config_path, bool open_proxy, int *proxy_so void *instance = gv_create(config_path, &gv_conf); if (instance == NULL) - return NULL; + return NULL; gv_start(instance); @@ -1712,47 +1729,47 @@ void Gvsoc_proxy::proxy_loop() FILE *sock = fdopen(this->reply_pipe[0], "r"); while(1) - { - char line[1024]; - - if (!fgets(line, 1024, sock)) - return ; - - std::string s = std::string(line); - std::regex regex{R"([\s]+)"}; - std::sregex_token_iterator it{s.begin(), s.end(), regex, -1}; - std::vector words{it, {}}; - - if (words.size() > 0) - { - if (words[0] == "stopped") - { - int64_t timestamp = std::atoll(words[1].c_str()); - printf("GOT STOP AT %ld\n", timestamp); - this->mutex.lock(); - this->stopped_timestamp = timestamp; - this->running = false; - this->cond.notify_all(); - this->mutex.unlock(); - } - else if (words[0] == "running") - { - int64_t timestamp = std::atoll(words[1].c_str()); - printf("GOT RUN AT %ld\n", timestamp); - this->mutex.lock(); - this->running = true; - this->cond.notify_all(); - this->mutex.unlock(); - } - else if (words[0] == "req=") - { - } - else - { - printf("Ignoring invalid command: %s\n", words[0].c_str()); - } - } - } + { + char line[1024]; + + if (!fgets(line, 1024, sock)) + return ; + + std::string s = std::string(line); + std::regex regex{R"([\s]+)"}; + std::sregex_token_iterator it{s.begin(), s.end(), regex, -1}; + std::vector words{it, {}}; + + if (words.size() > 0) + { + if (words[0] == "stopped") + { + int64_t timestamp = std::atoll(words[1].c_str()); + printf("GOT STOP AT %ld\n", timestamp); + this->mutex.lock(); + this->stopped_timestamp = timestamp; + this->running = false; + this->cond.notify_all(); + this->mutex.unlock(); + } + else if (words[0] == "running") + { + int64_t timestamp = std::atoll(words[1].c_str()); + printf("GOT RUN AT %ld\n", timestamp); + this->mutex.lock(); + this->running = true; + this->cond.notify_all(); + this->mutex.unlock(); + } + else if (words[0] == "req=") + { + } + else + { + printf("Ignoring invalid command: %s\n", words[0].c_str()); + } + } + } } @@ -1761,40 +1778,44 @@ int Gvsoc_proxy::open() pid_t ppid_before_fork = getpid(); if (pipe(this->req_pipe) == -1) - return -1; + return -1; if (pipe(this->reply_pipe) == -1) - return -1; - - pid_t child_id = fork(); - - if(child_id == -1) - { - return -1; - } - else if (child_id == 0) - { - int r = prctl(PR_SET_PDEATHSIG, SIGTERM); - if (r == -1) { perror(0); exit(1); } - // test in case the original parent exited just - // before the prctl() call - if (getppid() != ppid_before_fork) exit(1); - - void *instance = gv_open(this->config_path.c_str(), true, NULL, this->req_pipe[0], this->reply_pipe[1]); - - int retval = gv_run(instance); - - gv_stop(instance, retval); - - return retval; + return -1; + + int p[2]; + int buf; + pipe(p); + pid_t child = fork(); + if(child == -1) + { + return -1; + } + if (child == 0) { + ::close(p[1]); // close write end of pipe + setpgid(0, 0); // prevent ^C in parent from stopping this process + child = fork(); + if (child == 0) { + ::close(p[0]); // close read end of pipe (don't need it here) + void *instance = gv_open(this->config_path.c_str(), true, NULL, this->req_pipe[0], this->reply_pipe[1]); + + int retval = gv_run(instance); + + gv_stop(instance, retval); + return retval; + } + read(p[0], &buf, 1); // returns when parent exits for any reason + kill(child, 9); + exit(1); } else - { - this->running = false; - this->loop_thread = new std::thread(&Gvsoc_proxy::proxy_loop, this); - } + { + this->running = false; + this->loop_thread = new std::thread(&Gvsoc_proxy::proxy_loop, this); + } return 0; + } @@ -1812,9 +1833,9 @@ int64_t Gvsoc_proxy::pause() dprintf(this->req_pipe[1], "cmd=stop\n"); std::unique_lock lock(this->mutex); while (this->running) - { - this->cond.wait(lock); - } + { + this->cond.wait(lock); + } result = this->stopped_timestamp; lock.unlock(); return result; @@ -1869,23 +1890,23 @@ int64_t vp::time_scheduler::exec() vp::time_event *current = this->first_event; while (current && current->time == this->get_time()) - { - this->first_event = current->next; - current->set_enqueued(false); + { + this->first_event = current->next; + current->set_enqueued(false); - current->meth(current->_this, current); + current->meth(current->_this, current); - current = this->first_event; - } + current = this->first_event; + } if (this->first_event == NULL) - { - return -1; - } + { + return -1; + } else - { - return this->first_event->time - this->get_time(); - } + { + return this->first_event->time - this->get_time(); + } } @@ -1899,42 +1920,42 @@ vp::time_event::time_event(time_scheduler *comp, time_event_meth_t *meth) void vp::time_scheduler::reset(bool active) { if (active) - { - for (time_event *event: this->events) - { - this->cancel(event); - } - } + { + for (time_event *event: this->events) + { + this->cancel(event); + } + } } void vp::time_scheduler::cancel(vp::time_event *event) { if (!event->is_enqueued()) - return; + return; vp::time_event *current = this->first_event, *prev = NULL; while (current && current != event) - { - prev = current; - current = current->next; - } + { + prev = current; + current = current->next; + } if (prev) - { - prev->next = event->next; - } + { + prev->next = event->next; + } else - { - this->first_event = event->next; - } + { + this->first_event = event->next; + } event->set_enqueued(false); if (this->first_event == NULL) - { - this->dequeue_from_engine(); - } + { + this->dequeue_from_engine(); + } } void vp::time_scheduler::add_event(time_event *event) @@ -1951,15 +1972,15 @@ vp::time_event *vp::time_scheduler::enqueue(time_event *event, int64_t time) event->set_enqueued(true); while (current && current->time < full_time) - { - prev = current; - current = current->next; - } + { + prev = current; + current = current->next; + } if (prev) - prev->next = event; + prev->next = event; else - this->first_event = event; + this->first_event = event; event->next = current; event->time = full_time; @@ -1975,9 +1996,9 @@ extern "C" int gv_run(void *arg) vp::component *instance = (vp::component *)top->top_instance; if (!proxy) - { - instance->run(); - } + { + instance->run(); + } return instance->join(); } @@ -1987,9 +2008,9 @@ extern "C" void gv_init(struct gv_conf *gv_conf) { gv_conf->open_proxy = 0; if (gv_conf->proxy_socket) - { - *gv_conf->proxy_socket = -1; - } + { + *gv_conf->proxy_socket = -1; + } gv_conf->req_pipe = 0; gv_conf->reply_pipe = 0; } @@ -2001,9 +2022,9 @@ extern "C" void gv_stop(void *arg, int retval) vp::component *instance = (vp::component *)top->top_instance; if (proxy) - { - proxy->stop(retval); - } + { + proxy->stop(retval); + } instance->stop_all(); diff --git a/launcher/src/launcher.cpp b/launcher/src/launcher.cpp index 0b4f0c45..c9149140 100644 --- a/launcher/src/launcher.cpp +++ b/launcher/src/launcher.cpp @@ -31,7 +31,6 @@ #include #include #include -#include #include #include #include @@ -99,23 +98,24 @@ int gv_launch(void *handle) { gv_launcher_t *gv = (gv_launcher_t *)handle; - pid_t ppid_before_fork = getpid(); - child_id = fork(); - if(child_id == -1) { - return -1; - } else if (child_id == 0) { - int r = prctl(PR_SET_PDEATHSIG, SIGTERM); - if (r == -1) { perror(0); exit(1); } - // test in case the original parent exited just - // before the prctl() call - if (getppid() != ppid_before_fork) exit(1); - gv_process(gv); - return 0; - } else { - //replyFile = fdopen(replyPipe[0], "r"); + int p[2]; + int buf; + pipe(p); + pid_t child = fork(); + if (child == 0) { + close(p[1]); // close write end of pipe + setpgid(0, 0); // prevent ^C in parent from stopping this process + child = fork(); + if (child == 0) { + close(p[0]); // close read end of pipe (don't need it here) + gv_process(gv); + exit(0); + } + read(p[0], &buf, 1); // returns when parent exits for any reason + kill(child, 9); + exit(0); } - - + return 0; } diff --git a/models/cpu/iss/flexfloat/flexfloat.h b/models/cpu/iss/flexfloat/flexfloat.h index 90a00595..721d9bf0 100644 --- a/models/cpu/iss/flexfloat/flexfloat.h +++ b/models/cpu/iss/flexfloat/flexfloat.h @@ -40,10 +40,6 @@ extern "C" { #pragma STDC FENV_ACCESS ON #endif -#ifndef __STDC_IEC_559__ -#error "Implementation not IEEE compliant" -#endif - // GCC versions before 8.2 (for sure not on 7.2, don't know when it was fixed) don't raise flags on comparisons correctly #if !defined(__GNUC__) || (defined(__GNUC__) && (__GNUC__ >= 8) && (__GNUC_MINOR__ >= 2)) #define FLEXFLOAT_CORRECT_CMP_FLAGS 1 diff --git a/models/devices/jtag/ocd_jtag_bitbang.cpp b/models/devices/jtag/ocd_jtag_bitbang.cpp index fece29fd..c2dc4ca1 100644 --- a/models/devices/jtag/ocd_jtag_bitbang.cpp +++ b/models/devices/jtag/ocd_jtag_bitbang.cpp @@ -22,7 +22,6 @@ #include #include #include -#include #include #include #include diff --git a/models/devices/testbench/i2s_verif.cpp b/models/devices/testbench/i2s_verif.cpp index d5659425..cc3a0bd6 100644 --- a/models/devices/testbench/i2s_verif.cpp +++ b/models/devices/testbench/i2s_verif.cpp @@ -26,7 +26,11 @@ #include #include "i2s_verif.hpp" #ifdef USE_SNDFILE +#if !(__APPLE__) #include +#else +#include +#endif #endif class Slot; diff --git a/models/gdbserver/rsp.cpp b/models/gdbserver/rsp.cpp index fc7cf579..379363ca 100644 --- a/models/gdbserver/rsp.cpp +++ b/models/gdbserver/rsp.cpp @@ -22,7 +22,6 @@ #include "rsp.hpp" #include "gdbserver.hpp" #include -#include #include #define DEFAULT_THREAD 9 @@ -668,7 +667,7 @@ int Rsp::open_proxy(int port) continue; } - if(bind(this->proxy_socket_in, (struct sockaddr *)&addr, sizeof(addr)) == -1) + if(::bind(this->proxy_socket_in, (struct sockaddr *)&addr, sizeof(addr)) == -1) { port++; continue; @@ -1598,4 +1597,4 @@ void Rsp_capability::parse(char *buf, size_t len, Rsp_capabilities *caps) } } -#endif \ No newline at end of file +#endif diff --git a/models/utils/CMakeLists.txt b/models/utils/CMakeLists.txt index 43ac6c2f..6e42ded0 100644 --- a/models/utils/CMakeLists.txt +++ b/models/utils/CMakeLists.txt @@ -15,9 +15,9 @@ vp_model(NAME utils.clock_impl SOURCES "clock_impl.cpp" ) -vp_model(NAME utils.dpi_chip_wrapper - FORCE_BUILD 1 - SOURCES "dpi_chip_wrapper.cpp" - ) +# vp_model(NAME utils.dpi_chip_wrapper +# FORCE_BUILD 1 +# SOURCES "dpi_chip_wrapper.cpp" +# ) -add_subdirectory(loader) \ No newline at end of file +add_subdirectory(loader)