make.tmpl: add missing compiler attribute to build_progs
[AROS.git] / arch / ppc-chrp / rtas / rtas_init.c
blob44e21a9701cba93b4dab94a73f3a2d93713de525
1 /*
2 Copyright © 2009-2014, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define DEBUG 1
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)
21 int retval = TRUE;
22 void *OpenFirmwareBase;
23 void *key, *prop;
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 */
31 if (OpenFirmwareBase)
33 key = OF_OpenKey("/rtas");
34 if (key)
36 prop = OF_FindProperty(key, "load_base");
37 if (prop)
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");
45 if (prop)
47 void **reg = OF_GetPropValue(prop);
48 D(bug("[RTAS] Entry at %08x\n", *reg));
49 RTASBase->rtas_entry = *reg;
53 else
54 retval = FALSE;
57 return retval;
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)
71 AROS_LIBFUNC_INIT
73 void *OpenFirmwareBase = RTASBase->OpenFirmwareBase;
74 void *KernelBase = RTASBase->KernelBase;
76 int32_t token = 0;
77 int32_t retval = -1;
79 D(bug("[RTAS] Calling method '%s'\n", name));
81 void *key = OF_OpenKey("/rtas");
82 if (key)
84 void *prop = OF_FindProperty(key, name);
86 if (prop)
88 token = *(int32_t *)OF_GetPropValue(prop);
92 if (token)
94 D(bug("[RTAS] Method '%s', token %d\n", name, token));
95 int i;
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);
107 Disable();
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));
127 Enable();
129 else
130 retval = -1;
132 return retval;
134 AROS_LIBFUNC_EXIT
137 ADD2INITLIB(rtas_init, 0)