1 /* reg.c --- register set model for M32C simulator.
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/>. */
30 int enable_counting
= 0;
34 int addr_mask
= 0xffff;
35 int membus_mask
= 0xfffff;
38 unsigned int heapbottom
= 0;
39 unsigned int heaptop
= 0;
52 "intb", "intbl", "intbh",
53 "sp", "usp", "isp", "pc", "flags"
72 unsigned int b2mask
[] = { 0, 0xff, 0xffff, 0xffffff, 0xffffffff };
73 unsigned int b2signbit
[] = { 0, (1 << 7), (1 << 15), (1 << 24), (1 << 31) };
74 int b2maxsigned
[] = { 0, 0x7f, 0x7fff, 0x7fffff, 0x7fffffff };
75 int b2minsigned
[] = { 0, -128, -32768, -8388608, -2147483647 - 1 };
77 static regs_type oldregs
;
84 memset (®s
, 0, sizeof (regs
));
85 memset (&oldregs
, 0, sizeof (oldregs
));
89 set_pointer_width (int bytes
)
94 membus_mask
= 0x000fffff;
95 reg_bytes
[a0
] = reg_bytes
[a1
] = reg_bytes
[sb
] = reg_bytes
[fb
] =
96 reg_bytes
[sp
] = reg_bytes
[usp
] = reg_bytes
[isp
] = 2;
100 addr_mask
= 0xffffff;
101 membus_mask
= 0x00ffffff;
102 reg_bytes
[a0
] = reg_bytes
[a1
] = reg_bytes
[sb
] = reg_bytes
[fb
] =
103 reg_bytes
[sp
] = reg_bytes
[usp
] = reg_bytes
[isp
] = 3;
108 m32c_set_cpu (int cpu
)
114 set_pointer_width (2);
115 decode_opcode
= decode_r8c
;
119 set_pointer_width (3);
120 decode_opcode
= decode_m32c
;
129 get_reg_i (reg_id id
)
131 reg_bank_type
*b
= regs
.r
+ (FLAG_B
? 1 : 0);
140 return b
->r_r0
& 0xff;
146 return b
->r_r1
& 0xff;
150 return b
->r_r2
* 65536 + b
->r_r0
;
154 return b
->r_r3
* 65536 + b
->r_r1
;
157 return b
->r_a0
& addr_mask
;
159 return b
->r_a1
& addr_mask
;
161 return (b
->r_a1
& 0xffff) * 65536 | (b
->r_a0
& 0xffff);
164 return b
->r_sb
& addr_mask
;
166 return b
->r_fb
& addr_mask
;
169 return regs
.r_intbh
* 65536 + regs
.r_intbl
;
176 return ((regs
.r_flags
& FLAGBIT_U
) ? regs
.r_usp
: regs
.
179 return regs
.r_usp
& addr_mask
;
181 return regs
.r_isp
& addr_mask
;
184 return regs
.r_pc
& membus_mask
;
195 unsigned int rv
= get_reg_i (id
);
196 if (trace
> ((id
!= pc
&& id
!= fb
&& id
!= sp
) ? 0 : 1))
197 printf ("get_reg (%s) = %0*x\n", reg_names
[id
], reg_bytes
[id
] * 2, rv
);
202 get_reg_ll (reg_id id
)
204 reg_bank_type
*b
= regs
.r
+ (FLAG_B
? 1 : 0);
209 return ((DI
) b
->r_r3
<< 48
210 | (DI
) b
->r_r1
<< 32 | (DI
) b
->r_r2
<< 16 | (DI
) b
->r_r0
);
212 return ((DI
) b
->r_r3
<< 48
213 | (DI
) b
->r_r2
<< 32 | (DI
) b
->r_r1
<< 16 | (DI
) b
->r_r0
);
219 static int highest_sp
= 0, lowest_sp
= 0xffffff;
224 printf ("heap: %08x - %08x (%d bytes)\n", heapbottom
, heaptop
,
225 heaptop
- heapbottom
);
226 printf ("stack: %08x - %08x (%d bytes)\n", lowest_sp
, highest_sp
,
227 highest_sp
- lowest_sp
);
231 put_reg (reg_id id
, unsigned int v
)
233 if (trace
> ((id
!= pc
) ? 0 : 1))
234 printf ("put_reg (%s) = %0*x\n", reg_names
[id
], reg_bytes
[id
] * 2, v
);
236 reg_bank_type
*b
= regs
.r
+ (FLAG_B
? 1 : 0);
243 b
->r_r0
= (b
->r_r0
& 0xff) | (v
<< 8);
246 b
->r_r0
= (b
->r_r0
& 0xff00) | (v
& 0xff);
252 b
->r_r1
= (b
->r_r1
& 0xff) | (v
<< 8);
255 b
->r_r1
= (b
->r_r1
& 0xff00) | (v
& 0xff);
261 b
->r_r0
= v
& 0xffff;
268 b
->r_r1
= v
& 0xffff;
273 b
->r_a0
= v
& addr_mask
;
276 b
->r_a1
= v
& addr_mask
;
279 b
->r_a0
= v
& 0xffff;
284 b
->r_sb
= v
& addr_mask
;
287 b
->r_fb
= v
& addr_mask
;
291 regs
.r_intbl
= v
& 0xffff;
292 regs
.r_intbh
= v
>> 16;
295 regs
.r_intbl
= v
& 0xffff;
298 regs
.r_intbh
= v
& 0xff;
304 if (regs
.r_flags
& FLAGBIT_U
)
308 *spp
= v
& addr_mask
;
311 printf ("collision: pc %08lx heap %08x stack %08lx\n", regs
.r_pc
,
315 if (*spp
< lowest_sp
)
317 if (*spp
> highest_sp
)
322 regs
.r_usp
= v
& addr_mask
;
325 regs
.r_isp
= v
& addr_mask
;
329 regs
.r_pc
= v
& membus_mask
;
340 condition_true (int cond_id
)
345 static const char *cond_name
[] = {
346 "C", "C&!Z", "Z", "S",
347 "!C", "!(C&!Z)", "!Z", "!S",
348 "(S^O)|Z", "O", "!(S^O)", "unk",
349 "!((S^O)|Z)", "!O", "S^O", "unk"
351 switch (cond_id
& 15)
357 f
= FLAG_C
& !FLAG_Z
;
369 f
= !(FLAG_C
& !FLAG_Z
);
379 f
= (FLAG_S
^ FLAG_O
) | FLAG_Z
;
385 f
= !(FLAG_S
^ FLAG_O
);
388 f
= !((FLAG_S
^ FLAG_O
) | FLAG_Z
);
402 printf ("cond[%d] %s = %s\n", cond_id
, cond_name
[cond_id
& 15],
403 f
? "true" : "false");
407 static const char *cond_name
[] = {
408 "!C", "LEU", "!Z", "PZ",
409 "!O", "GT", "GE", "?",
410 "C", "GTU", "Z", "N",
411 "O", "LE", "LT", "!?"
413 switch (cond_id
& 15)
419 f
= !(FLAG_C
& !FLAG_Z
);
432 f
= !((FLAG_S
^ FLAG_O
) | FLAG_Z
);
435 f
= !(FLAG_S
^ FLAG_O
);
442 f
= FLAG_C
& !FLAG_Z
;
455 f
= (FLAG_S
^ FLAG_O
) | FLAG_Z
;
466 printf ("cond[%d] %s = %s\n", cond_id
, cond_name
[cond_id
& 15],
467 f
? "true" : "false");
473 set_flags (int mask
, int newbits
)
476 regs
.r_flags
&= ~mask
;
477 regs
.r_flags
|= newbits
& mask
;
480 printf ("flags now \033[32m %d", (regs
.r_flags
>> (A16
? 8 : 12)) & 7);
481 for (i
= 7; i
>= 0; i
--)
482 if (regs
.r_flags
& (1 << i
))
483 putchar ("CDZSBOIU"[i
]);
486 printf ("\033[0m\n");
491 set_oszc (int value
, int b
, int c
)
493 int mask
= b2mask
[b
];
498 if ((value
& mask
) == 0)
500 if (value
& b2signbit
[b
])
502 if ((value
> b2maxsigned
[b
]) || (value
< b2minsigned
[b
]))
504 set_flags (FLAGBIT_Z
| FLAGBIT_S
| FLAGBIT_O
| FLAGBIT_C
, f
);
508 set_szc (int value
, int b
, int c
)
510 int mask
= b2mask
[b
];
515 if ((value
& mask
) == 0)
517 if (value
& b2signbit
[b
])
519 set_flags (FLAGBIT_Z
| FLAGBIT_S
| FLAGBIT_C
, f
);
523 set_osz (int value
, int b
)
525 int mask
= b2mask
[b
];
528 if ((value
& mask
) == 0)
530 if (value
& b2signbit
[b
])
532 if (value
& ~mask
&& (value
& ~mask
) != ~mask
)
534 set_flags (FLAGBIT_Z
| FLAGBIT_S
| FLAGBIT_O
, f
);
538 set_sz (int value
, int b
)
540 int mask
= b2mask
[b
];
543 if ((value
& mask
) == 0)
545 if (value
& b2signbit
[b
])
547 set_flags (FLAGBIT_Z
| FLAGBIT_S
, f
);
551 set_zc (int z
, int c
)
553 set_flags (FLAGBIT_C
| FLAGBIT_Z
,
554 (c
? FLAGBIT_C
: 0) | (z
? FLAGBIT_Z
: 0));
560 set_flags (FLAGBIT_C
, c
? FLAGBIT_C
: 0);
564 put_reg_ll (reg_id id
, DI v
)
566 reg_bank_type
*b
= regs
.r
+ (FLAG_B
? 1 : 0);
591 static char fn
[] = "CDZSBOIU";
592 printf ("%d.", (f
>> 12) & 7);
593 for (i
= 7; i
>= 0; i
--)
598 #define TRC(f,n, id) \
599 if (oldregs.f != regs.f) \
601 printf(" %s %0*x:%0*x", n, \
602 reg_bytes[id]*2, (unsigned int)oldregs.f, \
603 reg_bytes[id]*2, (unsigned int)regs.f); \
604 oldregs.f = regs.f; \
608 trace_register_changes ()
612 printf ("\033[36mREGS:");
613 TRC (r
[0].r_r0
, "r0", r0
);
614 TRC (r
[0].r_r1
, "r1", r1
);
615 TRC (r
[0].r_r2
, "r2", r2
);
616 TRC (r
[0].r_r3
, "r3", r3
);
617 TRC (r
[0].r_a0
, "a0", a0
);
618 TRC (r
[0].r_a1
, "a1", a1
);
619 TRC (r
[0].r_sb
, "sb", sb
);
620 TRC (r
[0].r_fb
, "fb", fb
);
621 TRC (r
[1].r_r0
, "r0'", r0
);
622 TRC (r
[1].r_r1
, "r1'", r1
);
623 TRC (r
[1].r_r2
, "r2'", r2
);
624 TRC (r
[1].r_r3
, "r3'", r3
);
625 TRC (r
[1].r_a0
, "a0'", a0
);
626 TRC (r
[1].r_a1
, "a1'", a1
);
627 TRC (r
[1].r_sb
, "sb'", sb
);
628 TRC (r
[1].r_fb
, "fb'", fb
);
629 TRC (r_intbh
, "intbh", intbh
);
630 TRC (r_intbl
, "intbl", intbl
);
631 TRC (r_usp
, "usp", usp
);
632 TRC (r_isp
, "isp", isp
);
633 TRC (r_pc
, "pc", pc
);
634 if (oldregs
.r_flags
!= regs
.r_flags
)
637 print_flags (oldregs
.r_flags
);
639 print_flags (regs
.r_flags
);
641 printf ("\033[0m\n");
644 #define DRC(f, n, id) \
645 printf(" %-3s %0*x", n, \
646 reg_bytes[id]*2, (unsigned int)regs.f); \
649 m32c_dump_all_registers ()
651 printf ("\033[36mREGS:");
652 DRC (r
[0].r_r0
, "r0", r0
);
653 DRC (r
[0].r_r1
, "r1", r1
);
654 DRC (r
[0].r_r2
, "r2", r2
);
655 DRC (r
[0].r_r3
, "r3", r3
);
656 DRC (r
[0].r_a0
, "a0", a0
);
657 DRC (r
[0].r_a1
, "a1", a1
);
658 DRC (r
[0].r_sb
, "sb", sb
);
659 DRC (r
[0].r_fb
, "fb", fb
);
661 DRC (r
[1].r_r0
, "r0'", r0
);
662 DRC (r
[1].r_r1
, "r1'", r1
);
663 DRC (r
[1].r_r2
, "r2'", r2
);
664 DRC (r
[1].r_r3
, "r3'", r3
);
665 DRC (r
[1].r_a0
, "a0'", a0
);
666 DRC (r
[1].r_a1
, "a1'", a1
);
667 DRC (r
[1].r_sb
, "sb'", sb
);
668 DRC (r
[1].r_fb
, "fb'", fb
);
670 DRC (r_intbh
, "intbh", intbh
);
671 DRC (r_intbl
, "intbl", intbl
);
672 DRC (r_usp
, "usp", usp
);
673 DRC (r_isp
, "isp", isp
);
674 DRC (r_pc
, "pc", pc
);
676 print_flags (regs
.r_flags
);
677 printf ("\033[0m\n");
678 /*sim_disasm_one (); */
This page took 0.044077 seconds and 4 git commands to generate.