From:	MERC::"uunet!WKUVX1.BITNET!MacroMan"  8-APR-1993 20:49:13.84
To:	MACRO32@WKUVX1.BITNET
CC:	
Subj:	Re: NEED TO READ IMAGE-NAME FROM IMAGE-HEADER

In article <01GWQXAKLGAA9350PY@kopc.hhs.dk> Arne Vajhxj <ARNE@kopc.hhs.dk>
 writes:
>> I picked up the following piece of code a long time ago from some Decus tape
> and
>> now would like to modify it.  However, I am not a Macro hacker so I would
>> appreciate any help.  I want to be able to get the IMAGE NAME in addition to
>> the image-id and link-time.  Can someone tell me how?  Here is the code:
>[code omitted]
>
I have a similar problem with this piece of code which extracts this
information from the image header.  It is not equivalent to $GETJPI etc.
My problem with it is I want to run it on the Alpha.  Is there a simple
fix?

Thanks,
Michael

; Article 1228 of comp.os.vms:
; Path:
 hermes.chpc.utexas.edu!cs.utexas.edu!swrinde!elroy.jpl.nasa.gov!zardoz.cpd.com!
 dpdvax!potter
; From: potter@dpdvax.uucp
; Newsgroups: comp.os.vms
; Subject: Re: Program names and link dates
; Message-ID: <284.27bba96b@dpdvax.uucp>
; Date: 16 Feb 91 04:01:01 GMT
; References: <1991Feb6.200812.25355@astro.as.utexas.edu>
; Organization: Data Processing Design,  Anaheim CA
; Lines: 254
;
;
; We were looking to do a similar thing from a C program.  The part we
; especially needed was the version number specified in the linker
; IDENTIFICATION string.  It turns out this information is available.  We
; wrote a macro routine to return it for us.
;
; Here is the source for our routine.  It is called GET_IMAGE_IDENT.  Be aware
; that this routine is optimized for use with a C program -- it uses
; null-terminated strings instead of descriptors.  to build it, just type
;
;       MACRO GET_IMAGE_IDENT
;
; I hope this helps.
; --
;   David Potter                Voice: (714) 970-1515
;   Data Processing Design      UUCP: {lawnet,zardoz,dhw68k}!dpdvax!potter
;   Anaheim, CA                 Internet: potter@dpdvax.uucp
;
;------------------------------------------------------------------------------
; CUT HERE
;------------------------------------------------------------------------------
        .TITLE  GET_IMAGE_IDENT Get Image Identification Information

;------------------------------------------------------------------------------
;
;   File:               Get_Image_Ident.Mar
;   Author:             David R. Potter
;   Creation Date:      11-Jan-1991
;
;------------------------------------------------------------------------------
;
;   Description:
;
;       This function will extract the image identification from the image
;       header contained in the process' P1 space and return it to the caller.
;       It also returns the fully qualified file specification of the currently
;       executing image.
;
;   Inputs/Outputs:
;       4(ap)           <pszImageSpec>  The address of a null-terminated string
;                                         in which to return the fully qualified
;                                         image file specification.
;       8(ap)           <lImageSpecLen> The size of pszImageSpec (including spac
e
;                                         for the terminating null).
;       12(ap)          <pszImageName>  The address of a null-terminated string
;                                         in which to return the image name from
;                                         the image header.
;       16(ap)          <lImageNameLen> The size of pszImageName (including spac
e
;                                         for the terminating null).
;       20(ap)          <pszImageIdent> The address of a null-terminated string
;                                         in which to return the image version
;                                         number.
;       24(ap)          <lImageIdentLen> The size of pszImageIdent (including
;                                         space for the terminating null).
;       28(ap)          <pqLinkTime>    The address of a quadword in which to
;                                         return the link time.
;
;   Return:
;       SS$_NORMAL                      Normal successful completion.
;       SS$_ACCVIO                      Could not write to output buffer.
;       SS$_BUFFEROVF                   String was too long for output buffer.
;       LIB$_WRONUMARG                  Wrong number of arguments.
;
;------------------------------------------------------------------------------

        .LIBRARY        "SYS$LIBRARY:lib.mlb"
        .LINK           "SYS$SYSTEM:sys.stb" /Selective_Search

$IFDDEF                                                 ; Image File Description
s.
$IHDDEF                                                 ; Image Header Definitio
ns.
$IHIDEF                                                 ; Image Identification O
ffsets.
$SSDEF                                                  ; System Service Complet
ion Codes.









;------------------------------------------------------------------------------
;
;   GET_IMAGE_IDENT     Get Image Identification Information.
;
;------------------------------------------------------------------------------

        .PSECT  _GET_IMAGE_IDENT, PIC, CON, REL, GBL, SHR, EXE, RD, NOWRT, LONG
        .ENTRY  GET_IMAGE_IDENT, ^m<r2, r3, r4, r5, r6, r7>

; Parameters:
pszImageSpec    = 4
lImageSpecLen   = 8
pszImageName    = 12
lImageNameLen   = 16
pszImageIdent   = 20
lImageIdentLen  = 24
pqLinkTime      = 28

        movl            #SS$_NORMAL, r7                 ; Set the return status.

; Make sure we can write to the output buffers.

        cmpl    #2, (ap)                        ; Are these params specified?
        bleq    5$                              ; Branch if so.
        jmp     GII_DONE                        ; Jump if not.
5$:
        tstl    pszImageSpec(ap)                ; Does caller want this param?
        beql    10$                             ; Branch if not.
        tstl    lImageSpecLen(ap)               ; Any space in output string?
        beql    RET_BUFFEROVF                   ; Branch if not.

        IFNOWRT lImageSpecLen(ap), pszImageSpec(ap), RET_ACCVIO
10$:
        cmpl    #4, (ap)                        ; Are these params specified?
        bleq    15$                             ; Branch if so.
        jmp     PROBE_DONE                      ; Jump if not.
15$:
        tstl    pszImageName(ap)                ; Does caller want this param?
        beql    20$                             ; Branch if not.
        tstl    lImageNameLen(ap)               ; Any space in output string?
        beql    RET_BUFFEROVF                   ; Branch if not.

        IFNOWRT lImageNameLen(ap), pszImageName(ap), RET_ACCVIO
20$:
        cmpl    #6, (ap)                        ; Are these params specified?
        bleq    25$                             ; Branch if so.
        jmp     PROBE_DONE                      ; Jump if not.
25$:
        tstl    pszImageIdent(ap)               ; Does caller want this param?
        beql    30$                             ; Branch if not.
        tstl    lImageIdentLen(ap)              ; Any space in output string?
        beql    RET_BUFFEROVF                   ; Branch if not.

        IFNOWRT lImageIdentLen(ap), pszImageIdent(ap), RET_ACCVIO
30$:
        cmpl    #7, (ap)                        ; Is this parameter specified?
        bleq    35$                             ; Branch if so.
        jmp     PROBE_DONE                      ; Jump if not.
35$:
        tstl    pqLinkTime(ap)                  ; Does caller want this param?
        beql    PROBE_DONE                      ; Branch if not.

        IFWRT   #8, pqLinkTime(ap), PROBE_DONE
RET_ACCVIO:
        movzbl  #SS$_ACCVIO, r0                 ; Report an access violation.
        ret                                     ; Return to the caller.
RET_BUFFEROVF:
        movzwl  #SS$_BUFFEROVF, r0              ; Report a buffer overflow.
        ret                                     ; Return to the caller.
PROBE_DONE:









        movl    g^CTL$GL_IMGHDRBF, r6           ; Get image activator's image
                                                ;   header buffer address.

; Return the fully qualified image file specification.

        cmpl    #2, (ap)                        ; Are these params specified?
        bgtr    110$                            ; Branch if not.
        movl    pszImageSpec(ap), r4            ; Get caller's buffer address.
        beql    110$                            ; Branch if not specified.
        movl    lImageSpecLen(ap), r5           ; Get caller's buffer length.
        beql    110$                            ; Branch if empty.
        decl    r5                              ; Subtract one for ending null.

        movl    4(r6), r2                       ; R2=addr of image file descr.
        movq    IFD$Q_CURPROG(r2), r2           ; Get image name descr to R2/R3.
        movzwl  r2, r2                          ; Get size as a word.
        cmpl    r5, r2                          ; Caller's buffer big enough?
        bgeq    100$                            ; Branch if so.
        movl    r5, r2                          ; No - use caller's length.
        movzwl  #SS$_BUFFEROVF, r7              ; Set return status.
100$:
        movc3   r2, (r3), (r4)                  ; Copy the specification to
                                                ;   the caller's buffer.
        clrb    (r3)                            ; Null-terminate the string.
110$:

; Get the IHD address.

        movl    (r6), r2                        ; Point to Image HeaDer (IHD).
        movzwl  IHD$W_IMGIDOFF(r2), r0          ; IMaGe IDent OFFset in IHD.
        movab   (r2)[r0], r6                    ; Get image identification addr.

; Return the image name as specified by the link command.

        cmpl    #4, (ap)                        ; Are these params specified?
        bgtr    210$                            ; Branch if not.
        movl    pszImageName(ap), r4            ; Get caller's buffer address.
        beql    210$                            ; Branch if not specified.
        movl    lImageNameLen(ap), r5           ; Get caller's buffer length.
        beql    210$                            ; Branch if empty.
        decl    r5                              ; Subtract one for ending null.

        movzbl  IHI$T_IMGNAM(r6), r1            ; Get length of the image name.
        cmpw    r5, r1                          ; Caller's buffer big enough?
        bgeq    200$                            ; Branch if so.
        movl    r5, r1                          ; No - use caller's buffer len.
        movzwl  #SS$_BUFFEROVF, r7              ; Set return status.
200$:
        movab   <IHI$T_IMGNAM+1>(r6), r0        ; Get image name address.
        movc3   r1, (r0), (r4)                  ; Copy the specification to the
                                                ;   caller's buffer.
        clrb    (r3)                            ; Null-terminate the string.
210$:

; Return the image identification (version).

        cmpl    #6, (ap)                        ; Are these params specified?
        bgtr    310$                            ; Branch if not.
        movl    pszImageIdent(ap), r4           ; Get caller's buffer address.
        beql    310$                            ; Branch if not specified.
        movl    lImageIdentLen(ap), r5          ; Get caller's buffer length.
        beql    310$                            ; Branch if empty.
        decl    r5                              ; Subtract one for ending null.

        movzbl  IHI$T_IMGID(r6), r1             ; Get length of the IMAge ID.
        cmpw    r5, r1                          ; Caller's buffer big enough?
        bgeq    300$                            ; Branch if so.
        movl    r5, r1                          ; No - use caller's buffer len.
        movzwl  #SS$_BUFFEROVF, r7              ; Set return status.
300$:
        movab   <IHI$T_IMGID+1>(r6), r0         ; Get image name address.
        movc3   r1, (r0), (r4)                  ; Copy the specification to the
                                                ;   caller's buffer.
        clrb    (r3)                            ; Null-terminate the string.
310$:

; Return the link date/time.

        cmpl    #7, (ap)                        ; Is this parameter specified?
        bgtr    410$                            ; Branch if not.
        movl    pqLinkTime(ap), r4              ; Get caller's buffer address.
        beql    410$                            ; Branch if not specified.

        movq    IHI$Q_LINKTIME(r6), (r4)        ; Copy image link time to
                                                ;   caller's buffer.
410$:
GII_DONE:
        movl    r7, r0                          ; Set return status in R0.
        ret                                     ; Return to the caller.

;------------------------------------------------------------------------------

        .END
;------------------------------------------------------------------------------
; CUT HERE
;------------------------------------------------------------------------------



--
Michael Lemke
Astronomy, UT Austin, Texas
(michael@io.as.utexas.edu or UTSPAN::UTADNX::IO::MICHAEL [SPAN])
