Article 170391 of comp.os.vms:
In article <EAHx4o.H3u@world.std.com>, jcomeau@world.std.com says...
>
>This is an rtfm question, so a pointer to the "m" is appropriate. What is
>the VMS equivalent to the RSX LINK/PRIV switch that allows a program to
>access the hardware directly?

    Attached is some really, really hacky C code that will access a given
    64-bit physical memory address from user mode on a given Alpha CPU. 
    This program requires the process to have PFN map privilege.  If you
    supply the wrong physical address, the system will most like crash with 
    a machine check bugcheck!  In my case, this is precisely what was
    intended, since I use it to the debug the machine check handler.  I
    hope you find this example useful.

+---------------------------------------------------------------------------+
| Paul A. Jacobi                            Phone: (603) 881-1948           |
| Digital Equipment Corporation             FAX  : (603) 881-0189           |
| OpenVMS Systems Group, ZKO3-4/W23         Email: jacobi@star.enet.dec.com |
| 110 Spitbrook Road                                                        |
| Nashua, NH 03062-2698                                                     |
+---------------------------------------------------------------------------+


-------------------------- Cut here ----------------------------------------

/* Machine check test program
 *
 * Usage:
 *
 * mcheck cpuid pa_h pa_l
 *
 * Author:
 *	Paul A. Jacobi
 */
 

#include	<stdio>
#include	<ints>
#include	<stdlib>

#include	<diagdef>
#include	<cpbdef>
#include	<psldef>
#include	<starlet>
#include	<secdef>

/* Define your favorite default PA here */
#define DEFAULT_PA_H 3
#define DEFAULT_PA_L 81000000

typedef union {
    uint64 q;
    struct {
        uint32 l;
        uint32 h;
    } u;
} QUAD;

main(int argc, char **argv) {
    int cpuid;
    int status;
    QUAD pa;
    uint32 *va,*retva;
    uint32 pfn;
    uint32 data;
    uint32 va_array[2];
    uint32 retva_array[2];

    if (argv[1] == NULL)
        cpuid = 0;
    else    
        cpuid = atoi(argv[1]);

    printf("Setting process affinity to CPU ID %d\n",cpuid);
    status = sys$diagnose(DIAG$C_SETAFF,1,cpuid,CPB$M_FLAG_PERMANENT);
    if (!(status&1)) return(status);
    printf("Process affinity now set to CPU ID %d\n",cpuid);
    
    printf("Expanding working set....\n");

    status=sys$expreg(1,&va,1,0);
    if (!(status&1)) return(status);
    printf("Working set expanded.\n");

    if (argv[2] == NULL)
        pa.u.h = DEFAULT_PA_H;
    else        
        pa.u.h = strtoul(argv[2],NULL, 16);

    if (argv[3] == NULL)
        pa.u.l = DEFAULT_PA_L;
    else        
        pa.u.l = strtoul(argv[3],NULL, 16);

    printf("Physical address to map = %X",pa.u.h);
    printf("%X\n",pa.u.l);

    pfn = (uint32) (pa.q >> 13);
    printf("PFN to map = %X\n",pfn);

    va_array[0] = (uint32) va;
    va_array[1] = (((uint32) va_array[0]) + (8192 - 1));
    printf("Mapping PFN to virtual address....\n");
    status=sys$crmpsc(&va_array,&retva_array,PSL$C_USER,SEC$M_PFNMAP,NULL,
                      NULL,0,0,1,pfn,0,0);
    if (!(status&1)) return(status);

    printf("Attempting to access VA...this may cause a machine check!\n");

    retva = (uint32 *) retva_array[0];    
    data = *retva;   

    printf("Data = %X\n",data);
    printf("Access complete without machine check.\n");

    return(status);
}





