/* ***************************************************************************** * * Copytight (c) Digital Equipment Corporation, 1995 All Rights Reserved. * Unpublished rights reserved under the copyright laws of the United States. * * The software contained on this media is proprietary to and embodies the * confidential technology of Digital Equipment Corporation. Possession, use, * duplication or dissemination of the software and media is authorized only * pursuant to a valid written license from Digital Equipment Corporation. * * RESTRICTED RIGHTS LEGEND Use, duplication, or disclosure by the U.S. * Government is subject to restrictions as set forth in Subparagraph * (c)(1)(ii) of DFARS 252.227-7013, or in FAR 52.227-19, as applicable. * ***************************************************************************** /* This program creates a region in P2 space using the region creation service and then creates VAs within that region. The intent is to demonstrate the use of the region services and how to allocate virtual addresses within a region. The program also makes use of 64-bit descriptors and uses them to format return values into messages with the aid of SYS$GETMSG. To build and run this program type: $ CC/POINTER_SIZE=32/STANDARD=RELAXED/DEFINE=(__NEW_STARLET=1) - REGIONS.C $ LINK REGIONS.OBJ $ RUN REGIONS.EXE */ #include <descrip.h> /* Descriptor Definitions */ #include <far_pointers.h> /* Long Pointer Definitions */ #include <gen64def.h> /* Generic 64-bit Data Type Definition */ #include <iledef.h> /* Item List Entry Definitions */ #include <ints.h> /* Various Integer Typedefs */ #include <iosbdef.h> /* I/O Status Block Definition */ #include <psldef.h> /* PSL$ Constants */ #include <ssdef.h> /* SS$_ Message Codes */ #include <starlet.h> /* System Service Prototypes */ #include <stdio.h> /* printf */ #include <stdlib.h> /* malloc, free */ #include <string.h> /* memset */ #include <syidef.h> /* $GETSYI Item Code Definitions */ #include <vadef.h> /* VA Creation Flags and Constants */ /* Module-wide constants and macros. */ #define BUFFER_SIZE 132 #define HW_NAME_LENGTH 32 #define PAGELET_SIZE 512 #define REGION_SIZE 128 #define good_status(code) ((code) & 1) /* Module-wide Variables */ int page_size; $DESCRIPTOR64 (msgdsc, ""); /* Function Prototypes */ int get_page_size (void); static void print_message (int code, char *string); main (int argc, char **argv) { int i, status; uint64 length_64, master_length_64, return_length_64; GENERIC_64 region_id_64; VOID_PQ master_va_64, return_va_64; /* Get system page size, using SYS$GETSYI. */ status = get_page_size (); if (!good_status (status)) return (status); /* Get a buffer for the message descriptor. */ msgdsc.dsc64$pq_pointer = malloc (BUFFER_SIZE); printf ("Message Buffer Address = %016LX\n\n", msgdsc.dsc64$pq_pointer); /* Create a region in P2 space. */ length_64 = REGION_SIZE*page_size; status = sys$create_region_64 ( length_64, /* Size of Region to Create */ VA$C_REGION_UCREATE_UOWN, /* Protection on Region */ 0, /* Allocate in Region to Higher VAs */ ®ion_id_64, /* Region ID */ &master_va_64, /* Starting VA in Region Created */ &master_length_64); /* Size of Region Created */ if (!good_status (status)) { print_message (status, "SYS$CREATE_REGION_64"); return (status); } printf ("\nSYS$CREATE_REGION_64 Created this Region: %016LX - %016LX\n", master_va_64, (uint64) master_va_64 + master_length_64 - 1); /* Create virtual address space within the region. */ for (i = 0; i < 3; ++i) { status = sys$expreg_64 ( ®ion_id_64, /* Region to Create VAs In */ page_size, /* Number of Bytes to Create */ PSL$C_USER, /* Access Mode */ 0, /* Creation Flags */ &return_va_64, /* Starting VA in Range Created */ &return_length_64); /* Number of Bytes Created */ if (!good_status (status)) { print_message (status, "SYS$EXPREG_64"); return status; } printf ("Filling %016LX - %16LX with %0ds.\n", return_va_64, (uint64) return_va_64 + return_length_64 - 1, i); memset (return_va_64, i, page_size); } /* Return the virtual addresses created within the region, as well as the region itself. */ printf ("\nReturning Master Region: %016LX - %016LX\n", master_va_64, (uint64) master_va_64 + master_length_64 - 1); status = sys$delete_region_64 ( ®ion_id_64, /* Region to Delete */ PSL$C_USER, /* Access Mode */ &return_va_64, /* VA Deleted */ &return_length_64); /* Length Deleted */ if (good_status (status)) printf ("SYS$DELETE_REGION_64 Deleted VAs Between: %016LX - %016LX\n", return_va_64, (uint64) return_va_64 + return_length_64 - 1); else { print_message (status, "SYS$DELTE_REGION_64"); return (status); } /* Return message buffer. */ free (msgdsc.dsc64$pq_pointer); } /* This routine obtains the system page size using SYS$GETSYI. The return value is recorded in the module-wide location, page_size. */ int get_page_size () { int status; IOSB iosb; ILE3 item_list [2]; /* Fill in SYI item list to retrieve the system page size. */ item_list[0].ile3$w_length = sizeof (int); item_list[0].ile3$w_code = SYI$_PAGE_SIZE; item_list[0].ile3$ps_bufaddr = &page_size; item_list[0].ile3$ps_retlen_addr = 0; item_list[1].ile3$w_length = 0; item_list[1].ile3$w_code = 0; /* Get the system page size. */ status = sys$getsyiw ( 0, /* EFN */ 0, /* CSI address */ 0, /* Node name */ &item_list, /* Item list */ &iosb, /* I/O status block */ 0, /* AST address */ 0); /* AST parameter */ if (!good_status (status)) { print_message (status, "SYS$GETJPIW"); return (status); } if (!good_status (iosb.iosb$w_status)) { print_message (iosb.iosb$w_status, "SYS$GETJPIW IOSB"); return (iosb.iosb$w_status); } return SS$_NORMAL; } /* This routine takes the message code passed to the routine and then uses SYS$GETMSG to obtain the associated message text. That message is then printed to stdio along with a user-supplied text string. */ #pragma inline (print_message) static void print_message (int code, char *string) { msgdsc.dsc64$q_length = BUFFER_SIZE; sys$getmsg ( code, /* Message Code */ (unsigned short *) &msgdsc.dsc64$q_length, /* Returned Length */ &msgdsc, /* Message Descriptor */ 15, /* Message Flags */ 0); /* Optional Parameter */ *(msgdsc.dsc64$pq_pointer+msgdsc.dsc64$q_length) = '\0'; printf ("Call to %s returned: %s\n", string, msgdsc.dsc64$pq_pointer); }