예제 #1
0
void CpuRiscV_Functional::updatePipeline() {
    IInstruction *instr;
    CpuContextType *pContext = getpContext();

    if (dport.valid) {
        dport.valid = 0;
        updateDebugPort();
    }

    pContext->pc = pContext->npc;
    if (isRunning()) {
        fetchInstruction();
    }

    updateState();
    if (pContext->reset) {
        updateQueue();
        reset();
        return;
    } 

    instr = decodeInstruction(cacheline_);
    if (isRunning()) {
        last_hit_breakpoint_ = ~0;
        if (instr) {
            executeInstruction(instr, cacheline_);
        } else {
            pContext->npc += 4;
            generateException(EXCEPTION_InstrIllegal, pContext);

            RISCV_info("[%" RV_PRI64 "d] pc:%08x: %08x \t illegal instruction",
                        getStepCounter(),
                        static_cast<uint32_t>(pContext->pc), cacheline_[0]);
        }
    }

    updateQueue();

    handleTrap();
}
예제 #2
0
int UdpService::createDatagramSocket() {
    char hostName[256];
    if(gethostname(hostName, sizeof(hostName)) < 0) {
        return -1;
    }

    struct addrinfo hints;
    memset(&hints, 0, sizeof(hints));
    hints.ai_family = AF_UNSPEC;
    hints.ai_socktype = SOCK_STREAM;
    hints.ai_protocol = IPPROTO_TCP;

    /**
     * Check availability of IPv4 address assigned via attribute 'hostIP'.
     * If it woudn't be found use the last avaialble IP address.
     */
    bool host_ip_found = false;
    int retval;
    struct addrinfo *result = NULL;
    struct addrinfo *ptr = NULL;
    retval = getaddrinfo(hostName, "0", &hints, &result);
    if (retval != 0) {
        return -1;
    }

    for (ptr = result; ptr != NULL; ptr = ptr->ai_next) {
        // Find only IPV4 address, ignore others.
        if (ptr->ai_family != AF_INET) {
            continue;
        }
        sockaddr_ipv4_ = *((struct sockaddr_in *)ptr->ai_addr);
        RISCV_sprintf(sockaddr_ipv4_str_, sizeof(sockaddr_ipv4_str_), 
                    "%s", inet_ntoa(sockaddr_ipv4_.sin_addr));

        if (strcmp(inet_ntoa(sockaddr_ipv4_.sin_addr), 
                   hostIP_.to_string()) == 0) {
            host_ip_found = true;
            break;
        }
    }

    if (!host_ip_found) {
        RISCV_info("Selected IPv4 %s", inet_ntoa(sockaddr_ipv4_.sin_addr));
    } else {
#if 1
        /** jrkk proposal to hardcode IP address in a such way. No difference. */
        memset(&sockaddr_ipv4_, 0, sizeof (sockaddr_ipv4_));
        sockaddr_ipv4_.sin_family = AF_INET;
        inet_pton(AF_INET, hostIP_.to_string(), &(sockaddr_ipv4_.sin_addr));
#endif
    }

    hsock_ = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
    if (hsock_ < 0) {
        RISCV_error("%s", "Error: socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)");
        return -1;
    }

    int res = bind(hsock_, (struct sockaddr *)&sockaddr_ipv4_, 
                              sizeof(sockaddr_ipv4_));
    if (res != 0) {
        RISCV_error("Error: bind(hsock_, \"%s\", ...)", hostIP_.to_string());
        return -1;
    }

    addr_size_t addr_sz = sizeof(sockaddr_ipv4_);
    res = getsockname(hsock_, (struct sockaddr *)&sockaddr_ipv4_, &addr_sz);
    sockaddr_ipv4_port_ = ntohs(sockaddr_ipv4_.sin_port);

    RISCV_info("\tIPv4 address %s:%d . . . opened", 
                sockaddr_ipv4_str_, sockaddr_ipv4_port_);

    return 0;
}
예제 #3
0
void UART::transaction(Axi4TransactionType *payload) {
    uint64_t mask = (length_.to_uint64() - 1);
    uint64_t off = ((payload->addr - getBaseAddress()) & mask) / 4;
    char wrdata;
    if (payload->rw) {
        for (uint64_t i = 0; i < payload->xsize/4; i++) {
            if ((payload->wstrb & (0xf << 4*i)) == 0) {
                continue;
            }
            switch (off + i) {
            case 0:
                wrdata = static_cast<char>(payload->wpayload[i]);
                RISCV_info("Set data = %s", &regs_.data);
                for (unsigned n = 0; n < listeners_.size(); n++) {
                    IRawListener *lstn = static_cast<IRawListener *>(
                                        listeners_[n].to_iface());

                    lstn->updateData(&wrdata, 1);
                }
                break;
            case 1:
                regs_.status = payload->wpayload[i];
                RISCV_info("Set status = %08x", regs_.status);
                break;
            case 2:
                regs_.scaler = payload->wpayload[i];
                RISCV_info("Set scaler = %d", regs_.scaler);
                break;
            default:;
            }
        }
    } else {
        for (uint64_t i = 0; i < payload->xsize/4; i++) {
            switch (off + i) {
            case 0:
                if (rx_total_ == 0) {
                    payload->rpayload[i] = 0;
                } else {
                    payload->rpayload[i] = *p_rx_rd_;
                    rx_total_--;
                    if ((++p_rx_rd_) >= (rxfifo_ + RX_FIFO_SIZE)) {
                        p_rx_rd_ = rxfifo_;
                    }
                }
                RISCV_debug("Get data = %02x", (payload->rpayload[i] & 0xFF));
                break;
            case 1:
                regs_.status = UART_STATUS_TX_EMPTY;
                if (rx_total_ == 0) {
                    regs_.status |= UART_STATUS_RX_EMPTY;
                }
                payload->rpayload[i] = regs_.status;
                RISCV_info("Get status = %08x", regs_.status);
                break;
            case 2:
                payload->rpayload[i] = regs_.scaler;
                RISCV_info("Get scaler = %d", regs_.scaler);
                break;
            default:
                payload->rpayload[i] = ~0;
            }
        }
    }
}