1 /* $Id: mach.c,v 1.32 1994/06/24 13:07:10 ceriel Exp $ */
3 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
4 * See the copyright notice in the ACK home directory, in the file "Copyright".
9 * machine dependent back end routines for the Motorola 68000, 68010 or 68020
15 #define SYNTAX_68020 1
20 con_part(sz,w) register sz; word w; {
22 while (part_size % sz)
24 if (part_size == TEM_WSIZE)
29 w <<= 8*(3-part_size);
35 /* Shift 8 for m68k2, 16 otherwise */
40 assert(sz == TEM_WSIZE);
46 con_mult(sz) word sz; {
49 fatal("bad icon/ucon size");
50 fprintf(codefile,".data4 %s\n",str);
54 #define CODE_GENERATOR
55 #define FL_MSL_AT_LOW_ADDRESS 1
56 #define FL_MSW_AT_LOW_ADDRESS 1
57 #define FL_MSB_AT_LOW_ADDRESS 1
60 regscore(off,size,typ,score,totyp)
63 if (score == 0) return -1;
68 if (size != 4 || totyp != reg_pointer) return -1;
69 score += (score >> 1);
75 if (size != TEM_WSIZE || totyp == reg_pointer) return -1;
79 /* parameters must be initialised with an instruction
80 * like "move.l 4(a6),d0", which costs 2 words.
84 score--; /* save/restore */
88 char *rs_reg; /* e.g. "a3" or "d5" */
89 long rs_off; /* offset of variable */
90 int rs_size; /* 2 or 4 bytes */
105 register struct regsav_t *p;
109 fprintf(codefile,"movem.l (-%ld,a6),", nlocals);
111 fprintf(codefile,"movem.l -%ld(a6),", nlocals);
113 for (p = regsav; ;) {
114 fputs(p->rs_reg, codefile);
115 if (++p == ®sav[regnr]) break;
119 } else if (regnr == 1) {
122 fprintf(codefile,"move.l (-%ld,a6),%s\n",nlocals, p->rs_reg);
124 fprintf(codefile,"move.l -%ld(a6),%s\n",nlocals, p->rs_reg);
127 fputs("unlk a6\nrts\n", codefile);
132 register struct regsav_t *p;
136 fprintf(codefile,"link\ta6,#-%ld\n",nlocals);
138 if (nlocals > 32768) {
139 fprintf(codefile, "move.l a6,-(sp)\nmove.l sp,a6\nsub #%ld,sp\n", nlocals);
141 else fprintf(codefile,"link\ta6,#-%ld\n",nlocals);
144 fprintf(codefile, "tst.b %s\n",
153 fputs("movem.l ", codefile);
154 for (p = regsav; ;) {
155 fputs(p->rs_reg, codefile);
156 if (++p == ®sav[regnr]) break;
159 fputs(",(sp)\n", codefile);
160 } else if (regnr == 1) {
162 fprintf(codefile,"move.l %s,(sp)\n",p->rs_reg);
164 /* initialise register-parameters */
165 for (p = regsav; p < ®sav[regnr]; p++) {
166 if (p->rs_off >= 0) {
168 fprintf(codefile,"move.%c (%ld,a6),%s\n",
170 fprintf(codefile,"move.%c %ld(a6),%s\n",
172 (p->rs_size == 4 ? 'l' : 'w'),
184 regsav[regnr].rs_reg = s;
185 regsav[regnr].rs_off = off;
186 regsav[regnr++].rs_size = size;
187 fprintf(codefile, "!Local %ld into %s\n",off,s);
196 static int gdb_flag = 0;
201 if (! strcmp(s, "-gdb")) {
205 error("Unknown flag %s", s);
208 #endif /* MACH_OPTIONS */
210 mes(type) word type ; {
213 switch ( (int)type ) {
216 switch ( argt=getarg(
217 ptyp(sp_cend)|ptyp(sp_pnam)|sym_ptyp) ) {
222 fprintf(codefile,".define %s\n",argstr) ;
227 argt = getarg(str_ptyp | cst_ptyp);
229 fputs(".symb \"\", ", codefile);
231 fprintf(codefile, ".symb \"%s\", ", str);
232 argt = getarg(cst_ptyp);
235 argt = getarg(cst_ptyp);
237 argt = getarg(cst_ptyp|nof_ptyp|sof_ptyp|ilb_ptyp|pro_ptyp);
241 /* Change offset from AB into offset from
248 fprintf(codefile, "%s, 0x%x, %d\n", strarg(argt), a1, a2);
249 argt = getarg(end_ptyp);
252 argt = getarg(str_ptyp | cst_ptyp);
256 argt = getarg(cst_ptyp);
259 if (argval == N_SLINE
265 fputs("jsr (___u_LiB)\n", codefile);
267 fputs("jsr ___u_LiB\n", codefile);
269 cleanregs(); /* debugger might change variables */
271 fprintf(codefile, ".symd \"%s\", 0x%x,", str, (int) argval);
272 argt = getarg(cst_ptyp);
273 fprintf(codefile, "%d\n", (int) argval);
274 argt = getarg(end_ptyp);
277 while ( getarg(any_ptyp) != sp_cend ) ;
284 ".sect .text", /* SEGTXT */
285 ".sect .data", /* SEGCON */
286 ".sect .rom", /* SEGROM */
287 ".sect .bss" /* SEGBSS */