diff --git a/cadpli/cadpli.c b/cadpli/cadpli.c index 35fa57af3..1a1eac3b1 100644 --- a/cadpli/cadpli.c +++ b/cadpli/cadpli.c @@ -16,14 +16,14 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ -#ident "$Id: cadpli.c,v 1.1 2003/02/16 02:23:54 steve Exp $" +#ident "$Id: cadpli.c,v 1.2 2003/02/17 00:01:25 steve Exp $" # include # include -# include # include # include # include +# include "ivl_dlfcn.h" typedef void* (*funcvp)(void); @@ -39,7 +39,7 @@ static void thunker_register(void) for (idx = 0 ; idx < vlog_info.argc ; idx += 1) { char*module, *cp, *bp; - if (strncmp("+cadpli=", vlog_info.argv[idx], 8) != 0) + if (strncmp("-cadpli=", vlog_info.argv[idx], 8) != 0) continue; cp = vlog_info.argv[idx] + 8; @@ -52,7 +52,7 @@ static void thunker_register(void) strncpy(module, cp, bp-cp); module[bp-cp] = 0; - mod = dlopen(module, RTLD_LAZY); + mod = ivl_dlopen(module); if (mod == 0) { vpi_printf("%s link: %s\n", vlog_info.argv[idx], dlerror()); free(module); @@ -60,7 +60,7 @@ static void thunker_register(void) } bp += 1; - boot = dlsym(mod, bp); + boot = ivl_dlsym(mod, bp); if (boot == 0) { vpi_printf("%s: Symbol %s not found.\n", vlog_info.argv[idx], bp); @@ -89,6 +89,13 @@ s_tfcell veriusertfs[0]; /* * $Log: cadpli.c,v $ + * Revision 1.2 2003/02/17 00:01:25 steve + * Use a variant of ivl_dlfcn to do dynamic loading + * from within the cadpli module. + * + * Change the +cadpli flag to -cadpli, to keep the + * plusargs namespace clear. + * * Revision 1.1 2003/02/16 02:23:54 steve * Add the cadpli interface module. * diff --git a/cadpli/cadpli.txt b/cadpli/cadpli.txt index cd8553b64..9aa16b8b5 100644 --- a/cadpli/cadpli.txt +++ b/cadpli/cadpli.txt @@ -2,7 +2,7 @@ CADENCE PLI1 MODULES Copyright 2003 Stephen Williams - $Id: cadpli.txt,v 1.1 2003/02/16 02:44:47 steve Exp $ + $Id: cadpli.txt,v 1.2 2003/02/17 00:01:25 steve Exp $ With the cadpli module, Icarus Verilog is able to load PLI1 applications that were compiled and linked to be dynamic loaded by @@ -20,15 +20,15 @@ latter specify the share object and bootstrap function for running the module. For example, to run the module product.so, that has the bootstrap function "my_boot": - vvp -mcadpli a.out +cadpli=./product.so:my_boot + vvp -mcadpli a.out -cadpli=./product.so:my_boot The "-mcadpli" argument causes vvp to load the cadpli.vpl library -module. This activates the +cadpli= argument interpreter. The -+cadpli=: argument, then, cause vvp, through the +module. This activates the -cadpli= argument interpreter. The +-cadpli=: argument, then, causes vvp, through the cadpli module, to load the loadable PLI application, invoke the my_boot function to get a veriusertfs table, and scan that table to register the system tasks and functions exported by that object. The -format of the +cadpli= extended argument is essentially the same as +format of the -cadpli= extended argument is essentially the same as the +loadpli1= argument to Verilog-XL. The integration from this point is seamless. The PLI application @@ -36,6 +36,13 @@ hardly knows that it is being invoked by Icarus Verilog instead of Verilog-XL, so operates as it would otherwise. $Log: cadpli.txt,v $ +Revision 1.2 2003/02/17 00:01:25 steve + Use a variant of ivl_dlfcn to do dynamic loading + from within the cadpli module. + + Change the +cadpli flag to -cadpli, to keep the + plusargs namespace clear. + Revision 1.1 2003/02/16 02:44:47 steve Add the cadpli HOWTO. diff --git a/cadpli/ivl_dlfcn.h b/cadpli/ivl_dlfcn.h new file mode 100644 index 000000000..2b2f6806e --- /dev/null +++ b/cadpli/ivl_dlfcn.h @@ -0,0 +1,101 @@ +#ifndef __ivl_dlfcn_H +#define __ivl_dlfcn_H +/* + * Copyright (c) 2001 Stephen Williams (steve@icarus.com) + * + * This source code is free software; you can redistribute it + * and/or modify it in source code form under the terms of the GNU + * General Public License as published by the Free Software + * Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ +#ifdef HAVE_CVS_IDENT +#ident "$Id: ivl_dlfcn.h,v 1.1 2003/02/17 00:01:25 steve Exp $" +#endif + +#if defined(__MINGW32__) +# include +# include +typedef void * ivl_dll_t; +#elif defined(HAVE_DLFCN_H) +# include +typedef void* ivl_dll_t; +#elif defined(HAVE_DL_H) +# include +typedef shl_t ivl_dll_t; +#endif + +#if defined(__MINGW32__) +inline ivl_dll_t ivl_dlopen(const char *name) +{ return (void *)LoadLibrary(name); } + +inline void *ivl_dlsym(ivl_dll_t dll, const char *nm) +{ return (void *)GetProcAddress((HINSTANCE)dll,nm);} + +inline void ivl_dlclose(ivl_dll_t dll) +{ (void)FreeLibrary((HINSTANCE)dll);} + +inline const char *dlerror(void) +{ + static char msg[256]; + unsigned long err = GetLastError(); + FormatMessage( + FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + err, + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language + (LPTSTR) &msg, + sizeof(msg) - 1, + NULL + ); + return msg; +} + +#elif defined(HAVE_DLFCN_H) +inline ivl_dll_t ivl_dlopen(const char*name) +{ return dlopen(name,RTLD_LAZY); } + +inline void* ivl_dlsym(ivl_dll_t dll, const char*nm) +{ return dlsym(dll, nm); } + +inline void ivl_dlclose(ivl_dll_t dll) +{ dlclose(dll); } + +#elif defined(HAVE_DL_H) +inline ivl_dll_t ivl_dlopen(const char*name) +{ return shl_load(name, BIND_IMMEDIATE, 0); } + +inline void* ivl_dlsym(ivl_dll_t dll, const char*nm) +{ + void*sym; + int rc = shl_findsym(&dll, nm, TYPE_PROCEDURE, &sym); + return (rc == 0) ? sym : 0; +} + +inline void ivl_dlclose(ivl_dll_t dll) +{ shl_unload(dll); } + +inline const char*dlerror(void) +{ return strerror( errno ); } +#endif + +/* + * $Log: ivl_dlfcn.h,v $ + * Revision 1.1 2003/02/17 00:01:25 steve + * Use a variant of ivl_dlfcn to do dynamic loading + * from within the cadpli module. + * + * Change the +cadpli flag to -cadpli, to keep the + * plusargs namespace clear. + * + */ +#endif