19 static int (*prom) (
void *);
23 prom = (
int (*)(
void *))promptr;
33 unsigned int args[12];
42 for (i = 0; i < nargs; i++)
46 for (i = 0; i < nret; i++)
47 args.args[nargs+i] = 0;
52 return (nret > 0)?
args.args[nargs]: 0;
55 static int of_call_prom_ret(
const char *
service,
int nargs,
int nret,
56 unsigned int *rets, ...)
63 unsigned int args[12];
72 for (i = 0; i < nargs; i++)
76 for (i = 0; i < nret; i++)
77 args.args[nargs+i] = 0;
82 if (rets != (
void *) 0)
83 for (i = 1; i < nret; ++
i)
84 rets[i-1] =
args.args[nargs+i];
90 static int string_match(
const char *
s1,
const char *
s2)
104 static int need_map = -1;
108 static int check_of_version(
void)
116 if (
of_getprop(oprom,
"model", version,
sizeof(version)) <= 0)
118 version[
sizeof(
version)-1] = 0;
119 printf(
"OF version = '%s'\r\n", version);
120 if (!string_match(version,
"Open Firmware, 1.")
121 && !string_match(version,
"FirmWorks,3."))
131 if (
of_getprop(chosen,
"mmu", &chosen_mmu,
sizeof(chosen_mmu)) <= 0) {
139 printf(
"no memory node\n");
143 printf(
"old OF detected\r\n");
153 need_map = check_of_version();
154 if (align || !need_map)
155 return (
void *)
of_call_prom(
"claim", 3, 1, virt, size, align);
157 ret = of_call_prom_ret(
"call-method", 5, 2, &result,
"claim", memory,
159 if (ret != 0 || result == -1)
161 ret = of_call_prom_ret(
"call-method", 5, 2, &result,
"claim", chosen_mmu,
164 ret =
of_call_prom(
"call-method", 6, 1,
"map", chosen_mmu,
165 0x12, size, virt, virt);
166 return (
void *) virt;
180 printf(
"Trying to claim from 0x%lx to 0x%lx (0x%lx) got %p\r\n",
181 start,
end,
end - start, addr);
185 fatal(
"Can't allocate memory for kernel image!\n\r");
206 return of_call_prom(
"getprop", 4, 1, phandle, name, buf, buflen);
212 return of_call_prom(
"setprop", 4, 1, phandle, name, buf, buflen);