comp.lang.ada
 help / color / mirror / Atom feed
* Accessing a register with a larger size from generic
@ 2001-09-27 18:31 Lutz Donnerhacke
  2001-09-27 19:16 ` David C. Hoos
  2001-09-28  8:53 ` Lutz Donnerhacke
  0 siblings, 2 replies; 4+ messages in thread
From: Lutz Donnerhacke @ 2001-09-27 18:31 UTC (permalink / raw)


  ------------------------------
[...with, use, package (body), ...]
subtype long is Interfaces.C.long;

type call_code is (KILL, FORK, EXIT, ...);
for call_code use (KILL => 1, FORK => 2, ...);

generic
   call : call_code;
   type type1 is private;
function syscall1 (arg1 : type1) return long;

function syscall1 (arg1 : type1) return long is
   res : long;
begin
   Asm ("int $0x80",
        Outputs => long'Asm_Output ("=a", res),
        Inputs  => (call_code'Asm_Input ("0", call),
                    type1'Asm_Input ("b", arg1)),
        Volatile => True);
   return res;
end syscall1;
  ------------------------------

generates code (using GNAT 3.13p) like:
  movb $2, %al
  xorw %bx, %bx
  int  0x80
instead of
  movl $2, %eax
  xorl %ebx, %ebx
  int  0x80


How can I change the type of the generated RTL expression to SI independed
of the generic type?



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Accessing a register with a larger size from generic
  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
  1 sibling, 1 reply; 4+ messages in thread
From: David C. Hoos @ 2001-09-27 19:16 UTC (permalink / raw)
  To: comp.lang.ada

Could it be that you need to use a 'Size clause on
the call_code type so as to make it 32 bits instead of 8 bits?

The friendly compiler probably thinks it's helping you by
making your enumeration type 8 bits wide (assuming there are
less than 256 enumerates).

----- Original Message -----
From: "Lutz Donnerhacke" <lutz@iks-jena.de>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: Thursday, September 27, 2001 1:31 PM
Subject: Accessing a register with a larger size from generic


>   ------------------------------
> [...with, use, package (body), ...]
> subtype long is Interfaces.C.long;
>
> type call_code is (KILL, FORK, EXIT, ...);
> for call_code use (KILL => 1, FORK => 2, ...);
>
> generic
>    call : call_code;
>    type type1 is private;
> function syscall1 (arg1 : type1) return long;
>
> function syscall1 (arg1 : type1) return long is
>    res : long;
> begin
>    Asm ("int $0x80",
>         Outputs => long'Asm_Output ("=a", res),
>         Inputs  => (call_code'Asm_Input ("0", call),
>                     type1'Asm_Input ("b", arg1)),
>         Volatile => True);
>    return res;
> end syscall1;
>   ------------------------------
>
> generates code (using GNAT 3.13p) like:
>   movb $2, %al
>   xorw %bx, %bx
>   int  0x80
> instead of
>   movl $2, %eax
>   xorl %ebx, %ebx
>   int  0x80
>
>
> How can I change the type of the generated RTL expression to SI independed
> of the generic type?
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
>




^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Accessing a register with a larger size from generic
  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-09-28  8:53 ` Lutz Donnerhacke
  1 sibling, 0 replies; 4+ messages in thread
From: Lutz Donnerhacke @ 2001-09-28  8:53 UTC (permalink / raw)


* 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? 



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Accessing a register with a larger size from generic
  2001-09-27 19:16 ` David C. Hoos
@ 2001-10-02  8:01   ` Lutz Donnerhacke
  0 siblings, 0 replies; 4+ messages in thread
From: Lutz Donnerhacke @ 2001-10-02  8:01 UTC (permalink / raw)


* David C. Hoos wrote:
>From: "Lutz Donnerhacke" <lutz@iks-jena.de>
>> type call_code is (KILL, FORK, EXIT, ...);
[...]
>>    Asm ("int $0x80",
>>         Outputs => long'Asm_Output ("=a", res),

>Could it be that you need to use a 'Size clause on
>the call_code type so as to make it 32 bits instead of 8 bits?
>
>The friendly compiler probably thinks it's helping you by
>making your enumeration type 8 bits wide (assuming there are
>less than 256 enumerates).

Exactly. But setting the size of an arbitary input type for a possible Asm
use, causes major problems when constructing predefined composite types of
those types.



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2001-10-02  8:01 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox