2 static char rcsid2[] = "$Id: fillem.c,v 0.19 1994/06/24 13:27:20 ceriel Exp $";
26 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
27 * See the copyright notice in the ACK home directory, in the file "Copyright".
29 * Author: Hans van Staveren
32 #ifndef newplb /* retrofit for older mach.h */
38 It is an error to define both fmt_id and id_first.
39 Read the documentation.
45 It is an error to define both fmt_ilb and ilb_fmt.
46 Read the documentation.
50 /* segment types for switchseg() */
58 #define get8() getc(emfile)
61 extern FILE *codefile;
62 extern FILE *freopen();
64 int nextispseu,savetab1;
69 char *str,argstr[128],labstr[128];
70 unsigned int maxstrsiz;
81 extern char em_flag[];
82 extern short em_ptyp[];
85 /* Own version of atol that continues computing on overflow.
86 We don't know that about the ANSI C one.
91 register long total = 0;
92 register unsigned digit;
95 while (*s == ' ' || *s == '\t') s++;
101 while ((digit = *s++ - '0') < 10) {
105 return(minus ? -total : total);
109 #define sp_cstx sp_cst2
118 in_init(filename) char *filename; {
121 if (filename && (emfile=freopen(filename,"r",stdin))==NULL)
122 error("Can't open %s",filename);
123 if (get16()!=sp_magic)
124 error("Bad format %s",filename ? filename : "standard-input");
125 str = myalloc(maxstrsiz=256);
130 fprintf(codefile,"%s",modhead) ;
139 register struct emline *lp;
141 while ((emlines+nemlines)-emp<MAXEMLINES-5) {
142 assert(nemlines<MAXEMLINES);
144 emlines[nemlines].em_instr=0;
147 lp = &emlines[nemlines++];
151 error("unknown instruction byte");
155 lp->em_instr = op_lab;
156 lp->em_optyp = OPSYMBOL;
157 lp->em_soper = strarg(t);
158 lp->em_u.em_loper = argval;
165 nextispseu=1; savetab1=t;
170 nextispseu=1; savetab1=t;
175 lp->em_instr = opcode;
178 i=em_flag[lp->em_instr-sp_fmnem] & EM_PAR;
188 assert(t == sp_cstx);
191 lp->em_optyp = OPINT;
192 lp->em_u.em_ioper = argval;
193 lp->em_soper = tostring((word) argval);
198 lp->em_optyp = OPSYMBOL;
199 lp->em_soper = holstr((word) argval);
204 lp->em_optyp = OPSYMBOL;
205 lp->em_u.em_loper = argval;
206 lp->em_soper = strarg(t);
210 assert(t == sp_cstx);
211 lp->em_optyp = OPSYMBOL;
212 lp->em_soper = strarg(t);
213 lp->em_u.em_loper = argval;
216 lp->em_soper = strarg(t);
219 else if (t==sp_cstx) {
220 lp->em_optyp = OPINT;
221 lp->em_u.em_ioper = argval;
223 lp->em_optyp = OPSYMBOL;
231 word romcont[MAXROM+1];
234 unsigned stackupto();
236 if (nextispseu==0 || nemlines>0)
237 error("No table entry for %d",emlines[0].em_instr);
244 /* dummy = */stackupto(&fakestack[stackheight-1],maxply,TRUE);
249 { extern int Debug; extern char * strtdebug;
250 if (strcmp(strtdebug,argstr)==0)
251 Debug = strtdebug[-2]-'0';
272 error("Unknown opcode %d",savetab1);
276 sprintf(labstr,hol_fmt,++holno);
280 t = getarg(val_ptyp);
290 con(getarg(val_ptyp));
291 while ((t = getarg(any_ptyp)) != sp_cend)
303 if (t==sp_cstx && nromwords<MAXROM) {
304 romcont[nromwords] = (word) argval;
315 if (c == ps_rom) continue;
316 if (c != EOF) ungetc(c, emfile);
320 if (nromwords != 0) {
321 romcont[MAXROM]=rommask;
322 enterglo(labstr,romcont);
327 getarg(ptyp(sp_cst2));
328 if (argval == ms_emx) {
329 getarg(ptyp(sp_cst2));
330 if (argval != TEM_WSIZE)
331 fatal("bad word size");
332 getarg(ptyp(sp_cst2));
333 if (argval != TEM_PSIZE)
334 fatal("bad pointer size");
335 if ( getarg(any_ptyp)!=sp_cend )
336 fatal("too many parameters");
338 } else if (argval == ms_tes) {
339 int lbl, size, flthr;
340 getarg(ptyp(sp_cst2)); lbl = argval;
341 getarg(ptyp(sp_cst2)); size = argval;
342 getarg(ptyp(sp_cst2)); flthr = argval;
343 if ( getarg(any_ptyp)!=sp_cend )
344 fatal("too many parameters");
345 add_label(lbl,size, flthr);
348 } else if (argval == ms_gto) {
349 getarg(ptyp(sp_cend));
351 error("mes 3 not allowed here");
354 } else if (argval == ms_reg) {
356 int r_size,r_type,r_score;
357 struct regvar *linkreg();
360 error("mes 3 not allowed here");
361 if(getarg(ptyp(sp_cst2)|ptyp(sp_cend)) == sp_cend) {
368 getarg(ptyp(sp_cst2));
370 getarg(ptyp(sp_cst2));
372 if (r_type<reg_any || r_type>reg_float)
373 fatal("Bad type in register message");
374 if(getarg(ptyp(sp_cst2)|ptyp(sp_cend)) == sp_cend)
378 if ( getarg(any_ptyp)!=sp_cend )
379 fatal("too many parameters");
381 tryreg(linkreg(r_off,r_size,r_type,r_score),r_type);
388 strarg(getarg(sym_ptyp));
392 strarg(getarg(sym_ptyp));
396 strarg(getarg(ptyp(sp_pnam)));
400 strarg(getarg(ptyp(sp_pnam)));
406 strarg(getarg(ptyp(sp_pnam)));
409 prolog((full)argval);
415 getarg(cst_ptyp | ptyp(sp_cend));
426 error("No table entry for %d",savetab1);
430 /* ----- input ----- */
435 argtyp = t = table2();
437 fatal("unexpected EOF");
440 if ((typset & t) == 0)
441 error("bad argument type %d",argtyp);
449 if (i < sp_fmnem+sp_nmnem && i >= sp_fmnem) {
453 if (i < sp_fpseu+sp_npseu && i >= sp_fpseu) {
457 if (i < sp_filb0+sp_nilb0 && i >= sp_filb0) {
458 argval = i - sp_filb0;
468 if (i < sp_fcst0+sp_ncst0 && i >= sp_fcst0) {
469 argval = i - sp_zcst0;
503 offtyp = getarg(sym_ptyp);
510 consiz = (word) argval;
519 register int l_byte, h_byte;
523 if ( h_byte>=128 ) h_byte -= 256 ;
524 return l_byte | (h_byte*256) ;
532 l |= ((unsigned) get8())*256 ;
533 l |= get8()*256L*256L ;
535 if ( h_byte>=128 ) h_byte -= 256 ;
536 return l | (h_byte*256L*256*256L) ;
545 fatal("string/identifier too long");
546 if (argval >= maxstrsiz) {
548 str = myalloc((unsigned) argval + 1);
549 maxstrsiz = argval + 1;
551 strsiz = n = (int) argval;
565 fmt_ilb(procno,((int) argval),argstr);
567 sprintf(argstr,ilb_fmt,procno,(int)argval);
572 sprintf(argstr,dlb_fmt,dlbval);
575 sprintf(argstr,cst_fmt,(full)argval);
583 if (strsiz < 8 || str[0] == id_first)
585 sprintf(p,"%.*s",strsiz,str);
590 for (p = argstr; *p; p++)
592 if ((full) argval >= 0)
596 argval = - (full) argval;
598 sprintf(p,off_fmt,(full)argval);
603 return(mystrcpy(argstr));
610 fatal("bad BSS size");
613 || (t==sp_cstx && argval==BSS_INIT)
614 #endif /* BSS_INIT */
626 fatal("bad BSS initializer");
639 return((long)TEM_PSIZE);
646 return((long)TEM_PSIZE);
648 con_part(TEM_WSIZE,(word)argval);
649 return((long)TEM_WSIZE);
651 for (i = 0; i < strsiz; i++)
652 con_part(1,(word) str[i]);
653 return((long)strsiz);
656 if (argval > TEM_WSIZE) {
658 con_mult((word)argval);
660 con_part((int)argval,(word)atol(str));
672 extern char *segname[];
683 if ((curseg = s) >= 0)
684 fprintf(codefile,"%s\n",segname[s]);
692 dlbdlb(argstr,labstr);
705 assert(part_size == 0);
714 assert(part_size == 0);
721 * Each new data fragment and each data label starts at
722 * a new target machine word
731 string holstr(n) word n; {
733 sprintf(str,hol_off,n,holno);
734 return(mystrcpy(str));
738 /* ----- machine dependent routines ----- */