From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by yquem.inria.fr (Postfix) with ESMTP id 2F3C0BC6C for ; Fri, 4 Jan 2008 17:40:50 +0100 (CET) X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: AgAAAKzwfUdQDPIagWdsb2JhbACQEAIJBAQREweaT4IN X-IronPort-AV: E=Sophos;i="4.24,245,1196636400"; d="scan'208";a="7443596" Received: from smtp20.orange.fr ([80.12.242.26]) by mail3-smtp-sop.national.inria.fr with ESMTP; 04 Jan 2008 17:40:50 +0100 Received: from me-wanadoo.net (localhost [127.0.0.1]) by mwinf2006.orange.fr (SMTP Server) with ESMTP id A37A11C0004F for ; Fri, 4 Jan 2008 17:40:49 +0100 (CET) Received: from [192.168.1.5] (ASt-Lambert-152-1-62-107.w82-120.abo.wanadoo.fr [82.120.199.107]) by mwinf2006.orange.fr (SMTP Server) with ESMTP id 6C4491C000B2; Fri, 4 Jan 2008 17:40:49 +0100 (CET) X-ME-UUID: 20080104164049443.6C4491C000B2@mwinf2006.orange.fr Message-ID: <477E62C1.8060301@pragmadev.com> Date: Fri, 04 Jan 2008 17:45:53 +0100 From: David LONY Organization: PRAGMADEV User-Agent: Thunderbird 1.5.0.9 (Windows/20061207) MIME-Version: 1.0 To: Alain Frisch Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Interface between Ocaml and Assembler References: <477DFF6C.1070409@pragmadev.com> <477DFFC7.8@frisch.fr> In-Reply-To: <477DFFC7.8@frisch.fr> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit X-Spam: no; 0.00; ocaml:01 ocaml:01 stdio:01 mlvalues:01 val:01 val:01 argc:01 argv:01 argv:01 printf:01 gcc:01 ocamlopt:01 -output-obj:01 usr:01 lib:01 Ok ok.. But it will be easier to make a "bridge" like this one : "asm code" -> "C code"->"Ocaml code" ? For instance I made 3 program : The first one in assembly (gas.S): .text .global _start _start: call main ret The second in C (test.c): #include #include #include int test_char(int n) { static value * test_char_closure = NULL; if (test_char_closure == NULL) { test_char_closure = caml_named_value("caml_test_char"); } return Int_val(caml_callback(*test_char_closure, Val_int(n))); } int main(int argc, char ** argv) { int result; caml_startup(argv); result = test_char(10); printf("%d\n", result); return 0; } and the last in Ocaml (truc.ml) : let test_char a = a+1 let _ = Callback.register "caml_test_char" test_char;; But when I try to compile and link all object it fails... as gas.S -o gas.o gcc -c test.c -o test.o ocamlopt -output-obj truc.ml -o truc_main.o ld -o test gas.o test.o truc_main.o -L/usr/lib/ocaml/3.09.2/ -lasmrun -lm -ldl /usr/lib/ocaml/3.09.2//libasmrun.a(ints.o): In function `caml_int64_of_string': (.text+0xb4b): undefined reference to `__udivdi3' /usr/lib/ocaml/3.09.2//libasmrun.a(ints.o): In function `caml_int64_mod': (.text+0xe55): undefined reference to `__moddi3' /usr/lib/ocaml/3.09.2//libasmrun.a(ints.o): In function `caml_int64_div': (.text+0xe9e): undefined reference to `__divdi3' Does anyone has a solution ? Regards. David LONY Alain Frisch a écrit : > David LONY wrote: >> Is it possible to interface assembler code with an Ocaml code ? I >> mean..is it possible to call a Ocaml function from an assembler code >> by using the asm instruction "call my_function" (gas asm)? > > Yes, you can call an OCaml function from assembler using the same > method as from C, that is through caml_callback* functions (see > Section 18.7.1 in the OCaml manual). However, dealing with the GC > properly in assembler is tricky: you'll have to reproduce the behavior > of the CAMLlocal and CAMLparam macros. > > -- Alain > > >