12 Bprint(&bso, "%5.2f dodata\n", cputime());
14 for(p = datap; p != P; p = p->link) {
16 if(p->as == ADYNT || p->as == AINIT)
21 diag("initialize non-data (%d): %s\n%P",
23 v = p->from.offset + p->reg;
25 diag("initialize bounds (%ld): %s\n%P",
26 s->value, s->name, p);
31 * pull out string constants
33 for(p = datap; p != P; p = p->link) {
35 if(p->to.type == D_SCONST)
42 * assign 'small' variables to data segment
43 * (rational is that data segment is more easily
44 * addressed through offset on R12)
47 for(i=0; i<NHASH; i++)
48 for(s = hash[i]; s != S; s = s->link) {
50 if(t != SDATA && t != SBSS)
54 diag("%s: no size", s->name);
69 * assign large 'data' variables to data segment
71 for(i=0; i<NHASH; i++)
72 for(s = hash[i]; s != S; s = s->link) {
90 * everything else to bss segment
92 for(i=0; i<NHASH; i++)
93 for(s = hash[i]; s != S; s = s->link) {
102 bsssize = orig-datsize;
104 xdefine("setR12", SDATA, 0L+BIG);
105 xdefine("bdata", SDATA, 0L);
106 xdefine("edata", SDATA, datsize);
107 xdefine("end", SBSS, datsize+bsssize);
108 xdefine("etext", STEXT, 0L);
117 for(i=0; i<NHASH; i++)
118 for(s = hash[i]; s != S; s = s->link)
120 diag("%s: not defined", s->name);
128 for(i=0; i<20; i++) {
129 if(p == P || p->as != AB)
140 case ABEQ: return ABNE;
141 case ABNE: return ABEQ;
142 case ABCS: return ABCC;
143 case ABHS: return ABLO;
144 case ABCC: return ABCS;
145 case ABLO: return ABHS;
146 case ABMI: return ABPL;
147 case ABPL: return ABMI;
148 case ABVS: return ABVC;
149 case ABVC: return ABVS;
150 case ABHI: return ABLS;
151 case ABLS: return ABHI;
152 case ABGE: return ABLT;
153 case ABLT: return ABGE;
154 case ABGT: return ABLE;
155 case ABLE: return ABGT;
157 diag("unknown relation: %s", anames[a]);
165 Bprint(&bso, "%5.2f follow\n", cputime());
172 firstp = firstp->link;
193 if(!(p->mark & FOLL))
198 for(i=0,q=p; i<4; i++,q=q->link) {
206 if(a == AB || (a == ARET && q->scond == 14) || a == ARFE)
208 if(!q->cond || (q->cond->mark&FOLL))
210 if(a != ABEQ && a != ABNE)
217 print("cant happen 1\n");
227 if(a == AB || (a == ARET && q->scond == 14) || a == ARFE)
234 if(!(r->link->mark&FOLL))
236 if(!(r->cond->mark&FOLL))
237 print("cant happen 2\n");
245 q->to.type = D_BRANCH;
246 q->to.offset = p->pc;
253 if(a == AB || (a == ARET && p->scond == 14) || a == ARFE){
257 if(a != ABL && p->link != P) {
258 q = brchain(p->link);
259 if(a != ATEXT && a != ABCASE)
260 if(q != P && (q->mark&FOLL)) {
266 q = brchain(p->cond);
289 Bprint(&bso, "%5.2f patch\n", cputime());
292 s = lookup("exit", 0);
294 for(p = firstp; p != P; p = p->link) {
298 if((a == ABL || a == AB || a == ARET) &&
299 p->to.type != D_BRANCH && p->to.sym != S) {
303 diag("undefined: %s\n%P", s->name, p);
308 p->to.offset = s->value;
309 p->to.type = D_BRANCH;
313 diag("help: SUNDEF in AB || ARET");
315 p->to.type = D_BRANCH;
320 if(p->to.type != D_BRANCH || p->cond == UP)
323 for(q = firstp; q != P;) {
325 if(c >= q->forwd->pc) {
334 diag("branch out of range %ld\n%P", c, p);
340 for(p = firstp; p != P; p = p->link) {
343 if(p->cond != P && p->cond != UP) {
344 p->cond = brloop(p->cond);
346 if(p->to.type == D_BRANCH)
347 p->to.offset = p->cond->pc;
357 long dwn[LOG], cnt[LOG], i;
360 for(i=0; i<LOG; i++) {
363 cnt[i] = LOG * cnt[i-1];
368 for(p = firstp; p != P; p = p->link) {
397 if(q == p || c > 5000)
413 while(*s == ' ' || *s == '\t')
415 if(*s == '-' || *s == '+') {
418 while(*s == ' ' || *s == '\t')
421 if(s[0]=='0' && s[1]){
422 if(s[1]=='x' || s[1]=='X'){
425 if(*s >= '0' && *s <= '9')
426 n = n*16 + *s++ - '0';
427 else if(*s >= 'a' && *s <= 'f')
428 n = n*16 + *s++ - 'a' + 10;
429 else if(*s >= 'A' && *s <= 'F')
430 n = n*16 + *s++ - 'A' + 10;
435 while(*s >= '0' && *s <= '7')
436 n = n*8 + *s++ - '0';
438 while(*s >= '0' && *s <= '9')
439 n = n*10 + *s++ - '0';
466 for(i = 0; i < NHASH; i++)
467 for(s = hash[i]; s != S; s = s->link)
468 if(s->sig != 0 && s->type == SXREF && (nimports == 0 || s->subtype == SIMPORT)){
470 Bprint(&bso, "IMPORT: %s sig=%lux v=%ld\n", s->name, s->sig, s->value);
475 ckoff(Sym *s, long v)
477 if(v < 0 || v >= 1<<Roffset)
478 diag("relocation offset %ld for %s out of range", v, s->name);
482 newdata(Sym *s, int o, int w, int t)
491 p->from.type = D_OREG;
495 p->to.type = D_CONST;
503 int i, j, n, off, nb, sv, ne;
504 Sym *s, *et, *str, **esyms;
506 char buf[NSNAME], *t;
509 for(i = 0; i < NHASH; i++)
510 for(s = hash[i]; s != S; s = s->link)
511 if(s->sig != 0 && s->type != SXREF && s->type != SUNDEF && (nexports == 0 || s->subtype == SEXPORT))
513 esyms = malloc(n*sizeof(Sym*));
516 for(i = 0; i < NHASH; i++)
517 for(s = hash[i]; s != S; s = s->link)
518 if(s->sig != 0 && s->type != SXREF && s->type != SUNDEF && (nexports == 0 || s->subtype == SEXPORT))
520 for(i = 0; i < ne-1; i++)
521 for(j = i+1; j < ne; j++)
522 if(strcmp(esyms[i]->name, esyms[j]->name) > 0){
530 et = lookup(EXPTAB, 0);
531 if(et->type != 0 && et->type != SXREF)
532 diag("%s already defined", EXPTAB);
534 str = lookup(".string", 0);
538 for(i = 0; i < ne; i++){
540 Bprint(&bso, "EXPORT: %s sig=%lux t=%d\n", s->name, s->sig, s->type);
543 p = newdata(et, off, sizeof(long), D_EXTERN);
545 p->to.offset = s->sig;
548 p = newdata(et, off, sizeof(long), D_EXTERN);
550 p->to.name = D_EXTERN;
560 p = newdata(str, sv-NSNAME, NSNAME, D_STATIC);
561 p->to.type = D_SCONST;
562 p->to.sval = malloc(NSNAME);
563 memmove(p->to.sval, buf, NSNAME);
571 p = newdata(et, off, sizeof(long), D_EXTERN);
573 p->to.name = D_STATIC;
579 p = newdata(str, sv-nb, nb, D_STATIC);
580 p->to.type = D_SCONST;
581 p->to.sval = malloc(NSNAME);
582 memmove(p->to.sval, buf, nb);
585 for(i = 0; i < 3; i++){
586 newdata(et, off, sizeof(long), D_EXTERN);