Skip to content

Commit

Permalink
switching to oss-cad-suite, verilator framewoek now uses glfw, static…
Browse files Browse the repository at this point in the history
… compilation
  • Loading branch information
sylefeb committed Nov 16, 2023
1 parent 030e0ab commit 71c0e47
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 29 deletions.
13 changes: 7 additions & 6 deletions frameworks/boards/verilator/verilator.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -43,15 +44,15 @@ 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
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}"
Expand Down
46 changes: 27 additions & 19 deletions frameworks/verilator/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

#ifdef __APPLE__
#include <OpenGL/gl.h>
#include <GLUT/glut.h>
#include <GLFW/glfw3.h>
#else
#include <GL/gl.h>
#include <GL/glut.h>
#include <GLFW/glfw3.h>
#endif

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -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();
}

// ----------------------------------------------------------------------------
Expand Down Expand Up @@ -112,29 +110,30 @@ void render()
// yes: refresh frame
refresh();
}
// ask glut to immediately redraw
glutPostRedisplay();
}

// ----------------------------------------------------------------------------

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);
Expand All @@ -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);
Expand All @@ -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();
}

// ----------------------------------------------------------------------------
20 changes: 16 additions & 4 deletions get_started_mingw64.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ then
exit
fi

# -------------- install packages ----------------------------
pacman -S --noconfirm --needed unzip
pacman -S --noconfirm --needed wget
pacman -S --noconfirm --needed make
Expand All @@ -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 "--------------------------------------------------------------------"
Expand Down

0 comments on commit 71c0e47

Please sign in to comment.