summaryrefslogtreecommitdiffstats
path: root/sim/m32c
diff options
context:
space:
mode:
authorDJ Delorie <dj@redhat.com>2006-03-14 03:34:28 +0000
committerDJ Delorie <dj@redhat.com>2006-03-14 03:34:28 +0000
commit727b6b4b411c55d0d6719556bcf6a5da5c54adb6 (patch)
treef356cad6da3037f2447b33a9a826b98f4d25c0c7 /sim/m32c
parent1f810f7808a9364811ec4e9494eb5fc8daafe232 (diff)
downloadppe42-binutils-727b6b4b411c55d0d6719556bcf6a5da5c54adb6.tar.gz
ppe42-binutils-727b6b4b411c55d0d6719556bcf6a5da5c54adb6.zip
* mem.c (mem_put_byte): Hook simulated UART to stdout.
(mem_put_hi): Hook in simulated trace port. (mem_get_byte): Hook in simulated uart control port. * opc2c: Be more picky about matching special comments. * r8c.opc (shift_op): Limit shift counts to -16..16. (BMcnd): Map conditional codes. * reg.c (condition_true): Mask condition code to 4 bits. * syscalls.c: Include local syscall.h. * syscall.h: New, copied from libgloss.
Diffstat (limited to 'sim/m32c')
-rw-r--r--sim/m32c/ChangeLog12
-rw-r--r--sim/m32c/mem.c38
-rw-r--r--sim/m32c/r8c.opc17
-rw-r--r--sim/m32c/reg.c4
-rw-r--r--sim/m32c/syscall.h50
-rw-r--r--sim/m32c/syscalls.c2
6 files changed, 111 insertions, 12 deletions
diff --git a/sim/m32c/ChangeLog b/sim/m32c/ChangeLog
index 0e44c07b8e..9c3cae1132 100644
--- a/sim/m32c/ChangeLog
+++ b/sim/m32c/ChangeLog
@@ -1,3 +1,15 @@
+2006-03-13 DJ Delorie <dj@redhat.com>
+
+ * mem.c (mem_put_byte): Hook simulated UART to stdout.
+ (mem_put_hi): Hook in simulated trace port.
+ (mem_get_byte): Hook in simulated uart control port.
+ * opc2c: Be more picky about matching special comments.
+ * r8c.opc (shift_op): Limit shift counts to -16..16.
+ (BMcnd): Map conditional codes.
+ * reg.c (condition_true): Mask condition code to 4 bits.
+ * syscalls.c: Include local syscall.h.
+ * syscall.h: New, copied from libgloss.
+
2005-10-06 Jim Blandy <jimb@redhat.com>
Simulator for Renesas M32C and M16C, by DJ Delorie <dj@redhat.com>,
diff --git a/sim/m32c/mem.c b/sim/m32c/mem.c
index d7623a4b88..258c295ea6 100644
--- a/sim/m32c/mem.c
+++ b/sim/m32c/mem.c
@@ -202,6 +202,23 @@ mem_put_byte (int address, unsigned char value)
}
break;
+ case 0x3aa: /* uart1tx */
+ {
+ static int pending_exit = 0;
+ if (value == 0)
+ {
+ if (pending_exit)
+ {
+ step_result = M32C_MAKE_EXITED(value);
+ return;
+ }
+ pending_exit = 1;
+ }
+ else
+ putchar(value);
+ }
+ break;
+
case 0x400:
m32c_syscall (value);
break;
@@ -232,6 +249,11 @@ mem_put_qi (int address, unsigned char value)
void
mem_put_hi (int address, unsigned short value)
{
+ if (address == 0x402)
+ {
+ printf ("SimTrace: %06lx %04x\n", regs.r_pc, value);
+ return;
+ }
S ("<=");
mem_put_byte (address, value & 0xff);
mem_put_byte (address + 1, value >> 8);
@@ -288,16 +310,16 @@ mem_get_byte (int address)
address &= membus_mask;
S ("=>");
m = mem_ptr (address);
- if (trace)
+ switch (address)
{
- if (tpr)
+ case 0x3ad: /* uart1c1 */
+ E();
+ return 2; /* transmitter empty */
+ break;
+ default:
+ if (trace)
printf (" %02x", *m);
- else
- {
- S ("=>");
- printf (" %02x", *m);
- E ();
- }
+ break;
}
E ();
return *m;
diff --git a/sim/m32c/r8c.opc b/sim/m32c/r8c.opc
index 4a6ba51b78..4db0bda030 100644
--- a/sim/m32c/r8c.opc
+++ b/sim/m32c/r8c.opc
@@ -240,6 +240,15 @@ shift_op (srcdest sd, int arith, int count)
{
mask = 0xffffffffU;
msb = 0x80000000U;
+ if (count > 16 || count < -16)
+ {
+ fprintf(stderr, "Error: SI shift of %d undefined\n", count);
+ exit(1);
+ }
+ if (count > 16)
+ count = (count - 1) % 16 + 1;
+ if (count < -16)
+ count = -((-count - 1) % 16 + 1);
}
tprintf("%s %x by %d\n", arith ? "sha" : "shl", v, count);
@@ -292,6 +301,12 @@ shift_op (srcdest sd, int arith, int count)
tprintf ("b=%d, carry=%d, %s = %d\n", b, carry, #expr, v); \
set_c (v);
+/* The "BMcnd dest" opcode uses a different encoding for the */
+/* condition than other opcodes. */
+static int bmcnd_cond_map[] = {
+ 0, 1, 2, 3, 8, 9, 10, 11, 4, 5, 6, 7, 12, 13, 14, 15
+};
+
int
decode_r8c()
{
@@ -448,7 +463,7 @@ decode_r8c()
/** 0111 1110 0010 dest BMcnd dest */
dc = decode_bit (dest);
- if (condition_true (IMM (0)))
+ if (condition_true (bmcnd_cond_map [IMM (0) & 15]))
put_bit (dc, 1);
else
put_bit (dc, 0);
diff --git a/sim/m32c/reg.c b/sim/m32c/reg.c
index 40cb11c468..8c01675d39 100644
--- a/sim/m32c/reg.c
+++ b/sim/m32c/reg.c
@@ -347,7 +347,7 @@ condition_true (int cond_id)
"(S^O)|Z", "O", "!(S^O)", "unk",
"!((S^O)|Z)", "!O", "S^O", "unk"
};
- switch (cond_id)
+ switch (cond_id & 15)
{
case 0:
f = FLAG_C;
@@ -409,7 +409,7 @@ condition_true (int cond_id)
"C", "GTU", "Z", "N",
"O", "LE", "LT", "!?"
};
- switch (cond_id)
+ switch (cond_id & 15)
{
case 0:
f = !FLAG_C;
diff --git a/sim/m32c/syscall.h b/sim/m32c/syscall.h
new file mode 100644
index 0000000000..0194e039e7
--- /dev/null
+++ b/sim/m32c/syscall.h
@@ -0,0 +1,50 @@
+/* Copied from libgloss */
+/* General use syscall.h file.
+ The more ports that use this file, the simpler sim/common/nltvals.def
+ remains. */
+
+#ifndef LIBGLOSS_SYSCALL_H
+#define LIBGLOSS_SYSCALL_H
+
+/* Note: This file may be included by assembler source. */
+
+/* These should be as small as possible to allow a port to use a trap type
+ instruction, which the system call # as the trap (the d10v for instance
+ supports traps 0..31). An alternative would be to define one trap for doing
+ system calls, and put the system call number in a register that is not used
+ for the normal calling sequence (so that you don't have to shift down the
+ arguments to add the system call number). Obviously, if these system call
+ numbers are ever changed, all of the simulators and potentially user code
+ will need to be updated. */
+
+/* There is no current need for the following: SYS_execv, SYS_creat, SYS_wait,
+ etc. etc. Don't add them. */
+
+/* These are required by the ANSI C part of newlib (excluding system() of
+ course). */
+#define SYS_exit 1
+#define SYS_open 2
+#define SYS_close 3
+#define SYS_read 4
+#define SYS_write 5
+#define SYS_lseek 6
+#define SYS_unlink 7
+#define SYS_getpid 8
+#define SYS_kill 9
+#define SYS_fstat 10
+/*#define SYS_sbrk 11 - not currently a system call, but reserved. */
+
+/* ARGV support. */
+#define SYS_argvlen 12
+#define SYS_argv 13
+
+/* These are extras added for one reason or another. */
+#define SYS_chdir 14
+#define SYS_stat 15
+#define SYS_chmod 16
+#define SYS_utime 17
+#define SYS_time 18
+#define SYS_gettimeofday 19
+#define SYS_times 20
+#define SYS_link 21
+#endif
diff --git a/sim/m32c/syscalls.c b/sim/m32c/syscalls.c
index bf33c1d8b6..0a1c249fc8 100644
--- a/sim/m32c/syscalls.c
+++ b/sim/m32c/syscalls.c
@@ -33,7 +33,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
#include "mem.h"
#include "syscalls.h"
-#include "../../libgloss/syscall.h"
+#include "syscall.h"
/* The current syscall callbacks we're using. */
static struct host_callback_struct *callbacks;
OpenPOWER on IntegriCloud