27,10 → 27,12 |
*/ |
|
#include "ofw.h" |
#include "printf.h" |
|
ofw_entry ofw; |
|
phandle ofw_chosen; |
ihandle ofw_mmu; |
ihandle ofw_stdout; |
|
|
38,13 → 40,24 |
{ |
ofw_chosen = ofw_find_device("/chosen"); |
if (ofw_chosen == -1) |
ofw_call("exit", 0, 0); |
halt(); |
|
if (ofw_get_property(ofw_chosen, "stdout", &ofw_stdout, sizeof(ofw_stdout)) <= 0) |
ofw_stdout = 0; |
|
ofw_mmu = ofw_open("/mmu"); |
if (ofw_mmu == -1) { |
puts("Unable to open /mmu node\n"); |
halt(); |
} |
} |
|
void halt(void) |
{ |
ofw_call("exit", 0, 0); |
} |
|
|
int ofw_call(const char *service, const int nargs, const int nret, ...) |
{ |
va_list list; |
65,10 → 78,19 |
|
ofw(&args); |
|
return args.args[nargs]; |
if (nret > 0) |
return args.args[nargs + nret - 1]; |
else |
return 0; |
} |
|
|
ihandle ofw_open(const char *name) |
{ |
return ofw_call("open", 1, 1, name); |
} |
|
|
void ofw_write(const char *str, const int len) |
{ |
if (ofw_stdout == 0) |
78,17 → 100,6 |
} |
|
|
void ofw_puts(const char *str) |
{ |
int len = 0; |
|
while (str[len] != 0) |
len++; |
|
ofw_write(str, len); |
} |
|
|
phandle ofw_find_device(const char *name) |
{ |
return ofw_call("finddevice", 1, 1, name); |
105,3 → 116,9 |
{ |
return (void *) ofw_call("claim", 3, 1, addr, size, align); |
} |
|
|
void *ofw_translate(const void *virt) |
{ |
return (void *) ofw_call_method(ofw_mmu, "translate", 1, 5, virt); |
} |