Esempio n. 1
0
extern "C" IFace *RISCV_get_service_iface(const char *servname,
                                          const char *facename) {
    IService *iserv = static_cast<IService *>(RISCV_get_service(servname));
    if (iserv == NULL) {
        return NULL;
    }
    return iserv->getInterface(facename);
}
Esempio n. 2
0
const char *string_to_attribute(const char *cfg, 
                          AttributeType *out) {
    const char *pcur = skip_special_symbols(cfg);
   
    if (pcur[0] == '\'' || pcur[0] == '"') {
        AutoBuffer buf;
        uint8_t t1 = pcur[0];
        int str_sz = 0;
        pcur++;
        while (*pcur != t1 && *pcur != '\0') {
            pcur++;
            str_sz++;
        }
        buf.write_bin(&cfg[1], str_sz);
        pcur++;
        out->make_string(buf.getBuffer());
    } else if (pcur[0] == '[') {
        pcur++;
        pcur = skip_special_symbols(pcur);
        AttributeType new_item;
        out->make_list(0);
        while (*pcur != ']' && *pcur != '\0') {
            pcur = string_to_attribute(pcur, &new_item);
            out->realloc_list(out->size() + 1);
            (*out)[out->size() - 1] = new_item;

            pcur = skip_special_symbols(pcur);
            if (*pcur == ',') {
                pcur++;
                pcur = skip_special_symbols(pcur);
            }
        }
        pcur++;
        pcur = skip_special_symbols(pcur);
    } else if (pcur[0] == '{') {
        AttributeType new_key;
        AttributeType new_value;
        out->make_dict();

        pcur++;
        pcur = skip_special_symbols(pcur);
        while (*pcur != '}' && *pcur != '\0') {
            pcur = string_to_attribute(pcur, &new_key);
            pcur = skip_special_symbols(pcur);
            if (*pcur == ':') {
                pcur++;
            }
            pcur = skip_special_symbols(pcur);
            pcur = string_to_attribute(pcur, &new_value);

            (*out)[new_key.to_string()] = new_value;

            pcur = skip_special_symbols(pcur);
            if (*pcur == ',') {
                pcur++;
                pcur = skip_special_symbols(pcur);
            }
        }
        pcur++;
        pcur = skip_special_symbols(pcur);

        if (out->has_key("Type")) {
            if (strcmp((*out)["Type"].to_string(), IFACE_SERVICE) == 0) {
                IService *iserv; 
                iserv = static_cast<IService *>(
                        RISCV_get_service((*out)["ModuleName"].to_string()));
                out->attr_free();
                *out = AttributeType(iserv);
            } else {
                RISCV_printf(NULL, LOG_ERROR, 
                        "Not implemented string to dict. attribute");
            }
        }
    } else if (pcur[0] == '(') {
        AutoBuffer buf;
        char byte_value;
        pcur++;
        pcur = skip_special_symbols(pcur);
        while (*pcur != ')' && *pcur != '\0') {
            byte_value = 0;
            for (int n = 0; n < 2; n++) {
                if (*pcur >= 'A' && *pcur <= 'F') {
                    byte_value = (byte_value << 4) | ((*pcur - 'A') + 10);
                } else {
                    byte_value = (byte_value << 4) | (*pcur - '0');
                }
                pcur++;
            }
            buf.write_bin(&byte_value, 1);

            pcur = skip_special_symbols(pcur);
            if (*pcur == ',') {
                pcur++;
                pcur = skip_special_symbols(pcur);
            }
        }
        out->make_data(buf.size(), buf.getBuffer());
        pcur++;
        pcur = skip_special_symbols(pcur);
    } else {
        pcur = skip_special_symbols(pcur);
        if (pcur[0] == 'N' && pcur[1] == 'o' && pcur[2] == 'n'
                && pcur[3] == 'e') {
            pcur += 4;
        } else if (pcur[0] == 'f' && pcur[1] == 'a' && pcur[2] == 'l'
                && pcur[3] == 's' && pcur[4] == 'e') {
            pcur += 5;
            out->make_boolean(false);
        } else if (pcur[0] == 't' && pcur[1] == 'r' && pcur[2] == 'u'
                && pcur[3] == 'e') {
            pcur += 4;
            out->make_boolean(true);
        } else {
            char digits[32] = {0};
            int digits_cnt = 0;
            if (pcur[0] == '0' && pcur[1] == 'x') {
                pcur += 2;
                digits[digits_cnt++] = '0';
                digits[digits_cnt++] = 'x';
            }
            while ((*pcur >= '0' && *pcur <= '9') 
                || (*pcur >= 'a' && *pcur <= 'f')
                || (*pcur >= 'A' && *pcur <= 'F')) {
                digits[digits_cnt++] = *pcur++;
            }
            int64_t t1 = strtoull(digits, NULL, 0);
            out->make_int64(t1);
        }
    }
    return pcur;
}
Esempio n. 3
0
void CpuRiscV_Functional::executeInstruction(IInstruction *instr,
                                             uint32_t *rpayload) {

    CpuContextType *pContext = getpContext();
    if (pContext->reg_trace_file) {
        /** Save previous reg values to find modification after exec() */
        for (int i = 0; i < Reg_Total; i++) {
            iregs_prev[i] = pContext->regs[i];
        }
    }

    instr->exec(cacheline_, pContext);
#if 0
    //if (pContext->pc >= 0x10000000) {
    //if ((pContext->pc >= 0x100000b4 && pContext->pc <= 0x10000130)
    //|| (pContext->pc >= 0x10001ef4)
    //) 
    {
    //if (pContext->pc >= 0x10001928 && pContext->pc <= 0x10001960) {
        RISCV_debug("[%" RV_PRI64 "d] %08x: %08x \t %4s <prv=%d; mstatus=%016" RV_PRI64 "x; mcause=%016" RV_PRI64 "x; ra=%016" RV_PRI64 "x; sp=%016" RV_PRI64 "x; tp=%016" RV_PRI64 "x>", 
            getStepCounter(),
            static_cast<uint32_t>(pContext->pc),
            rpayload[0], instr->name(),
            pContext->cur_prv_level,
            pContext->csr[CSR_mstatus],
            pContext->csr[CSR_mcause],
            pContext->regs[Reg_ra],
            pContext->regs[Reg_sp],
            pContext->regs[Reg_tp]
            );
    }
#endif
    if (pContext->reg_trace_file) {
        int sz;
        sz = RISCV_sprintf(tstr, sizeof(tstr),"%8I64d [%08x] %08x: ",
            pContext->step_cnt, static_cast<uint32_t>(pContext->pc), rpayload[0]);

        bool reg_changed = false;
        for (int i = 0; i < 32; i++) {
            if (iregs_prev[i] != pContext->regs[i]) {
                reg_changed = true;
                sz += RISCV_sprintf(&tstr[sz], sizeof(tstr) - sz,
                        "%3s <= %016I64x\n", IREGS_NAMES[i], pContext->regs[i]);
            }
        }
        if (!reg_changed) {
            sz += RISCV_sprintf(&tstr[sz], sizeof(tstr) - sz, "%s", "-\n");
        }
        (*pContext->reg_trace_file) << tstr;
        pContext->reg_trace_file->flush();
    }

    if (generateRegTraceFile_.to_bool()) {
        char msg[16];
        int msg_len = 0;
        IService *uart = NULL;
        switch (pContext->step_cnt) {
        case 6000:
            uart = static_cast<IService *>(RISCV_get_service("uart0"));
            msg[0] = 'h';
            msg[1] = 'i';
            msg_len = 2;
            break;
        case 6500:
            uart = static_cast<IService *>(RISCV_get_service("uart0"));
            msg[0] = 'g';
            msg[1] = 'h';
            msg[2] = 't';
            msg_len = 3;
            break;
        case 8200:
            uart = static_cast<IService *>(RISCV_get_service("uart0"));
            msg[0] = 'i';
            msg[1] = 'c';
            msg_len = 2;
            break;
        case 8300:
            uart = static_cast<IService *>(RISCV_get_service("uart0"));
            msg[0] = 'k';
            msg[1] = 's';
            msg[2] = '\r';
            msg[3] = '\n';
            msg_len = 4;
            break;
        default:;
        }

        if (uart) {
            ISerial *iserial = static_cast<ISerial *>(
                        uart->getInterface(IFACE_SERIAL));
            //iserial->writeData("pnp\r\n", 6);
            //iserial->writeData("highticks\r\n", 11);
            iserial->writeData(msg, msg_len);
        }
    }


    if (pContext->regs[0] != 0) {
        RISCV_error("Register x0 was modificated (not equal to zero)", NULL);
    }
}