OpenCores
URL https://opencores.org/ocsvn/riscv_vhdl/riscv_vhdl/trunk

Subversion Repositories riscv_vhdl

[/] [riscv_vhdl/] [trunk/] [debugger/] [src/] [libdbg64g/] [api_core.cpp] - Diff between revs 3 and 4

Show entire file | Details | Blame | View Log

Rev 3 Rev 4
Line 1... Line 1...
/**
/*
 * @file
 *  Copyright 2018 Sergey Khabarov, sergeykhbr@gmail.com
 * @copyright  Copyright 2016 GNSS Sensor Ltd. All right reserved.
 *
 * @author     Sergey Khabarov - sergeykhbr@gmail.com
 *  Licensed under the Apache License, Version 2.0 (the "License");
 * @brief      Core API methods implementation.
 *  you may not use this file except in compliance with the License.
 
 *  You may obtain a copy of the License at
 
 *
 
 *      http://www.apache.org/licenses/LICENSE-2.0
 
 *
 
 *  Unless required by applicable law or agreed to in writing, software
 
 *  distributed under the License is distributed on an "AS IS" BASIS,
 
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
 *  See the License for the specific language governing permissions and
 
 *  limitations under the License.
 */
 */
 
 
#include <string>
#include <string>
#include "api_core.h"
#include "api_core.h"
#include "api_types.h"
#include "api_types.h"
Line 44... Line 53...
    void setExiting() { RISCV_event_set(&mutexExiting_); }
    void setExiting() { RISCV_event_set(&mutexExiting_); }
private:
private:
    int active_;
    int active_;
    event_def mutexExiting_;
    event_def mutexExiting_;
};
};
static CoreService core_("core");
static CoreService *pcore_ = NULL;
 
 
 
 
IFace *getInterface(const char *name) {
IFace *getInterface(const char *name) {
    return core_.getInterface(name);
    return pcore_->getInterface(name);
}
}
 
 
 
 
extern "C" int RISCV_init() {
extern "C" int RISCV_init() {
 
    pcore_ = new CoreService("core");
 
 
#if defined(_WIN32) || defined(__CYGWIN__)
#if defined(_WIN32) || defined(__CYGWIN__)
    WSADATA wsaData;
    WSADATA wsaData;
    if (WSAStartup(MAKEWORD(2, 2), &wsaData)) {
    if (WSAStartup(MAKEWORD(2, 2), &wsaData)) {
        RISCV_error("Can't initialize sockets library", NULL);
        RISCV_error("Can't initialize sockets library", NULL);
    }
    }
Line 82... Line 93...
    _unload_plugins(&listPlugins_);
    _unload_plugins(&listPlugins_);
    RISCV_mutex_lock(&mutex_printf);
    RISCV_mutex_lock(&mutex_printf);
    RISCV_mutex_destroy(&mutex_printf);
    RISCV_mutex_destroy(&mutex_printf);
    RISCV_mutex_lock(&mutexDefaultConsoles_);
    RISCV_mutex_lock(&mutexDefaultConsoles_);
    RISCV_mutex_destroy(&mutexDefaultConsoles_);
    RISCV_mutex_destroy(&mutexDefaultConsoles_);
 
    delete pcore_;
    RISCV_disable_log();
    RISCV_disable_log();
}
}
 
 
extern "C" int RISCV_set_configuration(AttributeType *cfg) {
extern "C" int RISCV_set_configuration(AttributeType *cfg) {
    IClass *icls;
    IClass *icls;
    IService *iserv;
    IService *iserv;
 
 
    Config_.clone(cfg);
    Config_.clone(cfg);
    if (!Config_.is_dict()) {
    if (!Config_.is_dict()) {
        RISCV_error("Wrong configuration.", NULL);
        printf("Wrong configuration.\n");
        return -1;
        return -1;
    }
    }
 
 
    AttributeType &Services = Config_["Services"];
    AttributeType &Services = Config_["Services"];
    if (Services.is_list()) {
    if (Services.is_list()) {
        for (unsigned i = 0; i < Services.size(); i++) {
        for (unsigned i = 0; i < Services.size(); i++) {
            icls = static_cast<IClass *>(
            const char *clsname = Services[i]["Class"].to_string();
                RISCV_get_class(Services[i]["Class"].to_string()));
            icls = static_cast<IClass *>(RISCV_get_class(clsname));
            if (icls == NULL) {
            if (icls == NULL) {
                RISCV_error("Class %s not found",
                printf("Class %s not found\n",
                             Services[i]["Class"].to_string());
                             Services[i]["Class"].to_string());
                return -1;
                return -1;
            }
            }
            /** Special global setting for the GUI class: */
            /** Special global setting for the GUI class: */
            if (strcmp(icls->getClassName(), "GuiPluginClass") == 0) {
            if (strcmp(icls->getClassName(), "GuiPluginClass") == 0) {
Line 129... Line 141...
        icls->postinitServices();
        icls->postinitServices();
    }
    }
 
 
    RISCV_printf(getInterface(IFACE_SERVICE), 0, "%s",
    RISCV_printf(getInterface(IFACE_SERVICE), 0, "%s",
    "\n**********************************************************\n"
    "\n**********************************************************\n"
    "  RISC-V debugger\n"
    "  System Emulator and Debugger\n"
    "  Author: Sergey Khabarov - sergeykhbr@gmail.com\n"
    "  Copyright (c) 2017 Sergey Khabarov.\n"
    "  Copyright 2016 GNSS Sensor Ltd. All right reserved.\n"
    "  All rights reserved.\n"
 
    "  e-mail: sergeykhbr@gmail.com\n"
    "**********************************************************");
    "**********************************************************");
 
 
    IHap *ihap;
    IHap *ihap;
    for (unsigned i = 0; i < listHap_.size(); i++) {
    for (unsigned i = 0; i < listHap_.size(); i++) {
        ihap = static_cast<IHap *>(listHap_[i].to_iface());
        ihap = static_cast<IHap *>(listHap_[i].to_iface());
Line 145... Line 158...
        }
        }
    }
    }
    return 0;
    return 0;
}
}
 
 
extern "C" const char *RISCV_get_configuration() {
extern "C" void RISCV_get_configuration(AttributeType *cfg) {
    IClass *icls;
    IClass *icls;
    AttributeType ret(Attr_Dict);
    cfg->make_dict();
    ret["GlobalSettings"] = Config_["GlobalSettings"];
    (*cfg)["GlobalSettings"] = Config_["GlobalSettings"];
    ret["Services"].make_list(0);
    (*cfg)["Services"].make_list(0);
    for (unsigned i = 0; i < listClasses_.size(); i++) {
    for (unsigned i = 0; i < listClasses_.size(); i++) {
        icls = static_cast<IClass *>(listClasses_[i].to_iface());
        icls = static_cast<IClass *>(listClasses_[i].to_iface());
        AttributeType val = icls->getConfiguration();
        AttributeType val = icls->getConfiguration();
        ret["Services"].add_to_list(&val);
        (*cfg)["Services"].add_to_list(&val);
    }
    }
    return ret.to_config();
    cfg->to_config();
}
}
 
 
extern "C" const AttributeType *RISCV_get_global_settings() {
extern "C" const AttributeType *RISCV_get_global_settings() {
    return &Config_["GlobalSettings"];
    return &Config_["GlobalSettings"];
}
}
Line 178... Line 191...
                                  const char *descr) {
                                  const char *descr) {
    IHap *ihap;
    IHap *ihap;
    EHapType etype = static_cast<EHapType>(type);
    EHapType etype = static_cast<EHapType>(type);
    for (unsigned i = 0; i < listHap_.size(); i++) {
    for (unsigned i = 0; i < listHap_.size(); i++) {
        ihap = static_cast<IHap *>(listHap_[i].to_iface());
        ihap = static_cast<IHap *>(listHap_[i].to_iface());
        if (ihap->getType() == etype) {
        if (ihap->getType() == HAP_All || ihap->getType() == etype) {
            ihap->hapTriggered(isrc, etype, descr);
            ihap->hapTriggered(isrc, etype, descr);
        }
        }
    }
    }
}
}
 
 
Line 227... Line 240...
        return NULL;
        return NULL;
    }
    }
    return iserv->getInterface(facename);
    return iserv->getInterface(facename);
}
}
 
 
 
extern "C" IFace *RISCV_get_service_port_iface(const char *servname,
 
                                               const char *portname,
 
                                               const char *facename) {
 
    IService *iserv = static_cast<IService *>(RISCV_get_service(servname));
 
    if (iserv == NULL) {
 
        RISCV_error("Service '%s' not found.", servname);
 
        return NULL;
 
    }
 
    return iserv->getPortInterface(portname, facename);
 
}
 
 
extern "C" void RISCV_get_services_with_iface(const char *iname,
extern "C" void RISCV_get_services_with_iface(const char *iname,
                                             AttributeType *list) {
                                             AttributeType *list) {
    IClass *icls;
    IClass *icls;
    IService *iserv;
    IService *iserv;
    IFace *iface;
    IFace *iface;
Line 238... Line 262...
    list->make_list(0);
    list->make_list(0);
 
 
    for (unsigned i = 0; i < listClasses_.size(); i++) {
    for (unsigned i = 0; i < listClasses_.size(); i++) {
        icls = static_cast<IClass *>(listClasses_[i].to_iface());
        icls = static_cast<IClass *>(listClasses_[i].to_iface());
        tlist = icls->getInstanceList();
        tlist = icls->getInstanceList();
        if (tlist->size()) {
        for (unsigned n = 0; n < tlist->size(); n++) {
            iserv = static_cast<IService *>((*tlist)[0u].to_iface());
            iserv = static_cast<IService *>((*tlist)[n].to_iface());
            iface = iserv->getInterface(iname);
            iface = iserv->getInterface(iname);
            if (iface) {
            if (iface) {
                AttributeType t1(iserv);
                AttributeType t1(iserv);
                list->add_to_list(&t1);
                list->add_to_list(&t1);
            }
            }
Line 275... Line 299...
    }
    }
 
 
    RISCV_trigger_hap(getInterface(IFACE_SERVICE),
    RISCV_trigger_hap(getInterface(IFACE_SERVICE),
                      HAP_BreakSimulation, "Exiting");
                      HAP_BreakSimulation, "Exiting");
    printf("All threads were stopped!\n");
    printf("All threads were stopped!\n");
    core_.shutdown();
    pcore_->shutdown();
    return 0;
    return 0;
}
}
 
 
struct TimerType {
struct TimerType {
    timer_callback_type cb;
    timer_callback_type cb;
Line 291... Line 315...
 
 
static const int TIMERS_MAX = 2;
static const int TIMERS_MAX = 2;
static TimerType timers_[TIMERS_MAX] = {{0}};
static TimerType timers_[TIMERS_MAX] = {{0}};
 
 
extern "C" void RISCV_break_simulation() {
extern "C" void RISCV_break_simulation() {
    if (core_.isExiting()) {
    if (pcore_->isExiting()) {
        return;
        return;
    }
    }
    core_.setExiting();
    pcore_->setExiting();
    LibThreadType data;
    LibThreadType data;
    data.func = reinterpret_cast<lib_thread_func>(safe_exit_thread);
    data.func = reinterpret_cast<lib_thread_func>(safe_exit_thread);
    data.args = 0;
    data.args = 0;
    RISCV_thread_create(&data);
    RISCV_thread_create(&data);
}
}
Line 306... Line 330...
 
 
extern "C" void RISCV_dispatcher_start() {
extern "C" void RISCV_dispatcher_start() {
    TimerType *tmr;
    TimerType *tmr;
    int sleep_interval = 20;
    int sleep_interval = 20;
    int delta;
    int delta;
    while (core_.isActive()) {
    while (pcore_->isActive()) {
        delta = 20;
        delta = 20;
        for (int i = 0; i < TIMERS_MAX; i++) {
        for (int i = 0; i < TIMERS_MAX; i++) {
            tmr = &timers_[i];
            tmr = &timers_[i];
            if (!tmr->cb || !tmr->interval) {
            if (!tmr->cb || !tmr->interval) {
                continue;
                continue;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.