annotate old-trunk/lwasm/old/insn_bitbit.c @ 344:0215a0fbf61b

Added assembly error system and additional checks for symbol syntax
author lost@starbug
date Thu, 25 Mar 2010 22:06:50 -0600
parents eb230fa7d28e
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_bitbit.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_bitbit_c_seen__
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
26
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
27 #include <config.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
28 #include <stdlib.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 #include "expr.h"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
33
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
34 // these instructions cannot tolerate external references
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
35 OPFUNC(insn_bitbit)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
36 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
37 int r;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
38 lwasm_expr_stack_t *s;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
39 int v1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
40 int tv;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
41
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
42 lwasm_emitop(as, l, instab[opnum].ops[0]);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
43
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
44 r = toupper(*(*p)++);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
45 if (r == 'A')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
46 r = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
47 else if (r == 'B')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
48 r = 2;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
49 else if (r == 'C' && toupper(**p) == 'C')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
50 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
51 r = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
52 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
53 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
54 else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
55 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
56 register_error(as, l, 1, "Bad register");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
57 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
58 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
59 if (*(*p)++ != ',')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
60 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
61 register_error(as, l, 1, "Bad operand");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
62 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
63 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
64 s = lwasm_evaluate_expr(as, l, *p, NULL, 0);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
65 if (!s)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
66 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
67 register_error(as, l, 1, "Bad operand");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
68 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
69 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
70 if (!lwasm_expr_is_constant(s))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
71 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
72 register_error(as, l, 2, "Incomplete reference");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
73 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
74 v1 = lwasm_expr_get_value(s);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
75 lwasm_expr_stack_free(s);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
76 if (v1 < 0 || v1 > 7)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
77 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
78 register_error(as, l, 2, "Invalid bit number");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
79 v1 = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
80 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
81 if (*(*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 r = (r << 6) | (v1 << 3);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
87
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
88 s = lwasm_evaluate_expr(as, l, *p, NULL, 0);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
89 if (!s)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
90 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
91 register_error(as, l, 1, "Bad operand");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
92 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
93 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
94 if (!lwasm_expr_is_constant(s))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
95 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
96 register_error(as, l, 1, "Incomplete reference");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
97 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
98 v1 = lwasm_expr_get_value(s);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
99 lwasm_expr_stack_free(s);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
100 if (v1 < 0 || v1 > 7)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
101 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
102 register_error(as, l, 2, "Invalid bit number");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
103 v1 = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
104 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
105 if (*(*p)++ != ',')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
106 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
107 register_error(as, l, 1, "Bad operand");
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 r |= v1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
111
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
112 lwasm_emit(as, l, r);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
113
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
114 // ignore base page address modifier
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
115 if (**p == '<')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
116 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
117
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
118 s = lwasm_evaluate_expr(as, l, *p, NULL, 0);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
119 if (!s)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
120 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
121 register_error(as, l, 1, "Bad operand");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
122 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
123 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
124 if (!lwasm_expr_is_constant(s))
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, "Incomplete reference");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
127 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
128 v1 = lwasm_expr_get_value(s);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
129 lwasm_expr_stack_free(s);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
130 v1 &= 0xFFFF;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
131
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
132 tv = v1 - ((as -> dpval) << 8);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
133 if (tv > 0xFF || tv < 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
134 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
135 register_error(as, l, 2, "Byte overflow");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
136 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
137 lwasm_emit(as, l, tv & 0xff);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
138 }