]> Joshua Wise's Git repositories - firearm.git/blob - testbench.cpp
Regfile: Rename signals for correct pipe stages.
[firearm.git] / testbench.cpp
1 #include "Vsystem.h"
2 #include <stdio.h>
3 #define _XOPEN_SOURCE
4 #include <stdlib.h>
5 #include <fcntl.h>
6 #include <termios.h>
7
8 Vsystem *top;
9
10 int ptyfd = -1;
11
12 void openpty()
13 {
14         int fd = posix_openpt(O_RDWR);
15         char b[128];
16         struct termios kbdios;
17         
18         grantpt(fd);  
19         fcntl(fd, F_SETFD, 0);  /* clear close-on-exec */
20         tcgetattr(fd, &kbdios);
21         kbdios.c_lflag &= ~(ECHO|ECHONL|ICANON|ISIG|IEXTEN);
22         tcsetattr(fd, TCSANOW, &kbdios);
23         sprintf(b, "urxvt -pty-fd %d -bg black -fg white -title \"Output terminal\" &", fd);
24         system(b);
25         unlockpt(fd);
26         ptyfd = open(ptsname(fd), O_RDWR | O_NONBLOCK);
27         close(fd);
28 }
29
30 unsigned int term_input()
31 {
32         int rv;
33         unsigned char c;
34         if (ptyfd == -1)
35                 openpty();
36         rv = read(ptyfd, &c, 1);
37         if (rv < 0)
38                 return 0;
39         return 0x100 | c;
40 }
41
42 void term_output(unsigned char d)
43 {
44         int fd = posix_openpt(O_RDWR);
45         static int fd2 = -1;
46         char b[128];
47
48         if (ptyfd == -1)
49                 openpty();
50         write(ptyfd, &d, 1);
51 }
52
53 unsigned int main_time = 0;
54
55 double sc_time_stamp ()
56 {
57         return main_time;
58 }
59
60 int main()
61 {
62         top = new Vsystem;
63         
64         top->clk = 0;
65         while (!Verilated::gotFinish())
66         {
67                 top->clk = !top->clk;
68                 top->rst = 0;
69                 top->eval();
70 //              if (top->clk == 1)
71 //                      printf("%d: Bubble: %d. PC: %08x. Ins'n: %08x\n", main_time/2, top->bubbleshield, top->pc, top->insn);
72                 
73                 main_time++;
74         }
75 }
This page took 0.028333 seconds and 4 git commands to generate.