[an error occurred while processing this directive]

HP OpenVMS Systems Documentation

Content starts here

OpenVMS Alpha Guide to 64-Bit Addressing and VLM Features


Previous Contents Index

8.2 Alpha/VAX Guidelines

Only address, size, and length arguments should be passed as quadwords by value.

Arguments passed by value are restricted to longwords on VAX. To be compatible with VAX APIs, quadword arguments should be passed by reference instead of by value. However, addresses, sizes and lengths are examples of arguments which, because of the architecture, could logically be longwords on OpenVMS VAX and quadwords on OpenVMS Alpha.

Even if the API will not be available on OpenVMS VAX, this guideline should still be followed for consistency across all APIs.

Avoid page size dependent units.

Arguments such as lengths and offsets should be represented in units that are page size independent, such as bytes.

A pagelet is an awkward unit. It was invented for compatibility with VAX and is used on OpenVMS Alpha within OpenVMS VAX compatible interfaces. A pagelet is equivalent in size to a VAX page and should not be considered a page size independent unit because it is often confused with a CPU-specific page on Alpha.

Example: Length_64 argument in EXPREG_64 is passed as a quadword byte count by value.

Naturally align all data passed by reference.

The called routine should specify to the compiler that arguments are aligned, and the compiler can perform more efficient load and store sequences. If the data is not naturally aligned, users will experience performance penalties.

If the called routine can execute incorrectly because the data passed by reference is not naturally aligned, the called routine should do explicit checking and return an error if not aligned. For example, if a load/locked, store/conditional is being done internally in the routine on the data, and the data is not aligned, the load/locked, store/conditional will not work properly.

8.3 Promoting an API from a 32-Bit API to a 64-Bit API

For ease of use, it is best to separate promoting an API from improving the 32-bit design or adding new functionality. Calling a routine within the new 64-bit API should be an easy programming task.

64-bit routines should accept 32-bit forms of structures as well as 64-bit forms.

To make it easy to modify calls to an API, the 32-bit form of a structure should be accepted by the interface as well as the 64-bit form.

Example: If the 32-bit API passed information by descriptor, the new interface should pass the same information by descriptor.

64-bit routines should provide the same functionality as the 32-bit routines.

An application currently calling the 32-bit API should be able to completely upgrade to calling the 64-bit API without having to preserve some of the old calls to the old 32-bit API just because the new 64-bit API is not a functional superset of the old API.

Example: SYS$EXPREG_64 works for P0, P1 and P2 process space. Callers can replace all calls to SYS$EXPREG since SYS$EXPREG_64 is a functional superset of $EXPREG.

Use the suffix "_64" when appropriate.

For system services, this suffix is used for routines that accept 64-bit addresses by reference. For promoted routines, this distinguishes the 64-bit capable version from its 32-bit counterpart. For new routines, it is a visible reminder that a 64-bit wide address cell will be read/written. This is also used when a structure is passed which contains an embedded 64-bit address, IF the structure is not self-identifying as a 64-bit structure. Hence, a routine name need not include "_64" simply because it receives a 64-bit descriptor. Remember that passing an arbitrary value by reference does not mean the suffix is required; passing a 64-bit address by reference does.

This practice is recommended for other routines as well.

Examples:

  • SYS$EXPREG_64 (region_id_64, length_64, acmode, return_va_64, return_length_64)
  • SYS$CMKRNL_64 (routine_64, quad_arglst_64)

8.4 Example of a 32-Bit Routine and a 64-Bit Routine

The following example illustrates a 32-bit routine interface that has been promoted to support 64-bit addressing. It handles several of the issues addressed in the guidelines.

The C function declaration for an old system service SYS$CRETVA looks like the following:


#pragma required_pointer_size save
#pragma required_pointer_size 32
int sys$cretva (
        struct _va_range * inadr,
        struct _va_range * retadr,
        unsigned int       acmode);
#pragma required_pointer_size restore

The C function declaration for a new system service SYS$CRETVA_64 looks like the following:


#pragma required_pointer_size save
#pragma required_pointer_size 64
int sys$cretva_64 (
        struct _generic_64 * region_id_64,
        void *               start_va_64,
        unsigned __int64     length_64,
        unsigned int         acmode,
        void **              return_va_64,
        unsigned __int64 *   return_length_64);
#pragma required_pointer_size restore

The new routine interface for SYS$CRETVA_64 corrects the embedded pointers within the _va_range structure, passes the 64-bit region_id_64 argument by reference and passes the 64-bit length_64 argument by value.


Chapter 9
OpenVMS Alpha Tools and Utilities That Support 64-Bit Addressing

This chapter briefly describes the following OpenVMS Alpha tools that have been enhanced to support 64-bit virtual addressing.

  • OpenVMS Debugger
  • System-code debugger
  • XDELTA
  • Watchpoint utility
  • SDA
  • LIB$ and CVT$ Facilities of the OpenVMS Run-Time Library

9.1 OpenVMS Debugger

On OpenVMS Alpha systems, the Debugger can access the extended memory made available by 64-bit addressing support. You can examine and manipulate data in the complete 64-bit address space.

You can examine a variable as a quadword by using the new option Quad, which is on the Typecast menu of both the Monitor pull-down menu and the Examine dialog box.

The default type for the debugger is longword, which is appropriate for debugging 32-bit applications. It might be advisable to change the default type to quadword for debugging applications that use the 64-bit address space. To do this, use the SET TYPE QUADWORD command.

Note that hexadecimal addresses are now 16-digit numbers on Alpha. For example,


DBG> EVALUATE/ADDRESS/HEX %hex 000004A0
00000000000004A0
DBG>

The debugger supports 32-bit and 64-bit pointers.

For more information about using the OpenVMS Debugger, see the OpenVMS Debugger Manual.

9.2 OpenVMS Alpha System-Code Debugger

The OpenVMS Alpha system-code debugger accepts 64-bit addresses and uses full 64-bit addresses to retrieve information.

9.3 Delta/XDelta

XDELTA has always supported 64-bit addressing on OpenVMS Alpha. Quadword display mode displays full quadwords of information. 64-bit address display mode accepts and displays all addresses as 64-bit quantities.

XDELTA has predefined command strings for displaying the contents of the PFN database. With the PFN database layout changes in OpenVMS Alpha Version 7.0, the command strings and the format of the displays have changed accordingly.

For more information about Delta/XDelta, see the OpenVMS Delta/XDelta Debugger Manual.

9.4 LIB$ and CVT$ Facilities of the OpenVMS Run-Time Library

For more information about 64-bit addressing support for the LIB$ and CVT$ facilities of the OpenVMS RTL library, refer to the OpenVMS RTL Library (LIB$) Manual.

9.5 Watchpoint Utility

The Watchpoint utility is a debugging tool that maintains a history of modifications that are made to a particular location in shared system space by setting watchpoints on 64-bit addresses. It watches any system address, whether in S0, S1, or S2 space.

A $QIO interface to the Watchpoint utility supports 64-bit addresses. The WATCHPOINT command interpreter (WP) issues $QIO requests to the WATCHPOINT driver (WPDRIVER) from commands that follow the standard rules of DCL grammar.

Enter commands at the WATCHPOINT> prompt to set, delete, and obtain information from watchpoints. Before invoking the WATCHPOINT command interpreter (WP) or loading the WATCHPOINT driver, you must set the SYSGEN MAXBUF dynamic parameter to 64000, as follows:


$ RUN SYS$SYSTEM:SYSGEN
SYSGEN> SET MAXBUF 64000
SYSGEN> WRITE ACTIVE
SYSGEN> EXIT

Before invoking WP, you must install the WPDRIVER with SYSMAN, as follows:


$ RUN SYS$SYSTEM:SYSMAN
SYSMAN> IO CONNECT WPA0/DRIVER=SYS$WPDRIVER/NOADAPTER
SYSMAN> EXIT

You can then invoke WP with the following command:


$ RUN SYS$SYSTEM:WP

Now you can enter commands at the WATCHPOINT> prompt to set, delete, and obtain information from watchpoints.

You can best view the WP help screens as well as the output to the Watchpoint utility using a terminal set to 132 characters, as follows:


$ SET TERM/WIDTH=132

9.6 SDA

As of OpenVMS Alpha Version 7.0, SDA allows a user to specify 64-bit addresses and 64-bit values in expressions. It will also display full 64-bit values where appropriate.

For more information about using SDA 64-bit addressing support, see the OpenVMS Alpha System Dump Analyzer Utility Manual.


Chapter 10
Language and Pointer Support for 64-Bit Addressing

Full support in DEC C and the DEC C Run-Time Library (RTL) for 64-bit addressing make C the preferred language for programming 64-bit applications, libraries, and system code for OpenVMS Alpha. The 64-bit pointers can be seamlessly integrated into existing C code, and new 64-bit applications can be developed, with natural C coding styles, that take advantage of the 64-bit address space provided by OpenVMS Alpha.

Support for all 32-bit pointer sizes (the default), all 64-bit pointer sizes, and the mixed 32-bit and 64-bit pointer size environment provide compatibility as well as flexibility for programming 64-bit OpenVMS applications in DEC C.

The ANSI-compliant, #pragma approach for supporting the mixed 32-bit and 64-bit pointer environment is common to DIGITAL UNIX. Features of 64-bit C support include memory allocation routine name mapping (transparent support for _malloc64 and _malloc32) and C-type checking for 32-bit versus 64-bit pointer types.

The OpenVMS Calling Standard describes the techniques used by all OpenVMS languages for invoking routines and passing data between them. The standard also defines the mechanisms that ensure consistency in error and exception handling routines.

The OpenVMS Calling Standard has always specified 64-bit wide parameters. In releases of OpenVMS Alpha prior to Version 7.0, called routines almost always ignored the upper 32-bits of arguments. As of OpenVMS Alpha Version 7.0, the OpenVMS Calling Standard provides the following support for 64-bit addresses:

  • Called routines can start to use complete 64-bit addresses.
  • Callers can pass either 32-bit or 64-bit pointers.
  • Pointers passed by reference often require a new 64-bit variant of the original routine.
  • Self-identifying structures, such as those defined for descriptors and item lists, enable an existing API to be enhanced compatibly.

OpenVMS Alpha 64-bit addressing support for mixed pointers also includes the following features:

  • OpenVMS Alpha 64-bit virtual address space layout that applies to all processes. (There are no special 64-bit processes or 32-bit processes.)
  • 64-bit pointer support for addressing the entire 64-bit OpenVMS Alpha address space layout including P0, P1, and P2 address spaces and S0/S1, S2, and page table address spaces.
  • 32-bit pointer compatibility for addressing P0, P1, and S0/S1 address spaces.
  • Many new 64-bit system services that support P0, P1, and P2 space addresses.
  • Many existing system services enhanced to support 64-bit addressing.
  • 32-bit sign-extension checking for all arguments passed to 32-bit, pointer- only system services.
  • C and MACRO-32 macros for handling 64-bit addresses.


Chapter 11
DEC C RTL Support for 64-Bit Addressing

This chapter describes the 64-bit addressing support provided by the DEC C Run-Time Library on OpenVMS Alpha Version 7.0 systems and higher.

The DEC C Run-Time Library includes the following features in support of 64-bit pointers:

  • Guaranteed binary and source compatibility of existing programs
  • No impact on applications that are not modified to exploit 64-bit support
  • Enhanced memory allocation routines that allocate 64-bit memory
  • Widened function parameters to accommodate 64-bit pointers
  • Dual implementations of functions that need to know the pointer size used by the caller
  • New information available to the DEC C Version 5.2 compiler or higher to seamlessly call the correct implementation
  • Ability to explicitly call either the 32-bit or 64-bit form of functions for applications that mix pointer sizes
  • A single shareable image for use by 32-bit and 64-bit applications

11.1 Using the DEC C Run-Time Library

The DEC C Run-Time Library on OpenVMS Alpha Version 7.0 systems and higher can generate and accept 64-bit pointers. Functions that require a second interface to be used with 64-bit pointers reside in the same object libraries and shareable images as their 32-bit counterparts. No new object libraries or shareable images are introduced. Using 64-bit pointers does not require changes to your link command or link options files.

The DEC C 64-bit environment allows an application to use both 32-bit and 64-bit addresses. For more information about how to manipulate pointer sizes, see the /POINTER_SIZE qualifier and #pragma pointer_size and #pragma required_pointer_size preprocessor directives in the DEC C User's Guide for OpenVMS Systems.

The /POINTER_SIZE qualifier requires you to specify a value of 32 or 64. This value is used as the default pointer size within the compilation unit. As an application programmer, you can compile one set of modules using 32-bit pointers and another set using 64-bit pointers. Use care when these two separate groups of modules call each other.

Use of the /POINTER_SIZE qualifier also influences the processing of DEC C RTL header files. For functions that have a 32-bit and 64-bit implementation, specifying /POINTER_SIZE enables function prototypes to access both functions, regardless of the actual value supplied to the qualifier. In addition, the value specified to the qualifier determines the default implementation to call during that compilation unit.

The #pragma pointer_size and #pragma required_pointer_size preprocessor directives can be used to change the pointer size in effect within a compilation unit. You can default pointers to 32-bit pointers and then declare specific pointers within the module as 64-bit pointers. You would also need to specifically call the _malloc64 form of malloc to obtain memory from the 64-bit memory area.

11.2 Obtaining 64-Bit Pointers to Memory

The DEC C RTL has many functions that return pointers to newly allocated memory. In each of these functions, the application owns the memory pointed to and is responsible for freeing that memory.

Functions that allocate memory are:

  • malloc
  • calloc
  • realloc
  • strdup

Each of these functions has a 32-bit and 64-bit implementation. When the /POINTER_SIZE qualifier is used, the following functions can also be called:

  • _malloc32, _malloc64
  • _calloc32, _calloc64
  • _realloc32, _realloc64
  • _strdup32, _strdup64

When /POINTER_SIZE=32 is specified, all malloc calls default to _malloc32.

When /POINTER_SIZE=64 is specified, all malloc calls default to _malloc64.

Regardless of whether the application calls a 32-bit or 64-bit memory allocation routine, there is still a single free function. This function accepts either pointer size.

Note that the memory allocation functions are the only ones that return pointers to 64-bit memory. All DEC C RTL structure pointers returned to the calling application (such as a FILE, WINDOW, or DIR) are always 32-bit pointers. This allows both 32-bit and 64-bit callers to pass these structure pointers within the application.

11.3 DEC C Header Files

The header files distributed with DEC C Version 5.2 and higher support 64-bit pointers. Each function prototype whose signature contains a pointer is constructed to indicate the size of the pointer accepted.

A 32-bit pointer can be passed as an argument to functions that accept either a 32-bit or 64-bit pointer for that argument.

A 64-bit pointer, however, cannot be passed as an argument to a function that accepts a 32-bit pointer. Attempts to do this are diagnosed by the compiler with a MAYLOSEDATA message. The diagnostic message IMPLICITFUNC means the compiler can do no additional pointer-size validation for calls to that function.

You might find the following pointer-size compiler diagnostics useful:

  • %CC-IMPLICITFUNC
    A function prototype was not found before using the specified function. The compiler and run-time system rely on prototype definitions to detect incorrect pointer-size usage. Failure to include the proper header files can lead to incorrect results or pointer truncation.
  • %CC-MAYLOSEDATA
    A truncation is necessary to do this operation. The operation could be passing a 64-bit pointer to a function that does not support a 64-bit pointer in the given context. It could also be a function returning a 64-bit pointer to a calling application that is trying to store that return value in a 32-bit pointer.
  • %CC-MAYHIDELOSS
    This message (when enabled) helps expose real MAYLOSEDATA messages that are being suppressed because of a cast operation.

11.4 Functions Affected

The DEC C RTL shipped with OpenVMS Alpha Version 7.0 accommodates applications that use only 32-bit pointers, only 64-bit pointers, or a combination of both. To use 64-bit memory, you must, at a minimum, recompile and relink an application. The amount of source code change required depends on the application itself, calls to other run-time libraries, and the combinations of pointer sizes used.

With respect to 64-bit pointer support, the functions in the DEC C RTL fall into four categories:

  • Functions not impacted by choice of pointer size
  • Functions enhanced to accept either pointer size
  • Functions having a 32-bit and 64-bit implementation
  • Functions that accept only 32-bit pointers

From an application developer's perspective, the first two types of functions are the easiest to use in either a single-pointer or mixed-pointer mode.

The third type requires no modifications when used in a single-pointer compilation but might require source code changes when used in a mixed-pointer mode.

The fourth type requires careful attention whenever 64-bit pointers are used.

11.4.1 No Pointer-Size Impact

The choice of pointer-size has no impact on a function if its prototype contains no pointer-related parameters or return values. The mathematical functions are good examples of this.

Even some functions in this category that do have pointers in their prototype are not impacted by pointer size. For example, strerror has the prototype:


char * strerror (int error_number);

This function returns a pointer to a character string, but this string is allocated by the DEC C RTL. As a result, to support both 32-bit and 64-bit applications, these types of pointers are guaranteed to fit in a 32-bit pointer.

11.4.2 Functions Accepting Both Pointer Sizes

The Alpha architecture supports 64-bit pointers. The OpenVMS Alpha Calling Standard specifies that all arguments are actually passed as 64-bit values. Before OpenVMS Alpha Version 7.0, all 32-bit addresses passed to procedures were sign-extended into this 64-bit parameter. The called function declared the parameters as 32-bit addresses, which caused the compiler to generate 32-bit instructions (such as LDL) to manipulate these parameters.

Many functions in the DEC C RTL are enhanced to receive the full 64-bit address. For example, consider strlen:


size_t strlen (const char *string);

The only pointer in this function is the character-string pointer. If the caller passes a 32-bit pointer, the function works with the sign-extended 64-bit address. If the caller passes a 64-bit address, the function works with that address directly.

The DEC C RTL continues to have only a single entry point for functions in this category. There are no source-code changes required to add any of the four pointer-size options for functions of this type. The OpenVMS documentation refers to these functions as 64-bit friendly.

11.4.3 Functions with Two Implementations

There are many reasons why a function might need two implementations---one for 32-bit pointers, the other for 64-bit pointers. Some of these reasons include:

  • The pointer size of the return value is the same size as the pointer size of one of the arguments. If the argument is 32 bits, the return value is 32 bits. If the argument is 64 bits, the return value is 64 bits.
  • One of the arguments is a pointer to an object whose size is pointer-size sensitive. To know how many bytes are being pointed to, the function must know whether the code was compiled in 32-bit or 64-bit pointer-size mode.
  • The function returns the address of dynamically allocated memory. The memory is allocated in 32-bit space when compiled for 32-bit pointers and in 64-bit space when compiled for 64-bit pointers.

From the application developer's point of view, there are three function prototypes for each of these functions. The <string.h> header file contains many functions whose return value is dependent upon the pointer size used as the first argument to the function call. For example, consider the memset function. The header file defines three entry points for this function:


void * memset   (void *memory_pointer, int character, size_t size);
void *_memset32 (void *memory_pointer, int character, size_t size);
void *_memset64 (void *memory_pointer, int character, size_t size);

The first prototype is the function that your application would currently call if using this function. The compiler changes a call to memset into a call to either _memset32 when compiled /POINTER_SIZE=32, or _memset64 when compiled /POINTER_SIZE=64.

You can override this default behavior by directly calling either the 32-bit or the 64-bit form of the function. This accommodates applications using mixed pointer sizes, regardless of the default pointer size specified with the /POINTER_SIZE qualifier.

Note that if the application is compiled without specifying the /POINTER_SIZE qualifier, neither the 32-bit specific nor the 64-bit specific function prototypes are defined. In this case, the compiler automatically calls the 32-bit interface for all interfaces having dual implementations.

Table 11-1 shows the DEC C RTL functions that have dual implementations in support of 64-bit pointer size. When compiling with the /POINTER_SIZE qualifier, calls to the unmodified function names are changed to calls to the function interface that matches the pointer size specified with the qualifier.

Table 11-1 Functions with Dual Implementations
basename malloc strpbrk wcsncat
bsearch mbsrtowcs strptime wcsncpy
calloc memccpy strrchr wcspbrk
catgets memchr strsep wcsrchr
ctermid memcpy strstr wcsrtombs
cuserid memmove strtod wcsstr
dirname memset strtok wcstok
fgetname mktemp strtol wcstol
fgets mmap strtoll wcstoul
fgetws qsort strtoq wcswcs
fullname realloc strtoul wmemchr
gcvt rindex strtoull wmemcpy
getcap strcat strtouq wmemmove
getcwd strchr tgetstr wmemset
getname strcpy tmpnam  
gets strdup wcscat  
index strncat wcschr  
longname strncpy wcscpy  


Previous Next Contents Index