1 |
dpavlin |
1 |
/* |
2 |
|
|
* PearPC |
3 |
|
|
* promdt.h |
4 |
|
|
* |
5 |
|
|
* Copyright (C) 2003, 2004 Sebastian Biallas (sb@biallas.net) |
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 version 2 as |
9 |
|
|
* published by the Free Software Foundation. |
10 |
|
|
* |
11 |
|
|
* This program is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 |
|
|
* GNU General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU General Public License |
17 |
|
|
* along with this program; if not, write to the Free Software |
18 |
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
19 |
|
|
*/ |
20 |
|
|
|
21 |
|
|
#ifndef __PROMDT_H__ |
22 |
|
|
#define __PROMDT_H__ |
23 |
|
|
|
24 |
|
|
#include "tools/data.h" |
25 |
|
|
#include "io/prom/fs/part.h" |
26 |
|
|
#include "promosi.h" |
27 |
|
|
|
28 |
|
|
class PromNode; |
29 |
|
|
class PromProp; |
30 |
|
|
class PromInstance; |
31 |
|
|
|
32 |
|
|
extern PromNode *gPromRoot; |
33 |
|
|
// FIXME: HACK!!! |
34 |
|
|
extern int gBootPartNum; |
35 |
|
|
extern int gBootNodeID; |
36 |
|
|
|
37 |
|
|
typedef uint32 PromInstanceHandle; |
38 |
|
|
typedef uint32 PromPackageHandle; |
39 |
|
|
|
40 |
|
|
#define ATOM_PROM_OBJECT MAGIC32("PRM\x00") |
41 |
|
|
#define ATOM_PROM_NODE MAGIC32("PRM\x01") |
42 |
|
|
#define ATOM_PROM_PROP MAGIC32("PRM\x02") |
43 |
|
|
|
44 |
|
|
/* |
45 |
|
|
* This is the base class for PromNode and PromProps, i.e. everything that is |
46 |
|
|
* in the device tree. |
47 |
|
|
*/ |
48 |
|
|
class PromObject: public Object { |
49 |
|
|
public: |
50 |
|
|
PromNode *owner; |
51 |
|
|
char *name; |
52 |
|
|
|
53 |
|
|
PromObject(const char *name); |
54 |
|
|
virtual ~PromObject(); |
55 |
|
|
virtual int compareTo(const Object *obj) const; |
56 |
|
|
virtual ObjectID getObjectID() const; |
57 |
|
|
virtual void setOwner(PromNode *aOwner); |
58 |
|
|
|
59 |
|
|
virtual uint32 toPath(char *buf, uint32 buflen); |
60 |
|
|
}; |
61 |
|
|
|
62 |
|
|
class PromNode: public PromObject { |
63 |
|
|
protected: |
64 |
|
|
Container *childs; |
65 |
|
|
Container *props; |
66 |
|
|
Container *shortcuts; |
67 |
|
|
int mPromNodeHandle; |
68 |
|
|
int mPromNodeInstancesHandles; |
69 |
|
|
public: |
70 |
|
|
static int promNodeHandles; |
71 |
|
|
PromNode(const char *name); |
72 |
|
|
virtual ~PromNode(); |
73 |
|
|
virtual ObjectID getObjectID() const; |
74 |
|
|
|
75 |
|
|
virtual bool addNode(PromNode *node); |
76 |
|
|
virtual bool addProp(PromProp *node); |
77 |
|
|
virtual bool addNodeShort(const char *name, const char *nodename); |
78 |
|
|
virtual PromNode * findNode(const char *name); |
79 |
|
|
virtual PromProp * findProp(const char *name); |
80 |
|
|
virtual PromNode * firstChild(); |
81 |
|
|
virtual PromNode * nextChild(PromNode *p); |
82 |
|
|
virtual PromProp * firstProp(); |
83 |
|
|
virtual PromProp * nextProp(PromProp *p); |
84 |
|
|
|
85 |
|
|
PromInstanceHandle open(const String ¶m); |
86 |
|
|
void close(PromInstanceHandle pih); |
87 |
|
|
PromPackageHandle getPHandle(); |
88 |
|
|
protected: |
89 |
|
|
virtual PromInstance * createInstance(const String ¶m); |
90 |
|
|
}; |
91 |
|
|
|
92 |
|
|
class PromProp: public PromObject { |
93 |
|
|
public: |
94 |
|
|
PromProp(const char *name); |
95 |
|
|
virtual ObjectID getObjectID() const; |
96 |
|
|
|
97 |
|
|
virtual uint32 getValue(uint32 buf, uint32 buflen); |
98 |
|
|
virtual uint32 getValueLen(); |
99 |
|
|
virtual uint32 setValue(uint32 buf, uint32 buflen); |
100 |
|
|
}; |
101 |
|
|
|
102 |
|
|
/* |
103 |
|
|
* This is the base class for instances of PromNodes. |
104 |
|
|
*/ |
105 |
|
|
class PromInstance: public Object { |
106 |
|
|
protected: |
107 |
|
|
PromNode *mType; |
108 |
|
|
PromInstanceHandle mHandle; |
109 |
|
|
public: |
110 |
|
|
PromInstance(PromNode *type, const String ¶m); |
111 |
|
|
virtual ~PromInstance(); |
112 |
|
|
|
113 |
|
|
PromNode *getType(); |
114 |
|
|
void setIHandle(PromInstanceHandle handle); |
115 |
|
|
PromInstanceHandle getIHandle(); |
116 |
|
|
virtual void callMethod(const char *method, prom_args *pa); |
117 |
|
|
virtual uint32 read(uint32 buf, int length); |
118 |
|
|
virtual uint32 seek(uint64 pos); |
119 |
|
|
virtual uint32 write(uint32 buf, int length); |
120 |
|
|
}; |
121 |
|
|
|
122 |
|
|
class PromPropLink: public PromProp { |
123 |
|
|
public: |
124 |
|
|
PromInstanceHandle value; |
125 |
|
|
PromPropLink(const char *name, PromInstanceHandle value); |
126 |
|
|
virtual ~PromPropLink(); |
127 |
|
|
|
128 |
|
|
virtual uint32 getValueLen(); |
129 |
|
|
virtual uint32 getValue(uint32 buf, uint32 buflen); |
130 |
|
|
}; |
131 |
|
|
|
132 |
|
|
class PromPropInt: public PromProp { |
133 |
|
|
public: |
134 |
|
|
uint32 value; |
135 |
|
|
PromPropInt(const char *name, uint32 value); |
136 |
|
|
virtual ~PromPropInt(); |
137 |
|
|
|
138 |
|
|
virtual uint32 getValueLen(); |
139 |
|
|
virtual uint32 getValue(uint32 buf, uint32 buflen); |
140 |
|
|
}; |
141 |
|
|
|
142 |
|
|
class PromPropMemory: public PromProp { |
143 |
|
|
public: |
144 |
|
|
void *buf; |
145 |
|
|
int size; |
146 |
|
|
PromPropMemory(const char *name, const void *buf, int size); |
147 |
|
|
virtual ~PromPropMemory(); |
148 |
|
|
|
149 |
|
|
virtual uint32 getValueLen(); |
150 |
|
|
virtual uint32 setValue(uint32 buf, uint32 buflen); |
151 |
|
|
virtual uint32 getValue(uint32 buf, uint32 buflen); |
152 |
|
|
}; |
153 |
|
|
|
154 |
|
|
class PromNodeATY: public PromNode { |
155 |
|
|
public: |
156 |
|
|
PromNodeATY(const char *name); |
157 |
|
|
protected: |
158 |
|
|
virtual PromInstance * createInstance(const String ¶m); |
159 |
|
|
}; |
160 |
|
|
|
161 |
|
|
|
162 |
|
|
class PromInstanceATY: public PromInstance { |
163 |
|
|
public: |
164 |
|
|
PromInstanceATY(PromNode *type, const String ¶m); |
165 |
|
|
|
166 |
|
|
virtual void callMethod(const char *method, prom_args *pa); |
167 |
|
|
virtual uint32 write(uint32 buf, int length); |
168 |
|
|
}; |
169 |
|
|
|
170 |
|
|
class PromNodeKBD: public PromNode { |
171 |
|
|
public: |
172 |
|
|
PromNodeKBD(const char *name); |
173 |
|
|
protected: |
174 |
|
|
virtual PromInstance * createInstance(const String ¶m); |
175 |
|
|
}; |
176 |
|
|
|
177 |
|
|
class PromInstanceKBD: public PromInstance { |
178 |
|
|
public: |
179 |
|
|
PromInstanceKBD(PromNode *type, const String ¶m); |
180 |
|
|
|
181 |
|
|
virtual uint32 read(uint32 buf, int length); |
182 |
|
|
}; |
183 |
|
|
|
184 |
|
|
class PromNodeRTAS: public PromNode { |
185 |
|
|
public: |
186 |
|
|
PromNodeRTAS(const char *name); |
187 |
|
|
protected: |
188 |
|
|
virtual PromInstance * createInstance(const String ¶m); |
189 |
|
|
}; |
190 |
|
|
|
191 |
|
|
class PromInstanceRTAS: public PromInstance { |
192 |
|
|
public: |
193 |
|
|
PromInstanceRTAS(PromNode *type, const String ¶m); |
194 |
|
|
|
195 |
|
|
virtual void callMethod(const char *method, prom_args *pa); |
196 |
|
|
virtual uint32 write(uint32 buf, int length); |
197 |
|
|
}; |
198 |
|
|
|
199 |
|
|
class PromNodeMMU: public PromNode { |
200 |
|
|
public: |
201 |
|
|
PromNodeMMU(const char *name); |
202 |
|
|
protected: |
203 |
|
|
virtual PromInstance * createInstance(const String ¶m); |
204 |
|
|
}; |
205 |
|
|
|
206 |
|
|
class PromInstanceMMU: public PromInstance { |
207 |
|
|
public: |
208 |
|
|
PromInstanceMMU(PromNode *type, const String ¶m); |
209 |
|
|
|
210 |
|
|
virtual void callMethod(const char *method, prom_args *pa); |
211 |
|
|
virtual uint32 write(uint32 buf, int length); |
212 |
|
|
}; |
213 |
|
|
|
214 |
|
|
class PromNodeMemory: public PromNode { |
215 |
|
|
public: |
216 |
|
|
PromNodeMemory(const char *name); |
217 |
|
|
protected: |
218 |
|
|
virtual PromInstance * createInstance(const String ¶m); |
219 |
|
|
}; |
220 |
|
|
|
221 |
|
|
class PromInstanceMemory: public PromInstance { |
222 |
|
|
public: |
223 |
|
|
PromInstanceMemory(PromNode *type, const String ¶m); |
224 |
|
|
|
225 |
|
|
virtual void callMethod(const char *method, prom_args *pa); |
226 |
|
|
}; |
227 |
|
|
|
228 |
|
|
class PromNodeDisk: public PromNode { |
229 |
|
|
public: |
230 |
|
|
int mNumber; |
231 |
|
|
PartitionMap *pm; |
232 |
|
|
File *mDevice; |
233 |
|
|
FileSystem *mFS; |
234 |
|
|
|
235 |
|
|
PromNodeDisk(const char *name, int aNumber); |
236 |
|
|
virtual ~PromNodeDisk(); |
237 |
|
|
protected: |
238 |
|
|
virtual PromInstance * createInstance(const String ¶m); |
239 |
|
|
}; |
240 |
|
|
|
241 |
|
|
class PromInstanceDiskPart: public PromInstance { |
242 |
|
|
int mNumber; |
243 |
|
|
uint64 mOffset; |
244 |
|
|
public: |
245 |
|
|
|
246 |
|
|
PromInstanceDiskPart(PromNode *type, uint partnum); |
247 |
|
|
virtual void callMethod(const char *method, prom_args *pa); |
248 |
|
|
virtual uint32 read(uint32 buf, int length); |
249 |
|
|
virtual uint32 seek(uint64 pos); |
250 |
|
|
virtual uint32 write(uint32 buf, int length); |
251 |
|
|
}; |
252 |
|
|
|
253 |
|
|
class PromInstanceDiskFile: public PromInstance { |
254 |
|
|
public: |
255 |
|
|
File * mFile; |
256 |
|
|
|
257 |
|
|
PromInstanceDiskFile(PromNode *type, File *file); |
258 |
|
|
virtual void callMethod(const char *method, prom_args *pa); |
259 |
|
|
virtual uint32 read(uint32 buf, int length); |
260 |
|
|
virtual uint32 seek(uint64 pos); |
261 |
|
|
virtual uint32 write(uint32 buf, int length); |
262 |
|
|
}; |
263 |
|
|
|
264 |
|
|
class PromPropString: public PromProp { |
265 |
|
|
public: |
266 |
|
|
char *value; |
267 |
|
|
PromPropString(const char *name, const char *value); |
268 |
|
|
virtual ~PromPropString(); |
269 |
|
|
|
270 |
|
|
virtual uint32 getValueLen(); |
271 |
|
|
virtual uint32 getValue(uint32 buf, uint32 buflen); |
272 |
|
|
virtual uint32 setValue(uint32 buf, uint32 buflen); |
273 |
|
|
}; |
274 |
|
|
|
275 |
|
|
#define FIND_DEVICE_FIND 0 |
276 |
|
|
#define FIND_DEVICE_OPEN 1 |
277 |
|
|
PromNode *findDevice(const char *aPathName, int type, PromInstanceHandle *ret); |
278 |
|
|
void prom_init_device_tree(); |
279 |
|
|
void prom_done_device_tree(); |
280 |
|
|
|
281 |
|
|
PromNode *handleToPackage(PromPackageHandle ph); |
282 |
|
|
PromInstance *handleToInstance(PromInstanceHandle ih); |
283 |
|
|
|
284 |
|
|
#endif |