2 Copyright © 2009-2014, The AROS Development Team. All rights reserved.
8 //#include <asm/mpc5200b.h>
9 #include <aros/debug.h>
10 #include <aros/symbolsets.h>
11 #include <aros/libcall.h>
12 #include <proto/openfirmware.h>
13 #include <proto/kernel.h>
14 #include <proto/exec.h>
15 #include <proto/rtas.h>
17 #include "rtas_private.h"
19 static int rtas_init(struct RTASBase
*RTASBase
)
22 void *OpenFirmwareBase
;
25 D(bug("[RTAS] RTAS Init.\n"));
27 OpenFirmwareBase
= RTASBase
->OpenFirmwareBase
= OpenResource("openfirmware.resource");
28 RTASBase
->KernelBase
= OpenResource("kernel.resource");
30 /* Get some addresses from OF tree */
33 key
= OF_OpenKey("/rtas");
36 prop
= OF_FindProperty(key
, "load_base");
39 void **reg
= OF_GetPropValue(prop
);
40 D(bug("[RTAS] RTAS loaded at %08x\n", *reg
));
41 RTASBase
->rtas_base
= *reg
;
44 prop
= OF_FindProperty(key
, "entry");
47 void **reg
= OF_GetPropValue(prop
);
48 D(bug("[RTAS] Entry at %08x\n", *reg
));
49 RTASBase
->rtas_entry
= *reg
;
60 extern void return_entry();
61 extern void return_2();
63 AROS_LH5(int32_t, RTASCall
,
64 AROS_LHA(const char *, name
, A0
),
65 AROS_LHA(uint32_t, nargs
, D0
),
66 AROS_LHA(uint32_t, nrets
, D1
),
67 AROS_LHA(uint32_t *, output
, A1
),
68 AROS_LHA(va_list, args
, A2
),
69 struct RTASBase
*, RTASBase
, 1, Rtas
)
73 void *OpenFirmwareBase
= RTASBase
->OpenFirmwareBase
;
74 void *KernelBase
= RTASBase
->KernelBase
;
79 D(bug("[RTAS] Calling method '%s'\n", name
));
81 void *key
= OF_OpenKey("/rtas");
84 void *prop
= OF_FindProperty(key
, name
);
88 token
= *(int32_t *)OF_GetPropValue(prop
);
94 D(bug("[RTAS] Method '%s', token %d\n", name
, token
));
97 RTASBase
->rtas_args
.token
= token
;
98 RTASBase
->rtas_args
.nargs
= nargs
;
99 RTASBase
->rtas_args
.nret
= nrets
;
100 RTASBase
->rtas_args
.rets
= KrnVirtualToPhysical(&RTASBase
->rtas_args
.args
[nargs
]);
102 for (i
=0; i
< nargs
; i
++)
104 RTASBase
->rtas_args
.args
[i
] = va_arg(args
, uint32_t);
110 register intptr_t args
asm ("r4") = KrnVirtualToPhysical(&RTASBase
->rtas_args
);
111 register intptr_t base
asm ("r5") = RTASBase
->rtas_base
;
112 register intptr_t entry
asm ("r6") = RTASBase
->rtas_entry
;
114 asm volatile("li %%r3,%0; sc"::"i"(9 /*SC_RTAS*/),"r"(args
),"r"(base
),"r"(entry
):"memory","r3");
117 if (nrets
> 1 && output
)
119 for (i
=0; i
< nrets
-1; i
++)
120 output
[i
] = RTASBase
->rtas_args
.rets
[i
+1];
123 retval
= nrets
> 0 ? RTASBase
->rtas_args
.rets
[0] : 0;
125 D(bug("[RTAS] The call returned %d\n", retval
));
137 ADD2INITLIB(rtas_init
, 0)