From 75f6b78daf3b7b8a0d0cc870965e645c50c408e2 Mon Sep 17 00:00:00 2001 From: Charles Papon Date: Wed, 24 May 2017 23:53:31 +0200 Subject: [PATCH] OpenOCD successfuly connected to target --- .../SpinalRiscv/Plugin/DebugPlugin.scala | 6 ++- src/test/cpp/regression/main.cpp | 52 ++++++++++++++++--- src/test/cpp/regression/makefile | 12 ++++- .../resources/hex/debugPluginExternal.hex | 39 ++++++++++++++ 4 files changed, 98 insertions(+), 11 deletions(-) create mode 100644 src/test/resources/hex/debugPluginExternal.hex diff --git a/src/main/scala/SpinalRiscv/Plugin/DebugPlugin.scala b/src/main/scala/SpinalRiscv/Plugin/DebugPlugin.scala index 6aa9d20..3f70a9a 100644 --- a/src/main/scala/SpinalRiscv/Plugin/DebugPlugin.scala +++ b/src/main/scala/SpinalRiscv/Plugin/DebugPlugin.scala @@ -138,8 +138,10 @@ class DebugPlugin(debugClockDomain : ClockDomain) extends Plugin[VexRiscv] { io.resetOut := RegNext(resetIt) - when(haltIt || stepIt) { - service(classOf[InterruptionInhibitor]).inhibateInterrupts() + if(serviceExist(classOf[InterruptionInhibitor])) { + when(haltIt || stepIt) { + service(classOf[InterruptionInhibitor]).inhibateInterrupts() + } } }} } diff --git a/src/test/cpp/regression/main.cpp b/src/test/cpp/regression/main.cpp index cf16d7e..b8d2ce5 100644 --- a/src/test/cpp/regression/main.cpp +++ b/src/test/cpp/regression/main.cpp @@ -17,6 +17,13 @@ #include +#include + +struct timespec timer_get(){ + struct timespec start_time; + clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start_time); + return start_time; +} class Memory{ public: @@ -157,6 +164,8 @@ public: VVexRiscv* top; bool resetDone = false; int i; + double cyclesPerSecond = 10e6; + double allowedCycles = 0.0; uint32_t bootPc = -1; uint32_t iStall = 1,dStall = 1; #ifdef TRACE @@ -171,15 +180,20 @@ public: ofstream memTraces; ofstream logTraces; + struct timespec start_time; + Workspace(string name){ testsCounter++; this->name = name; top = new VVexRiscv; - regTraces.open (name + ".regTrace"); - memTraces.open (name + ".memTrace"); + #ifdef TRACE_ACCESS + regTraces.open (name + ".regTrace"); + memTraces.open (name + ".memTrace"); + #endif logTraces.open (name + ".logTrace"); fillSimELements(); + clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &start_time); } virtual ~Workspace(){ @@ -198,6 +212,11 @@ public: return this; } + Workspace* setCyclesPerSecond(double value){ + cyclesPerSecond = value; + return this; + } + Workspace* bootAt(uint32_t pc) { bootPc = pc;} @@ -326,9 +345,21 @@ public: if(bootPc != -1) top->VexRiscv->prefetch_PcManagerSimplePlugin_pcReg = bootPc; #endif + try { // run simulation for 100 clock periods for (i = 16; i < timeout*2; i+=2) { + while(allowedCycles <= 0.0){ + struct timespec end_time; + clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &end_time); + uint64_t diffInNanos = end_time.tv_sec*1e9 + end_time.tv_nsec - start_time.tv_sec*1e9 - start_time.tv_nsec; + start_time = end_time; + double dt = diffInNanos*1e-9; + allowedCycles += dt*cyclesPerSecond; + if(allowedCycles > cyclesPerSecond/100) allowedCycles = cyclesPerSecond/100; + } + allowedCycles-=1.0; + #ifndef REF_TIME mTime = i/2; #endif @@ -596,8 +627,8 @@ public: #include #include #include - #include + /** Returns true on success, or false if there was an error */ bool SetSocketBlockingEnabled(int fd, bool blocking) { @@ -644,7 +675,7 @@ public: // Address family = Internet // serverAddr.sin_family = AF_INET; // Set port number, using htons function to use proper byte order // - serverAddr.sin_port = htons(7891); + serverAddr.sin_port = htons(7893); // Set IP address to localhost // serverAddr.sin_addr.s_addr = inet_addr("127.0.0.1"); // Set all bits of the padding field to 0 // @@ -688,6 +719,8 @@ public: virtual void preCycle(){ if(clientHandle == -1){ clientHandle = accept(serverSocket, (struct sockaddr *) &serverStorage, &addr_size); + if(clientHandle != -1) + printf("CONNECTED\n"); } @@ -962,7 +995,6 @@ public: void clientThread(){ struct sockaddr_in serverAddr; - socklen_t addr_size; //---- Create the socket. The three arguments are: ----// // 1) Internet domain 2) Stream socket 3) Default protocol (TCP in this case) // @@ -972,20 +1004,21 @@ public: // Address family = Internet // serverAddr.sin_family = AF_INET; // Set port number, using htons function to use proper byte order // - serverAddr.sin_port = htons(7891); + serverAddr.sin_port = htons(7893); // Set IP address to localhost // serverAddr.sin_addr.s_addr = inet_addr("127.0.0.1"); // Set all bits of the padding field to 0 // memset(serverAddr.sin_zero, '\0', sizeof serverAddr.sin_zero); //---- Connect the socket to the server using the address struct ----// - addr_size = sizeof serverAddr; + socklen_t addr_size = sizeof serverAddr; int error = connect(clientSocket, (struct sockaddr *) &serverAddr, addr_size); // printf("!! %x\n",readCmd(2,0x8)); uint32_t debugAddress = 0xFFF00000; uint32_t readValue; while(resetDone != true){usleep(100);} + while((readCmd(2,debugAddress) & RISCV_SPINAL_FLAGS_HALT) == 0){usleep(100);} if((readValue = readCmd(2,debugAddress + 4)) != 0x0000000C){ printf("wrong break PC %x\n",readValue); @@ -1128,7 +1161,6 @@ string riscvTestDiv[] = { "rv32um-p-remu" }; -#include struct timespec timer_start(){ struct timespec start_time; @@ -1155,6 +1187,10 @@ int main(int argc, char **argv, char **env) { for(int idx = 0;idx < 1;idx++){ #ifndef REF + #ifdef DEBUG_PLUGIN_EXTERNAL + Workspace("debugPluginExternal").loadHex("../../resources/hex/debugPluginExternal.hex")->noInstructionReadCheck()->setCyclesPerSecond(5e3)->run(1e9); + #endif + TestA().run(); diff --git a/src/test/cpp/regression/makefile b/src/test/cpp/regression/makefile index 131aeaf..322550b 100644 --- a/src/test/cpp/regression/makefile +++ b/src/test/cpp/regression/makefile @@ -1,10 +1,12 @@ IBUS=IBUS_CACHED DBUS=DBUS_CACHED -TRACE=no +TRACE=yes +TRACE_ACCESS=yes TRACE_START=0 CSR=yes MMU=yes DEBUG_PLUGIN=yes +DEBUG_PLUGIN_EXTERNAL=yes DHRYSTONE=yes FREE_RTOS=no REDO=10 @@ -43,10 +45,18 @@ ifeq ($(MMU),yes) ADDCFLAGS += -CFLAGS -DMMU endif +ifeq ($(TRACE_ACCESS),yes) + ADDCFLAGS += -CFLAGS -DTRACE_ACCESS +endif + ifeq ($(DEBUG_PLUGIN),yes) ADDCFLAGS += -CFLAGS -DDEBUG_PLUGIN endif +ifeq ($(DEBUG_PLUGIN_EXTERNAL),yes) + ADDCFLAGS += -CFLAGS -DDEBUG_PLUGIN_EXTERNAL +endif + ifeq ($(REF),yes) ADDCFLAGS += -CFLAGS -DREF endif diff --git a/src/test/resources/hex/debugPluginExternal.hex b/src/test/resources/hex/debugPluginExternal.hex new file mode 100644 index 0000000..b727d9c --- /dev/null +++ b/src/test/resources/hex/debugPluginExternal.hex @@ -0,0 +1,39 @@ +:100000006F008013130000001300000013000000B5 +:100010001300000013000000130000001300000094 +:1000200013000000130101F82320310023221100E6 +:10003000232421002326310023284100232A5100B4 +:10004000232C6100232E71002320810223229102A0 +:100050002324A1022326B1022328C102232AD1028C +:10006000232CE102232EF102232001052322110576 +:10007000232421052326310523284105232A510560 +:10008000232C6105232E710523208107232291074C +:100090002324A1072326B1072328C107232AD10738 +:1000A000232CE107232EF1071300000013000000AA +:1000B0001300000013000000832041008321C100D1 +:1000C0000322010183224101032381018323C10112 +:1000D0000324010283244102032581028325C102F6 +:1000E0000326010383264103032781038327C103DA +:1000F0000328010483284104032981048329C104BE +:10010000032A0105832A4105032B8105832BC105A1 +:10011000032C0106832C4106032D8106832DC10685 +:10012000032E0107832E4107032F8107832FC10769 +:1001300013010108130000001711000013010188CA +:10014000130540011300000013000000130000001D +:100150001305F5FFE31805FE170500401305C5F16B +:1001600097050040938545F16308B50023200500FD +:10017000130545006FF05FFF170500401305C5EF3D +:100180001301C1FF97050040938505EF630EB5008D +:1001900083260500130545002320A100E780060003 +:1001A000032501006FF01FFE1301410017030040FB +:0801B000E70043E56F000000C9 +:020000044000BA +:10000000130101FE232E8100130401029307100047 +:100010002324F4FE930720002322F4FE93073000EC +:100020002320F4FE032784FE832744FE3307F700D2 +:10003000832704FEB307F7002326F4FE8327C4FEBC +:10004000938717002326F4FE8327C4FE9387270097 +:100050002326F4FE0327C4FE832704FEB307F7001C +:100060002326F4FEB70700900327C4FE23A0E70071 +:040070006FF09FFD91 +:0400000300000138C0 +:00000001FF