comp.lang.ada
 help / color / mirror / Atom feed
From: lutz@iks-jena.de (Lutz Donnerhacke)
Subject: Re: Accessing a register with a larger size from generic
Date: Fri, 28 Sep 2001 08:53:51 +0000 (UTC)
Date: 2001-09-28T08:53:51+00:00	[thread overview]
Message-ID: <slrn9r8ekt.kv.lutz@taranis.iks-jena.de> (raw)
In-Reply-To: slrn9r6s3u.pqt.lutz@belenus.iks-jena.de

* Lutz Donnerhacke wrote:
>  ------------------------------
>[...with, use, package (body), ...]
>subtype long is Interfaces.C.long;
...
+ for call_code'Size use long'Size;
>
>generic
>   call : call_code;
>   type type1 is private;
>function syscall1 (arg1 : type1) return long;
>
>function syscall1 (arg1 : type1) return long is
>   res : long;
+   function To_Long is Unchecked_Conversion (type1, long);
>begin
>   Asm ("int $0x80",
>        Outputs => long'Asm_Output ("=a", res),
-        Inputs  => (call_code'Asm_Input ("0", call),
-                    type1'Asm_Input ("b", arg1)),
+        Inputs  => (long'Asm_Input ("0", To_Long (call)),
+                    long'Asm_Input ("b", To_Long (arg1))),
>        Volatile => True);
>   return res;
>end syscall1;
>  ------------------------------

This is a quick and dirty solution, because the user is required to use only
types of the given size. In most cases this requires the following ugly code:

  type filedescriptor is new Interfaces.C.int;
  type filedescriptor_long is new filedescriptor;          -- better subtype?
  for filedescriptor_long'Size use Interfaces.C.long'Size; -- ... no: fails
  type ... is record ... fd : filedescriptor; ... end record;
  for ... use record ... fd at ... range 0 .. 15; ... end record;
  
  function sys_close is new syscall1 (CLOSE, filedescriptor_long);
  ...
  if sys_close (filedescriptor_long (fd)) /= 0 then  -- Ugly!

Something I can try? 



      parent reply	other threads:[~2001-09-28  8:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-09-27 18:31 Accessing a register with a larger size from generic Lutz Donnerhacke
2001-09-27 19:16 ` David C. Hoos
2001-10-02  8:01   ` Lutz Donnerhacke
2001-09-28  8:53 ` Lutz Donnerhacke [this message]
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox