1 /* reg.c --- register set model for RX simulator.
3 Copyright (C) 2005-2020 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/>. */
33 int enable_counting
= 0;
44 unsigned int heapbottom
= 0;
45 unsigned int heaptop
= 0;
48 /* general registers */
49 "r0", "r1", "r2", "r3", "r4", "r5", "r6", "r7",
50 "r8", "r9", "r10", "r11", "r12", "r13", "r14", "r15",
51 /* control register */
52 "psw", "pc", "usp", "fpsw", "RES", "RES", "RES", "RES",
53 "bpsw", "bpc", "isp", "fintv", "intb", "RES", "RES", "RES",
54 "RES", "RES", "RES", "RES", "RES", "RES", "RES", "RES",
55 "RES", "RES", "RES", "RES", "RES", "RES", "RES", "RES",
56 "temp", "acc", "acchi", "accmi", "acclo"
59 unsigned int b2mask
[] = { 0, 0xff, 0xffff, 0xffffff, 0xffffffff };
60 unsigned int b2signbit
[] = { 0, (1 << 7), (1 << 15), (1 << 24), (1 << 31) };
61 int b2maxsigned
[] = { 0, 0x7f, 0x7fff, 0x7fffff, 0x7fffffff };
62 int b2minsigned
[] = { 0, -128, -32768, -8388608, -2147483647 - 1 };
64 static regs_type oldregs
;
69 memset (®s
, 0, sizeof (regs
));
70 memset (&oldregs
, 0, sizeof (oldregs
));
82 return regs
.r_psw
& FLAGBIT_U
? regs
.r_usp
: regs
.r_isp
;
84 if (id
>= 1 && id
<= 15)
110 return (SI
)(regs
.r_acc
>> 32);
112 return (SI
)(regs
.r_acc
>> 16);
114 return (SI
)regs
.r_acc
;
122 unsigned int rv
= get_reg_i (id
);
123 if (trace
> ((id
!= pc
&& id
!= sp
) ? 0 : 1))
124 printf ("get_reg (%s) = %08x\n", reg_names
[id
], rv
);
128 static unsigned long long
143 unsigned long long rv
= get_reg64_i (id
);
144 if (trace
> ((id
!= pc
&& id
!= sp
) ? 0 : 1))
145 printf ("get_reg (%s) = %016llx\n", reg_names
[id
], rv
);
149 static int highest_sp
= 0, lowest_sp
= 0xffffff;
154 if (heapbottom
< heaptop
)
155 printf ("heap: %08x - %08x (%d bytes)\n", heapbottom
, heaptop
,
156 heaptop
- heapbottom
);
157 if (lowest_sp
< highest_sp
)
158 printf ("stack: %08x - %08x (%d bytes)\n", lowest_sp
, highest_sp
,
159 highest_sp
- lowest_sp
);
163 put_reg (int id
, unsigned int v
)
165 if (trace
> ((id
!= pc
) ? 0 : 1))
166 printf ("put_reg (%s) = %08x\n", reg_names
[id
], v
);
177 /* This is an odd one - The Cx flags are AND'd, and the FS flag
179 anded
= regs
.r_fpsw
& v
;
180 anded
|= ~ FPSWBITS_CMASK
;
181 regs
.r_fpsw
= v
& anded
;
182 if (regs
.r_fpsw
& FPSWBITS_FMASK
)
183 regs
.r_fpsw
|= FPSWBITS_FSUM
;
185 regs
.r_fpsw
&= ~FPSWBITS_FSUM
;
211 regs
.r_acc
= (regs
.r_acc
& 0xffffffffULL
) | ((DI
)v
<< 32);
214 regs
.r_acc
= (regs
.r_acc
& ~0xffffffff0000ULL
) | ((DI
)v
<< 16);
217 regs
.r_acc
= (regs
.r_acc
& ~0xffffffffULL
) | ((DI
)v
);
220 case 0: /* Stack pointer is "in" R0. */
226 const char * fname
= NULL
;
228 sim_get_current_source_location (& dummy
, & fname
, &line
);
230 /* The setjmp and longjmp functions play tricks with the stack pointer. */
232 || (strcmp (fname
, "_setjmp") != 0
233 && strcmp (fname
, "_longjmp") != 0))
235 printf ("collision in %s: pc %08x heap %08x stack %08x\n",
236 fname
, (unsigned int) regs
.r_pc
, heaptop
, v
);
248 if (regs
.r_psw
& FLAGBIT_U
)
256 if (id
>= 1 && id
<= 15)
264 put_reg64 (int id
, unsigned long long v
)
266 if (trace
> ((id
!= pc
) ? 0 : 1))
267 printf ("put_reg (%s) = %016llx\n", reg_names
[id
], v
);
280 condition_true (int cond_id
)
284 static const char *cond_name
[] = {
302 switch (cond_id
& 15)
317 f
= FLAG_C
& !FLAG_Z
;
320 f
= !(FLAG_C
& !FLAG_Z
);
330 f
= !(FLAG_S
^ FLAG_O
);
336 f
= !((FLAG_S
^ FLAG_O
) | FLAG_Z
);
339 f
= (FLAG_S
^ FLAG_O
) | FLAG_Z
;
354 if (trace
&& ((cond_id
& 15) != 14))
355 printf ("cond[%d] %s = %s\n", cond_id
, cond_name
[cond_id
& 15],
356 f
? "true" : "false");
361 set_flags (int mask
, int newbits
)
363 regs
.r_psw
&= rx_flagand
;
364 regs
.r_psw
|= rx_flagor
;
365 regs
.r_psw
|= (newbits
& mask
& rx_flagmask
);
370 printf ("flags now \033[32m %d", (int)((regs
.r_psw
>> 24) & 7));
371 for (i
= 17; i
>= 0; i
--)
372 if (0x3000f & (1 << i
))
374 if (regs
.r_psw
& (1 << i
))
375 putchar ("CZSO------------IU"[i
]);
379 printf ("\033[0m\n");
384 set_oszc (long long value
, int b
, int c
)
386 unsigned int mask
= b2mask
[b
];
391 if ((value
& mask
) == 0)
393 if (value
& b2signbit
[b
])
395 if ((value
> b2maxsigned
[b
]) || (value
< b2minsigned
[b
]))
397 set_flags (FLAGBIT_Z
| FLAGBIT_S
| FLAGBIT_O
| FLAGBIT_C
, f
);
401 set_szc (long long value
, int b
, int c
)
403 unsigned int mask
= b2mask
[b
];
408 if ((value
& mask
) == 0)
410 if (value
& b2signbit
[b
])
412 set_flags (FLAGBIT_Z
| FLAGBIT_S
| FLAGBIT_C
, f
);
416 set_osz (long long value
, int b
)
418 unsigned int mask
= b2mask
[b
];
421 if ((value
& mask
) == 0)
423 if (value
& b2signbit
[b
])
425 if ((value
> b2maxsigned
[b
]) || (value
< b2minsigned
[b
]))
427 set_flags (FLAGBIT_Z
| FLAGBIT_S
| FLAGBIT_O
, f
);
431 set_sz (long long value
, int b
)
433 unsigned int mask
= b2mask
[b
];
436 if ((value
& mask
) == 0)
438 if (value
& b2signbit
[b
])
440 set_flags (FLAGBIT_Z
| FLAGBIT_S
, f
);
444 set_zc (int z
, int c
)
446 set_flags (FLAGBIT_C
| FLAGBIT_Z
,
447 (c
? FLAGBIT_C
: 0) | (z
? FLAGBIT_Z
: 0));
453 set_flags (FLAGBIT_C
, c
? FLAGBIT_C
: 0);
463 ipl
= (rpsw
& FLAGBITS_IPL
) >> FLAGSHIFT_IPL
;
466 *bp
++ = (ipl
/ 10) + '0';
470 for (i
= 20; i
>= 0; i
--)
471 if (0x13000f & (1 << i
))
474 *bp
++ = "CZSO------------IU--P"[i
];
485 static char buf
[100];
487 int i
; /* ---+---+---+---+---+---+---+---+ */
488 const char s1
[] = "FFFFFF-----------EEEEE-DCCCCCCRR";
489 const char s2
[] = "SXUZOV-----------XUZOV-NEXUZOV01";
490 const char rm
[4][3] = { "RC", "RZ", "RP", "RN" };
492 for (i
= 31; i
>= 0; i
--)
493 if (0xfc007dfc & (1 << i
))
505 strcpy (bp
, rm
[rpsw
&3]);
510 if (oldregs.f != regs.f) \
512 if (tag) { printf (tag); tag = 0; } \
513 printf(" %s %08x:%08x", n, \
514 (unsigned int)oldregs.f, \
515 (unsigned int)regs.f); \
516 oldregs.f = regs.f; \
520 trace_register_changes (void)
522 char *tag
= "\033[36mREGS:";
528 TRC (r
[i
], reg_names
[i
]);
529 TRC (r_intb
, "intb");
532 if (oldregs
.r_psw
!= regs
.r_psw
)
534 if (tag
) { printf (tag
); tag
= 0; }
535 printf(" psw %s:", psw2str(oldregs
.r_psw
));
536 printf("%s", psw2str(regs
.r_psw
));
537 oldregs
.r_psw
= regs
.r_psw
;
540 if (oldregs
.r_fpsw
!= regs
.r_fpsw
)
542 if (tag
) { printf (tag
); tag
= 0; }
543 printf(" fpsw %s:", fpsw2str(oldregs
.r_fpsw
));
544 printf("%s", fpsw2str(regs
.r_fpsw
));
545 oldregs
.r_fpsw
= regs
.r_fpsw
;
548 if (oldregs
.r_acc
!= regs
.r_acc
)
550 if (tag
) { printf (tag
); tag
= 0; }
551 printf(" acc %016llx:", oldregs
.r_acc
);
552 printf("%016llx", regs
.r_acc
);
553 oldregs
.r_acc
= regs
.r_acc
;
557 printf ("\033[0m\n");