4 static char rcsid[] = "$Id: mach.c,v 1.9 1994/06/24 13:41:44 ceriel Exp $";
7 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
8 * See the copyright notice in the ACK home directory, in the file "Copyright".
13 * Machine dependent back end routines for the VAX using 4-byte words
17 * Byte order: | 3 | 2 | 1 | 0 |
24 * Align new bytes on boundary of its on size.
26 while (part_size % sz) part_size++;
28 if (part_size == TEM_WSIZE)
30 if (sz == 1 || sz == 2) {
31 /* Smaller than a machineword. */
32 w &= (sz == 1 ? 0xFF : 0xFFFF);
46 fatal("bad icon/ucon size");
47 fprintf(codefile,".data4\t%s\n",str);
51 static int gdb_flag = 0;
56 if (! strcmp(s, "-gdb")) {
60 error("Unknown flag %s", s);
63 #endif /* MACH_OPTIONS */
70 switch ( (int)mesno ) {
74 ptyp(sp_cend)|ptyp(sp_pnam)|sym_ptyp) ) {
79 fprintf(codefile,".define %s\n",argstr) ;
84 argt = getarg(str_ptyp | cst_ptyp);
86 fputs(".symb \"\", ", codefile);
88 fprintf(codefile, ".symb \"%s\", ", str);
89 argt = getarg(cst_ptyp);
92 argt = getarg(cst_ptyp);
94 argt = getarg(cst_ptyp|nof_ptyp|sof_ptyp|ilb_ptyp|pro_ptyp);
98 /* Change offset from AB into offset from
99 the frame pointer (ab).
105 fprintf(codefile, "%s, 0x%x, %d\n", strarg(argt), a1, a2);
106 argt = getarg(end_ptyp);
109 argt = getarg(str_ptyp | cst_ptyp);
113 argt = getarg(cst_ptyp);
116 if (argval == N_SLINE
121 fputs("calls $0,___u_LiB\n", codefile);
122 cleanregs(); /* debugger might change variables */
124 fprintf(codefile, ".symd \"%s\", 0x%x,", str, (int) argval);
125 argt = getarg(cst_ptyp);
126 fprintf(codefile, "%d\n", (int) argval);
127 argt = getarg(end_ptyp);
130 while ( getarg(any_ptyp) != sp_cend ) ;
136 #define CODE_GENERATOR
143 fprintf(codefile,".data2 00\n");
147 fprintf(codefile,"\tclrl\t-(sp)\n");
148 else if (nlocals == 8)
149 fprintf(codefile,"\tclrq\t-(sp)\n");
151 fprintf(codefile,"\tsubl2\t$%ld,sp\n",nlocals);
154 #endif /* not REGVARS */
157 ".sect .text", /* SEGTXT */
158 ".sect .data", /* SEGCON */
159 ".sect .rom", /* SEGROM */
160 ".sect .bss" /* SEGBSS */
164 static full nlocals; /* Number of local variables. */
166 #define NR_REG 8 /* Number of registers. */
168 #define LAST_REG (FIRST_REG + NR_REG - 1)
171 * Save number of locals.
179 * Structure to store information about the registers to be stored.
181 static struct s_reg {
182 char *sr_str; /* Name of register used. */
183 long sr_off; /* Offset from LB. */
184 int sr_size; /* Size in bytes. */
185 } a_reg[NR_REG + 1], *p_reg;
188 * Initialize saving of registers.
196 * Called for each register to be saved.
197 * Save the parameters in the struct.
199 regsave(str, off, size)
206 (p_reg++)->sr_size = size;
208 "\t! Local %ld, size %d, to register %s\n",
214 * Generate code to save the registers.
218 register struct s_reg *p;
224 count = p_reg - a_reg;
226 * For each register to be saved, set a bit in the
227 * mask corresponding to its number.
229 for (p = a_reg; p < p_reg; p++) {
230 i = atoi(p->sr_str + 1);
239 * Now generate code to save registers.
241 fprintf(codefile, ".data2 0%o\n", mask);
243 * Emit code to initialize parameters in registers.
245 for (p = a_reg; p < p_reg; p++)
248 "mov%c\t%ld(ap), %s\n",
249 p->sr_size == 4 ? 'l' : 'q',
255 * Generate room for locals.
260 fprintf(codefile,"clrl\t-(sp)\n");
261 else if (nlocals == 8)
262 fprintf(codefile,"clrq\t-(sp)\n");
264 fprintf(codefile,"subl2\t$%ld,sp\n",nlocals);
270 regscore(off, size, typ, score, totyp)
272 int size, typ, totyp, score;
274 register int i = score;
277 * If the offset doesn't fit in a byte, word-offset is used,
278 * which is one byte more expensive.
280 if (off > 127 || off < -128) i *= 2;
282 * Compute cost of initialization for parameters.
284 if (off > 127) i -= 5;
285 else if (off >= 0) i -= 4;
287 * Storing a pointer in a register sometimes saves an instruction.
289 if (typ == reg_pointer) i += score;
290 else if (typ == reg_loop) i += 5;
292 * Now adjust for the saving of the register.
293 * But this costs no space at all.