1 /* reg.c --- register set model for M32C simulator.
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/>. */
31 int enable_counting
= 0;
35 int addr_mask
= 0xffff;
36 int membus_mask
= 0xfffff;
39 unsigned int heapbottom
= 0;
40 unsigned int heaptop
= 0;
53 "intb", "intbl", "intbh",
54 "sp", "usp", "isp", "pc", "flags"
73 unsigned int b2mask
[] = { 0, 0xff, 0xffff, 0xffffff, 0xffffffff };
74 unsigned int b2signbit
[] = { 0, (1 << 7), (1 << 15), (1 << 24), (1 << 31) };
75 int b2maxsigned
[] = { 0, 0x7f, 0x7fff, 0x7fffff, 0x7fffffff };
76 int b2minsigned
[] = { 0, -128, -32768, -8388608, -2147483647 - 1 };
78 static regs_type oldregs
;
85 memset (®s
, 0, sizeof (regs
));
86 memset (&oldregs
, 0, sizeof (oldregs
));
90 set_pointer_width (int bytes
)
95 membus_mask
= 0x000fffff;
96 reg_bytes
[a0
] = reg_bytes
[a1
] = reg_bytes
[sb
] = reg_bytes
[fb
] =
97 reg_bytes
[sp
] = reg_bytes
[usp
] = reg_bytes
[isp
] = 2;
101 addr_mask
= 0xffffff;
102 membus_mask
= 0x00ffffff;
103 reg_bytes
[a0
] = reg_bytes
[a1
] = reg_bytes
[sb
] = reg_bytes
[fb
] =
104 reg_bytes
[sp
] = reg_bytes
[usp
] = reg_bytes
[isp
] = 3;
109 m32c_set_cpu (int cpu
)
115 set_pointer_width (2);
116 decode_opcode
= decode_r8c
;
120 set_pointer_width (3);
121 decode_opcode
= decode_m32c
;
130 get_reg_i (reg_id id
)
132 reg_bank_type
*b
= regs
.r
+ (FLAG_B
? 1 : 0);
141 return b
->r_r0
& 0xff;
147 return b
->r_r1
& 0xff;
151 return b
->r_r2
* 65536 + b
->r_r0
;
155 return b
->r_r3
* 65536 + b
->r_r1
;
158 return b
->r_a0
& addr_mask
;
160 return b
->r_a1
& addr_mask
;
162 return (b
->r_a1
& 0xffff) * 65536 | (b
->r_a0
& 0xffff);
165 return b
->r_sb
& addr_mask
;
167 return b
->r_fb
& addr_mask
;
170 return regs
.r_intbh
* 65536 + regs
.r_intbl
;
177 return ((regs
.r_flags
& FLAGBIT_U
) ? regs
.r_usp
: regs
.
180 return regs
.r_usp
& addr_mask
;
182 return regs
.r_isp
& addr_mask
;
185 return regs
.r_pc
& membus_mask
;
196 unsigned int rv
= get_reg_i (id
);
197 if (trace
> ((id
!= pc
&& id
!= fb
&& id
!= sp
) ? 0 : 1))
198 printf ("get_reg (%s) = %0*x\n", reg_names
[id
], reg_bytes
[id
] * 2, rv
);
203 get_reg_ll (reg_id id
)
205 reg_bank_type
*b
= regs
.r
+ (FLAG_B
? 1 : 0);
210 return ((DI
) b
->r_r3
<< 48
211 | (DI
) b
->r_r1
<< 32 | (DI
) b
->r_r2
<< 16 | (DI
) b
->r_r0
);
213 return ((DI
) b
->r_r3
<< 48
214 | (DI
) b
->r_r2
<< 32 | (DI
) b
->r_r1
<< 16 | (DI
) b
->r_r0
);
220 static int highest_sp
= 0, lowest_sp
= 0xffffff;
225 printf ("heap: %08x - %08x (%d bytes)\n", heapbottom
, heaptop
,
226 heaptop
- heapbottom
);
227 printf ("stack: %08x - %08x (%d bytes)\n", lowest_sp
, highest_sp
,
228 highest_sp
- lowest_sp
);
232 put_reg (reg_id id
, unsigned int v
)
234 if (trace
> ((id
!= pc
) ? 0 : 1))
235 printf ("put_reg (%s) = %0*x\n", reg_names
[id
], reg_bytes
[id
] * 2, v
);
237 reg_bank_type
*b
= regs
.r
+ (FLAG_B
? 1 : 0);
244 b
->r_r0
= (b
->r_r0
& 0xff) | (v
<< 8);
247 b
->r_r0
= (b
->r_r0
& 0xff00) | (v
& 0xff);
253 b
->r_r1
= (b
->r_r1
& 0xff) | (v
<< 8);
256 b
->r_r1
= (b
->r_r1
& 0xff00) | (v
& 0xff);
262 b
->r_r0
= v
& 0xffff;
269 b
->r_r1
= v
& 0xffff;
274 b
->r_a0
= v
& addr_mask
;
277 b
->r_a1
= v
& addr_mask
;
280 b
->r_a0
= v
& 0xffff;
285 b
->r_sb
= v
& addr_mask
;
288 b
->r_fb
= v
& addr_mask
;
292 regs
.r_intbl
= v
& 0xffff;
293 regs
.r_intbh
= v
>> 16;
296 regs
.r_intbl
= v
& 0xffff;
299 regs
.r_intbh
= v
& 0xff;
305 if (regs
.r_flags
& FLAGBIT_U
)
309 *spp
= v
& addr_mask
;
312 printf ("collision: pc %08lx heap %08x stack %08lx\n", regs
.r_pc
,
316 if (*spp
< lowest_sp
)
318 if (*spp
> highest_sp
)
323 regs
.r_usp
= v
& addr_mask
;
326 regs
.r_isp
= v
& addr_mask
;
330 regs
.r_pc
= v
& membus_mask
;
341 condition_true (int cond_id
)
346 static const char *cond_name
[] = {
347 "C", "C&!Z", "Z", "S",
348 "!C", "!(C&!Z)", "!Z", "!S",
349 "(S^O)|Z", "O", "!(S^O)", "unk",
350 "!((S^O)|Z)", "!O", "S^O", "unk"
352 switch (cond_id
& 15)
358 f
= FLAG_C
& !FLAG_Z
;
370 f
= !(FLAG_C
& !FLAG_Z
);
380 f
= (FLAG_S
^ FLAG_O
) | FLAG_Z
;
386 f
= !(FLAG_S
^ FLAG_O
);
389 f
= !((FLAG_S
^ FLAG_O
) | FLAG_Z
);
403 printf ("cond[%d] %s = %s\n", cond_id
, cond_name
[cond_id
& 15],
404 f
? "true" : "false");
408 static const char *cond_name
[] = {
409 "!C", "LEU", "!Z", "PZ",
410 "!O", "GT", "GE", "?",
411 "C", "GTU", "Z", "N",
412 "O", "LE", "LT", "!?"
414 switch (cond_id
& 15)
420 f
= !(FLAG_C
& !FLAG_Z
);
433 f
= !((FLAG_S
^ FLAG_O
) | FLAG_Z
);
436 f
= !(FLAG_S
^ FLAG_O
);
443 f
= FLAG_C
& !FLAG_Z
;
456 f
= (FLAG_S
^ FLAG_O
) | FLAG_Z
;
467 printf ("cond[%d] %s = %s\n", cond_id
, cond_name
[cond_id
& 15],
468 f
? "true" : "false");
474 set_flags (int mask
, int newbits
)
477 regs
.r_flags
&= ~mask
;
478 regs
.r_flags
|= newbits
& mask
;
481 printf ("flags now \033[32m %d", (regs
.r_flags
>> (A16
? 8 : 12)) & 7);
482 for (i
= 7; i
>= 0; i
--)
483 if (regs
.r_flags
& (1 << i
))
484 putchar ("CDZSBOIU"[i
]);
487 printf ("\033[0m\n");
492 set_oszc (int value
, int b
, int c
)
494 int mask
= b2mask
[b
];
499 if ((value
& mask
) == 0)
501 if (value
& b2signbit
[b
])
503 if ((value
> b2maxsigned
[b
]) || (value
< b2minsigned
[b
]))
505 set_flags (FLAGBIT_Z
| FLAGBIT_S
| FLAGBIT_O
| FLAGBIT_C
, f
);
509 set_szc (int value
, int b
, int c
)
511 int mask
= b2mask
[b
];
516 if ((value
& mask
) == 0)
518 if (value
& b2signbit
[b
])
520 set_flags (FLAGBIT_Z
| FLAGBIT_S
| FLAGBIT_C
, f
);
524 set_osz (int value
, int b
)
526 int mask
= b2mask
[b
];
529 if ((value
& mask
) == 0)
531 if (value
& b2signbit
[b
])
533 if (value
& ~mask
&& (value
& ~mask
) != ~mask
)
535 set_flags (FLAGBIT_Z
| FLAGBIT_S
| FLAGBIT_O
, f
);
539 set_sz (int value
, int b
)
541 int mask
= b2mask
[b
];
544 if ((value
& mask
) == 0)
546 if (value
& b2signbit
[b
])
548 set_flags (FLAGBIT_Z
| FLAGBIT_S
, f
);
552 set_zc (int z
, int c
)
554 set_flags (FLAGBIT_C
| FLAGBIT_Z
,
555 (c
? FLAGBIT_C
: 0) | (z
? FLAGBIT_Z
: 0));
561 set_flags (FLAGBIT_C
, c
? FLAGBIT_C
: 0);
565 put_reg_ll (reg_id id
, DI v
)
567 reg_bank_type
*b
= regs
.r
+ (FLAG_B
? 1 : 0);
592 static char fn
[] = "CDZSBOIU";
593 printf ("%d.", (f
>> 12) & 7);
594 for (i
= 7; i
>= 0; i
--)
599 #define TRC(f,n, id) \
600 if (oldregs.f != regs.f) \
602 printf(" %s %0*x:%0*x", n, \
603 reg_bytes[id]*2, (unsigned int)oldregs.f, \
604 reg_bytes[id]*2, (unsigned int)regs.f); \
605 oldregs.f = regs.f; \
609 trace_register_changes ()
613 printf ("\033[36mREGS:");
614 TRC (r
[0].r_r0
, "r0", r0
);
615 TRC (r
[0].r_r1
, "r1", r1
);
616 TRC (r
[0].r_r2
, "r2", r2
);
617 TRC (r
[0].r_r3
, "r3", r3
);
618 TRC (r
[0].r_a0
, "a0", a0
);
619 TRC (r
[0].r_a1
, "a1", a1
);
620 TRC (r
[0].r_sb
, "sb", sb
);
621 TRC (r
[0].r_fb
, "fb", fb
);
622 TRC (r
[1].r_r0
, "r0'", r0
);
623 TRC (r
[1].r_r1
, "r1'", r1
);
624 TRC (r
[1].r_r2
, "r2'", r2
);
625 TRC (r
[1].r_r3
, "r3'", r3
);
626 TRC (r
[1].r_a0
, "a0'", a0
);
627 TRC (r
[1].r_a1
, "a1'", a1
);
628 TRC (r
[1].r_sb
, "sb'", sb
);
629 TRC (r
[1].r_fb
, "fb'", fb
);
630 TRC (r_intbh
, "intbh", intbh
);
631 TRC (r_intbl
, "intbl", intbl
);
632 TRC (r_usp
, "usp", usp
);
633 TRC (r_isp
, "isp", isp
);
634 TRC (r_pc
, "pc", pc
);
635 if (oldregs
.r_flags
!= regs
.r_flags
)
638 print_flags (oldregs
.r_flags
);
640 print_flags (regs
.r_flags
);
642 printf ("\033[0m\n");
645 #define DRC(f, n, id) \
646 printf(" %-3s %0*x", n, \
647 reg_bytes[id]*2, (unsigned int)regs.f); \
650 m32c_dump_all_registers ()
652 printf ("\033[36mREGS:");
653 DRC (r
[0].r_r0
, "r0", r0
);
654 DRC (r
[0].r_r1
, "r1", r1
);
655 DRC (r
[0].r_r2
, "r2", r2
);
656 DRC (r
[0].r_r3
, "r3", r3
);
657 DRC (r
[0].r_a0
, "a0", a0
);
658 DRC (r
[0].r_a1
, "a1", a1
);
659 DRC (r
[0].r_sb
, "sb", sb
);
660 DRC (r
[0].r_fb
, "fb", fb
);
662 DRC (r
[1].r_r0
, "r0'", r0
);
663 DRC (r
[1].r_r1
, "r1'", r1
);
664 DRC (r
[1].r_r2
, "r2'", r2
);
665 DRC (r
[1].r_r3
, "r3'", r3
);
666 DRC (r
[1].r_a0
, "a0'", a0
);
667 DRC (r
[1].r_a1
, "a1'", a1
);
668 DRC (r
[1].r_sb
, "sb'", sb
);
669 DRC (r
[1].r_fb
, "fb'", fb
);
671 DRC (r_intbh
, "intbh", intbh
);
672 DRC (r_intbl
, "intbl", intbl
);
673 DRC (r_usp
, "usp", usp
);
674 DRC (r_isp
, "isp", isp
);
675 DRC (r_pc
, "pc", pc
);
677 print_flags (regs
.r_flags
);
678 printf ("\033[0m\n");
679 /*sim_disasm_one (); */
This page took 0.042973 seconds and 4 git commands to generate.