fixes for host gcc 4.6.1
[zpugcc/jano.git] / toolchain / gcc / libgloss / mips / cfe_api.c
blobab5ac9059da336f0abcef153bf94ad4a604dc946
1 /* From: CFE Id: cfe_api.c,v 1.16 2002/07/09 23:29:11 cgd Exp $ */
3 /*
4 * Copyright 2000, 2001, 2002
5 * Broadcom Corporation. All rights reserved.
6 *
7 * This software is furnished under license and may be used and copied only
8 * in accordance with the following terms and conditions. Subject to these
9 * conditions, you may download, copy, install, use, modify and distribute
10 * modified or unmodified copies of this software in source and/or binary
11 * form. No title or ownership is transferred hereby.
13 * 1) Any source code used, modified or distributed must reproduce and
14 * retain this copyright notice and list of conditions as they appear in
15 * the source file.
17 * 2) No right is granted to use any trade name, trademark, or logo of
18 * Broadcom Corporation. The "Broadcom Corporation" name may not be
19 * used to endorse or promote products derived from this software
20 * without the prior written permission of Broadcom Corporation.
22 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED
23 * WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF
24 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
25 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE
26 * FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE
27 * LIABLE FOR DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
30 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
31 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
32 * OR OTHERWISE), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 /* *********************************************************************
37 * Broadcom Common Firmware Environment (CFE)
39 * Device Function stubs File: cfe_api.c
41 * This module contains device function stubs (small routines to
42 * call the standard "iocb" interface entry point to CFE).
43 * There should be one routine here per iocb function call.
45 * Authors: Mitch Lichtenberg, Chris Demetriou
47 ********************************************************************* */
49 #include "cfe_api.h"
50 #include "cfe_api_int.h"
52 /* Cast from a native pointer to a cfe_xptr_t and back. */
53 #define XPTR_FROM_NATIVE(n) ((cfe_xptr_t) (intptr_t) (n))
54 #define NATIVE_FROM_XPTR(x) ((void *) (intptr_t) (x))
56 #ifdef CFE_API_IMPL_NAMESPACE
57 #define cfe_iocb_dispatch(a) __cfe_iocb_dispatch(a)
58 #endif
59 int cfe_iocb_dispatch(cfe_xiocb_t *xiocb);
61 #if defined(CFE_API_common) || defined(CFE_API_ALL)
63 * Declare the dispatch function with args of "intptr_t".
64 * This makes sure whatever model we're compiling in
65 * puts the pointers in a single register. For example,
66 * combining -mlong64 and -mips1 or -mips2 would lead to
67 * trouble, since the handle and IOCB pointer will be
68 * passed in two registers each, and CFE expects one.
71 static int (*cfe_dispfunc)(intptr_t handle, intptr_t xiocb) = 0;
72 static cfe_xuint_t cfe_handle = 0;
74 int
75 cfe_init(cfe_xuint_t handle, cfe_xuint_t ept)
77 cfe_dispfunc = NATIVE_FROM_XPTR(ept);
78 cfe_handle = handle;
79 return 0;
82 int
83 cfe_iocb_dispatch(cfe_xiocb_t *xiocb)
85 if (!cfe_dispfunc) return -1;
86 return (*cfe_dispfunc)((intptr_t)cfe_handle, (intptr_t)xiocb);
88 #endif /* CFE_API_common || CFE_API_ALL */
90 #if defined(CFE_API_close) || defined(CFE_API_ALL)
91 int
92 cfe_close(int handle)
94 cfe_xiocb_t xiocb;
96 xiocb.xiocb_fcode = CFE_CMD_DEV_CLOSE;
97 xiocb.xiocb_status = 0;
98 xiocb.xiocb_handle = handle;
99 xiocb.xiocb_flags = 0;
100 xiocb.xiocb_psize = 0;
102 cfe_iocb_dispatch(&xiocb);
104 return xiocb.xiocb_status;
107 #endif /* CFE_API_close || CFE_API_ALL */
109 #if defined(CFE_API_cpu_start) || defined(CFE_API_ALL)
111 cfe_cpu_start(int cpu, void (*fn)(void), long sp, long gp, long a1)
113 cfe_xiocb_t xiocb;
115 xiocb.xiocb_fcode = CFE_CMD_FW_CPUCTL;
116 xiocb.xiocb_status = 0;
117 xiocb.xiocb_handle = 0;
118 xiocb.xiocb_flags = 0;
119 xiocb.xiocb_psize = sizeof(xiocb_cpuctl_t);
120 xiocb.plist.xiocb_cpuctl.cpu_number = cpu;
121 xiocb.plist.xiocb_cpuctl.cpu_command = CFE_CPU_CMD_START;
122 xiocb.plist.xiocb_cpuctl.gp_val = gp;
123 xiocb.plist.xiocb_cpuctl.sp_val = sp;
124 xiocb.plist.xiocb_cpuctl.a1_val = a1;
125 xiocb.plist.xiocb_cpuctl.start_addr = (long)fn;
127 cfe_iocb_dispatch(&xiocb);
129 return xiocb.xiocb_status;
131 #endif /* CFE_API_cpu_start || CFE_API_ALL */
133 #if defined(CFE_API_cpu_stop) || defined(CFE_API_ALL)
135 cfe_cpu_stop(int cpu)
137 cfe_xiocb_t xiocb;
139 xiocb.xiocb_fcode = CFE_CMD_FW_CPUCTL;
140 xiocb.xiocb_status = 0;
141 xiocb.xiocb_handle = 0;
142 xiocb.xiocb_flags = 0;
143 xiocb.xiocb_psize = sizeof(xiocb_cpuctl_t);
144 xiocb.plist.xiocb_cpuctl.cpu_number = cpu;
145 xiocb.plist.xiocb_cpuctl.cpu_command = CFE_CPU_CMD_STOP;
147 cfe_iocb_dispatch(&xiocb);
149 return xiocb.xiocb_status;
151 #endif /* CFE_API_cpu_stop || CFE_API_ALL */
153 #if defined(CFE_API_enumenv) || defined(CFE_API_ALL)
155 cfe_enumenv(int idx, char *name, int namelen, char *val, int vallen)
157 cfe_xiocb_t xiocb;
159 xiocb.xiocb_fcode = CFE_CMD_ENV_SET;
160 xiocb.xiocb_status = 0;
161 xiocb.xiocb_handle = 0;
162 xiocb.xiocb_flags = 0;
163 xiocb.xiocb_psize = sizeof(xiocb_envbuf_t);
164 xiocb.plist.xiocb_envbuf.enum_idx = idx;
165 xiocb.plist.xiocb_envbuf.name_ptr = XPTR_FROM_NATIVE(name);
166 xiocb.plist.xiocb_envbuf.name_length = namelen;
167 xiocb.plist.xiocb_envbuf.val_ptr = XPTR_FROM_NATIVE(val);
168 xiocb.plist.xiocb_envbuf.val_length = vallen;
170 cfe_iocb_dispatch(&xiocb);
172 return xiocb.xiocb_status;
174 #endif /* CFE_API_enumenv || CFE_API_ALL */
176 #if defined(CFE_API_enummem) || defined(CFE_API_ALL)
178 cfe_enummem(int idx, int flags, cfe_xuint_t *start, cfe_xuint_t *length,
179 cfe_xuint_t *type)
181 cfe_xiocb_t xiocb;
183 xiocb.xiocb_fcode = CFE_CMD_FW_MEMENUM;
184 xiocb.xiocb_status = 0;
185 xiocb.xiocb_handle = 0;
186 xiocb.xiocb_flags = flags;
187 xiocb.xiocb_psize = sizeof(xiocb_meminfo_t);
188 xiocb.plist.xiocb_meminfo.mi_idx = idx;
190 cfe_iocb_dispatch(&xiocb);
192 if (xiocb.xiocb_status < 0)
193 return xiocb.xiocb_status;
195 *start = xiocb.plist.xiocb_meminfo.mi_addr;
196 *length = xiocb.plist.xiocb_meminfo.mi_size;
197 *type = xiocb.plist.xiocb_meminfo.mi_type;
199 return 0;
201 #endif /* CFE_API_enummem || CFE_API_ALL */
203 #if defined(CFE_API_exit) || defined(CFE_API_ALL)
205 cfe_exit(int warm, int status)
207 cfe_xiocb_t xiocb;
209 xiocb.xiocb_fcode = CFE_CMD_FW_RESTART;
210 xiocb.xiocb_status = 0;
211 xiocb.xiocb_handle = 0;
212 xiocb.xiocb_flags = warm ? CFE_FLG_WARMSTART : 0;
213 xiocb.xiocb_psize = sizeof(xiocb_exitstat_t);
214 xiocb.plist.xiocb_exitstat.status = status;
216 cfe_iocb_dispatch(&xiocb);
218 return xiocb.xiocb_status;
220 #endif /* CFE_API_exit || CFE_API_ALL */
222 #if defined(CFE_API_flushcache) || defined(CFE_API_ALL)
224 cfe_flushcache(int flg)
226 cfe_xiocb_t xiocb;
228 xiocb.xiocb_fcode = CFE_CMD_FW_FLUSHCACHE;
229 xiocb.xiocb_status = 0;
230 xiocb.xiocb_handle = 0;
231 xiocb.xiocb_flags = flg;
232 xiocb.xiocb_psize = 0;
234 cfe_iocb_dispatch(&xiocb);
236 return xiocb.xiocb_status;
238 #endif /* CFE_API_flushcache || CFE_API_ALL */
240 #if defined(CFE_API_getdevinfo) || defined(CFE_API_ALL)
242 cfe_getdevinfo(char *name)
244 cfe_xiocb_t xiocb;
246 xiocb.xiocb_fcode = CFE_CMD_DEV_GETINFO;
247 xiocb.xiocb_status = 0;
248 xiocb.xiocb_handle = 0;
249 xiocb.xiocb_flags = 0;
250 xiocb.xiocb_psize = sizeof(xiocb_buffer_t);
251 xiocb.plist.xiocb_buffer.buf_offset = 0;
252 xiocb.plist.xiocb_buffer.buf_ptr = XPTR_FROM_NATIVE(name);
253 xiocb.plist.xiocb_buffer.buf_length = cfe_strlen(name);
255 cfe_iocb_dispatch(&xiocb);
257 if (xiocb.xiocb_status < 0)
258 return xiocb.xiocb_status;
259 return xiocb.plist.xiocb_buffer.buf_devflags;
261 #endif /* CFE_API_getdevinfo || CFE_API_ALL */
263 #if defined(CFE_API_getenv) || defined(CFE_API_ALL)
265 cfe_getenv(char *name, char *dest, int destlen)
267 cfe_xiocb_t xiocb;
269 *dest = 0;
271 xiocb.xiocb_fcode = CFE_CMD_ENV_GET;
272 xiocb.xiocb_status = 0;
273 xiocb.xiocb_handle = 0;
274 xiocb.xiocb_flags = 0;
275 xiocb.xiocb_psize = sizeof(xiocb_envbuf_t);
276 xiocb.plist.xiocb_envbuf.enum_idx = 0;
277 xiocb.plist.xiocb_envbuf.name_ptr = XPTR_FROM_NATIVE(name);
278 xiocb.plist.xiocb_envbuf.name_length = cfe_strlen(name);
279 xiocb.plist.xiocb_envbuf.val_ptr = XPTR_FROM_NATIVE(dest);
280 xiocb.plist.xiocb_envbuf.val_length = destlen;
282 cfe_iocb_dispatch(&xiocb);
284 return xiocb.xiocb_status;
286 #endif /* CFE_API_getenv || CFE_API_ALL */
288 #if defined(CFE_API_getfwinfo) || defined(CFE_API_ALL)
290 cfe_getfwinfo(cfe_fwinfo_t *info)
292 cfe_xiocb_t xiocb;
294 xiocb.xiocb_fcode = CFE_CMD_FW_GETINFO;
295 xiocb.xiocb_status = 0;
296 xiocb.xiocb_handle = 0;
297 xiocb.xiocb_flags = 0;
298 xiocb.xiocb_psize = sizeof(xiocb_fwinfo_t);
300 cfe_iocb_dispatch(&xiocb);
302 if (xiocb.xiocb_status < 0)
303 return xiocb.xiocb_status;
305 info->fwi_version = xiocb.plist.xiocb_fwinfo.fwi_version;
306 info->fwi_totalmem = xiocb.plist.xiocb_fwinfo.fwi_totalmem;
307 info->fwi_flags = xiocb.plist.xiocb_fwinfo.fwi_flags;
308 info->fwi_boardid = xiocb.plist.xiocb_fwinfo.fwi_boardid;
309 info->fwi_bootarea_va = xiocb.plist.xiocb_fwinfo.fwi_bootarea_va;
310 info->fwi_bootarea_pa = xiocb.plist.xiocb_fwinfo.fwi_bootarea_pa;
311 info->fwi_bootarea_size = xiocb.plist.xiocb_fwinfo.fwi_bootarea_size;
312 #if 0
313 info->fwi_reserved1 = xiocb.plist.xiocb_fwinfo.fwi_reserved1;
314 info->fwi_reserved2 = xiocb.plist.xiocb_fwinfo.fwi_reserved2;
315 info->fwi_reserved3 = xiocb.plist.xiocb_fwinfo.fwi_reserved3;
316 #endif
318 return 0;
320 #endif /* CFE_API_getfwinfo || CFE_API_ALL */
322 #if defined(CFE_API_getstdhandle) || defined(CFE_API_ALL)
324 cfe_getstdhandle(int flg)
326 cfe_xiocb_t xiocb;
328 xiocb.xiocb_fcode = CFE_CMD_DEV_GETHANDLE;
329 xiocb.xiocb_status = 0;
330 xiocb.xiocb_handle = 0;
331 xiocb.xiocb_flags = flg;
332 xiocb.xiocb_psize = 0;
334 cfe_iocb_dispatch(&xiocb);
336 if (xiocb.xiocb_status < 0)
337 return xiocb.xiocb_status;
338 return xiocb.xiocb_handle;
341 #endif /* CFE_API_getstdhandle || CFE_API_ALL */
343 #if defined(CFE_API_getticks) || defined(CFE_API_ALL)
344 int64_t
345 #ifdef CFE_API_IMPL_NAMESPACE
346 __cfe_getticks(void)
347 #else
348 cfe_getticks(void)
349 #endif
351 cfe_xiocb_t xiocb;
353 xiocb.xiocb_fcode = CFE_CMD_FW_GETTIME;
354 xiocb.xiocb_status = 0;
355 xiocb.xiocb_handle = 0;
356 xiocb.xiocb_flags = 0;
357 xiocb.xiocb_psize = sizeof(xiocb_time_t);
358 xiocb.plist.xiocb_time.ticks = 0;
360 cfe_iocb_dispatch(&xiocb);
362 return xiocb.plist.xiocb_time.ticks;
365 #endif /* CFE_API_getticks || CFE_API_ALL */
367 #if defined(CFE_API_inpstat) || defined(CFE_API_ALL)
369 cfe_inpstat(int handle)
371 cfe_xiocb_t xiocb;
373 xiocb.xiocb_fcode = CFE_CMD_DEV_INPSTAT;
374 xiocb.xiocb_status = 0;
375 xiocb.xiocb_handle = handle;
376 xiocb.xiocb_flags = 0;
377 xiocb.xiocb_psize = sizeof(xiocb_inpstat_t);
378 xiocb.plist.xiocb_inpstat.inp_status = 0;
380 cfe_iocb_dispatch(&xiocb);
382 if (xiocb.xiocb_status < 0)
383 return xiocb.xiocb_status;
384 return xiocb.plist.xiocb_inpstat.inp_status;
387 #endif /* CFE_API_inpstat || CFE_API_ALL */
389 #if defined(CFE_API_ioctl) || defined(CFE_API_ALL)
391 cfe_ioctl(int handle, unsigned int ioctlnum, unsigned char *buffer, int length,
392 int *retlen, cfe_xuint_t offset)
394 cfe_xiocb_t xiocb;
396 xiocb.xiocb_fcode = CFE_CMD_DEV_IOCTL;
397 xiocb.xiocb_status = 0;
398 xiocb.xiocb_handle = handle;
399 xiocb.xiocb_flags = 0;
400 xiocb.xiocb_psize = sizeof(xiocb_buffer_t);
401 xiocb.plist.xiocb_buffer.buf_offset = offset;
402 xiocb.plist.xiocb_buffer.buf_ioctlcmd = ioctlnum;
403 xiocb.plist.xiocb_buffer.buf_ptr = XPTR_FROM_NATIVE(buffer);
404 xiocb.plist.xiocb_buffer.buf_length = length;
406 cfe_iocb_dispatch(&xiocb);
408 if (retlen)
409 *retlen = xiocb.plist.xiocb_buffer.buf_retlen;
410 return xiocb.xiocb_status;
412 #endif /* CFE_API_ioctl || CFE_API_ALL */
414 #if defined(CFE_API_open) || defined(CFE_API_ALL)
416 cfe_open(char *name)
418 cfe_xiocb_t xiocb;
420 xiocb.xiocb_fcode = CFE_CMD_DEV_OPEN;
421 xiocb.xiocb_status = 0;
422 xiocb.xiocb_handle = 0;
423 xiocb.xiocb_flags = 0;
424 xiocb.xiocb_psize = sizeof(xiocb_buffer_t);
425 xiocb.plist.xiocb_buffer.buf_offset = 0;
426 xiocb.plist.xiocb_buffer.buf_ptr = XPTR_FROM_NATIVE(name);
427 xiocb.plist.xiocb_buffer.buf_length = cfe_strlen(name);
429 cfe_iocb_dispatch(&xiocb);
431 if (xiocb.xiocb_status < 0)
432 return xiocb.xiocb_status;
433 return xiocb.xiocb_handle;
435 #endif /* CFE_API_open || CFE_API_ALL */
437 #if defined(CFE_API_read) || defined(CFE_API_ALL)
439 cfe_read(int handle, unsigned char *buffer, int length)
441 return cfe_readblk(handle, 0, buffer, length);
443 #endif /* CFE_API_read || CFE_API_ALL */
445 #if defined(CFE_API_readblk) || defined(CFE_API_ALL)
447 cfe_readblk(int handle, cfe_xint_t offset, unsigned char *buffer, int length)
449 cfe_xiocb_t xiocb;
451 xiocb.xiocb_fcode = CFE_CMD_DEV_READ;
452 xiocb.xiocb_status = 0;
453 xiocb.xiocb_handle = handle;
454 xiocb.xiocb_flags = 0;
455 xiocb.xiocb_psize = sizeof(xiocb_buffer_t);
456 xiocb.plist.xiocb_buffer.buf_offset = offset;
457 xiocb.plist.xiocb_buffer.buf_ptr = XPTR_FROM_NATIVE(buffer);
458 xiocb.plist.xiocb_buffer.buf_length = length;
460 cfe_iocb_dispatch(&xiocb);
462 if (xiocb.xiocb_status < 0)
463 return xiocb.xiocb_status;
464 return xiocb.plist.xiocb_buffer.buf_retlen;
466 #endif /* CFE_API_readblk || CFE_API_ALL */
468 #if defined(CFE_API_setenv) || defined(CFE_API_ALL)
470 cfe_setenv(char *name, char *val)
472 cfe_xiocb_t xiocb;
474 xiocb.xiocb_fcode = CFE_CMD_ENV_SET;
475 xiocb.xiocb_status = 0;
476 xiocb.xiocb_handle = 0;
477 xiocb.xiocb_flags = 0;
478 xiocb.xiocb_psize = sizeof(xiocb_envbuf_t);
479 xiocb.plist.xiocb_envbuf.enum_idx = 0;
480 xiocb.plist.xiocb_envbuf.name_ptr = XPTR_FROM_NATIVE(name);
481 xiocb.plist.xiocb_envbuf.name_length = cfe_strlen(name);
482 xiocb.plist.xiocb_envbuf.val_ptr = XPTR_FROM_NATIVE(val);
483 xiocb.plist.xiocb_envbuf.val_length = cfe_strlen(val);
485 cfe_iocb_dispatch(&xiocb);
487 return xiocb.xiocb_status;
489 #endif /* CFE_API_setenv || CFE_API_ALL */
491 #if (defined(CFE_API_strlen) || defined(CFE_API_ALL)) \
492 && !defined(CFE_API_STRLEN_CUSTOM)
494 cfe_strlen(char *name)
496 int count = 0;
498 while (*name++)
499 count++;
501 return count;
503 #endif /* CFE_API_strlen || CFE_API_ALL */
505 #if defined(CFE_API_write) || defined(CFE_API_ALL)
507 cfe_write(int handle, unsigned char *buffer, int length)
509 return cfe_writeblk(handle, 0, buffer, length);
511 #endif /* CFE_API_write || CFE_API_ALL */
513 #if defined(CFE_API_writeblk) || defined(CFE_API_ALL)
515 cfe_writeblk(int handle, cfe_xint_t offset, unsigned char *buffer, int length)
517 cfe_xiocb_t xiocb;
519 xiocb.xiocb_fcode = CFE_CMD_DEV_WRITE;
520 xiocb.xiocb_status = 0;
521 xiocb.xiocb_handle = handle;
522 xiocb.xiocb_flags = 0;
523 xiocb.xiocb_psize = sizeof(xiocb_buffer_t);
524 xiocb.plist.xiocb_buffer.buf_offset = offset;
525 xiocb.plist.xiocb_buffer.buf_ptr = XPTR_FROM_NATIVE(buffer);
526 xiocb.plist.xiocb_buffer.buf_length = length;
528 cfe_iocb_dispatch(&xiocb);
530 if (xiocb.xiocb_status < 0)
531 return xiocb.xiocb_status;
532 return xiocb.plist.xiocb_buffer.buf_retlen;
534 #endif /* CFE_API_writeblk || CFE_API_ALL */