Annotation of coherent/d/conf/tboot/objects.c, revision 1.1

1.1     ! root        1: /* objects.c -- routines for handling different object formats.
        !             2:  * Currently, only COFF and COHERENT l.out are supported.
        !             3:  */
        !             4: #include <sys/inode.h>
        !             5: #include <sys/types.h>
        !             6: #include <l.out.h>
        !             7: #include <coff.h>      /* COFF */
        !             8: 
        !             9: #include "tboot.h"
        !            10: 
        !            11: /* Extract information from an object file that describes how to
        !            12:  * load an executable.
        !            13:  * The magic number of the file is in "magic".
        !            14:  * The object file's inode is in "ip".
        !            15:  *
        !            16:  * The information needed is extracted into "table".
        !            17:  * The value for the data segment is put in "data_seg".
        !            18:  *
        !            19:  * Returns TRUE if the needed information could be extracted, FALSE ow.
        !            20:  */
        !            21: 
        !            22: int
        !            23: object2load(magic, ip, table, data_seg)
        !            24:        uint16 magic;
        !            25:        struct inode *ip;
        !            26:        struct load_segment table[];
        !            27:        uint16 *data_seg;
        !            28: {
        !            29:        int retval;
        !            30: 
        !            31:        switch (magic) {
        !            32:        /* Is this an i386 COFF executable?  */
        !            33:        case I386MAGIC:
        !            34:                VERBOSE( puts("COFF!  COFF!\r\n"); );
        !            35:                retval = 
        !            36:                        coff2load(ip, table, data_seg);
        !            37:                break;
        !            38:                
        !            39:        /* Is this an l.out executable?  */
        !            40:        case L_MAGIC:
        !            41:                VERBOSE( puts("l.out!\r\n"); );
        !            42:                retval =
        !            43:                        lout2load(ip, table, data_seg);
        !            44:                break;
        !            45:        
        !            46:        default:
        !            47:                retval = FALSE;
        !            48:                break;
        !            49:        } /* switch (magic) */
        !            50: 
        !            51:        return (retval);
        !            52: } /* object2load() */
        !            53: 
        !            54: 
        !            55: /* Look up symbol(s) in an object file. 
        !            56:  * searches  the name list  (symbol table) of  the load module
        !            57:  * "filename" for each symbol in the array pointed to by "nlp".
        !            58:  *
        !            59:  * nlp points to an array of nlist structures, terminated by a
        !            60:  * structure with a null string as its n_name member.
        !            61:  *
        !            62:  * If "filename" is not a load module or has had its symbol table
        !            63:  * stripped, all returned n_type and n_value entries will be zero.
        !            64:  *
        !            65:  */
        !            66: 
        !            67: uint16
        !            68: object_nlist(magic, filename, symbol)
        !            69:        uint16 magic;
        !            70:        char *filename;
        !            71:        char *symbol;
        !            72: {
        !            73:        uint32 tmp;
        !            74:        unsigned int retval;            /* Return value.  */
        !            75: 
        !            76:        switch (magic) {
        !            77:        /* Is this an i386 COFF executable?  */
        !            78:        case I386MAGIC:
        !            79:                /* Check that offset into data segment is < 64K.  */
        !            80:                if ((tmp = wrap_coffnlist(filename, symbol)) > MAXUINT16) {
        !            81:                        puts("object_nlist(): ERROR: Symbol ");
        !            82:                        puts(symbol);
        !            83:                        puts(" will not fit into 16 bits.\r\n");
        !            84:                        puts(symbol); puts("=");
        !            85:                        print32(tmp);
        !            86:                        puts("\r\n");
        !            87:                        
        !            88:                        retval = 0;
        !            89:                } else {
        !            90:                        retval = (uint16) tmp;
        !            91:                }
        !            92:                break;
        !            93:                
        !            94:        /* Is this an l.out executable?  */
        !            95:        case L_MAGIC:
        !            96:                retval = wrap_l_out_nlist(filename, symbol);
        !            97:                break;
        !            98:        
        !            99:        default:
        !           100:                break;
        !           101:        } /* switch (magic) */
        !           102: 
        !           103:        return (retval);
        !           104: } /* object_nlist() */
        !           105: 
        !           106: 
        !           107: /* Determine the value for sys_base based on the type of the load file.  */
        !           108: uint16
        !           109: object_sys_base(magic)
        !           110:        int magic;
        !           111: {
        !           112:        uint16 retval;
        !           113: 
        !           114:        switch (magic) {
        !           115:        /* Is this an i386 COFF executable?  */
        !           116:        case I386MAGIC:
        !           117:                retval = COFF_SYS_BASE;
        !           118:                break;
        !           119:                
        !           120:        /* Is this an l.out executable?  */
        !           121:        case L_MAGIC:
        !           122:                retval = DEF_SYS_BASE;
        !           123:                break;
        !           124:        
        !           125:        default:
        !           126:                break;
        !           127:        } /* switch (magic) */
        !           128: 
        !           129:        return(retval);
        !           130: } /* object_sys_base() */
        !           131: 
        !           132: #ifdef TEST
        !           133: main()
        !           134: {
        !           135:        printf("pipdev: %x", object_nlist(I386MAGIC, "/at386", "pipedev"));
        !           136: } /* main () */
        !           137: 
        !           138: #endif /* TEST */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.