diff --git a/ivtest/vpi/hello_vpi1.c b/ivtest/vpi/hello_vpi1.c new file mode 100644 index 000000000..1476fff4b --- /dev/null +++ b/ivtest/vpi/hello_vpi1.c @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2002 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 + */ + +# include + +PLI_INT32 my_hello_calltf(PLI_BYTE8 *xx) +{ + (void)xx; /* Parameter is not used. */ + vpi_printf("Hello World, from VPI.\n"); + return 0; +} diff --git a/ivtest/vpi/hello_vpi2.c b/ivtest/vpi/hello_vpi2.c new file mode 100644 index 000000000..7d6477445 --- /dev/null +++ b/ivtest/vpi/hello_vpi2.c @@ -0,0 +1,43 @@ +/* + * Copyright (c) 2002 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 + */ + +# include + +extern PLI_INT32 my_hello_calltf(PLI_BYTE8 *xx); + +static void my_hello_register(void) +{ + s_vpi_systf_data tf_data; + + tf_data.type = vpiSysTask; + tf_data.tfname = "$my_hello"; + tf_data.calltf = my_hello_calltf; + tf_data.compiletf = 0; + tf_data.sizetf = 0; + vpi_register_systf(&tf_data); +} + +/* + * This is a table of register functions. This table is the external + * symbol that the simulator looks for when loading this .vpi module. + */ +void (*vlog_startup_routines[])(void) = { + my_hello_register, + 0 +}; diff --git a/ivtest/vpi/hello_vpi2.v b/ivtest/vpi/hello_vpi2.v new file mode 100644 index 000000000..1c73ec986 --- /dev/null +++ b/ivtest/vpi/hello_vpi2.v @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2002 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 + */ + + /* + * Here we have the canonical "Hello, World" program written in Verilog, + * with VPI. It uses the hello_vpi.vpi module that is compiled from + * the hello_vpi.c program also in this directory. See the + * hello_vpi.c for instructions on how to compile it. + * + * Compile this program with the command: + * + * iverilog -ohello_vpi hello_vpi.vl + * + * After churning for a little while, the program will create the output + * file "hello" which is compiled, linked and ready to run. Run this + * program like so: + * + * vvp -M. -mhello_vpi hello_vpi + * + * and the program will print the message to its output. Easy! For + * more on how to make the iverilog command work, see the iverilog + * manual page. + */ + +module main(); + +initial + begin + $my_hello; + $finish(0); + end + +endmodule diff --git a/ivtest/vpi_gold/hello2.log b/ivtest/vpi_gold/hello2.log new file mode 100644 index 000000000..ccaa342e4 --- /dev/null +++ b/ivtest/vpi_gold/hello2.log @@ -0,0 +1,4 @@ +Compiling vpi/hello_vpi1.c... +Compiling vpi/hello_vpi2.c... +Making hello_vpi2.vpi from hello_vpi1.o hello_vpi2.o... +Hello World, from VPI. diff --git a/ivtest/vpi_regress.list b/ivtest/vpi_regress.list index d0f85705b..86d68b047 100644 --- a/ivtest/vpi_regress.list +++ b/ivtest/vpi_regress.list @@ -111,6 +111,7 @@ getp normal getp.c getp.log hello_poke normal hello_poke.c hello_poke.log hello_tf normal hello_tf.c hello_tf.log hello_vpi normal hello_vpi.c hello.log +hello_vpi2 normal hello_vpi2.c hello2.log vpi/hello_vpi1.c listparams normal listparams.c listparams.log memmon normal,-g1995 memmon.c memmon.log memwide normal memwide.cc memwide.log