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);
137 seek(cout, HEADR+textsize, 0);
142 Bprint(&bso, "%5.2f datblk\n", cputime());
148 write(cout, buf, INITDAT-textsize);
152 for(v = 0; v < datsize; v += sizeof(buf)-Dbufslop) {
153 if(datsize-v > sizeof(buf)-Dbufslop)
154 datblk(v, sizeof(buf)-Dbufslop);
156 datblk(v, datsize-v);
164 Bprint(&bso, "%5.2f sym\n", cputime());
171 seek(cout, HEADR+textsize+datsize, 0);
177 Bprint(&bso, "%5.2f sp\n", cputime());
180 Bprint(&bso, "%5.2f pc\n", cputime());
189 seek(cout, HEADR+textsize+datsize, 0);
194 Bprint(&bso, "%5.2f headr\n", cputime());
201 magic |= 0x00008000; /* fat header */
203 magic |= 0x80000000; /* dlm */
204 lput(magic); /* magic */
205 lput(textsize); /* sizes */
208 lput(symsize); /* nsyms */
210 lput(PADDR(vl)); /* va of entry */
211 lput(spsize); /* sp offsets */
212 lput(lcsize); /* line offsets */
213 llput(vl); /* va of entry */
219 lput(magic); /* magic */
220 lput(textsize); /* sizes */
223 lput(symsize); /* nsyms */
224 lput(entryvalue()); /* va of entry */
225 lput(spsize); /* sp offsets */
226 lput(lcsize); /* line offsets */
229 strnput("\177ELF", 4); /* e_ident */
230 cput(1); /* class = 32 bit */
231 cput(1); /* data = LSB */
232 cput(1); /* version = CURRENT */
234 wputl(2); /* type = EXEC */
236 wputl(3); /* machine = 386 */
238 wputl(62); /* machine = AMD64 */
239 lputl(1L); /* version = CURRENT */
240 lputl(PADDR(entryvalue())); /* entry vaddr */
241 lputl(52L); /* offset to first phdr */
242 lputl(0L); /* offset to first shdr */
243 lputl(0L); /* processor specific flags */
244 wputl(52); /* Ehdr size */
245 wputl(32); /* Phdr size */
246 wputl(3); /* # of Phdrs */
247 wputl(0); /* Shdr size */
248 wputl(0); /* # of Shdrs */
249 wputl(0); /* Shdr string size */
251 lputl(1L); /* text - type = PT_LOAD */
252 lputl(HEADR); /* file offset */
253 lputl(INITTEXT); /* vaddr */
254 lputl(PADDR(INITTEXT)); /* paddr */
255 lputl(textsize); /* file size */
256 lputl(textsize); /* memory size */
257 lputl(0x05L); /* protections = RX */
258 lputl(INITRND); /* alignment */
260 lputl(1L); /* data - type = PT_LOAD */
261 lputl(HEADR+textsize); /* file offset */
262 lputl(INITDAT); /* vaddr */
263 lputl(PADDR(INITDAT)); /* paddr */
264 lputl(datsize); /* file size */
265 lputl(datsize+bsssize); /* memory size */
266 lputl(0x06L); /* protections = RW */
267 lputl(INITRND); /* alignment */
269 lputl(0L); /* symbols - type = PT_NULL */
270 lputl(HEADR+textsize+datsize); /* file offset */
273 lputl(symsize); /* symbol table size */
274 lputl(lcsize); /* line number size */
275 lputl(0x04L); /* protections = R */
276 lputl(0x04L); /* alignment */
287 n = sizeof(buf.cbuf) - cbc;
289 write(cout, buf.cbuf, n);
291 cbc = sizeof(buf.cbuf);
295 datblk(long s, long n)
303 memset(buf.dbuf, 0, n+Dbufslop);
304 for(p = datap; p != P; p = p->link) {
306 l = p->from.sym->value + p->from.offset - s;
319 if(p->as != AINIT && p->as != ADYNT && !p->from.sym->dupok) {
320 for(j=l+(c-i)-1; j>=l; j--)
323 diag("multiple initialization");
332 fl = ieeedtof(&p->to.ieee);
334 if(debug['a'] && i == 0) {
335 Bprint(&bso, pcstr, l+s+INITDAT);
337 Bprint(&bso, "%.2ux", cast[fnuxi4[j]]);
338 Bprint(&bso, "\t%P\n", curp);
341 buf.dbuf[l] = cast[fnuxi4[i]];
346 cast = (uchar*)&p->to.ieee;
347 if(debug['a'] && i == 0) {
348 Bprint(&bso, pcstr, l+s+INITDAT);
350 Bprint(&bso, "%.2ux", cast[fnuxi8[j]]);
351 Bprint(&bso, "\t%P\n", curp);
354 buf.dbuf[l] = cast[fnuxi8[i]];
362 if(debug['a'] && i == 0) {
363 Bprint(&bso, pcstr, l+s+INITDAT);
365 Bprint(&bso, "%.2ux", p->to.scon[j] & 0xff);
366 Bprint(&bso, "\t%P\n", curp);
369 buf.dbuf[l] = p->to.scon[i];
375 if(p->to.type == D_ADDR) {
376 if(p->to.index != D_STATIC && p->to.index != D_EXTERN)
377 diag("DADDR type%P", p);
379 if(p->to.sym->type == SUNDEF)
381 o += p->to.sym->value;
382 if(p->to.sym->type != STEXT && p->to.sym->type != SUNDEF)
385 dynreloc(p->to.sym, l+s+INITDAT, 1);
392 diag("bad nuxi %d %d\n%P", c, i, curp);
395 if(debug['a'] && i == 0) {
396 Bprint(&bso, pcstr, l+s+INITDAT);
398 Bprint(&bso, "%.2ux", cast[inuxi1[j]]);
399 Bprint(&bso, "\t%P\n", curp);
402 buf.dbuf[l] = cast[inuxi1[i]];
407 if(debug['a'] && i == 0) {
408 Bprint(&bso, pcstr, l+s+INITDAT);
410 Bprint(&bso, "%.2ux", cast[inuxi2[j]]);
411 Bprint(&bso, "\t%P\n", curp);
414 buf.dbuf[l] = cast[inuxi2[i]];
419 if(debug['a'] && i == 0) {
420 Bprint(&bso, pcstr, l+s+INITDAT);
422 Bprint(&bso, "%.2ux", cast[inuxi4[j]]);
423 Bprint(&bso, "\t%P\n", curp);
426 buf.dbuf[l] = cast[inuxi4[i]];
432 if(debug['a'] && i == 0) {
433 Bprint(&bso, pcstr, l+s+INITDAT);
435 Bprint(&bso, "%.2ux", cast[inuxi8[j]]);
436 Bprint(&bso, "\t%P\n", curp);
439 buf.dbuf[l] = cast[inuxi8[i]];
447 write(cout, buf.dbuf, n);
451 rnd(vlong v, vlong r)