• Aucun résultat trouvé

Porting between HP-UX Pascal and the Pascal Workstation

Dans le document HP-UX Portability Guide (Page 179-189)

This section will be helpful if you need to port programs between the Series 300/400 Pascal Workstation and Series 300/400 HP-UX Pascal. It focuses on conversions of Pascal programs, but also comments on assembly language translation. Some of the information may not apply to Series 700/800 porting.

The material presented deals with commonly encountered porting problems.

Because the Series 300/400 HP-UX Pascal compiler was developed from the Series 200/300 HP Pascal Workstation, the two implementations are very similar. However, some differences still exist when porting between the two systems. If your programs to be ported use operating system-dependent features like low-level I/O functions, then you may have a significant porting job.

Note The following does not cover the few differences between Series 200/300 and Series 300/400 Pascal Workstations. The differences that exist are documented in the Pascal Workstation documentation set.

Module Names

Module names on HP- UX Pascal can be up to 12 characters, while on the Pascal Workstation they can be up to 15.

7-14 Porting Pascal Programs

Real Data Type

Real variables are 32 bits on HP- UX Pascal and 64 bits on the Pascal Workstation. longreals are 64 bits on both implementations.

Input

Although standard Pascal specifies unbuffered input on the HP- UX Pascal implementation, on the Pascal Workstation input is buffered by default. To override this, add the following statement to the beginning of your program:

rewrite(input," ,'unbuffered');

lastpos

lastpos is not implemented on the Pascal Workstation.

linepos

linepos is not implemented on the Pascal Workstation.

Absolute Addressing

Absolute addressing of variables, available through $SYSPROG$, have little meaning on a system which uses virtual memory. Instead, the user will need to use system names. For example, to simulate the Pascal Workstation function IORESULT, the user may declare:

VAR

ioresult['asm_ioresult']: integer;

This declaration gives the user access to the ioresul t variable. Note, however, that the above declaration also gives the user a compiler warning namely symbol already declared regarding asm_ioresul t.

Accessing absolute addresses (such as on the Model 236 graphics display) will result in a system error namely segmentation violation. To gain access to such memory, the user must follow the techniques described in the HP- UX Refer'ence under Section 7: graphics(7).

Porting Pascal Programs 7 -15

7

File Naming

File names in programs on the Pascal Workstation are of the form:

VOL: FILENAME

With HP- UX Pascal, file naming must follow the HP- UX path naming

conventions. This occurs in $INCLUDE$, $SEARCH$, RESET, REWRITE, OPEN, and APPEND statements. Since a user may execute a program from any directory, it is safest to use full path names, rather than relative paths. The following special Pascal Workstation names should translate as follows:

• CONSOLE: Should use the predefined file variable output or the name / dev /tty in a rewrite statement.

• PRINTER: Should use /dev/rlp (/dev/lp is usually locked from user access).

Note that this bypasses the spooler, and could intermix with someone else's output.

• SYSTERM: Simulating this capability first requires a system call to turn off echoing, and then the statement reset (input , " ,'unbuffered').

$SEARCH$ File Names

$SEARCH$ file names on the Pascal Workstation must refer to either simple relocatable ( .0) or archived ( . a) format object files. Libraries will be maintained by the archiver (ar), and the compiler will need a directory in 7 the archive file. This is accomplished by running the program ar -ts on the

archive which creates an entry (in the archive file). This entry can be u~ed

(by the compiler and loader) to randomly access the entry points stored in the library.

Terminal I/O

Pascal on the Pascal Workstation is defined to have unbuffered terminal I/O.

However, the HP-UX system buffers input based on a "line" (a string of characters, terminated by a newline). To overcome this system buffering of input into lines, the user must specify:

rewrite(input,",'unbuffered');

7 -16 Porting Pascal Programs

Heap Management

The Pascal Workstation gives you two choices for dynamic memory

management. The normal mode uses MARK/RELEASE to form a simple scheme.

For more general cases, $HEAP_DISPOSE$ is needed, which will then allow the DISPOSE statement to return memory to the system.

Using HP-UX Pascal, the user has three choices of memory managers: HEAP1, HEAP2, or MALLOC. HEAP1 and HEAP2 are Pascal memory managers, while MALLOC is the system library (C) memory manager.

HEAP1 provides for a simple scheme where DISPOSE returns memory to the Pascal free list, while a RELEASE returns everything above the memory pointer to the HP- UX memory system. This memory then becomes available to any other heap manager. However, this version does not allow any RELEASE to be done after any calls to MALLOC. This does not sound like much of a restriction, but consider that any system calls that you make that need memory are likely to get them via MALLOC.

HEAP2 is more flexible, and allows for coexistence with MALLOC calls. This is accomplished at the cost of additional overhead in both space (8 extra bytes are allocated forward and backward pointers) and time (a RELEASE must traverse the linked list disposing of each block).

The last scheme uses calls to the system library procedure MALLOC to allocate memory. This is a "do-it-yourself' memory allocation scheme, and it requires using $sysprog$ and anyptrs. However, since this method uses MALLOC, it is compatible with allocation by system intrinsics and C.

The HP-UX IOCTL System Call

The following program shows how to use the HP- UX system call IOCTL to modify terminal characteristics. It does unbuffered, non-echoed terminal input.

IOCTL turns off echoing, sets the minimum length line to 1 character, and sets the line timeout to 0.1 seconds.

Porting Pascal Programs 7 ·17

7

7

{simulate the C struct "termio" from /usr/include/termio.h}

termio = packed record

{here are the EXTERBAL/$ALIAS definitions for the system intrinsics}

function $alias '_open'$ openx( var path cst ring

flag integer integer;

external;

function $alias '_read'$ readx( fildes integer var buffer cstring

num integer integer;

external;

procedure $alias '_ioctl'$ ioctl( fildes control

begin

device:='/dev/tty '+chr(O)j fildes:=openx(device,O_RDOBLY)j

{ get the current terminal setup}

ioctl(fildes,TCGETA,old_state)j new_state:=old_statej

{ set the min~um number of chars for a read to 1 } new_state.c_cc[4] :=chr(1)j

{ set the t~eout after the first char to .1 seconds}

new_state.c_cc[5] :=chr(1)j { turn off echoing } new_state.c_lflag[12]:=falsej

{ turn off canonical input (i.e. erase, kill, etc.) } new_state.c_lflag[14]:=falsej

{ load this "new" terminal setup } ioctl(fildes,TCSETAF,new_state)j prompt('enter your name: ')j

repeat

{ now read a single character } result:=readx(fildes,buffer,1)j

{ now echo the successor of the char } if buffer[O]=chr(255) then write(chr(O»

else write(succ(buffer[O]»j { stop on -n }

until buffer[O]=chr(4)j

ioctl(fildes,TCSETAF,old_state)j end.

Porting Pascal Programs 7 ·19

7

17

Library Differences

The Pascal Workstation and HP- UX Pascal use different libraries. This manual will not discuss the differences in detail; for such information, refer to the manuals containing the information on the libraries.

For Pascal Workstation library information, see the Pascal Procedure Library manual.

For HP- UX Pascal library information, you will find relevant material contained in several HP- UX manuals:

• General information on the I/O library is documented in Programming on HP-UX.

• For graphics information, see the applicable graphics manuals.

• The system library is documented in Section 3 of the HP- UX Reference.

Pascal Workstation Libraries

On the Pascal Workstation, there are three primary libraries used by almost everyone:

• The DGL graphics library. This provides a high level (Pascal) interface to device-independent graphics. DGL on the Pascal Workstation is a functional copy of the HP 1000 FORTRAN DGL library. The interface has been changed to provide more relevant names for the procedures as well as a Pascal interface.

• The I/O library. This provides various levels of access to the I/O cards on the Series 300/400 system. These include HP-IB, GPIO, and a serial interface library.

• The INTERFACE library. This is a permanently loaded library (via ini tlib), which contains much of the operating system software (disk drivers, keyboard, etc.).

HP-UX Libraries

HP- UX libraries have similar capabilities as those on the Pascal Workstation, as described below.

7 -20 Porting Pascal Programs

The DGL Graphics Library. On HP- UX, the original HP1000 FORTRAN DGL library was ported creating these differences from the Pascal Workstation:

• The original procedure names were retained.

• Parameters are all passed by reference (var).

• Strings are FORTRAN character arrays (with a separate length parameter).

• Integers are 16 bit integers.

Two header files are provided. They should be included in each program needing access to DGL. The first header,

/usr/lib/graphics/pascal/pdgll.h, provides the type definitions

needed for interfacing to DGL. This includes int and string132. The second header, /usr/lib/graphics/pascal/pdg12 .h, provides the declarations for all the EXTERNAL DGL procedures. It includes $ALIAS$ statements for each used to convert from Pascal string variables.

STAR BASE Library. Another graphics library is STARBASE. This package is intended to be an extension of the HP Graphics Peripheral Interface Standard, which is an extension of the ANSI standard Virtual Device Metafile and Virtual Device Interface. These (and thus STARBASE) form the basis of the Graphics Kernel System. This is a higher level ANSI standard (2D) graphics package.

The STARBASE library provides a high-performance interface to graphics hardware and other selected graphics peripherals. It provides support unavailable in DGL, with access to more device features. STARBASE is available on the 4.0 and subsequent releases of HP- UX.

SYSTEM Library. The SYS TEM library on HP -UX consists of a number of library files. These reside in the directories /lib and /usr/lib, as well as in the kernel itself. The capabilities provided exceed those available on the Pascal Workstation in many cases, but in others, they fall short. Two sections of the HP- UX Reference describe these capabilities in concise form. Section 2 describes the system intrinsics, which are the operating system calls. Section

Porting Pascal Programs 7 ·21

7

7

3 describes the system libraries, which are the libraries for C, math, standard I/O, and various specialized libraries. The HP- UX Reference describes these capabilities via a C language interface (due to the fact that most of them are written in C). Pascal interfacing to any of these functions is usually fairly straightforward, with the main effort involved a result of replacing the header files that are needed.

Compiler Option Differences

The compiler options available on HP- UX Series 300/400 Pascal, with the exceptions below, are a subset of the ones available on the Pascal Workstation implementation. The following options are available only on the Pascal Workstation.

Controls error checking on system I/O routine calls.

Changes size and location of compiler's . REF file.

Controls stack overflow checking.

Switches order of parameters for the STRPOS function.

Allows use of UCSD Pascal extensions. UCSD extensions are not and will not be implemented on HP- UX. There are simple fixes for most of these capabilities. Most notably, the UCSD string functions are supported through Pascal string functions. Also, to allow case statements to "fall through," an OTHERWISE clause is needed.

In addition, the compiler option PARTIAL_EVAL is implemented differently on the two systems. The default on the Pascal Workstation is OFF, but the default on HP-UX Series 300/400 Pascal is ON. This was done to make HP-UX Series 300/400 Pascal compatible with previous HP-UX Pascal implementations. Note that this is different from early releases of Series 300/400 HP -UX Pascal.

7 ·22 Porting Pascal Programs

Assembly Language Conversion

The conversion of assembly language routines from the Pascal Workstation to HP- UX is fairly straightforward. An HP- UX command exists on the Series 300/400 called atrans which translates a Pascal Workstation assembly language source file into an HP- UX assembly language source file using the assembly syntax available since release 5.15. On HP- UX, the external names are referenced via 32 bit addresses, so the code size may grow. Also, many of the assembler directives will not port directly to HP- UX, but some of the important ones have replacements.

The following are points to be aware of when converting:

• Absolute displacements off the program counter cannot be guaranteed to translate correctly. Any line referencing the program counter will be flagged by a warning message.

• The HP- UX assembler restricts expressions involving forward references for which atrans makes no check. Such references may involve only a single symbol, a symbol plus or minus an absolute expression, or the subtraction of two symbols.

• The character <0 is not accepted as a valid identifier character on the HP- UX assembler. It is translated to A and a warning is issued.

• Lines containing the following pseudo-ops have no parallel on the HP- UX assembler and are translated as comment lines: decimal, end, lIen, list, Iprint, nolist, noobj, nosyms, page, spc, sprint, and ttl.

• Lines containing the mname, include, and src pseudo-ops are translated as comment lines, and a warning is printed.

• The following pseudo-ops require manual intervention to translate: com, lmode, ~rg, rorg, rmode, smode, and start. Each line containing these pseudo-ops will cause a message to be printed stating that an error will be generated by the HP-UX assembler.

• When specifying certain addressing modes, the Pascal Workstation assembler allows some operands to appear out of order, whereas the HP-UX assembler does not. atrans does not rearrange these into proper order.

Porting Pascal Programs 7-23

7

7

Dans le document HP-UX Portability Guide (Page 179-189)