ZipCPU / zipcpu

A small, light weight, RISC CPU soft core
1.27k stars 153 forks source link

Issue while building sim/verilator #24

Closed GreenMan-1 closed 1 year ago

GreenMan-1 commented 1 year ago

Hi, I came across the below-mentioned error while making some changes in zipcpu_tb.cpp and then ran the make command to build it.

# make
Building dependencies
g++ -Wall -Og -g -D__WORDSIZE=64 -DNEW_VERILATOR -I../../rtl/obj_dir -I../../rtl -I../../sw/zasm -I/usr/share/verilator/include -I/usr/share/verilator/include/vltstd -c zipcpu_tb.cpp -o obj-pc/zipsys_tb.o
In file included from zipcpu_tb.cpp:84:
zipelf.h:1:1: error: expected unqualified-id before ‘.’ token
    1 | ../cpp/zipelf.h
      | ^
zipcpu_tb.cpp: In function ‘int main(int, char**)’:
zipcpu_tb.cpp:2454:10: error: ‘iself’ was not declared in this scope
 2454 |       &&(iself(argv[argn]))) {
      |          ^~~~~
zipcpu_tb.cpp:2455:5: error: ‘ELFSECTION’ was not declared in this scope
 2455 |     ELFSECTION **secpp = NULL, *secp;
      |     ^~~~~~~~~~
zipcpu_tb.cpp:2455:18: error: ‘secpp’ was not declared in this scope
 2455 |     ELFSECTION **secpp = NULL, *secp;
      |                  ^~~~~
zipcpu_tb.cpp:2455:33: error: ‘secp’ was not declared in this scope
 2455 |     ELFSECTION **secpp = NULL, *secp;
      |                                 ^~~~
zipcpu_tb.cpp:2457:5: error: ‘elfread’ was not declared in this scope; did you mean ‘fread’?
 2457 |     elfread(argv[argn], entry, secpp);
      |     ^~~~~~~
      |     fread
In file included from zipcpu_tb.cpp:83:
testb.h: In instantiation of ‘TESTB<VA>::TESTB() [with VA = Vzipsystem]’:
zipcpu_tb.cpp:471:58:   required from here
testb.h:55:12: warning: ‘new’ of type ‘Vzipsystem’ with extended alignment 64 [-Waligned-new=]
   55 |   m_core = new VA;
      |            ^~~~~~
testb.h:55:12: note: uses ‘void* operator new(std::size_t)’, which does not have an alignment parameter
testb.h:55:12: note: use ‘-faligned-new’ to enable C++17 over-aligned new support
make: *** [Makefile:175: obj-pc/zipsys_tb.o] Error 1

so to resolve this error I copied zipelf.h & zipelf.cpp from cpp/ folder to verilator/ folder then the build was successful but there were some warnings as mentioned below

# make
g++ -Wall -Og -g -D__WORDSIZE=64 -DNEW_VERILATOR -I../../rtl/obj_dir -I../../rtl -I../../sw/zasm -I/usr/share/verilator/include -I/usr/share/verilator/include/vltstd -c zipcpu_tb.cpp -o obj-pc/zipsys_tb.o
In file included from zipcpu_tb.cpp:83:
testb.h: In instantiation of ‘TESTB<VA>::TESTB() [with VA = Vzipsystem]’:
zipcpu_tb.cpp:471:58:   required from here
testb.h:55:12: warning: ‘new’ of type ‘Vzipsystem’ with extended alignment 64 [-Waligned-new=]
   55 |   m_core = new VA;
      |            ^~~~~~
testb.h:55:12: note: uses ‘void* operator new(std::size_t)’, which does not have an alignment parameter
testb.h:55:12: note: use ‘-faligned-new’ to enable C++17 over-aligned new support
g++ -Wall -Og -g -D__WORDSIZE=64 -DNEW_VERILATOR -I../../rtl/obj_dir -I../../rtl -I../../sw/zasm -I/usr/share/verilator/include -I/usr/share/verilator/include/vltstd -c memsim.cpp -o obj-pc/memsim.o
g++ -Wall -Og -g -D__WORDSIZE=64 -DNEW_VERILATOR -I../../rtl/obj_dir -I../../rtl -I../../sw/zasm -I/usr/share/verilator/include -I/usr/share/verilator/include/vltstd -c zipelf.cpp -o obj-pc/zipelf.o
g++ -Wall -Og -g -D__WORDSIZE=64 -DNEW_VERILATOR -I../../rtl/obj_dir -I../../rtl -I../../sw/zasm -I/usr/share/verilator/include -I/usr/share/verilator/include/vltstd -c twoc.cpp -o obj-pc/twoc.o
g++ -Wall -Og -g -D__WORDSIZE=64 -DNEW_VERILATOR -I../../rtl/obj_dir -I../../rtl -I../../sw/zasm -I/usr/share/verilator/include -I/usr/share/verilator/include/vltstd -c byteswap.cpp -o obj-pc/byteswap.o
g++ -Wall -Og -g -D__WORDSIZE=64 -I../../rtl/obj_dir -I../../rtl -I../../sw/zasm -I/usr/share/verilator/include -I/usr/share/verilator/include/vltstd -c ../../sw/zasm/zopcodes.cpp -o obj-pc/zopcodes.o
../../sw/zasm/zopcodes.cpp: In function ‘void zipi_to_halfstring(uint32_t, ZIPI, char*, const ZOPCODE*)’:
../../sw/zasm/zopcodes.cpp:539:30: warning: passing argument 1 to restrict-qualified parameter aliases with argument 3 [-Wrestrict]
  539 |   sprintf(line, "%-11s", line);
      |                              ^
../../sw/zasm/zopcodes.cpp:540:38: warning: passing argument 1 to restrict-qualified parameter aliases with argument 3 [-Wrestrict]
  540 |   sprintf(line, "%s0x%08x", line, ref);
      |                                      ^
../../sw/zasm/zopcodes.cpp:541:46: warning: passing argument 1 to restrict-qualified parameter aliases with argument 3 [-Wrestrict]
  541 |   sprintf(line, "%s,%s", line, zip_regstr[dv]);
      |                                              ^
../../sw/zasm/zopcodes.cpp:576:33: warning: passing argument 1 to restrict-qualified parameter aliases with argument 3 [-Wrestrict]
  576 |    } sprintf(line, "%-11s", line); // Pad it to 11 chars
      |                                 ^
g++ -Wall -Og -g -D__WORDSIZE=64 -I../../rtl/obj_dir -I../../rtl -I../../sw/zasm -I/usr/share/verilator/include -I/usr/share/verilator/include/vltstd -c /usr/share/verilator/include/verilated.cpp -o obj-pc/verilated.o
/usr/share/verilator/include/verilated.cpp: In function ‘void VL_READMEM_N(bool, int, QData, int, const string&, void*, QData, QData)’:
/usr/share/verilator/include/verilated.cpp:1835:15: warning: comparison of integer expressions of different signedness: ‘QData’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
 1835 |     if (start < array_lsb) start = array_lsb;
      |         ~~~~~~^~~~~~~~~~~
/usr/share/verilator/include/verilated.cpp: In function ‘void VL_WRITEMEM_N(bool, int, QData, int, const string&, const void*, QData, QData)’:
/usr/share/verilator/include/verilated.cpp:1886:15: warning: comparison of integer expressions of different signedness: ‘QData’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
 1886 |     if (start < array_lsb) start = array_lsb;
      |         ~~~~~~^~~~~~~~~~~
g++ -Wall -Og -g -D__WORDSIZE=64 -I../../rtl/obj_dir -I../../rtl -I../../sw/zasm -I/usr/share/verilator/include -I/usr/share/verilator/include/vltstd -c /usr/share/verilator/include/verilated_vcd_c.cpp -o obj-pc/verilated_vcd_c.o
g++ -Wall -Og -g -D__WORDSIZE=64 -I../../rtl/obj_dir -I../../rtl -I../../sw/zasm -I/usr/share/verilator/include -I/usr/share/verilator/include/vltstd obj-pc/zipsys_tb.o   obj-pc/memsim.o obj-pc/zipelf.o obj-pc/twoc.o obj-pc/byteswap.o obj-pc/zopcodes.o obj-pc/verilated.o obj-pc/verilated_vcd_c.o ../../rtl/obj_dir/Vzipsystem__ALL.a -lncurses -lelf -o zipsys_tb
g++ -DZIPBONES -DNEW_VERILATOR -Wall -Og -g -D__WORDSIZE=64 -I../../rtl/obj_dir -I../../rtl -I../../sw/zasm -I/usr/share/verilator/include -I/usr/share/verilator/include/vltstd -c zipcpu_tb.cpp -o obj-pc/zipbones_tb.o
In file included from zipcpu_tb.cpp:83:
testb.h: In instantiation of ‘TESTB<VA>::TESTB() [with VA = Vzipbones]’:
zipcpu_tb.cpp:471:58:   required from here
testb.h:55:12: warning: ‘new’ of type ‘Vzipbones’ with extended alignment 64 [-Waligned-new=]
   55 |   m_core = new VA;
      |            ^~~~~~
testb.h:55:12: note: uses ‘void* operator new(std::size_t)’, which does not have an alignment parameter
testb.h:55:12: note: use ‘-faligned-new’ to enable C++17 over-aligned new support
g++ -Wall -Og -g -D__WORDSIZE=64 -I../../rtl/obj_dir -I../../rtl -I../../sw/zasm -I/usr/share/verilator/include -I/usr/share/verilator/include/vltstd obj-pc/zipbones_tb.o obj-pc/memsim.o obj-pc/zipelf.o obj-pc/twoc.o obj-pc/byteswap.o obj-pc/zopcodes.o obj-pc/verilated.o obj-pc/verilated_vcd_c.o ../../rtl/obj_dir/Vzipbones__ALL.a -lncurses -lelf -o zipbones_tb
g++ -Wall -Og -g -D__WORDSIZE=64 -DNEW_VERILATOR -I../../rtl/obj_dir -I../../rtl -I../../sw/zasm -I/usr/share/verilator/include -I/usr/share/verilator/include/vltstd -c pdump.cpp -o obj-pc/pdump.o
g++ -Wall -Og -g -D__WORDSIZE=64 -I../../rtl/obj_dir -I../../rtl -I../../sw/zasm -I/usr/share/verilator/include -I/usr/share/verilator/include/vltstd obj-pc/pdump.o obj-pc/zipelf.o obj-pc/twoc.o obj-pc/byteswap.o obj-pc/zopcodes.o -lelf -o pdump
g++ -Wall -Og -g -D__WORDSIZE=64 -DNEW_VERILATOR -I../../rtl/obj_dir -I../../rtl -I../../sw/zasm -I/usr/share/verilator/include -I/usr/share/verilator/include/vltstd -c div_tb.cpp -o obj-pc/div_tb.o
div_tb.cpp: In member function ‘void DIV_TB::dbgdump()’:
div_tb.cpp:114:41: warning: passing argument 1 to restrict-qualified parameter aliases with argument 3 [-Wrestrict]
  114 |   sprintf(s, "%s\n%10s %40s",s, "Div","");
      |                                         ^
div_tb.cpp:118:34: warning: passing argument 1 to restrict-qualified parameter aliases with argument 3 [-Wrestrict]
  118 |   sprintf(s, "%s\n%10s ",s, "Div"); s = &s[strlen(s)];
      |                                  ^
div_tb.cpp:121:39: warning: passing argument 1 to restrict-qualified parameter aliases with argument 3 [-Wrestrict]
  121 |   sprintf(s, "%s\n%10s %40s",s, "Q",""); s=&s[strlen(s)];
      |                                       ^
div_tb.cpp:123:42: warning: passing argument 1 to restrict-qualified parameter aliases with argument 3 [-Wrestrict]
  123 |   sprintf(s, "%s\n%10s %38s",s, "Diff","");
      |                                          ^
In file included from div_tb.cpp:70:
testb.h: In instantiation of ‘TESTB<VA>::TESTB() [with VA = Vdiv]’:
div_tb.cpp:77:15:   required from here
testb.h:55:12: warning: ‘new’ of type ‘Vdiv’ with extended alignment 64 [-Waligned-new=]
   55 |   m_core = new VA;
      |            ^~~~~~
testb.h:55:12: note: uses ‘void* operator new(std::size_t)’, which does not have an alignment parameter
testb.h:55:12: note: use ‘-faligned-new’ to enable C++17 over-aligned new support
g++ -Wall -Og -g -D__WORDSIZE=64 -DNEW_VERILATOR -I../../rtl/obj_dir -I../../rtl -I../../sw/zasm -I/usr/share/verilator/include -I/usr/share/verilator/include/vltstd obj-pc/div_tb.o obj-pc/twoc.o /usr/share/verilator/include/verilated.cpp /usr/share/verilator/include/verilated_vcd_c.cpp ../../rtl/obj_dir/Vdiv__ALL.a -o div_tb
/usr/share/verilator/include/verilated.cpp: In function ‘void VL_READMEM_N(bool, int, QData, int, const string&, void*, QData, QData)’:
/usr/share/verilator/include/verilated.cpp:1835:15: warning: comparison of integer expressions of different signedness: ‘QData’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
 1835 |     if (start < array_lsb) start = array_lsb;
      |         ~~~~~~^~~~~~~~~~~
/usr/share/verilator/include/verilated.cpp: In function ‘void VL_WRITEMEM_N(bool, int, QData, int, const string&, const void*, QData, QData)’:
/usr/share/verilator/include/verilated.cpp:1886:15: warning: comparison of integer expressions of different signedness: ‘QData’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
 1886 |     if (start < array_lsb) start = array_lsb;
      |         ~~~~~~^~~~~~~~~~~
g++ -Wall -Og -g -D__WORDSIZE=64 -DNEW_VERILATOR -I../../rtl/obj_dir -I../../rtl -I../../sw/zasm -I/usr/share/verilator/include -I/usr/share/verilator/include/vltstd -c mpy_tb.cpp -o obj-pc/mpy_tb.o
In file included from mpy_tb.cpp:64:
testb.h: In instantiation of ‘TESTB<VA>::TESTB() [with VA = Vcpuops]’:
mpy_tb.cpp:71:18:   required from here
testb.h:55:12: warning: ‘new’ of type ‘Vcpuops’ with extended alignment 64 [-Waligned-new=]
   55 |   m_core = new VA;
      |            ^~~~~~
testb.h:55:12: note: uses ‘void* operator new(std::size_t)’, which does not have an alignment parameter
testb.h:55:12: note: use ‘-faligned-new’ to enable C++17 over-aligned new support
g++ -Wall -Og -g -D__WORDSIZE=64 -DNEW_VERILATOR -I../../rtl/obj_dir -I../../rtl -I../../sw/zasm -I/usr/share/verilator/include -I/usr/share/verilator/include/vltstd obj-pc/mpy_tb.o obj-pc/twoc.o /usr/share/verilator/include/verilated.cpp /usr/share/verilator/include/verilated_vcd_c.cpp ../../rtl/obj_dir/Vcpuops__ALL.a -o mpy_tb
/usr/share/verilator/include/verilated.cpp: In function ‘void VL_READMEM_N(bool, int, QData, int, const string&, void*, QData, QData)’:
/usr/share/verilator/include/verilated.cpp:1835:15: warning: comparison of integer expressions of different signedness: ‘QData’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
 1835 |     if (start < array_lsb) start = array_lsb;
      |         ~~~~~~^~~~~~~~~~~
/usr/share/verilator/include/verilated.cpp: In function ‘void VL_WRITEMEM_N(bool, int, QData, int, const string&, const void*, QData, QData)’:
/usr/share/verilator/include/verilated.cpp:1886:15: warning: comparison of integer expressions of different signedness: ‘QData’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
 1886 |     if (start < array_lsb) start = array_lsb;
      |         ~~~~~~^~~~~~~~~~~
g++ -Wall -Og -g -D__WORDSIZE=64 -DNEW_VERILATOR -I../../rtl/obj_dir -I../../rtl -I../../sw/zasm -I/usr/share/verilator/include -I/usr/share/verilator/include/vltstd -c pfcache_tb.cpp -o obj-pc/pfcache_tb.o
In file included from pfcache_tb.cpp:53:
testb.h: In instantiation of ‘TESTB<VA>::TESTB() [with VA = Vpfcache]’:
pfcache_tb.cpp:69:50:   required from here
testb.h:55:12: warning: ‘new’ of type ‘Vpfcache’ with extended alignment 64 [-Waligned-new=]
   55 |   m_core = new VA;
      |            ^~~~~~
testb.h:55:12: note: uses ‘void* operator new(std::size_t)’, which does not have an alignment parameter
testb.h:55:12: note: use ‘-faligned-new’ to enable C++17 over-aligned new support
g++ -Wall -Og -g -D__WORDSIZE=64 -DNEW_VERILATOR -I../../rtl/obj_dir -I../../rtl -I../../sw/zasm -I/usr/share/verilator/include -I/usr/share/verilator/include/vltstd -I../../rtl/obj_dir obj-pc/pfcache_tb.o obj-pc/memsim.o obj-pc/byteswap.o /usr/share/verilator/include/verilated.cpp /usr/share/verilator/include/verilated_vcd_c.cpp ../../rtl/obj_dir/Vpfcache__ALL.a -o pfcache_tb
/usr/share/verilator/include/verilated.cpp: In function ‘void VL_READMEM_N(bool, int, QData, int, const string&, void*, QData, QData)’:
/usr/share/verilator/include/verilated.cpp:1835:15: warning: comparison of integer expressions of different signedness: ‘QData’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
 1835 |     if (start < array_lsb) start = array_lsb;
      |         ~~~~~~^~~~~~~~~~~
/usr/share/verilator/include/verilated.cpp: In function ‘void VL_WRITEMEM_N(bool, int, QData, int, const string&, const void*, QData, QData)’:
/usr/share/verilator/include/verilated.cpp:1886:15: warning: comparison of integer expressions of different signedness: ‘QData’ {aka ‘long unsigned int’} and ‘int’ [-Wsign-compare]
 1886 |     if (start < array_lsb) start = array_lsb;

and also I need to run in su mode i.e sudo su otherwise I am getting the following error

$ make
ctags: cannot open tag file : Permission denied
g++ -Wall -Og -g -D__WORDSIZE=64 -DNEW_VERILATOR -I../../rtl/obj_dir -I../../rtl -I../../sw/zasm -I/usr/share/verilator/include -I/usr/share/verilator/include/vltstd -c zipcpu_tb.cpp -o obj-pc/zipsys_tb.o
In file included from zipcpu_tb.cpp:83:
testb.h: In instantiation of ‘TESTB<VA>::TESTB() [with VA = Vzipsystem]’:
zipcpu_tb.cpp:471:58:   required from here
testb.h:55:12: warning: ‘new’ of type ‘Vzipsystem’ with extended alignment 64 [-Waligned-new=]
   55 |   m_core = new VA;
      |            ^~~~~~
testb.h:55:12: note: uses ‘void* operator new(std::size_t)’, which does not have an alignment parameter
testb.h:55:12: note: use ‘-faligned-new’ to enable C++17 over-aligned new support
Assembler messages:
Fatal error: can't create obj-pc/zipsys_tb.o: Permission denied
make: *** [Makefile:175: obj-pc/zipsys_tb.o] Error 1

Is this ok or am I doing any serious mistakes? Please let me know.

ZipCPU commented 1 year ago

sudo is nor required!

It looks like you have some root owned files lying around. Perhaps these are build products from when you (accidentally?) attempted to build with sudo, perhaps they are from something else. Try setting the ownership of all files back to yourself, and the sudo problem should be resolved. Something like ...

sudo find . -exec chown user \{\} \;, where user is your user name, should work. (I make no promises, I haven't tested it, do your own homework, etc.--but this is where I would start.) Make sure you are in the appropriate zipcpu directory when doing this, and it should then change ownership of all files at your current directory level and deeper to your user.

The requirement for -faligned-new is somewhat of a confusing requirement between Verilator and g++. It comes from Verilator using a new g++ language feature. You can either safely ignore this, or add the -faligned-new flag to the CFLAGS Makefile variable.

The ZipCPU test bench does require access to zipelf.h and zipelf.cpp. In my development tree, these are soft linked to ../cpp/zipelf.h and ../cpp/zipelf.cpp.

The warnings from zopcodes.cpp is the result of g++ getting upgraded, and something that didn't used to generate warnings now does. The same should be true with div_tb.cpp. The comparison of different signedness warning is also similar--g++ didn't used to complain about that, although it now does. In most cases, the integers in question will never be so large their signedness will matter, but it is something that I'm sure a newer version of Verilator will likely fix.

Dan

GreenMan-1 commented 1 year ago

OK, i will check from my end, Thank you very much Dan