-
Notifications
You must be signed in to change notification settings - Fork 356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Run the object code from somewhere else then GHDL #819
Comments
Hi @Ingrimmsch, there are multiple ways to achieve what you want.
Some context: the object files are generated after executing I assume that you already knew this, because you read https://ghdl.readthedocs.io/en/latest/using/QuickStartGuide.html at some point. But you might have not understood that you won't get any binary after
The most straighforward solution is for you to use any backend which is not mcode (i.e. GCC or LLVM). This is because mcode is a built-in backend which executes the last steps of elaboration in-memory and runs the simulation directly. Conversely, GCC/LLVM cannot run from memory, so an executable binary is always created as a result of the elaboration (
Additionaly, it is possible to wrap GHDL in some external C/Ada program. As explained in https://ghdl.readthedocs.io/en/latest/using/Foreign.html#wrapping-and-starting-a-ghdl-simulation-from-a-foreign-program, you can write your own C program, and declare
The result will be equivalent in both cases: an executable binary with the default entrypoint set to your Furthemore, it is possible to let the binary be dynamically loaded, as if it was a shared library. This allows to use the same binary in two contexts:
There are some details to take into account when following this last approach, which are related to the visibility of the symbols/functions compiled into the binary/shared library. But I won't go into details now. Please, let us know if you want further details.
Your are very welcome. But you need not to worry about it. This question is much common than you think. It is not usual for VHDL simulators/compilers to support multiple backends, so many people need some time to wrap their head around it. The next question that might arise, is how to pass CLI arguments to the binary you generated. More precisely, how do you parse
I downloaded it and had a look at it. But I did nothing with it, because I think that your question is not really related to the design (VHDL code), but to how to use the tool (GHDL). Nonetheless, let us know if you have any further issue once you have understood the differences between backends. Last, but not least, please feel free to suggest any enhancement to the docs, if you find that it can be made easier to follow for newcomers. *1 @tgingold, I am not sure about this, since you did some recent changes to mcode related to the generation of shared libraries. Is it currently possible to generate an executable object (name it binary or shared library) with mcode? *2 @tgingold, I am neither sure about this. Is correct to say the the first method above will default to EDIT @Ingrimmsch, please, let me suggest you to use VUnit, once you have understood the basics of GHDL. It will make it easier for you to set (complex) generics, generate/open waveforms and print/log messages. Precisely, I use VUnit + GHDL to generate executable binaries that I can then move and run as independent programs. |
*1 @tgingold, I am not sure about this, since you did some recent changes to mcode related to the generation of shared libraries. Is it currently possible to generate an executable object (name it binary or shared library) with mcode?
No. mcode is only for internal execution. But it is possible
*2 @tgingold, I am neither sure about this. Is correct to say the the first method above will default to ghdl_main but that the second one will not compile to an executable binary if main is not defined?
In the ghdl runtime library (grt), there is a default main that directly calls ghdl_main.
|
Hi @1138-4eb, thank you for your detailed answer. First of all -> As a backend i am already using GCC 9.1.0, which is why i already was able to generate some object code. I saw that it's possible to run the GHDL simulation like this, but that wont solve my problem. Probably i wasn't specific enough: I want to try to make a live-time simulation of a VHDL code to extend a small program at my university. Therefore i thought that it would be the easiest way to take the pre-generated object-code of GHDL and use it to simulate a VHDL codes behavior live-time. When the project is finished i want to use a view vhdl modules, connect them virtually with real In- and Out-Pins to make a Piece of hardware thats not as performant as the final FPGA but that you can use to test the basic functions. I hope my attempt is more understandable like this. Greetings Ingrimmsch |
See comment about generics above:
To read the outputs, you can use VHPIDIRECCT or VPI. The following example uses VHPI: https://github.com/VUnit/vunit/pull/465/files
VUnit/vunit#465, VUnit/vunit#470 and VUnit/vunit#476 are work in progress to make it easier to implement these kind of co-simulation schemes with VHPIDIRECT. There are other examples where the 'view' is implemented with Flask and Vuejs, but the core functionality is the same. |
Repository ghdl/ghdl-cosim contains documentation and examples about the features discussed above. |
Hi,
i am playing around with GHDL for a view weeks by now.
In the last days i am trying to find a way to run the object file, generated by gcc, wihtout the further usage of ghdl.
Therefore i analyzed the code in unix but i couldn't figure out how to run the file so far.
Is there a workaround for this task or do you have some advices for me to solve it?
Or is there even a simple way to figure out the name of the function i have to call plus the needed sequence and type of the values i have to hand over to the function?
I know that this request is pretty uncommon, therefore i would like to thank you already now for every help.
Greetings
Ingrimmsch
P.S.: I added the simple example i am using to figure it out inside this .zip file:
ghdl_example.zip
The text was updated successfully, but these errors were encountered: