gas: avoid spurious failures in non-ELF targets in the SPARC testsuite.
[deliverable/binutils-gdb.git] / sim / ppc / hw_pal.c
index 64a56f80aadb0d7482b85765314281e6bc0920bb..0789929cde067130165ea41d40d8ed6748663acd 100644 (file)
@@ -4,7 +4,7 @@
     
     This program is free software; you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
+    the Free Software Foundation; either version 3 of the License, or
     (at your option) any later version.
     
     This program is distributed in the hope that it will be useful,
@@ -13,8 +13,7 @@
     GNU General Public License for more details.
     
     You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+    along with this program; if not, see <http://www.gnu.org/licenses/>.
     
     */
 
@@ -30,9 +29,6 @@
 
 #include "cpu.h"
 
-#include <stdio.h>
-#include <fcntl.h>
-
 #ifdef HAVE_STRING_H
 #include <string.h>
 #else
 #include <stdlib.h>
 #endif
 
-#if !defined(O_NDELAY) || !defined(F_GETFL) || !defined(F_SETFL)
-#undef WITH_STDIO
-#define WITH_STDIO DO_USE_STDIO
-#endif
 
 /* DEVICE
+
    
    pal - glue logic device containing assorted junk
+
    
    DESCRIPTION
+
    
    Typical hardware dependant hack.  This device allows the firmware
    to gain access to all the things the firmware needs (but the OS
    status register indicates the output fifo is not full by being
    nonzero, outputs the character written to the tty's output port.
 
+
    PROPERTIES
    
+
    reg = <address> <size> (required)
 
    Specify the address (within the parent bus) that this device is to
    live.
 
+
    */
 
 
@@ -135,6 +133,7 @@ typedef struct _hw_pal_console_buffer {
 typedef struct _hw_pal_device {
   hw_pal_console_buffer input;
   hw_pal_console_buffer output;
+  device *disk;
 } hw_pal_device;
 
 
@@ -142,51 +141,18 @@ typedef struct _hw_pal_device {
 static void
 scan_hw_pal(hw_pal_device *hw_pal)
 {
-  if (WITH_STDIO == DO_USE_STDIO) {
-    int c = getchar ();
-    if (c == EOF) {
-      hw_pal->input.buffer = 0;
-      hw_pal->input.status = 0;
-    } else {
-      hw_pal->input.buffer = c;
-      hw_pal->input.status = 1;
-    }
-
-  } else {
-#if !defined(O_NDELAY) || !defined(F_GETFL) || !defined(F_SETFL)
-    error ("O_NDELAY, F_GETFL, or F_SETFL not defined");
-
-#else
-    /* check for input */
-    int flags;
-    int status;
-    /* get the old status */
-    flags = fcntl(0, F_GETFL, 0);
-    if (flags == -1) {
-      perror("hw_pal");
-      return;
-    }
-    /* temp, disable blocking IO */
-    status = fcntl(0, F_SETFL, flags | O_NDELAY);
-    if (status == -1) {
-      perror("hw_pal");
-      return;
-    }
-    /* try for input */
-    status = read(0, &hw_pal->input.buffer, 1);
-    if (status == 1) {
-      hw_pal->input.status = 1;
-    }
-    else {
-      hw_pal->input.status = 0;
-    }
-    /* return to regular vewing */
-    flags = fcntl(0, F_SETFL, flags);
-    if (flags == -1) {
-      perror("hw_pal");
-      return;
-    }
-#endif
+  char c;
+  int count;
+  count = sim_io_read_stdin(&c, sizeof(c));
+  switch (count) {
+  case sim_io_not_ready:
+  case sim_io_eof:
+    hw_pal->input.buffer = 0;
+    hw_pal->input.status = 0;
+    break;
+  default:
+    hw_pal->input.buffer = c;
+    hw_pal->input.status = 1;
   }
 }
 
@@ -195,13 +161,7 @@ static void
 write_hw_pal(hw_pal_device *hw_pal,
             char val)
 {
-  if (WITH_STDIO == DO_USE_STDIO) {
-    putchar (val);
-
-  } else {
-    printf_filtered("%c", val) ;
-  }
-
+  sim_io_write_stdout(&val, 1);
   hw_pal->output.buffer = val;
   hw_pal->output.status = 1;
 }
@@ -221,25 +181,32 @@ hw_pal_io_read_buffer_callback(device *me,
   switch (addr & hw_pal_address_mask) {
   case hw_pal_cpu_nr_register:
     val = cpu_nr(processor);
+    DTRACE(pal, ("read - cpu-nr %d\n", val));
     break;
   case hw_pal_nr_cpu_register:
-    val = device_find_integer_property(me, "/openprom/options/smp");
+    val = tree_find_integer_property(me, "/openprom/options/smp");
+    DTRACE(pal, ("read - nr-cpu %d\n", val));
     break;
   case hw_pal_read_fifo:
     val = hw_pal->input.buffer;
+    DTRACE(pal, ("read - input-fifo %d\n", val));
     break;
   case hw_pal_read_status:
     scan_hw_pal(hw_pal);
     val = hw_pal->input.status;
+    DTRACE(pal, ("read - input-status %d\n", val));
     break;
   case hw_pal_write_fifo:
     val = hw_pal->output.buffer;
+    DTRACE(pal, ("read - output-fifo %d\n", val));
     break;
   case hw_pal_write_status:
     val = hw_pal->output.status;
+    DTRACE(pal, ("read - output-status %d\n", val));
     break;
   default:
     val = 0;
+    DTRACE(pal, ("read - ???\n"));
   }
   memset(dest, 0, nr_bytes);
   *(unsigned_1*)dest = val;
@@ -271,15 +238,19 @@ hw_pal_io_write_buffer_callback(device *me,
     break;
   case hw_pal_read_fifo:
     hw_pal->input.buffer = byte[0];
+    DTRACE(pal, ("write - input-fifo %d\n", byte[0]));
     break;
   case hw_pal_read_status:
     hw_pal->input.status = byte[0];
+    DTRACE(pal, ("write - input-status %d\n", byte[0]));
     break;
   case hw_pal_write_fifo:
     write_hw_pal(hw_pal, byte[0]);
+    DTRACE(pal, ("write - output-fifo %d\n", byte[0]));
     break;
   case hw_pal_write_status:
     hw_pal->output.status = byte[0];
+    DTRACE(pal, ("write - output-status %d\n", byte[0]));
     break;
   }
   return nr_bytes;
@@ -300,14 +271,8 @@ hw_pal_instance_read_callback(device_instance *instance,
                              void *buf,
                              unsigned_word len)
 {
-  char *buf_char = (char *)buf;
-  if (WITH_STDIO == DO_USE_STDIO) {
-    char *line = fgets (buf_char, len, stdin);
-    return ((!line) ? -1 : strlen (buf_char));
-
-  } else {
-    return read(0, buf_char, len);
-  }
+  DITRACE(pal, ("read - %s (%ld)", (const char*)buf, (long int)len));
+  return sim_io_read_stdin(buf, len);
 }
 
 static int
@@ -318,12 +283,10 @@ hw_pal_instance_write_callback(device_instance *instance,
   int i;
   const char *chp = buf;
   hw_pal_device *hw_pal = device_instance_data(instance);
+  DITRACE(pal, ("write - %s (%ld)", (const char*)buf, (long int)len));
   for (i = 0; i < len; i++)
     write_hw_pal(hw_pal, chp[i]);
-
-  if (WITH_STDIO == DO_USE_STDIO) {
-    fflush (stdout);
-  }
+  sim_io_flush_stdoutput();
   return i;
 }
 
@@ -350,14 +313,31 @@ static const device_interrupt_port_descriptor hw_pal_interrupt_ports[] = {
 };
 
 
+static void
+hw_pal_attach_address(device *me,
+                     attach_type attach,
+                     int space,
+                     unsigned_word addr,
+                     unsigned nr_bytes,
+                     access_type access,
+                     device *client)
+{
+  hw_pal_device *pal = (hw_pal_device*)device_data(me);
+  pal->disk = client;
+}
+
+
 static device_callbacks const hw_pal_callbacks = {
   { generic_device_init_address, },
-  { NULL, }, /* address */
+  { hw_pal_attach_address, }, /* address */
   { hw_pal_io_read_buffer_callback,
       hw_pal_io_write_buffer_callback, },
   { NULL, }, /* DMA */
   { NULL, NULL, hw_pal_interrupt_ports }, /* interrupt */
-  { NULL, }, /* unit */
+  { generic_device_unit_decode,
+    generic_device_unit_encode,
+    generic_device_address_to_attach_address,
+    generic_device_size_to_attach_size },
   hw_pal_create_instance,
 };
 
This page took 0.026119 seconds and 4 git commands to generate.