1 /* srcdest.c --- decoding M32C addressing modes.
3 Copyright (C) 2005, 2007, 2008, 2009, 2010, 2011
4 Free Software Foundation, Inc.
5 Contributed by Red Hat, Inc.
7 This file is part of the GNU simulators.
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>. */
29 static int src_indirect
= 0;
30 static int dest_indirect
= 0;
31 static int src_addend
= 0;
32 static int dest_addend
= 0;
42 rv
= mem_get_qi (get_reg (pc
));
56 rv
= mem_get_hi (get_reg (pc
));
70 rv
= mem_get_psi (get_reg (pc
));
79 return disp24 () & 0x000fffff;
90 *--bp
= (v
& 1) ? '1' : '0';
97 static const char *the_bits
= 0;
100 decode_indirect (int si
, int di
)
104 if (trace
&& (si
|| di
))
105 printf ("indirect: s:%d d:%d\n", si
, di
);
109 decode_index (int sa
, int da
)
113 if (trace
&& (sa
|| da
))
114 printf ("index: s:%d d:%d\n", sa
, da
);
118 decode_srcdest4 (int destcode
, int bw
)
121 sd
.bytes
= bw
? 2 : 1;
122 sd
.mem
= (destcode
>= 6) ? 1 : 0;
123 static const char *dc_wnames
[16] = { "r0", "r1", "r2", "r3",
124 "a0", "a1", "[a0]", "[a1]",
125 "disp8[a0]", "disp8[a1]", "disp8[sb]", "disp8[fb]",
126 "disp16[a0]", "disp16[a1]", "disp16[sb]", "disp16"
128 static const char *dc_bnames
[4] = { "r0l", "r0h", "r1l", "r1h" };;
132 const char *n
= dc_wnames
[destcode
];
133 if (bw
== 0 && destcode
<= 3)
134 n
= dc_bnames
[destcode
];
136 the_bits
= bits (destcode
, 4);
137 printf ("decode: %s (%d) : %s\n", the_bits
, destcode
, n
);
144 sd
.u
.reg
= bw
? r0
: r0l
;
147 sd
.u
.reg
= bw
? r1
: r0h
;
150 sd
.u
.reg
= bw
? r2
: r1l
;
153 sd
.u
.reg
= bw
? r3
: r1h
;
162 sd
.u
.addr
= get_reg (a0
);
165 sd
.u
.addr
= get_reg (a1
);
168 sd
.u
.addr
= get_reg (a0
) + disp8 ();
171 sd
.u
.addr
= get_reg (a1
) + disp8 ();
174 sd
.u
.addr
= get_reg (sb
) + disp8 ();
177 sd
.u
.addr
= get_reg (fb
) + sign_ext (disp8 (), 8);
180 sd
.u
.addr
= get_reg (a0
) + disp16 ();
183 sd
.u
.addr
= get_reg (a1
) + disp16 ();
186 sd
.u
.addr
= get_reg (sb
) + disp16 ();
189 sd
.u
.addr
= disp16 ();
195 sd
.u
.addr
&= addr_mask
;
200 decode_jumpdest (int destcode
, int w
)
203 sd
.bytes
= w
? 2 : 3;
204 sd
.mem
= (destcode
>= 6) ? 1 : 0;
205 static const char *dc_wnames
[16] = { "r0", "r1", "r2", "r3",
206 "a0", "a1", "[a0]", "[a1]",
207 "disp8[a0]", "disp8[a1]", "disp8[sb]", "disp8[fb]",
208 "disp20[a0]", "disp20[a1]", "disp16[sb]", "abs16"
210 static const char *dc_anames
[4] = { "r0l", "r0h", "r1l", "r1h" };
214 const char *n
= dc_wnames
[destcode
];
215 if (w
== 0 && destcode
<= 3)
216 n
= dc_anames
[destcode
];
218 the_bits
= bits (destcode
, 4);
219 printf ("decode: %s : %s\n", the_bits
, n
);
226 sd
.u
.reg
= w
? r0
: r2r0
;
229 sd
.u
.reg
= w
? r1
: r2r0
;
232 sd
.u
.reg
= w
? r2
: r3r1
;
235 sd
.u
.reg
= w
? r3
: r3r1
;
238 sd
.u
.reg
= w
? a0
: a1a0
;
241 sd
.u
.reg
= w
? a1
: a1a0
;
244 sd
.u
.addr
= get_reg (a0
);
247 sd
.u
.addr
= get_reg (a1
);
250 sd
.u
.addr
= get_reg (a0
) + disp8 ();
253 sd
.u
.addr
= get_reg (a1
) + disp8 ();
256 sd
.u
.addr
= get_reg (sb
) + disp8 ();
259 sd
.u
.addr
= get_reg (fb
) + sign_ext (disp8 (), 8);
262 sd
.u
.addr
= get_reg (a0
) + disp20 ();
265 sd
.u
.addr
= get_reg (a1
) + disp20 ();
268 sd
.u
.addr
= get_reg (sb
) + disp16 ();
271 sd
.u
.addr
= disp16 ();
277 sd
.u
.addr
&= addr_mask
;
282 decode_dest3 (int destcode
, int bw
)
284 static char map
[8] = { -1, -1, -1, 1, 0, 10, 11, 15 };
286 the_bits
= bits (destcode
, 3);
287 return decode_srcdest4 (map
[destcode
], bw
);
291 decode_src2 (int srccode
, int bw
, int d
)
293 static char map
[4] = { 0, 10, 11, 15 };
295 the_bits
= bits (srccode
, 2);
296 return decode_srcdest4 (srccode
? map
[srccode
] : 1 - d
, bw
);
309 a0
, a0
, 1, 0, "[A0]"}, /* 0 0 0 0 0 */
311 a1
, a1
, 1, 0, "[A1]"}, /* 0 0 0 0 1 */
313 a0
, a0
, 0, 0, "A0"}, /* 0 0 0 1 0 */
315 a1
, a1
, 0, 0, "A1"}, /* 0 0 0 1 1 */
317 a0
, a0
, 1, 1, "dsp:8[A0]"}, /* 0 0 1 0 0 */
319 a1
, a1
, 1, 1, "dsp:8[A1]"}, /* 0 0 1 0 1 */
321 sb
, sb
, 1, 1, "dsp:8[SB]"}, /* 0 0 1 1 0 */
323 fb
, fb
, 1, -1, "dsp:8[FB]"}, /* 0 0 1 1 1 */
325 a0
, a0
, 1, 2, "dsp:16[A0]"}, /* 0 1 0 0 0 */
327 a1
, a1
, 1, 2, "dsp:16[A1]"}, /* 0 1 0 0 1 */
329 sb
, sb
, 1, 2, "dsp:16[SB]"}, /* 0 1 0 1 0 */
331 fb
, fb
, 1, -2, "dsp:16[FB]"}, /* 0 1 0 1 1 */
333 a0
, a0
, 1, 3, "dsp:24[A0]"}, /* 0 1 1 0 0 */
335 a1
, a1
, 1, 3, "dsp:24[A1]"}, /* 0 1 1 0 1 */
337 mem
, mem
, 1, 3, "abs24"}, /* 0 1 1 1 0 */
339 mem
, mem
, 1, 2, "abs16"}, /* 0 1 1 1 1 */
341 r0h
, r2
, 0, 0, "R0H/R2"}, /* 1 0 0 0 0 */
343 r1h
, r3
, 0, 0, "R1H/R3"}, /* 1 0 0 0 1 */
345 r0l
, r0
, 0, 0, "R0L/R0"}, /* 1 0 0 1 0 */
347 r1l
, r1
, 0, 0, "R1L/R1"}, /* 1 0 0 1 1 */
351 decode_sd23 (int bbb
, int bb
, int bytes
, int ind
, int add
)
354 int code
= (bbb
<< 2) | bb
;
356 if (code
>= sizeof (modes23
) / sizeof (modes23
[0]))
370 sprintf (ad
, "%+d", add
);
374 the_bits
= bits (code
, 4);
375 printf ("decode: %s (%d) : %s%s%s%s\n", the_bits
, code
, b1
,
376 modes23
[code
].name
, ad
, b2
);
381 sd
.mem
= modes23
[code
].is_memory
;
384 if (modes23
[code
].w_regno
== mem
)
387 sd
.u
.addr
= get_reg (modes23
[code
].w_regno
);
388 switch (modes23
[code
].disp_bytes
)
391 sd
.u
.addr
+= disp8 ();
394 sd
.u
.addr
+= disp16 ();
397 sd
.u
.addr
+= sign_ext (disp8 (), 8);
400 sd
.u
.addr
+= sign_ext (disp16 (), 16);
403 sd
.u
.addr
+= disp24 ();
411 sd
.u
.addr
= mem_get_si (sd
.u
.addr
& membus_mask
);
412 sd
.u
.addr
&= membus_mask
;
416 sd
.u
.reg
= (bytes
> 1) ? modes23
[code
].w_regno
: modes23
[code
].b_regno
;
417 if (bytes
== 3 || bytes
== 4)
440 decode_dest23 (int ddd
, int dd
, int bytes
)
442 return decode_sd23 (ddd
, dd
, bytes
, dest_indirect
, dest_addend
);
446 decode_src23 (int sss
, int ss
, int bytes
)
448 return decode_sd23 (sss
, ss
, bytes
, src_indirect
, src_addend
);
452 decode_dest2 (int dd
, int bytes
)
454 /* r0l/r0, abs16, dsp:8[SB], dsp:8[FB] */
455 static char map
[4] = { 0x12, 0x0f, 0x06, 0x07 };
457 the_bits
= bits (dd
, 2);
458 return decode_sd23 (map
[dd
] >> 2, map
[dd
] & 3, bytes
, dest_indirect
,
463 decode_src3 (int sss
, int bytes
)
465 /* r0, r1, a0, a1, r2, r3, N/A, N/A */
466 static char map
[8] = { 0x12, 0x13, 0x02, 0x03, 0x10, 0x11, 0, 0 };
468 the_bits
= bits (sss
, 3);
469 return decode_sd23 (map
[sss
] >> 2, map
[sss
] & 3, bytes
, src_indirect
,
474 decode_dest1 (int destcode
, int bw
)
476 the_bits
= bits (destcode
, 1);
477 return decode_srcdest4 (destcode
, bw
);
481 decode_cr (int crcode
)
483 static int regcode
[] = { 0, intbl
, intbh
, flags
, isp
, sp
, sb
, fb
};
487 sd
.u
.reg
= regcode
[crcode
& 7];
492 decode_cr_b (int crcode
, int bank
)
494 /* FIXME: intbl, intbh, isp */
495 static int regcode
[3][8] = {
496 {0, 0, flags
, 0, 0, 0, 0, 0},
497 {intb
, sp
, sb
, fb
, 0, 0, 0, isp
},
498 {0, 0, 0, 0, 0, 0, 0, 0}
502 sd
.bytes
= bank
? 3 : 2;
503 sd
.u
.reg
= regcode
[bank
][crcode
& 7];
508 widen_sd (srcdest sd
)
540 rv
.bytes
= reg_bytes
[reg
];
555 v
= mem_get_qi (sd
.u
.addr
);
558 v
= mem_get_hi (sd
.u
.addr
);
561 v
= mem_get_psi (sd
.u
.addr
);
564 v
= mem_get_si (sd
.u
.addr
);
572 v
= get_reg (sd
.u
.reg
);
590 put_dest (srcdest sd
, int v
)
597 mem_put_qi (sd
.u
.addr
, v
);
600 mem_put_hi (sd
.u
.addr
, v
);
603 mem_put_psi (sd
.u
.addr
, v
);
606 mem_put_si (sd
.u
.addr
, v
);
624 put_reg (sd
.u
.reg
, v
);
629 decode_bit (int destcode
)
633 static const char *dc_names
[] = { "r0", "r1", "r2", "r3",
634 "a0", "a1", "[a0]", "[a1]",
635 "disp8[a0]", "disp8[a1]", "disp8[sb]", "disp8[fb]",
636 "disp16[a0]", "disp16[a1]", "disp16[sb]", "abs16"
641 const char *the_bits
= bits (destcode
, 4);
642 printf ("decode: %s : %s\n", the_bits
, dc_names
[destcode
]);
672 addr
= get_reg (a0
) + disp8 ();
675 addr
= get_reg (a1
) + disp8 ();
678 addr
= get_reg (sb
) * 8 + disp8 ();
681 addr
= get_reg (fb
) * 8 + sign_ext (disp8 (), 8);
684 addr
= get_reg (a0
) + disp16 ();
687 addr
= get_reg (a1
) + disp16 ();
690 addr
= get_reg (sb
) + disp16 ();
701 sd
.mask
= 1 << (d
& 0x0f);
707 sd
.mask
= 1 << (addr
& 7);
708 sd
.u
.addr
= addr
>> 3;
714 decode_bit11 (int op0
)
717 sd
.mask
= 1 << (op0
& 7);
719 sd
.u
.addr
= get_reg (sb
) + disp8 ();
728 b
= mem_get_qi (sd
.u
.addr
) & sd
.mask
;
730 b
= get_reg (sd
.u
.reg
) & sd
.mask
;
735 put_bit (srcdest sd
, int val
)
739 b
= mem_get_qi (sd
.u
.addr
);
741 b
= get_reg (sd
.u
.reg
);
747 mem_put_qi (sd
.u
.addr
, b
);
749 put_reg (sd
.u
.reg
, b
);
753 get_bit2 (srcdest sd
, int bit
)
757 b
= mem_get_qi (sd
.u
.addr
+ (bit
>> 3)) & (1 << (bit
& 7));
759 b
= get_reg (sd
.u
.reg
) & (1 << bit
);
764 put_bit2 (srcdest sd
, int bit
, int val
)
768 b
= mem_get_qi (sd
.u
.addr
+ (bit
>> 3));
770 b
= get_reg (sd
.u
.reg
);
772 b
|= (1 << (bit
& 7));
774 b
&= ~(1 << (bit
& 7));
776 mem_put_qi (sd
.u
.addr
+ (bit
>> 3), b
);
778 put_reg (sd
.u
.reg
, b
);
This page took 0.045398 seconds and 4 git commands to generate.