Mercurial > hg > index.cgi
annotate lwasm/insn_rlist.c @ 556:928c033c0cd0
Allow MOD directive to accept only the standard base header parameters
There are cases where only the standard OS9 module header fields are to be
provided. This could be, for instance, in the case of a nonstandard user
type module. So allow the execution offset and data size fields to be
omitted entirely and handle the module length correctly as well.
author | William Astle <lost@l-w.ca> |
---|---|
date | Fri, 08 Sep 2023 00:32:40 -0600 |
parents | f9ffd1935cee |
children |
rev | line source |
---|---|
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
1 /* |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
2 insn_rlist.c |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
3 Copyright © 2009 William Astle |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
4 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
5 This file is part of LWASM. |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
6 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
7 LWASM is free software: you can redistribute it and/or modify it under the |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
8 terms of the GNU General Public License as published by the Free Software |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
9 Foundation, either version 3 of the License, or (at your option) any later |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
10 version. |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
11 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
12 This program is distributed in the hope that it will be useful, but WITHOUT |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
15 more details. |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
16 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
17 You should have received a copy of the GNU General Public License along with |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
18 this program. If not, see <http://www.gnu.org/licenses/>. |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
19 */ |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
20 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
21 /* |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
22 for handling inherent mode instructions |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
23 */ |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
24 |
2
7317fbe024af
Clean up insane number of compiler warnings under -Wall
lost@l-w.ca
parents:
0
diff
changeset
|
25 #include <ctype.h> |
7317fbe024af
Clean up insane number of compiler warnings under -Wall
lost@l-w.ca
parents:
0
diff
changeset
|
26 |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
27 #include "lwasm.h" |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
28 #include "instab.h" |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
29 |
552
f9ffd1935cee
Add explicit immediate mode to register list instructions (PSHS, etc.)
William Astle <lost@l-w.ca>
parents:
404
diff
changeset
|
30 PARSEFUNC(insn_parse_imm8); |
f9ffd1935cee
Add explicit immediate mode to register list instructions (PSHS, etc.)
William Astle <lost@l-w.ca>
parents:
404
diff
changeset
|
31 EMITFUNC(insn_emit_imm8); |
f9ffd1935cee
Add explicit immediate mode to register list instructions (PSHS, etc.)
William Astle <lost@l-w.ca>
parents:
404
diff
changeset
|
32 |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
33 PARSEFUNC(insn_parse_rlist) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
34 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
35 int rb = 0; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
36 int rn; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
37 static const char *regs = "CCA B DPX Y U PCD S "; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
38 |
552
f9ffd1935cee
Add explicit immediate mode to register list instructions (PSHS, etc.)
William Astle <lost@l-w.ca>
parents:
404
diff
changeset
|
39 l -> lint = 0; |
f9ffd1935cee
Add explicit immediate mode to register list instructions (PSHS, etc.)
William Astle <lost@l-w.ca>
parents:
404
diff
changeset
|
40 if (**p == '#') |
f9ffd1935cee
Add explicit immediate mode to register list instructions (PSHS, etc.)
William Astle <lost@l-w.ca>
parents:
404
diff
changeset
|
41 { |
f9ffd1935cee
Add explicit immediate mode to register list instructions (PSHS, etc.)
William Astle <lost@l-w.ca>
parents:
404
diff
changeset
|
42 insn_parse_imm8(as, l, p); |
f9ffd1935cee
Add explicit immediate mode to register list instructions (PSHS, etc.)
William Astle <lost@l-w.ca>
parents:
404
diff
changeset
|
43 l -> lint = 1; |
f9ffd1935cee
Add explicit immediate mode to register list instructions (PSHS, etc.)
William Astle <lost@l-w.ca>
parents:
404
diff
changeset
|
44 return; |
f9ffd1935cee
Add explicit immediate mode to register list instructions (PSHS, etc.)
William Astle <lost@l-w.ca>
parents:
404
diff
changeset
|
45 } |
f9ffd1935cee
Add explicit immediate mode to register list instructions (PSHS, etc.)
William Astle <lost@l-w.ca>
parents:
404
diff
changeset
|
46 |
404
f6e03c2cebfb
Fix "rlist" to recognize comments as end of operand
William Astle <lost@l-w.ca>
parents:
402
diff
changeset
|
47 while (**p && !isspace(**p) && **p != ';' && **p != '*') |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
48 { |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
49 rn = lwasm_lookupreg2(regs, p); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
50 if (rn < 0) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
51 { |
370
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
368
diff
changeset
|
52 lwasm_register_error2(as, l, E_REGISTER_BAD, "'%s'", *p); |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
53 return; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
54 } |
402
b20f14edda5a
Completed initial conversion to new parser allowing spaces in operands
William Astle <lost@l-w.ca>
parents:
376
diff
changeset
|
55 lwasm_skip_to_next_token(l, p); |
404
f6e03c2cebfb
Fix "rlist" to recognize comments as end of operand
William Astle <lost@l-w.ca>
parents:
402
diff
changeset
|
56 if (**p && **p != ',' && !isspace(**p) && **p != ';' && **p != '*') |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
57 { |
370
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
368
diff
changeset
|
58 lwasm_register_error(as, l, E_OPERAND_BAD); |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
59 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
60 if (**p == ',') |
402
b20f14edda5a
Completed initial conversion to new parser allowing spaces in operands
William Astle <lost@l-w.ca>
parents:
376
diff
changeset
|
61 { |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
62 (*p)++; |
402
b20f14edda5a
Completed initial conversion to new parser allowing spaces in operands
William Astle <lost@l-w.ca>
parents:
376
diff
changeset
|
63 lwasm_skip_to_next_token(l, p); |
b20f14edda5a
Completed initial conversion to new parser allowing spaces in operands
William Astle <lost@l-w.ca>
parents:
376
diff
changeset
|
64 } |
373
00fced888c5d
Fix psh/pul to not accept the stack pointer as a valid argument
William Astle <lost@l-w.ca>
parents:
370
diff
changeset
|
65 if ((instab[l -> insn].ops[0]) & 2) |
00fced888c5d
Fix psh/pul to not accept the stack pointer as a valid argument
William Astle <lost@l-w.ca>
parents:
370
diff
changeset
|
66 { |
00fced888c5d
Fix psh/pul to not accept the stack pointer as a valid argument
William Astle <lost@l-w.ca>
parents:
370
diff
changeset
|
67 // pshu/pulu |
00fced888c5d
Fix psh/pul to not accept the stack pointer as a valid argument
William Astle <lost@l-w.ca>
parents:
370
diff
changeset
|
68 if (rn == 6) |
00fced888c5d
Fix psh/pul to not accept the stack pointer as a valid argument
William Astle <lost@l-w.ca>
parents:
370
diff
changeset
|
69 { |
00fced888c5d
Fix psh/pul to not accept the stack pointer as a valid argument
William Astle <lost@l-w.ca>
parents:
370
diff
changeset
|
70 lwasm_register_error2(as, l, E_REGISTER_BAD, "'%s'", "u"); |
00fced888c5d
Fix psh/pul to not accept the stack pointer as a valid argument
William Astle <lost@l-w.ca>
parents:
370
diff
changeset
|
71 return; |
00fced888c5d
Fix psh/pul to not accept the stack pointer as a valid argument
William Astle <lost@l-w.ca>
parents:
370
diff
changeset
|
72 } |
00fced888c5d
Fix psh/pul to not accept the stack pointer as a valid argument
William Astle <lost@l-w.ca>
parents:
370
diff
changeset
|
73 } |
00fced888c5d
Fix psh/pul to not accept the stack pointer as a valid argument
William Astle <lost@l-w.ca>
parents:
370
diff
changeset
|
74 else |
00fced888c5d
Fix psh/pul to not accept the stack pointer as a valid argument
William Astle <lost@l-w.ca>
parents:
370
diff
changeset
|
75 { |
00fced888c5d
Fix psh/pul to not accept the stack pointer as a valid argument
William Astle <lost@l-w.ca>
parents:
370
diff
changeset
|
76 if (rn == 9) |
00fced888c5d
Fix psh/pul to not accept the stack pointer as a valid argument
William Astle <lost@l-w.ca>
parents:
370
diff
changeset
|
77 { |
00fced888c5d
Fix psh/pul to not accept the stack pointer as a valid argument
William Astle <lost@l-w.ca>
parents:
370
diff
changeset
|
78 lwasm_register_error2(as, l, E_REGISTER_BAD, "'%s'", "s"); |
00fced888c5d
Fix psh/pul to not accept the stack pointer as a valid argument
William Astle <lost@l-w.ca>
parents:
370
diff
changeset
|
79 return; |
00fced888c5d
Fix psh/pul to not accept the stack pointer as a valid argument
William Astle <lost@l-w.ca>
parents:
370
diff
changeset
|
80 } |
00fced888c5d
Fix psh/pul to not accept the stack pointer as a valid argument
William Astle <lost@l-w.ca>
parents:
370
diff
changeset
|
81 } |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
82 if (rn == 8) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
83 rn = 6; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
84 else if (rn == 9) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
85 rn = 0x40; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
86 else |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
87 rn = 1 << rn; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
88 rb |= rn; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
89 } |
368
362f8fb0695b
Make psh/pul error out if no registers given
William Astle <lost@l-w.ca>
parents:
2
diff
changeset
|
90 if (rb == 0) |
370
8764142b3192
Convert internal error/warning handling framework to a new unified system
William Astle <lost@l-w.ca>
parents:
368
diff
changeset
|
91 lwasm_register_error(as, l, E_OPERAND_BAD); |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
92 l -> len = OPLEN(instab[l -> insn].ops[0]) + 1; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
93 l -> pb = rb; |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
94 } |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
95 |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
96 EMITFUNC(insn_emit_rlist) |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
97 { |
552
f9ffd1935cee
Add explicit immediate mode to register list instructions (PSHS, etc.)
William Astle <lost@l-w.ca>
parents:
404
diff
changeset
|
98 if (l -> lint == 1) |
f9ffd1935cee
Add explicit immediate mode to register list instructions (PSHS, etc.)
William Astle <lost@l-w.ca>
parents:
404
diff
changeset
|
99 { |
f9ffd1935cee
Add explicit immediate mode to register list instructions (PSHS, etc.)
William Astle <lost@l-w.ca>
parents:
404
diff
changeset
|
100 insn_emit_imm8(as, l); |
f9ffd1935cee
Add explicit immediate mode to register list instructions (PSHS, etc.)
William Astle <lost@l-w.ca>
parents:
404
diff
changeset
|
101 return; |
f9ffd1935cee
Add explicit immediate mode to register list instructions (PSHS, etc.)
William Astle <lost@l-w.ca>
parents:
404
diff
changeset
|
102 } |
f9ffd1935cee
Add explicit immediate mode to register list instructions (PSHS, etc.)
William Astle <lost@l-w.ca>
parents:
404
diff
changeset
|
103 |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
104 lwasm_emitop(l, instab[l -> insn].ops[0]); |
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
105 lwasm_emit(l, l -> pb); |
376 | 106 |
107 l -> cycle_adj = lwasm_cycle_calc_rlist(l); | |
0
2c24602be78f
Initial import from lwtools 3.0.1 version, with new hand built build system and file reorganization
lost@l-w.ca
parents:
diff
changeset
|
108 } |