| 1 |
4 |
sergeykhbr |
/*
|
| 2 |
|
|
* Copyright 2018 Sergey Khabarov, sergeykhbr@gmail.com
|
| 3 |
|
|
*
|
| 4 |
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
| 5 |
|
|
* you may not use this file except in compliance with the License.
|
| 6 |
|
|
* You may obtain a copy of the License at
|
| 7 |
|
|
*
|
| 8 |
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
| 9 |
|
|
*
|
| 10 |
|
|
* Unless required by applicable law or agreed to in writing, software
|
| 11 |
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
| 12 |
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 13 |
|
|
* See the License for the specific language governing permissions and
|
| 14 |
|
|
* limitations under the License.
|
| 15 |
|
|
*/
|
| 16 |
|
|
|
| 17 |
|
|
#include "api_core.h"
|
| 18 |
|
|
#include "iservice.h"
|
| 19 |
|
|
#include "coreservices/ilink.h"
|
| 20 |
|
|
#include "coreservices/ithread.h"
|
| 21 |
|
|
#include "coreservices/icpugen.h"
|
| 22 |
|
|
#include "coreservices/icpuriscv.h"
|
| 23 |
|
|
/** Plugin verification */
|
| 24 |
|
|
#include "simple_plugin/isimple_plugin.h"
|
| 25 |
|
|
#include <stdio.h>
|
| 26 |
|
|
#include <string>
|
| 27 |
|
|
|
| 28 |
|
|
using namespace debugger;
|
| 29 |
|
|
|
| 30 |
|
|
static AttributeType Config;
|
| 31 |
|
|
|
| 32 |
|
|
const AttributeType *getConfigOfService(const AttributeType &cfg,
|
| 33 |
|
|
const char *name) {
|
| 34 |
|
|
const AttributeType &serv = cfg["Services"];
|
| 35 |
|
|
for (unsigned i = 0; i < serv.size(); i++) {
|
| 36 |
|
|
const AttributeType &inst = serv[i]["Instances"];
|
| 37 |
|
|
for (unsigned n = 0; n < inst.size(); n++) {
|
| 38 |
|
|
if (strcmp(inst[n]["Name"].to_string(), name) == 0) {
|
| 39 |
|
|
return &inst[n];
|
| 40 |
|
|
}
|
| 41 |
|
|
}
|
| 42 |
|
|
}
|
| 43 |
|
|
return 0;
|
| 44 |
|
|
}
|
| 45 |
|
|
|
| 46 |
|
|
int main(int argc, char* argv[]) {
|
| 47 |
|
|
AttributeType scriptFile("");
|
| 48 |
|
|
AttributeType databuf;
|
| 49 |
|
|
|
| 50 |
|
|
RISCV_init();
|
| 51 |
|
|
RISCV_set_current_dir();
|
| 52 |
|
|
|
| 53 |
|
|
// Parse arguments:
|
| 54 |
|
|
if (argc > 1) {
|
| 55 |
|
|
for (int i = 1; i < argc; i++) {
|
| 56 |
|
|
if (strcmp(argv[i], "-c") == 0) {
|
| 57 |
|
|
i++;
|
| 58 |
|
|
RISCV_read_json_file(argv[i], &databuf);
|
| 59 |
|
|
} else if (strcmp(argv[i], "-script") == 0) {
|
| 60 |
|
|
i++;
|
| 61 |
|
|
scriptFile.make_string(argv[i]);
|
| 62 |
|
|
}
|
| 63 |
|
|
}
|
| 64 |
|
|
}
|
| 65 |
|
|
|
| 66 |
|
|
if (databuf.size() == 0) {
|
| 67 |
|
|
printf("Error: Platform script file not defined\n");
|
| 68 |
|
|
printf(" Use -c key to specify configuration file location:\n");
|
| 69 |
|
|
printf("Example: appdbg64.exe -c ../../targets/default.json\n");
|
| 70 |
|
|
return 0;
|
| 71 |
|
|
}
|
| 72 |
|
|
|
| 73 |
|
|
Config.from_config(databuf.to_string());
|
| 74 |
|
|
Config["GlobalSettings"]["ScriptFile"] = scriptFile;
|
| 75 |
|
|
|
| 76 |
|
|
if (RISCV_set_configuration(&Config)) {
|
| 77 |
|
|
printf("Error: can't instantiate configuration\n");
|
| 78 |
|
|
return 0;
|
| 79 |
|
|
}
|
| 80 |
|
|
|
| 81 |
|
|
// Connect simulator to the EDCL debugger if enabled:
|
| 82 |
|
|
if (Config["GlobalSettings"]["SimEnable"].to_bool()) {
|
| 83 |
|
|
ILink *iudp1 = static_cast<ILink *>
|
| 84 |
|
|
(RISCV_get_service_iface("udpboard", IFACE_LINK));
|
| 85 |
|
|
ILink *iudp2 = static_cast<ILink *>
|
| 86 |
|
|
(RISCV_get_service_iface("udpedcl", IFACE_LINK));
|
| 87 |
|
|
|
| 88 |
|
|
AttributeType t1;
|
| 89 |
|
|
iudp1->getConnectionSettings(&t1);
|
| 90 |
|
|
iudp2->setConnectionSettings(&t1);
|
| 91 |
|
|
iudp2->getConnectionSettings(&t1);
|
| 92 |
|
|
iudp1->setConnectionSettings(&t1);
|
| 93 |
|
|
}
|
| 94 |
|
|
|
| 95 |
|
|
IService *itst = static_cast<IService *>(RISCV_get_service("example0"));
|
| 96 |
|
|
if (itst == NULL) {
|
| 97 |
|
|
/**
|
| 98 |
|
|
* @brief Create instance of the example plugin class.
|
| 99 |
|
|
*/
|
| 100 |
|
|
IFace *simple = RISCV_get_class("SimplePluginClass");
|
| 101 |
|
|
if (simple) {
|
| 102 |
|
|
itst = static_cast<IService *>(RISCV_create_service(
|
| 103 |
|
|
simple, "example0", NULL));
|
| 104 |
|
|
}
|
| 105 |
|
|
}
|
| 106 |
|
|
|
| 107 |
|
|
/**
|
| 108 |
|
|
* Unreset all CPUs
|
| 109 |
|
|
*/
|
| 110 |
|
|
/*AttributeType cpu_list;
|
| 111 |
|
|
RISCV_get_services_with_iface(IFACE_CPU_RISCV, &cpu_list);
|
| 112 |
|
|
for (unsigned i = 0; i < cpu_list.size(); i++) {
|
| 113 |
|
|
IService *iserv = static_cast<IService *>(cpu_list[i].to_iface());
|
| 114 |
|
|
ICpuGeneric *icpu = static_cast<ICpuGeneric *>(
|
| 115 |
|
|
iserv->getInterface(IFACE_CPU_GENERIC));
|
| 116 |
|
|
icpu->lowerSignal(CPU_SIGNAL_RESET); // Active HIGH. Unreset CPU model.
|
| 117 |
|
|
}*/
|
| 118 |
|
|
|
| 119 |
|
|
if (itst != NULL) {
|
| 120 |
|
|
/** Get plugin specific interface. */
|
| 121 |
|
|
ISimplePlugin * itst_access = static_cast<ISimplePlugin *>(
|
| 122 |
|
|
itst->getInterface(IFACE_SIMPLE_PLUGIN));
|
| 123 |
|
|
/** Call example method */
|
| 124 |
|
|
itst_access->exampleAction(0xcafe);
|
| 125 |
|
|
}
|
| 126 |
|
|
|
| 127 |
|
|
RISCV_dispatcher_start();
|
| 128 |
|
|
|
| 129 |
|
|
//const char *t1 = RISCV_get_configuration();
|
| 130 |
|
|
//RISCV_write_json_file(configFile.to_string(), t1);
|
| 131 |
|
|
RISCV_cleanup();
|
| 132 |
|
|
return 0;
|
| 133 |
|
|
}
|