4 * Created on: Mar 22, 2009
10 #include <asm/mpc5200b.h>
11 #include <aros/debug.h>
12 #include <aros/symbolsets.h>
13 #include <aros/libcall.h>
14 #include <proto/openfirmware.h>
15 #include <proto/kernel.h>
16 #include <proto/exec.h>
17 #include <proto/rtas.h>
19 #include "rtas_private.h"
21 static int rtas_init(struct RTASBase
*RTASBase
)
24 void *OpenFirmwareBase
;
27 D(bug("[RTAS] RTAS Init.\n"));
29 OpenFirmwareBase
= RTASBase
->OpenFirmwareBase
= OpenResource("openfirmware.resource");
30 RTASBase
->KernelBase
= OpenResource("kernel.resource");
32 /* Get some addresses from OF tree */
35 key
= OF_OpenKey("/rtas");
38 prop
= OF_FindProperty(key
, "load_base");
41 void **reg
= OF_GetPropValue(prop
);
42 D(bug("[RTAS] RTAS loaded at %08x\n", *reg
));
43 RTASBase
->rtas_base
= *reg
;
46 prop
= OF_FindProperty(key
, "entry");
49 void **reg
= OF_GetPropValue(prop
);
50 D(bug("[RTAS] Entry at %08x\n", *reg
));
51 RTASBase
->rtas_entry
= *reg
;
62 extern void return_entry();
63 extern void return_2();
65 AROS_LH5(int32_t, RTASCall
,
66 AROS_LHA(const char *, name
, A0
),
67 AROS_LHA(uint32_t, nargs
, D0
),
68 AROS_LHA(uint32_t, nrets
, D1
),
69 AROS_LHA(uint32_t *, output
, A1
),
70 AROS_LHA(va_list, args
, A2
),
71 struct RTASBase
*, RTASBase
, 0, Rtas
)
75 void *OpenFirmwareBase
= RTASBase
->OpenFirmwareBase
;
76 void *KernelBase
= RTASBase
->KernelBase
;
81 D(bug("[RTAS] Calling method '%s'\n", name
));
83 void *key
= OF_OpenKey("/rtas");
86 void *prop
= OF_FindProperty(key
, name
);
90 token
= *(int32_t *)OF_GetPropValue(prop
);
96 D(bug("[RTAS] Method '%s', token %d\n", name
, token
));
99 RTASBase
->rtas_args
.token
= token
;
100 RTASBase
->rtas_args
.nargs
= nargs
;
101 RTASBase
->rtas_args
.nret
= nrets
;
102 RTASBase
->rtas_args
.rets
= KrnVirtualToPhysical(&RTASBase
->rtas_args
.args
[nargs
]);
104 for (i
=0; i
< nargs
; i
++)
106 RTASBase
->rtas_args
.args
[i
] = va_arg(args
, uint32_t);
112 register intptr_t args
asm ("r4") = KrnVirtualToPhysical(&RTASBase
->rtas_args
);
113 register intptr_t base
asm ("r5") = RTASBase
->rtas_base
;
114 register intptr_t entry
asm ("r6") = RTASBase
->rtas_entry
;
116 asm volatile("li %%r3,%0; sc"::"i"(9 /*SC_RTAS*/),"r"(args
),"r"(base
),"r"(entry
):"memory","r3");
119 if (nrets
> 1 && output
)
121 for (i
=0; i
< nrets
-1; i
++)
122 output
[i
] = RTASBase
->rtas_args
.rets
[i
+1];
125 retval
= nrets
> 0 ? RTASBase
->rtas_args
.rets
[0] : 0;
127 D(bug("[RTAS] The call returned %d\n", retval
));
139 ADD2INITLIB(rtas_init
, 0)