00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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