Trimodal Programing
Trimodal Programing
on z/OS
SHARE 118 in Atlanta, Session 10409
Avri J. Adleman, IBM
[email protected]
(Presented by John Ehrman, IBM)
March 16, 2012
AJA-2
Historical perspective Historical perspective
Classical S360/370
370/XA
ESA/390
(1988) Dataspaces and Access Registers
z/Architecture
(2001) Trimodal addressing: 24-, 31-, or 64-bit
addressing
AJA-3
Memory layout Memory layout
Below the 16M Line
24 Bit Addressing
Code: RMODE=24
Data: GETMAIN LOC=BELOW
Above the 16M Line
31 Bit Address
Code: RMODE=ANY
(may be below the line)
Data: GETMAIN LOC=ANY
(may be below the line)
Above the 2G Bar
64 Bit Address
Code: None (as yet)
Data: IARV64
0
16 Megabytes
(2
24
Bytes)
2 Gigabytes
(2
31
Bytes)
16 Exabytes
(2
64
Bytes)
Blackout Area (2G)
Below the 16M
Line
Data & Code
Above the 16M
Line
Data & Code
Above the 2G Bar
Data Only
System
Code and/or Data
AJA-4
Terminology: all machine generations Terminology: all machine generations
Byte 8 bits
Halfword 2 Bytes (16 Bits)
Fullword (Word) 4 Bytes (32 Bits)
Doubleword 8 Bytes (64 Bits)
Quadword 16 Bytes (128 Bits)
Notation: 64-bit based [32-bit based]
64-bit based (Doubleword)
32-bit based (Fullword)
Positions:
High Order refers to the low numbered bits
Low Order refers to the high numbered bits
AJA-5
Registers Registers
16 General Purpose Registers
In all generations of processors
Pre-z/Architecture
32 bits in size (the Traditional environment)
z/Architecture
64 bits in size: (sometimes called Grande)
Low Order Word: same as with Pre-z/Architecture processors
TraditionalInstructions that use 24- and 31-bit addressing
High Order Word: z/Architecture Extension
New z/Architecture Instructions
Modal and modeless
64 bit addressing
Ignored by traditionalmodeless instructions
AJA-6
Address formats Address formats
24-bit addressing
31-bit addressing
64-bit addressing
8 Bits 24 bits
0,1 . . . 7,8 . . . 31
1
Bit 31 Bits
0 1 . . . 31
(32 Bits High Half: New) 64 Bits (32 Bits Low Half: Old)
0 . . . 31, 32 . . . 63
AJA-7
24-bit addressing in System/360 24-bit addressing in System/360
32 bits
High 8 bits (0 to 7) for user (flags, etc)
BALR instruction (ILC, CC, Program Mask)
DCB fields
Low 24 bits (8 to 31) for addressing
Special addressing-mode instructions
None (none needed!)
AJA-8
24- and 31-bit addressing in 370/XA 24- and 31-bit addressing in 370/XA
32 Bits
High Order bit indicates addressing mode
0 for 24-bit addressing, 1 for 31-bit addressing
Bits 1 to 7 depend on addressing mode
Part of the address (31-bit addressing)
Flags, etc. (24-bit addressing)
Special addressing-mode instructions
BSM (Branch and Set Mode)
BASSM (Branch and Save and Set Mode)
More about these two, later
AJA-9
64-, 31-, and 24-bit addressing in 64-, 31-, and 24-bit addressing in
z/Architecture z/Architecture
General Purpose Registers: 64 Bits (Doubleword)
32 Bit Extension (High Order Word)
Part of Address, Data, or Unused
32 Bit Original (Low Order Word)
Retains Addressing Methodology for 24 -and 31-bit processing
Low order Bit 63[31]
Considered part of address -or- 64-bit addressing-mode indicator!
Special addressing-mode instructions
Traditional:
BASSM, BSM
New with z/Architecture:
SAM24, SAM31, SAM64 and TAM
AJA-10
PSW description: 2 architecture modes PSW description: 2 architecture modes
ESA/390 mode
Doubleword (64 Bits )
Bit 12 is always 1
Bit 31 is always 0
Instruction Address:
Bits 33 to 63
Addressing Mode (A)
Bit 32 determines addressing
mode
0 in 24-bit mode
1 in 31-bit mode
z/Architecture mode
Quadword (128 Bits)
Bit 12 is always 0
Bit 31 contains the EA mode
Instruction Address
Bits 64 to 127
Addressing mode
Bit 31 (EA): Extended Addressing
Mode
Bit 32 (BA): Basic Addressing
Mode
EA(0) EA(1)
BA(0) 24 Invalid
BA(1) 31 64
Addressing Modes
AJA-11
PSW formats: 2 architecture modes PSW formats: 2 architecture modes
ESA/390: Doubleword (64 bits)
Instruction Address (Bits 0 to 31)
Instruction Address (Bits 32 to 63)
z/Architecture: Quadword (128 bits)
Instruction Address A
0 R 000 T I E Key 1 M W P AS CC Mask 0000 0000
0 R 000 T I E Key 0 M W P AS CC Mask 0000 000
Zero-Filled (Bits 33 to 63)
B
E
AJA-12
Architecture-mode-dependent Architecture-mode-dependent
instructions instructions
Processed differently based on Architecture Mode:
Same code may behave differently in z/Architecture mode vs.
non- z/Architecture (ESA/390) mode
Small (rare) number of cases
Examples:
BAKR and PR
Saves/Restores 64 bit registers
ESTA
PSW functions
BASSM & BSM
We will talk more about these two
Differences are minimal
They do what you would expect
AJA-13
Modeless instructions Modeless instructions
Independent of architecture mode and addressing mode
Function is identical
Generally non-storage access type instructions
Register-register type instructions
Size of register access implied by instruction name
General Purpose Registers
Pre-z/Architecture instructions
Operate only on low order word (bit 32[0] to bit 63[31])
High order word (bits 0 to 31 of 64) ignored
Examples: L, LR, A, AR, M, MR, SRDA,
z/Architecture instructions
Operate either on 32-bit or all 64-bit registers
Examples: LGR (64-64), AGFR (64-32), RLL (32), RLLG (64),
AJA-14
" Regular" " Regular" modal instructions (1) modal instructions (1)
Addresses function differently based on addressing mode
Base and Displacement are no different
May be hybrid with modeless
Very predictable
No hidden surprises
Generally the most commonly used instructions
Examples:
MVC both storage operands depend on addressing mode
Loads and Stores (hybrids)
Arg
1
(register) size is based on instruction name (e.g. L vs LG)
Arg
2
(base and displacement) depends on addressing mode
AJA-15
" Regular" " Regular" modal instructions (2) modal instructions (2)
Load Address Types
LA, LAE, LAY: R
1
,D
2
(X
2
,B
2
)
Modal Processing 64-bit register
24-bit (high word is unchanged)
Low order word
Clears eight bits: 32[0] to 39[7]
Retains all other bits
31-bit (high word is unchanged)
Low order word
Clears one bit: 32[0]
Retains all other bits
64-bit
Sets full 64 bit register
Lengths in registers usually interpreted based on addressing modes
Examples: CLCLE, MVCLE, TRE, etc.
Some do not, such as MVCL and CLCL
FF FF FF FF 00 FF FF FF
FF FF FF FF 7F FF FF FF
FF FF FF FF FF FF FF FF
AJA-16
" Irregular" " Irregular" modal instructions modal instructions
Function differently based on addressing mode
Reference or address storage
Base and Displacement
Register storage reference
Have possible unpredictable side effects or processing
Visit: Principles of Operations
Read the fine print!
Not many cases; usually, extensive or complex instructions
Examples:
TRT sets GPR 1 differently depending on addressing mode
ESTA (see code 1)
If possible use code 4
AJA-17
Mode-switching instructions Mode-switching instructions
Branch & Set Mode
BSM R
1
,R
2
RR-Format:
R
1
= 32- or 64-bit register
R
1
0
Receives PSW addressing
mode bit only; rest unchanged
R
1
= 0
No Address mode bit saved
R
2
= 32- or 64-bit register
R
2
0
Branch-to address
New addressing mode
R
2
= 0
No Branching
No Address Mode bit saved
Branch & Save & Set Mode
BASSM R
1
,R
2
RR-Format:
R
1
= 32- or 64-bit register
R
1
any register number
Receives current PSW
address (of next instruction)
and PSW addressing mode
R
2
= 32- or 64-bit register
R
2
0
Branch-to address
New addressing mode
R
2
= 0
No Branching
No Address Mode bit saved
0B R
1
R
2
0C R
1
R
2
AJA-18
Register addressing-mode formats for Register addressing-mode formats for
BSM and BASSM BSM and BASSM
Bits: 0 to 31 32 33 to 39 40 to 62 63
Ignored 0 Ignored Address 0
Ignored 1 Address 0
Address 1
Bit Mappings
24-Bit Addressing Mode
31-Bit Addressing Mode
64-Bit Addressing Mode
Mode Setting Bit
AJA-19
BASSM & BSM addressing BASSM & BSM addressing
Pre z/Architecture
Always an even branch
address
32-bit Register Only
High order bit mode setting
0 for 24-bit addressing
1 for 31-bit addressing
Low order bit
Part of instruction address
0: Valid
1: Odd instruction
address; Invalid!
z/Architecture 64-bit
Always an even branch
address
64-bit register
Low-order bit (63)
Not used as part of branch
address
0 for 24-, 31-bit addressing
1 for 64-bit addressing
High/Low order bit 32[0]
For 24-, 31-bit addressing
determines mode as in pre-
z/Architecture
For 64-bit mode, part of
instruction address
Note !!!
AJA-20
Mode-switching examples: Mode-switching examples:
calls within a single assembly calls within a single assembly
* Goto 24-bit mode from any mode
LA R15,GOTO24
BASSM R14,R15
* Goto 31-bit mode from any mode (1)
L R15,GOTO31@
BASSM R14,R15
* Goto 31-bit mode from any mode (2)
LARL R15,GOTO31
OILH R15,X'8000'
BASSM R14,R15
* Goto 64-bit mode from any mode
XGR R15,R15 For 24/31->64
LARL R15,GOTO64
OILL R15,X'0001'
BASSM R14,R15
GOTO31@ DC A(GOTO31+X'80000000')
* Entry into 24-bit Mode
GOTO24 DC 0H Below the line
. . .
BSM 0,R14 Return to Caller
* Entry into 31-bit Mode
GOTO31 DC 0H Below/Above line
. . .
BSM 0,R14 Return to Caller
* Entry into 64-bit Mode
GOTO64 DC 0H Below/Above line
. . .
BSM 0,R14 Return to Caller
AJA-21
z/Architecture addressing-mode z/Architecture addressing-mode
instructions instructions
SAMxx:
Set Addressing Mode
E-Type (2-Byte) format with Opcode X'010x'
No registers set/modified; no register preload required
Old mode not retained
Types
SAM24: Switch to 24 bit addressing mode
SAM31: Switch to 31 bit addressing mode
SAM64: Switch to 64 bit addressing mode
TAM
Test Addressing Mode
E-Type (2-byte) format:
Sets condition code based on current addressing mode
CC=0 24-bit addressing (Branch on Zero)
CC=1 31-bit addressing (Branch on Mixed)
CC=2 Unused
CC=3 64-bit addressing (Branch on One)
No registers set or changed
Addressing mode is not switched
01 0B
01 0C
01 0D
01 0E
* Examples:
SAM24 , To AMODE(24)
. . .
SAM31 , To AMODE(31)
. . .
SAM64 , To AMODE(64)
. . .
TAM , Test AMODE
JZ IN24
JO IN64
* Running in AMODE(31)
IN31 DS 0H
. . .
* Running in AMODE(31)
IN24 DS 0H
. . .
* Running in AMODE(64)
IN64 DS 0H
. . .
AJA-22
BALR vs. BASR BALR vs. BASR
BALR R
1
,R
2
Since S/360
High order word
24-, 31-bit mode: ignored
64-bit mode: part of address
Processing Modes (R
1
)
24-bit addressing contains ILC,
CC, Program Mask, 24 bit
address
31- and 64-bit addressing,
identical to BASR
Deprecated now
Use BASR for branch and link
Use IPM instruction for CC
and Program Mask
BASR R
1
,R
2
Since XA/370 (bimodal)
High order word
24-, 31-bit mode: ignored
64-bit mode: part of address
Processing Modes (R
1
)
24- and 31-bit addressing:
contains mode bit and address
64-bit addressing: contains
only the address, no mode
bit(s)
Preferred method of branch and
link (or save) without mode
switching
More consistent
AJA-23
Memory referencing by 64-bit addresses Memory referencing by 64-bit addresses
Blackout Area (2G)
Below the 16M
Line
Data & Code
Above the 16M
Line
Data & Code
Above the 2G Bar
Data Only
System
Code and/or Data
XX XX XX XX ?? ?? ?? ??
00 00 00 00 8? ?? ?? ??
00 00 00 00 0X ?? ?? ??
00 00 00 00 00 ?? ?? ??
XX
At least one bit is not
zero among all XXs
??
Any bit combination
8?
High-order bit is one, all
others any combination
0X
High-order bit is zero,
seven other bits any
combination with at least
one bit set to one.
00
All bits zero
Legend
AJA-24
Special considerations Special considerations
16M Line
System data and code straddles the line
Application code or data will not cross over
GETMAIN either totally below or above the line
Program object segment (class) will either be totally below or above the
line
2G Bar
Blackout zone for MVS is first 2G above the 2G bar
Technically, a valid addressable region!!
Applies to a 64-bit address
High word is all zeroes
Low Order word has address with bit (32[0]) set to 1
IARV64 will not allocate storage in blackout zone
AJA-25
The useful LLGT and LLGTR The useful LLGT and LLGTR
instructions instructions
Load Logical Grande Thirty One Bits
LLGT R
1
,D
2
(X
2
,B
2
)
RXY Format:
LLGTR R
1
,R
2
RRE Format:
Source (Register or Storage)
Fullword, 32 bits (Arg
2
)
Target Register (R
1
)
Doubleword, 64 bits
High word set to all zeroes
Low order word copied from source
Low order word, High Bit 32[0] set to 0
E3 R
1
X
2
B
2
DL
2
DH
2
17
B9 17 ?? R
1
R
2
FF FF FF FF
7F FF FF FF 00 00 00 00
AJA-26
Example: Call and Return Example: Call and Return
TITLE BAD CASE
MYPGM CSECT ,
MYPGM AMODE MY_AMODE
MYPGM RMODE MY_RMODE
AMODE EQU ... bit setting ...
. . .
L R15,YOURPGM@
BASR R14,R15
. . .
YOURPGM@ DC A(YOURPGM+AMODE)
END ,
YOURPGM CSECT ,
YOURPGM AMODE YOUR_AMODE
YOURPGM RMODE YOUR_RMODE
. . .
BSM 0,R14
END ,
TITLE GOOD CASE
MYPGM CSECT ,
MYPGM AMODE MY_AMODE
MYPGM RMODE MY_RMODE
AMODE EQU ... bit setting ...
. . .
XGR R15,R15 <--Important!
L R15,YOURPGM@
BASSM R14,R15
. . .
YOURPGM@ DC A(YOURPGM+AMODE)
END ,
YOURPGM CSECT ,
YOURPGM AMODE YOUR_AMODE
YOURPGM RMODE YOUR_RMODE
. . .
BSM 0,R14
END ,
BAD CASE: Worked OK for MY_AMODE=YOUR_AMODE for 24 and 31 but fails for 64
Fails for MY_AMODEYOUR_AMODE
GOOD CASE: Works for all MY_AMODE and YOUR_AMODE values
AJA-27
Notes: Call and Return Notes: Call and Return
BASR with BR