On Wed, Apr 10, 2013 at 12:41 AM, Martin Strubel <[email protected]>wrote:
> Hi Jon, > > > > > I am attempting to write a multithreaded application in VHDL, using GHDL > > as the compiler. I need to call from C a function written in VHDL and > > compiled into object form using GHDL back into the VHDL code somehow, > > since I can't get direct access to pthreads from VHDL. > > Did you check the VHPI interface? You can call C stuff from VHDL, but > maybe you've run into issues with pointers? > I don't need pointers right now, and anyway they would be somewhat useless as VHDL only has an abstract pointer type. If I can get the damn variables and functions properly exported as symbols in the final elaborated executable (see below), I can always hack it on the C side by manually specifying the symbols in fixed code at compile time, or passing strings of symbol names using VHPIDIRECT and then using dlsym() (with a linker option to force exported symbols to be dynamic) to get direct access to the symbol table at runtime. > I'd imagine calling VHDL routines from C a little riskier. > Well, I found the initial problem. Apparently the only symbols exported (even in munged/mangled format) from the elaboration step are the architecture blocks and not the function/procedure code sections. Fine for simulation, but not so good for "real" program execution. I am going to try either re-linking the various .o files with the elaborated executable, or skipping the elaboration step altogether and doing the linking using 'ld' (and then probably use a C-language main() entrypoint stub). > See below about comments to linking. > > > > > I see that my main function work.init_pkg.init shows up in the symbol > > table of the VHDL object file: > > > > 000000000000008b g F .text00000000000000d0 work__init_pkg__init > > > > I have tried using: > > > > extern void work__init_pkg__init(); > > > > in my C code, but at link time the compiler claims that it can't find > > the symbol: > > > > ghdl -e --workdir=../../work -Wl,-l:../lib/libc_scandir_.o > > -Wl,-l:../lib/clock_posix_.o -Wl,-l:../lib/threader_.o -Wl,-ldl > > -Wl,-lpthread controlix > > ../lib/threader_.o: In function `thread': > > /home/jon/controlix-code-0/src/lib/threader_.c:20: undefined reference > > to `work__init_pkg__init' > > > > Any ideas what's wrong, or what I should be doing differently? > > > > The symbol have a prepended '_' to be called from C directly. You sure? Prepended '_' or not, I didn't see any matching symbol for my init() function anywhere in the elaborated executable (too long of a symbol table to paste into a mailing list message, just take my word for it). > You'd have > to probably develop some sort of wrapper and/or use nasty inline > assembler hacks. > See above. If I can get the binary objects to link in properly with their original symbol tables, I can get pointers to work. Jon
_______________________________________________ Ghdl-discuss mailing list [email protected] https://mail.gna.org/listinfo/ghdl-discuss
