PowerPC64 ld segfault with code in non-executable sections
[external/binutils.git] / sim / ppc / device_table.h
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 3 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, see <http://www.gnu.org/licenses/>.
17  
18     */
19
20
21 #ifndef _DEVICE_TABLE_H_
22 #define _DEVICE_TABLE_H_
23
24 #include "basics.h"
25 #include "device.h"
26 #include "tree.h"
27
28 #ifdef HAVE_STRING_H
29 #include <string.h>
30 #else
31 #ifdef HAVE_STRINGS_H
32 #include <strings.h>
33 #endif
34 #endif
35
36
37 typedef struct _device_callbacks device_callbacks;
38
39
40 /* The creator, returns a pointer to any data that should be allocated
41    once during (multiple) simulation runs */
42
43 typedef void *(device_creator)
44      (const char *name,
45       const device_unit *unit_address,
46       const char *args);
47
48
49 /* two stages of initialization */
50
51 typedef void (device_init_callback)
52      (device *me);
53      
54 typedef struct _device_init_callbacks {
55   device_init_callback *address; /* NULL - ignore */
56   device_init_callback *data; /* NULL - ignore */
57 } device_init_callbacks;
58
59
60 /* attaching/detaching a devices address space to its parent */
61
62 typedef void (device_address_callback)
63      (device *me,
64       attach_type attach,
65       int space,
66       unsigned_word addr,
67       unsigned nr_bytes,
68       access_type access,
69       device *client); /*callback/default*/
70
71 typedef struct _device_address_callbacks {
72   device_address_callback *attach;
73   device_address_callback *detach;
74 } device_address_callbacks;
75
76
77 /* I/O operations - from parent */
78
79 typedef unsigned (device_io_read_buffer_callback)
80      (device *me,
81       void *dest,
82       int space,
83       unsigned_word addr,
84       unsigned nr_bytes,
85       cpu *processor,
86       unsigned_word cia);
87
88 typedef unsigned (device_io_write_buffer_callback)
89      (device *me,
90       const void *source,
91       int space,
92       unsigned_word addr,
93       unsigned nr_bytes,
94       cpu *processor,
95       unsigned_word cia);
96
97 typedef struct _device_io_callbacks { /* NULL - error */
98   device_io_read_buffer_callback *read_buffer;
99   device_io_write_buffer_callback *write_buffer;
100 } device_io_callbacks;
101
102
103 /* DMA transfers by a device via its parent */
104
105 typedef unsigned (device_dma_read_buffer_callback)
106      (device *me,
107       void *dest,
108       int space,
109       unsigned_word addr,
110       unsigned nr_bytes);
111
112 typedef unsigned (device_dma_write_buffer_callback)
113      (device *me,
114       const void *source,
115       int space,
116       unsigned_word addr,
117       unsigned nr_bytes,
118       int violate_read_only_section);
119
120 typedef struct _device_dma_callbacks { /* NULL - error */
121   device_dma_read_buffer_callback *read_buffer;
122   device_dma_write_buffer_callback *write_buffer;
123 } device_dma_callbacks;
124
125
126 /* Interrupts */
127
128 typedef void (device_interrupt_event_callback)
129      (device *me,
130       int my_port,
131       device *source,
132       int source_port,
133       int level,
134       cpu *processor,
135       unsigned_word cia);
136
137 typedef void (device_child_interrupt_event_callback)
138      (device *me,
139       device *parent,
140       device *source,
141       int source_port,
142       int level,
143       cpu *processor,
144       unsigned_word cia);
145       
146 typedef struct _device_interrupt_port_descriptor {
147   const char *name;
148   int number; 
149   int nr_ports;
150   port_direction direction;
151 } device_interrupt_port_descriptor;
152
153 typedef struct _device_interrupt_callbacks {
154   device_interrupt_event_callback *event;
155   device_child_interrupt_event_callback *child_event;
156   const device_interrupt_port_descriptor *ports;
157 } device_interrupt_callbacks;
158
159
160 /* symbolic value decoding */
161
162 typedef int (device_unit_decode_callback)
163      (device *bus,
164       const char *unit,
165       device_unit *address);
166
167 typedef int (device_unit_encode_callback)
168      (device *bus,
169       const device_unit *unit_address,
170       char *buf,
171       int sizeof_buf);
172
173 typedef int (device_address_to_attach_address_callback)
174      (device *bus,
175       const device_unit *address,
176       int *attach_space,
177       unsigned_word *attach_address,
178       device *client);
179
180 typedef int (device_size_to_attach_size_callback)
181      (device *bus,
182       const device_unit *size,
183       unsigned *nr_bytes,
184       device *client);
185
186 typedef struct _device_convert_callbacks {
187   device_unit_decode_callback *decode_unit;
188   device_unit_encode_callback *encode_unit;
189   device_address_to_attach_address_callback *address_to_attach_address;
190   device_size_to_attach_size_callback *size_to_attach_size;
191 } device_convert_callbacks;
192
193
194 /* instances */
195
196 typedef void (device_instance_delete_callback)
197      (device_instance *instance);
198
199 typedef int (device_instance_read_callback)
200      (device_instance *instance,
201       void *buf,
202       unsigned_word len);
203
204 typedef int (device_instance_write_callback)
205      (device_instance *instance,
206       const void *buf,
207       unsigned_word len);
208
209 typedef int (device_instance_seek_callback)
210      (device_instance *instance,
211       unsigned_word pos_hi,
212       unsigned_word pos_lo);
213
214 typedef int (device_instance_method)
215      (device_instance *instance,
216       int n_stack_args,
217       unsigned_cell stack_args[/*n_stack_args*/],
218       int n_stack_returns,
219       unsigned_cell stack_returns[/*n_stack_returns*/]);
220
221 typedef struct _device_instance_methods {
222   const char *name;
223   device_instance_method *method;
224 } device_instance_methods;
225
226 struct _device_instance_callbacks { /* NULL - error */
227   device_instance_delete_callback *delete;
228   device_instance_read_callback *read;
229   device_instance_write_callback *write;
230   device_instance_seek_callback *seek;
231   const device_instance_methods *methods;
232 };
233
234 typedef device_instance *(device_create_instance_callback)
235      (device *me,
236       const char *full_path,
237       const char *args);
238
239 typedef device_instance *(package_create_instance_callback)
240      (device_instance *parent,
241       const char *args);
242
243
244 /* all else fails */
245
246 typedef int (device_ioctl_callback)
247      (device *me,
248       cpu *processor,
249       unsigned_word cia,
250       device_ioctl_request request,
251       va_list ap);
252
253 typedef void (device_usage_callback)
254      (int verbose);
255
256
257 /* the callbacks */
258
259 struct _device_callbacks {
260
261   /* initialization */
262   device_init_callbacks init;
263
264   /* address/data config - from child */
265   device_address_callbacks address;
266
267   /* address/data transfer - from parent */
268   device_io_callbacks io;
269
270   /* address/data transfer - from child */
271   device_dma_callbacks dma;
272
273   /* interrupt signalling */
274   device_interrupt_callbacks interrupt;
275
276   /* bus address decoding */
277   device_convert_callbacks convert;
278
279   /* instances */
280   device_create_instance_callback *instance_create;
281
282   /* back door to anything we've forgot */
283   device_ioctl_callback *ioctl;
284   device_usage_callback *usage;
285 };
286
287
288 /* Table of all the devices and a function to lookup/create a device
289    from its name */
290
291 typedef struct _device_descriptor device_descriptor;
292 struct _device_descriptor {
293   const char *name;
294   device_creator *creator;
295   const device_callbacks *callbacks;
296 };
297
298 extern const device_descriptor *const device_table[];
299 #include "hw.h"
300
301
302 /* Pass through, ignore and generic callback functions.  A call going
303    towards the root device are passed on up, local calls are ignored
304    and call downs abort */
305
306 extern device_address_callback passthrough_device_address_attach;
307 extern device_address_callback passthrough_device_address_detach;
308 extern device_dma_read_buffer_callback passthrough_device_dma_read_buffer;
309 extern device_dma_write_buffer_callback passthrough_device_dma_write_buffer;
310
311 extern device_unit_decode_callback ignore_device_unit_decode;
312
313 extern device_init_callback generic_device_init_address;
314 extern device_unit_decode_callback generic_device_unit_decode;
315 extern device_unit_encode_callback generic_device_unit_encode;
316 extern device_address_to_attach_address_callback generic_device_address_to_attach_address;
317 extern device_size_to_attach_size_callback generic_device_size_to_attach_size;
318
319
320 extern const device_callbacks passthrough_device_callbacks;
321
322 #endif /* _DEVICE_TABLE_H_ */