Re: XLC C/C++, __R1 and Register 0

2022-10-27 Thread Colin Paice
I wrote Spice up a C program by using __asm__ to include inline assembler.

   But this whole area seems not very well documented
You could save register 0 in a variable with the assembler code
Colin

On Thu, 27 Oct 2022 at 18:14, Charles Mills  wrote:

> XLC defines a macro __R1 in stdlib.h. It is the contents of GPR 1 on entry
> to the program. Looking at stdlib, it is #defined as __gtab(12) -- or there
> may be further #defines farther back -- that is as far as I have
> researched. I am guessing __gtab() is a magically-defined internal
> function. I use __R1 and I am totally under control on it, but I have some
> questions:
>
> 1. Where is it documented? As I say, I use it and it works, but I don't
> recall how I learned about it, and wondered if and where it was documented.
>
> 2. Is there any equivalent way to get the contents of GPR 0 (short of
> writing an assembler front-end, which is a small PITA of its own)? Why? So
> a routine called from Rexx could get the Environment Block address. Or does
> anyone have another good way of getting that?
>
> 3.Any other cool stuff available from __gtab()?
>
> Thanks,
> Charles
>
> --
> For IBM-MAIN subscribe / signoff / archive access instructions,
> send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN
>

--
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN


Re: XLC C/C++, __R1 and Register 0

2022-10-27 Thread Charles Mills
Thanks. Not sure if that would work, because I suspect that GPR 0 when my C++ 
code starts actually executing is no longer the GPR 0 on entry to CEESTART.

Charles

--
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN


Re: XLC C/C++, __R1 and Register 0

2022-10-27 Thread Tony Harminc
On Thu, 27 Oct 2022 at 13:55, Charles Mills  wrote:

> Thanks. Not sure if that would work, because I suspect that GPR 0 when my
> C++ code starts actually executing is no longer the GPR 0 on entry to
> CEESTART.
>

I'd guess you're right. But surely CEESTART will have saved it in TCBFSA,
and that's easy enough to access. Unless, of course, CEESTART thinks itself
exempt from following standard OS conventions because, you know, it's LE...

Tony H.

--
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN


Re: XLC C/C++, __R1 and Register 0

2022-10-27 Thread Paul Gilmartin
On Thu, 27 Oct 2022 12:14:19 -0500, Charles Mills  wrote:
>...
>2. Is there any equivalent way to get the contents of GPR 0 (short of writing 
>an assembler front-end, which is a small PITA of its own)? Why? So a routine 
>called from Rexx could get the Environment Block address. Or does anyone have 
>another good way of getting that?
>
Characteristic undisciplined CMS designer behavior: "No one cares about GPR 0,
so we can just use it for the Environment Block address."

I think I've seen similar uses of GPR 0 in CMS code.

(CDC 6K series made B0 a hardwired 0, so developers weren't so tempted.
But it still caused pipeline block.)

>3.Any other cool stuff available from __gtab()?
>
No help in 
.
Is there any access to the RSA?

-- 
gil

--
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN


Re: XLC C/C++, __R1 and Register 0

2022-10-27 Thread Charles Mills
It's being called from Rexx running under zOSMF so would TCBFSA apply?

Charles


-Original Message-
From: IBM Mainframe Discussion List [mailto:IBM-MAIN@LISTSERV.UA.EDU] On Behalf 
Of Tony Harminc
Sent: Thursday, October 27, 2022 11:09 AM
To: IBM-MAIN@LISTSERV.UA.EDU
Subject: Re: XLC C/C++, __R1 and Register 0

On Thu, 27 Oct 2022 at 13:55, Charles Mills  wrote:

> Thanks. Not sure if that would work, because I suspect that GPR 0 when 
> my
> C++ code starts actually executing is no longer the GPR 0 on entry to
> CEESTART.
>

I'd guess you're right. But surely CEESTART will have saved it in TCBFSA, and 
that's easy enough to access. Unless, of course, CEESTART thinks itself exempt 
from following standard OS conventions because, you know, it's LE...

Tony H.

--
For IBM-MAIN subscribe / signoff / archive access instructions, send email to 
lists...@listserv.ua.edu with the message: INFO IBM-MAIN

--
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN


Re: XLC C/C++, __R1 and Register 0

2022-10-27 Thread Charles Mills
That gtab "documentation" is a joke!

How do I find __gfunc.h? I don't see it in the header libraries. No @@GFUNC.

Charles


-Original Message-
From: IBM Mainframe Discussion List [mailto:IBM-MAIN@LISTSERV.UA.EDU] On Behalf 
Of Paul Gilmartin
Sent: Thursday, October 27, 2022 11:10 AM
To: IBM-MAIN@LISTSERV.UA.EDU
Subject: Re: XLC C/C++, __R1 and Register 0

...

>3.Any other cool stuff available from __gtab()?
>
No help in 
<https://www.ibm.com/docs/en/zos/2.5.0?topic=files-gfunch-gtca-gtab-functions>.
Is there any access to the RSA?

-- 
gil

--
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN

--
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN


Re: XLC C/C++, __R1 and Register 0

2022-10-27 Thread Tony Harminc
On Thu, 27 Oct 2022 at 14:30, Charles Mills  wrote:

> It's being called from Rexx running under zOSMF so would TCBFSA apply?
>

No, I suppose not. I was thinking this was an EXEC PGM= thing, but on
reflection obviously not. But how does REXX invoke a program? (This is a
REXX Call statement?)

There's also the super annoying thing about REXX silently ignoring an R0
that isn't a valid EnvBlok pointer, and using some default. So not clear
where you would get that - IIRC REXX owns a TCB (STCB?) field that points
to some OCO anchor that would probably eventually yield the envbok.

Tony H.

--
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN


Re: XLC C/C++, __R1 and Register 0

2022-10-27 Thread Colin Paice
I wrote a Rexx calling a C function a while ago.  I've just dumped the code
into https://github.com/colinpaicemq/RexxToC/tree/main/code

CCQUERY  compiles and runs it
QREXX is the rexx ...  v =
 CPQUERY("QR","P.","1+bySlG9Ug/c2TbK6o++",100,2);
main c program in  query
glue code in glue
glue code puts the rexx parameters so you can have

in QUERY...  int  CTOREXX(rexParms * p  ,  evalblock * pEval, ENVBLOCK
*pEnv ){...

let me know  (offline) if you have any questions.

Colin



On Thu, 27 Oct 2022 at 19:40, Charles Mills  wrote:

> That gtab "documentation" is a joke!
>
> How do I find __gfunc.h? I don't see it in the header libraries. No
> @@GFUNC.
>
> Charles
>
>
> -Original Message-
> From: IBM Mainframe Discussion List [mailto:IBM-MAIN@LISTSERV.UA.EDU] On
> Behalf Of Paul Gilmartin
> Sent: Thursday, October 27, 2022 11:10 AM
> To: IBM-MAIN@LISTSERV.UA.EDU
> Subject: Re: XLC C/C++, __R1 and Register 0
>
> ...
>
> >3.Any other cool stuff available from __gtab()?
> >
> No help in <
> https://www.ibm.com/docs/en/zos/2.5.0?topic=files-gfunch-gtca-gtab-functions
> >.
> Is there any access to the RSA?
>
> --
> gil
>
> --
> For IBM-MAIN subscribe / signoff / archive access instructions,
> send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN
>
> --
> For IBM-MAIN subscribe / signoff / archive access instructions,
> send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN
>

--
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN


Re: XLC C/C++, __R1 and Register 0

2022-10-27 Thread Charles Mills
> But how does REXX invoke a program? 

Ret = MYFUNC(parm1, parm2)

> glue code puts the rexx parameters 

Yeah, I know how to do a front-end to the C++ but I would rather not add that 
complexity.

If no one comes up with a better answer I will just go with passing 0 for the 
Environment Block and see what happens.

Why couldn't Rexx have put the Environment Block pointer somewhere *standard*? 
They pass a bunch of pointers off of R1 -- why not one more?

Charles

--
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN


Re: XLC C/C++, __R1 and Register 0

2022-10-27 Thread David Crayford

You can obtain the environment block by calling IRXINIT("FINDENVB ")

On 28/10/22 04:43, Charles Mills wrote:

But how does REXX invoke a program?

Ret = MYFUNC(parm1, parm2)


glue code puts the rexx parameters

Yeah, I know how to do a front-end to the C++ but I would rather not add that 
complexity.

If no one comes up with a better answer I will just go with passing 0 for the 
Environment Block and see what happens.

Why couldn't Rexx have put the Environment Block pointer somewhere *standard*? 
They pass a bunch of pointers off of R1 -- why not one more?

Charles

--
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN


--
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN


Re: XLC C/C++, __R1 and Register 0

2022-10-27 Thread Paul Gilmartin
On Thu, 27 Oct 2022 15:43:59 -0500, Charles Mills wrote:
>
>Yeah, I know how to do a front-end to the C++ but I would rather not add that 
>complexity.
>  
(Guessing)  How about ADDRESS LINKMVS to a minimal function?  Just:
 LRR15,R0
 BRR15

Yes, it adds another thing to the protocol.

>If no one comes up with a better answer I will just go with passing 0 for the 
>Environment Block and see what happens.
>
>Why couldn't Rexx have put the Environment Block pointer somewhere *standard*? 
>They pass a bunch of pointers off of R1 -- why not one more?
>
o Compatibility with bad CMS conventions
o Using a register that's presumed useless.

-- 
gil

--
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN


Re: XLC C/C++, __R1 and Register 0

2022-10-27 Thread Michael Stein
On Thu, Oct 27, 2022 at 12:14:19PM -0500, Charles Mills wrote:
> XLC defines a macro __R1 in stdlib.h. It is the contents of GPR 1 on
> entry to the program. Looking at stdlib, it is #defined as __gtab(12)
> -- or there may be further #defines farther back -- that is as far as I
> have researched. I am guessing __gtab() is a magically-defined internal
> function. I use __R1 and I am totally under control on it, but I have
> some questions:

> 2. Is there any equivalent way to get the contents of GPR 0 (short of
> writing an assembler front-end, which is a small PITA of its own)? Why? So
> a routine called from Rexx could get the Environment Block address. Or
> does anyone have another good way of getting that?

Wild guess:  __gtab(8) might get you the contents of the R0 from the caller.

This assumes __gtab(offset) retuns the value from a standard old 72 byte
save area save area and the parm is the offset from the r14 slot..

So the callers registers would be stored in order R14 through R12 starting
at __gtab(0)

--
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN


Re: XLC C/C++, __R1 and Register 0

2022-10-28 Thread Seymour J Metz
There are three cases

 1. address foo bar baz
Pass command bar baz to environment foo
address foo
bar baz

 2. call bar baz
Invoke bar with parameter baz; return value optional

 3. bar(baz) in an expression
Invoke bar with parameter baz; return value required


The last two cases are essentially the same. In the first case the value of baz 
is passed as a single parameter even if it contains spaces or commas, but the 
command processor for the environment may parse it into subparameters.

In the second and third cases baz must be a list of expressions, separated by 
commas; there are no constrains on the values of those expressions.

z/OS 2.5 TSO/E REXX Reference, SA32-0972-5, contains details in Chapter 12. 
TSO/E REXX programming services and Chapter 14. Language processor environments


--
Shmuel (Seymour J.) Metz
http://mason.gmu.edu/~smetz3


From: IBM Mainframe Discussion List [IBM-MAIN@LISTSERV.UA.EDU] on behalf of 
Tony Harminc [t...@harminc.net]
Sent: Thursday, October 27, 2022 3:08 PM
To: IBM-MAIN@LISTSERV.UA.EDU
Subject: Re: XLC C/C++, __R1 and Register 0

On Thu, 27 Oct 2022 at 14:30, Charles Mills  wrote:

> It's being called from Rexx running under zOSMF so would TCBFSA apply?
>

No, I suppose not. I was thinking this was an EXEC PGM= thing, but on
reflection obviously not. But how does REXX invoke a program? (This is a
REXX Call statement?)

There's also the super annoying thing about REXX silently ignoring an R0
that isn't a valid EnvBlok pointer, and using some default. So not clear
where you would get that - IIRC REXX owns a TCB (STCB?) field that points
to some OCO anchor that would probably eventually yield the envbok.

Tony H.

--
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN

--
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN


Re: XLC C/C++, __R1 and Register 0

2022-10-28 Thread Charles Mills
Thanks.

What is the relevance to my question? (How do I obtain the contents of R0 on 
entry to a C program from Rexx?)

Charles


-Original Message-
From: IBM Mainframe Discussion List [mailto:IBM-MAIN@LISTSERV.UA.EDU] On Behalf 
Of Seymour J Metz
Sent: Friday, October 28, 2022 3:02 PM
To: IBM-MAIN@LISTSERV.UA.EDU
Subject: Re: XLC C/C++, __R1 and Register 0

There are three cases

 1. address foo bar baz
Pass command bar baz to environment foo
address foo
bar baz

 2. call bar baz
Invoke bar with parameter baz; return value optional

 3. bar(baz) in an expression
Invoke bar with parameter baz; return value required


The last two cases are essentially the same. In the first case the value of baz 
is passed as a single parameter even if it contains spaces or commas, but the 
command processor for the environment may parse it into subparameters.

In the second and third cases baz must be a list of expressions, separated by 
commas; there are no constrains on the values of those expressions.

z/OS 2.5 TSO/E REXX Reference, SA32-0972-5, contains details in Chapter 12. 
TSO/E REXX programming services and Chapter 14. Language processor environments

--
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN


Re: XLC C/C++, __R1 and Register 0

2022-10-28 Thread David Crayford
There is a field in the LE Enclave Control Block called 
CEEEDB_R13_PARENT which is a pointer to a DSA containing the registers 
of the enclave parent. If you can be bothered. I would just use 
IRXINIT("FINDENVB ") to get the environment block as opposed to fiddling 
about with control blocks.


On 29/10/22 06:46, Charles Mills wrote:

Thanks.

What is the relevance to my question? (How do I obtain the contents of R0 on 
entry to a C program from Rexx?)

Charles


-Original Message-
From: IBM Mainframe Discussion List [mailto:IBM-MAIN@LISTSERV.UA.EDU] On Behalf 
Of Seymour J Metz
Sent: Friday, October 28, 2022 3:02 PM
To: IBM-MAIN@LISTSERV.UA.EDU
Subject: Re: XLC C/C++, __R1 and Register 0

There are three cases

  1. address foo bar baz
 Pass command bar baz to environment foo
 address foo
 bar baz

  2. call bar baz
 Invoke bar with parameter baz; return value optional

  3. bar(baz) in an expression
 Invoke bar with parameter baz; return value required
 


The last two cases are essentially the same. In the first case the value of baz 
is passed as a single parameter even if it contains spaces or commas, but the 
command processor for the environment may parse it into subparameters.

In the second and third cases baz must be a list of expressions, separated by 
commas; there are no constrains on the values of those expressions.

z/OS 2.5 TSO/E REXX Reference, SA32-0972-5, contains details in Chapter 12. 
TSO/E REXX programming services and Chapter 14. Language processor environments

--
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN


--
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN


Re: XLC C/C++, __R1 and Register 0

2022-10-28 Thread Charles Mills
I would guess that FINDENVB is no better, no different really, than passing 0 
and letting IRXEXCOM take a guess. Am I wrong? The way I read the docs is that 
method will fail if the caller is using a Rexx "reentrant environment." Am I 
wrong?

Charles


-Original Message-
From: IBM Mainframe Discussion List [mailto:IBM-MAIN@LISTSERV.UA.EDU] On Behalf 
Of David Crayford
Sent: Friday, October 28, 2022 4:31 PM
To: IBM-MAIN@LISTSERV.UA.EDU
Subject: Re: XLC C/C++, __R1 and Register 0

There is a field in the LE Enclave Control Block called CEEEDB_R13_PARENT which 
is a pointer to a DSA containing the registers of the enclave parent. If you 
can be bothered. I would just use IRXINIT("FINDENVB ") to get the environment 
block as opposed to fiddling about with control blocks.

--
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN


Re: XLC C/C++, __R1 and Register 0

2022-10-28 Thread David Crayford
FINDENVB is reliable. It's designed for languages that don't have access 
to R0. I use it in all my REXX command processors written in C++.


On 29/10/22 08:55, Charles Mills wrote:

I would guess that FINDENVB is no better, no different really, than passing 0 and letting 
IRXEXCOM take a guess. Am I wrong? The way I read the docs is that method will fail if 
the caller is using a Rexx "reentrant environment." Am I wrong?

Charles


-Original Message-
From: IBM Mainframe Discussion List [mailto:IBM-MAIN@LISTSERV.UA.EDU] On Behalf 
Of David Crayford
Sent: Friday, October 28, 2022 4:31 PM
To: IBM-MAIN@LISTSERV.UA.EDU
Subject: Re: XLC C/C++, __R1 and Register 0

There is a field in the LE Enclave Control Block called CEEEDB_R13_PARENT which is a 
pointer to a DSA containing the registers of the enclave parent. If you can be bothered. 
I would just use IRXINIT("FINDENVB ") to get the environment block as opposed 
to fiddling about with control blocks.

--
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN


--
For IBM-MAIN subscribe / signoff / archive access instructions,
send email to lists...@listserv.ua.edu with the message: INFO IBM-MAIN