annotate old-trunk/lwasm/old/insn_tfm.c @ 339:eb230fa7d28e

Prepare for migration to hg
author lost
date Fri, 19 Mar 2010 02:54:14 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
339
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
1 /*
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
2 insn_tfm.c
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
3 Copyright © 2009 William Astle
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
4
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
5 This file is part of LWASM.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
6
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
7 LWASM is free software: you can redistribute it and/or modify it under the
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
8 terms of the GNU General Public License as published by the Free Software
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
9 Foundation, either version 3 of the License, or (at your option) any later
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
10 version.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
11
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
12 This program is distributed in the hope that it will be useful, but WITHOUT
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
15 more details.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
16
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
17 You should have received a copy of the GNU General Public License along with
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
18 this program. If not, see <http://www.gnu.org/licenses/>.
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
19 */
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
20
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
21 /*
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
22 for handling inherent mode instructions
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
23 */
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
24
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
25 #define __insn_tfm_c_seen__
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
26 #include <config.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
27 #include <ctype.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
28 #include <string.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
29
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
30 #include "lwasm.h"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
31 #include "instab.h"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
32
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
33 OPFUNC(insn_tfm)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
34 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
35 static const char *reglist = "DXYUS AB 00EF";
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
36 int r0, r1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
37 char *c;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
38 int tfm = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
39
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
40 c = strchr(reglist, toupper(*(*p)++));
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
41 if (!c)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
42 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
43 register_error(as, l, 1, "Unknown operation");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
44 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
45 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
46 r0 = c - reglist;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
47 if (**p == '+')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
48 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
49 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
50 tfm = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
51 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
52 else if (**p == '-')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
53 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
54 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
55 tfm = 2;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
56 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
57 if (*(*p)++ != ',')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
58 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
59 register_error(as, l, 1, "Unknown operation");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
60 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
61 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
62 c = strchr(reglist, toupper(*(*p)++));
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
63 if (!c)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
64 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
65 register_error(as, l, 1, "Unknown operation");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
66 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
67 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
68 r1 = c - reglist;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
69
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
70 if (**p == '+')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
71 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
72 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
73 tfm |= 4;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
74 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
75 else if (**p == '-')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
76 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
77 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
78 tfm |= 8;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
79 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
80
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
81 if (**p && !isspace(**p))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
82 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
83 register_error(as, l, 1, "Bad operand");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
84 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
85 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
86
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
87 // valid values of tfm here are:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
88 // 1: r0+,r1 (2)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
89 // 4: r0,r1+ (3)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
90 // 5: r0+,r1+ (0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
91 // 10: r0-,r1- (1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
92 switch (tfm)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
93 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
94 case 5: //r0+,r1+
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
95 lwasm_emitop(as, l, instab[opnum].ops[0]);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
96 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
97 case 10: //r0-,r1-
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
98 lwasm_emitop(as, l, instab[opnum].ops[1]);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
99 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
100 case 1: // r0+,r1
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
101 lwasm_emitop(as, l, instab[opnum].ops[2]);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
102 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
103 case 4: // r0,r1+
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
104 lwasm_emitop(as, l, instab[opnum].ops[3]);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
105 break;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
106 default:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
107 register_error(as, l, 1, "Unknown operation");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
108 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
109 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
110 lwasm_emit(as, l, (r0 << 4) | r1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
111 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
112
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
113 OPFUNC(insn_tfmrtor)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
114 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
115 int r0, r1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
116 static const char *regs = "D X Y U S A B 0 0 E F ";
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
117
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
118 lwasm_emitop(as, l, instab[opnum].ops[0]);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
119 // register to register (r0,r1)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
120 // registers are in order:
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
121 // D,X,Y,U,S,PC,W,V
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
122 // A,B,CC,DP,0,0,E,F
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
123 r0 = lwasm_lookupreg2(regs, p);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
124 if (r0 < 0 || *(*p)++ != ',')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
125 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
126 register_error(as, l, 1, "Bad operand");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
127 r0 = r1 = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
128 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
129 else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
130 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
131 r1 = lwasm_lookupreg2(regs, p);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
132 if (r1 < 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
133 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
134 register_error(as, l, 1, "Bad operand");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
135 r0 = r1 = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
136 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
137 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
138 lwasm_emit(as, l, (r0 << 4) | r1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
139 }