|
|
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 <filehdr.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: #ifdef VERBOSE
35: puts("COFF! COFF!\r\n");
36: #endif
37: retval =
38: coff2load(ip, table, data_seg);
39: break;
40:
41: /* Is this an l.out executable? */
42: case L_MAGIC:
43: #ifdef VERBOSE
44: puts("l.out!\r\n");
45: #endif
46: retval =
47: lout2load(ip, table, data_seg);
48: break;
49:
50: default:
51: retval = (1==2);
52: break;
53: } /* switch (magic) */
54:
55: return (retval);
56: } /* object2load() */
57:
58:
59: /* Look up symbol(s) in an object file.
60: * searches the name list (symbol table) of the load module
61: * "filename" for each symbol in the array pointed to by "nlp".
62: *
63: * nlp points to an array of nlist structures, terminated by a
64: * structure with a null string as its n_name member.
65: *
66: * If "filename" is not a load module or has had its symbol table
67: * stripped, all returned n_type and n_value entries will be zero.
68: *
69: */
70:
71: uint16
72: object_nlist(magic, filename, symbol)
73: uint16 magic;
74: char *filename;
75: char *symbol;
76: {
77: uint32 tmp;
78: unsigned int retval; /* Return value. */
79: struct nlist nlp[2]; /* For talking with l_out_nlist(). */
80:
81: switch (magic) {
82: /* Is this an i386 COFF executable? */
83: case I386MAGIC:
84: /* Check that offset into data segment is < 64K. */
85: if ((tmp = wrap_coffnlist(filename, symbol)) > MAXUINT16) {
86: puts("object_nlist(): ERROR: Symbol ");
87: puts(symbol);
88: puts(" will not fit into 16 bits.\r\n");
89: puts(symbol); puts("=");
90: print32(tmp);
91: puts("\r\n");
92:
93: retval = 0;
94: } else {
95: retval = (uint16) tmp;
96: }
97: break;
98:
99: /* Is this an l.out executable? */
100: case L_MAGIC:
101: strcpy(nlp[0].n_name, symbol);
102: strcat(nlp[0].n_name, "_");
103: nlp[1].n_name[0] = '\0';
104: l_out_nlist(filename, nlp);
105: retval = nlp[0].n_value;
106: break;
107:
108: default:
109: break;
110: } /* switch (magic) */
111:
112: return (retval);
113: } /* object_nlist() */
114:
115:
116: /* Determine the value for sys_base based on the type of the load file. */
117: uint16
118: object_sys_base(magic)
119: int magic;
120: {
121: uint16 retval;
122:
123: switch (magic) {
124: /* Is this an i386 COFF executable? */
125: case I386MAGIC:
126: retval = COFF_SYS_BASE;
127: break;
128:
129: /* Is this an l.out executable? */
130: case L_MAGIC:
131: retval = DEF_SYS_BASE;
132: break;
133:
134: default:
135: break;
136: } /* switch (magic) */
137:
138: return(retval);
139: } /* object_sys_base() */
140:
141: #ifdef TEST
142: main()
143: {
144: printf("pipdev: %x", object_nlist(I386MAGIC, "/at386", "pipedev"));
145: } /* main () */
146:
147: #endif /* TEST */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.