ofw.c

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 2005 Martin Decky
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  *
00009  * - Redistributions of source code must retain the above copyright
00010  *   notice, this list of conditions and the following disclaimer.
00011  * - Redistributions in binary form must reproduce the above copyright
00012  *   notice, this list of conditions and the following disclaimer in the
00013  *   documentation and/or other materials provided with the distribution.
00014  * - The name of the author may not be used to endorse or promote products
00015  *   derived from this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
00018  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00019  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
00020  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
00021  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
00022  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
00023  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
00024  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
00025  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
00026  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00035 #include <genarch/ofw/ofw.h>
00036 #include <arch/asm.h>
00037 #include <stdarg.h>
00038 #include <cpu.h>
00039 #include <arch/types.h>
00040 
00041 ofw_entry ofw;
00042 
00043 phandle ofw_chosen;
00044 ihandle ofw_stdin;
00045 ihandle ofw_stdout;
00046 
00047 void ofw_init(void)
00048 {
00049         ofw_chosen = ofw_find_device("/chosen");
00050         if (ofw_chosen == -1)
00051                 ofw_done();
00052         
00053         if (ofw_get_property(ofw_chosen, "stdin",  &ofw_stdin, sizeof(ofw_stdin)) <= 0)
00054                 ofw_stdin = 0;
00055                 
00056         if (ofw_get_property(ofw_chosen, "stdout",  &ofw_stdout, sizeof(ofw_stdout)) <= 0)
00057                 ofw_stdout = 0; 
00058 }
00059 
00060 void ofw_done(void)
00061 {
00062         (void) ofw_call("exit", 0, 0);
00063         cpu_halt();
00064 }
00065 
00066 __native ofw_call(const char *service, const int nargs, const int nret, ...)
00067 {
00068         va_list list;
00069         ofw_args_t args;
00070         int i;
00071         
00072         args.service = service;
00073         args.nargs = nargs;
00074         args.nret = nret;
00075         
00076         va_start(list, nret);
00077         for (i = 0; i < nargs; i++)
00078                 args.args[i] = va_arg(list, ofw_arg_t);
00079         va_end(list);
00080         
00081         for (i = 0; i < nret; i++)
00082                 args.args[i + nargs] = 0;
00083         
00084         ofw(&args);
00085         
00086         return args.args[nargs];
00087 }
00088 
00089 void ofw_putchar(const char ch)
00090 {
00091         if (ofw_stdout == 0)
00092                 return;
00093         
00094         (void) ofw_call("write", 3, 1, ofw_stdout, &ch, 1);
00095 }
00096 
00103 char ofw_getchar(void)
00104 {
00105         char ch;
00106 
00107         if (ofw_stdin == 0)
00108                 return 0;
00109         
00110         if (ofw_call("read", 3, 1, ofw_stdin, &ch, 1) == 1)
00111                 return ch;
00112         else
00113                 return 0;
00114 }
00115 
00116 phandle ofw_find_device(const char *name)
00117 {
00118         return (phandle) ofw_call("finddevice", 1, 1, name);
00119 }
00120 
00121 int ofw_get_property(const phandle device, const char *name, void *buf, const int buflen)
00122 {
00123         return (int) ofw_call("getprop", 4, 1, device, name, buf, buflen);
00124 }
00125 
00126 void *ofw_claim(const void *addr, const int size, const int align)
00127 {
00128         return (void *) ofw_call("claim", 3, 1, addr, size, align);
00129 }
00130 

Generated on Sun Jun 18 17:37:25 2006 for HelenOS Kernel (sparc64) by  doxygen 1.4.6