Intel XENIX 286 Programmers Guide (86) - Tenox.tc

Intel XENIX 286 Programmers Guide (86) - Tenox.tc Intel XENIX 286 Programmers Guide (86) - Tenox.tc

09.06.2013 Views

XENIX Programming cc: C Compiler Creating Small, Middle, Large, and Huge Programs The cc command supports the creation of programs of a variety of sizes and purposes using the -Ms, -Mm, -Ml, -Mh, and -i options. These options define the size of a given program by defining the number of segments in physical memory to be allocated for your program's use. They also determine how the system loads the program for execution. The cc command allows the creation of programs in five different memory models: impure-text small model, pure-text small model, middle model, large model, and huge model. Each model defines a different type of program structure and storage. Impure-Text Small Model These programs occupy one 64K-byte physical segment in which both text (machine instructions) and data are combined. By default, cc creates impure small model programs. They can also be created using the -Ms option. Pure-Text Small Model These programs occupy two 64K-byte physical segments. Text and data are in separate segments. The text is read-only and may be shared by several processes at once. The maximum program size is 128K bytes. Pure small model programs are created using the -i flag when linking small model programs. Middle Model These programs occupy several physical segments when linked, but only one segment contains data. A text segment is allocated per source module, but all data segments are combined. Special calls and returns are used to access functions in other segments. The total amount of text can be any size. Data must not exceed 64K bytes. Middle models programs are created using the -Mm option. These programs are always pure. Large Model These programs occupy several physical segments with both text and data in as many segments as required. Text is handled as in middle model. Special addresses are used to access data in other segments. Text and data may be any size, but no data item may be larger than 64K bytes. Large model programs are created using the -Ml option. These programs are always pure. Huge Model These programs occupy several physical segments with both text and data as in large model, but arrays may span segments, allowing them to be larger than 64K bytes. Arrays which span more than two segments (128K bytes) must contain elements whose size in bytes is a power of two. Huge model programs are created using the -Mh option. These programs are always pure. Small and middle model object files can be linked only with object files and libraries of the same model. Large and huge model object files can be linked only with large and huge model object files and libraries. You cannot combine small, medium, and large/huge model object files into one executable program. cc automatically selects the correct small, middle, or large versions of the standard libraries based on the configuration option. It is up to you to make sure that all of your object files and private libraries are properly compiled in the appropriate model. 2-5

cc: C Compiler XENIX Programming The special calls and returns used in middle and large model programs may affect execution time, particularly if frequent calls are made to very short routines. In middle, large, and huge model programs, function pointers are 32 bits long. In large and huge model programs, data pointers are 32 bits long. Programs making use of such pointers must be written carefully to avoid incorrect declaration and use of these types. lint will help to check for correct use. Keep the following in mind when programming in huge model. Objects No object can cross a segment boundary. Objects are defined as data structures that can be elements of an array, scalar objects (integers and floating point numbers), and composite objects (structures and unions). If the array requires three or more segments (more than 128K bytes), then the size of the objects in the array must be a power of two. Address Space When accessing a huge model array, the compiler simulates a linear address space. Array Alignment Arrays of objects requiring more than one segment are aligned so that no object crosses a 64K-byte boundary. Pointer Size Another item to be considered when programming in huge model is the value produced by sizeof(huge_item) and sizeof(huge_ptrl - huge_ptr2). To obtain the correct value, sizeof must be type cast as a long 2-6 (long)sizeof(huge item) (long)sizeof(huge =ptrl - huge _ptr2) where the value returned is a long instead of a normal integer.

cc: C Compiler <strong>XENIX</strong> Programming<br />

The special calls and returns used in middle and large model programs may affect<br />

execution time, particularly if frequent calls are made to very short routines.<br />

In middle, large, and huge model programs, function pointers are 32 bits long. In large<br />

and huge model programs, data pointers are 32 bits long. Programs making use of such<br />

pointers must be written carefully to avoid incorrect declaration and use of these types.<br />

lint will help to check for correct use.<br />

Keep the following in mind when programming in huge model.<br />

Objects<br />

No object can cross a segment boundary. Objects are defined as data structures<br />

that can be elements of an array, scalar objects (integers and floating point<br />

numbers), and composite objects (structures and unions). If the array requires<br />

three or more segments (more than 128K bytes), then the size of the objects in<br />

the array must be a power of two.<br />

Address Space<br />

When accessing a huge model array, the compiler simulates a linear address<br />

space.<br />

Array Alignment<br />

Arrays of objects requiring more than one segment are aligned so that no object<br />

crosses a 64K-byte boundary.<br />

Pointer Size<br />

Another item to be considered when programming in huge model is the value<br />

produced by sizeof(huge_item) and sizeof(huge_ptrl - huge_ptr2). To obtain the<br />

correct value, sizeof must be type cast as a long<br />

2-6<br />

(long)sizeof(huge item)<br />

(long)sizeof(huge =ptrl - huge _ptr2)<br />

where the value returned is a long instead of a normal integer.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!