Re: gdb-7.12 powerpc-rtems4.12-gdb does not build on FreeBSD.

Pedro Alves
2016-11-24T14:59:57Z

On 11/24/2016 02:18 PM, John Baldwin wrote:
> On Thursday, November 24, 2016 12:12:45 PM Pedro Alves wrote:

>> The PPC sim shouldn't be calling GDB's "error" directly. If it does,
>> then that's should be fixed. There's an "error" method in the
>> host_callback structure (filled in by GDB) that should be used instead.
>
> Ah, the sim defines its own 'error()' routine in misc.c. It also defines its
> own zalloc() and a few other routines, but misc.o isn't included in libsim.a,
> only for specific binaries (it seems to be a stub defined to hold routines
> normally defined in gdb for use in stand-alone programs). Curiously, sim_calls.c
> defines its own zalloc(). I tried adding an error() to sim_calls.c and that
> fixes the build. I modeled it on sim_io_error():

Ah, yes, that's indeed simpler than what I was going for (see below, incomplete).
Yours should be able to go to both 7.12 and master. Please send it to gdb-patches.

This exposes something else that needs to be done, as long
as the sim is C -- gdb/remote-sim.c:gdb_os_error (which is
what host_callback->error is set to, throws a C++ exception,
and that will want to cross the sim. But that will only work
if the sim is build with -fexceptions (which is the default
on x86_64). So we either need to always build the sim explicitly
with -fexceptions, or we need to longjmp out of the sim instead
of throwing a C++ exception. E.g., wrap calls into the sim
with TRY_SJLJ/CATCH_SJLJ and make gdb_os_error use
throw_exception_sjlj, like we handle longjmp-ing across
readline.

From a9311bc383f45829ec695a55bbbb301deeafff8d Mon Sep 17 00:00:00 2001
From: Pedro Alves <palves@redhat.com>
Date: Thu, 24 Nov 2016 12:25:50 +0000
Subject: [PATCH] psim and error

---
sim/ppc/cap.c | 8 ++++----
sim/ppc/corefile.c | 9 ++++-----
sim/ppc/cpu.c | 4 ++--
sim/ppc/debug.c | 2 +-
sim/ppc/debug.h | 4 ++--
sim/ppc/device.c | 20 ++++++++++----------
sim/ppc/device_table.c | 2 +-
sim/ppc/dgen.c | 2 +-
sim/ppc/emul_bugapi.c | 16 ++++++++--------
sim/ppc/emul_chirp.c | 43 ++++++++++++++++++++++--------------------
sim/ppc/emul_generic.c | 11 ++++++-----
sim/ppc/emul_netbsd.c | 10 +++++-----
sim/ppc/events.c | 2 +-
sim/ppc/gen-icache.c | 2 +-
sim/ppc/gen-idecode.c | 4 ++--
sim/ppc/gen-model.c | 6 ++++--
sim/ppc/gen-support.c | 2 +-
sim/ppc/hw_core.c | 2 +-
sim/ppc/hw_cpu.c | 7 +++----
sim/ppc/hw_init.c | 2 +-
sim/ppc/hw_nvram.c | 2 +-
sim/ppc/hw_phb.c | 4 ++--
sim/ppc/hw_register.c | 2 +-
sim/ppc/hw_sem.c | 31 +++++++++++++++---------------
sim/ppc/hw_shm.c | 12 ++++++------
sim/ppc/igen.c | 4 ++--
sim/ppc/interrupts.c | 38 ++++++++++++++-----------------------
sim/ppc/ld-cache.c | 2 +-
sim/ppc/ld-decode.c | 2 +-
sim/ppc/ld-insn.c | 23 ++++++++++++-----------
sim/ppc/lf.c | 2 +-
sim/ppc/main.c | 49 +++++++++++++++++++++++++++++++-----------------
sim/ppc/misc.c | 8 ++++----
sim/ppc/misc.h | 22 +++++++++++-----------
sim/ppc/mon.c | 2 +-
sim/ppc/os_emul.c | 4 ++--
sim/ppc/ppc-instructions | 10 +++++-----
sim/ppc/psim.c | 5 +++--
sim/ppc/sim_callbacks.h | 15 +++++++++++++--
sim/ppc/sim_calls.c | 36 +++++++++++++++++++++--------------
sim/ppc/table.c | 2 +-
sim/ppc/tree.c | 6 +++---
sim/ppc/vm.c | 8 ++++----
sim/ppc/vm_n.h | 4 ++--
44 files changed, 240 insertions(+), 211 deletions(-)

diff --git a/sim/ppc/cap.c b/sim/ppc/cap.c
index 48ac5bc..f20f92b 100644
--- a/sim/ppc/cap.c
+++ b/sim/ppc/cap.c
@@ -53,12 +53,12 @@ cap_init(cap *db)
down to nr 1 */
while (current_map->next != NULL) {
if (current_map->external != current_map->next->external + 1)
- error("cap: cap database possibly corrupt");
+ sim_io_error ("cap: cap database possibly corrupt");
current_map = current_map->next;
}
ASSERT(current_map->next == NULL);
if (current_map->external != 1)
- error("cap: cap database possibly currupt");
+ sim_io_error ("cap: cap database possibly currupt");
}
else {
db->nr_mappings = 0;
@@ -99,7 +99,7 @@ cap_add(cap *db,
void *internal)
{
if (cap_external(db, internal) != 0) {
- error("cap: attempting to add an object already in the data base");
+ sim_io_error ("cap: attempting to add an object already in the data base");
}
else {
/* insert at the front making things in decending order */
@@ -127,7 +127,7 @@ cap_remove(cap *db,
}
current_map = &(*current_map)->next;
}
- error("cap: attempt to remove nonexistant internal object");
+ sim_io_error ("cap: attempt to remove nonexistant internal object");
}

#endif
diff --git a/sim/ppc/corefile.c b/sim/ppc/corefile.c
index d784d64..211ef80 100644
--- a/sim/ppc/corefile.c
+++ b/sim/ppc/corefile.c
@@ -153,8 +153,8 @@ new_core_mapping(attach_type attach,
new_mapping->device = device;
}
else {
- error("new_core_mapping() - internal error - unknown attach type %d\n",
- attach);
+ sim_io_internal_error("unknown attach type %d",
+ attach);
}
return new_mapping;
}
@@ -263,8 +263,7 @@ core_attach(core *memory,
free_buffer = NULL;
break;
default:
- error("core_attach() internal error\n");
- break;
+ sim_io_internal_error ("bad switch");
}
}
/* allocated buffer must attach to at least one thing */
@@ -291,7 +290,7 @@ core_map_find_mapping(core_map *map,
mapping = mapping->next;
}
if (abort)
- error("core_find_mapping() - access to unmaped address, attach a default map to handle this - addr=0x%x nr_bytes=0x%x processor=0x%x cia=0x%x\n",
+ sim_io_internal_error ("access to unmaped address, attach a default map to handle this - addr=0x%x nr_bytes=0x%x processor=0x%x cia=0x%x",
addr, nr_bytes, processor, cia);
return NULL;
}
diff --git a/sim/ppc/cpu.c b/sim/ppc/cpu.c
index c7e8bdf..a119f2c 100644
--- a/sim/ppc/cpu.c
+++ b/sim/ppc/cpu.c
@@ -216,7 +216,7 @@ cpu_error(cpu *processor,

/* sanity check */
if (strlen(message) >= sizeof(message))
- error("cpu_error: buffer overflow");
+ sim_io_internal_error ("buffer overflow");

if (processor != NULL) {
printf_filtered("cpu %d, cia 0x%lx: %s\n",
@@ -224,7 +224,7 @@ cpu_error(cpu *processor,
cpu_halt(processor, cia, was_signalled, -1);
}
else {
- error("cpu: %s", message);
+ sim_io_internal_error ("cpu: %s", message);
}
}

diff --git a/sim/ppc/debug.c b/sim/ppc/debug.c
index 1ec279b..a9e9569 100644
--- a/sim/ppc/debug.c
+++ b/sim/ppc/debug.c
@@ -111,7 +111,7 @@ trace_option(const char *option,
if (i > 0 && i < nr_trace_options)
ppc_trace[i] = setting;
else
- error("Unknown trace option: %s\n", option);
+ psim_fatal_error ("Unknown trace option: %s\n", option);
}

}
diff --git a/sim/ppc/debug.h b/sim/ppc/debug.h
index 6f19624..92e283a 100644
--- a/sim/ppc/debug.h
+++ b/sim/ppc/debug.h
@@ -155,8 +155,8 @@ do { \
do { \
if (WITH_ASSERT) { \
if (!(EXPRESSION)) { \
- error("%s:%d: assertion failed - %s\n", \
- filter_filename(__FILE__), __LINE__, #EXPRESSION); \
+ sim_io_error("%s:%d: assertion failed - %s\n", \
+ filter_filename(__FILE__), __LINE__, #EXPRESSION); \
} \
} \
} while (0)
diff --git a/sim/ppc/device.c b/sim/ppc/device.c
index d5093bb..89a7af4 100644
--- a/sim/ppc/device.c
+++ b/sim/ppc/device.c
@@ -199,7 +199,7 @@ device_full_name(device *leaf,
/* construct a name */
if (leaf->parent == NULL) {
if (sizeof_buf < 1)
- error("device_full_name: buffer overflow");
+ sim_io_internal_error ("device_full_name: buffer overflow");
*buf = '\0';
}
else {
@@ -215,7 +215,7 @@ device_full_name(device *leaf,
unit[0] = '\0';
if (strlen(buf) + strlen("/") + strlen(leaf->name) + strlen(unit)
>= sizeof_buf)
- error("device_full_name: buffer overflow");
+ sim_io_internal_error ("buffer overflow");
strcat(buf, "/");
strcat(buf, leaf->name);
strcat (buf, unit);
@@ -1766,14 +1766,14 @@ device_interrupt_encode(device *me,
strcpy(buf, ports->name);
sprintf(buf + strlen(buf), "%d", port_number - ports->number);
if (strlen(buf) >= sizeof_buf)
- error("device_interrupt_encode: buffer overflow");
+ sim_io_internal_error ("buffer overflow");
return strlen(buf);
}
}
else {
if (ports->number == port_number) {
if (strlen(ports->name) >= sizeof_buf)
- error("device_interrupt_encode: buffer overflow");
+ sim_io_internal_error ("buffer overflow");
strcpy(buf, ports->name);
return strlen(buf);
}
@@ -1784,7 +1784,7 @@ device_interrupt_encode(device *me,
}
sprintf(buf, "%d", port_number);
if (strlen(buf) >= sizeof_buf)
- error("device_interrupt_encode: buffer overflow");
+ sim_io_internal_error ("buffer overflow");
return strlen(buf);
}

@@ -1828,15 +1828,15 @@ device_error(device *me,
va_end(ap);
/* sanity check */
if (strlen(message) >= sizeof(message))
- error("device_error: buffer overflow");
+ sim_io_internal_error ("buffer overflow");
if (me == NULL)
- error("device: %s", message);
+ sim_io_internal_error ("device: %s", message);
else if (me->path != NULL && me->path[0] != '\0')
- error("%s: %s", me->path, message);
+ sim_io_internal_error ("%s: %s", me->path, message);
else if (me->name != NULL && me->name[0] != '\0')
- error("%s: %s", me->name, message);
+ sim_io_internal_error ("%s: %s", me->name, message);
else
- error("device: %s", message);
+ sim_io_internal_error ("device: %s", message);
while(1);
}

diff --git a/sim/ppc/device_table.c b/sim/ppc/device_table.c
index d2c6195..c10b93d 100644
--- a/sim/ppc/device_table.c
+++ b/sim/ppc/device_table.c
@@ -169,7 +169,7 @@ generic_device_unit_encode(device *bus,
len = pos - buf;
}
if (len >= sizeof_buf)
- error("generic_unit_encode - buffer overflow\n");
+ sim_io_internal_error ("buffer overflow");
return len;
}

diff --git a/sim/ppc/dgen.c b/sim/ppc/dgen.c
index 8e8f5fb..19b97b0 100644
--- a/sim/ppc/dgen.c
+++ b/sim/ppc/dgen.c
@@ -328,7 +328,7 @@ main(int argc,
real_file_name = NULL;
break;
default:
- error("unknown option\n");
+ psim_fatal_error ("unknown option\n");
}
}
return 0;
diff --git a/sim/ppc/emul_bugapi.c b/sim/ppc/emul_bugapi.c
index e33d0cf..856e890 100644
--- a/sim/ppc/emul_bugapi.c
+++ b/sim/ppc/emul_bugapi.c
@@ -419,8 +419,8 @@ emul_bugapi_do_diskio(os_emul_data *bugapi,
T2H(descriptor.addr_mod);
if (descriptor.dev_lun >= nr_bugapi_disks
|| bugapi->disk[descriptor.dev_lun] == NULL) {
- error("emul_bugapi_do_diskio: attempt to access unconfigured disk /chosen/disk%d",
- descriptor.dev_lun);
+ sim_io_internal_error ("attempt to access unconfigured disk /chosen/disk%d",
+ descriptor.dev_lun);
}
else {
for (block = 0; block < descriptor.blk_cnt; block++) {
@@ -430,20 +430,20 @@ emul_bugapi_do_diskio(os_emul_data *bugapi,
unsigned_word byte_nr = block_nr * sizeof(buf);
unsigned_word block_addr = descriptor.pbuffer + block*sizeof(buf);
if (device_instance_seek(disk, 0, byte_nr) < 0)
- error("emul_bugapi_do_diskio: bad seek\n");
+ sim_io_internal_error ("bad seek");
switch (call_id) {
case _DSKRD:
if (device_instance_read(disk, buf, sizeof(buf)) != sizeof(buf))
- error("emul_`bugapi_do_diskio: bad read\n");
+ sim_io_internal_error ("bad read");
emul_write_buffer(buf, block_addr, sizeof(buf), processor, cia);
break;
case _DSKWR:
emul_read_buffer(buf, block_addr, sizeof(buf), processor, cia);
if (device_instance_write(disk, buf, sizeof(buf)) != sizeof(buf))
- error("emul_bugapi_do_diskio: bad write\n");
+ sim_io_internal_error ("bad write");
break;
default:
- error("emul_bugapi_do_diskio: bad switch\n");
+ sim_io_internal_error ("bad switch");
}
}
}
@@ -502,8 +502,8 @@ emul_bugapi_instruction_call(cpu *processor,

switch (call_id) {
default:
- error("emul-bugapi: unimplemented bugapi %s from address 0x%lx\n",
- emul_bugapi_instruction_name (call_id), SRR0);
+ sim_io_internal_error ("unimplemented bugapi %s from address 0x%lx",
+ emul_bugapi_instruction_name (call_id), SRR0);
break;

/* read a single character, output r3 = byte */
diff --git a/sim/ppc/emul_chirp.c b/sim/ppc/emul_chirp.c
index f326410..c8549dc 100644
--- a/sim/ppc/emul_chirp.c
+++ b/sim/ppc/emul_chirp.c
@@ -889,7 +889,7 @@ chirp_emul_call_method(os_emul_data *data,
/* see if we can emulate this method */
if (ihandle == NULL) {
/* OpenFirmware doesn't define this error */
- error("chirp: invalid ihandle passed to call-method method");
+ sim_io_internal_error ("invalid ihandle passed to call-method method");
}
else {
args.stack[stack_catch_result] =
@@ -975,7 +975,7 @@ chirp_emul_close(os_emul_data *data,
/* close the device */
if (ihandle == NULL) {
/* OpenFirmware doesn't define this error */
- error("chirp: invalid ihandle passed to close method");
+ sim_io_internal_error ("chirp: invalid ihandle passed to close method");
}
else {
device_instance_delete(ihandle);
@@ -1016,7 +1016,7 @@ chirp_emul_read(os_emul_data *data,
(unsigned long)args.len));
if (ihandle == NULL) {
/* OpenFirmware doesn't define this error */
- error("chirp: invalid ihandle passed to read method");
+ sim_io_internal_error ("chirp: invalid ihandle passed to read method");
}
else {
/* do the reads */
@@ -1055,7 +1055,7 @@ chirp_emul_read(os_emul_data *data,
args.actual = sim_io_not_ready;
break;
default:
- error("Bad error value %ld", (long)actual);
+ sim_io_internal_error ("Bad error value %ld", (long)actual);
break;
}
}
@@ -1107,7 +1107,7 @@ chirp_emul_write(os_emul_data *data,
buf, (long)actual));
if (ihandle == NULL) {
/* OpenFirmware doesn't define this error */
- error("chirp: invalid ihandle passed to write method");
+ sim_io_internal_error ("chirp: invalid ihandle passed to write method");
}
else {
/* write it out */
@@ -1153,7 +1153,7 @@ chirp_emul_seek(os_emul_data *data,
args.pos_hi, args.pos_lo));
if (ihandle == NULL) {
/* OpenFirmware doesn't define this error */
- error("chirp: invalid ihandle passed to seek method");
+ sim_io_internal_error ("chirp: invalid ihandle passed to seek method");
}
else {
/* seek it out */
@@ -1210,15 +1210,16 @@ chirp_emul_claim(os_emul_data *data,
mem_in[2] = args.virt;
if (device_instance_call_method(memory, "claim",
3, mem_in, 1, mem_out) < 0)
- error("chirp: claim failed to allocate memory virt=0x%lx size=%ld align=%d",
- (unsigned long)args.virt,
- (long int)args.size,
- (int)args.align);
+ sim_io_internal_error ("chirp: claim failed to allocate memory "
+ "virt=0x%lx size=%ld align=%d",
+ (unsigned long)args.virt,
+ (long int)args.size,
+ (int)args.align);
args.baseaddr = mem_out[0];
}
/* if using virtual addresses, create a 1-1 map of this address space */
if (!data->real_mode) {
- error("chirp: claim method does not support virtual mode");
+ sim_io_internal_error ("chirp: claim method does not support virtual mode");
}
/* return the base address */
TRACE(trace_os_emul, ("claim - out - baseaddr=0x%lx\n",
@@ -1262,13 +1263,15 @@ chirp_emul_release(os_emul_data *data,
mem_in[1] = args.virt;
if (device_instance_call_method(memory, "release",
2, mem_in, 0, NULL) < 0)
- error("chirp: claim failed to release memory virt=0x%lx size=%ld",
- (unsigned long)args.virt,
- (long int)args.size);
+ sim_io_internal_error ("chirp: claim failed to release memory "
+ "virt=0x%lx size=%ld",
+ (unsigned long)args.virt,
+ (long int)args.size);
}
/* if using virtual addresses, remove the 1-1 map of this address space */
if (!data->real_mode) {
- error("chirp: release method does not support virtual mode");
+ sim_io_internal_error ("chirp: release method does not "
+ "support virtual mode");
}
/* return the base address */
TRACE(trace_os_emul, ("release - out\n"));
@@ -1314,7 +1317,7 @@ chirp_emul_enter(os_emul_data *data,
cpu *processor,
unsigned_word cia)
{
- error("chirp: enter method not implemented\n");
+ sim_io_internal_error ("chirp: enter method not implemented\n");
return 0;
}

@@ -1340,7 +1343,7 @@ chirp_emul_chain(os_emul_data *data,
cpu *processor,
unsigned_word cia)
{
- error("chirp: chain method not implemented\n");
+ sim_io_internal_error ("chirp: chain method not implemented");
return 0;
}

@@ -1352,7 +1355,7 @@ chirp_emul_interpret(os_emul_data *data,
cpu *processor,
unsigned_word cia)
{
- error("chirp: interpret method not implemented\n");
+ sim_io_internal_error ("chirp: interpret method not implemented");
return 0;
}

@@ -1361,7 +1364,7 @@ chirp_emul_set_callback(os_emul_data *data,
cpu *processor,
unsigned_word cia)
{
- error("chirp: set_callback method not implemented\n");
+ sim_io_internal_error ("chirp: set_callback method not implemented");
return 0;
}

@@ -1370,7 +1373,7 @@ chirp_emul_set_symbol_lookup(os_emul_data *data,
cpu *processor,
unsigned_word cia)
{
- error("chirp: set_symbol_lookup method not implemented\n");
+ sim_io_internal_error ("chirp: set_symbol_lookup method not implemented");
return 0;
}

diff --git a/sim/ppc/emul_generic.c b/sim/ppc/emul_generic.c
index dc0b2cf..3935113 100644
--- a/sim/ppc/emul_generic.c
+++ b/sim/ppc/emul_generic.c
@@ -218,14 +218,15 @@ emul_do_system_call(os_emul_data *emul_data,
{
emul_syscall_handler *handler = NULL;
if (call >= emul->nr_system_calls)
- error("do_call() os_emul call %d out-of-range\n", call);
+ sim_io_internal_error ("os_emul call %d out-of-range", call);

handler = emul->syscall_descriptor[call].handler;
if (handler == NULL) {
if (emul->syscall_descriptor[call].name) {
- error("do_call() unimplemented call %s\n", emul->syscall_descriptor[call].name);
+ sim_io_internal_error ("unimplemented call %s",
+ emul->syscall_descriptor[call].name);
} else {
- error("do_call() unimplemented call %d\n", call);
+ sim_io_internal_error ("unimplemented call %d", call);
}
}

@@ -305,8 +306,8 @@ emul_add_tree_hardware(device *root)

/* sanity check the number of processors */
if (nr_cpus > MAX_NR_PROCESSORS)
- error("Specified number of processors (%d) exceeds the number configured (%d).\n",
- nr_cpus, MAX_NR_PROCESSORS);
+ sim_io_error ("Specified number of processors (%d) exceeds the number configured (%d).",
+ nr_cpus, MAX_NR_PROCESSORS);

/* set the number of address cells (1 or 2) */
tree_parse(root, "#address-cells %d", WITH_TARGET_WORD_BITSIZE / 32);
diff --git a/sim/ppc/emul_netbsd.c b/sim/ppc/emul_netbsd.c
index 12dfb21..f3b702a 100644
--- a/sim/ppc/emul_netbsd.c
+++ b/sim/ppc/emul_netbsd.c
@@ -1032,7 +1032,7 @@ do___sysctl(os_emul_data *emul,

/* pluck out the management information base id */
if (namelen < 1)
- error("system_call()SYS___sysctl bad name[0]\n");
+ sim_io_error ("system_call()SYS___sysctl bad name[0]");
mib = vm_data_map_read_word(cpu_data_map(processor),
name,
processor,
@@ -1046,7 +1046,7 @@ do___sysctl(os_emul_data *emul,
# error "CTL_HW"
#endif
if (namelen < 2)
- error("system_call()SYS___sysctl - CTL_HW - bad name[1]\n");
+ sim_io_error ("system_call()SYS___sysctl - CTL_HW - bad name[1]\n");
mib = vm_data_map_read_word(cpu_data_map(processor),
name,
processor,
@@ -1062,19 +1062,19 @@ do___sysctl(os_emul_data *emul,
processor,
cia);
if (sizeof(natural_word) > oldlen)
- error("system_call()sysctl - CTL_HW.HW_PAGESIZE - to small\n");
+ sim_io_error ("system_call()sysctl - CTL_HW.HW_PAGESIZE - to small\n");
int_val = 8192;
oldlen = sizeof(int_val);
emul_write_word(oldp, int_val, processor, cia);
emul_write_word(oldlenp, oldlen, processor, cia);
break;
default:
- error("sysctl() CTL_HW.%d unknown\n", mib);
+ sim_io_error ("sysctl() CTL_HW.%d unknown\n", mib);
break;
}
break;
default:
- error("sysctl() name[0]=%d unknown\n", (int)mib);
+ sim_io_error ("sysctl() name[0]=%d unknown\n", (int)mib);
break;
}
emul_write_status(processor, 0, 0); /* always succeed */
diff --git a/sim/ppc/events.c b/sim/ppc/events.c
index 130b28b..f363601 100644
--- a/sim/ppc/events.c
+++ b/sim/ppc/events.c
@@ -193,7 +193,7 @@ insert_event_entry(event_queue *events,
signed64 time_of_event;

if (delta < 0)
- error("what is past is past!\n");
+ sim_io_internal_error ("what is past is past!\n");

/* compute when the event should occure */
time_of_event = event_queue_time(events) + delta;
diff --git a/sim/ppc/gen-icache.c b/sim/ppc/gen-icache.c
index 8acf3fb..1df67b0 100644
--- a/sim/ppc/gen-icache.c
+++ b/sim/ppc/gen-icache.c
@@ -655,7 +655,7 @@ print_icache_internal_function_definition(insn_table *table,
table_entry_print_cpp_line_nr(file, function);
if ((code & generate_with_semantic_icache)) {
lf_print__c_code(file, function->annex);
- lf_printf(file, "error(\"Internal function must longjump\\n\");\n");
+ lf_printf(file, "sim_io_internal_error(\"Internal function must longjump\\n\");\n");
lf_printf(file, "return 0;\n");
}
else {
diff --git a/sim/ppc/gen-idecode.c b/sim/ppc/gen-idecode.c
index 256ba75..deda162 100644
--- a/sim/ppc/gen-idecode.c
+++ b/sim/ppc/gen-idecode.c
@@ -479,7 +479,7 @@ idecode_switch_end(insn_table *table,
print_idecode_switch_illegal(file, result);
break;
case padded_switch_gen:
- lf_printf(file, " error(\"Internal error - bad switch generated\\n\");\n");
+ lf_printf(file, " sim_io_internal_error(\"bad switch generated\");\n");
lf_printf(file, " break;\n");
break;
default:
@@ -1543,6 +1543,6 @@ gen_idecode_c(lf *file,

}
else {
- error("Something is wrong!\n");
+ psim_fatal_error ("Something is wrong!\n");
}
}
diff --git a/sim/ppc/gen-model.c b/sim/ppc/gen-model.c
index 00f2b02..8871012 100644
--- a/sim/ppc/gen-model.c
+++ b/sim/ppc/gen-model.c
@@ -56,7 +56,8 @@ model_c_or_h_function(insn_table *entry,
{
if (function->fields[function_type] == NULL
|| function->fields[function_type][0] == '\0') {
- error("Model function type not specified for %s", function->fields[function_name]);
+ psim_fatal_error ("Model function type not specified for %s",
+ function->fields[function_name]);
}
lf_printf(file, "\n");
lf_print_function_type(file, function->fields[function_type], prefix, " ");
@@ -207,7 +208,8 @@ model_c_function(insn_table *table,
{
if (function->fields[function_type] == NULL
|| function->fields[function_type][0] == '\0') {
- error("Model function return type not specified for %s", function->fields[function_name]);
+ psim_fatal_error ("Model function return type not specified for %s",
+ function->fields[function_name]);
}
else {
lf_printf(file, "\n");
diff --git a/sim/ppc/gen-support.c b/sim/ppc/gen-support.c
index 85ab497..25b1529 100644
--- a/sim/ppc/gen-support.c
+++ b/sim/ppc/gen-support.c
@@ -105,7 +105,7 @@ support_c_function(insn_table *table,
lf_indent(file, +2);
lf_print__c_code(file, function->annex);
if (it_is("internal", function->fields[insn_flags])) {
- lf_printf(file, "error(\"Internal function must longjump\\n\");\n");
+ lf_printf(file, "sim_io_internal_error(\"Internal function must longjump\");\n");
lf_printf(file, "return 0;\n");
}
lf_indent(file, -2);
diff --git a/sim/ppc/hw_core.c b/sim/ppc/hw_core.c
index 0aa0fdd..fe97fce 100644
--- a/sim/ppc/hw_core.c
+++ b/sim/ppc/hw_core.c
@@ -67,7 +67,7 @@ hw_core_attach_address_callback(device *me,
{
core *memory = (core*)device_data(me);
if (space != 0)
- error("core_attach_address_callback() invalid address space\n");
+ sim_io_internal_error ("invalid address space");
core_attach(memory,
attach,
space,
diff --git a/sim/ppc/hw_cpu.c b/sim/ppc/hw_cpu.c
index df807c1..27f21f9 100644
--- a/sim/ppc/hw_cpu.c
+++ b/sim/ppc/hw_cpu.c
@@ -131,8 +131,7 @@ hw_cpu_interrupt_event(device *me,
{
hw_cpu_device *hw_cpu = (hw_cpu_device*)device_data(me);
if (my_port < 0 || my_port >= hw_cpu_nr_interrupt_ports)
- error("hw_cpu_interrupt_event_callback: interrupt port out of range %d\n",
- my_port);
+ sim_io_internal_error ("interrupt port out of range %d", my_port);
switch (my_port) {
/*case hw_cpu_hard_reset:*/
/*case hw_cpu_soft_reset:*/
@@ -141,8 +140,8 @@ hw_cpu_interrupt_event(device *me,
break;
/*case hw_cpu_machine_check_interrupt:*/
default:
- error("hw_cpu_deliver_interrupt: unimplemented interrupt port %d\n",
- my_port);
+ sim_io_internal_error ("unimplemented interrupt port %d",
+ my_port);
break;
}
}
diff --git a/sim/ppc/hw_init.c b/sim/ppc/hw_init.c
index 0e7403b..896b038 100644
--- a/sim/ppc/hw_init.c
+++ b/sim/ppc/hw_init.c
@@ -350,7 +350,7 @@ update_for_binary_section(bfd *abfd,

/* If there is an .interp section, it means it needs a shared library interpreter. */
if (strcmp(".interp", bfd_get_section_name(abfd, the_section)) == 0)
- error("Shared libraries are not yet supported.\n");
+ sim_io_internal_error ("Shared libraries are not yet supported.\n");

/* determine the devices access */
access = access_read;
diff --git a/sim/ppc/hw_nvram.c b/sim/ppc/hw_nvram.c
index f8caaa8..bf89556 100644
--- a/sim/ppc/hw_nvram.c
+++ b/sim/ppc/hw_nvram.c
@@ -201,7 +201,7 @@ hw_nvram_update_clock(hw_nvram_device *nvram,
static void
hw_nvram_set_clock(hw_nvram_device *nvram, cpu *processor)
{
- error ("fixme - how do I set the localtime\n");
+ psim_fatal_error ("fixme - how do I set the localtime\n");
}

static unsigned
diff --git a/sim/ppc/hw_phb.c b/sim/ppc/hw_phb.c
index 8e3fb17..8425637 100644
--- a/sim/ppc/hw_phb.c
+++ b/sim/ppc/hw_phb.c
@@ -791,7 +791,7 @@ hw_phb_unit_encode(device *me,
(unsigned long)unit_address->cells[2]);
}
if (strlen(buf) > sizeof_buf)
- error("buffer overflow");
+ sim_io_internal_error ("buffer overflow");
return strlen(buf);
}

@@ -1049,7 +1049,7 @@ hw_phb_create(const char *name,
pci_space->name = "special";
break;
default:
- error ("internal error");
+ sim_io_internal_error ("internal error");
break;
}
}
diff --git a/sim/ppc/hw_register.c b/sim/ppc/hw_register.c
index de65c9f..3bc29a6 100644
--- a/sim/ppc/hw_register.c
+++ b/sim/ppc/hw_register.c
@@ -101,7 +101,7 @@ do_register_init(device *me,
&value,
name,
cooked_transfer) <= 0)
- error("Invalid register name %s\n", name);
+ psim_fatal_error ("Invalid register name %s\n", name);
}
}

diff --git a/sim/ppc/hw_sem.c b/sim/ppc/hw_sem.c
index f1c3295..585acb6 100644
--- a/sim/ppc/hw_sem.c
+++ b/sim/ppc/hw_sem.c
@@ -121,10 +121,10 @@ hw_sem_init_data(device *me)
/* initialize the properties of the sem */

if (device_find_property(me, "key") == NULL)
- error("sem_init_data() required key property is missing\n");
+ sim_io_internal_error ("required key property is missing");

if (device_find_property(me, "value") == NULL)
- error("sem_init_data() required value property is missing\n");
+ sim_io_internal_error ("required value property is missing");

sem->key = (key_t) device_find_integer_property(me, "key");
DTRACE(sem, ("semaphore key (%d)\n", sem->key) );
@@ -142,22 +142,22 @@ hw_sem_init_data(device *me)

sem->id = semget(sem->key, 1, IPC_CREAT | 0660);
if (sem->id == -1)
- error("hw_sem_init_data() semget failed\n");
+ sim_io_internal_error ("semget failed\n");

help.val = sem->initial;
status = semctl( sem->id, 0, SETVAL, help );
if (status == -1)
- error("hw_sem_init_data() semctl -- set value failed\n");
+ sim_io_internal_error ("semctl -- set value failed");

} else {
sem->id = semget(sem->key, 1, 0660);
if (sem->id == -1)
- error("hw_sem_init_data() semget failed\n");
+ sim_io_internal_error ("semget failed");
}

sem->count = semctl( sem->id, 0, GETVAL, help );
if (sem->count == -1)
- error("hw_sem_init_data() semctl -- get value failed\n");
+ sim_io_internal_error ("semctl -- get value failed\n");
DTRACE(sem, ("semaphore OS value (%d)\n", sem->count) );
}

@@ -173,10 +173,10 @@ hw_sem_attach_address_callback(device *me,
hw_sem_device *sem = (hw_sem_device*)device_data(me);

if (space != 0)
- error("sem_attach_address_callback() invalid address space\n");
+ sim_io_internal_error ("invalid address space");

if (nr_bytes == 12)
- error("sem_attach_address_callback() invalid size\n");
+ sim_io_internal_error ("invalid size");

sem->physical_address = addr;
DTRACE(sem, ("semaphore physical_address=0x%x\n", addr));
@@ -202,13 +202,13 @@ hw_sem_io_read_buffer(device *me,
DTRACE(sem, ("semaphore read addr=0x%x length=%d\n", addr, nr_bytes));

if (!(addr >= sem->physical_address && addr <= sem->physical_address + 11))
- error("hw_sem_io_read_buffer() invalid address - out of range\n");
+ sim_io_internal_error ("invalid address - out of range");

if ((addr % 4) != 0)
- error("hw_sem_io_read_buffer() invalid address - alignment\n");
+ sim_io_internal_error ("invalid address - alignment");

if (nr_bytes != 4)
- error("hw_sem_io_read_buffer() invalid length\n");
+ sim_io_internal_error ("invalid length");

switch ( (addr - sem->physical_address) / 4 ) {

@@ -223,7 +223,7 @@ hw_sem_io_read_buffer(device *me,
status = semop(sem->id, &sb, 1);
if (status == -1) {
perror( "hw_sem.c: lock" );
- error("hw_sem_io_read_buffer() sem lock\n");
+ sim_io_internal_error ("sem lock");
}

DTRACE(sem, ("semaphore lock %d\n", sem->count));
@@ -237,14 +237,13 @@ hw_sem_io_read_buffer(device *me,
status = semop(sem->id, &sb, 1);
if (status == -1) {
perror( "hw_sem.c: unlock" );
- error("hw_sem_io_read_buffer() sem unlock\n");
+ sim_io_internal_error ("sem unlock");
}
DTRACE(sem, ("semaphore unlock %d\n", sem->count));
break;

default:
- error("hw_sem_io_read_buffer() invalid address - unknown error\n");
- break;
+ sim_io_internal_error ("invalid address - unknown error");
}

/* assume target is big endian */
@@ -253,7 +252,7 @@ hw_sem_io_read_buffer(device *me,
DTRACE(sem, ("semaphore OS value (%d)\n", u32) );
if (u32 == 0xffffffff) {
perror( "hw_sem.c: getval" );
- error("hw_sem_io_read_buffer() semctl -- get value failed\n");
+ sim_io_internal_error ("semctl -- get value failed");
}

memcpy(dest, &u32, nr_bytes);
diff --git a/sim/ppc/hw_shm.c b/sim/ppc/hw_shm.c
index 3128871..75fb100 100644
--- a/sim/ppc/hw_shm.c
+++ b/sim/ppc/hw_shm.c
@@ -102,14 +102,14 @@ hw_shm_init_data(device *me)

/* Obtain the Key Value */
if (device_find_property(me, "key") == NULL)
- error("shm_init_data() required key property is missing\n");
+ sim_io_internal_error ("shm_init_data() required key property is missing\n");

shm->key = (key_t) device_find_integer_property(me, "key");
DTRACE(shm, ("shm key (0x%08x)\n", shm->key) );

/* Figure out where this memory is in address space and how long it is */
if ( !device_find_reg_array_property(me, "reg", 0, &reg) )
- error("hw_shm_init_data() no address registered\n");
+ sim_io_internal_error ("no address registered");

/* Determine the address and length being as paranoid as possible */
shm->physical_address = 0xffffffff;
@@ -138,11 +138,11 @@ hw_shm_init_data(device *me)
/* Now actually attach to or create the shared memory area */
shm->id = shmget(shm->key, shm->sizeof_memory, IPC_CREAT | 0660);
if (shm->id == -1)
- error("hw_shm_init_data() shmget failed\n");
+ sim_io_internal_error ("shmget failed");

shm->shm_address = shmat(shm->id, (char *)0, SHM_RND);
if (shm->shm_address == (void *)-1)
- error("hw_shm_init_data() shmat failed\n");
+ sim_io_internal_error ("shmat failed");
}

static void
@@ -157,10 +157,10 @@ hw_shm_attach_address_callback(device *me,
hw_shm_device *shm = (hw_shm_device*)device_data(me);

if (space != 0)
- error("shm_attach_address_callback() invalid address space\n");
+ sim_io_internal_error ("invalid address space");

if (nr_bytes == 0)
- error("shm_attach_address_callback() invalid size\n");
+ sim_io_internal_error ("invalid size");
}

diff --git a/sim/ppc/igen.c b/sim/ppc/igen.c
index 5a1df3e..321e225 100644
--- a/sim/ppc/igen.c
+++ b/sim/ppc/igen.c
@@ -440,7 +440,7 @@ main(int argc,
code |= generate_with_icache;
break;
default:
- error (NULL, "Expecting -Ggen-icache or -Ggen-icache=<N>\n");
+ psim_fatal_error ("Expecting -Ggen-icache or -Ggen-icache=<N>\n");
}
}
}
@@ -557,7 +557,7 @@ main(int argc,
real_file_name = NULL;
break;
default:
- error("unknown option\n");
+ psim_fatal_error ("unknown option\n");
}
}
return 0;
diff --git a/sim/ppc/interrupts.c b/sim/ppc/interrupts.c
index db100fd..9c4b0ba 100644
--- a/sim/ppc/interrupts.c
+++ b/sim/ppc/interrupts.c
@@ -141,8 +141,7 @@ machine_check_interrupt(cpu *processor,
cpu_restart(processor, cia);

default:
- error("internal error - machine_check_interrupt - bad switch");
-
+ sim_io_internal_error ("bad switch");
}
}

@@ -159,8 +158,7 @@ data_storage_interrupt(cpu *processor,

case USER_ENVIRONMENT:
case VIRTUAL_ENVIRONMENT:
- error("internal error - data_storage_interrupt - should not be called in VEA mode");
- break;
+ sim_io_internal_error ("should not be called in VEA mode");

case OPERATING_ENVIRONMENT:
{
@@ -185,8 +183,7 @@ data_storage_interrupt(cpu *processor,
DSISR = dsisr_earwax_disabled | direction;
break;
default:
- error("internal error - data_storage_interrupt - reason %d not implemented", reason);
- break;
+ sim_io_internal_error ("reason %d not implemented", reason);
}
DAR = (spreg)ea;
TRACE(trace_interrupts, ("data storage interrupt - cia=0x%lx DAR=0x%lx DSISR=0x%lx\n",
@@ -198,8 +195,7 @@ data_storage_interrupt(cpu *processor,
}

default:
- error("internal error - data_storage_interrupt - bad switch");
-
+ sim_io_internal_error ("bad switch");
}
}

@@ -214,7 +210,7 @@ instruction_storage_interrupt(cpu *processor,

case USER_ENVIRONMENT:
case VIRTUAL_ENVIRONMENT:
- error("internal error - instruction_storage_interrupt - should not be called in VEA mode");
+ sim_io_internal_error ("should not be called in VEA mode");

case OPERATING_ENVIRONMENT:
{
@@ -234,7 +230,7 @@ instruction_storage_interrupt(cpu *processor,
break;
default:
srr1_set = 0;
- error("internal error - instruction_storage_interrupt - reason %d not implemented");
+ sim_io_internal_error ("reason %d not implemented");
break;
}
TRACE(trace_interrupts, ("instruction storage interrupt - cia=0x%lx SRR1|=0x%lx\n",
@@ -245,8 +241,7 @@ instruction_storage_interrupt(cpu *processor,
}

default:
- error("internal error - instruction_storage_interrupt - bad switch");
-
+ sim_io_internal_error ("bad switch");
}
}

@@ -275,8 +270,7 @@ alignment_interrupt(cpu *processor,
cpu_restart(processor, cia);

default:
- error("internal error - alignment_interrupt - bad switch");
-
+ sim_io_internal_error ("bad switch");
}
}

@@ -319,7 +313,7 @@ program_interrupt(cpu *processor,
"problematic branch detected, see MPC860 C0 errata");
break;
default:
- error("internal error - program_interrupt - reason %d not implemented", reason);
+ sim_io_internal_error ("reason %d not implemented", reason);
}

case OPERATING_ENVIRONMENT:
@@ -346,7 +340,7 @@ program_interrupt(cpu *processor,
break;
default:
srr1_set = 0;
- error("internal error - program_interrupt - reason %d not implemented", reason);
+ sim_io_internal_error ("reason %d not implemented", reason);
break;
}
TRACE(trace_interrupts, ("program interrupt - cia=0x%lx SRR1|=0x%lx\n",
@@ -357,8 +351,7 @@ program_interrupt(cpu *processor,
}

default:
- error("internal error - program_interrupt - bad switch");
-
+ sim_io_internal_error ("bad switch");
}
}

@@ -381,8 +374,7 @@ floating_point_unavailable_interrupt(cpu *processor,
cpu_restart(processor, cia);

default:
- error("internal error - floating_point_unavailable_interrupt - bad switch");
-
+ sim_io_internal_error ("bad switch");
}
}

@@ -406,8 +398,7 @@ system_call_interrupt(cpu *processor,
cpu_restart(processor, cia);

default:
- error("internal error - system_call_interrupt - bad switch");
-
+ sim_io_internal_error ("bad switch");
}
}

@@ -428,8 +419,7 @@ floating_point_assist_interrupt(cpu *processor,
cpu_restart(processor, cia);

default:
- error("internal error - floating_point_assist_interrupt - bad switch");
-
+ sim_io_internal_error ("bad switch");
}
}

diff --git a/sim/ppc/ld-cache.c b/sim/ppc/ld-cache.c
index 29a7035..dfd0da9 100644
--- a/sim/ppc/ld-cache.c
+++ b/sim/ppc/ld-cache.c
@@ -118,7 +118,7 @@ main(int argc, char **argv)
{
cache_table *rules;
if (argc != 3)
- error("Usage: cache <cache-file> <hi-bit-nr>\n");
+ psim_fatal_error ("Usage: cache <cache-file> <hi-bit-nr>\n");
rules = load_cache_table(argv[1], a2i(argv[2]));
dump_cache_rules(rules, 0);
return 0;
diff --git a/sim/ppc/ld-decode.c b/sim/ppc/ld-decode.c
index 3b2e1a0..dc69baf 100644
--- a/sim/ppc/ld-decode.c
+++ b/sim/ppc/ld-decode.c
@@ -146,7 +146,7 @@ main(int argc, char **argv)
{
decode_table *rules;
if (argc != 3)
- error("Usage: decode <decode-file> <hi-bit-nr>\n");
+ psim_fatal_error ("Usage: decode <decode-file> <hi-bit-nr>\n");
rules = load_decode_table(argv[1], a2i(argv[2]));
dump_decode_rules(rules, 0);
return 0;
diff --git a/sim/ppc/ld-insn.c b/sim/ppc/ld-insn.c
index e39131c..b673615 100644
--- a/sim/ppc/ld-insn.c
+++ b/sim/ppc/ld-insn.c
@@ -92,8 +92,8 @@ parse_insn_format(table_entry *entry,

/* sanity check */
if (!isdigit(*chp)) {
- error("%s:%d: missing position field at `%s'\n",
- entry->file_name, entry->line_nr, chp);
+ psim_fatal_error ("%s:%d: missing position field at `%s'\n",
+ entry->file_name, entry->line_nr, chp);
}

/* break out the bit position */
@@ -104,8 +104,8 @@ parse_insn_format(table_entry *entry,
if (*chp == '.' && strlen_pos > 0)
chp++;
else {
- error("%s:%d: missing field value at %s\n",
- entry->file_name, entry->line_nr, chp);
+ psim_fatal_error ("%s:%d: missing field value at %s\n",
+ entry->file_name, entry->line_nr, chp);
break;
}

@@ -119,8 +119,8 @@ parse_insn_format(table_entry *entry,
if (*chp == ',')
chp++;
else if (*chp != '\0' || strlen_val == 0) {
- error("%s:%d: missing field terminator at %s\n",
- entry->file_name, entry->line_nr, chp);
+ psim_fatal_error ("%s:%d: missing field terminator at %s\n",
+ entry->file_name, entry->line_nr, chp);
break;
}

@@ -198,7 +198,7 @@ parse_include_entry (table *file,
{
/* parse the include file_entry */
if (file_entry->nr_fields < 4)
- error ("Incorrect nr fields for include record\n");
+ psim_fatal_error ("Incorrect nr fields for include record\n");
/* process it */
if (!is_filtered_out(file_entry->fields[include_flags], filters))
{
@@ -308,8 +308,8 @@ insn_table_insert_insn(insn_table *table,
}

if (!model_ptr)
- error("%s:%d: machine model `%s' was not known about\n",
- file_entry->file_name, file_entry->line_nr, name);
+ psim_fatal_error("%s:%d: machine model `%s' was not known about\n",
+ file_entry->file_name, file_entry->line_nr, name);
}

/* insert it according to the order of the fields */
@@ -645,7 +645,7 @@ insn_table_find_opcode_field(insn *insns,
curr_opcode->boolean_constant = rule->special_constant;
break;
default:
- error("Something is going wrong\n");
+ psim_fatal_error ("Something is going wrong\n");
}

return curr_opcode;
@@ -972,7 +972,8 @@ main(int argc, char **argv)
cache_table *cache_rules = NULL;

if (argc != 5)
- error("Usage: insn <filter> <hi-bit-nr> <decode-table> <insn-table>\n");
+ psim_fatal_error ("\
+Usage: insn <filter> <hi-bit-nr> <decode-table> <insn-table>\n");

filters = new_filter(argv[1], filters);
hi_bit_nr = a2i(argv[2]);
diff --git a/sim/ppc/lf.c b/sim/ppc/lf.c
index 1794a27..d0d3f6a 100644
--- a/sim/ppc/lf.c
+++ b/sim/ppc/lf.c
@@ -217,7 +217,7 @@ lf_print__c_code(lf *file,
chp++;
}
if (in_bit_field)
- error("bit field paren miss match some where\n");
+ psim_fatal_error ("bit field paren miss match some where\n");
if (*chp == '\n') {
nr += lf_putchr(file, '\n');
chp++;
diff --git a/sim/ppc/main.c b/sim/ppc/main.c
index 667c02f..d2c8060 100644
--- a/sim/ppc/main.c
+++ b/sim/ppc/main.c
@@ -78,7 +78,7 @@ sim_io_printf_filtered(const char *msg, ...)
}

void
-error (const char *msg, ...)
+psim_fatal_error (const char *msg, ...)
{
va_list ap;
va_start(ap, msg);
@@ -111,7 +111,7 @@ sim_io_write_stdout(const char *buf,
return write(1, buf, sizeof_buf);
break;
default:
- error("sim_io_write_stdout: invalid switch\n");
+ sim_io_internal_error ("sim_io_write_stdout: invalid switch\n");
}
return 0;
}
@@ -134,7 +134,7 @@ sim_io_write_stderr(const char *buf,
return write(2, buf, sizeof_buf);
break;
default:
- error("sim_io_write_stdout: invalid switch\n");
+ sim_io_internal_error ("sim_io_write_stdout: invalid switch\n");
}
return 0;
}
@@ -204,7 +204,7 @@ sim_io_read_stdin(char *buf,
break;
#endif
default:
- error("sim_io_read_stdin: invalid switch\n");
+ sim_io_internal_error ("invalid switch");
break;
}
return 0;
@@ -220,19 +220,16 @@ sim_io_flush_stdoutput(void)
case DONT_USE_STDIO:
break;
default:
- error("sim_io_flush_stdoutput: invalid switch\n");
+ sim_io_internal_error ("invalid switch");
break;
}
}

-void
-sim_io_error (SIM_DESC sd, const char *msg, ...)
+static void
+sim_io_verror (const char *msg, va_list ap)
{
- va_list ap;
- va_start(ap, msg);
vprintf(msg, ap);
printf("\n");
- va_end(ap);

/* any final clean up */
if (ppc_trace[trace_print_info] && simulation != NULL)
@@ -241,13 +238,34 @@ sim_io_error (SIM_DESC sd, const char *msg, ...)
exit (1);
}

+void
+sim_io_error (const char *msg, ...)
+{
+ va_list ap;
+
+ va_start (ap, msg);
+ sim_io_verror (msg, ap);
+ va_end (ap);
+}
+
+void
+sim_io_internal_error_1 (const char *file, int line,
+ const char *msg, ...)
+{
+ va_list ap;
+
+ printf ("%s:%d: ", file, line);
+ va_start (ap, msg);
+ sim_io_verror (msg, ap);
+ va_end (ap);
+}

void *
zalloc(long size)
{
void *memory = malloc(size);
if (memory == NULL)
- error("zalloc failed\n");
+ sim_io_internal_error ("zalloc failed");
memset(memory, 0, size);
return memory;
}
@@ -312,11 +330,9 @@ main(int argc, char **argv)
status = psim_get_status(simulation);
switch (status.reason) {
case was_continuing:
- error("psim: continuing while stopped!\n");
- return 0;
+ psim_fatal_error ("psim: continuing while stopped!\n");
case was_trap:
- error("psim: no trap insn\n");
- return 0;
+ psim_fatal_error ("psim: no trap insn\n");
case was_exited:
return status.signal;
case was_signalled:
@@ -325,7 +341,6 @@ main(int argc, char **argv)
(long)status.program_counter);
return status.signal;
default:
- error("unknown halt condition\n");
- return 0;
+ psim_fatal_error ("unknown halt condition\n");
}
}
diff --git a/sim/ppc/misc.c b/sim/ppc/misc.c
index 8c21bd3..223abdc 100644
--- a/sim/ppc/misc.c
+++ b/sim/ppc/misc.c
@@ -38,7 +38,7 @@
#endif

void
-error (char *msg, ...)
+psim_fatal_error (const char *msg, ...)
{
va_list ap;
va_start(ap, msg);
@@ -52,7 +52,7 @@ zalloc(long size)
{
void *memory = malloc(size);
if (memory == NULL)
- error("zalloc failed\n");
+ psim_fatal_error ("zalloc failed\n");
memset(memory, 0, size);
return memory;
}
@@ -196,7 +196,7 @@ name2i(const char *names,
if (curr->i >= 0)
return curr->i;
else
- error("%s contains no valid names\n", names);
+ psim_fatal_error ("%s contains no valid names\n", names);
return 0;
}

@@ -209,6 +209,6 @@ i2name(const int i,
return map->name;
map++;
}
- error("map lookup failed for %d\n", i);
+ psim_fatal_error ("map lookup failed for %d\n", i);
return NULL;
}
diff --git a/sim/ppc/misc.h b/sim/ppc/misc.h
index 232f2ea..29c662c 100644
--- a/sim/ppc/misc.h
+++ b/sim/ppc/misc.h
@@ -42,19 +42,19 @@
#endif

-
#include "filter_filename.h"

-extern void error
-(char *msg, ...);
-
-#define ASSERT(EXPRESSION) \
-do { \
- if (!(EXPRESSION)) { \
- error("%s:%d: assertion failed - %s\n", \
- filter_filename (__FILE__), __LINE__, #EXPRESSION); \
- } \
-} while (0)
+extern void psim_fatal_error (const char *msg, ...);
+
+#define ASSERT(EXPRESSION) \
+ do { \
+ if (!(EXPRESSION)) \
+ { \
+ psim_fatal_error ("%s:%d: assertion failed - %s\n", \
+ filter_filename (__FILE__), \
+ __LINE__, #EXPRESSION); \
+ } \
+ } while (0)

#define ZALLOC(TYPE) (TYPE*)zalloc(sizeof(TYPE))
#define NZALLOC(TYPE,N) ((TYPE*) zalloc (sizeof(TYPE) * (N)))
diff --git a/sim/ppc/mon.c b/sim/ppc/mon.c
index 8235b66..921bad3 100644
--- a/sim/ppc/mon.c
+++ b/sim/ppc/mon.c
@@ -98,7 +98,7 @@ mon_cpu(mon *monitor,
int cpu_nr)
{
if (cpu_nr < 0 || cpu_nr >= MAX_NR_PROCESSORS)
- error("mon_cpu() - invalid cpu number\n");
+ sim_io_internal_error ("invalid cpu number");
return &monitor->cpu_monitor[cpu_nr];
}

diff --git a/sim/ppc/os_emul.c b/sim/ppc/os_emul.c
index 73792c9..4e532e7 100644
--- a/sim/ppc/os_emul.c
+++ b/sim/ppc/os_emul.c
@@ -56,7 +56,7 @@ os_emul_create(const char *file_name,
image = bfd_openr(file_name, NULL);
if (image == NULL) {
bfd_perror(file_name);
- error("nothing loaded\n");
+ sim_io_error ("nothing loaded");
}

/* check it is an executable */
@@ -125,7 +125,7 @@ os_emul_system_call(cpu *processor,
if (emulation != (os_emul*)0 && emulation->system_call != 0)
emulation->system_call(processor, cia, emulation->data);
else
- error("System call emulation not available\n");
+ sim_io_error ("System call emulation not available");
}

INLINE_OS_EMUL\
diff --git a/sim/ppc/ppc-instructions b/sim/ppc/ppc-instructions
index 1a2e51a..6b7c931 100644
--- a/sim/ppc/ppc-instructions
+++ b/sim/ppc/ppc-instructions
@@ -803,7 +803,7 @@ model_data *::model-function::model_create:cpu *processor
case MODEL_ppc603: model_ptr->max_nr_writebacks = 2; break;
case MODEL_ppc603e: model_ptr->max_nr_writebacks = 2; break;
case MODEL_ppc604: model_ptr->max_nr_writebacks = 2; break;
- default: error ("Unknown model %d\n", CURRENT_MODEL);
+ default: sim_io_internal_error ("Unknown model %d", CURRENT_MODEL);
}
return model_ptr;

@@ -1032,7 +1032,7 @@ unsigned64::function::DOUBLE:unsigned32 WORD
| INSERTED64(EXTRACTED32(WORD, 2, 31), 5, (63 - 29)));
}
else {
- error("DOUBLE - unknown case\n");
+ sim_io_internal_error ("unknown case");
FRT = 0;
}
return FRT;
@@ -1357,7 +1357,7 @@ unsigned64::function::select_qnan:unsigned64 fra, unsigned64 frb, unsigned64 frc
else if (generate_qnan)
frt = MASK64(1, 12); /* 0x7FF8_0000_0000_0000 */
else
- error("select_qnan - default reached\n");
+ sim_io_internal_error ("default reached");
return frt;

@@ -1430,10 +1430,10 @@ void::function::invalid_arithemetic_operation:cpu *processor, unsigned_word cia,
else {
/* invalid operation exception disabled */
if (instruction_is_convert_to_64bit) {
- error("oopsi");
+ sim_io_internal_error ("oopsi");
}
else if (instruction_is_convert_to_32bit) {
- error("oopsi");
+ sim_io_internal_error ("oopsi");
}
else { /* arrith, frsp */
*frt = select_qnan(fra, frb, frc,
diff --git a/sim/ppc/psim.c b/sim/ppc/psim.c
index 3e322e3..6ccbf5f 100644
--- a/sim/ppc/psim.c
+++ b/sim/ppc/psim.c
@@ -112,7 +112,7 @@ find_arg(char *err_msg,
{
*ptr_to_argp += 1;
if (argv[*ptr_to_argp] == NULL)
- error(err_msg);
+ sim_io_internal_error (err_msg);
return argv[*ptr_to_argp];
}

@@ -332,7 +332,8 @@ psim_options(device *root,
{
tree_parse(root, "/options/mpc860c0 %s", param+9);
}
- else error("Invalid mpc860c0 option for -o\n");
+ else
+ sim_io_error ("Invalid mpc860c0 option for -o");
}
else
current = tree_parse(current, "%s", param);
diff --git a/sim/ppc/sim_callbacks.h b/sim/ppc/sim_callbacks.h
index 61c6e2f..3d9bdd1 100644
--- a/sim/ppc/sim_callbacks.h
+++ b/sim/ppc/sim_callbacks.h
@@ -29,8 +29,19 @@
void sim_io_printf_filtered
(const char *msg, ...) __attribute__ ((format (printf, 1, 2)));

-void NORETURN error
-(const char *msg, ...);
+void NORETURN sim_io_error
+(const char *msg, ...) __attribute__ ((format (printf, 1, 2)));
+
+void NORETURN sim_io_internal_error_1 (const char *file, int line,
+ const char *msg, ...)
+ __attribute__ ((format (printf, 3, 4)));
+
+#define sim_io_internal_error(...) \
+ sim_io_internal_error_1 (__FILE__, __LINE__, __VA_ARGS__)
+
+/* Hack to catch calls to error with a hard error. */
+struct foo {};
+void NORETURN error (struct foo t);

/* External environment:
diff --git a/sim/ppc/sim_calls.c b/sim/ppc/sim_calls.c
index 470c958..b2e9b2f 100644
--- a/sim/ppc/sim_calls.c
+++ b/sim/ppc/sim_calls.c
@@ -116,14 +116,14 @@ sim_load (SIM_DESC sd, const char *prog, bfd *abfd, int from_tty)
{
abfd = bfd_openr (prog, 0);
if (abfd == NULL)
- error ("psim: can't open \"%s\": %s\n",
- prog, bfd_errmsg (bfd_get_error ()));
+ sim_io_error ("psim: can't open \"%s\": %s\n",
+ prog, bfd_errmsg (bfd_get_error ()));
if (!bfd_check_format (abfd, bfd_object))
{
const char *errmsg = bfd_errmsg (bfd_get_error ());
bfd_close (abfd);
- error ("psim: \"%s\" is not an object file: %s\n",
- prog, errmsg);
+ sim_io_error ("psim: \"%s\" is not an object file: %s\n",
+ prog, errmsg);
}
bfd_close (abfd);
}
@@ -173,7 +173,7 @@ sim_create_inferior (SIM_DESC sd,
entry_point));

if (simulator == NULL)
- error ("No program loaded");
+ sim_io_error ("No program loaded");

if (abfd != NULL)
entry_point = bfd_get_start_address (abfd);
@@ -299,7 +299,7 @@ sim_io_read_stdin(char *buf,
return callbacks->read(callbacks, 0, buf, sizeof_buf);
break;
default:
- error("sim_io_read_stdin: unaccounted switch\n");
+ sim_io_internal_error ("unaccounted switch");
break;
}
return 0;
@@ -317,7 +317,7 @@ sim_io_write_stdout(const char *buf,
return callbacks->write(callbacks, 1, buf, sizeof_buf);
break;
default:
- error("sim_io_write_stdout: unaccounted switch\n");
+ sim_io_internal_error ("unaccounted switch");
break;
}
return 0;
@@ -336,7 +336,7 @@ sim_io_write_stderr(const char *buf,
return callbacks->write(callbacks, 3, buf, sizeof_buf);
break;
default:
- error("sim_io_write_stderr: unaccounted switch\n");
+ sim_io_internal_error ("unaccounted switch");
break;
}
return 0;
@@ -355,7 +355,7 @@ sim_io_printf_filtered(const char *fmt,
va_end(ap);
/* sanity check */
if (strlen(message) >= sizeof(message))
- error("sim_io_printf_filtered: buffer overflow\n");
+ sim_io_internal_error ("buffer overflow");
callbacks->printf_filtered(callbacks, "%s", message);
}

@@ -369,13 +369,23 @@ sim_io_flush_stdoutput(void)
case DONT_USE_STDIO:
break;
default:
- error("sim_io_read_stdin: unaccounted switch\n");
- break;
+ sim_io_internal_error ("unaccounted switch");
}
}

void
-sim_io_error (SIM_DESC sd, const char *fmt, ...)
+sim_io_error (const char *fmt, ...)
+{
+ va_list ap;
+ va_start(ap, fmt);
+ callbacks->evprintf_filtered (callbacks, fmt, ap);
+ va_end(ap);
+ callbacks->error (callbacks, "");
+}
+
+void
+sim_io_internal_error_1 (const char *file, int line,
+ const char *fmt, ...)
{
va_list ap;
va_start(ap, fmt);
@@ -390,8 +400,6 @@ void *
zalloc(long size)
{
void *memory = (void*)xmalloc(size);
- if (memory == NULL)
- error("xmalloc failed\n");
memset(memory, 0, size);
return memory;
}
diff --git a/sim/ppc/table.c b/sim/ppc/table.c
index 43c7462..2975b93 100644
--- a/sim/ppc/table.c
+++ b/sim/ppc/table.c
@@ -104,7 +104,7 @@ table_push (table *root,
/* free (dup_name); */
if (include->next == NULL)
{
- error ("Problem opening file `%s'\n", file_name);
+ fprintf (stderr, "Problem opening file `%s'\n", file_name);
perror (file_name);
exit (1);
}
diff --git a/sim/ppc/tree.c b/sim/ppc/tree.c
index 5d20bf4..d135a21 100644
--- a/sim/ppc/tree.c
+++ b/sim/ppc/tree.c
@@ -95,7 +95,7 @@ split_device_specifier(device *current,
alias[len] = device_specifier[len];
len++;
if (len >= sizeof(alias))
- error("split_device_specifier: buffer overflow");
+ sim_io_error ("split_device_specifier: buffer overflow");
}
alias[len] = '\0';
if (aliases != NULL
@@ -113,7 +113,7 @@ split_device_specifier(device *current,

/* check no overflow */
if (strlen(spec->buf) >= sizeof(spec->buf))
- error("split_device_specifier: buffer overflow\n");
+ sim_io_error ("split_device_specifier: buffer overflow\n");

/* strip leading spaces */
chp = spec->buf;
@@ -811,7 +811,7 @@ tree_parse(device *current,
vsprintf(device_specifier, fmt, ap);
va_end(ap);
if (strlen(device_specifier) >= sizeof(device_specifier))
- error("device_tree_add_deviced: buffer overflow\n");
+ sim_io_internal_error ("device_tree_add_deviced: buffer overflow\n");
}

/* construct the tree down to the final device */
diff --git a/sim/ppc/vm.c b/sim/ppc/vm.c
index 8cf4e8f..3f13af3 100644
--- a/sim/ppc/vm.c
+++ b/sim/ppc/vm.c
@@ -456,11 +456,11 @@ vm_create(core *physical)
if (nr_om_segment_tlb_entries
!= (1 << (om_segment_tlb_index_stop_bit
- om_segment_tlb_index_start_bit + 1)))
- error("internal error - vm_create - problem with om_segment constants\n");
+ sim_io_internal_error ("problem with om_segment constants");
if (nr_om_page_tlb_entries
!= (1 << (om_page_tlb_index_stop_bit
- om_page_tlb_index_start_bit + 1)))
- error("internal error - vm_create - problem with om_page constants\n");
+ sim_io_internal_error ("problem with om_page constants");

/* create the new vm register file */
virtual = ZALLOC(vm);
@@ -698,7 +698,7 @@ om_interrupt(cpu *processor,
instruction_storage_interrupt(processor, cia, reason);
break;
default:
- error("internal error - om_interrupt - unexpected access type %d", access);
+ sim_io_internal_error ("unexpected access type %d", access);
}
}

@@ -1054,7 +1054,7 @@ vm_translate(om_map *map,
processor, cia,
abort);
default:
- error("internal error - vm_translate - bad switch");
+ sim_io_internal_error ("bad switch");
return 0;
}
}
diff --git a/sim/ppc/vm_n.h b/sim/ppc/vm_n.h
index 563cd1c..a066c58 100644
--- a/sim/ppc/vm_n.h
+++ b/sim/ppc/vm_n.h
@@ -73,7 +73,7 @@ vm_data_map_read_N(vm_data_map *map,
return val;
}
default:
- error("internal error - vm_data_map_read_N - bad switch");
+ sim_io_internal_error ("bad switch");
return 0;
}
}
@@ -120,7 +120,7 @@ vm_data_map_write_N(vm_data_map *map,
}
break;
default:
- error("internal error - vm_data_map_write_N - bad switch");
+ sim_io_internal_error ("bad switch");
}
}
}
--
2.5.5