iverilog/vpi/sys_icarus.c

319 lines
10 KiB
C
Raw Normal View History

/*
Add the stochastic (queue) tasks/function This patch adds full support for the stochastic tasks/functions except the mean inter-arrival and average wait statistics are not currently available. These will be added in a later patch. This implementation goes a bit beyond the standard and supports the following: 1. The job and inform arguments support 32 bit four state values. 2. The id for all routines, the job and inform arguments for $q_add(), the statistic code for $q_exam() along with the queue type and maximum length arguments for $q_initialize() can be less than or equal to 32 bits. The argument will be sign extended if needed to fill the internal 32 bit value. 3. The job and inform arguments to $q_remove() and the status argument for all the routines must be 32 bits, but do not have to be an integer variable (e.g. a 32 bit register or part select is OK). 4. An undefined bit in the id argument for any of the routines will return a status of 2 (undefined queue id). Undefined bits are not automatically converted to zero. 5. Undefined bits in the $q_initialize() queue type and maximum length arguments or the $q_exam() statistic code argument are also flagged as an error (are not converted to zero). 6. The $q_full() function returns 2 on error, the other routines that return a value $q_remove() job/inform arguments and the $q_exam() statistic value argument will usually return x on error. 7. An invalid statistic code will set the $q_exam() status to 8. 8. The $q_exam() statistic value argument can be 32 bits or larger. This allows returning large statistical time values. 9. All time values are internally saved in simulation time units. They will be converted to the calling module's time unit (with rounding) before they are returned. 10. If a $q_exam() statistical value is too large to fit into the variable the maximum positive value will be returned and the status code will be set to 9 (value is too large). 11. If a statistical value is currently undefined $q_exam() will return 10 (no statistical information) (e.g. using code 5 on an empty queue).
2011-04-11 02:16:25 +02:00
* Copyright (C) 2008-2011 Cary R. (cygcary@yahoo.com)
*
* This program is free software; you can redistribute it and/or modify
* it 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.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "sys_priv.h"
#include <assert.h>
static PLI_INT32 finish_and_return_calltf(ICARUS_VPI_CONST PLI_BYTE8* name)
{
vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
vpiHandle argv = vpi_iterate(vpiArgument, callh);
vpiHandle arg;
s_vpi_value val;
(void) name; /* Not used! */
/* Get the return value. */
arg = vpi_scan(argv);
vpi_free_object(argv);
val.format = vpiIntVal;
vpi_get_value(arg, &val);
/* Set the return value. */
vpip_set_return_value(val.value.integer);
/* Now finish. */
vpi_control(vpiFinish, 1);
return 0;
}
static PLI_INT32 task_not_implemented_compiletf(ICARUS_VPI_CONST PLI_BYTE8* name)
{
vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
vpi_printf("%s:%d: SORRY: task %s() is not currently implemented.\n",
vpi_get_str(vpiFile, callh), (int)vpi_get(vpiLineNo, callh),
name);
vpi_control(vpiFinish, 1);
return 0;
}
/*
* This is used to warn the user that the specified optional system
* task/function is not available (from Annex C 1364-2005).
*/
static PLI_INT32 missing_optional_compiletf(ICARUS_VPI_CONST PLI_BYTE8* name)
{
vpiHandle callh = vpi_handle(vpiSysTfCall, 0);
vpi_printf("%s:%d: SORRY: %s() is not available in Icarus verilog.\n",
vpi_get_str(vpiFile, callh), (int)vpi_get(vpiLineNo, callh),
name);
vpi_control(vpiFinish, 1);
return 0;
}
/*
* Register the function with Verilog.
*/
void sys_special_register(void)
{
s_vpi_systf_data tf_data;
vpiHandle res;
tf_data.type = vpiSysTask;
tf_data.calltf = finish_and_return_calltf;
tf_data.compiletf = sys_one_numeric_arg_compiletf;
tf_data.sizetf = 0;
tf_data.tfname = "$finish_and_return";
tf_data.user_data = "$finish_and_return";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
/* These tasks are not currently implemented. */
tf_data.type = vpiSysTask;
tf_data.calltf = 0;
tf_data.sizetf = 0;
tf_data.compiletf = task_not_implemented_compiletf;
tf_data.tfname = "$fmonitor";
tf_data.user_data = "$fmonitor";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$fmonitorb";
tf_data.user_data = "$fmonitorb";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$fmonitoro";
tf_data.user_data = "$fmonitoro";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$fmonitorh";
tf_data.user_data = "$fmonitorh";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$async$and$array";
tf_data.user_data = "$async$and$array";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$async$nand$array";
tf_data.user_data = "$async$nand$array";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$async$or$array";
tf_data.user_data = "$async$or$array";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$async$nor$array";
tf_data.user_data = "$async$nor$array";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$async$and$plane";
tf_data.user_data = "$async$and$plane";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$async$nand$plane";
tf_data.user_data = "$async$nand$plane";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$async$or$plane";
tf_data.user_data = "$async$or$plane";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$async$nor$plane";
tf_data.user_data = "$async$nor$plane";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$sync$and$array";
tf_data.user_data = "$sync$and$array";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$sync$nand$array";
tf_data.user_data = "$sync$nand$array";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$sync$or$array";
tf_data.user_data = "$sync$or$array";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$sync$nor$array";
tf_data.user_data = "$sync$nor$array";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$sync$and$plane";
tf_data.user_data = "$sync$and$plane";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$sync$nand$plane";
tf_data.user_data = "$sync$nand$plane";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$sync$or$plane";
tf_data.user_data = "$sync$or$plane";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$sync$nor$plane";
tf_data.user_data = "$sync$nor$plane";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$dumpports";
tf_data.user_data = "$dumpports";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$dumpportsoff";
tf_data.user_data = "$dumpportsoff";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$dumpportson";
tf_data.user_data = "$dumpportson";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$dumpportsall";
tf_data.user_data = "$dumpportsall";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$dumpportslimit";
tf_data.user_data = "$dumpportslimit";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$dumpportsflush";
tf_data.user_data = "$dumpportsflush";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
/* The following optional system tasks/functions are not implemented
* in Icarus Verilog (from Annex C 1364-2005). */
tf_data.type = vpiSysTask;
tf_data.calltf = 0;
tf_data.sizetf = 0;
tf_data.compiletf = missing_optional_compiletf;
tf_data.tfname = "$input";
tf_data.user_data = "$input";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$key";
tf_data.user_data = "$key";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$nokey";
tf_data.user_data = "$nokey";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$list";
tf_data.user_data = "$list";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$log";
tf_data.user_data = "$log";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$nolog";
tf_data.user_data = "$nolog";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$save";
tf_data.user_data = "$save";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$restart";
tf_data.user_data = "$restart";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$incsave";
tf_data.user_data = "$incsave";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$scope";
tf_data.user_data = "$scope";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$showscopes";
tf_data.user_data = "$showscopes";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$showvars";
tf_data.user_data = "$showvars";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$sreadmemb";
tf_data.user_data = "$sreadmemb";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$sreadmemh";
tf_data.user_data = "$sreadmemh";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
/* Optional functions. */
tf_data.type = vpiSysFunc;
tf_data.sysfunctype = vpiIntFunc;
tf_data.tfname = "$countdrivers";
tf_data.user_data = "$countdrivers";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$getpattern";
tf_data.user_data = "$getpattern";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
tf_data.tfname = "$scale";
tf_data.user_data = "$scale";
res = vpi_register_systf(&tf_data);
vpip_make_systf_system_defined(res);
}