1 /* reg.c --- register set model for M32C simulator.
3 Copyright (C) 2005, 2007 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;
33 int addr_mask
= 0xffff;
34 int membus_mask
= 0xfffff;
37 unsigned int heapbottom
= 0;
38 unsigned int heaptop
= 0;
51 "intb", "intbl", "intbh",
52 "sp", "usp", "isp", "pc", "flags"
71 unsigned int b2mask
[] = { 0, 0xff, 0xffff, 0xffffff, 0xffffffff };
72 unsigned int b2signbit
[] = { 0, (1 << 7), (1 << 15), (1 << 24), (1 << 31) };
73 int b2maxsigned
[] = { 0, 0x7f, 0x7fff, 0x7fffff, 0x7fffffff };
74 int b2minsigned
[] = { 0, -128, -32768, -8388608, -2147483647 - 1 };
76 static regs_type oldregs
;
81 memset (®s
, 0, sizeof (regs
));
82 memset (&oldregs
, 0, sizeof (oldregs
));
86 set_pointer_width (int bytes
)
91 membus_mask
= 0x000fffff;
92 reg_bytes
[a0
] = reg_bytes
[a1
] = reg_bytes
[sb
] = reg_bytes
[fb
] =
93 reg_bytes
[sp
] = reg_bytes
[usp
] = reg_bytes
[isp
] = 2;
98 membus_mask
= 0x00ffffff;
99 reg_bytes
[a0
] = reg_bytes
[a1
] = reg_bytes
[sb
] = reg_bytes
[fb
] =
100 reg_bytes
[sp
] = reg_bytes
[usp
] = reg_bytes
[isp
] = 3;
105 m32c_set_cpu (int cpu
)
111 set_pointer_width (2);
112 decode_opcode
= decode_r8c
;
116 set_pointer_width (3);
117 decode_opcode
= decode_m32c
;
126 get_reg_i (reg_id id
)
128 reg_bank_type
*b
= regs
.r
+ (FLAG_B
? 1 : 0);
137 return b
->r_r0
& 0xff;
143 return b
->r_r1
& 0xff;
147 return b
->r_r2
* 65536 + b
->r_r0
;
151 return b
->r_r3
* 65536 + b
->r_r1
;
154 return b
->r_a0
& addr_mask
;
156 return b
->r_a1
& addr_mask
;
158 return (b
->r_a1
& 0xffff) * 65536 | (b
->r_a0
& 0xffff);
161 return b
->r_sb
& addr_mask
;
163 return b
->r_fb
& addr_mask
;
166 return regs
.r_intbh
* 65536 + regs
.r_intbl
;
173 return ((regs
.r_flags
& FLAGBIT_U
) ? regs
.r_usp
: regs
.
176 return regs
.r_usp
& addr_mask
;
178 return regs
.r_isp
& addr_mask
;
181 return regs
.r_pc
& membus_mask
;
192 unsigned int rv
= get_reg_i (id
);
193 if (trace
> ((id
!= pc
&& id
!= fb
&& id
!= sp
) ? 0 : 1))
194 printf ("get_reg (%s) = %0*x\n", reg_names
[id
], reg_bytes
[id
] * 2, rv
);
199 get_reg_ll (reg_id id
)
201 reg_bank_type
*b
= regs
.r
+ (FLAG_B
? 1 : 0);
206 return ((DI
) b
->r_r3
<< 48
207 | (DI
) b
->r_r1
<< 32 | (DI
) b
->r_r2
<< 16 | (DI
) b
->r_r0
);
209 return ((DI
) b
->r_r3
<< 48
210 | (DI
) b
->r_r2
<< 32 | (DI
) b
->r_r1
<< 16 | (DI
) b
->r_r0
);
216 static int highest_sp
= 0, lowest_sp
= 0xffffff;
221 printf ("heap: %08x - %08x (%d bytes)\n", heapbottom
, heaptop
,
222 heaptop
- heapbottom
);
223 printf ("stack: %08x - %08x (%d bytes)\n", lowest_sp
, highest_sp
,
224 highest_sp
- lowest_sp
);
228 put_reg (reg_id id
, unsigned int v
)
230 if (trace
> ((id
!= pc
) ? 0 : 1))
231 printf ("put_reg (%s) = %0*x\n", reg_names
[id
], reg_bytes
[id
] * 2, v
);
233 reg_bank_type
*b
= regs
.r
+ (FLAG_B
? 1 : 0);
240 b
->r_r0
= (b
->r_r0
& 0xff) | (v
<< 8);
243 b
->r_r0
= (b
->r_r0
& 0xff00) | (v
& 0xff);
249 b
->r_r1
= (b
->r_r1
& 0xff) | (v
<< 8);
252 b
->r_r1
= (b
->r_r1
& 0xff00) | (v
& 0xff);
258 b
->r_r0
= v
& 0xffff;
265 b
->r_r1
= v
& 0xffff;
270 b
->r_a0
= v
& addr_mask
;
273 b
->r_a1
= v
& addr_mask
;
276 b
->r_a0
= v
& 0xffff;
281 b
->r_sb
= v
& addr_mask
;
284 b
->r_fb
= v
& addr_mask
;
288 regs
.r_intbl
= v
& 0xffff;
289 regs
.r_intbh
= v
>> 16;
292 regs
.r_intbl
= v
& 0xffff;
295 regs
.r_intbh
= v
& 0xff;
301 if (regs
.r_flags
& FLAGBIT_U
)
305 *spp
= v
& addr_mask
;
308 printf ("collision: pc %08lx heap %08x stack %08lx\n", regs
.r_pc
,
312 if (*spp
< lowest_sp
)
314 if (*spp
> highest_sp
)
319 regs
.r_usp
= v
& addr_mask
;
322 regs
.r_isp
= v
& addr_mask
;
326 regs
.r_pc
= v
& membus_mask
;
337 condition_true (int cond_id
)
342 static const char *cond_name
[] = {
343 "C", "C&!Z", "Z", "S",
344 "!C", "!(C&!Z)", "!Z", "!S",
345 "(S^O)|Z", "O", "!(S^O)", "unk",
346 "!((S^O)|Z)", "!O", "S^O", "unk"
348 switch (cond_id
& 15)
354 f
= FLAG_C
& !FLAG_Z
;
366 f
= !(FLAG_C
& !FLAG_Z
);
376 f
= (FLAG_S
^ FLAG_O
) | FLAG_Z
;
382 f
= !(FLAG_S
^ FLAG_O
);
385 f
= !((FLAG_S
^ FLAG_O
) | FLAG_Z
);
399 printf ("cond[%d] %s = %s\n", cond_id
, cond_name
[cond_id
& 15],
400 f
? "true" : "false");
404 static const char *cond_name
[] = {
405 "!C", "LEU", "!Z", "PZ",
406 "!O", "GT", "GE", "?",
407 "C", "GTU", "Z", "N",
408 "O", "LE", "LT", "!?"
410 switch (cond_id
& 15)
416 f
= !(FLAG_C
& !FLAG_Z
);
429 f
= !((FLAG_S
^ FLAG_O
) | FLAG_Z
);
432 f
= !(FLAG_S
^ FLAG_O
);
439 f
= FLAG_C
& !FLAG_Z
;
452 f
= (FLAG_S
^ FLAG_O
) | FLAG_Z
;
463 printf ("cond[%d] %s = %s\n", cond_id
, cond_name
[cond_id
& 15],
464 f
? "true" : "false");
470 set_flags (int mask
, int newbits
)
473 regs
.r_flags
&= ~mask
;
474 regs
.r_flags
|= newbits
& mask
;
477 printf ("flags now \033[32m %d", (regs
.r_flags
>> (A16
? 8 : 12)) & 7);
478 for (i
= 7; i
>= 0; i
--)
479 if (regs
.r_flags
& (1 << i
))
480 putchar ("CDZSBOIU"[i
]);
483 printf ("\033[0m\n");
488 set_oszc (int value
, int b
, int c
)
490 int mask
= b2mask
[b
];
495 if ((value
& mask
) == 0)
497 if (value
& b2signbit
[b
])
499 if ((value
> b2maxsigned
[b
]) || (value
< b2minsigned
[b
]))
501 set_flags (FLAGBIT_Z
| FLAGBIT_S
| FLAGBIT_O
| FLAGBIT_C
, f
);
505 set_szc (int value
, int b
, int c
)
507 int mask
= b2mask
[b
];
512 if ((value
& mask
) == 0)
514 if (value
& b2signbit
[b
])
516 set_flags (FLAGBIT_Z
| FLAGBIT_S
| FLAGBIT_C
, f
);
520 set_osz (int value
, int b
)
522 int mask
= b2mask
[b
];
525 if ((value
& mask
) == 0)
527 if (value
& b2signbit
[b
])
529 if (value
& ~mask
&& (value
& ~mask
) != ~mask
)
531 set_flags (FLAGBIT_Z
| FLAGBIT_S
| FLAGBIT_O
, f
);
535 set_sz (int value
, int b
)
537 int mask
= b2mask
[b
];
540 if ((value
& mask
) == 0)
542 if (value
& b2signbit
[b
])
544 set_flags (FLAGBIT_Z
| FLAGBIT_S
, f
);
548 set_zc (int z
, int c
)
550 set_flags (FLAGBIT_C
| FLAGBIT_Z
,
551 (c
? FLAGBIT_C
: 0) | (z
? FLAGBIT_Z
: 0));
557 set_flags (FLAGBIT_C
, c
? FLAGBIT_C
: 0);
561 put_reg_ll (reg_id id
, DI v
)
563 reg_bank_type
*b
= regs
.r
+ (FLAG_B
? 1 : 0);
584 #define TRC(f,n, id) \
585 if (oldregs.f != regs.f) \
587 printf(" %s %0*x:%0*x", n, \
588 reg_bytes[id]*2, (unsigned int)oldregs.f, \
589 reg_bytes[id]*2, (unsigned int)regs.f); \
590 oldregs.f = regs.f; \
594 trace_register_changes ()
598 printf ("\033[36mREGS:");
599 TRC (r
[0].r_r0
, "r0", r0
);
600 TRC (r
[0].r_r1
, "r1", r1
);
601 TRC (r
[0].r_r2
, "r2", r2
);
602 TRC (r
[0].r_r3
, "r3", r3
);
603 TRC (r
[0].r_a0
, "a0", a0
);
604 TRC (r
[0].r_a1
, "a1", a1
);
605 TRC (r
[0].r_sb
, "sb", sb
);
606 TRC (r
[0].r_fb
, "fb", fb
);
607 TRC (r
[1].r_r0
, "r0'", r0
);
608 TRC (r
[1].r_r1
, "r1'", r1
);
609 TRC (r
[1].r_r2
, "r2'", r2
);
610 TRC (r
[1].r_r3
, "r3'", r3
);
611 TRC (r
[1].r_a0
, "a0'", a0
);
612 TRC (r
[1].r_a1
, "a1'", a1
);
613 TRC (r
[1].r_sb
, "sb'", sb
);
614 TRC (r
[1].r_fb
, "fb'", fb
);
615 TRC (r_intbh
, "intbh", intbh
);
616 TRC (r_intbl
, "intbl", intbl
);
617 TRC (r_usp
, "usp", usp
);
618 TRC (r_isp
, "isp", isp
);
619 TRC (r_pc
, "pc", pc
);
620 TRC (r_flags
, "flags", flags
);
621 printf ("\033[0m\n");
This page took 0.042654 seconds and 5 git commands to generate.