annotate src/insn_bitbit.c @ 210:f481641b3371

Added ability to specify lwex target for ld
author lost
date Tue, 21 Apr 2009 03:47:24 +0000
parents f59c0916753d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
1 /*
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
2 insn_bitbit.c
33
74a3fef7c8d0 Added general addressing modes (immediate, base page, extended, indexed)
lost
parents: 32
diff changeset
3 Copyright © 2009 William Astle
32
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
4
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
5 This file is part of LWASM.
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
6
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
7 LWASM is free software: you can redistribute it and/or modify it under the
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
8 terms of the GNU General Public License as published by the Free Software
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
9 Foundation, either version 3 of the License, or (at your option) any later
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
10 version.
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
11
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
12 This program is distributed in the hope that it will be useful, but WITHOUT
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
15 more details.
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
16
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
17 You should have received a copy of the GNU General Public License along with
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
18 this program. If not, see <http://www.gnu.org/licenses/>.
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
19 */
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
20
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
21 /*
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
22 for handling inherent mode instructions
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
23 */
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
24
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
25 #define __insn_bitbit_c_seen__
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
26
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
27 #include <stdlib.h>
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
28
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
29 #include "lwasm.h"
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
30 #include "instab.h"
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
31 #include "expr.h"
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
32
80
8929e1ee99cf Checkpointing deployment of non-constant expression handling
lost
parents: 37
diff changeset
33 // these instructions cannot tolerate external references
32
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
34 OPFUNC(insn_bitbit)
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
35 {
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
36 int r;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
37 lwasm_expr_stack_t *s;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
38 int v1;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
39 int tv;
80
8929e1ee99cf Checkpointing deployment of non-constant expression handling
lost
parents: 37
diff changeset
40
32
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
41 lwasm_emitop(as, l, instab[opnum].ops[0]);
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
42
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
43 r = toupper(*(*p)++);
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
44 if (r == 'A')
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
45 r = 1;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
46 else if (r == 'B')
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
47 r = 2;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
48 else if (r == 'C' && toupper(**p) == 'C')
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
49 {
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
50 r = 0;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
51 (*p)++;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
52 }
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
53 else
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
54 {
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
55 register_error(as, l, 1, "Bad register");
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
56 return;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
57 }
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
58 if (*(*p)++ != ',')
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
59 {
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
60 register_error(as, l, 1, "Bad operand");
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
61 return;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
62 }
101
f59c0916753d Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents: 80
diff changeset
63 s = lwasm_evaluate_expr(as, l, *p, NULL, 0);
32
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
64 if (!s)
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
65 {
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
66 register_error(as, l, 1, "Bad operand");
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
67 return;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
68 }
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
69 if (!lwasm_expr_is_constant(s))
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
70 {
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
71 register_error(as, l, 2, "Incomplete reference");
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
72 }
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
73 v1 = lwasm_expr_get_value(s);
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
74 lwasm_expr_stack_free(s);
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
75 if (v1 < 0 || v1 > 7)
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
76 {
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
77 register_error(as, l, 2, "Invalid bit number");
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
78 v1 = 0;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
79 }
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
80 if (*(*p)++ != ',')
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
81 {
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
82 register_error(as, l, 1, "Bad operand");
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
83 return;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
84 }
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
85 r = (r << 6) | (v1 << 3);
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
86
101
f59c0916753d Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents: 80
diff changeset
87 s = lwasm_evaluate_expr(as, l, *p, NULL, 0);
32
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
88 if (!s)
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
89 {
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
90 register_error(as, l, 1, "Bad operand");
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
91 return;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
92 }
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
93 if (!lwasm_expr_is_constant(s))
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
94 {
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
95 register_error(as, l, 1, "Incomplete reference");
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
96 }
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
97 v1 = lwasm_expr_get_value(s);
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
98 lwasm_expr_stack_free(s);
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
99 if (v1 < 0 || v1 > 7)
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
100 {
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
101 register_error(as, l, 2, "Invalid bit number");
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
102 v1 = 0;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
103 }
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
104 if (*(*p)++ != ',')
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
105 {
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
106 register_error(as, l, 1, "Bad operand");
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
107 return;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
108 }
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
109 r |= v1;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
110
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
111 lwasm_emit(as, l, r);
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
112
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
113 // ignore base page address modifier
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
114 if (**p == '<')
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
115 (*p)++;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
116
101
f59c0916753d Fixed relative branches and PCR addressing to handle constant intra-section references properly
lost
parents: 80
diff changeset
117 s = lwasm_evaluate_expr(as, l, *p, NULL, 0);
32
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
118 if (!s)
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
119 {
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
120 register_error(as, l, 1, "Bad operand");
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
121 return;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
122 }
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
123 if (!lwasm_expr_is_constant(s))
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
124 {
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
125 register_error(as, l, 1, "Incomplete reference");
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
126 }
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
127 v1 = lwasm_expr_get_value(s);
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
128 lwasm_expr_stack_free(s);
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
129 v1 &= 0xFFFF;
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
130
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
131 tv = v1 - ((as -> dpval) << 8);
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
132 if (tv > 0xFF || tv < 0)
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
133 {
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
134 register_error(as, l, 2, "Byte overflow");
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
135 }
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
136 lwasm_emit(as, l, tv & 0xff);
9bd0fbfe7405 Added basic indexed mode handling
lost
parents:
diff changeset
137 }