How to call a "C" function that is implemented in a ROM (or at an address) from ADA? -
i have question way call "c" function in rom, looking way without involving link-time changes.
for example, know "c" function:
int my_func(int a);
is located @ address 0xffff_aaaa;
so try:
type rom_my_func access function (a : interfaces.c.int) return interfaces.c.int; pragma convention (c, rom_my_func); ada_my_func : rom_my_func := 16#ffff_aaaa#;
the error can't around assignment of ada_my_func, unsure if there typecast, , attempt @ using system.address_to_access_conversions did not prove successful either.
any pointer(s) examples and/or appreciated.
if you’re using modern gnat , ada2012 can say
function my_func (a : interfaces.c.int) return interfaces.c.int import, convention => c, address => system'to_address (16#ffff_aaaa#);
note system’to_address
gnat-specific; use system.storage_elements.to_address
.
i ran program using under gdb , got
(gdb) run starting program: /users/simon/tmp/so/asker program received signal sigsegv, segmentation fault. 0x00000000ffffaaaa in ?? ()
so it’s done right thing.
without using ada2012 aspects, write
function my_func (a : interfaces.c.int) return interfaces.c.int; pragma import (c, my_func); my_func'address use system'to_address (16#ffff_aaaa#);
Comments
Post a Comment