From bec5fe9f190e8a66225ab35015908323bcf01c76 Mon Sep 17 00:00:00 2001 From: umarcor Date: Sun, 26 May 2019 19:20:33 +0200 Subject: [PATCH] fix(examples/vhdl/external_buffer): use the reference C sources * add sigabrt.md --- examples/vhdl/external_buffer/run.py | 20 +++++++++-- examples/vhdl/external_buffer/src/main.c | 46 ++---------------------- 2 files changed, 20 insertions(+), 46 deletions(-) diff --git a/examples/vhdl/external_buffer/run.py b/examples/vhdl/external_buffer/run.py index 0241b07793..4f8bc4aa41 100644 --- a/examples/vhdl/external_buffer/run.py +++ b/examples/vhdl/external_buffer/run.py @@ -28,8 +28,12 @@ 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") @@ -42,6 +46,8 @@ "gcc", "-fPIC", "-DTYPE=int32_t", + "-I", + ext_srcs, "-c", join(src_path, "main.c"), "-o", @@ -58,6 +64,8 @@ "gcc", "-fPIC", "-DTYPE=uint8_t", + "-I", + ext_srcs, "-c", join(src_path, "main.c"), "-o", @@ -76,8 +84,16 @@ # 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/src/main.c b/examples/vhdl/external_buffer/src/main.c index bb9aff1e1b..c63bb4e492 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