/* @(#)Copyright (c), 1987, 1993 StatSci, Inc.  All rights reserved. */
/* @(#)loader.h version 3.1 created 5/30/93 */
#if defined(APOLLO) /*(*/
/* Splus options and C compiler version changes required slight changes in
 * this APOLLO header file to get compilations/executions to work.  DLR.
 */
/*  loader.h, /usr/include/apollo

     --------------------------------------------------------------------------
    |   THE FOLLOWING PROGRAMS ARE THE SOLE PROPERTY OF APOLLO COMPUTER INC.   |
    |         AND CONTAIN ITS PROPRIETARY AND CONFIDENTIAL INFORMATION.        |
     --------------------------------------------------------------------------
*/

#ifndef _SYS_STDSYMS_INCLUDED
#	include <sys/stdsyms.h>
#endif /* _SYS_STDSYMS_INCLUDED */

#ifndef apollo_loader_h
#define apollo_loader_h
                         
#define loader_$module_code   0x03030000
#define loader_$too_many_undefined        (loader_$module_code+1)   /* too many undefined symbols for the loader to deal with */
#define loader_$too_many_sections         (loader_$module_code+2)   /* too many sections for the loader to deal with */
#define loader_$no_copy_space             (loader_$module_code+3)   /* not enough r/w space to copy object module into */
#define loader_$not_a_program             (loader_$module_code+4)   /* loader couldn't recognize the program module as an format it understood  */
#define loader_$wrong_version             (loader_$module_code+5)   /* loader couldn't deal with this version of the program module  */
#define loader_$no_proc_space             (loader_$module_code+6)   /* unused */
#define loader_$no_rw_space               (loader_$module_code+7)   /* not enough r/w storage for the r/w section of the program module */
#define loader_$no_kg_space               (loader_$module_code+8)   /* not enough r/w storage to build the kgt */
#define loader_$undef_glbl                (loader_$module_code+9)   /* an undefined symbol was referenced */
#define loader_$undef_glbl_in_lib         (loader_$module_code+10)  /* an undefined symbol was referenced in a global library */
#define loader_$peb_required              (loader_$module_code+11)  /* a PEB floating point accelerator is required to run this program */
#define loader_$bkpts_in_obj              (loader_$module_code+12)  /* a debugger has crashed and left breakpoints installed in this program */
#define loader_$unix_init_required        (loader_$module_code+13)  /* unused */
#define loader_$dnx60_required            (loader_$module_code+14)  /* a DN160, DN460, or DN660 processor needed to run this program */
#define loader_$m881_required             (loader_$module_code+15)  /* a processor with a 68881 floating point accelerator needed to run this program */
#define loader_$m020_required             (loader_$module_code+16)  /* a processor with a 68020 cpu needed to run this program */
#define loader_$xrev_incompatible         (loader_$module_code+17)  /* incorrect mixing of different revision software attempted */
#define loader_$space_used                (loader_$module_code+18)  /* The address space specified for use by the loader was occupied already */
#define loader_$abs_space_used            (loader_$module_code+19)  /* The address space specified by the absolute program was occupied already */
#define loader_$abs_reloc_needed          (loader_$module_code+20)  /* Attempting to load a program that needs relocation that can't be done at load time */
#define loader_$incompatible_load_mode    (loader_$module_code+21)  /* invalid combination of arguments to loader */
#define loader_$error_with_shared_lib     (loader_$module_code+22)  /* There was some error in loading one of the shared libraries */
#define loader_$shared_lib_pic_required   (loader_$module_code+22)  /* one of the shared libraries wasn't PIC */
#define loader_$mfpa_required             (loader_$module_code+23)  /* an processor with a FPA floating point accelerator needed to run this program */
#define loader_$end_of_image_list         (loader_$module_code+24)  /* No more images exists in the list */
#define loader_$invalid_image_handle      (loader_$module_code+25)  /* Image handle passed into loader is invalid */
#define loader_$invalid_section_number    (loader_$module_code+26)  /* invalid section number requested from loader */
#define loader_$linking_required          (loader_$module_code+27)  /* program can't be loaded without a linking phase */
#define loader_$obsolete_systype          (loader_$module_code+28)  /* systype specified by the program can't be loaded anymore */
#define loader_$table_in_use              (loader_$module_code+29)  /* unused */
#define loader_$no_module_for_mach_type   (loader_$module_code+30)  /* compound executable contains no module appropriate to machine type */
#define loader_$obsolete_systype_sys3     (loader_$module_code+31)  /* sys3-specific warning about program requiring obsolete systype */
#define loader_$pic_required              (loader_$module_code+32)  /* load context precludes absolute code object modules */
#define loader_$cannot_unload             (loader_$module_code+33)  /* load context precludes unload */


typedef unsigned short loader_$opts;

#define loader_$copy_proc        (loader_$opts)0x0001      /* copy read-only text into address space, instead of mapping */
#define loader_$install          (loader_$opts)0x0002      /* install defined globals into KGT */
#define loader_$no_unresolveds   (loader_$opts)0x0004      /* don't load if there are unresolved globals */
#define loader_$dont_redefine    (loader_$opts)0x0008      /* Don't redefine any already known symbols in the KGT */
#define loader_$load_writable    (loader_$opts)0x0010      /* map the read-only text writable in the address space */
#define loader_$keep_on_exec     (loader_$opts)0x0020      /* Keep program loaded across execs. */
#define loader_$no_dynamic       (loader_$opts)0x0040      /* don't load if there are unresolvable references */
#define loader_$opt_dummy07      (loader_$opts)0x0080      /* reserved */
#define loader_$opt_dummy08      (loader_$opts)0x0100      /* reserved */
#define loader_$opt_dummy09      (loader_$opts)0x0200      /* reserved */
#define loader_$opt_dummy10      (loader_$opts)0x0400      /* reserved */
#define loader_$load_secure_only (loader_$opts)0x0800      /* For Apollo use, don't resolve against user inlibed libraries */
#define loader_$load_global_data (loader_$opts)0x1000      /* For Apollo use, load data sections in global R/W storage. */
#define loader_$load_main        (loader_$opts)0x2000      /* For Apollo use, load as main program, causing etext, edata, end, bss to change*/
#define loader_$load_global      (loader_$opts)0x4000      /* for Apollo use, load in global space */
#define loader_$load_only_post_sr9_5  (loader_$opts)0x8000 /* For Apollo use, load only post sr9.5 object modules */

#define loader_$string_maxlen 4096

typedef short loader_$string_index;  /* 0..loader_$string_maxlen */
typedef char  loader_$string[loader_$string_maxlen];

typedef void *loader_$handle_t;         /* returned by loader to request section information */

#define loader_$kg_symbol -1            /* "section size" for symbol definition */

typedef unsigned short loader_$kg_lookup_opts;

#define loader_$kg_force_load   (loader_$kg_lookup_opts)0x0001  /* Causes symbols in global libraries to be loaded if not already */
#define loader_$kg_public_only  (loader_$kg_lookup_opts)0x0002  /* Only lookup symbols in public address space, i.e ignore privately installed symbols */
#define loader_$kg_function_only    (loader_$kg_lookup_opts)0x0004  /* Only match symbols marked as function */
#define loader_$kg_data_only    (loader_$kg_lookup_opts)0x0008  /* Only match symbols marked as data */
#define loader_$kg_secure_only  (loader_$kg_lookup_opts)0x0010  /* Don't resolve to user inlibed symbols */
#define loader_$kg_lookup_pad5  (loader_$kg_lookup_opts)0x0020  /* reserved */
#define loader_$kg_lookup_pad6  (loader_$kg_lookup_opts)0x0040  /* reserved */
#define loader_$kg_lookup_pad7  (loader_$kg_lookup_opts)0x0080  /* reserved */
#define loader_$kg_lookup_pad8  (loader_$kg_lookup_opts)0x0100  /* reserved */
#define loader_$kg_lookup_pad9  (loader_$kg_lookup_opts)0x0200  /* reserved */
#define loader_$kg_lookup_pada  (loader_$kg_lookup_opts)0x0400  /* reserved */
#define loader_$kg_lookup_padb  (loader_$kg_lookup_opts)0x0800  /* reserved */
#define loader_$kg_lookup_padc  (loader_$kg_lookup_opts)0x1000  /* reserved */
#define loader_$kg_lookup_padd  (loader_$kg_lookup_opts)0x2000  /* reserved */
#define loader_$kg_lookup_pade  (loader_$kg_lookup_opts)0x4000  /* reserved */
#define loader_$kg_bypass_inlib (loader_$kg_lookup_opts)0x8000  /* for Apollo use, used internally by the loader */

/* approved interface to determine load information */

typedef unsigned short loader_$sym_flags;               /* information about a symbol */

#define loader_$sym_loaded   (loader_$sym_flags)0x0001  /* is currently loaded into the address space */
#define loader_$sym_known    (loader_$sym_flags)0x0002  /* is currently publically available */
#define loader_$sym_dynamic  (loader_$sym_flags)0x0004  /* will be loaded at execution of symbol */
#define loader_$sym_function     (loader_$sym_flags)0x0008  /* is known to be a function */
#define loader_$sym_data     (loader_$sym_flags)0x0010  /* is known to be a data symbol */
#define loader_$sym_section  (loader_$sym_flags)0x0020  /* is a section name */
#define loader_$sym_pad6     (loader_$sym_flags)0x0040  /* reserved */
#define loader_$sym_pad7     (loader_$sym_flags)0x0080  /* reserved */
#define loader_$sym_pad8     (loader_$sym_flags)0x0100  /* reserved */
#define loader_$sym_pad9     (loader_$sym_flags)0x0200  /* reserved */
#define loader_$sym_pada     (loader_$sym_flags)0x0400  /* reserved */
#define loader_$sym_padb     (loader_$sym_flags)0x0800  /* reserved */
#define loader_$sym_padc     (loader_$sym_flags)0x1000  /* reserved */
#define loader_$sym_padd     (loader_$sym_flags)0x2000  /* reserved */
#define loader_$sym_pade     (loader_$sym_flags)0x4000  /* reserved */
#define loader_$sym_pre_sr95 (loader_$sym_flags)0x8000  /* for Apollo use, is used to pre sr9.5 compatibility */

typedef unsigned short loader_$kg_define_opts;

#define loader_$kg_keep_on_exec  (loader_$kg_define_opts)0x0001 /* keep in address space after an exec happens */
#define loader_$kg_function      (loader_$kg_define_opts)0x0002 /* symbol is to be marked as a function symbol */
#define loader_$kg_define_pad2   (loader_$kg_define_opts)0x0004 /* reserved */
#define loader_$kg_define_pad3   (loader_$kg_define_opts)0x0008 /* reserved */
#define loader_$kg_define_pad4   (loader_$kg_define_opts)0x0010 /* reserved */
#define loader_$kg_define_pad5   (loader_$kg_define_opts)0x0020 /* reserved */
#define loader_$kg_define_pad6   (loader_$kg_define_opts)0x0040 /* reserved */
#define loader_$kg_define_pad7   (loader_$kg_define_opts)0x0080 /* reserved */
#define loader_$kg_define_pad8   (loader_$kg_define_opts)0x0100 /* reserved */
#define loader_$kg_define_pad9   (loader_$kg_define_opts)0x0200 /* reserved */
#define loader_$kg_define_pada   (loader_$kg_define_opts)0x0400 /* reserved */
#define loader_$kg_define_padb   (loader_$kg_define_opts)0x0800 /* reserved */
#define loader_$kg_define_padc   (loader_$kg_define_opts)0x1000 /* reserved */
#define loader_$kg_define_padd   (loader_$kg_define_opts)0x2000 /* reserved */
#define loader_$kg_global        (loader_$kg_define_opts)0x4000 /* for Apollo use, load the symbol in the global kgt */
#define loader_$kg_is_pre_sr95   (loader_$kg_define_opts)0x8000 /* for Apollo use, is used to pre sr9.5 compatibility */

#pragma push_alignment
#pragma word_alignment

/* information about an image loaded into memory */
typedef struct {
    uid_$t           image_uid;       /* uid of object contining image */
    loader_$handle_t handle;          /* handle of this image */
    loader_$handle_t next_handle;     /* handle of next image */
    unsigned long    nsects;          /* number of sections in this image */
    unsigned long    image_base;      /* base offset of image in image file */
    loader_$opts     opts;            /* options object was loaded with */
} loader_$image __attribute((aligned(1))); /* so sizeof is alignment insensitive */

/* information about a section of an image */
typedef struct {
    unsigned long    addr;            /* address at which this section is loaded */
    unsigned long    paddr;           /* expected start address (from object file) */
    unsigned long    len;             /* the length of this section */
    unsigned long    sect_num;        /* section number as found in object file */
    loader_$string  *name;            /* name (this is in the same address space as the image) */
    short            name_len;        /* the length of the name */
} loader_$section __attribute((aligned(1))); /* so sizeof is alignment insensitive */

/* information about a known library */
typedef struct {
    uid_$t           lib_uid;         /* uid of object */
    loader_$handle_t handle;          /* internal handle */
    int              pad:13;          /* reserved */
    boolean          dynamic:1;       /* library is loaded dynamically at run time */
    boolean          global:1;        /* library must be in global space */
    boolean          inlib:1;         /* library was inlib'd */
} loader_$known_lib __attribute((aligned(1))); /* so sizeof is alignment insensitive */

#pragma pop_alignment

typedef void (*library_$init_ptr_t) (
#if __STDC__
     status_$t *status, 
     boolean global_init
#endif
    );

typedef library_$init_ptr_t library_$init_section_t[];
typedef library_$init_section_t *library_$init_section_ptr_t;

#define library_$init_section_name   "library_$init_pure_data$"


/*  Required for C++ V2.0  */
#ifdef  __cplusplus
    extern "C" {
#endif

/* --------------------------------------------------------------------- */
/* L O A D - load an object module given its name */
_DECL_FUNC(void, loader_$load ,(
    char             *name,
    short            &nam_len,
    loader_$opts     &opts,
    loader_$handle_t *handle,
    status_$t        *status
    ));

/* --------------------------------------------------------------------- */
/* C O N D _ L O A D - load an object module given its name,
  returns true if object module was successfully loaded,
  false if it was not loaded because it had already been
  installed in the process or an error was encountered
  (cf. status) */

_DECL_FUNC(boolean, loader_$cond_load ,(
    char             *name,
    short            &nam_len,
    loader_$opts     &opts,
    loader_$handle_t *handle,
    status_$t        *status
    ));

/* --------------------------------------------------------------------- */
/* U N L O A D - unload object module */
_DECL_FUNC(void, loader_$unload ,(
    loader_$handle_t &handle,
    status_$t        *status));

/* --------------------------------------------------------------------- */
/* I N L I B - inlib a library */

_DECL_FUNC(void, loader_$inlib ,(
    char             *name,
    short            &nam_len,
    status_$t        *status
    ));

/* --------------------------------------------------------------------- */
/* C L E A R _ I N L I B - clear inlib list */

_DECL_FUNC(void, loader_$clear_inlib ,(
    status_$t        *status
    ));

/* --------------------------------------------------------------------- */
/* L O O K U P- look up a symbol or section and get its address, if defined.
 *  section_size = loader_$kg_symbol for symbol,
 *  section_size = section_size for section 
 *  returns a set of loader_$sym_flags
 */

_DECL_FUNC(loader_$sym_flags, loader_$kg_lookup ,(
    char             *name,
    short            &nam_len,
    long             &section_size,
    loader_$kg_lookup_opts   &lookup_opts,
    void             **address
    ));

/* --------------------------------------------------------------------- */
/* D E F I N E - put a symbol symbol or section and its address into the kgt.
 *  section_size = loader_$kg_symbol for symbol,
 *  section_size = section_size for section
 */

_DECL_FUNC(void, loader_$kg_define ,(
    char             *name,
    short            &nam_len,
    void            *&address,
    long             &section_size,
    loader_$kg_define_opts   &define_opts,
    status_$t        *status
   ));

#if 0   /* Following bad in non-ansi environment and not needed in sys_funs.c*/
/* --------------------------------------------------------------------- */
/* S T A R T _ A D D R - look up start address of given program load     */

_DECL_FUNC(void *,  loader_$lookup_start_addr, (
    loader_$handle_t &handle,
    status_$t        *status
    )) #options(a0_return);
#endif

/* --------------------------------------------------------------------- */
/* S T A C K _ S I Z E - look up stack size requirement */

_DECL_FUNC(unsigned long, loader_$lookup_stack_size ,(
    loader_$handle_t &handle,
    status_$t        *status
    ));

/* --------------------------------------------------------------------- */
/* approved interface to determine load information */
/* I N Q U I R E   I M A G E  -  get information about what has been loaded into an address space. */

_DECL_FUNC(void, loader_$inquire_image ,(
    loader_$handle_t &handle,           /* handle of the image */
    loader_$image    *image,            /* The requested information */
    status_$t        *status
    ));

/* --------------------------------------------------------------------- */
/* I N Q U I R E   S E C T I O N  -  get information about what the sections in an image. */
_DECL_FUNC(void, loader_$inquire_section ,(
    loader_$handle_t &handle,          /* handle of image */
    unsigned long    &index,           /* load index of the section that we want information on. */
    loader_$section  *section,         /* The requested information */
    status_$t        *status
    ));

/* --------------------------------------------------------------------- */
/* I N Q U I R E   S T A T  -  gets information about changes in the load map. */
_DECL_FUNC(void, loader_$inquire_stat ,(
    unsigned long    *load_count,     /* number of images that have been loaded since process creation */
    unsigned long    *unload_count,   /* number of images that have been unloaded since process creation */
    status_$t        *status
    ));


/* --------------------------------------------------------------------- */
/* I N Q U I R E _ K N O W N _ L I B - get information on known libraries. */
_DECL_FUNC(void, loader_$inquire_known_lib ,(
    loader_$handle_t  &handle,         /* handle of previous image. nil will get you the first. */
    loader_$known_lib *info,           /* The requested information */
    status_$t         *status
    ));

#ifdef  __cplusplus
    }
#endif

#endif /* apollo_loader_h */
#endif /* APOLLO *) */
