6 * © 1994-1998 Straylight
9 /*----- Licensing note ----------------------------------------------------*
11 * This file is part of Straylight's Dynamic Linking System (SDLS)
13 * SDLS is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2, or (at your option)
18 * SDLS is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with SDLS. If not, write to the Free Software Foundation,
25 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36 #include "aof/chunk.h"
37 #include "hashtable.h"
49 #define cstub__MAGIC 0x004c4c44
50 #define cstub__VERSION 100
54 static void cstub__enames(char *p,unsigned ord,void *handle)
56 cstub__thing *t=handle;
57 if (ord==0xFFFFFFFF && hash_find(t->osym,p))
58 aof_string(p,t->f.area);
61 static void cstub__entries(char *p,unsigned ord,void *handle)
63 cstub__thing *t=handle;
64 static int entry[1]={0xE3A0F000}; /* MOV PC,#0 */
65 if (hash_find(t->osym,p))
67 aof_addsym(p,t->f.area->next-t->abase,0,t->areaname,&t->f);
70 aof_add(entry,t->f.area);
74 aof_add(ord,t->f.area);
78 void cstub(char *name,readdef_info *inf,hashtable osym)
85 /* --- Don't check if we're creating application stubs --- */
89 if (!(inf->errored & rd_name))
91 inf->errored|=rd_name;
95 if (!(inf->errored & rd_version))
97 inf->errored|=rd_version;
100 if (inf->errored & rd_name)
104 fp=fopen(name,"wb"); /* Open the output file */
105 if (!fp) /* If the file wasn't opened */
106 error(NOOPENOUT,name); /* Better give an error */
109 char _buf[sizeof(chunk_fixedHeader)+5*sizeof(chunk_tableEntry)];
110 chunk_header *h=(chunk_header *)&_buf; /* Allocate memory easily :-) */
112 aof_chunkinfo obj_idfn={0};
113 aof_chunkinfo obj_head={0};
114 aof_chunkinfo obj_area={0};
115 aof_chunkinfo obj_symt={0};
116 aof_chunkinfo obj_strt={0};
117 aof_chunkinfo reloc={0};
135 h->hdr.id=chunk_MAGIC; /* Fill in magic thingy */
136 h->hdr.maxChunks=h->hdr.numChunks=5; /* And number of chunks */
138 aof_string("Straylight Dynamic Link Library building system 1.01",
142 aof_int(0,&obj_strt);
144 aof_int((int)aof_RELOC,&obj_head);
145 aof_int(150,&obj_head);
146 aof_int((inf->apptbl ? 1 : 3),&obj_head);
147 aof_int(obj_symt.next/sizeof(aof_symbol),&obj_head);
148 aof_int(0,&obj_head);
149 aof_int(0,&obj_head);
151 /* --- Do entry names for dll table --- */
154 t.areaname=aof_string("DLL$$AppEntry",&obj_strt);
156 t.areaname=aof_string("DLL$$Strings",&obj_strt);
157 t.abase=obj_area.next;
161 sym_dllName=obj_symt.next/16;
162 aof_addsym("_dll_name",
163 obj_area.next-t.abase,
170 sprintf(buffer,"%s[%s]",inf->dllpath,inf->name);
171 aof_string(buffer,&obj_area);
175 sprintf(buffer,"[%s]",inf->name);
176 aof_string(buffer,&obj_area);
179 sym_dllEntries=obj_symt.next/16;
180 aof_addsym("_dll_entries",
181 obj_area.next-t.abase,
186 /* --- Hack for link v. 5.00 --- *
188 * We IMPORT the symbol _dll_findall in order to ensure that DLLLib
194 sym.name=aof_string("_dll_findall",&obj_strt);
197 aof_add(sym,&obj_symt);
202 aof_addsym("DLL$$AppEntryNames",
203 obj_area.next-t.abase,
209 hash_enumOrdered(inf->sym,cstub__enames,&t);
211 { char c=0; aof_add(c,&obj_area); }
217 aof_int(t.areaname,&obj_head);
218 aof_int(0x00002202,&obj_head);
219 aof_int(obj_area.next-osize,&obj_head);
220 aof_int(reloc.next/8-orelocs,&obj_head);
221 aof_int(0,&obj_head);
222 aof_addBlock(reloc.p,reloc.next,&obj_area);
224 orelocs=reloc.next/8;
226 /* --- Do entry veneers table --- */
228 t.areaname=aof_string("DLL$$Stubs",&obj_strt);
229 t.abase=obj_area.next;
231 sym_dllStubs=obj_symt.next/16;
232 aof_addsym("_dll_stubs",
233 obj_area.next-t.abase,
240 aof_addsym("DLL$$AppEntryStubs",
241 obj_area.next-t.abase,
248 hash_enumOrdered(inf->sym,cstub__entries,&t);
250 aof_int(-1,&obj_area);
254 aof_int(t.areaname,&obj_head);
255 aof_int(0x00002202,&obj_head);
256 aof_int(obj_area.next-osize,&obj_head);
257 aof_int(reloc.next/8-orelocs,&obj_head);
258 aof_int(0,&obj_head);
259 aof_addBlock(reloc.p,reloc.next,&obj_area);
261 orelocs=reloc.next/8;
263 /* --- Do external DLL table area --- */
267 t.areaname=aof_string("DLL$$ExternalTable",&obj_strt);
268 t.abase=obj_area.next;
270 tmp=aof_int(0,&obj_area)-t.abase;
272 aof_int(0x000A0000 | sym_dllName,&reloc);
274 aof_int(inf->version,&obj_area);
276 tmp=aof_int(0,&obj_area)-t.abase;
278 aof_int(0x000A0000 | sym_dllEntries,&reloc);
280 tmp=aof_int(0,&obj_area)-t.abase;
282 aof_int(0x000A0000 | sym_dllStubs,&reloc);
286 aof_int(t.areaname,&obj_head);
287 aof_int(0x00002202,&obj_head);
288 aof_int(obj_area.next-osize,&obj_head);
289 aof_int(reloc.next/8-orelocs,&obj_head);
290 aof_int(0,&obj_head);
291 aof_addBlock(reloc.p,reloc.next,&obj_area);
293 orelocs=reloc.next/8;
296 aof_fill(obj_strt.next,0,&obj_strt);
299 o=obj_symt.next/sizeof(aof_symbol);
300 aof_fill(o,12,&obj_head);
302 memcpy(h->table[0].chunkName,"OBJ_IDFN",8);
303 memcpy(h->table[1].chunkName,"OBJ_HEAD",8);
304 memcpy(h->table[2].chunkName,"OBJ_AREA",8);
305 memcpy(h->table[3].chunkName,"OBJ_SYMT",8);
306 memcpy(h->table[4].chunkName,"OBJ_STRT",8);
308 o=sizeof(chunk_fixedHeader)+5*sizeof(chunk_tableEntry);
310 h->table[0].offset=o;
311 h->table[0].size=obj_idfn.next;
314 h->table[1].offset=o;
315 h->table[1].size=obj_head.next;
318 h->table[2].offset=o;
319 h->table[2].size=obj_area.next;
322 h->table[3].offset=o;
323 h->table[3].size=obj_symt.next;
326 h->table[4].offset=o;
327 h->table[4].size=obj_strt.next;
330 fwrite(h,sizeof(chunk_fixedHeader)+5*sizeof(chunk_tableEntry),1,fp);
331 fwrite(obj_idfn.p,obj_idfn.next,1,fp);
332 fwrite(obj_head.p,obj_head.next,1,fp);
333 fwrite(obj_area.p,obj_area.next,1,fp);
334 fwrite(obj_symt.p,obj_symt.next,1,fp);
335 fwrite(obj_strt.p,obj_strt.next,1,fp);