]> Joshua Wise's Git repositories - firearm.git/blobdiff - testbench.cpp
Global: More re-piping, and a bugfix for a bug recently introduced. (Regressions...
[firearm.git] / testbench.cpp
index 4188d71555204b17cb2ad4057a326902b851943d..9ad4b2da082abc7c016aa8255db73339ede56b7a 100644 (file)
@@ -1,8 +1,55 @@
 #include "Vsystem.h"
 #include <stdio.h>
+#define _XOPEN_SOURCE
+#include <stdlib.h>
+#include <fcntl.h>
+#include <termios.h>
 
 Vsystem *top;
 
+int ptyfd = -1;
+
+void openpty()
+{
+       int fd = posix_openpt(O_RDWR);
+       char b[128];
+       struct termios kbdios;
+       
+       grantpt(fd);  
+       fcntl(fd, F_SETFD, 0);  /* clear close-on-exec */
+       tcgetattr(fd, &kbdios);
+       kbdios.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
+       tcsetattr(fd, TCSANOW, &kbdios);
+       sprintf(b, "urxvt -pty-fd %d -bg black -fg white -title \"Output terminal\" &", fd);
+       system(b);
+       unlockpt(fd);
+       ptyfd = open(ptsname(fd), O_RDWR | O_NONBLOCK);
+       close(fd);
+}
+
+unsigned int term_input()
+{
+       int rv;
+       unsigned char c;
+       if (ptyfd == -1)
+               openpty();
+       rv = read(ptyfd, &c, 1);
+       if (rv < 0)
+               return 0;
+       return 0x100 | c;
+}
+
+void term_output(unsigned char d)
+{
+       int fd = posix_openpt(O_RDWR);
+       static int fd2 = -1;
+       char b[128];
+
+       if (ptyfd == -1)
+               openpty();
+       write(ptyfd, &d, 1);
+}
+
 unsigned int main_time = 0;
 
 double sc_time_stamp ()
@@ -18,7 +65,7 @@ int main()
        while (!Verilated::gotFinish())
        {
                top->clk = !top->clk;
-               
+               top->rst = 0;
                top->eval();
 //             if (top->clk == 1)
 //                     printf("%d: Bubble: %d. PC: %08x. Ins'n: %08x\n", main_time/2, top->bubbleshield, top->pc, top->insn);
This page took 0.025712 seconds and 4 git commands to generate.