Section F.2. Data Types, Addresses, and Machine Words


F.2. Data Types, Addresses, and Machine Words

When porting applications to Linux on zSeries, it is important to know how the data types and addressing differ on the zSeries platform compared to other hardware platforms.

F.2.1. 31-Bit Addresses

Current zSeries models are 64-bit architectures. For historical reasons, the next-smaller address size is 31-bit, not 32-bit. The 31-bit mode might still be in use for compatibility reasons. It is important to note that 31-bit addresses actually do not have a thirty-second bit, so any address 0x80000000 + n actually maps onto 0x00000000 + n.

Note, however, that casting an integer value to a pointer value does not conform to the language standard. Also, absolute addresses are most likely platform-dependent, so any code actually affected by the problem just mentioned will probably need changes.

Of course, pointer values created using the language's "official" features are always correct. For this reason, the compiler saves the effort to clear the leftmost bit, causing the following expression to yield false:

(void*)0x80000000 == (void*)0x00000000 


F.2.2. Absolute Addresses

A related problem is caused by applications that try to load code at an absolute address by calling mmap with the flag MAP_FIXED. Such usage of absolute addresses is not portable in general and may need changes.

F.2.3. Numbering Conventions for Bits

In Linux, it is common to denote individual bits by the exponent they would have when interpreted as binary numbers. The bits of a 32-bit word, for example, would be denoted as follows:

+--+--+--+----+--+--+ | 31 | 30 | 29 |  ... 2 | 1 | 0 | +--+--+--+----+--+--+ 


Documentation related to the zSeries mainframe, however, counts bits from left to right:

+--+--+--+-----+--+--+ | 0 | 1 | 2 | ... 29 | 30 | 31 | +--+--+--+-----+--+--+ 


Here, the rightmost bit with binary value 20 is called "bit 31." On a 64-bit system, this bit is called "bit 63."

F.2.4. Standard Data Type Sizes

Table F-1 shows the standard sizes of C data types.

Table F-1. Standard C Data Type Sizes

Type

31-Bit Mode

64-Bit Mode

Char

1

1

Short

2

2

Int

4

4

Float

4

4

Long

4

8

Pointer

4

8

Long long

8

8

Double

8

8

Long double

8

8

size_t

4

8

ptrdiff_t

4

8

wchar_t

4

4


The alignment is always the same as the type sizethat is, a variable of type int is 4 bytes long and is stored at a 4-byte boundary. Table F-2 shows the standard data types of the Linux kernel.

Table F-2. Standard Linux Kernel Data Types
 

gid_t

mode_t

pid_t

uid_t

31-bit mode

unsigned int

unsigned int

int

unsigned int

64-bit mode

unsigned int

unsigned int

int

unsigned int


You can find detailed information about data layout in the ELF Application Binary Interface Supplement.[2],[3]

[2] http://oss.software.ibm.com/linux390/docu/l390abi0.pdf

[3] http://oss.software.ibm.com/linux390/docu/lzsabi0.pdf




UNIX to Linux Porting. A Comprehensive Reference
UNIX to Linux Porting: A Comprehensive Reference
ISBN: 0131871099
EAN: 2147483647
Year: 2004
Pages: 175

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net