aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cagney <cagney@redhat.com>1997-10-14 23:45:52 +0000
committerAndrew Cagney <cagney@redhat.com>1997-10-14 23:45:52 +0000
commitfd89abc20473920dd03e81829de9622620a2e9f9 (patch)
tree81ba408755e794f6c3ab2167f815e9c394ad4c81
parent0543ba6ec81daf4c0d25d3d300dfaa9982eb11c4 (diff)
downloadgdb-fd89abc20473920dd03e81829de9622620a2e9f9.zip
gdb-fd89abc20473920dd03e81829de9622620a2e9f9.tar.gz
gdb-fd89abc20473920dd03e81829de9622620a2e9f9.tar.bz2
Handle core regions which start at a poorly aligned address.
-rw-r--r--sim/common/ChangeLog12
-rw-r--r--sim/common/sim-core.c62
-rw-r--r--sim/common/sim-core.h4
3 files changed, 51 insertions, 27 deletions
diff --git a/sim/common/ChangeLog b/sim/common/ChangeLog
index a42cdaa..697282a 100644
--- a/sim/common/ChangeLog
+++ b/sim/common/ChangeLog
@@ -1,3 +1,15 @@
+Wed Oct 15 09:24:19 1997 Andrew Cagney <cagney@b1.cygnus.com>
+
+ * sim-core.h (struct _sim_core_mapping): Change free_buffer to
+ type void*.
+
+ * sim-core.c (sim_core_uninstall, new_sim_core_mapping,
+ sim_core_map_attach, sim_core_map_detach): Change free_buffer to
+ type void*.
+ (sim_core_attach): Rename buffer_freed to free_buffer, type
+ void*. Ensure that allocated buffer is alligned according to
+ region's address.
+
Mon Oct 13 11:34:50 1997 Andrew Cagney <cagney@b1.cygnus.com>
* sim-alu.h (ALU64_HAD_OVERFLOW): Define.
diff --git a/sim/common/sim-core.c b/sim/common/sim-core.c
index 079c964..92657d8 100644
--- a/sim/common/sim-core.c
+++ b/sim/common/sim-core.c
@@ -25,6 +25,14 @@
#include "sim-main.h"
#include "sim-assert.h"
+#include <signal.h>
+
+/* for Windows builds. signal numbers used by MSVC are mostly
+ the same as non-linux unixen. */
+#ifndef SIGBUS
+# define SIGBUS 10
+#endif
+
/* "core" module install handler.
@@ -63,9 +71,9 @@ sim_core_uninstall (SIM_DESC sd)
while (curr != NULL) {
sim_core_mapping *tbd = curr;
curr = curr->next;
- if (tbd->free_buffer) {
+ if (tbd->free_buffer != NULL) {
SIM_ASSERT(tbd->buffer != NULL);
- zfree(tbd->buffer);
+ zfree(tbd->free_buffer);
}
zfree(tbd);
}
@@ -103,15 +111,18 @@ sim_core_signal (SIM_DESC sd,
switch (sig)
{
case sim_core_unmapped_signal:
- sim_engine_abort (sd, cpu, cia, "sim-core: %d byte %s to unmaped address 0x%lx",
- nr_bytes, copy, (unsigned long) addr);
+ sim_io_eprintf (sd, "core: %d byte %s to unmaped address 0x%lx\n",
+ nr_bytes, copy, (unsigned long) addr);
+ sim_engine_halt (sd, cpu, NULL, cia, sim_signalled, SIGSEGV);
break;
case sim_core_unaligned_signal:
- sim_engine_abort (sd, cpu, cia, "sim-core: %d byte misaligned %s to address 0x%lx",
- nr_bytes, copy, (unsigned long) addr);
+ sim_io_eprintf (sd, "core: %d byte misaligned %s to address 0x%lx",
+ nr_bytes, copy, (unsigned long) addr);
+ sim_engine_halt (sd, cpu, NULL, cia, sim_signalled, SIGBUS);
break;
default:
- sim_engine_abort (sd, cpu, cia, "sim_core_signal - internal error - bad switch");
+ sim_engine_abort (sd, cpu, cia,
+ "sim_core_signal - internal error - bad switch");
}
}
#endif
@@ -141,7 +152,7 @@ new_sim_core_mapping (SIM_DESC sd,
unsigned modulo,
device *device,
void *buffer,
- int free_buffer)
+ void *free_buffer)
{
sim_core_mapping *new_mapping = ZALLOC(sim_core_mapping);
/* common */
@@ -182,7 +193,7 @@ sim_core_map_attach (SIM_DESC sd,
unsigned modulo,
device *client, /*callback/default*/
void *buffer, /*raw_memory*/
- int free_buffer) /*raw_memory*/
+ void *free_buffer) /*raw_memory*/
{
/* find the insertion point for this additional mapping and then
insert */
@@ -190,7 +201,7 @@ sim_core_map_attach (SIM_DESC sd,
sim_core_mapping **last_mapping;
SIM_ASSERT ((attach >= attach_callback)
- <= (client != NULL && buffer == NULL && !free_buffer));
+ <= (client != NULL && buffer == NULL && free_buffer == NULL));
SIM_ASSERT ((attach == attach_raw_memory)
<= (client == NULL && buffer != NULL));
@@ -272,7 +283,7 @@ sim_core_attach (SIM_DESC sd,
sim_core *memory = STATE_CORE(sd);
sim_core_maps map;
void *buffer;
- int buffer_freed;
+ void *free_buffer;
/* check for for attempt to use unimplemented per-processor core map */
if (cpu != NULL)
@@ -322,19 +333,20 @@ sim_core_attach (SIM_DESC sd,
}
if (optional_buffer == NULL)
{
- buffer = zalloc (modulo == 0 ? nr_bytes : modulo);
- buffer_freed = 0;
+ int padding = (addr % sizeof (unsigned64));
+ free_buffer = zalloc ((modulo == 0 ? nr_bytes : modulo) + padding);
+ buffer = (char*) free_buffer + padding;
}
else
{
buffer = optional_buffer;
- buffer_freed = 1;
+ free_buffer = NULL;
}
}
else if (attach >= attach_callback)
{
buffer = NULL;
- buffer_freed = 1;
+ free_buffer = NULL;
}
else
{
@@ -344,7 +356,7 @@ sim_core_attach (SIM_DESC sd,
sim_io_error (sd, "sim_core_attach - internal error - conflicting buffer and attach arguments");
#endif
buffer = NULL;
- buffer_freed = 1;
+ free_buffer = NULL;
}
/* attach the region to all applicable access maps */
@@ -359,24 +371,24 @@ sim_core_attach (SIM_DESC sd,
sim_core_map_attach (sd, &memory->common.map[map],
attach,
space, addr, nr_bytes, modulo,
- client, buffer, !buffer_freed);
- buffer_freed ++;
+ client, buffer, free_buffer);
+ free_buffer = NULL;
break;
case sim_core_write_map:
if (access & access_write)
sim_core_map_attach (sd, &memory->common.map[map],
attach,
space, addr, nr_bytes, modulo,
- client, buffer, !buffer_freed);
- buffer_freed ++;
+ client, buffer, free_buffer);
+ free_buffer = NULL;
break;
case sim_core_execute_map:
if (access & access_exec)
sim_core_map_attach (sd, &memory->common.map[map],
attach,
space, addr, nr_bytes, modulo,
- client, buffer, !buffer_freed);
- buffer_freed ++;
+ client, buffer, free_buffer);
+ free_buffer = NULL;
break;
case nr_sim_core_maps:
sim_io_error (sd, "sim_core_attach - internal error - bad switch");
@@ -417,8 +429,8 @@ sim_core_map_detach (SIM_DESC sd,
{
sim_core_mapping *dead = (*entry);
(*entry) = dead->next;
- if (dead->free_buffer)
- zfree (dead->buffer);
+ if (dead->free_buffer != NULL)
+ zfree (dead->free_buffer);
zfree (dead);
return;
}
@@ -711,7 +723,7 @@ sim_core_xor_write_buffer (SIM_DESC sd,
else
/* only break up transfers when xor-endian is both selected and enabled */
{
- unsigned_1 x[WITH_XOR_ENDIAN];
+ unsigned_1 x[WITH_XOR_ENDIAN + 1]; /* +1 to avoid zero sized array */
unsigned nr_transfered = 0;
address_word start = addr;
unsigned nr_this_transfer = (WITH_XOR_ENDIAN - (addr & ~(WITH_XOR_ENDIAN - 1)));
diff --git a/sim/common/sim-core.h b/sim/common/sim-core.h
index a2d5ed9..686a845 100644
--- a/sim/common/sim-core.h
+++ b/sim/common/sim-core.h
@@ -48,7 +48,7 @@ struct _sim_core_mapping {
unsigned_word nr_bytes;
unsigned mask;
/* memory map */
- int free_buffer;
+ void *free_buffer;
void *buffer;
/* callback map */
device *device;
@@ -90,7 +90,7 @@ struct _sim_core {
typedef struct _sim_cpu_core {
sim_core_common common;
- address_word xor[WITH_XOR_ENDIAN];
+ address_word xor[WITH_XOR_ENDIAN + 1]; /* +1 to avoid zero-sized array */
} sim_cpu_core;