On Tue, Aug 11, 2020 at 12:57 PM Tony Thigpen <[email protected]> wrote:
> I came across the following code today. The program can either be called > by JCL or from either an HLL or assembler program. While I included some > extra code for clarity, the code I am asking for comments on is the code > that 'fixes' R14 so that a BSM can be used instead of a BR. I just > thought I would ask what others think about this method. > > XXXXXXXX CSECT > XXXXXXXX AMODE ANY > XXXXXXXX RMODE 24 SOME IBM CODE IN HERE MAY REQUIRE R24 > USING XXXXXXXX,R15 > B COPYRGHTEND > ...... > COPYRGHTEND DS 0D > STM R14,R12,12(R13) SAVE CALLERS REGISTERS > BCTR R14,0 BACKUP TO CALLING INST > BCTR R14,0 . > BUG!!! What if the routine were invoked with a BAL (4 bytes), BAS( 4 bytes) , BRAS( 4 bytes) , or BRASL (6 bytes) instruction? Also, there is the case of the "calling" instruction (BAS, BASR, BAL, BALR, BASSM, BSM) being invoked by an EX instruction? The return address is then the instruction after the EX )( bytes) or EXRL (6 bytes). In all but the last two cases, I think it might be possible to get the ILC to adjust the backwards displacement. But with EX or EXRL, you'd need to figure out the address of the actual instruction. Personally, I don't think I want to do that. > CLI 0(R14),X'0C' BASSM? > BE R14_OK > CLI 0(R14),X'0D' BSM? > BE R14_OK > L R14,12(,R13) GET ORG R14 > LA R14,0(,R14) CLEAR HI BIT/BYTE > BSM R14,0 ADD PROPER AMODE > ST R14,12(,R13) SET R14 FOR RETURN BY BSM > R14_OK DS 0H > DROP R15 > LA R1,SAVEAREA > ST R1,8(,R13) FORWARD POINTER > ST R13,4(,R1) BACKWARD POINTER > LR R13,R1 ESTABLISH PERM R13 AREA > L R1,4(,R13) GET BACK ORG R0 & R1 > LM R0,R1,20(R1) FROM ORG SAVEAREA > * > LA R8,0(,R15) ESTABLISH ADDRESSABILITY > LA R15,1 . > LA R10,4095(R15,R8) . > USING XXXXXXXX,R8,R10 . > > The return code is: > RETURNR15 DS 0H > L R1,4(,R13) GET CALLER SAVE AREA ADDRESS > ST R15,16(,R1) SAVE RETURN CODE > LM R14,R12,12(R13) RESTORE REGISTERS > BSM 0,R14 GO BACK > > Tony Thigpen >
