From 979c3c25fd3f51d8effb28593edf222841053de9 Mon Sep 17 00:00:00 2001 From: Michael Meissner Date: Mon, 8 Jan 1996 18:01:17 +0000 Subject: Latest cagney update --- sim/ppc/emul_bugapi.c | 98 +++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 88 insertions(+), 10 deletions(-) (limited to 'sim/ppc/emul_bugapi.c') diff --git a/sim/ppc/emul_bugapi.c b/sim/ppc/emul_bugapi.c index 309869e..252c3ce 100644 --- a/sim/ppc/emul_bugapi.c +++ b/sim/ppc/emul_bugapi.c @@ -23,6 +23,27 @@ #define _EMUL_BUGAPI_C_ +/* from bug.S - Dale Rahn */ +#define _INCHR 0x00 +#define _INSTAT 0x01 +#define _INLN 0x02 +#define _READSTR 0x03 +#define _READLN 0x04 +#define _OUTCHR 0x20 +#define _OUTSTR 0x21 +#define _OUTLN 0x22 +#define _DSKRD 0x10 +#define _DSKWR 0x11 +#define _DSKCFIG 0x12 +#define _DSKFMT 0x14 +#define _DSKCTRL 0x15 +#define _WRITE 0x23 +#define _WRITELN 0x24 +#define _DELAY 0x43 +#define _RTC_RD 0x53 +#define _RETURN 0x63 +#define _BRD_ID 0x70 + /* Note: this module is called via a table. There is no benefit in making it inline */ @@ -32,13 +53,27 @@ /* Any starting address less than this is assumed to be an OEA program rather than VEA. */ #ifndef OEA_START_ADDRESS -#define OEA_START_ADDRESS 4096 +#define OEA_START_ADDRESS 0x4000 #endif #ifndef OEA_MEMORY_SIZE #define OEA_MEMORY_SIZE 0x100000 #endif +/* All but CPU 0 are put into an infinate loop, this loop instruction + is stored at the address below */ +#ifndef OEA_STALL_CPU_LOOP_ADDRESS +#define OEA_STALL_CPU_LOOP_ADDRESS 0x00c10 +#endif + +/* At initiallization, the system call exception branches to the BUG + emulation code */ + +#ifndef OEA_SYSTEM_CALL_ADDRESS +#define OEA_SYSTEM_CALL_ADDRESS 0x00c00 +#endif + + static os_emul_data * emul_bugapi_create(device *root, bfd *image, @@ -47,9 +82,11 @@ emul_bugapi_create(device *root, /* check it really is for us */ if (name != NULL - && strcmp(name, "bugapi") != 0) + && strcmp(name, "bugapi") != 0 + && strcmp(name, "bug") != 0) return NULL; if (image != NULL + && name == NULL && bfd_get_start_address(image) > OEA_START_ADDRESS) return NULL; @@ -58,8 +95,12 @@ emul_bugapi_create(device *root, const memory_size = OEA_MEMORY_SIZE; const elf_binary = (image != NULL && image->xvec->flavour == bfd_target_elf_flavour); - const little_endian = (image != NULL - && !image->xvec->byteorder_big_p); +#ifdef bfd_little_endian /* new bfd */ + const little_endian = (image != NULL && bfd_little_endian(image)); +#else + const little_endian = (image != NULL && + !image->xvec->byteorder_big_p); +#endif { /* options */ device *options = device_tree_add_found(root, "/", "options"); @@ -75,7 +116,7 @@ emul_bugapi_create(device *root, device_add_boolean_property(options, "strict-alignment?", (WITH_ALIGNMENT == STRICT_ALIGNMENT - || !image->xvec->byteorder_big_p)); + || little_endian)); device_add_boolean_property(options, "floating-point?", WITH_FLOATING_POINT); @@ -98,15 +139,32 @@ emul_bugapi_create(device *root, device *init_register = device_tree_add_found(init, "", "register"); device_add_integer_property(init_register, "pc", - 0); + OEA_STALL_CPU_LOOP_ADDRESS); + device_add_integer_property(init_register, + "0.pc", + bfd_get_start_address(image)); device_add_integer_property(init_register, "sp", memory_size-16); device_add_integer_property(init_register, "msr", - (little_endian - ? msr_little_endian_mode - : 0)); + (msr_recoverable_interrupt + | (little_endian + ? msr_little_endian_mode + : 0) + )); + device_tree_add_found_uw_u_u(init, "", + "data", + OEA_SYSTEM_CALL_ADDRESS, + 4, 0x1); /*emul-call*/ + device_tree_add_found_uw_u_u(init, "", + "data", + OEA_SYSTEM_CALL_ADDRESS + 4, + 4, 0x4c000064); /*rfi*/ + device_tree_add_found_uw_u_u(init, "", + "data", + OEA_STALL_CPU_LOOP_ADDRESS, + 4, 0x48000000); /*b .*/ } { device *init_stack = device_tree_add_found(init, "", "stack"); @@ -140,8 +198,28 @@ emul_bugapi_instruction_call(cpu *processor, unsigned_word ra, os_emul_data *emul_data) { - error("emul_bugapi_instruction_call() not implemented\n"); + const int call_id = cpu_registers(processor)->gpr[10]; + /* check that this isn't an invalid instruction */ + if (cia != OEA_SYSTEM_CALL_ADDRESS) + return 0; + switch (call_id) { + case _OUTCHR: + printf_filtered("%c", cpu_registers(processor)->gpr[3]); + break; + case _OUTLN: + printf_filtered("\n"); + break; + case _RETURN: + cpu_halt(processor, cia, was_exited, 0); /* always succeeds */ + break; + default: + error("emul-bugapi: unimplemented bugapi call 0x%x from address 0x%lx\n", + call_id, SRR0); + break; + } return 1; + /* the instruction following this one is a RFI. Thus by just + continuing the return from system call is performed */ } const os_emul emul_bugapi = { -- cgit v1.1