Move the HFS+ filesystem handler into its own new package /packages/hfsplus-files.
[openbios.git] / utils / ofclient / of1275.c
blobff0778279cc63c633bbe412694b6216d2a174085
2 #include "of1275.h"
3 #include "endian.h"
4 static int (*of1275_server) (void *) = (int (*)(void *)) -1;
6 _start(void *residual_data_structure,
7 void *program_entry_point,
8 int (*client_interface_handler) (void *), void *args, int argslen)
10 int status;
11 of1275_server = client_interface_handler;
12 status = main();
13 of1275_exit(status);
16 /* 6.3.2.1 Client interface */
19 int of1275_test(const char *name, int *missing)
21 int result;
22 static of1275_test_service s;
23 s.service = "test";
24 s.n_args = 1;
25 s.n_returns = 1;
26 s.name = name;
27 result = of1275_server(&s);
28 *missing = s.missing;
29 return result;
33 /* 6.3.2.2 Device tree */
36 int of1275_peer(int phandle, int *sibling_phandle)
38 int result;
39 static of1275_peer_service s;
40 s.service = "peer";
41 s.n_args = 1;
42 s.n_returns = 1;
43 s.phandle = phandle;
44 result = of1275_server(&s);
45 *sibling_phandle = s.sibling_phandle;
46 return result;
49 int of1275_child(int phandle, int *child_phandle)
51 int result;
52 static of1275_child_service s;
53 s.service = "child";
54 s.n_args = 1;
55 s.n_returns = 1;
56 s.phandle = phandle;
57 result = of1275_server(&s);
58 *child_phandle = s.child_phandle;
59 return result;
62 int of1275_parent(int phandle, int *parent_phandle)
64 int result;
65 static of1275_parent_service s;
66 s.service = "parent";
67 s.n_args = 1;
68 s.n_returns = 1;
69 s.phandle = phandle;
70 result = of1275_server(&s);
71 *parent_phandle = s.parent_phandle;
72 return result;
75 int of1275_instance_to_package(int ihandle, int *phandle)
77 int result;
78 static of1275_instance_to_package_service s;
79 s.service = "instance-to-package";
80 s.n_args = 1;
81 s.n_returns = 1;
82 s.ihandle = ihandle;
83 result = of1275_server(&s);
84 *phandle = s.phandle;
85 return result;
88 int of1275_getproplen(int phandle, const char *name, int *proplen)
90 int result;
91 static of1275_getproplen_service s;
92 s.service = "getproplen";
93 s.n_args = 2;
94 s.n_returns = 1;
95 s.phandle = phandle;
96 s.name = name;
97 result = of1275_server(&s);
98 *proplen = s.proplen;
99 return result;
103 of1275_getprop(int phandle, const char *name, void *buf, int buflen,
104 int *size)
106 int result;
107 static of1275_getprop_service s;
108 s.service = "getprop";
109 s.n_args = 4;
110 s.n_returns = 1;
111 s.phandle = phandle;
112 s.name = name;
113 s.buf = buf;
114 s.buflen = buflen;
115 result = of1275_server(&s);
116 *size = s.size;
117 return result;
121 of1275_nextprop(int phandle, const char *previous, void *buf, int *flag)
123 int result;
124 static of1275_nextprop_service s;
125 s.service = "nextprop";
126 s.n_args = 3;
127 s.n_returns = 1;
128 s.phandle = phandle;
129 s.previous = previous;
130 s.buf = buf;
131 result = of1275_server(&s);
132 *flag = s.flag;
133 return result;
137 of1275_setprop(int phandle, const char *name, void *buf, int len,
138 int *size)
140 int result;
141 static of1275_setprop_service s;
142 s.service = "setprop";
143 s.n_args = 4;
144 s.n_returns = 1;
145 s.phandle = phandle;
146 s.name = name;
147 s.buf = buf;
148 s.len = len;
149 result = of1275_server(&s);
150 *size = s.size;
151 return result;
155 of1275_canon(const char *device_specifier, void *buf, int buflen,
156 int *length)
158 int result;
159 static of1275_canon_service s;
160 s.service = "canon";
161 s.n_args = 3;
162 s.n_returns = 1;
163 s.device_specifier = device_specifier;
164 s.buf = buf;
165 s.buflen = buflen;
166 result = of1275_server(&s);
167 *length = s.length;
168 return result;
171 int of1275_finddevice(const char *device_specifier, int *phandle)
173 int result;
174 static of1275_finddevice_service s;
175 s.service = "finddevice";
176 s.n_args = 1;
177 s.n_returns = 1;
178 s.device_specifier = device_specifier;
179 result = of1275_server(&s);
180 *phandle = s.phandle;
181 return result;
185 of1275_instance_to_path(int ihandle, void *buf, int buflen, int *length)
187 int result;
188 static of1275_instance_to_path_service s;
189 s.service = "instance-to-path";
190 s.n_args = 3;
191 s.n_returns = 1;
192 s.ihandle = ihandle;
193 s.buf = buf;
194 s.buflen = buflen;
195 result = of1275_server(&s);
196 *length = s.length;
197 return result;
200 int of1275_package_to_path(int phandle, void *buf, int buflen, int *length)
202 int result;
203 static of1275_package_to_path_service s;
204 s.service = "package-to-path";
205 s.n_args = 3;
206 s.n_returns = 1;
207 s.phandle = phandle;
208 s.buf = buf;
209 s.buflen = buflen;
210 result = of1275_server(&s);
211 *length = s.length;
212 return result;
215 /* int of1275_call_method(const char *method, int ihandle, ...); */
218 /* 6.3.2.3 Device I/O */
221 int of1275_open(const char *device_specifier, int *ihandle)
223 int result;
224 static of1275_open_service s;
225 s.service = "open";
226 s.n_args = 1;
227 s.n_returns = 1;
228 s.device_specifier = device_specifier;
229 result = of1275_server(&s);
230 *ihandle = s.ihandle;
231 return result;
234 int of1275_close(int ihandle)
236 int result;
237 static of1275_close_service s;
238 s.service = "close";
239 s.n_args = 1;
240 s.n_returns = 0;
241 s.ihandle = ihandle;
242 result = of1275_server(&s);
243 return result;
246 int of1275_read(int ihandle, void *addr, int len, int *actual)
248 int result;
249 static of1275_read_service s;
250 s.service = "read";
251 s.n_args = 3;
252 s.n_returns = 1;
253 s.ihandle = ihandle;
254 s.addr = addr;
255 s.len = len;
256 result = of1275_server(&s);
257 *actual = s.actual;
258 return result;
261 int of1275_write(int ihandle, void *addr, int len, int *actual)
263 int result;
264 static of1275_write_service s;
265 s.service = "write";
266 s.n_args = 3;
267 s.n_returns = 1;
268 s.ihandle = ihandle;
269 s.addr = addr;
270 s.len = len;
271 result = of1275_server(&s);
272 *actual = s.actual;
273 return result;
276 int of1275_seek(int ihandle, int pos_hi, int pos_lo, int *status)
278 int result;
279 static of1275_seek_service s;
280 s.service = "seek";
281 s.n_args = 3;
282 s.n_returns = 1;
283 s.ihandle = ihandle;
284 s.pos_hi = pos_hi;
285 s.pos_lo = pos_lo;
286 result = of1275_server(&s);
287 *status = s.status;
288 return result;
292 /* 6.3.2.4 Memory */
295 int of1275_claim(void *virt, int size, int align, void **baseaddr)
297 int result;
298 static of1275_claim_service s;
299 s.service = "claim";
300 s.n_args = 3;
301 s.n_returns = 1;
302 s.virt = virt;
303 s.size = size;
304 s.align = align;
305 result = of1275_server(&s);
306 *baseaddr = s.baseaddr;
307 return result;
310 int of1275_release(void *virt, int size)
312 int result;
313 static of1275_release_service s;
314 s.service = "release";
315 s.n_args = 2;
316 s.n_returns = 0;
317 s.virt = virt;
318 s.size = size;
319 result = of1275_server(&s);
320 return result;
324 /* 6.3.2.5 Control transfer */
327 int of1275_boot(const char *bootspec)
329 int result;
330 static of1275_boot_service s;
331 s.service = "boot";
332 s.n_args = 1;
333 s.n_returns = 0;
334 s.bootspec = bootspec;
335 result = of1275_server(&s);
336 return result;
339 int of1275_enter(void)
341 int result;
342 static of1275_enter_service s;
343 s.service = "enter";
344 s.n_args = 0;
345 s.n_returns = 0;
346 result = of1275_server(&s);
347 return result;
350 int of1275_exit(int status)
352 int result;
353 static of1275_exit_service s;
354 s.service = "exit";
355 s.n_args = 1;
356 s.n_returns = 0;
357 s.status = status;
358 result = of1275_server(&s);
359 return result;
362 /* int of1275_chain(void *virt, int size, void *entry, void *args, int len); */
365 /* 6.3.2.6 User interface */
368 /* int of1275_interpret(const char *arg, ...); */
370 int of1275_set_callback(void *newfunc, void **oldfunc)
372 int result;
373 static of1275_set_callback_service s;
374 s.service = "set-callback";
375 s.n_args = 1;
376 s.n_returns = 1;
377 s.newfunc = newfunc;
378 result = of1275_server(&s);
379 *oldfunc = s.oldfunc;
380 return result;
383 int of1275_set_symbol_lookup(void *sym_to_value, void *value_to_sym)
385 int result;
386 static of1275_set_symbol_lookup_service s;
387 s.service = "set-symbol-lookup";
388 s.n_args = 2;
389 s.n_returns = 0;
390 s.sym_to_value = sym_to_value;
391 s.value_to_sym = s.value_to_sym;
392 result = of1275_server(&s);
393 return result;
397 /* 6.3.2.7 Time */
399 int of1275_milliseconds(int *ms)
401 int result;
402 static of1275_milliseconds_service s;
403 s.service = "milliseconds";
404 s.n_args = 0;
405 s.n_returns = 1;
406 result = of1275_server(&s);
407 *ms = s.ms;
408 return result;
412 int of_find_integer_property(const char *device, const char *property)
414 int phandle;
415 int integer;
416 int size;
417 /* find the device's phandle */
418 if (of1275_finddevice(device, &phandle) < 0) {
419 //printk("of1275: no such device '%s'\n", device);
420 exit(1);
422 /* find the device's property */
423 of1275_getprop(phandle, property, &integer,
424 sizeof(integer), &size);
425 if (size < sizeof(integer)) {
426 //printk("of1275: unknown integer property '%s'\n", property);
427 exit(1);
429 return ntohl(integer);
432 void
433 of_find_string_property(const char *device,
434 const char *property,
435 char *string, int sizeof_string)
437 int phandle;
438 int size;
439 /* find the device's phandle */
440 if (of1275_finddevice(device, &phandle) < 0) {
441 //printk("of1275: no such device '%s'\n", device);
442 exit(1);
445 /* find the device's property */
446 of1275_getprop(phandle, property, string, sizeof_string, &size);
447 if (size == 0 || size >= sizeof_string) {
448 //printk("of1275: unknown string property '%s'\n", property);
449 exit(1);