This commit was generated by cvs2svn to track changes on a CVS vendor
[external/binutils.git] / sim / m32r / devices.c
1 /* m32r device support
2    Copyright (C) 1997, 1998 Free Software Foundation, Inc.
3    Contributed by Cygnus Solutions.
4
5 This file is part of GDB, the GNU debugger.
6
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License along
18 with this program; if not, write to the Free Software Foundation, Inc.,
19 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
20
21 #include "sim-main.h"
22
23 #ifdef HAVE_DV_SOCKSER
24 #include "dv-sockser.h"
25 #endif
26
27 /* Handling the MSPR register is done by creating a device in the core
28    mapping that winds up here.  */
29
30 device m32r_devices;
31
32 int
33 device_io_read_buffer (device *me, void *source, int space,
34                        address_word addr, unsigned nr_bytes,
35                        SIM_CPU *cpu, sim_cia cia)
36 {
37   SIM_DESC sd = CPU_STATE (cpu);
38
39   if (STATE_ENVIRONMENT (sd) != OPERATING_ENVIRONMENT)
40     return nr_bytes;
41
42 #ifdef HAVE_DV_SOCKSER
43   if (addr == UART_INCHAR_ADDR)
44     {
45       int c = dv_sockser_read (sd);
46       if (c == -1)
47         return 0;
48       *(char *) source = c;
49       return 1;
50     }
51   if (addr == UART_STATUS_ADDR)
52     {
53       int status = dv_sockser_status (sd);
54       unsigned char *p = source;
55       p[0] = 0;
56       p[1] = (((status & DV_SOCKSER_INPUT_EMPTY)
57 #ifdef UART_INPUT_READY0
58                ? UART_INPUT_READY : 0)
59 #else
60                ? 0 : UART_INPUT_READY)
61 #endif
62               + ((status & DV_SOCKSER_OUTPUT_EMPTY) ? UART_OUTPUT_READY : 0));
63       return 2;
64     }
65 #endif
66
67   return nr_bytes;
68 }
69
70 int
71 device_io_write_buffer (device *me, const void *source, int space,
72                         address_word addr, unsigned nr_bytes,
73                         SIM_CPU *cpu, sim_cia cia)
74 {
75   SIM_DESC sd = CPU_STATE (cpu);
76
77 #if WITH_SCACHE
78   /* MSPR support is deprecated but is kept in for upward compatibility
79      with existing overlay support.  */
80   if (addr == MSPR_ADDR)
81     {
82       if ((*(const char *) source & MSPR_PURGE) != 0)
83         scache_flush (sd);
84       return nr_bytes;
85     }
86   if (addr == MCCR_ADDR)
87     {
88       if ((*(const char *) source & MCCR_CP) != 0)
89         scache_flush (sd);
90       return nr_bytes;
91     }
92 #endif
93
94   if (STATE_ENVIRONMENT (sd) != OPERATING_ENVIRONMENT)
95     return nr_bytes;
96
97 #if HAVE_DV_SOCKSER
98   if (addr == UART_OUTCHAR_ADDR)
99     {
100       int rc = dv_sockser_write (sd, *(char *) source);
101       return rc == 1;
102     }
103 #endif
104
105   return nr_bytes;
106 }
107
108 void device_error () {}