Pristine Ack-5.5
[Ack-5.5.git] / mach / pdp / cg / mach.c
1 #ifndef NORCSID
2 static char rcsid[] = "$Id: mach.c,v 2.18 1994/06/24 13:11:41 ceriel Exp $";
3 #endif
4
5 /*
6  * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
7  * See the copyright notice in the ACK home directory, in the file "Copyright".
8  *
9  * Author: Hans van Staveren
10  */
11
12 /*
13  * machine dependent back end routines for the PDP-11
14  */
15
16 /* #define REGPATCH             /* save all registers in markblock */
17
18 con_part(sz,w) register sz; word w; {
19
20         while (part_size % sz)
21                 part_size++;
22         if (part_size == TEM_WSIZE)
23                 part_flush();
24         if (sz == 1) {
25                 w &= 0xFF;
26                 if (part_size)
27                         w <<= 8;
28                 part_word |= w;
29         } else {
30                 assert(sz == 2);
31                 part_word = w;
32         }
33         part_size += sz;
34 }
35
36 con_mult(sz) word sz; {
37         long l, atol();
38
39         if (sz != 4)
40                 fatal("bad icon/ucon size");
41         l = atol(str);
42 #ifdef ACK_ASS
43         fprintf(codefile,".data2 0%o, 0%o !%s\n",(int)(l>>16),(int)l, str);
44 #else
45         fprintf(codefile,"\t%o;%o\n",(int)(l>>16),(int)l);
46 #endif
47 }
48
49 #define PDPFLOAT
50 #define FL_MSL_AT_LOW_ADDRESS   1
51 #define FL_MSW_AT_LOW_ADDRESS   1
52 #define FL_MSB_AT_LOW_ADDRESS   0
53 #define CODE_GENERATOR
54 #include <con_float>
55
56 #ifdef REGVARS
57
58 char Rstring[10];
59 full lbytes;
60 struct regadm {
61         char *ra_str;
62         long  ra_off;
63 } regadm[2];
64 int n_regvars;
65
66 regscore(off,size,typ,score,totyp) long off; {
67
68         if (size != 2)
69                 return(-1);
70         score -= 1;     /* allow for save/restore */
71         if (off>=0)
72                 score -= 2;
73         if (typ==reg_pointer)
74                 score *= 17;
75         else if (typ==reg_loop)
76                 score = 10*score+50;    /* Guestimate */
77         else
78                 score *= 10;
79         return(score);  /* estimated # of words of profit */
80 }
81
82 i_regsave() {
83
84         Rstring[0] = 0;
85         n_regvars=0;
86 }
87
88 f_regsave() {
89         register i;
90
91         if (n_regvars==0 || lbytes==0) {
92 #ifdef REGPATCH
93                 fprintf(codefile,"mov r2,-(sp)\nmov r4,-(sp)\n");
94 #endif
95                 fprintf(codefile,"mov r5,-(sp)\nmov sp,r5\n");
96                 if (lbytes == 2)
97                         fprintf(codefile,"tst -(sp)\n");
98                 else if (lbytes!=0)
99                         fprintf(codefile,"sub $0%o,sp\n",lbytes);
100                 for (i=0;i<n_regvars;i++)
101                         fprintf(codefile,"mov %s,-(sp)\n",regadm[i].ra_str);
102         } else {
103                 if (lbytes>6) {
104                         fprintf(codefile,"mov $0%o,r0\n",lbytes);
105                         fprintf(codefile,"jsr r5,PR%s\n",Rstring);
106                 } else {
107                         fprintf(codefile,"jsr r5,PR%d%s\n",lbytes,Rstring);
108                 }
109         }
110         for (i=0;i<n_regvars;i++)
111                 if (regadm[i].ra_off>=0)
112                         fprintf(codefile,"mov 0%lo(r5),%s\n",regadm[i].ra_off,
113                                                 regadm[i].ra_str);
114 }
115
116 regsave(regstr,off,size) char *regstr; long off; {
117
118         fprintf(codefile,"%c Local %ld into %s\n",COMMENTCHAR,off,regstr);
119 /* commented away 
120 #ifndef REGPATCH
121         fprintf(codefile,"mov %s,-(sp)\n",regstr);
122 #endif
123         strcat(Rstring,regstr);
124         if (off>=0)
125                 fprintf(codefile,"mov 0%lo(r5),%s\n",off,regstr);
126 end of commented away */
127
128         strcat(Rstring,regstr);
129         regadm[n_regvars].ra_str = regstr;
130         regadm[n_regvars].ra_off = off;
131         n_regvars++;
132 }
133
134 regreturn() {
135
136 #ifdef REGPATCH
137         fprintf(codefile,"jmp eret\n");
138 #else
139         fprintf(codefile,"jmp RT%s\n",Rstring);
140 #endif
141 }
142
143 #endif
144
145 prolog(nlocals) full nlocals; {
146
147 #ifndef REGVARS
148 #ifdef REGPATCH
149         fprintf(codefile,"mov r2,-(sp)\nmov r4,-(sp)\n");
150 #endif
151         fprintf(codefile,"mov r5,-(sp)\nmov sp,r5\n");
152         if (nlocals == 0)
153                 return;
154         if (nlocals == 2)
155                 fprintf(codefile,"tst -(sp)\n");
156         else
157                 fprintf(codefile,"sub $0%o,sp\n",nlocals);
158 #else
159         lbytes = nlocals;
160 #endif
161 }
162
163 dlbdlb(as,ls) string as,ls; {
164
165         if (strlen(as)+strlen(ls)+2<sizeof(labstr)) {
166                 strcat(ls,":");
167                 strcat(ls,as);
168         } else
169                 fatal("too many consecutive labels");
170 }
171
172 mes(type) word type; {
173         int argt ;
174
175         switch ( (int)type ) {
176         case ms_ext :
177                 for (;;) {
178                         switch ( argt=getarg(
179                             ptyp(sp_cend)|ptyp(sp_pnam)|sym_ptyp) ) {
180                         case sp_cend :
181                                 return ;
182                         default:
183                                 strarg(argt) ;
184 #ifdef ACK_ASS
185                                 fprintf(codefile,".define %s\n",argstr) ;
186 #else
187                                 fprintf(codefile,".globl %s\n",argstr) ;
188 #endif
189                                 break ;
190                         }
191                 }
192         default :
193                 while ( getarg(any_ptyp) != sp_cend ) ;
194                 break ;
195         }
196 }
197
198 char    *segname[] = {
199 #ifdef ACK_ASS
200         ".sect .text",        /* SEGTXT */
201         ".sect .data",        /* SEGCON */
202         ".sect .rom",         /* SEGROM */
203         ".sect .bss"          /* SEGBSS */
204 #else
205         ".text",        /* SEGTXT */
206         ".data",        /* SEGCON */
207         ".data",        /* SEGROM */
208         ".bss"          /* SEGBSS */
209 #endif
210 };