5 #define PADDR(a) ((a) & ~0xfffffffff0000000ull)
14 if(*a >= '0' && *a <= '9')
24 return s->value+INITDAT;
26 diag("entry not text: %s", s->name);
71 strnput(char *s, int n)
73 for(; *s && n > 0; s++){
93 Bprint(&bso, "%5.2f asmb\n", cputime());
99 for(p = firstp; p != P; p = p->link) {
105 diag("phase error %llux sb %llux in %s", p->pc, pc, TNAME);
114 Bprint(&bso, pcstr, pc);
115 for(op1 = and; op1 < andptr; op1++)
116 Bprint(&bso, "%.2ux", *op1 & 0xff);
117 Bprint(&bso, "\t%P\n", curp);
122 else if(reloca != nil)
123 diag("reloc failure: %P", curp);
125 memmove(cbp, and, a);
133 diag("unknown header type %ld", HEADTYPE);
136 seek(cout, HEADR+textsize, 0);
141 Bprint(&bso, "%5.2f datblk\n", cputime());
147 write(cout, buf, INITDAT-textsize);
151 for(v = 0; v < datsize; v += sizeof(buf)-Dbufslop) {
152 if(datsize-v > sizeof(buf)-Dbufslop)
153 datblk(v, sizeof(buf)-Dbufslop);
155 datblk(v, datsize-v);
163 Bprint(&bso, "%5.2f sym\n", cputime());
169 seek(cout, HEADR+textsize+datsize, 0);
175 Bprint(&bso, "%5.2f sp\n", cputime());
178 Bprint(&bso, "%5.2f pc\n", cputime());
187 seek(cout, HEADR+textsize+datsize, 0);
192 Bprint(&bso, "%5.2f headr\n", cputime());
199 magic |= 0x00008000; /* fat header */
201 magic |= 0x80000000; /* dlm */
202 lput(magic); /* magic */
203 lput(textsize); /* sizes */
206 lput(symsize); /* nsyms */
208 lput(PADDR(vl)); /* va of entry */
209 lput(spsize); /* sp offsets */
210 lput(lcsize); /* line offsets */
211 llput(vl); /* va of entry */
217 lput(magic); /* magic */
218 lput(textsize); /* sizes */
221 lput(symsize); /* nsyms */
222 lput(entryvalue()); /* va of entry */
223 lput(spsize); /* sp offsets */
224 lput(lcsize); /* line offsets */
227 strnput("\177ELF", 4); /* e_ident */
228 cput(1); /* class = 32 bit */
229 cput(1); /* data = LSB */
230 cput(1); /* version = CURRENT */
232 wputl(2); /* type = EXEC */
234 wputl(3); /* machine = 386 */
236 wputl(62); /* machine = AMD64 */
237 lputl(1L); /* version = CURRENT */
238 lputl(PADDR(entryvalue())); /* entry vaddr */
239 lputl(52L); /* offset to first phdr */
240 lputl(0L); /* offset to first shdr */
241 lputl(0L); /* processor specific flags */
242 wputl(52); /* Ehdr size */
243 wputl(32); /* Phdr size */
244 wputl(3); /* # of Phdrs */
245 wputl(0); /* Shdr size */
246 wputl(0); /* # of Shdrs */
247 wputl(0); /* Shdr string size */
249 lputl(1L); /* text - type = PT_LOAD */
250 lputl(HEADR); /* file offset */
251 lputl(INITTEXT); /* vaddr */
252 lputl(PADDR(INITTEXT)); /* paddr */
253 lputl(textsize); /* file size */
254 lputl(textsize); /* memory size */
255 lputl(0x05L); /* protections = RX */
256 lputl(INITRND); /* alignment */
258 lputl(1L); /* data - type = PT_LOAD */
259 lputl(HEADR+textsize); /* file offset */
260 lputl(INITDAT); /* vaddr */
261 lputl(PADDR(INITDAT)); /* paddr */
262 lputl(datsize); /* file size */
263 lputl(datsize+bsssize); /* memory size */
264 lputl(0x06L); /* protections = RW */
265 lputl(INITRND); /* alignment */
267 lputl(0L); /* symbols - type = PT_NULL */
268 lputl(HEADR+textsize+datsize); /* file offset */
271 lputl(symsize); /* symbol table size */
272 lputl(lcsize); /* line number size */
273 lputl(0x04L); /* protections = R */
274 lputl(0x04L); /* alignment */
285 n = sizeof(buf.cbuf) - cbc;
287 write(cout, buf.cbuf, n);
289 cbc = sizeof(buf.cbuf);
293 datblk(long s, long n)
301 memset(buf.dbuf, 0, n+Dbufslop);
302 for(p = datap; p != P; p = p->link) {
304 l = p->from.sym->value + p->from.offset - s;
317 if(p->as != AINIT && p->as != ADYNT) {
318 for(j=l+(c-i)-1; j>=l; j--)
321 diag("multiple initialization");
330 fl = ieeedtof(&p->to.ieee);
332 if(debug['a'] && i == 0) {
333 Bprint(&bso, pcstr, l+s+INITDAT);
335 Bprint(&bso, "%.2ux", cast[fnuxi4[j]]);
336 Bprint(&bso, "\t%P\n", curp);
339 buf.dbuf[l] = cast[fnuxi4[i]];
344 cast = (uchar*)&p->to.ieee;
345 if(debug['a'] && i == 0) {
346 Bprint(&bso, pcstr, l+s+INITDAT);
348 Bprint(&bso, "%.2ux", cast[fnuxi8[j]]);
349 Bprint(&bso, "\t%P\n", curp);
352 buf.dbuf[l] = cast[fnuxi8[i]];
360 if(debug['a'] && i == 0) {
361 Bprint(&bso, pcstr, l+s+INITDAT);
363 Bprint(&bso, "%.2ux", p->to.scon[j] & 0xff);
364 Bprint(&bso, "\t%P\n", curp);
367 buf.dbuf[l] = p->to.scon[i];
373 if(p->to.type == D_ADDR) {
374 if(p->to.index != D_STATIC && p->to.index != D_EXTERN)
375 diag("DADDR type%P", p);
377 if(p->to.sym->type == SUNDEF)
379 o += p->to.sym->value;
380 if(p->to.sym->type != STEXT && p->to.sym->type != SUNDEF)
383 dynreloc(p->to.sym, l+s+INITDAT, 1);
390 diag("bad nuxi %d %d\n%P", c, i, curp);
393 if(debug['a'] && i == 0) {
394 Bprint(&bso, pcstr, l+s+INITDAT);
396 Bprint(&bso, "%.2ux", cast[inuxi1[j]]);
397 Bprint(&bso, "\t%P\n", curp);
400 buf.dbuf[l] = cast[inuxi1[i]];
405 if(debug['a'] && i == 0) {
406 Bprint(&bso, pcstr, l+s+INITDAT);
408 Bprint(&bso, "%.2ux", cast[inuxi2[j]]);
409 Bprint(&bso, "\t%P\n", curp);
412 buf.dbuf[l] = cast[inuxi2[i]];
417 if(debug['a'] && i == 0) {
418 Bprint(&bso, pcstr, l+s+INITDAT);
420 Bprint(&bso, "%.2ux", cast[inuxi4[j]]);
421 Bprint(&bso, "\t%P\n", curp);
424 buf.dbuf[l] = cast[inuxi4[i]];
430 if(debug['a'] && i == 0) {
431 Bprint(&bso, pcstr, l+s+INITDAT);
433 Bprint(&bso, "%.2ux", cast[inuxi8[j]]);
434 Bprint(&bso, "\t%P\n", curp);
437 buf.dbuf[l] = cast[inuxi8[i]];
445 write(cout, buf.dbuf, n);
449 rnd(vlong v, vlong r)