Debian Codegraph @

arch/sparc64/code.c

raw symbols SCIP
1 /* $Id: code.c,v 1.23 2015/07/24 07:57:01 ragge Exp $ */
2
3 /*
4 * Copyright (c) 2008 David Crawshaw <[email protected]>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #include "pass1.h"
20
21 /*
22 * Print out assembler segment name.
23 */
24 void
25 setseg(int seg, char *name)
26 {
27 switch (seg) {
28 case PROG: name = ".text"; break;
29 case DATA:
30 case LDATA: name = ".data"; break;
31 case STRNG:
32 case RDATA: name = ".section .rodata"; break;
33 case UDATA: break;
34 case PICLDATA:
35 case PICDATA:
36 case PICRDATA:
37 case TLSDATA:
38 case TLSUDATA:
39 case CTORS:
40 case DTORS:
41 uerror("FIXME: unknown section");
42 case NMSEG:
43 printf("\t.section %s,\"a%c\",@progbits\n", name,
44 cftnsp ? 'x' : 'w');
45 return;
46 }
47 printf("\t%s\n", name);
48 }
49
50
51 void
52 defloc(struct symtab *sp)
53 {
54 TWORD t;
55 char *name;
56
57 t = sp->stype;
58
59 if ((name = sp->soname) == NULL)
60 name = exname(sp->sname);
61
62 if (!ISFTN(t)) {
63 printf("\t.type %s,#object\n", name);
64 printf("\t.size %s," CONFMT "\n", name,
65 tsize(sp->stype, sp->sdf, sp->sap) / SZCHAR);
66 }
67 if (sp->sclass == EXTDEF)
68 printf("\t.global %s\n", name);
69 if (sp->slevel == 0) {
70 printf("%s:\n", name);
71 } else
72 printf(LABFMT ":\n", sp->soffset);
73 }
74
75 void
76 efcode(void)
77 {
78 /* XXX */
79 }
80
81 void
82 bfcode(struct symtab **sp, int cnt)
83 {
84 int i, off;
85 NODE *p, *q;
86 struct symtab *sym;
87
88 /* Process the first six arguments. */
89 for (i=0; i < cnt && i < 6; i++) {
90 sym = sp[i];
91 q = block(REG, NIL, NIL, sym->stype, sym->sdf, sym->sap);
92 q->n_rval = RETREG_PRE(sym->stype) + i;
93 p = tempnode(0, sym->stype, sym->sdf, sym->sap);
94 sym->soffset = regno(p);
95 sym->sflags |= STNODE;
96 p = buildtree(ASSIGN, p, q);
97 ecomp(p);
98 }
99
100 /* Process the remaining arguments. */
101 for (off = V9RESERVE; i < cnt; i++) {
102 sym = sp[i];
103 p = tempnode(0, sym->stype, sym->sdf, sym->sap);
104 off = ALIGN(off, (tlen(p) - 1));
105 sym->soffset = off * SZCHAR;
106 off += tlen(p);
107 p = buildtree(ASSIGN, p, nametree(sym));
108 sym->soffset = regno(p->n_left);
109 sym->sflags |= STNODE;
110 ecomp(p);
111 }
112 }
113
114 void
115 ejobcode(int flag)
116 {
117 }
118
119 void
120 bjobcode(void)
121 {
122 astypnames[USHORT] = astypnames[SHORT] = "\t.half";
123 astypnames[INT] = astypnames[UNSIGNED] = "\t.long";
124 astypnames[LONG] = astypnames[ULONG] =
125 astypnames[LONGLONG] = astypnames[ULONGLONG] = "\t.xword";
126 }
127
128 /*
129 * The first six 64-bit arguments are saved in the registers O0 to O5,
130 * which become I0 to I5 after the "save" instruction moves the register
131 * window. Arguments 7 and up must be saved on the stack to %sp+BIAS+176.
132 *
133 * For a pretty picture, see Figure 3-16 in the SPARC Compliance Def 2.4.
134 */
135 static NODE *
136 moveargs(NODE *p, int *regp, int *stacksize)
137 {
138 NODE *r, *q;
139
140 if (p->n_op == CM) {
141 p->n_left = moveargs(p->n_left, regp, stacksize);
142 r = p->n_right;
143 } else {
144 r = p;
145 }
146
147 /* XXX more than six FP args can and should be passed in registers. */
148 if (*regp > 5 && r->n_op != STARG) {
149 /* We are storing the stack offset in n_rval. */
150 r = block(FUNARG, r, NIL, r->n_type, r->n_df, r->n_ap);
151 /* Make sure we are appropriately aligned. */
152 *stacksize = ALIGN(*stacksize, (tlen(r) - 1));
153 r->n_rval = *stacksize;
154 *stacksize += tlen(r);
155 } else if (r->n_op == STARG)
156 cerror("op STARG in moveargs");
157 else {
158 q = block(REG, NIL, NIL, r->n_type, r->n_df, r->n_ap);
159
160 /*
161 * The first six non-FP arguments go in the registers O0 - O5.
162 * Float arguments are stored in %fp1, %fp3, ..., %fp29, %fp31.
163 * Double arguments are stored in %fp0, %fp2, ..., %fp28, %fp30.
164 * A non-fp argument still increments register, eg.
165 * test(int a, int b, float b)
166 * takes %o0, %o1, %fp5.
167 */
168 if (q->n_type == FLOAT)
169 q->n_rval = F0 + (*regp++ * 2) + 1;
170 else if (q->n_type == DOUBLE)
171 q->n_rval = D0 + *regp++;
172 else if (q->n_type == LDOUBLE)
173 cerror("long double support incomplete");
174 else
175 q->n_rval = O0 + (*regp)++;
176
177 r = buildtree(ASSIGN, q, r);
178 }
179
180 if (p->n_op == CM) {
181 p->n_right = r;
182 return p;
183 }
184
185 return r;
186 }
187
188 NODE *
189 funcode(NODE *p)
190 {
191 NODE *r, *l;
192 int reg = 0, stacksize = 0;
193
194 r = l = 0;
195
196 p->n_right = moveargs(p->n_right, &reg, &stacksize);
197
198 /*
199 * This is a particularly gross and inefficient way to handle
200 * argument overflows. First, we calculate how much stack space
201 * we need in moveargs(). Then we assign it by moving %sp, make
202 * the function call, and then move %sp back.
203 *
204 * What we should be doing is getting the maximum of all the needed
205 * stacksize values to the prologue and doing it all in the "save"
206 * instruction.
207 */
208 if (stacksize != 0) {
209 stacksize = V9STEP(stacksize); /* 16-bit alignment. */
210
211 r = block(REG, NIL, NIL, INT, 0, 0);
212 r->n_lval = 0;
213 r->n_rval = SP;
214 r = block(MINUS, r, bcon(stacksize), INT, 0, 0);
215
216 l = block(REG, NIL, NIL, INT, 0, 0);
217 l->n_lval = 0;
218 l->n_rval = SP;
219 r = buildtree(ASSIGN, l, r);
220
221 p = buildtree(COMOP, r, p);
222
223 r = block(REG, NIL, NIL, INT, 0, 0);
224 r->n_lval = 0;
225 r->n_rval = SP;
226 r = block(PLUS, r, bcon(stacksize), INT, 0, 0);
227
228 l = block(REG, NIL, NIL, INT, 0, 0);
229 l->n_lval = 0;
230 l->n_rval = SP;
231 r = buildtree(ASSIGN, l, r);
232
233 p = buildtree(COMOP, p, r);
234
235 }
236 return p;
237 }
238
239 void
240 fldty(struct symtab *p)
241 {
242 }
243
244 int
245 mygenswitch(int num, TWORD type, struct swents **p, int n)
246 {
247 return 0;
248 }
249
250 /*
251 * Return "canonical frame address".
252 */
253 NODE *
254 builtin_cfa(const struct bitable *bt, NODE *a)
255 {
256 uerror("missing %s", __func__);
257 return bcon(0);
258 }
259
260 NODE *
261 builtin_frame_address(const struct bitable *bt, NODE *a)
262 {
263 uerror("missing %s", __func__);
264 return bcon(0);
265 }
266
267 NODE *
268 builtin_return_address(const struct bitable *bt, NODE *a)
269 {
270 uerror("missing %s", __func__);
271 return bcon(0);
272 }