Split out hw-alloc code. Add constructor and destructor for hw-alloc.
[deliverable/binutils-gdb.git] / sim / common / hw-base.h
1 /* This file is part of the program psim.
2
3 Copyright (C) 1994-1998, 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_ROOT
23 #define HW_ROOT
24
25 /* A root device from which dv-* devices can be built */
26
27 #include "hw-device.h"
28
29 #include "hw-properties.h"
30 #include "hw-events.h"
31 #include "hw-alloc.h"
32 /* #include "hw-instances.h" */
33 /* #include "hw-handles.h" */
34 #include "hw-ports.h"
35
36 typedef void (hw_finish_callback)
37 (struct hw *me);
38
39 struct hw_device_descriptor {
40 const char *family;
41 hw_finish_callback *to_finish;
42 };
43
44 /* Create a primative device */
45
46 struct hw *hw_create
47 (struct sim_state *sd,
48 struct hw *parent,
49 const char *family,
50 const char *name,
51 const char *unit,
52 const char *args);
53
54
55 /* Complete the creation of that device (finish overrides methods
56 using the set_hw_* operations below) */
57
58 void hw_finish
59 (struct hw *me);
60
61 int hw_finished_p
62 (struct hw *me);
63
64
65 /* Delete the entire device */
66
67 void hw_delete
68 (struct hw *me);
69
70
71 /* Override device methods */
72
73 #define set_hw_data(hw, value) \
74 ((hw)->data_of_hw = (value))
75
76 #define set_hw_reset(hw, method) \
77 ((hw)->to_reset = method)
78
79 #define set_hw_io_read_buffer(hw, method) \
80 ((hw)->to_io_read_buffer = (method))
81 #define set_hw_io_write_buffer(hw, method) \
82 ((hw)->to_io_write_buffer = (method))
83
84 #define set_hw_dma_read_buffer(me, method) \
85 ((me)->to_dma_read_buffer = (method))
86 #define set_hw_dma_write_buffer(me, method) \
87 ((me)->to_dma_write_buffer = (method))
88
89 #define set_hw_attach_address(hw, method) \
90 ((hw)->to_attach_address = (method))
91 #define set_hw_detach_address(hw, method) \
92 ((hw)->to_detach_address = (method))
93
94 #define set_hw_unit_decode(hw, method) \
95 ((hw)->to_unit_decode = (method))
96 #define set_hw_unit_encode(hw, method) \
97 ((hw)->to_unit_encode = (method))
98
99 #define set_hw_unit_address_to_attach_address(hw, method) \
100 ((hw)->to_unit_address_to_attach_address = (method))
101 #define set_hw_unit_size_to_attach_size(hw, method) \
102 ((hw)->to_unit_size_to_attach_size = (method))
103
104 typedef void (hw_delete_callback)
105 (struct hw *me);
106
107 #define set_hw_delete(hw, method) \
108 ((hw)->base_of_hw->to_delete = (method))
109
110
111 /* Helper functions to make the implementation of a device easier */
112
113 /* Go through the devices reg properties and look for those specifying
114 an address to attach various registers to */
115
116 void do_hw_attach_regs (struct hw *me);
117
118 /* Perform a polling read on FD returning either the number of bytes
119 or a hw_io status code that indicates the reason for the read
120 failure */
121
122 enum {
123 HW_IO_EOF = -1, HW_IO_NOT_READY = -2, /* See: IEEE 1275 */
124 };
125
126 typedef int (do_hw_poll_read_method)
127 (SIM_DESC sd, int, char *, int);
128
129 int do_hw_poll_read
130 (struct hw *me,
131 do_hw_poll_read_method *read,
132 int sim_io_fd,
133 void *buf,
134 unsigned size_of_buf);
135
136
137 /* ALLOC */
138
139 extern void create_hw_alloc_data
140 (struct hw *hw);
141 extern void delete_hw_alloc_data
142 (struct hw *hw);
143
144
145 /* PORTS */
146
147 extern void create_hw_port_data
148 (struct hw *hw);
149 extern void delete_hw_port_data
150 (struct hw *hw);
151
152
153 /* EVENTS */
154
155 extern void create_hw_event_data
156 (struct hw *hw);
157 extern void delete_hw_event_data
158 (struct hw *hw);
159
160
161
162 #endif
This page took 0.032858 seconds and 4 git commands to generate.