Skip to content

Commit f6743c8

Browse files
committed
- Commiting freeldr OFW stub source code. In order to compile them, you need to have a cygwin install (or be under *nix system which is able to produce a real elf result). Source code is not cleaned up, but I decided to commit right away so they don't get lost.
svn path=/branches/olpc/; revision=28471
1 parent 624686a commit f6743c8

File tree

19 files changed

+2603
-0
lines changed

19 files changed

+2603
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// See license at end of file
2+
3+
#include "types.h"
4+
5+
typedef long phandle;
6+
typedef long ihandle;
7+
8+
typedef struct {
9+
long hi, lo;
10+
long size;
11+
} reg;
12+
13+
#ifdef putchar
14+
# undef putchar
15+
#endif
16+
#ifdef puts
17+
# undef puts
18+
#endif
19+
20+
typedef enum {
21+
NOALLOC,
22+
ALLOC
23+
} allocflag;
24+
25+
#define new(t) (t *)zalloc(sizeof(t));
26+
27+
// LICENSE_BEGIN
28+
// Copyright (c) 2006 FirmWorks
29+
//
30+
// Permission is hereby granted, free of charge, to any person obtaining
31+
// a copy of this software and associated documentation files (the
32+
// "Software"), to deal in the Software without restriction, including
33+
// without limitation the rights to use, copy, modify, merge, publish,
34+
// distribute, sublicense, and/or sell copies of the Software, and to
35+
// permit persons to whom the Software is furnished to do so, subject to
36+
// the following conditions:
37+
//
38+
// The above copyright notice and this permission notice shall be
39+
// included in all copies or substantial portions of the Software.
40+
//
41+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
42+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
43+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
44+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
45+
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
46+
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
47+
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
48+
//
49+
// LICENSE_END
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
/*
2+
* callofw.c - Open Firmware client interface for 32-bit systems.
3+
* This code is intended to be portable to any 32-bit Open Firmware
4+
* implementation with a standard client interface that can be
5+
* called when Linux is running.
6+
*/
7+
8+
#include <stdarg.h>
9+
#include <asm/callofw.h>
10+
#include <linux/types.h>
11+
#include <linux/spinlock.h>
12+
13+
u32 (*call_firmware)(u32 *);
14+
15+
static DEFINE_SPINLOCK(prom_lock);
16+
17+
#define MAXARGS 20
18+
int callofw(char *name, int numargs, int numres, ...)
19+
{
20+
va_list ap;
21+
u32 argarray[MAXARGS+3];
22+
int argnum = 3;
23+
int retval;
24+
int *intp;
25+
unsigned long flags;
26+
27+
if (call_firmware == NULL)
28+
return -1;
29+
30+
argarray[0] = (u32)name;
31+
argarray[1] = numargs;
32+
argarray[2] = numres;
33+
34+
if ((numargs + numres) > MAXARGS)
35+
return -1;
36+
37+
va_start(ap, numres);
38+
while (numargs--)
39+
argarray[argnum++] = va_arg(ap, int);
40+
41+
spin_lock_irqsave(&prom_lock, flags);
42+
retval = call_firmware(argarray);
43+
spin_unlock_irqrestore(&prom_lock, flags);
44+
45+
if (retval == 0) {
46+
while (numres--) {
47+
intp = va_arg(ap, int *);
48+
*intp = argarray[argnum++];
49+
}
50+
}
51+
va_end(ap);
52+
return retval;
53+
}
54+
55+
/*
56+
The return value from callofw in all cases is 0 if the attempt to call the
57+
function succeeded, nonzero otherwise. That return value is from the
58+
gateway function only. Any results from the called function are returned
59+
via output argument pointers.
60+
61+
Here are call templates for all the standard OFW client services.
62+
63+
callofw("test", 1, 1, namestr, &missing);
64+
callofw("peer", 1, 1, phandle, &sibling_phandle);
65+
callofw("child", 1, 1, phandle, &child_phandle);
66+
callofw("parent", 1, 1, phandle, &parent_phandle);
67+
callofw("instance-to-package", 1, 1, ihandle, &phandle);
68+
callofw("getproplen", 2, 1, phandle, namestr, &proplen);
69+
callofw("getprop", 4, 1, phandle, namestr, bufaddr, buflen, &size);
70+
callofw("nextprop", 3, 1, phandle, previousstr, bufaddr, &flag);
71+
callofw("setprop", 4, 1, phandle, namestr, bufaddr, len, &size);
72+
callofw("canon", 3, 1, devspecstr, bufaddr, buflen, &length);
73+
callofw("finddevice", 1, 1, devspecstr, &phandle);
74+
callofw("instance-to-path", 3, 1, ihandle, bufaddr, buflen, &length);
75+
callofw("instance-to-interposed-path", 3, 1, ihandle, bufaddr, buflen, &length);
76+
callofw("package-to-path", 3, 1, phandle, bufaddr, buflen, &length);
77+
callofw("call-method", numin, numout, in0, in1, ..., &out0, &out1, ...);
78+
callofw("open", 1, 1, devspecstr, &ihandle);
79+
callofw("close", 1, 0, ihandle);
80+
callofw("read", 3, 1, ihandle, addr, len, &actual);
81+
callofw("write", 3, 1, ihandle, addr, len, &actual);
82+
callofw("seek", 3, 1, ihandle, pos_hi, pos_lo, &status);
83+
callofw("claim", 3, 1, virtaddr, size, align, &baseaddr);
84+
callofw("release", 2, 0, virtaddr, size);
85+
callofw("boot", 1, 0, bootspecstr);
86+
callofw("enter", 0, 0);
87+
callofw("exit", 0, 0);
88+
callofw("chain", 5, 0, virtaddr, size, entryaddr, argsaddr, len);
89+
callofw("interpret", numin+1, numout+1, cmdstr, in0, ..., &catchres, &out0, ...);
90+
callofw("set-callback", 1, 1, newfuncaddr, &oldfuncaddr);
91+
callofw("set-symbol-lookup", 2, 0, symtovaladdr, valtosymaddr);
92+
callofw("milliseconds", 0, 1, &ms);
93+
*/
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
// See license at end of file
2+
3+
/* For gcc, compile with -fno-builtin to suppress warnings */
4+
5+
#include "1275.h"
6+
7+
#include <stdarg.h>
8+
9+
int level = 0;
10+
11+
int Debug = 0;
12+
13+
VOID
14+
debug(int debug_level, char *fmt, ...)
15+
{
16+
va_list args;
17+
int i;
18+
19+
if (!(debug_level & Debug))
20+
return;
21+
22+
va_start(args, fmt);
23+
for (i = 0; i < level; ++i)
24+
putchar('\t');
25+
printf(fmt, args);
26+
va_end(args);
27+
}
28+
29+
// LICENSE_BEGIN
30+
// Copyright (c) 2006 FirmWorks
31+
//
32+
// Permission is hereby granted, free of charge, to any person obtaining
33+
// a copy of this software and associated documentation files (the
34+
// "Software"), to deal in the Software without restriction, including
35+
// without limitation the rights to use, copy, modify, merge, publish,
36+
// distribute, sublicense, and/or sell copies of the Software, and to
37+
// permit persons to whom the Software is furnished to do so, subject to
38+
// the following conditions:
39+
//
40+
// The above copyright notice and this permission notice shall be
41+
// included in all copies or substantial portions of the Software.
42+
//
43+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
44+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
45+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
46+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
47+
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
48+
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
49+
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
50+
//
51+
// LICENSE_END
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// See license at end of file
2+
3+
/* For gcc, compile with -fno-builtin to suppress warnings */
4+
5+
#include "1275.h"
6+
7+
int
8+
decode_int(UCHAR *p)
9+
{
10+
ULONG i = *p++ << 8;
11+
i = (i + *p++) << 8;
12+
i = (i + *p++) << 8;
13+
return (i + *p);
14+
}
15+
16+
int
17+
get_int_prop(phandle node, char *key)
18+
{
19+
int res;
20+
char buf[sizeof(int)];
21+
22+
res = OFGetprop(node, key, buf, sizeof(int));
23+
if (res != sizeof(int)) {
24+
#ifdef notdef
25+
fatal("get_int_prop(node %x, key '%s') returned %x\n",
26+
node, key, res);
27+
#endif
28+
return(-1);
29+
}
30+
return(decode_int((UCHAR *) buf));
31+
}
32+
33+
int
34+
get_int_prop_def(phandle node, char *key, int defval)
35+
{
36+
int res;
37+
char buf[sizeof(int)];
38+
39+
res = OFGetprop(node, key, buf, sizeof(int));
40+
if (res != sizeof(int)) {
41+
return(defval);
42+
}
43+
return(decode_int((UCHAR *) buf));
44+
}
45+
46+
// LICENSE_BEGIN
47+
// Copyright (c) 2006 FirmWorks
48+
//
49+
// Permission is hereby granted, free of charge, to any person obtaining
50+
// a copy of this software and associated documentation files (the
51+
// "Software"), to deal in the Software without restriction, including
52+
// without limitation the rights to use, copy, modify, merge, publish,
53+
// distribute, sublicense, and/or sell copies of the Software, and to
54+
// permit persons to whom the Software is furnished to do so, subject to
55+
// the following conditions:
56+
//
57+
// The above copyright notice and this permission notice shall be
58+
// included in all copies or substantial portions of the Software.
59+
//
60+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
61+
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
62+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
63+
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
64+
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
65+
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
66+
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
67+
//
68+
// LICENSE_END

0 commit comments

Comments
 (0)