From 71c0e47e758eb6b4dcdf58939ee25db64c0c30cf Mon Sep 17 00:00:00 2001 From: Sylvain Lefebvre Date: Thu, 16 Nov 2023 12:48:24 +0100 Subject: [PATCH] switching to oss-cad-suite, verilator framewoek now uses glfw, static compilation --- frameworks/boards/verilator/verilator.sh | 13 +++---- frameworks/verilator/display.cpp | 46 ++++++++++++++---------- get_started_mingw64.sh | 20 ++++++++--- 3 files changed, 50 insertions(+), 29 deletions(-) diff --git a/frameworks/boards/verilator/verilator.sh b/frameworks/boards/verilator/verilator.sh index ce6ee438..0255c828 100755 --- a/frameworks/boards/verilator/verilator.sh +++ b/frameworks/boards/verilator/verilator.sh @@ -14,20 +14,21 @@ SRC_FILE=`cygpath $1` *) esac +LDFLAGS="-LDFLAGS --static " + # LDFLAGS for OpenGL (VGA / SPIscreen) case "$(uname -s)" in MINGW*) -LDFLAGS="-LDFLAGS -lopengl32 -LDFLAGS -lfreeglut" +LDFLAGS+="-LDFLAGS -lopengl32 -LDFLAGS -lglfw3 -LDFLAGS -lgdi32" ;; Darwin*) #nproc doesn't work on mac, so alias an equivalent command alias nproc="sysctl -n hw.logicalcpu" - #add openGL frameworks -LDFLAGS='-LDFLAGS -framework -LDFLAGS OpenGL -LDFLAGS -framework -LDFLAGS GLUT -LDFLAGS -pthread' +LDFLAGS+='-LDFLAGS -framework -LDFLAGS OpenGL -LDFLAGS -framework -LDFLAGS glfw3 -LDFLAGS -pthread' ;; *) -LDFLAGS="-LDFLAGS -lGL -LDFLAGS -lglut -LDFLAGS -pthread" +LDFLAGS+="-LDFLAGS -lGL -LDFLAGS -lglfw3 -LDFLAGS -pthread" ;; esac @@ -43,7 +44,7 @@ else export MAKE=mingw32-make fi -export PATH=$PATH:$SILICE_DIR/../tools/fpga-binutils/mingw64/bin/:$SILICE_DIR +export PATH=$PATH:$SILICE_DIR/../tools/oss-cad-suite/:$SILICE_DIR if [[ -z "${VERILATOR_ROOT}" ]]; then case "$(uname -s)" in @@ -51,7 +52,7 @@ Linux) unset VERILATOR_ROOT ;; *) -# export VERILATOR_ROOT=$SILICE_DIR/../tools/fpga-binutils/mingw64/ +export VERILATOR_ROOT=$SILICE_DIR/../tools/oss-cad-suite/share/verilator/ ;; esac echo "VERILATOR_ROOT is set to ${VERILATOR_ROOT}" diff --git a/frameworks/verilator/display.cpp b/frameworks/verilator/display.cpp index f8a7aaf5..6dddebf4 100644 --- a/frameworks/verilator/display.cpp +++ b/frameworks/verilator/display.cpp @@ -34,10 +34,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #ifdef __APPLE__ #include -#include +#include #else #include -#include +#include #endif // ---------------------------------------------------------------------------- @@ -66,8 +66,6 @@ void refresh() glTexCoord2f(1.0f, 1.0f); glVertex2f(1.0f, 1.0f); glTexCoord2f(0.0f, 1.0f); glVertex2f(0.0f, 1.0f); glEnd(); - // swap buffers - glutSwapBuffers(); } // ---------------------------------------------------------------------------- @@ -112,8 +110,6 @@ void render() // yes: refresh frame refresh(); } - // ask glut to immediately redraw - glutPostRedisplay(); } // ---------------------------------------------------------------------------- @@ -121,20 +117,23 @@ void render() void display_loop(DisplayChip *chip) { g_Chip = chip; - // glut window - int argc=0; - char *argv[1] = {NULL}; - glutInit(&argc, argv); - glutInitDisplayMode(GLUT_RGBA | GLUT_SINGLE); + // glfw window + if (!glfwInit()) { + fprintf(stderr,"ERROR: cannot initialize glfw."); + exit(-1); + } + GLFWwindow* window = NULL; if (g_Chip->framebuffer().w() <= 320) { - glutInitWindowSize(2*g_Chip->framebuffer().w(), - 2*g_Chip->framebuffer().h()); + window = glfwCreateWindow(2*g_Chip->framebuffer().w(), + 2*g_Chip->framebuffer().h(), + "Silice verilator framework", NULL, NULL); } else { - glutInitWindowSize(g_Chip->framebuffer().w(), - g_Chip->framebuffer().h()); + window = glfwCreateWindow(g_Chip->framebuffer().w(), + g_Chip->framebuffer().h(), + "Silice verilator framework", NULL, NULL); } - glutCreateWindow("Silice verilator framework"); - glutDisplayFunc(render); + glfwMakeContextCurrent(window); + glfwSwapInterval(1); // prepare texture glGenTextures(1,&g_FBtexture); glBindTexture(GL_TEXTURE_2D,g_FBtexture); @@ -150,7 +149,6 @@ void display_loop(DisplayChip *chip) glEnable(GL_TEXTURE_2D); glColor3f(1.0f,1.0f,1.0f); // setup view - glViewport(0,0,g_Chip->framebuffer().w(),g_Chip->framebuffer().h()); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0.0f, 1.0f, 1.0f, 0.0f, -1.0f, 1.0f); @@ -159,7 +157,17 @@ void display_loop(DisplayChip *chip) // start simulation in a thread std::thread th(simul); // enter main loop - glutMainLoop(); + while (!glfwWindowShouldClose(window)) { + int width, height; + glfwGetFramebufferSize(window, &width, &height); + glViewport(0, 0, width, height); + render(); + glfwSwapBuffers(window); + glfwPollEvents(); + } + // terminate + glfwDestroyWindow(window); + glfwTerminate(); } // ---------------------------------------------------------------------------- diff --git a/get_started_mingw64.sh b/get_started_mingw64.sh index cd787652..01006da2 100755 --- a/get_started_mingw64.sh +++ b/get_started_mingw64.sh @@ -12,6 +12,7 @@ then exit fi +# -------------- install packages ---------------------------- pacman -S --noconfirm --needed unzip pacman -S --noconfirm --needed wget pacman -S --noconfirm --needed make @@ -28,17 +29,28 @@ pacman -S --noconfirm --needed ${MINGW_PACKAGE_PREFIX}-dfu-util pacman -S --noconfirm --needed ${MINGW_PACKAGE_PREFIX}-boost # pacman -S --noconfirm --needed ${MINGW_PACKAGE_PREFIX}-nextpnr # pacman -S --noconfirm --needed ${MINGW_PACKAGE_PREFIX}-yosys +pacman -S --noconfirm --needed ${MINGW_PACKAGE_PREFIX}-glfw -wget -c https://github.com/sylefeb/fpga-binutils/releases/download/v20230510/fpga-binutils-64.zip +# -------------- get pre-compile binaries (no longer used) --- +# wget -c https://github.com/sylefeb/fpga-binutils/releases/download/v20230510/fpga-binutils-64.zip +# unzip -o fpga-binutils-64.zip -d tools/fpga-binutils/ +# rm fpga-binutils-64.zip -unzip -o fpga-binutils-64.zip -d tools/fpga-binutils/ +# -------------- retrieve oss-cad-suite package -------------- +OSS_CAD_MONTH=11 +OSS_CAD_DAY=15 +OSS_CAD_YEAR=2023 -rm fpga-binutils-64.zip +wget -c https://github.com/YosysHQ/oss-cad-suite-build/releases/download/$OSS_CAD_YEAR-$OSS_CAD_MONTH-$OSS_CAD_DAY/oss-cad-suite-windows-x64-$OSS_CAD_YEAR$OSS_CAD_MONTH$OSS_CAD_DAY.exe +cd tools ; ../oss-cad-suite-windows-x64-$OSS_CAD_YEAR$OSS_CAD_MONTH$OSS_CAD_DAY.exe ; cd - +# -------------- compile Silice ----------------------------- ./compile_silice_mingw64.sh +# -------------- add path to .bashrc ------------------------ DIR=`pwd` -echo 'export PATH=$PATH:'$DIR/bin':'$DIR/tools/fpga-binutils/mingw64/bin >> ~/.bashrc +echo 'export PATH=$PATH:'$DIR/bin >> ~/.bashrc +echo 'source '$DIR'/tools/oss-cad-suite-env.sh' >> ~/.bashrc echo "" echo "--------------------------------------------------------------------"