PowerAda Using Objects Defined by Other Languages

From OC Systems Wiki!
< PowerAda:Interface to Other Languages
Revision as of 00:35, 25 April 2019 by imported>WikiVisor (Text replacement - """ to """)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

The Import pragma provides a means of addressing objects through an external name. The actual object must be created in some other unit, normally by another language, and this capability allows you to import that object and reference it in Ada. For example, to define an Ada variable to correspond to the C global variable errno in the read-write segment, you could use the declaration:

Error_Value : Integer;
pragma Import( C, Error_Value, "errno");

Note that explicit initialization for imported objects are not allowed. Any implicit initialization (for example, setting access values to null) is not performed for imported objects.

Note: As is the case for imported subprograms, the Link_Name parameter of pragma Import is also available for objects, but should not normally be needed.

Where Parameters are Passed

For a call to an Ada subprogram, the compiler allocates a parameter area on the stack and reserves enough space to hold all the parameters to the subprogram. "Register Usage" shows the registers that are available for passing parameters. For such parameters, space is reserved in the stack but is not initialized. For other parameters, which are not placed into registers, the values are placed on the stack. For more details about how particular kinds of data types are passed to Ada subprograms, generate an assembler listing with the -a compiler option and refer to the listing.

Register Usage

The PowerPC architecture specifies 32 general-purpose registers, 32 floating-point registers, and several control registers. When calling subprograms specified in Import pragmas, PowerAda programs use the usual PowerPC conventions for register linkage. The register usage during a call to an Ada subprogram is shown in the table below. Registers designated as "preserved" contain the same values when the subprogram ends as when it is entered.

Register Use Preserved
r0 Local temporary No
r1 Stack pointer Yes
r2 TOC pointer Yes
r3..r10 Parameters (not floating-point)

Non-float function return in r3

r11..r12 Local temporary No
r13..r19 Local temporary Yes
r20 Current task MSR Yes
r21..r28 Local temporary Yes
r29 Pointer for nested subprograms Yes
r30 Local temporary Yes
r31 Auxiliary stack frame pointer Yes
fp0 Local temporary No
fp1 .. fp13 Floating Point Parameter values

Float function return in fp1

fp14 .. fp31 Local temporary Yes

Note: These conventions may change in subsequent releases or as a result of service. Avoid building strong dependencies on these conventions to prevent possible migration problems. For Linux register usage, consult your Linux documentation.