-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathMakefile
More file actions
157 lines (129 loc) · 6.14 KB
/
Copy pathMakefile
File metadata and controls
157 lines (129 loc) · 6.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
######################################################################
#
# DESCRIPTION: Verilator with GUI
#
# This calls the object directory makefile. That allows the objects to
# be placed in the "current directory" which simplifies the Makefile.
#
# Copyright 2003-2018 by Wilson Snyder. This program is free software; you can
# redistribute it and/or modify it under the terms of either the GNU
# Lesser General Public License Version 3 or the Perl Artistic License
# Version 2.0.
#
# Modifications by Icaro Dantas de Araujo Lima and Elmar Melcher at UFCG, 2018
#
######################################################################
# Check for sanity to avoid later confusion
ifneq ($(words $(CURDIR)),1)
$(error Unsupported: GNU Make cannot build in directories containing spaces, build elsewhere: '$(CURDIR)')
endif
ifeq ($(findstring MINGW,$(shell uname)),MINGW)
CFLTK=-I/mingw64/include
LFLTK=-L/mingw64/lib -mwindows -lfltk_images -lfltk -lole32 -luuid -lcomctl32 -lws2_32
FLTK=-CFLAGS "$(CFLTK)" -LDFLAGS "$(LFLTK)"
CTHREAD=-DMINGW
VBOOST=-LDFLAGS "-L/mingw64/lib -lboost_system-mt -lws2_32 -lwsock32"
else
LFLTK=-lfltk_images -lpng -lz -lfltk
FLTK=-LDFLAGS "$(LFLTK)"
BOOST=-std=c++11 -lboost_system -lpthread
VBOOST=-CFLAGS "-std=c++11" -LDFLAGS "-lboost_system -lpthread"
endif
HDL_SIM=$(wildcard *.sv)
WARN=-Wno-CASEINCOMPLETE -Wno-WIDTH -Wno-COMBDLY
######################################################################
# If $VERILATOR_ROOT isn't in the environment, we assume it is part of a
# package install, and verilator is in your path. Otherwise find the
# binary relative to $VERILATOR_ROOT (such as when inside the git sources).
ifeq ($(VERILATOR_ROOT),)
VERILATOR = verilator
else
export VERILATOR_ROOT
VERILATOR = $(VERILATOR_ROOT)/bin/verilator
endif
TMP=/tmp${subst $(HOME),,${PWD}}
CUR=${PWD}
CABLE?=1
CABLE_1=$(shell expr $(CABLE) - 1)
DIVIDE_BY=$(shell grep parameter top.sv | grep divide_by | grep -oP '(?<!\d)\d*(?!\d)' )
SHELL=/bin/bash
# if there is a .101 file, use that one to create a.out instead of C or assembly
ifeq ($(wildcard *.101),)
aout_exe = aout_s
else
aout_exe = aout_101
endif
# if there are program ARGS, we need the proxy kernel
ifeq ($(ARGS),)
RVLDFL=-nostartfiles -T/usr/local/riscv/link.ld
PK =
else
RVLDFL =
PK = pk
endif
default: $(HDL_SIM) sim_socket.o remote.bin
$(VERILATOR) $(WARN) -cc --exe +1800-2012ext+sv top.sv veri.cpp ../sim_socket.o $(VBOOST)
$(MAKE) -j 2 -C obj_dir -f Vtop.mk
obj_dir/Vtop $(DIVIDE_BY)
# this only works on a LABARC workstation with Quartus properly configured
syn: $(HDL_SIM) inst.objdump
# @sintetize $(TMP) $(CABLE)
@qc_RISCV $(CABLE)
@qs_inst $(CABLE_1)
rm -f q.log
( while [ $$(cat q.log 2>/dev/null | wc -l) -lt 3 ]; do sleep 0.2; done; ./remote.bin $$(tail -1 q.log | cut -d' ' -f5) ) &
source /labarc/util/qr.cmd $(CABLE_1)
# from elf to object dump
%.objdump : a.out
@echo "****** disassembly listing of executable file?"
riscv32-unknown-elf-objdump -d -j .text | sed -n '/<main>:/,/<exit>:/p' | sed '/<exit>:/d' | sed "s/ *\t/\t/g"
@echo "****** from the executable file called a.out, create a file called $@ which contains only RISC-V instruction as hexadecimal numbers"
riscv32-unknown-elf-objdump -s -j .text | egrep "^( [0-9a-f]{8}){2}" | cut -b11-45 > $@
isa: a.out spike-gui.bin
@echo "****** create a spike command file called a.cmd which will advance the pc until main at the start of the simulation"
echo -n "until pc 0 " >a.cmd
riscv32-unknown-elf-objdump -j .text -t a.out | grep " main" | cut -d' ' -f1 >>a.cmd
@echo "****** write disassembly listing of executable file to a file called disa.txt, which will be read by spike GUI"
riscv32-unknown-elf-objdump -d -j .text | sed -n '/<main>:/,/<exit>:/p' | sed '/<exit>:/d' | sed "s/ *\t/\t/g" >disa.txt
@echo "****** call RISC-V ISA simulator spike with GUI"
rm -f q.log
( while [ $$(cat q.log 2>/dev/null | wc -l) -eq 0 ]; do sleep 0.2; done; ./spike-gui.bin $$(cut -d' ' -f8 q.log) ) &
(spike -d -s --debug-cmd=a.cmd $(PK) a.out $(ARGS); echo $$? ) | tee q.log
a.out: $(wildcard *.[sc1]*)
@make $(aout_exe)
# from assembly to elf
aout_s : $(wildcard *.s) $(sort $(patsubst %.c,%.s,$(wildcard *.c)))
@echo "****** call assembler to transform assembly file(s) $^ into one executable file called a.out"
riscv32-unknown-elf-gcc $(RVLDFL) $^
@if ! [ -z "$(RVLDFL)" ]; then echo "****** The option -nostartfiles excludes code that is only necessary to run the executable file on Linux. The option -T\$(RISCV)/link.ld puts main at address 0x80000000, as spike demands."; fi
# from .101 to elf
aout_101 : $(wildcard *.101) binmake
@echo "****** remove comment and space from $^ and transform the strings of 0's and 1's to binary values"
grep ^\ *[01] $< | sed 's/;.*//g' | sed 's/ //g' | ./binmake
@echo "****** The binary values are now in a bare metal file called a.bin ."
@echo "****** create an executable file called a.out, copying from another file (riscv.out) while inserting a.bin after main"
riscv32-unknown-elf-objcopy --update-section .text=a.bin --strip-symbol=_end server/riscv.out a.out
# from C to assembly
%.s : %.c
@echo "****** compile the file called $< to an assembly file called $@"
riscv32-unknown-elf-gcc -O1 -S $<
@echo "****** conteúdo do arquivo assembly $@:"
grep -v "^[[:space:]]\." $@
binmake: binmake.cc
gcc -o binmake binmake.cc
remote.bin: remote.cpp communicator.o gui.o
$(CXX) $(CFLTK) remote.cpp communicator.o gui.o -o remote.bin $(BOOST) $(LFLTK)
spike-gui.bin: spike-gui.cpp communicator.o
$(CXX) $(CFLTK) -o spike-gui.bin $< communicator.o $(BOOST) $(LFLTK)
sim_socket.o: sim_socket.cpp
$(CXX) -std=c++11 $(CTHREAD) -c $<
gui.o: gui.cpp gui.h
$(CXX) $(CFLTK) -c $<
communicator.o: communicator.cpp communicator.h
$(CXX) -std=c++11 $(CTHREAD) -c communicator.cpp
######################################################################
maintainer-copy::
clean mostlyclean distclean maintainer-clean::
-rm -rf obj_dir *.h.gch *.o *.bin *.log *.dmp *.vpd core a.out *.objdump binmake
isa-clean::
-rm -f a.out a.bin a.cmd *.s *.c *.objdump *.101