annotate old-trunk/lwasm/old/os9.c @ 348:11a95c6414b4

Added third func to instab to split resolve and emit logic
author lost@starbug
date Sat, 27 Mar 2010 22:15:07 -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 os9.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 This file implements the various pseudo operations related to OS9 target
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
22 */
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
23 #include <config.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
24 #include <errno.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
25 #include <stdio.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
26 #include <stdlib.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
27 #include <string.h>
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
28 #include "lwasm.h"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
29 #include "instab.h"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
30 #include "expr.h"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
31 #include "util.h"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
32
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
33 OPFUNC(pseudo_os9)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
34 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
35 int r, rval;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
36
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
37 if (as -> outformat != OUTPUT_OS9)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
38 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
39 register_error(as, l, 1, "os9 directive only valid for OS9 target");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
40 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
41 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
42
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
43 // fetch immediate value
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
44 r = lwasm_expr_result2(as, l, p, 0, &rval, 0);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
45 if (r != 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
46 rval = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
47 if (r == 1 && as -> passnum == 2)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
48 register_error(as, l, 2, "Illegal external or intersegment reference");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
49
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
50 // SWI2; FCB ...
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
51 lwasm_emit(as, l, 0x10);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
52 lwasm_emit(as, l, 0x3f);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
53 lwasm_emit(as, l, rval);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
54 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
55
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
56 OPFUNC(pseudo_mod)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
57 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
58 int modvals[6];
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
59 int r, v, i;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
60
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
61 if (as -> outformat != OUTPUT_OS9)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
62 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
63 register_error(as, l, 1, "mod directive only valid for OS9 target");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
64 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
65 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
66
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
67 if (as -> inmod)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
68 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
69 register_error(as, l, 1, "Already in a module!");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
70 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
71 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
72
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
73 // parse 6 expressions...
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
74 for (i = 0; i < 5; i++)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
75 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
76 r = lwasm_expr_result2(as, l, p, 0, &v, -1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
77 if (r < 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
78 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
79 if (r > 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
80 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
81 register_error(as, l, 2, "Illegal external or inter-segment reference (only 1 per FDB line)");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
82 v = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
83 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
84 else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
85 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
86 modvals[i] = v;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
87 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
88 if (**p != ',')
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
89 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
90 register_error(as, l, 1, "Bad operand");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
91 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
92 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
93 (*p)++;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
94 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
95 r = lwasm_expr_result2(as, l, p, 0, &v, -1);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
96 if (r < 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
97 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
98 if (r > 0)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
99 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
100 register_error(as, l, 2, "Illegal external or inter-segment reference (only 1 per FDB line)");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
101 v = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
102 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
103 else
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
104 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
105 modvals[5] = v;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
106 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
107
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
108 l -> inmod = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
109
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
110 // we have an implicit ORG 0 with "mod"
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
111 l -> codeaddr = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
112 l -> addrset = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
113 as -> addr = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
114
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
115 // init crc
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
116 as -> crc[0] = 0xff;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
117 as -> crc[1] = 0xff;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
118 as -> crc[2] = 0xff;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
119 as -> inmod = 1;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
120
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
121 // sync bytes
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
122 lwasm_emit(as, l, 0x87);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
123 lwasm_emit(as, l, 0xcd);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
124
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
125 // mod length
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
126 lwasm_emit(as, l, modvals[0] >> 8);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
127 lwasm_emit(as, l, modvals[0] & 0xff);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
128
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
129 // name offset
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
130 lwasm_emit(as, l, modvals[1] >> 8);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
131 lwasm_emit(as, l, modvals[1] & 0xff);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
132
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
133 // type
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
134 lwasm_emit(as, l, modvals[2]);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
135
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
136 // flags/rev
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
137 lwasm_emit(as, l, modvals[3]);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
138
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
139 // header check
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
140 lwasm_emit(as, l, ~(0x87 ^ 0xCD ^ (modvals[0] >> 8) ^ (modvals[0] & 0xff)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
141 ^ (modvals[1] >> 8) ^ (modvals[1] & 0xff)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
142 ^ modvals[2] ^ modvals[3]));
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
143
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
144 // module type specific output
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
145 // note that these are handled the same for all so
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
146 // there need not be any special casing
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
147
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
148 // exec offset or fmgr name offset
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
149 lwasm_emit(as, l, modvals[4] >> 8);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
150 lwasm_emit(as, l, modvals[4] & 0xff);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
151
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
152 // data size or drvr name offset
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
153 lwasm_emit(as, l, modvals[5] >> 8);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
154 lwasm_emit(as, l, modvals[5] & 0xff);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
155 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
156
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
157 OPFUNC(pseudo_emod)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
158 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
159 unsigned char tcrc[3];
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
160
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
161 if (as -> outformat != OUTPUT_OS9)
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
162 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
163 register_error(as, l, 1, "emod directive only valid for OS9 target");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
164 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
165 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
166
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
167 if (!(as -> inmod))
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
168 {
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
169 register_error(as, l, 1, "not in a module!");
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
170 return;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
171 }
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
172
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
173 // don't mess with CRC!
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
174 tcrc[0] = as -> crc[0] ^ 0xff;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
175 tcrc[1] = as -> crc[1] ^ 0xff;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
176 tcrc[2] = as -> crc[2] ^ 0xff;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
177 lwasm_emit(as, l, tcrc[0]);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
178 lwasm_emit(as, l, tcrc[1]);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
179 lwasm_emit(as, l, tcrc[2]);
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
180 as -> inmod = 0;
eb230fa7d28e Prepare for migration to hg
lost
parents:
diff changeset
181 }