[Info-vax] Volatile, was: Re: yet another sys$qiow question
VAXman- at SendSpamHere.ORG
VAXman- at SendSpamHere.ORG
Wed Aug 19 15:41:07 EDT 2015
In article <fcdd3e23-53c1-4eb2-a5bb-c9339ec4f6b4 at googlegroups.com>, John Reagan <xyzzy1959 at gmail.com> writes:
>On Wednesday, August 19, 2015 at 12:58:05 PM UTC-4, VAXman- wrote:
>> In article <>, Simon Clubley <> writes:
>> >On 2015-08-19, VAXman- @SendSpamHere.ORG <> wrote:
>> >> Question: If "volatile" is necessary, shouldn't this code keep spinni=
>ng its
>> >> tail???
>> >>
>> >
>> >No, because you only have a function call in the loop (sys$qiow())
>> >(and the function call additionally directly references iosb BTW).
>> >
>> >This means that regardless of whether the compiler terminates the
>> >caching scope for iosb at any function call or whether it only
>> >terminates the caching scope when a function call references iosb,
>> >your code still causes the compiler to generate code to re-read the
>> >current contents of the iosb variable after the function call returns.
>> >
>> >The current discussion is based around the belief C compilers terminate
>> >the caching scope at any function call. I don't know if this is true
>> >for all the other languages VMS supports.
>>=20
>> So, I should put the $QIO in a subroutine.
>>=20
>
>Well, the compiler saw that somebody took the address of the IOSB and passe=
>d it along to $QIO. The compiler doesn't know if that address was saved in=
> some global variable. So the call to your jacket routine is still probabl=
>y sufficient to tell the compiler (this routine call might write into every=
> possible global variable and write into every variable whose address was e=
>ver taken).
OK. Got it! This should hide the 'iosb' use -- and it does. ;)
#pragma environment save
#ifndef __NEW_STARLET
#define __NEW_STARLET New_and_Improved
#endif
#include <builtins.h> // DECC built-in function definitions
#include <c_asm.h> // DECC asm() intrinsic function definiitons
#include <descrip.h> // OpenVMS descriptor structure definitions
#include <efndef.h> // OpenVMS event flag number definitions
#include <iodef.h> // OpenVMS $QIO I/O function code definitions
#include <iosbdef.h> // OpenVMS I/O status block structure definitions
#include <starlet.h> // OpenVMS system service prototype & codes
#include <stsdef.h> // OpenVMS system message format definitions
#include <vadef.h> // OpenVMS virtual address vield definitions
int sts = 0, ctr = 0;
unsigned short chan;
$DESCRIPTOR(sys$output,"SYS$OUTPUT");
char star[] ={'|','/','-','\\'};
void *sp;
int main()
{
/////////////////////////////////////////////////////////////////////////
//Remove the '//' comment to enable 'volatile' type qualifier on IOSB. //
/////////////////////////////////////////////////////////////////////////
// volatile
IOSB iosb = { 0, 0, 0};
sp = (void *)asm("bis %r29,%r31,%r0;"); // get FP address
sp = &((char*)sp)[VA$S_VADEF]; // skip PDSC address
// usp is now at iosb
if (!((sts=SYS$ASSIGN(
&sys$output, // device name
&chan, // channel
0, // access mode
0 // mailbox name
))&STS$M_SUCCESS)) return sts;
while (iosb.iosb$w_status == 0)
{
if (!((sts=SYS$QIO(
EFN$C_ENF, // event flag number
chan, // channel
IO$_WRITEVBLK, // QIO function
(IOSB*)sp, // I/O status block
0, // AST address
0, // AST parameter
&star[(ctr++)&3], // P1: VA of buffer
1, // P2: number of bytes
0, // P3: n/a
0x8D000000, // P4: carriage control
0, // P5: n/a
0 // P6: n/a
))&STS$M_SUCCESS)) return sts;
}
}
#pragma environment restore
--
VAXman- A Bored Certified VMS Kernel Mode Hacker VAXman(at)TMESIS(dot)ORG
I speak to machines with the voice of humanity.
More information about the Info-vax
mailing list