2 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3 * See the copyright notice in the ACK home directory, in the file "Copyright".
8 static char rcs_m[]= "$Id: mach.c,v 1.11 1995/03/17 12:37:06 ceriel Exp $" ;
9 static char rcs_mh[]= ID_MH ;
15 * machine dependent back end routines for the Intel 80386
18 con_part(sz,w) register sz; word w; {
20 while (part_size % sz)
22 if (part_size == TEM_WSIZE)
24 if (sz == 1 || sz == 2) {
25 w &= (sz == 1 ? 0xFF : 0xFFFF);
35 con_mult(sz) word sz; {
39 fatal("bad icon/ucon size");
41 fprintf(codefile,"\t.data4 %ld\n", l);
44 #define CODE_GENERATOR
46 #define FL_MSL_AT_LOW_ADDRESS 0
47 #define FL_MSW_AT_LOW_ADDRESS 0
48 #define FL_MSB_AT_LOW_ADDRESS 0
53 string holstr(n) word n; {
55 sprintf(str,hol_off,n,holno);
56 return(mystrcpy(str));
64 prolog(nlocals) full nlocals; {
66 fputs("push ebp\nmov ebp,esp\n", codefile);
71 probably not better on 386.
74 fputs("push eax\n", codefile);
77 fputs("push eax\n", codefile);
81 fprintf(codefile, "sub\tesp,%ld\n",nlocals);
94 regscore(off, size, typ, score, totyp)
97 if (size != 4) return -1;
100 if (typ == reg_pointer || typ == reg_loop) score += (score >> 2);
101 score -= 2; /* cost of saving */
102 if (off >= 0) score -= 3;
115 if (si_off != di_off) {
116 if (si_off == -lbytes) lbytes -= 4;
117 if (di_off == -lbytes) lbytes -= 4;
118 if (si_off == -lbytes) lbytes -= 4;
120 if (lbytes) fprintf(codefile, "sub\tesp,%ld\n",(long) lbytes);
122 fputs("push edi\n", codefile);
123 if (si_off != -1) fputs("push esi\n", codefile);
125 else if (firstreg == -1) {
126 fputs("push esi\n", codefile);
127 if (di_off != -1) fputs("push edi\n", codefile);
130 fprintf(codefile, "mov esi,%ld(ebp)\n", si_off);
132 fprintf(codefile, "mov edi,%ld(ebp)\n", di_off);
135 regsave(regstr, off, size)
139 if (strcmp(regstr, "esi") == 0) {
140 if (! firstreg) firstreg = -1;
144 if (! firstreg) firstreg = 1;
152 if (si_off != -1) fputs("pop esi\n", codefile);
153 fputs("pop edi\n", codefile);
155 else if (firstreg == -1) {
156 if (di_off != -1) fputs("pop edi\n", codefile);
157 fputs("pop esi\n", codefile);
159 fputs("leave\nret\n", codefile);
164 static int gdb_flag = 0;
165 static char *fp_hook_nam;
170 if (! strcmp(s, "-gdb")) {
173 else if (s[1] == 'F') {
177 error("Unknown flag %s", s);
180 #endif /* MACH_OPTIONS */
182 mes(type) word type ; {
185 switch ( (int)type ) {
188 switch ( argt=getarg(
189 ptyp(sp_cend)|ptyp(sp_pnam)|sym_ptyp) ) {
194 fprintf(codefile, ".define %s\n",argstr) ;
199 argt = getarg(str_ptyp | cst_ptyp);
201 fputs(".symb \"\", ", codefile);
203 fprintf(codefile, ".symb \"%s\", ", str);
204 argt = getarg(cst_ptyp);
207 argt = getarg(cst_ptyp);
209 argt = getarg(cst_ptyp|nof_ptyp|sof_ptyp|ilb_ptyp|pro_ptyp);
213 /* Change offset from AB into offset from
214 the frame pointer (bp).
220 fprintf(codefile, "%s, 0x%x, %d\n", strarg(argt), a1, a2);
221 argt = getarg(end_ptyp);
224 argt = getarg(str_ptyp | cst_ptyp);
228 argt = getarg(cst_ptyp);
231 if (argval == N_SLINE
236 fputs("call ___u_LiB\n", codefile);
237 cleanregs(); /* debugger might change variables */
239 fprintf(codefile, ".symd \"%s\", 0x%x,", str, (int) argval);
240 argt = getarg(cst_ptyp);
241 fprintf(codefile, "%d\n", (int) argval);
242 argt = getarg(end_ptyp);
253 while ( getarg(any_ptyp) != sp_cend ) ;
259 ".sect .text", /* SEGTXT */
260 ".sect .data", /* SEGCON */
261 ".sect .rom", /* SEGROM */
262 ".sect .bss" /* SEGBSS */