Full text
Ampliación de la funcionalidad de las herramientas de simulación de RVFPGA Extending the functionality of the simulation tools for RVFPGA Trabajo de Fin de Grado Curso 2023–2024 Autor Óscar Lobato Parra Directores Daniel Ángel Chaver Martínez Katzalin Olcoz Herrero Grado en Ingeniería Informática Facultad de Informática Universidad Complutense de Madrid
Ampliación de la funcionalidad de las herramientas de simulación de RVFPGA Extending the functionality of the simulation tools for RVFPGA Trabajo de Fin de Grado en Ingeniería Informática Autor Óscar Lobato Parra Directores Daniel Ángel Chaver Martínez Katzalin Olcoz Herrero Convocatoria: Febrero 2024 Grado en Ingeniería Informática Facultad de Informática Universidad Complutense de Madrid 23 de Enero de 2024
Resumen Ampliación de la funcionalidad de las herramientas de simulación de RVFPGA Este proyecto trata sobre herramientas para la docencia de Arquitectura de Computadores basadas en la arquitectura RISC-V. En el primer capítulo se cuentan los antecedentes, objetivos y plan de trabajo propuesto para este proyecto. Después se explican las distintas herramientas que se usan para ayudar en la docencia de asignaturas de AC, insistiendo especialmente en el proyecto RVfpga, en el que se basa la mayor parte del trabajo. En los siguientes dos capítulos se detallan las contribuciones de este trabajo a dos de los simuladores de RVfpga. En primer lugar, se ha añadido a ViDBo el led tricolor, un periférico que ayuda a realizar las prácticas del proyecto. En segundo lugar, se ha intentado modificar la funcionalidad de simulador del pipeline, también incluido en el proyecto RVfpga. Finalmente, el capítulo 5 trata sobre el intento de integrar uno de los cores en el simulador Ripes. En el último capítulo se resumen las conclusiones y algunas propuestas de trabajo futuro. Palabras clave RISCVfpga, RISC-V, simuladores, herramientas docentes, Arquitectura de Computadores, RIPES. v
Abstract Extending the functionality of the simulation tools for RVFPGA This project is about the tools for teaching Computer Architecture based on the RISC-V architecture. In the first chapter the background, objectives and work plan for this project are explained. Later, the different tools used to help in the teaching of CA subjects are explained, focusing specially in the RVfpga project, in which most of the project is based on. In the next two chapters, the contributions of this project to two of the simulators included in RVfpga are detailed. First, the tri-color led peripheral has been added to ViDBo. This peripheral helps carrying out the practical exercises of the RVfpga project. In second place, the pipeline simulator included in RVfpga is tried to be modified. In chapter 5 is about the attempt of integrating one of the cores to the Ripes simulator. Lastly, some conclusions and future work proposals are summarized. Keywords RISCVfpga, RISC-V, simulators, teaching tools, Computer Architecture, RIPES. vii
Contents 1. Introduction 1 1.1. Background ................................ 1 1.2. Objectives................................. 1 1.3. WorkPlan................................. 2 2. Tools for teaching Computer Architecture based on RISC-V 3 2.1. Introduction................................ 3 2.2. RISC-VFPGACourse.......................... 4 2.2.1. VeeREH1Core.......................... 5 2.2.2. VeeREL2Core.......................... 5 2.3. Simulators used in this project . . . . . . . . . . . . . . . . . . . . . . 5 2.3.1. RVfpga-ViDBo .......................... 6 2.3.2. RVfpga-Pipeline . . . . . . . . . . . . . . . . . . . . . . . . . . 6 2.3.3. Ripes................................ 7 3. Contribution to RVfpga Simulator: ViDBo 9 3.1. ViDBoarchitecture............................ 9 3.2. SystemonChip.............................. 10 3.2.1. Tri-colorLEDs .......................... 11 3.2.2. PWM ............................... 11 3.3. Implementation.............................. 12 3.3.1. Modifying the backend . . . . . . . . . . . . . . . . . . . . . . 13 3.3.2. Modifying the frontend . . . . . . . . . . . . . . . . . . . . . . 17 4. Contribution to RVfpga Simulator: Pipeline 21 4.1. Infrastructure............................... 21 4.1.1. GTK................................ 22 4.2. Implementation.............................. 22 5. Research on the RIPES simulator 25 5.1. Infrastructure of RIPES . . . . . . . . . . . . . . . . . . . . . . . . . 25 5.1.1. Toolchain for Building Ripes . . . . . . . . . . . . . . . . . . . 26 ix
4Chapter 2. Tools for teaching Computer Architecture based on RISC-V lack of understanding the architecture and its extensions, the inability to access, understand, and use RISC-V tools, and the difficulty in gathering and using all of the pieces needed to deploy, understand, and expand a commercial, non-trivial, RISC-V core and SoC with its accompanying development environment and tools. This has led to a plethora of opensource educational materials [6] and design alternatives, ranging from very simple in-order designs to more aggressive out-of-order proposals. Two such designs are the BRISC-V Toolbox [1] and LeaRnV [9]. BRISC-V represents a huge effort to build a complete web-based ecosystem including a compiler, simulator, and a generator of fullysynthesizable hardware systems. However, this toolbox provides only the cores but not accompanying labs or exercises. The LeaRnV course aims to train students in hardware-software co-design. The RVfpga course [11] aims to address all of the above challenges by showing the complete path from system setup to using, programming, understanding, and expanding the RISC-V core and SoC, including learning how to use the RISC-V toolchain and simulators, how to use and understand a commercial RISC-V SoC targeted to an FPGA, and how to extend and modify the SoC and core. Since this project is mostly an extension of the RVfpga course, it will be explained in more detail in the following section. 2.2. RISC-V FPGA Course The RISC-V FPGA course, also known as RVfpga, is a course in Computer Architecture developed by the Imagination University Programme, which aims to provide knowledge about understanding the digital design at the level of the instruction set architecture, in this case RISC-V. Figure 2.1 shows the hierarchy of the RVfpga System, from the core to the targeted simulators and boards. The course has been released using two different cores: VeeR EH1 Core (see section 2.2.1) and VeeR EL2 (see section 2.2.2), which both have been used in this project. The core is extended with a Core Complex, designed by the manufacturers. Then, Core Complex is included in a SoC, which is done by RVfpga Course, adding new components. We will elaborate more on this in chapter 3. The aim is to have as many functionalities as possible, since the course aims to teach Computer Architecture designs in depth. The last level in the hierarchy is the system target: an FPGA board or a simulator. In this case, we will have RVfpgaNexys and RVfpgaSim, which will be covered in section 2.3. The RVfpga System includes three different simulators, each of them covering a different aspect of the Computer Architecture field, which are the following ones: RVfpga-ViDBo (see section 2.3.1). RVfpga-Pipeline (see chapter 4). RVfpga-Trace We will be focusing on the ViDBo and Pipeline simulators in this project.
2.3. Simulators used in this project 5 Figure 2.1: RVfpga System Hierarchy 2.2.1. VeeR EH1 Core The VeeR EH1 -formerly SweRV EH1- is a RISC-V core developed by Chips Alliance. It is a superescalar processor, with a 32-bit architecture and dual-issue 9-stage pipeline. It has 4 pipes, two for ALU operations, one for memory accesses and the other one for multiplications. There is also a 34-cycle latency divider, which is not pipelined. With this microarchitecture, the extensions supported of the Instruction Set Architecture are the RISC-V integer (I), compressed instruction (C) and integer multiplication and division (M). 2.2.2. VeeR EL2 Core The VeeR EL2 Core is another RISC-V core developed by Chips Alliance. It is a smaller core with respect to the VeeR EH1 previously explained. In this case, this is a scalar 4-stage pipelined core with 3 different pipes. These pipes are one for execution, one for memory operations and another one for multiplications. As well as the VeeR EH1, it has a non-pipelined divider. 2.3. Simulators used in this project In this section, we will explain the most relevant features of the simulators that are being used in the project.
6Chapter 2. Tools for teaching Computer Architecture based on RISC-V Figure 2.2: VeeR EH1 core microarchitecture [11] 2.3.1. RVfpga-ViDBo The Virtual Development Board, or ViDBo, is a simulator of a RVfpga System running on the Nexys Artix-7 FPGA developed by Digilent. Figure 2.4 shows the physical board, with all the components. This simulator is conceived to provide an accurate simulation of the system, interacting with the user as if the user had the physical board on their desk. This is achieved by having all the logic underlying all the peripherals translated into simulated circuits, so that we can get the same output as in the real world. Actually, any program that is executed on the ViDBo simulator behaves in the same way when executing on the physical board. In fact, there exists some I/O practices in the RVfpga course that might be needing to use the peripherals of the FPGA. That is why in ViDBo all the effort is put into having most of the peripherals integrated in the simulator. In the case of this project, we added the functionality of the Tri-Color LED, which is used by various practices that are provided with the course. 2.3.2. RVfpga-Pipeline When teaching Computer Architecture, one of the most important parts for understanding better the processor design is being able to keep track of the changes in the internal signals of the procesor. In the case of pipelined procesors, being able to check the internal signals of the pipeline is key. Students learning processor designing, may find useful to have a simulator where these changes in the values of the signals are visible. This is what the RVfpga-Pipeline simulator is in charge of. It will show the
2.3. Simulators used in this project 7 Figure 2.3: VeeR EL2 core microarchitecture [11] signals in each of the stages of the pipeline of the processor being simulated. The interface is very simple, showing the signals in the place they are in the actual pipeline, but without any graphical reference, it is over a blank background. 2.3.3. Ripes The Ripes [10] simulator enhances the previous one, since it also covers the tracking of signal values, but it extends its functionalities. This is a graphical computer architecture simulator for processors designed using the RISC-V Instruction Set Architecture. One of the features that this simulator has is a view for the pipelined processor, where all the internal signals of the processor are showing their values while the simulation is being run. Figure 2.5 shows this idea. Apart from being able to check the signals of the pipeline, we can also have the information regarding other parts of the core, like the I/O peripherals or the memory, which figure 2.6 shows.
8Chapter 2. Tools for teaching Computer Architecture based on RISC-V Figure 2.4: Nexys A7 FPGA Board [11] Figure 2.5: Ripes[10] processor view Figure 2.6: Ripes[10] memory view
Chapter 3 Contribution to RVfpga Simulator: ViDBo This part of the project consists on extending the functionalities of the Virtual Development Board -ViDBo- integrated in the RVfpga course by Imagination Technologies. Before starting to describe our contribution to the ViDBo simulator, we should remark that this implementation is already being used in the latest version of the RVfpga course[11]. 3.1. ViDBo architecture ViDBo is an application that simulates the behaviour of a SoC, in the case of this version, the RVfpga SoC based on the VeeR EH1 core explained in chapter 2. As all the applications, we can separate its architecture into two big parts: backend and frontend. Although the architecture is very complex, we will only be focusing on the important parts for the project. More specifically, the backend is the part of the simulator where most of the work happens. In this case, we will have the Rvfpga SoC, coded in a Hardware Description Language, and a top module. This top module is described in Verilog, in the rvfpgasim.v file, that will instantiate all the components and signals of the Core that are used for the simulation. The top module is given as an input to Verilator 1. We could think that this tool is a simulator, but the truth is that it is a compiler, since what Verilator does is converting a model coded in a Hardware Description Language -in this case, Veriloginto a C++ -or SystemC- that can be compiled and executed. On the other hand, the frontend is mainly the visual part of the application. In ViDBo, the interface is shown to the user by means of an HTTP server, since everything in this part is coded in HTML and XML languages. Figure 3.1 illustrates the backend and frontend of the different RVfpga tools. We can see that the backend will be common for all the tools in the RVfpga course, whereas the frontend is different depending on the tool that we are using. These parts must be communicating in some way. This is done by the vidbo.c 1https://verilator.org/guide/latest/ 9
10 Chapter 3. Contribution to RVfpga Simulator: ViDBo Figure 3.1: Backend and Frontend architecture of RVfpgaEH1 [11] and vidbo.h files, which describe the interface that must exist in between both parts of the application. The most relevant function of the interface for this implementation is vidbo_send(), which imposes restrictions when sending data from the simulation to the user view. This is the code of the function: int vidbo_send ( vidbo_context_t ∗context , unsigned long _time , char const ∗group , char const ∗item , int val ) { append(&head , _time , group , item , val ) ; lws_callback_on_writable_all_protocol(context−>context , context−>protocols ); return 1; } Although the function is quite complex, the key part to understand is the argument "int val". The restriction imposes that there should be a 32-bit value sent in each call of the function, so that in the implementation we will have to take it into account. We will develop this idea in depth in section 3.3. These files are used to build up the final executable program, Vrvfpgasim, using the well-known make tool. This executable is in charge of running the simulation and being able to interact with the user, by showing the values of the simulator and treating the inputs from the user. 3.2. System on Chip The System on Chip -SoC- this version of ViDBo implements is based on the version 0.7.3 of the SweRVolf SoC 2. This SoC is built over the VeeR EH1 Core Complex, an extension of the VeeR EH1 Core explained in 2. This SoC includes a Boot ROM, a UART, SPI controller, among other functionalities. 2https://github.com/chipsalliance/Cores-SweRVolf/releases/tag/v0.7.3
3.2. System on Chip 11 The RVfpga course extends this functionality in the SoC, by including several new components, such a General Purpose Input/Output controller, a timer controller -also called PTC in this implementation- and another SPI controller. This extended SoC is called SweRVolfX, which figure 3.2 illustrates. Figure 3.2: SweRVolfX SoC [11]. Extensions in red. At the moment this project started, several peripherals were not yet transitioned to simulated circuits, and we chose to transition the RGB LEDs of the board. 3.2.1. Tri-color LEDs This peripheral can show different colors given three different components, following the RGB format; that is, 3 8-bit wide signals to represent colours. Each of these signals can vary from values 0 to 255 in decimal notation, so that the color strength will depend on the value of the signal, in a proportional relationship. The timer module, called PTC, an abbreviation for the different modes the module can operate, that is; Timer mode, PWM mode and Counter mode, is the one in charge of controlling the functionality of this peripheral. Although we have three different modes, the one that is relevant for us so far is the PWM. 3.2.2. PWM The Pulse-Width Modulation -or PWM- is an operating mode of the PTC module of the Core. This modulation is used to create an analog signal using a digital source. Its behaviour is defined by two fields: duty cycle and frequency. The duty cycle is the percentage of time a signal is high over an interval. Figure 3.3 shows a representation of a PWM integrator producing an output voltage by integrating the pulse train. The SoC will generate the PWM from the PTC module (see figure 3.2). This module will provide us four different registers that will define the modulation:
12 Chapter 3. Contribution to RVfpga Simulator: ViDBo 1. RPTC_CTRL: Control register for the PTC core. 2. RPTC_CNTR: Register used to actually count, and is incremented at every timer clock cycle. 3. RPTC_HRC: PTC HI Reference/Capture register. 4. RPTC_LRC: PTC LO Reference/Capture register. Figure 3.3: Representation of a PWM Integrator Producing an Output Voltage by Integrating the Pulse Train[5] To operate in PWM mode, RPTC_HRC and RPTC_LRC should be set with the value of low and high periods of the PWM output signal. RPTC_HRC is number of clock cycles after reset of the RPTC_CNTR when PWM output should go high and RPTC_LRC is number of clock cycles after reset of the RPTC_CNTR when PWM output should go low. RPTC_CNTR can be reset with the hardware reset, bit RPTC_CTRL[CNTRRST] or periodically when RPTC_CTRL[SINGLE] bit is cleared. To enable PWM output driver, RPTC_CTRL[OE] should be set. To enable continues operation, RPTC_CTRL[SINGLE] should be cleared and RPTC_CTRL[EN] should be set. The RPTC_HRC should have lower value than RPTC_LRC. This is because PWM output goes first high and later low. This information is extracted from OpenCores 3. 3.3. Implementation The goal of this implementation is to support the functionality of the Tri-Color LEDs in the simulated RVfpga SoC. By taking a look at the Nexys A7 Reference Manual[5], where it is explained how the LEDs work and which are the needed signals, we started working on the implementation. The manual[5] says that three signals are needed for each Tri-Color LED, one for red, one for green and another one for blue. These signals must come from the top-module, which in the case of ViDBo is a Verilated model that will be in charge of running the simulation. The file that manages the simulation is tb_ViDBo.cpp, and it contains the main simulation loop, whose main body is as follows: while ( ! ( done | | Verilated : : gotFinish ( ) ) ) { ... // Implementation for the t ri −c olor LEDs i f ( main_time % 10000 == 0) { 3https://opencores.org/
3.3. Implementation 13 ... } top−>clk = ! top−>clk ; main_time+=10; } The loop is full of conditional clauses that will check the variable called main_time, which is a counter of clock cycles for the processor of the machine the simulator is running in. Due to potential performance issues, the checking of the signals from the simulation is done at every 10.000 clock cycles, in order to have a more optimized program. At the end of the loop the clock signal is flipped, since each iteration of this loop represents half of a clock cycle; but also the main_time counter is updated, meaning that each clock cycle will move forward 20 instants of time. 3.3.1. Modifying the backend After researching all this information regarding the project, the implementation can begin. We need to know the needed signals that are generated by the top module, explained in section 3.1, that must be described in a HDL file, rvfpgasim.v in the case of ViDBo. This is the code in Verilog for the signals that come from the timer module in the Core: ‘ i f d e f ViDBo ... . pwm_pad_o_ptc2 (pwm_pad_o_ptc2) , . pwm_pad_o_ptc3 (pwm_pad_o_ptc3) , . pwm_pad_o_ptc4 (pwm_pad_o_ptc4) , ... ... ‘ i f d e f ViDBo assign LED_B = pwm_pad_o_ptc2 ; assign LED_R = pwm_pad_o_ptc3 ; assign LED_G = pwm_pad_o_ptc4 ; ‘endif As it is described, the important signals are pwm_pad_o_ptc2, pwm_pad_o_ptc3 and pwm_pad_o_ptc4 (each of these signals is the PWM output of the three PTC modules connected to the Tri-color LED peripheral). In the first block they are assigned to get the value from the Core, and in the second block we can see the renaming for them, in order to be easier for the programmer to use them in the tb_ViDBo.cpp file. Their names are LED_B, LED_R and LED_G respectively. With this, we can use the signals in our implementation as follows: top->LED_R, top->LED_G, top->LED_B. The behaviour of the signals were the same for the three of them. These values given by the simulation expressed a binary behaviour: ’0’ when the LED that represented that signal should be off and ’1’ when the LED should be on.
Chapter 4 Contribution to RVfpga Simulator: Pipeline The RVfpga course covers another simulator, in this case to visualize the pipeline of VeeR processors. Since the aim of the course is teaching Computer Architecture, it must cover different approaches in order to have a better view of the entire ecosystem. The purpose of this contribution is to enhance the user interface, making the simulator more visually attractive, to give a better explanation to the potential students that might be using the tool. The idea is to add the actual datapath of the processor that is being simulated, since in the first version of the simulator, the signals were placed right where they should be in the datapath, so we wanted to enhance the vision by adding the image. Figures 4.1 and 4.2 show the execution of the simulator for both the cores that have been implemented. Figure 4.1: RVfpga Pipeline simulator execution for EH1 core 4.1. Infrastructure In the case of this simulator, the Pipeline simulator, the backend will be exactly the same as the one we had in the ViDBo simulator, explained in chapter 3. It is 21
22 Chapter 4. Contribution to RVfpga Simulator: Pipeline Figure 4.2: RVfpga Pipeline simulator execution for EL2 core a SoC that is being simulated with Verilator. The difference remains in the signals selected. Since there is no interaction with peripherals in this simulator what we want to see are the internal signals of the core and not their outputs. The file structure is similar to the one we had in ViDBo. In this case, all the management of signals is done in the tb_PipelineSimulator.cpp file, which is the file to be modified while implementing the idea of the contribution. The important part in this contribution is the frontend of the simulator. This interface is designed using the GTK tool, which will be the main focus of this contribution. So, in the following section we will introduce the tool. 4.1.1. GTK The GTK Project 1is an open-source library that contains a set of graphical components to develop graphical user interfaces. GTK supports a wide range of the newest technologies regarding user interfaces and graphics, as well as many programming languages, so it can be used across most of the platforms. The GTK Project contains several libraries, which cover different utilities regarding user interfaces. It is distributed in several libraries, like GTK, GDK, GdkPixBuf or Cairo, among others. The documentation 2is centralized in a single website. 4.2. Implementation The important library for this implementation is GTK, since it is the library that was being used when this implementation started. In fact, it was programmed 1https://www.gtk.org/ 2https://docs.gtk.org/
4.2. Implementation 23 as if the window of the simulator were a big matrix of elements -in the GTK nomenclature, grid-. This approach makes sense since it was first thought to place the signal names and values that come from the backend of the simulator. Each signal is placed in a coordinate of the grid, by means of the following function: void gtk_grid_attach (GtkGrid∗grid , GtkWidget∗child , int column , int row , int width , int height ) The gtk_grid _attach() function will place a given GtkWiget in a given position, determined by the parameters column, row, width and height. The problems arised when this contribution was proposed. Since we were sticked to what it was done before, we had to manage the matrix of elements. The approach was very straightforward, by placing the image of the pipelined processor in the background. This idea did not succeed since there was no way for the image to be placed in the right position, since the overlapping is not allowed by this library when having a grid. To allow the overlapping of images, the whole code should be refactored, by changing the structure of the graphical elements in the simulator. Our next approach was to add the images of the components in the position they should be. We took as a reference the positions already computed for the signals and tags the simulator has. We discovered that the library did not treat the coordinates like in a conventional matrix we could think about. We thought that if a component was added in the position (20,10) with a width of 10 and height 5, the component would occupy until the (30, 15) position in the grid. But this was not the case. In fact, the computation of the rows and columns in the grid is proportional and relative to what the actual size of the image of the component is. It will use a scale to compute the final positions. We cannot elaborate more on that since the documentation does not provide any guidance on this topic, nor how the positions are actually computed. Figure 4.3 represents the idea we are explaining. Figure 4.3: RVfpga Pipeline simulator implementation trial Due to lack of time, we did not dig in more, but at least we have discovered
24 Chapter 4. Contribution to RVfpga Simulator: Pipeline some of the limitations for this library. This could be enhanced as a future work, to improve the graphical user interface in the simulator.
Chapter 5 Research on the RIPES simulator Ripes [10] is a very powerful simulator, since there are many tools available for the user and it is good for getting to know the RISC-V architecture and Computer Architecture in general. Thus, we thought that it would be interesting to move one of the cores from the VeeR family to this platform, in order to improve the already explained Pipeline simulator in the RVfpga course. We saw this idea as a challenge, since the already-existing processors available in the simulator were not simulated by the Verilator tool used in RVfpga. Since we wanted to improve the experience of the course, we thought about integrating Verilator-simulated processors in the Ripes simulator. Before doing it, some preliminary work had been made regarding this idea, so we started researching it. This work done is documented in the GitHub repository for Ripes [10], in an article called "New processor Models"1. We took as a reference this document, where the experimental implementation of the PicoRV32 Core 2in Ripes is explained. This core is simpler than the one we were interested in adding, the VeeR EL2 Core, but it should be a good guide. In the document it is mentioned how to add a new processor model, step by step, indicating the important pieces of the code that should be modified in order to success in the implementation. To extend the experiment to the core we want to implement, we first should study the infrastructure of the application in order to understand in a better way what to modify. 5.1. Infrastructure of RIPES When this research started, the Ripes simulator was able to perform the simulation of some generic processors using the RISC-V architecture, all of them with 5 and 6 stages but different features, to have a wide range of situations covered by the tool. These are the supported RISC-V processors in Ripes: 5-stage RISC-V processor 1https://github.com/mortbopet/Ripes/blob/master/docs/new_processor_models.md 2https://github.com/YosysHQ/picorv32 25
26 Chapter 5. Research on the RIPES simulator 5-stage without forwarding unit RISC-V processor 5-stage without harzard unit RISC-V processor 5-stage without forwarding unit nor hazard unit RISC-V processor 6-stage dual issue RISC-V processor All of the processors mentioned above are available in 32-bit and 64-bit versions. This simulation was performed by an ad-hoc simulation coded in C++ language, where the instructions in the selected processor were executed stage by stage. This was also extended to the memory view and I/O view of the processor. 5.1.1. Toolchain for Building Ripes To start implementing the idea, we first had to deeply understand the project and the first step was putting Ripes to work in our local machine. In the repository, there is a guide to compile the project, so that was the entry point of this implementation. The guide explained the needed toolchain to build up the project, that will be explained next. 5.1.1.1. Qt The first tool mentioned for Ripes to work is Qt 3. This is a tool owned and developed by the Qt Group, which provides a framework for developing graphical user interfaces. It can be used by open-source developers, as in this case happened,when Petersen used it to develop the user interface we have in Ripes. The requirements for Ripes are, at the moment of this research, to have the 6.5.0 or later version of Qt. We only had to install this framework in our machine to build Ripes, so our knowledge in Qt should not be more than the utility of the framework. As far as we could see, the work that had been made regarding the implementation for the PicorV32 core was done with Qt 5.0, an older version than the required one by Ripes. This arised an incompatibility to try the previous implementation for the PicoRV32 core in the available version of Ripes. That is why our first goal was to put Ripes to work in our local machine, to start researching and implementing. But this was not the only tool required by Ripes. 5.1.1.2. CMake CMake 4is an open-source software for generating and building programs. This is a project by Kitware, a company focused on researching and developing open-source software in the graphics area. This tool provides several commands to be used while building programs, and in our case, it is integrated to work with Qt. What represented a problem during this research is the integration of both platforms. When building a program with 3https://www.qt.io/ 4https://cmake.org/
5.1. Infrastructure of RIPES 27 CMake and Qt, the requirement for both platforms to work together, is that CMake should know where Qt is installed. For that reason, the CMAKE_PREFIX_PATH variable should be set. It may seem easy since it is only setting an environment variable, but the truth is that we had to dig in the documentation quite deep to learn that this variable, also behaves as a variable that is stored in the cache of the project that is being built, so that it must be set when invoking the CMake tool with the following command: cmake −DCMAKE_PREFIX_PATH= <installation_path_Qt> −S <source−dir> −B <build−dir> Disclaimer: The Ripes simulator has many other dependencies on other tools to work properly, but we are only focusing on the important ones for this project. 5.1.2. Simulator backend As we had mentioned at the beggining of this section, the simulation in Ripes for the available processors is done by an ad-hoc implementation in C++. Since all the processors designed are RISC-V and have similar pipelines, the only differences are some modules for forwarding and hazard detection, but the memory behaves in the same way, as does the ALU, etc. These considerations led Ripes to have a structure where all the processors share the files that describe the behaviour of their common components, and the simulation sources will specialize depending on the processor being used. Here we can see an example: ... i f ( RipesSettings : : value (RIPES_SETTING_PROCESSOR_ID) . i s N u l l ( ) ) { m_currentID = ProcessorID : : RV32_5S; }else { m_currentID = RipesSettings : : value (RIPES_SETTING_PROCESSOR_ID) . value<ProcessorID >(); m_currentID = m_currentID >= ProcessorID : :NUM_PROCESSORS ? ProcessorID : : RV32_5S : m_currentID ; } ... QStringList ext ensions ; i f ( RipesSettings : : value (RIPES_SETTING_PROCESSOR_EXTENSIONS) . i s N u l l ( ) ) extens ions = ProcessorRegistry : : get Desc ripti on ( m_currentID ) . i s a I n f o ( ) . supportedExtensions ; else extens ions = RipesSettings : : value (RIPES_SETTING_PROCESSOR_EXTENSIONS) . value<QStringList >();
28 Chapter 5. Research on the RIPES simulator This example shows exactly what we are explaining. The code is prepared to handle some processor-dependant constraints, so it is done as if it were a template, where it will specialize in the processor that is being in use. In fact, it shows how the default processor when launching Ripes is set, in this case the 32-bit 5- stage RISC-V processor. If the user selects another processor, it is also set in the variable m_currentID. This variable will store the needed information for the current processor that is being simulated in the program. The second part of the code shows how the extensions of the selected processor are extracted, with the method getDescription(), where the stored processor is needed, as well as its supported extensions. 5.2. Verilator-simulated processors in Ripes The goal of this implementation is to add new Verilator-simulated -or Verilatedprocessors in Ripes. The documentation mentioned at the beginning of this chapter gives an almost-full implementation for a Verilated processor. From all the steps the guide provides, there is one we should remark: all the processors in Ripes must be wrapped in an interface, Ripes-dedicated. This is the case of the ripesprocessor.h interface. This interface is in charge of controlling the interaction between the processor that is being simulated and the Ripes environment. It contains several important functions and data structures, like the one that stores the different stages an instruction can be in, in order to interact with the user interface to provide accurate information. This is the code: struct StageInfo { enum class State { None , Stalled , Flushed , WayHazard , Unused }; AInt pc = 0; bool stage_valid = false ; State state ; QString namedState = "" ; bool operator==(const StageInfo& other ) const { return this−>pc == other . pc && this−>stage_valid == other . stage_valid && this−>st a t e == other . st a t e ; } bool operator !=( const StageInfo& other ) const { return ! ( ∗this == other ) ; } }; It contains functions that are important for the simulator to work properly, such as controlling the Program Counter of the processor or the clock. If we take a look at the normal workflow of Ripes, we can check that there are many signals whose values are constantly being updated, at every clock cycle. These signals must come from the simulated core, and in our case, from the Verilator model. This represented the beginning of the end of this implementation, which was
5.2. Verilator-simulated processors in Ripes 29 not finished. To deeply understand this, we may need to outline some features of Verilator. 5.2.1. Verilator limitations When we first saw the opportunity to contribute such a promising project as Ripes, we were very delighted because the current simulator for pipelined processors in the RVfpga Course, explained in chapter 4, could be enhanced. The guide we were following pursued a full implementation in the simulator, but there was a part missing; the visual part, the frontend of the implementation. There was no layout for the PicoRV32 processor, which is the processor being added to Ripes, and the reason was clear. In the layout of all the generic processors Ripes has by default, there are several signals that will be updated, no matter whether the simulation is run without stops, or run step by step. Verilator is a very powerful tool, but it was not enough for this approach. If we take a look at the documentation 5, we can understand better the hierarchy of files that Verilator will create during the generation of executable code processes. During the process, the original signals from the HDL files, where the processor models are described, can be changed, making the tracking of these very difficult. Since Verilator does not ensure that the final model may have the same hierarchy as the input hierarchy of HDL files, and signals can be deleted, or changed, this implementation could be a potential failure. In fact, now it makes sense that the processor model that is integrated in the guide we are following skips this part. Due to lack of time to inquire into this problem, since we realized about this problem after understanding all the infrastructure of the application and all the tools that it needs to work, we propose this research as a future work. More conclusions could be made if we had more time, but this is a potential guide for those who might want to try this in the future, to know the limitations. 5https://verilator.org/guide/latest/verilating.html