1 /* srcdest.c --- decoding M32C addressing modes.
3 Copyright (C) 2005-2014 Free Software Foundation, Inc.
4 Contributed by Red Hat, Inc.
6 This file is part of the GNU simulators.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>. */
28 static int src_indirect
= 0;
29 static int dest_indirect
= 0;
30 static int src_addend
= 0;
31 static int dest_addend
= 0;
41 rv
= mem_get_qi (get_reg (pc
));
55 rv
= mem_get_hi (get_reg (pc
));
69 rv
= mem_get_psi (get_reg (pc
));
78 return disp24 () & 0x000fffff;
89 *--bp
= (v
& 1) ? '1' : '0';
96 static const char *the_bits
= 0;
99 decode_indirect (int si
, int di
)
103 if (trace
&& (si
|| di
))
104 printf ("indirect: s:%d d:%d\n", si
, di
);
108 decode_index (int sa
, int da
)
112 if (trace
&& (sa
|| da
))
113 printf ("index: s:%d d:%d\n", sa
, da
);
117 decode_srcdest4 (int destcode
, int bw
)
120 sd
.bytes
= bw
? 2 : 1;
121 sd
.mem
= (destcode
>= 6) ? 1 : 0;
122 static const char *dc_wnames
[16] = { "r0", "r1", "r2", "r3",
123 "a0", "a1", "[a0]", "[a1]",
124 "disp8[a0]", "disp8[a1]", "disp8[sb]", "disp8[fb]",
125 "disp16[a0]", "disp16[a1]", "disp16[sb]", "disp16"
127 static const char *dc_bnames
[4] = { "r0l", "r0h", "r1l", "r1h" };;
131 const char *n
= dc_wnames
[destcode
];
132 if (bw
== 0 && destcode
<= 3)
133 n
= dc_bnames
[destcode
];
135 the_bits
= bits (destcode
, 4);
136 printf ("decode: %s (%d) : %s\n", the_bits
, destcode
, n
);
143 sd
.u
.reg
= bw
? r0
: r0l
;
146 sd
.u
.reg
= bw
? r1
: r0h
;
149 sd
.u
.reg
= bw
? r2
: r1l
;
152 sd
.u
.reg
= bw
? r3
: r1h
;
161 sd
.u
.addr
= get_reg (a0
);
164 sd
.u
.addr
= get_reg (a1
);
167 sd
.u
.addr
= get_reg (a0
) + disp8 ();
170 sd
.u
.addr
= get_reg (a1
) + disp8 ();
173 sd
.u
.addr
= get_reg (sb
) + disp8 ();
176 sd
.u
.addr
= get_reg (fb
) + sign_ext (disp8 (), 8);
179 sd
.u
.addr
= get_reg (a0
) + disp16 ();
182 sd
.u
.addr
= get_reg (a1
) + disp16 ();
185 sd
.u
.addr
= get_reg (sb
) + disp16 ();
188 sd
.u
.addr
= disp16 ();
194 sd
.u
.addr
&= addr_mask
;
199 decode_jumpdest (int destcode
, int w
)
202 sd
.bytes
= w
? 2 : 3;
203 sd
.mem
= (destcode
>= 6) ? 1 : 0;
204 static const char *dc_wnames
[16] = { "r0", "r1", "r2", "r3",
205 "a0", "a1", "[a0]", "[a1]",
206 "disp8[a0]", "disp8[a1]", "disp8[sb]", "disp8[fb]",
207 "disp20[a0]", "disp20[a1]", "disp16[sb]", "abs16"
209 static const char *dc_anames
[4] = { "r0l", "r0h", "r1l", "r1h" };
213 const char *n
= dc_wnames
[destcode
];
214 if (w
== 0 && destcode
<= 3)
215 n
= dc_anames
[destcode
];
217 the_bits
= bits (destcode
, 4);
218 printf ("decode: %s : %s\n", the_bits
, n
);
225 sd
.u
.reg
= w
? r0
: r2r0
;
228 sd
.u
.reg
= w
? r1
: r2r0
;
231 sd
.u
.reg
= w
? r2
: r3r1
;
234 sd
.u
.reg
= w
? r3
: r3r1
;
237 sd
.u
.reg
= w
? a0
: a1a0
;
240 sd
.u
.reg
= w
? a1
: a1a0
;
243 sd
.u
.addr
= get_reg (a0
);
246 sd
.u
.addr
= get_reg (a1
);
249 sd
.u
.addr
= get_reg (a0
) + disp8 ();
252 sd
.u
.addr
= get_reg (a1
) + disp8 ();
255 sd
.u
.addr
= get_reg (sb
) + disp8 ();
258 sd
.u
.addr
= get_reg (fb
) + sign_ext (disp8 (), 8);
261 sd
.u
.addr
= get_reg (a0
) + disp20 ();
264 sd
.u
.addr
= get_reg (a1
) + disp20 ();
267 sd
.u
.addr
= get_reg (sb
) + disp16 ();
270 sd
.u
.addr
= disp16 ();
276 sd
.u
.addr
&= addr_mask
;
281 decode_dest3 (int destcode
, int bw
)
283 static char map
[8] = { -1, -1, -1, 1, 0, 10, 11, 15 };
285 the_bits
= bits (destcode
, 3);
286 return decode_srcdest4 (map
[destcode
], bw
);
290 decode_src2 (int srccode
, int bw
, int d
)
292 static char map
[4] = { 0, 10, 11, 15 };
294 the_bits
= bits (srccode
, 2);
295 return decode_srcdest4 (srccode
? map
[srccode
] : 1 - d
, bw
);
308 a0
, a0
, 1, 0, "[A0]"}, /* 0 0 0 0 0 */
310 a1
, a1
, 1, 0, "[A1]"}, /* 0 0 0 0 1 */
312 a0
, a0
, 0, 0, "A0"}, /* 0 0 0 1 0 */
314 a1
, a1
, 0, 0, "A1"}, /* 0 0 0 1 1 */
316 a0
, a0
, 1, 1, "dsp:8[A0]"}, /* 0 0 1 0 0 */
318 a1
, a1
, 1, 1, "dsp:8[A1]"}, /* 0 0 1 0 1 */
320 sb
, sb
, 1, 1, "dsp:8[SB]"}, /* 0 0 1 1 0 */
322 fb
, fb
, 1, -1, "dsp:8[FB]"}, /* 0 0 1 1 1 */
324 a0
, a0
, 1, 2, "dsp:16[A0]"}, /* 0 1 0 0 0 */
326 a1
, a1
, 1, 2, "dsp:16[A1]"}, /* 0 1 0 0 1 */
328 sb
, sb
, 1, 2, "dsp:16[SB]"}, /* 0 1 0 1 0 */
330 fb
, fb
, 1, -2, "dsp:16[FB]"}, /* 0 1 0 1 1 */
332 a0
, a0
, 1, 3, "dsp:24[A0]"}, /* 0 1 1 0 0 */
334 a1
, a1
, 1, 3, "dsp:24[A1]"}, /* 0 1 1 0 1 */
336 mem
, mem
, 1, 3, "abs24"}, /* 0 1 1 1 0 */
338 mem
, mem
, 1, 2, "abs16"}, /* 0 1 1 1 1 */
340 r0h
, r2
, 0, 0, "R0H/R2"}, /* 1 0 0 0 0 */
342 r1h
, r3
, 0, 0, "R1H/R3"}, /* 1 0 0 0 1 */
344 r0l
, r0
, 0, 0, "R0L/R0"}, /* 1 0 0 1 0 */
346 r1l
, r1
, 0, 0, "R1L/R1"}, /* 1 0 0 1 1 */
350 decode_sd23 (int bbb
, int bb
, int bytes
, int ind
, int add
)
353 int code
= (bbb
<< 2) | bb
;
355 if (code
>= sizeof (modes23
) / sizeof (modes23
[0]))
369 sprintf (ad
, "%+d", add
);
373 the_bits
= bits (code
, 4);
374 printf ("decode: %s (%d) : %s%s%s%s\n", the_bits
, code
, b1
,
375 modes23
[code
].name
, ad
, b2
);
380 sd
.mem
= modes23
[code
].is_memory
;
383 if (modes23
[code
].w_regno
== mem
)
386 sd
.u
.addr
= get_reg (modes23
[code
].w_regno
);
387 switch (modes23
[code
].disp_bytes
)
390 sd
.u
.addr
+= disp8 ();
393 sd
.u
.addr
+= disp16 ();
396 sd
.u
.addr
+= sign_ext (disp8 (), 8);
399 sd
.u
.addr
+= sign_ext (disp16 (), 16);
402 sd
.u
.addr
+= disp24 ();
410 sd
.u
.addr
= mem_get_si (sd
.u
.addr
& membus_mask
);
411 sd
.u
.addr
&= membus_mask
;
415 sd
.u
.reg
= (bytes
> 1) ? modes23
[code
].w_regno
: modes23
[code
].b_regno
;
416 if (bytes
== 3 || bytes
== 4)
439 decode_dest23 (int ddd
, int dd
, int bytes
)
441 return decode_sd23 (ddd
, dd
, bytes
, dest_indirect
, dest_addend
);
445 decode_src23 (int sss
, int ss
, int bytes
)
447 return decode_sd23 (sss
, ss
, bytes
, src_indirect
, src_addend
);
451 decode_dest2 (int dd
, int bytes
)
453 /* r0l/r0, abs16, dsp:8[SB], dsp:8[FB] */
454 static char map
[4] = { 0x12, 0x0f, 0x06, 0x07 };
456 the_bits
= bits (dd
, 2);
457 return decode_sd23 (map
[dd
] >> 2, map
[dd
] & 3, bytes
, dest_indirect
,
462 decode_src3 (int sss
, int bytes
)
464 /* r0, r1, a0, a1, r2, r3, N/A, N/A */
465 static char map
[8] = { 0x12, 0x13, 0x02, 0x03, 0x10, 0x11, 0, 0 };
467 the_bits
= bits (sss
, 3);
468 return decode_sd23 (map
[sss
] >> 2, map
[sss
] & 3, bytes
, src_indirect
,
473 decode_dest1 (int destcode
, int bw
)
475 the_bits
= bits (destcode
, 1);
476 return decode_srcdest4 (destcode
, bw
);
480 decode_cr (int crcode
)
482 static int regcode
[] = { 0, intbl
, intbh
, flags
, isp
, sp
, sb
, fb
};
486 sd
.u
.reg
= regcode
[crcode
& 7];
491 decode_cr_b (int crcode
, int bank
)
493 /* FIXME: intbl, intbh, isp */
494 static int regcode
[3][8] = {
495 {0, 0, flags
, 0, 0, 0, 0, 0},
496 {intb
, sp
, sb
, fb
, 0, 0, 0, isp
},
497 {0, 0, 0, 0, 0, 0, 0, 0}
501 sd
.bytes
= bank
? 3 : 2;
502 sd
.u
.reg
= regcode
[bank
][crcode
& 7];
507 widen_sd (srcdest sd
)
539 rv
.bytes
= reg_bytes
[reg
];
554 v
= mem_get_qi (sd
.u
.addr
);
557 v
= mem_get_hi (sd
.u
.addr
);
560 v
= mem_get_psi (sd
.u
.addr
);
563 v
= mem_get_si (sd
.u
.addr
);
571 v
= get_reg (sd
.u
.reg
);
589 put_dest (srcdest sd
, int v
)
596 mem_put_qi (sd
.u
.addr
, v
);
599 mem_put_hi (sd
.u
.addr
, v
);
602 mem_put_psi (sd
.u
.addr
, v
);
605 mem_put_si (sd
.u
.addr
, v
);
623 put_reg (sd
.u
.reg
, v
);
628 decode_bit (int destcode
)
632 static const char *dc_names
[] = { "r0", "r1", "r2", "r3",
633 "a0", "a1", "[a0]", "[a1]",
634 "disp8[a0]", "disp8[a1]", "disp8[sb]", "disp8[fb]",
635 "disp16[a0]", "disp16[a1]", "disp16[sb]", "abs16"
640 const char *the_bits
= bits (destcode
, 4);
641 printf ("decode: %s : %s\n", the_bits
, dc_names
[destcode
]);
671 addr
= get_reg (a0
) + disp8 ();
674 addr
= get_reg (a1
) + disp8 ();
677 addr
= get_reg (sb
) * 8 + disp8 ();
680 addr
= get_reg (fb
) * 8 + sign_ext (disp8 (), 8);
683 addr
= get_reg (a0
) + disp16 ();
686 addr
= get_reg (a1
) + disp16 ();
689 addr
= get_reg (sb
) + disp16 ();
700 sd
.mask
= 1 << (d
& 0x0f);
706 sd
.mask
= 1 << (addr
& 7);
707 sd
.u
.addr
= addr
>> 3;
713 decode_bit11 (int op0
)
716 sd
.mask
= 1 << (op0
& 7);
718 sd
.u
.addr
= get_reg (sb
) + disp8 ();
727 b
= mem_get_qi (sd
.u
.addr
) & sd
.mask
;
729 b
= get_reg (sd
.u
.reg
) & sd
.mask
;
734 put_bit (srcdest sd
, int val
)
738 b
= mem_get_qi (sd
.u
.addr
);
740 b
= get_reg (sd
.u
.reg
);
746 mem_put_qi (sd
.u
.addr
, b
);
748 put_reg (sd
.u
.reg
, b
);
752 get_bit2 (srcdest sd
, int bit
)
756 b
= mem_get_qi (sd
.u
.addr
+ (bit
>> 3)) & (1 << (bit
& 7));
758 b
= get_reg (sd
.u
.reg
) & (1 << bit
);
763 put_bit2 (srcdest sd
, int bit
, int val
)
767 b
= mem_get_qi (sd
.u
.addr
+ (bit
>> 3));
769 b
= get_reg (sd
.u
.reg
);
771 b
|= (1 << (bit
& 7));
773 b
&= ~(1 << (bit
& 7));
775 mem_put_qi (sd
.u
.addr
+ (bit
>> 3), b
);
777 put_reg (sd
.u
.reg
, b
);
This page took 0.046594 seconds and 4 git commands to generate.