1 /* srcdest.c --- decoding M32C addressing modes.
3 Copyright (C) 2005 Free Software Foundation, Inc.
4 Contributed by Red Hat, Inc.
6 This file is part of the GNU simulators.
8 The GNU simulators are free software; you can redistribute them and/or
9 modify them under the terms of the GNU General Public License as
10 published by the Free Software Foundation; either version 2 of the
11 License, or (at your option) any later version.
13 The GNU simulators are distributed in the hope that they will be
14 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with the GNU simulators; if not, write to the Free Software
20 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
30 static int src_indirect
= 0;
31 static int dest_indirect
= 0;
32 static int src_addend
= 0;
33 static int dest_addend
= 0;
43 rv
= mem_get_qi (get_reg (pc
));
57 rv
= mem_get_hi (get_reg (pc
));
71 rv
= mem_get_psi (get_reg (pc
));
80 return disp24 () & 0x000fffff;
91 *--bp
= (v
& 1) ? '1' : '0';
98 static const char *the_bits
= 0;
101 decode_indirect (int si
, int di
)
105 if (trace
&& (si
|| di
))
106 printf ("indirect: s:%d d:%d\n", si
, di
);
110 decode_index (int sa
, int da
)
114 if (trace
&& (sa
|| da
))
115 printf ("index: s:%d d:%d\n", sa
, da
);
119 decode_srcdest4 (int destcode
, int bw
)
122 sd
.bytes
= bw
? 2 : 1;
123 sd
.mem
= (destcode
>= 6) ? 1 : 0;
124 static const char *dc_wnames
[16] = { "r0", "r1", "r2", "r3",
125 "a0", "a1", "[a0]", "[a1]",
126 "disp8[a0]", "disp8[a1]", "disp8[sb]", "disp8[fb]",
127 "disp16[a0]", "disp16[a1]", "disp16[sb]", "disp16"
129 static const char *dc_bnames
[4] = { "r0l", "r0h", "r1l", "r1h" };;
133 const char *n
= dc_wnames
[destcode
];
134 if (bw
== 0 && destcode
<= 3)
135 n
= dc_bnames
[destcode
];
137 the_bits
= bits (destcode
, 4);
138 printf ("decode: %s (%d) : %s\n", the_bits
, destcode
, n
);
145 sd
.u
.reg
= bw
? r0
: r0l
;
148 sd
.u
.reg
= bw
? r1
: r0h
;
151 sd
.u
.reg
= bw
? r2
: r1l
;
154 sd
.u
.reg
= bw
? r3
: r1h
;
163 sd
.u
.addr
= get_reg (a0
);
166 sd
.u
.addr
= get_reg (a1
);
169 sd
.u
.addr
= get_reg (a0
) + disp8 ();
172 sd
.u
.addr
= get_reg (a1
) + disp8 ();
175 sd
.u
.addr
= get_reg (sb
) + disp8 ();
178 sd
.u
.addr
= get_reg (fb
) + sign_ext (disp8 (), 8);
181 sd
.u
.addr
= get_reg (a0
) + disp16 ();
184 sd
.u
.addr
= get_reg (a1
) + disp16 ();
187 sd
.u
.addr
= get_reg (sb
) + disp16 ();
190 sd
.u
.addr
= disp16 ();
196 sd
.u
.addr
&= addr_mask
;
201 decode_jumpdest (int destcode
, int w
)
204 sd
.bytes
= w
? 2 : 3;
205 sd
.mem
= (destcode
>= 6) ? 1 : 0;
206 static const char *dc_wnames
[16] = { "r0", "r1", "r2", "r3",
207 "a0", "a1", "[a0]", "[a1]",
208 "disp8[a0]", "disp8[a1]", "disp8[sb]", "disp8[fb]",
209 "disp20[a0]", "disp20[a1]", "disp16[sb]", "abs16"
211 static const char *dc_anames
[4] = { "r0l", "r0h", "r1l", "r1h" };
215 const char *n
= dc_wnames
[destcode
];
216 if (w
== 0 && destcode
<= 3)
217 n
= dc_anames
[destcode
];
219 the_bits
= bits (destcode
, 4);
220 printf ("decode: %s : %s\n", the_bits
, n
);
227 sd
.u
.reg
= w
? r0
: r2r0
;
230 sd
.u
.reg
= w
? r1
: r2r0
;
233 sd
.u
.reg
= w
? r2
: r3r1
;
236 sd
.u
.reg
= w
? r3
: r3r1
;
239 sd
.u
.reg
= w
? a0
: a1a0
;
242 sd
.u
.reg
= w
? a1
: a1a0
;
245 sd
.u
.addr
= get_reg (a0
);
248 sd
.u
.addr
= get_reg (a1
);
251 sd
.u
.addr
= get_reg (a0
) + disp8 ();
254 sd
.u
.addr
= get_reg (a1
) + disp8 ();
257 sd
.u
.addr
= get_reg (sb
) + disp8 ();
260 sd
.u
.addr
= get_reg (fb
) + sign_ext (disp8 (), 8);
263 sd
.u
.addr
= get_reg (a0
) + disp20 ();
266 sd
.u
.addr
= get_reg (a1
) + disp20 ();
269 sd
.u
.addr
= get_reg (sb
) + disp16 ();
272 sd
.u
.addr
= disp16 ();
278 sd
.u
.addr
&= addr_mask
;
283 decode_dest3 (int destcode
, int bw
)
285 static char map
[8] = { -1, -1, -1, 1, 0, 10, 11, 15 };
287 the_bits
= bits (destcode
, 3);
288 return decode_srcdest4 (map
[destcode
], bw
);
292 decode_src2 (int srccode
, int bw
, int d
)
294 static char map
[4] = { 0, 10, 11, 15 };
296 the_bits
= bits (srccode
, 2);
297 return decode_srcdest4 (srccode
? map
[srccode
] : 1 - d
, bw
);
310 a0
, a0
, 1, 0, "[A0]"}, /* 0 0 0 0 0 */
312 a1
, a1
, 1, 0, "[A1]"}, /* 0 0 0 0 1 */
314 a0
, a0
, 0, 0, "A0"}, /* 0 0 0 1 0 */
316 a1
, a1
, 0, 0, "A1"}, /* 0 0 0 1 1 */
318 a0
, a0
, 1, 1, "dsp:8[A0]"}, /* 0 0 1 0 0 */
320 a1
, a1
, 1, 1, "dsp:8[A1]"}, /* 0 0 1 0 1 */
322 sb
, sb
, 1, 1, "dsp:8[SB]"}, /* 0 0 1 1 0 */
324 fb
, fb
, 1, -1, "dsp:8[FB]"}, /* 0 0 1 1 1 */
326 a0
, a0
, 1, 2, "dsp:16[A0]"}, /* 0 1 0 0 0 */
328 a1
, a1
, 1, 2, "dsp:16[A1]"}, /* 0 1 0 0 1 */
330 sb
, sb
, 1, 2, "dsp:16[SB]"}, /* 0 1 0 1 0 */
332 fb
, fb
, 1, -2, "dsp:16[FB]"}, /* 0 1 0 1 1 */
334 a0
, a0
, 1, 3, "dsp:24[A0]"}, /* 0 1 1 0 0 */
336 a1
, a1
, 1, 3, "dsp:24[A1]"}, /* 0 1 1 0 1 */
338 mem
, mem
, 1, 3, "abs24"}, /* 0 1 1 1 0 */
340 mem
, mem
, 1, 2, "abs16"}, /* 0 1 1 1 1 */
342 r0h
, r2
, 0, 0, "R0H/R2"}, /* 1 0 0 0 0 */
344 r1h
, r3
, 0, 0, "R1H/R3"}, /* 1 0 0 0 1 */
346 r0l
, r0
, 0, 0, "R0L/R0"}, /* 1 0 0 1 0 */
348 r1l
, r1
, 0, 0, "R1L/R1"}, /* 1 0 0 1 1 */
352 decode_sd23 (int bbb
, int bb
, int bytes
, int ind
, int add
)
355 int code
= (bbb
<< 2) | bb
;
357 if (code
>= sizeof (modes23
) / sizeof (modes23
[0]))
371 sprintf (ad
, "%+d", add
);
375 the_bits
= bits (code
, 4);
376 printf ("decode: %s (%d) : %s%s%s%s\n", the_bits
, code
, b1
,
377 modes23
[code
].name
, ad
, b2
);
382 sd
.mem
= modes23
[code
].is_memory
;
385 if (modes23
[code
].w_regno
== mem
)
388 sd
.u
.addr
= get_reg (modes23
[code
].w_regno
);
389 switch (modes23
[code
].disp_bytes
)
392 sd
.u
.addr
+= disp8 ();
395 sd
.u
.addr
+= disp16 ();
398 sd
.u
.addr
+= sign_ext (disp8 (), 8);
401 sd
.u
.addr
+= sign_ext (disp16 (), 16);
404 sd
.u
.addr
+= disp24 ();
412 sd
.u
.addr
= mem_get_si (sd
.u
.addr
& membus_mask
);
413 sd
.u
.addr
&= membus_mask
;
417 sd
.u
.reg
= (bytes
> 1) ? modes23
[code
].w_regno
: modes23
[code
].b_regno
;
418 if (bytes
== 3 || bytes
== 4)
441 decode_dest23 (int ddd
, int dd
, int bytes
)
443 return decode_sd23 (ddd
, dd
, bytes
, dest_indirect
, dest_addend
);
447 decode_src23 (int sss
, int ss
, int bytes
)
449 return decode_sd23 (sss
, ss
, bytes
, src_indirect
, src_addend
);
453 decode_dest2 (int dd
, int bytes
)
455 /* r0l/r0, abs16, dsp:8[SB], dsp:8[FB] */
456 static char map
[4] = { 0x12, 0x0f, 0x06, 0x07 };
458 the_bits
= bits (dd
, 2);
459 return decode_sd23 (map
[dd
] >> 2, map
[dd
] & 3, bytes
, dest_indirect
,
464 decode_src3 (int sss
, int bytes
)
466 /* r0, r1, a0, a1, r2, r3, N/A, N/A */
467 static char map
[8] = { 0x12, 0x13, 0x02, 0x03, 0x10, 0x11, 0, 0 };
469 the_bits
= bits (sss
, 3);
470 return decode_sd23 (map
[sss
] >> 2, map
[sss
] & 3, bytes
, src_indirect
,
475 decode_dest1 (int destcode
, int bw
)
477 the_bits
= bits (destcode
, 1);
478 return decode_srcdest4 (destcode
, bw
);
482 decode_cr (int crcode
)
484 static int regcode
[] = { 0, intbl
, intbh
, flags
, isp
, sp
, sb
, fb
};
488 sd
.u
.reg
= regcode
[crcode
& 7];
493 decode_cr_b (int crcode
, int bank
)
495 /* FIXME: intbl, intbh, isp */
496 static int regcode
[3][8] = {
497 {0, 0, flags
, 0, 0, 0, 0, 0},
498 {intb
, sp
, sb
, fb
, 0, 0, 0, isp
},
499 {0, 0, 0, 0, 0, 0, 0, 0}
503 sd
.bytes
= bank
? 3 : 2;
504 sd
.u
.reg
= regcode
[bank
][crcode
& 7];
509 widen_sd (srcdest sd
)
541 rv
.bytes
= reg_bytes
[reg
];
556 v
= mem_get_qi (sd
.u
.addr
);
559 v
= mem_get_hi (sd
.u
.addr
);
562 v
= mem_get_psi (sd
.u
.addr
);
565 v
= mem_get_si (sd
.u
.addr
);
573 v
= get_reg (sd
.u
.reg
);
591 put_dest (srcdest sd
, int v
)
598 mem_put_qi (sd
.u
.addr
, v
);
601 mem_put_hi (sd
.u
.addr
, v
);
604 mem_put_psi (sd
.u
.addr
, v
);
607 mem_put_si (sd
.u
.addr
, v
);
625 put_reg (sd
.u
.reg
, v
);
630 decode_bit (int destcode
)
634 static const char *dc_names
[] = { "r0", "r1", "r2", "r3",
635 "a0", "a1", "[a0]", "[a1]",
636 "disp8[a0]", "disp8[a1]", "disp8[sb]", "disp8[fb]",
637 "disp16[a0]", "disp16[a1]", "disp16[sb]", "abs16"
642 const char *the_bits
= bits (destcode
, 4);
643 printf ("decode: %s : %s\n", the_bits
, dc_names
[destcode
]);
673 addr
= get_reg (a0
) + disp8 ();
676 addr
= get_reg (a1
) + disp8 ();
679 addr
= get_reg (sb
) * 8 + disp8 ();
682 addr
= get_reg (fb
) * 8 + sign_ext (disp8 (), 8);
685 addr
= get_reg (a0
) + disp16 ();
688 addr
= get_reg (a1
) + disp16 ();
691 addr
= get_reg (sb
) + disp16 ();
702 sd
.mask
= 1 << (d
& 0x0f);
708 sd
.mask
= 1 << (addr
& 7);
709 sd
.u
.addr
= addr
>> 3;
715 decode_bit11 (int op0
)
718 sd
.mask
= 1 << (op0
& 7);
720 sd
.u
.addr
= get_reg (sb
) + disp8 ();
729 b
= mem_get_qi (sd
.u
.addr
) & sd
.mask
;
731 b
= get_reg (sd
.u
.reg
) & sd
.mask
;
736 put_bit (srcdest sd
, int val
)
740 b
= mem_get_qi (sd
.u
.addr
);
742 b
= get_reg (sd
.u
.reg
);
748 mem_put_qi (sd
.u
.addr
, b
);
750 put_reg (sd
.u
.reg
, b
);
754 get_bit2 (srcdest sd
, int bit
)
758 b
= mem_get_qi (sd
.u
.addr
+ (bit
>> 3)) & (1 << (bit
& 7));
760 b
= get_reg (sd
.u
.reg
) & (1 << bit
);
765 put_bit2 (srcdest sd
, int bit
, int val
)
769 b
= mem_get_qi (sd
.u
.addr
+ (bit
>> 3));
771 b
= get_reg (sd
.u
.reg
);
773 b
|= (1 << (bit
& 7));
775 b
&= ~(1 << (bit
& 7));
777 mem_put_qi (sd
.u
.addr
+ (bit
>> 3), b
);
779 put_reg (sd
.u
.reg
, b
);