|
|
1.1 root 1: /*-
2: * Copyright (c) 1984 The Regents of the University of California.
3: * All rights reserved.
4: *
5: * Redistribution and use in source and binary forms, with or without
6: * modification, are permitted provided that the following conditions
7: * are met:
8: * 1. Redistributions of source code must retain the above copyright
9: * notice, this list of conditions and the following disclaimer.
10: * 2. Redistributions in binary form must reproduce the above copyright
11: * notice, this list of conditions and the following disclaimer in the
12: * documentation and/or other materials provided with the distribution.
13: * 3. All advertising materials mentioning features or use of this software
14: * must display the following acknowledgement:
15: * This product includes software developed by the University of
16: * California, Berkeley and its contributors.
17: * 4. Neither the name of the University nor the names of its contributors
18: * may be used to endorse or promote products derived from this software
19: * without specific prior written permission.
20: *
21: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31: * SUCH DAMAGE.
32: */
33:
34: #ifndef lint
35: static char sccsid[] = "@(#)machdep.c 1.4 (Berkeley) 5/8/91";
36: #endif /* not lint */
37:
38: #include <stdio.h>
39: #include <ctype.h>
40: #include "inline.h"
41:
42: extern char *strcpy();
43: extern char *strcat();
44: extern char *index();
45:
46: /*
47: * The routines and tables in this file must be rewritten
48: * for each new machine that this program is ported to.
49: */
50:
51: /*
52: * Instruction stop table.
53: * All instructions that implicitly modify any of the temporary
54: * registers, change control flow, or implicitly loop must be
55: * listed in this table. It is used to find the end of a basic
56: * block when scanning backwards through the instruction stream
57: * trying to merge the inline expansion.
58: */
59: struct inststoptbl inststoptable[] = {
60: /* control */
61: { "bbssi" }, { "bcc" }, { "bcs" }, { "beql" }, { "beqlu" },
62: { "bgeq" }, { "bgequ" }, { "bgtr" }, { "bgtru" }, { "bleq" },
63: { "blequ" }, { "blss" }, { "blssu" }, { "bneq" }, { "bnequ" },
64: { "brb" }, { "brw" }, { "bvc" }, { "bvs" }, { "jmp" },
65: /* jump versions of control */
66: { "jbc" }, { "jbs" }, { "jeql" }, { "jeqlu" },
67: { "jgeq" }, { "jgequ" }, { "jgtr" }, { "jgtru" }, { "jleq" },
68: { "jlequ" }, { "jlss" }, { "jlssu" }, { "jneq" }, { "jnequ" },
69: { "jcc" }, { "jcs" }, { "jvc" }, { "jvs" }, { "jbr" },
70: /* multiple registers */
71: { "loadr" },
72: /* bit field */
73: { "bbc" }, { "bbs" },
74: /* character string and block move */
75: { "cmps2" }, { "cmps3" }, { "movblk" }, { "movs2" }, { "movs3" },
76: /* procedure call */
77: { "callf" }, { "calls" }, { "ret" },
78: /* loop control */
79: { "aobleq" }, { "aoblss" }, { "casel" },
80: /* privileged and miscellaneous */
81: { "bpt" }, { "halt" }, { "kcall" }, { "ldpctx" }, { "rei" },
82: { "svpctx" },
83: { "" }
84: };
85:
86: /*
87: * Check to see if a line is a candidate for replacement.
88: * Return pointer to name to be looked up in pattern table.
89: */
90: char *
91: doreplaceon(cp)
92: char *cp;
93: {
94:
95: if (bcmp(cp, "callf\t", 6))
96: return (0);
97: if ((cp = index(cp + 6, ',')) == 0)
98: return (0);
99: return (++cp);
100: }
101:
102: /*
103: * Find out how many arguments the function is being called with.
104: * A return value of -1 indicates that the count can't be determined.
105: */
106: countargs(cp)
107: char *cp;
108: {
109: int i;
110:
111: if ((cp = index(cp, '$')) == 0)
112: return (-1);
113: if (!isdigit(*++cp) || (i = atoi(cp)) == -1)
114: return (-1);
115: return (i/4 - 1);
116: }
117:
118: /*
119: * Find the next argument to the function being expanded.
120: */
121: nextarg(argc, argv)
122: int argc;
123: char *argv[];
124: {
125: register char *lastarg = argv[2];
126:
127: if (argc == 3 &&
128: bcmp(argv[0], "mov", 3) == 0 &&
129: bcmp(argv[1], "(sp)+", 6) == 0 &&
130: lastarg[0] == 'r' && isdigit(lastarg[1]) && lastarg[2] == '\0')
131: return (lastarg[1] - '0');
132: return (-1);
133: }
134:
135: /*
136: * Determine whether the current line pushes an argument.
137: */
138: ispusharg(argc, argv)
139: int argc;
140: char *argv[];
141: {
142:
143: if (argc < 2)
144: return (0);
145: if (argc == 2 && bcmp(argv[0], "push", 4) == 0)
146: return (1);
147: if (bcmp(argv[argc - 1], "-(sp)", 6) == 0)
148: return (1);
149: return (0);
150: }
151:
152: /*
153: * Determine which (if any) registers are modified
154: * Return register number that is modified, -1 if none are modified.
155: */
156: modifies(argc, argv)
157: int argc;
158: char *argv[];
159: {
160: register char *lastarg = argv[argc - 1];
161:
162: /*
163: * For the tahoe all we care about are r0 to r5
164: */
165: if (lastarg[0] == 'r' && isdigit(lastarg[1]) && lastarg[2] == '\0')
166: return (lastarg[1] - '0');
167: return (-1);
168: }
169:
170: /*
171: * Rewrite the instruction in (argc, argv) to store its
172: * contents into arg instead of onto the stack. The new
173: * instruction is placed in the buffer that is provided.
174: */
175: rewrite(instbuf, argc, argv, target)
176: char *instbuf;
177: int argc;
178: char *argv[];
179: int target;
180: {
181:
182: switch (argc) {
183: case 0:
184: instbuf[0] = '\0';
185: fprintf(stderr, "blank line to rewrite?\n");
186: return;
187: case 1:
188: sprintf(instbuf, "\t%s\n", argv[0]);
189: fprintf(stderr, "rewrite?-> %s", instbuf);
190: return;
191: case 2:
192: if (bcmp(argv[0], "push", 4) == 0) {
193: sprintf(instbuf, "\tmov%s\t%s,r%d\n",
194: &argv[0][4], argv[1], target);
195: return;
196: }
197: sprintf(instbuf, "\t%s\tr%d\n", argv[0], target);
198: return;
199: case 3:
200: sprintf(instbuf, "\t%s\t%s,r%d\n", argv[0], argv[1], target);
201: return;
202: case 4:
203: sprintf(instbuf, "\t%s\t%s,%s,r%d\n",
204: argv[0], argv[1], argv[2], target);
205: return;
206: case 5:
207: sprintf(instbuf, "\t%s\t%s,%s,%s,r%d\n",
208: argv[0], argv[1], argv[2], argv[3], target);
209: return;
210: default:
211: sprintf(instbuf, "\t%s\t%s", argv[0], argv[1]);
212: argc -= 2, argv += 2;
213: while (argc-- > 0) {
214: strcat(instbuf, ",");
215: strcat(instbuf, *argv++);
216: }
217: strcat(instbuf, "\n");
218: fprintf(stderr, "rewrite?-> %s", instbuf);
219: return;
220: }
221: }
222:
223: /*
224: * Do any necessary post expansion cleanup.
225: */
226: cleanup(numargs)
227: int numargs;
228: {
229:
230: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.