powerpc-ofw-boot/src/ofw/tree.c

285 lines
5.6 KiB
C
Raw Normal View History

2023-07-01 11:07:36 +00:00
#include <ofw.h>
2023-07-01 10:27:07 +00:00
extern void (*ofw)();
2023-07-01 11:08:55 +00:00
phandle child(phandle _child)
2023-07-01 10:27:07 +00:00
{
2023-07-01 11:08:55 +00:00
struct
2023-07-01 10:27:07 +00:00
{
char* service;
2023-07-01 14:07:47 +00:00
int32_t n_args;
int32_t n_rets;
2023-07-01 11:08:55 +00:00
phandle arg;
phandle ret;
2023-07-01 10:27:07 +00:00
} ofw_arg;
2023-07-01 11:23:50 +00:00
SERVICE("child", 6, 1, 1);
2023-07-01 10:27:07 +00:00
2023-07-01 11:08:55 +00:00
ofw_arg.arg = _child;
2023-07-01 10:27:07 +00:00
ofw(&ofw_arg);
return ofw_arg.ret;
}
2023-07-01 11:07:36 +00:00
phandle parent(phandle _parent)
{
struct
{
char* service;
2023-07-01 14:07:47 +00:00
int32_t n_args;
int32_t n_rets;
2023-07-01 11:07:36 +00:00
phandle arg;
phandle ret;
} ofw_arg;
2023-07-01 11:23:50 +00:00
SERVICE("parent", 7, 1, 1);
2023-07-01 11:07:36 +00:00
ofw_arg.arg = _parent;
ofw(&ofw_arg);
return ofw_arg.ret;
}
2023-07-01 11:35:19 +00:00
phandle instance_to_package(ihandle instance)
2023-07-01 11:07:36 +00:00
{
struct
{
char* service;
2023-07-01 14:07:47 +00:00
int32_t n_args;
int32_t n_rets;
2023-07-01 11:07:36 +00:00
ihandle arg;
phandle ret;
} ofw_arg;
2023-07-01 11:23:50 +00:00
SERVICE("instance-to-package", 20, 1, 1);
2023-07-01 11:07:36 +00:00
2023-07-01 11:35:19 +00:00
ofw_arg.arg = instance;
2023-07-01 11:07:36 +00:00
ofw(&ofw_arg);
return ofw_arg.ret;
}
2023-07-01 14:07:47 +00:00
int32_t getproplen(phandle node, char* name)
2023-07-01 11:07:36 +00:00
{
struct
{
char* service;
2023-07-01 14:07:47 +00:00
int32_t n_args;
int32_t n_rets;
2023-07-01 11:07:36 +00:00
phandle arg1;
2023-07-01 11:08:55 +00:00
char* arg2;
2023-07-01 14:07:47 +00:00
int32_t ret;
2023-07-01 11:07:36 +00:00
} ofw_arg;
2023-07-01 11:23:50 +00:00
SERVICE("getproplen", 11, 2, 1);
2023-07-01 11:07:36 +00:00
ofw_arg.arg1 = node;
2023-07-01 11:08:55 +00:00
ofw_arg.arg2 = name;
2023-07-01 11:07:36 +00:00
ofw(&ofw_arg);
return ofw_arg.ret;
}
2023-07-01 14:22:16 +00:00
int32_t getprop(phandle node, char* name, void* buf, int32_t buflen)
2023-07-01 11:07:36 +00:00
{
struct
{
char* service;
2023-07-01 14:07:47 +00:00
int32_t n_args;
int32_t n_rets;
2023-07-01 11:07:36 +00:00
phandle arg1;
2023-07-01 11:08:55 +00:00
char* arg2;
2023-07-01 14:22:16 +00:00
void* arg3;
2023-07-01 14:07:47 +00:00
int32_t arg4;
int32_t ret;
2023-07-01 11:07:36 +00:00
} ofw_arg;
2023-07-01 11:23:50 +00:00
SERVICE("getprop", 8, 4, 1);
2023-07-01 11:07:36 +00:00
ofw_arg.arg1 = node;
ofw_arg.arg2 = name;
2023-07-01 11:08:55 +00:00
ofw_arg.arg3 = buf;
ofw_arg.arg4 = buflen;
2023-07-01 11:07:36 +00:00
ofw(&ofw_arg);
return ofw_arg.ret;
}
2023-07-01 14:22:16 +00:00
int32_t nextprop(phandle node, char* previous, void* buf)
2023-07-01 11:07:36 +00:00
{
struct
{
char* service;
2023-07-01 14:07:47 +00:00
int32_t n_args;
int32_t n_rets;
2023-07-01 11:07:36 +00:00
phandle arg1;
char* arg2;
2023-07-01 14:22:16 +00:00
void* arg3;
2023-07-01 14:07:47 +00:00
int32_t ret;
2023-07-01 11:07:36 +00:00
} ofw_arg;
2023-07-01 11:23:50 +00:00
SERVICE("nextprop", 9, 3, 1);
2023-07-01 11:07:36 +00:00
ofw_arg.arg1 = node;
ofw_arg.arg2 = previous;
ofw_arg.arg3 = buf;
ofw(&ofw_arg);
return ofw_arg.ret;
}
2023-07-01 14:22:16 +00:00
int32_t setprop(phandle node, char* name, void* buf, int32_t len)
2023-07-01 11:07:36 +00:00
{
struct
{
char* service;
2023-07-01 14:07:47 +00:00
int32_t n_args;
int32_t n_rets;
2023-07-01 11:07:36 +00:00
phandle arg1;
char* arg2;
2023-07-01 14:22:16 +00:00
void* arg3;
2023-07-01 14:07:47 +00:00
int32_t arg4;
int32_t ret;
2023-07-01 11:07:36 +00:00
} ofw_arg;
char _service[8] = "setprop";
ofw_arg.service = _service;
ofw_arg.n_args = 4;
ofw_arg.n_rets = 1;
ofw_arg.arg1 = node;
ofw_arg.arg2 = name;
ofw_arg.arg3 = buf;
ofw_arg.arg4 = len;
ofw(&ofw_arg);
return ofw_arg.ret;
}
2023-07-01 14:22:16 +00:00
int32_t canon(char* device, void* buf, int32_t buflen)
2023-07-01 11:07:36 +00:00
{
struct
{
char* service;
2023-07-01 14:07:47 +00:00
int32_t n_args;
int32_t n_rets;
2023-07-01 11:07:36 +00:00
char* arg1;
2023-07-01 14:22:16 +00:00
void* arg2;
2023-07-01 14:07:47 +00:00
int32_t arg3;
int32_t ret;
2023-07-01 11:07:36 +00:00
} ofw_arg;
2023-07-01 11:23:50 +00:00
SERVICE("canon", 6, 3, 1);
2023-07-01 11:07:36 +00:00
ofw_arg.arg1 = device;
ofw_arg.arg2 = buf;
ofw_arg.arg3 = buflen;
ofw(&ofw_arg);
return ofw_arg.ret;
}
phandle finddevice(char* device)
{
struct
{
char* service;
2023-07-01 14:07:47 +00:00
int32_t n_args;
int32_t n_rets;
2023-07-01 11:07:36 +00:00
char* arg1;
2023-07-01 14:07:47 +00:00
int32_t ret;
2023-07-01 11:07:36 +00:00
} ofw_arg;
2023-07-01 11:23:50 +00:00
SERVICE("finddevice", 11, 1, 1);
2023-07-01 11:07:36 +00:00
ofw_arg.arg1 = device;
ofw(&ofw_arg);
return ofw_arg.ret;
}
2023-07-01 14:22:16 +00:00
int32_t instance_to_path(ihandle instance, void* buf, int32_t buflen)
2023-07-01 11:07:36 +00:00
{
struct
{
char* service;
2023-07-01 14:07:47 +00:00
int32_t n_args;
int32_t n_rets;
2023-07-01 11:07:36 +00:00
ihandle arg1;
2023-07-01 14:22:16 +00:00
void* arg2;
2023-07-01 14:07:47 +00:00
int32_t arg3;
int32_t ret;
2023-07-01 11:07:36 +00:00
} ofw_arg;
2023-07-01 11:23:50 +00:00
SERVICE("instance-to-path", 17, 3, 1);
2023-07-01 11:07:36 +00:00
ofw_arg.arg1 = instance;
ofw_arg.arg2 = buf;
ofw_arg.arg3 = buflen;
ofw(&ofw_arg);
return ofw_arg.ret;
}
2023-07-01 14:22:16 +00:00
int32_t package_to_path(phandle package, void* buf, int32_t buflen)
2023-07-01 11:07:36 +00:00
{
struct
{
char* service;
2023-07-01 14:07:47 +00:00
int32_t n_args;
int32_t n_rets;
2023-07-01 11:07:36 +00:00
ihandle arg1;
2023-07-01 14:22:16 +00:00
void* arg2;
2023-07-01 14:07:47 +00:00
int32_t arg3;
int32_t ret;
2023-07-01 11:07:36 +00:00
} ofw_arg;
2023-07-01 11:23:50 +00:00
SERVICE("package-to-path", 16, 3, 1);
2023-07-01 11:07:36 +00:00
ofw_arg.arg1 = package;
ofw_arg.arg2 = buf;
ofw_arg.arg3 = buflen;
ofw(&ofw_arg);
return ofw_arg.ret;
}
2023-07-01 20:34:49 +00:00
void* call_method(char* method, ihandle instance, int32_t* stack_args, int32_t n_stack_args, int32_t n_ret_args, int32_t* retaddr)
2023-07-01 11:07:36 +00:00
{
2023-07-01 16:15:06 +00:00
struct
{
char* service;
int32_t n_args;
int32_t n_rets;
char* arg1;
ihandle arg2;
int32_t argN[n_stack_args];
int32_t ret1;
2023-07-01 20:34:49 +00:00
int32_t retN[n_ret_args];
2023-07-01 16:15:06 +00:00
} ofw_arg;
2023-07-01 20:34:49 +00:00
SERVICE("call-method", 12, 2+n_stack_args, n_ret_args);
2023-07-01 16:15:06 +00:00
ofw_arg.arg1 = method;
ofw_arg.arg2 = instance;
int i;
for (i = 0; i < n_stack_args; i++)
{
ofw_arg.argN[i] = stack_args[i];
}
ofw(&ofw_arg);
2023-07-01 16:27:27 +00:00
*retaddr = ofw_arg.ret1;
2023-07-01 20:34:49 +00:00
for (i = 1; i < n_ret_args+1; i++)
2023-07-01 16:15:06 +00:00
{
2023-07-01 16:27:27 +00:00
retaddr[i] = ofw_arg.retN[i];
2023-07-01 16:15:06 +00:00
}
2023-07-01 16:27:27 +00:00
return retaddr;
2023-07-01 11:07:36 +00:00
}
2023-07-01 11:08:55 +00:00