/**************************************************************/ /* sim_conv.cpp Date: 2018/10/22 */ /* */ /* Copyright (c) 2018 GIS. All rights reserved. */ /* */ /**************************************************************/ // -------------------------------------------------- // INCLUDES // -------------------------------------------------- #include #include #include #include #include #include #include #include "sim_conv.h" // -------------------------------------------------- // LOCAL DEFINITIONS // -------------------------------------------------- // -------------------------------------------------- // GLOBAL VARIABLES // -------------------------------------------------- static volatile uint32_t* phyMemBase = 0; static volatile uint32_t* virtMemBase = 0; static int node = 0; // -------------------------------------------------- // Set the base addresses to use by support functions // -------------------------------------------------- void setMemBaseAddr(uint32_t* paddr, uint32_t* vaddr) { phyMemBase = paddr; virtMemBase = vaddr; } // -------------------------------------------------- // Simulation control functions // -------------------------------------------------- void usleepSim(unsigned time) { if (time > 0) { usleep(time); } } // -------------------------------------------------- // This function is the host support for memory word // reads, to the spec. of the mem_model used in // simulation // -------------------------------------------------- uint32_t ReadRamWord (const uint64_t addr, const int le, const uint32_t nodeIn) { // nodeIn parameter not used, but remember last node value passed in to use // for any subsequence read_ext() or write_ext() calls. node = nodeIn; // check upper bits of the address match the physical address location. if ((addr & 0xff000000) != (uint32_t)phyMemBase) { fprintf(stderr, "ReadRamWord: ERROR addr out of range! (addr=0x%08x phyMemBase=0x%08x)\n", (uint32_t)addr, (uint32_t)phyMemBase); return 0; } volatile uint32_t* raddr = (virtMemBase + ((uint32_t)addr & 0xffffff)/4); //printf("addr=%08x raddr=%08x *raddr=%08x\n", (uint32_t)addr, (uint32_t)raddr, *raddr); // Read the data from the virtual memory address mapped to the physical buffer, and return return *raddr; } // -------------------------------------------------- // This function is the host support for memory word // writes, to the spec. of the mem_model used in // simulation. // -------------------------------------------------- void WriteRamWord (const uint64_t addr, const uint32_t data, const int le, const uint32_t nodeIn) { // nodeIn parameter not used, but remember last node value passed in to use // for any subsequence read_ext() or write_ext() calls. node = nodeIn; // Check upper bits of the address match the physical address location. if ((addr & 0xff000000) != (uint32_t)phyMemBase) { fprintf(stderr, "WriteRamWord: ERROR addr out of range!\n"); return; } volatile uint32_t* waddr = (virtMemBase + ((uint32_t)addr & 0xffffff)/4); *waddr = data; //printf("addr=%08x waddr=%08x data=%08x\n", (uint32_t)addr, (uint32_t)waddr, data); } // --------------------------------------------------- // This function is the host support for memory word // writes, to the spec. of the external methods needed // by VProc // --------------------------------------------------- void write_ext (uint32_t addr, uint32_t data) { WriteRamWord (addr, data, MEM_MODEL_DEFAULT_ENDIAN, node); } // --------------------------------------------------- // This function is the host support for memory word // reads, to the spec. of the external methods needed // by VProc // --------------------------------------------------- uint32_t read_ext (uint32_t addr, uint32_t* data) { *data = ReadRamWord (addr, MEM_MODEL_DEFAULT_ENDIAN, node); return 0; }