Pristine Ack-5.5
[Ack-5.5.git] / mach / i86 / ncg / mach.c
1 /*
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".
4  *
5  */
6
7 #ifndef NORCSID
8 static char rcs_m[]= "$Id: mach.c,v 1.10 1994/06/24 13:00:02 ceriel Exp $" ;
9 static char rcs_mh[]= ID_MH ;
10 #endif
11
12 /*
13  * machine dependent back end routines for the Intel 8086
14  */
15
16 con_part(sz,w) register sz; word w; {
17
18         while (part_size % sz)
19                 part_size++;
20         if (part_size == TEM_WSIZE)
21                 part_flush();
22         if (sz == 1) {
23                 w &= 0xFF;
24                 if (part_size)
25                         w <<= 8;
26                 part_word |= w;
27         } else {
28                 assert(sz == 2);
29                 part_word = w;
30         }
31         part_size += sz;
32 }
33
34 con_mult(sz) word sz; {
35         long l;
36
37         if (sz != 4)
38                 fatal("bad icon/ucon size");
39         l = atol(str);
40         fprintf(codefile,"\t.data2 %d,%d\n",
41                         (int)l&0xFFFF,(int)(l>>16)&0xFFFF);
42 }
43
44 #define CODE_GENERATOR 
45 #define IEEEFLOAT 
46 #define FL_MSL_AT_LOW_ADDRESS   0
47 #define FL_MSW_AT_LOW_ADDRESS   0
48 #define FL_MSB_AT_LOW_ADDRESS   0
49 #include <con_float>
50
51 /*
52
53 string holstr(n) word n; {
54
55         sprintf(str,hol_off,n,holno);
56         return(mystrcpy(str));
57 }
58 */
59
60 #ifdef REGVARS
61 full lbytes;
62 #endif
63
64 prolog(nlocals) full nlocals; {
65
66         fputs("\tpush\tbp\n\tmov\tbp,sp\n", codefile);
67 #ifdef REGVARS
68         lbytes = nlocals;
69 #else
70         switch (nlocals) {
71         case 4: fputs("\tpush\tax\n", codefile);
72         case 2: fputs("\tpush\tax\n", codefile);
73         case 0: break;
74         default:
75                 fprintf(codefile, "\tsub\tsp,%d\n",nlocals); break;
76         }
77 #endif
78 }
79
80 #ifdef REGVARS
81 long si_off;
82 long di_off;
83 int firstreg;
84
85 regscore(off, size, typ, score, totyp)
86         long off;
87 {
88         if (size != 2) return -1;
89         score -= 1;
90         score += score;
91         if (typ == reg_pointer || typ == reg_loop) score += (score >> 2);
92         score -= 2;     /* cost of saving */
93         if (off >= 0) score -= 3;
94         return score;
95 }
96
97 i_regsave()
98 {
99         si_off = -1;
100         di_off = -1;
101         firstreg = 0;
102 }
103
104 f_regsave()
105 {
106         if (si_off != di_off) {
107                 if (di_off == -lbytes) lbytes -= 2;
108                 if (si_off == -lbytes) lbytes -= 2;
109                 if (di_off == -lbytes) lbytes -= 2;
110         }
111         switch (lbytes) {
112         case 4: fputs("\tpush\tax\n", codefile);
113         case 2: fputs("\tpush\tax\n", codefile);
114         case 0: break;
115         default:
116                 fprintf(codefile, "\tsub\tsp,%d\n",lbytes); break;
117         }
118         if (firstreg == 1) {
119                 fputs("push di\n", codefile);
120                 if (si_off != -1) fputs("push si\n", codefile);
121         }
122         else if (firstreg == -1) {
123                 fputs("push si\n", codefile);
124                 if (di_off != -1) fputs("push di\n", codefile);
125         }
126         if (di_off >= 0)
127                 fprintf(codefile, "mov di,%ld(bp)\n", di_off);
128         if (si_off >= 0)
129                 fprintf(codefile, "mov si,%ld(bp)\n", si_off);
130 }
131
132 regsave(regstr, off, size)
133         char *regstr;
134         long off;
135 {
136         if (strcmp(regstr, "si") == 0) {
137                 if (! firstreg) firstreg = -1;
138                 si_off = off;
139         }
140         else {
141                 if (! firstreg) firstreg = 1;
142                 di_off = off;
143         }
144 }
145
146 regreturn()
147 {
148         if (firstreg == 1) {
149                 if (si_off != -1) fputs("jmp .sdret\n", codefile);
150                 else fputs("jmp .dret\n", codefile);
151         }
152         else if (firstreg == -1) {
153                 if (di_off != -1) fputs("jmp .dsret\n", codefile);
154                 else fputs("jmp .sret\n", codefile);
155         }
156         else fputs("jmp .cret\n", codefile);
157 }
158 #endif /* REGVARS */
159
160 mes(type) word type ; {
161         int argt ;
162
163         switch ( (int)type ) {
164         case ms_ext :
165                 for (;;) {
166                         switch ( argt=getarg(
167                             ptyp(sp_cend)|ptyp(sp_pnam)|sym_ptyp) ) {
168                         case sp_cend :
169                                 return ;
170                         default:
171                                 strarg(argt) ;
172                                 fprintf(codefile, ".define %s\n",argstr) ;
173                                 break ;
174                         }
175                 }
176         default :
177                 while ( getarg(any_ptyp) != sp_cend ) ;
178                 break ;
179         }
180 }
181
182 char    *segname[] = {
183         ".sect .text",        /* SEGTXT */
184         ".sect .data",        /* SEGCON */
185         ".sect .rom",        /* SEGROM */
186         ".sect .bss"          /* SEGBSS */
187 };