diff --git a/examples/vhdl/external_buffer/run.py b/examples/vhdl/external_buffer/run.py index 76cd627d2..6f040b24e 100644 --- a/examples/vhdl/external_buffer/run.py +++ b/examples/vhdl/external_buffer/run.py @@ -28,8 +28,10 @@ from vunit import VUnit from os import popen from os.path import join, dirname +import inspect src_path = join(dirname(__file__), 'src') +ext_srcs = join(dirname(inspect.getfile(VUnit)), 'vhdl', 'data_types', 'src', 'external') # Compile C applications to an objects c_iobj = join(src_path, 'imain.o') @@ -38,6 +40,7 @@ print(popen(' '.join([ 'gcc', '-fPIC', '-DTYPE=int32_t', + '-I', ext_srcs, '-c', join(src_path, 'main.c'), '-o', c_iobj ])).read()) @@ -45,6 +48,7 @@ print(popen(' '.join([ 'gcc', '-fPIC', '-DTYPE=uint8_t', + '-I', ext_srcs, '-c', join(src_path, 'main.c'), '-o', c_bobj ])).read()) @@ -58,8 +62,8 @@ # Add the C object to the elaboration of GHDL for tb in lib.get_test_benches(pattern='*tb_ext*', allow_empty=False): - tb.set_sim_option('ghdl.elab_flags', ['-Wl,' + c_bobj], overwrite=True) + tb.set_sim_option('ghdl.elab_flags', ['-Wl,' + c_bobj, '-Wl,-Wl,--version-script=' + join(ext_srcs, 'grt.ver')], overwrite=True) for tb in lib.get_test_benches(pattern='*tb_ext*_integer*', allow_empty=False): - tb.set_sim_option('ghdl.elab_flags', ['-Wl,' + c_iobj], overwrite=True) + tb.set_sim_option('ghdl.elab_flags', ['-Wl,' + c_iobj, '-Wl,-Wl,--version-script=' + join(ext_srcs, 'grt.ver')], overwrite=True) vu.main() diff --git a/examples/vhdl/external_buffer/sigabrt.md b/examples/vhdl/external_buffer/sigabrt.md new file mode 100644 index 000000000..822d76d6c --- /dev/null +++ b/examples/vhdl/external_buffer/sigabrt.md @@ -0,0 +1,26 @@ +When VHDL 1993 is used, the simulation is terminated with an `abort`, which prevents the user from running post-checks. +These are some snippets to test it. See https://github.com/VUnit/vunit/pull/469#issuecomment-485723516. + +``` python +https://bugs.python.org/issue12423 +def handler(signum, frame): + print('Signal handler called with signal', signum) +import signal +signal.signal(signal.SIGABRT, handler) +import os +os.abort() +``` + +``` c +#include + +void sigabrtHandler(int sig_num) +{ + // Reset handler to catch SIGINT next time. Refer http://en.cppreference.com/w/c/program/signal + signal(SIGABRT, sigabrtHandler); + printf("\nSIGABRT caught!\n"); + fflush(stdout); +} + +signal(SIGABRT, sigabrtHandler); +``` \ No newline at end of file diff --git a/examples/vhdl/external_buffer/src/main.c b/examples/vhdl/external_buffer/src/main.c index bb9aff1e1..c63bb4e49 100644 --- a/examples/vhdl/external_buffer/src/main.c +++ b/examples/vhdl/external_buffer/src/main.c @@ -21,10 +21,8 @@ or tb_ext_integer_vector.vhd #include #include #include +#include "vhpidirect_user.h" -extern int ghdl_main (int argc, char **argv); - -uint8_t *D[1]; const uint32_t length = 5; /* @@ -34,7 +32,7 @@ const uint32_t length = 5; [2/3, 3/3), while incrementing each value by two. */ static void exit_handler(void) { - uint i, j, z, k; + unsigned i, j, z, k; TYPE expected, got; k = 0; for (j=0; j<3; j++) { @@ -80,43 +78,3 @@ int main(int argc, char **argv) { // Start the simulation return ghdl_main(argc, argv); } - -// External string/byte_vector through access (mode = extacc) - -void set_string_ptr(uint8_t id, uint8_t *p) { - D[id] = p; -} - -uintptr_t get_string_ptr(uint8_t id) { - return (uintptr_t)D[id]; -} - -// External string/byte_vector through functions (mode = extfnc) - -void write_char(uint8_t id, uint32_t i, uint8_t v ) { - D[id][i] = v; -} - -uint8_t read_char(uint8_t id, uint32_t i) { - return D[id][i]; -} - -// External integer_vector through access (mode = extacc) - -void set_intvec_ptr(uint8_t id, uintptr_t *p) { - D[id] = (uint8_t*)p; -} - -uintptr_t get_intvec_ptr(uint8_t id) { - return (uintptr_t)D[id]; -} - -// External integer_vector through functions (mode = extfnc) - -void write_integer(uint8_t id, uint32_t i, int32_t v) { - ((int32_t*)D[id])[i] = v; -} - -int32_t read_integer(uint8_t id, uint32_t i) { - return ((int32_t*)D[id])[i]; -} \ No newline at end of file