annotate lwasm/insn_rtor.c @ 448:5cccf90bf838 3.0 tip

Fixed bug with complex external references generating invalid relocations in the object file
author lost@l-w.ca
date Fri, 05 Nov 2010 22:27:00 -0600
parents 0cf4948d53b4
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
357
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
1 /*
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
2 insn_rtor.c
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
3 Copyright © 2010 William Astle
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
4
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
5 This file is part of LWASM.
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
6
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
7 LWASM is free software: you can redistribute it and/or modify it under the
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
8 terms of the GNU General Public License as published by the Free Software
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
9 Foundation, either version 3 of the License, or (at your option) any later
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
10 version.
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
11
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
12 This program is distributed in the hope that it will be useful, but WITHOUT
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
15 more details.
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
16
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
17 You should have received a copy of the GNU General Public License along with
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
18 this program. If not, see <http://www.gnu.org/licenses/>.
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
19
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
20 */
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
21
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
22 #include <config.h>
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
23
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
24 #include "lwasm.h"
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
25 #include "instab.h"
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
26
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
27 PARSEFUNC(insn_parse_rtor)
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
28 {
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
29 int r0, r1;
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
30
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
31 static const char *regs = "D X Y U S PCW V A B CCDP0 0 E F ";
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
32 static const char *regs9 = "D X Y U S PC A B CCDP ";
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
33
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
34 // register to register (r0,r1)
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
35 // registers are in order:
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
36 // D,X,Y,U,S,PC,W,V
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
37 // A,B,CC,DP,0,0,E,F
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
38
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
39 r0 = lwasm_lookupreg2((as -> target == TARGET_6309) ? regs9 : regs, p);
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
40 if (r0 < 0 || *(*p)++ != ',')
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
41 {
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
42 lwasm_register_error(as, l, "Bad operand");
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
43 r0 = r1 = 0;
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
44 }
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
45 else
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
46 {
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
47 r1 = lwasm_lookupreg2((as -> target = TARGET_6309) ? regs9 : regs, p);
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
48 if (r1 < 0)
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
49 {
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
50 lwasm_register_error(as, l, "Bad operand");
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
51 r0 = r1 = 0;
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
52 }
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
53 }
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
54 l -> pb = (r0 << 4) | r1;
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
55 l -> len = OPLEN(instab[l -> insn].ops[0]) + 1;
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
56 }
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
57
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
58 EMITFUNC(insn_emit_rtor)
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
59 {
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
60 lwasm_emitop(l, instab[l -> insn].ops[0]);
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
61 lwasm_emit(l, l -> pb);
0cf4948d53b4 Checkpoint - adding actual cpu instructions
lost@starbug
parents:
diff changeset
62 }