This commit was generated by cvs2svn to track changes on a CVS vendor
[external/binutils.git] / sim / ppc / hw_core.c
1 /*  This file is part of the program psim.
2     
3     Copyright (C) 1994-1996, Andrew Cagney <cagney@highland.com.au>
4     
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9     
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14     
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18     
19     */
20
21
22 #ifndef _HW_CORE_C_
23 #define _HW_CORE_C_
24
25 #include "device_table.h"
26
27 #include "corefile.h"
28
29
30 /* DEVICE
31    
32    core - root of the device tree
33    
34    DESCRIPTION
35    
36    The core device positioned at the root of the device tree appears
37    to its child devices as a normal device just like every other
38    device in the tree.
39
40    Internally it is implemented using a core object.  Requests to
41    attach (or detach) address spaces are passed to that core object.
42    Requests to transfer (DMA) data are reflected back down the device
43    tree using the core_map data transfer methods.
44
45    PROPERTIES
46
47    None.
48
49    */
50
51
52 static void
53 hw_core_init_address_callback(device *me)
54 {
55   core *memory = (core*)device_data(me);
56   core_init(memory);
57 }
58
59
60 static void
61 hw_core_attach_address_callback(device *me,
62                                 const char *name,
63                                 attach_type attach,
64                                 int space,
65                                 unsigned_word addr,
66                                 unsigned nr_bytes,
67                                 access_type access,
68                                 device *who) /*callback/default*/
69 {
70   core *memory = (core*)device_data(me);
71   if (space != 0)
72     error("core_attach_address_callback() invalid address space\n");
73   core_attach(memory,
74               attach,
75               space,
76               access,
77               addr,
78               nr_bytes,
79               who);
80 }
81
82
83 static unsigned
84 hw_core_dma_read_buffer_callback(device *me,
85                                  void *dest,
86                                  int space,
87                                  unsigned_word addr,
88                                  unsigned nr_bytes)
89 {
90   core *memory = (core*)device_data(me);
91   return core_map_read_buffer(core_readable(memory),
92                               dest,
93                               addr,
94                               nr_bytes);
95 }
96
97
98 static unsigned
99 hw_core_dma_write_buffer_callback(device *me,
100                                   const void *source,
101                                   int space,
102                                   unsigned_word addr,
103                                   unsigned nr_bytes,
104                                   int violate_read_only_section)
105 {
106   core *memory = (core*)device_data(me);
107   core_map *map = (violate_read_only_section
108                    ? core_readable(memory)
109                    : core_writeable(memory));
110   return core_map_write_buffer(map,
111                                source,
112                                addr,
113                                nr_bytes);
114 }
115
116 static device_callbacks const hw_core_callbacks = {
117   { hw_core_init_address_callback, },
118   { hw_core_attach_address_callback, },
119   { NULL, }, /* IO */
120   { hw_core_dma_read_buffer_callback,
121     hw_core_dma_write_buffer_callback, },
122   { NULL, }, /* interrupt */
123   { generic_device_unit_decode,
124     generic_device_unit_encode, }
125 };
126
127
128 static void *
129 hw_core_create(const char *name,
130                const device_unit *unit_address,
131                const char *args)
132 {
133   core *memory = core_create();
134   return memory;
135 }
136
137 const device_descriptor hw_core_device_descriptor[] = {
138   { "core", hw_core_create, &hw_core_callbacks },
139   { NULL },
140 };
141
142 #endif /* _HW_CORE_C_ */