16 main(int argc, char **argv)
24 Binit(bioout, 1, OWRITE);
35 text = open(file, OREAD);
37 fatal(1, "open text '%s'", file);
39 Bprint(bioout, "5i\n");
49 ulong t, d, b, bssend;
52 t = (fhdr.txtaddr+fhdr.txtsz+(BY2PG-1)) & ~(BY2PG-1);
53 d = (t + fhdr.datsz + (BY2PG-1)) & ~(BY2PG-1);
54 bssend = t + fhdr.datsz + fhdr.bsssz;
55 b = (bssend + (BY2PG-1)) & ~(BY2PG-1);
57 s = &memory.seg[Text];
59 s->base = fhdr.txtaddr - fhdr.hdrsz;
61 s->fileoff = fhdr.txtoff - fhdr.hdrsz;
62 s->fileend = s->fileoff + fhdr.txtsz;
63 s->table = emalloc(((s->end-s->base)/BY2PG)*sizeof(uchar*));
65 iprof = emalloc(((s->end-s->base)/PROFGRAN)*sizeof(long));
68 s = &memory.seg[Data];
72 s->fileoff = fhdr.datoff;
73 s->fileend = s->fileoff + fhdr.datsz;
74 datasize = fhdr.datsz;
75 s->table = emalloc(((s->end-s->base)/BY2PG)*sizeof(uchar*));
81 s->table = emalloc(((s->end-s->base)/BY2PG)*sizeof(uchar*));
83 s = &memory.seg[Stack];
85 s->base = STACKTOP-STACKSIZE;
87 s->table = emalloc(((s->end-s->base)/BY2PG)*sizeof(uchar*));
89 reg.r[REGPC] = fhdr.entry;
97 extern Machdata armmach;
100 if (!crackhdr(fd, &fhdr))
101 fatal(0, "read text header");
103 if(fhdr.type != FARM )
104 fatal(0, "bad magic number: %d %d", fhdr.type, FARM);
106 if (syminit(fd, &fhdr) < 0)
109 symmap = loadmap(symmap, fd, &fhdr);
110 if (mach->sbreg && lookup(0, mach->sbreg, &s))
122 memset(®, 0, sizeof(Registers));
124 for(i = 0; i > Nseg; i++) {
126 l = ((s->end-s->base)/BY2PG)*sizeof(uchar*);
127 for(m = 0; m < l; m++)
133 memset(&memory, 0, sizeof(memory));
135 for(b = bplist; b; b = b->next)
140 initstk(int argc, char *argv[])
148 tos = STACKTOP - sizeof(Tos)*2; /* we'll assume twice the host's is big enough */
150 for (i = 0; i < sizeof(Tos)*2; i++)
151 putmem_b(tos + i, 0);
154 * pid is second word from end of tos and needs to be set for nsec().
155 * we know arm is a 32-bit cpu, so we'll assume knowledge of the Tos
156 * struct for now, and use our pid.
158 putmem_w(tos + 4*4 + 2*sizeof(ulong) + 3*sizeof(uvlong), getpid());
160 /* Build exec stack */
161 size = strlen(file)+1+BY2WD+BY2WD+BY2WD;
162 for(i = 0; i < argc; i++)
163 size += strlen(argv[i])+BY2WD+1;
169 reg.r[1] = STACKTOP-4; /* Plan 9 profiling clock (why & why in R1?) */
172 putmem_w(sp, argc+1);
175 /* Compute sizeof(argv) and push argv[0] */
176 ap = sp+((argc+1)*BY2WD)+BY2WD;
180 /* Build argv[0] string into stack */
181 for(p = file; *p; p++)
184 putmem_b(ap++, '\0');
186 /* Loop through pushing the arguments */
187 for(i = 0; i < argc; i++) {
190 for(p = argv[i]; *p; p++)
192 putmem_b(ap++, '\0');
194 /* Null terminate argv */
200 fatal(int syserr, char *fmt, ...)
202 char buf[ERRMAX], *s;
206 vseprint(buf, buf+sizeof(buf), fmt, arg);
216 itrace(char *fmt, ...)
222 vseprint(buf, buf+sizeof(buf), fmt, arg);
224 Bprint(bioout, "%8lux %.8lux %2d %s\n", reg.ar, reg.ir, reg.class, buf);
232 Bprint(bioout, "PC #%-8lux SP #%-8lux \n",
233 reg.r[REGPC], reg.r[REGSP]);
235 for(i = 0; i < 16; i++) {
236 if((i%4) == 0 && i != 0)
237 Bprint(bioout, "\n");
238 Bprint(bioout, "R%-2d #%-8lux ", i, reg.r[i]);
240 Bprint(bioout, "\n");
260 fatal(0, "no memory");
267 erealloc(void *a, ulong oldsize, ulong size)
273 fatal(0, "no memory");