[openfirmware] [commit] r2919 - in clients: hello lib lib/arm lib/x86
repository service
svn at openfirmware.info
Tue Mar 27 02:22:53 CEST 2012
Author: wmb
Date: Tue Mar 27 02:22:52 2012
New Revision: 2919
URL: http://tracker.coreboot.org/trac/openfirmware/changeset/2919
Log:
Client library - big checkin to
a) Support cell-sized stdin and stdout properties
b) Clean up data typing to satisfy XCode compilers
Added:
clients/lib/cellprop.c (contents, props changed)
clients/lib/string.h (contents, props changed)
clients/lib/x86/start.S
Modified:
clients/hello/hello.c
clients/lib/1275.h
clients/lib/arm/makefile
clients/lib/arm/start.c
clients/lib/debug.c
clients/lib/intprop.c
clients/lib/lib.c
clients/lib/malloc.c
clients/lib/malloc.h
clients/lib/mem.c
clients/lib/printf.c
clients/lib/regprop.c
clients/lib/strings.c
clients/lib/strprop.c
clients/lib/wrappers.c
clients/lib/x86/makefile
clients/lib/x86/start.s
Modified: clients/hello/hello.c
==============================================================================
--- clients/hello/hello.c Tue Mar 27 02:14:21 2012 (r2918)
+++ clients/hello/hello.c Tue Mar 27 02:22:52 2012 (r2919)
@@ -1,4 +1,7 @@
-main()
+#include "1275.h"
+
+int main()
{
printf("Hello, world\n");
+ return 0;
}
Modified: clients/lib/1275.h
==============================================================================
--- clients/lib/1275.h Tue Mar 27 02:14:21 2012 (r2918)
+++ clients/lib/1275.h Tue Mar 27 02:22:52 2012 (r2919)
@@ -1,13 +1,23 @@
// See license at end of file
-#include "types.h"
+// -----------------------------------------------------------------
+// Type definitions and miscellaneous data structures
-typedef long phandle;
-typedef long ihandle;
+#ifndef __1275_h__
+#define __1275_h__
+
+#define NULL 0
+
+typedef unsigned char UCHAR;
+typedef unsigned long ULONG;
+
+typedef ULONG cell_t ;
+typedef ULONG phandle;
+typedef ULONG ihandle;
typedef struct {
- long hi, lo;
- long size;
+ ULONG hi, lo;
+ ULONG size;
} reg;
#ifdef putchar
@@ -24,60 +34,73 @@
#define new(t) (t *)zalloc(sizeof(t));
-#ifdef SPRO
-typedef long long cell_t;
-#else
-typedef unsigned long cell_t ;
-#endif
-
-#ifdef CIF64
-#define LOW(index) ((index*2) + 1)
-#else
#define LOW(index) (index)
-#endif
-extern int call_firmware(ULONG *);
-extern void warn(char *fmt, ...);
+// -----------------------------------------------------------------
+// External C library functions, and the like.
-#ifdef CIF64
-#define CIF_HANDLER_IN 6
-#else
-#define CIF_HANDLER_IN 3
-#endif
+#include <stdlib.h>
+
+extern int decode_int(UCHAR *);
+extern void exit(int);
+extern void fatal(char *fmt, ...);
+extern void free(void *);
+extern cell_t get_cell_prop(phandle, char *);
+extern cell_t get_cell_prop_def(phandle, char *, cell_t);
+extern int get_int_prop(phandle, char *);
+extern int get_int_prop_def(phandle, char *, int);
+extern char *get_str_prop(phandle, const char *, allocflag);
+extern void *malloc(size_t);
+extern void memcpy(void *, void *, size_t);
+extern void memset(void *, int, size_t);
+extern int memcmp(const void *, const void *, size_t);
+extern int printf(char *fmt, ...);
+extern void putchar(UCHAR);
+extern void *realloc(void *, size_t);
+extern void warn(char *fmt, ...);
+extern void *zalloc(size_t);
+// -----------------------------------------------------------------
+// Open Firmware client interface calls.
+
+#define CIF_HANDLER_IN 3
extern int call_firmware(ULONG *);
-extern void warn(char *fmt, ...);
-int atoi(const char *s);
void OFClose(ihandle id);
phandle OFPeer(phandle device_id);
phandle OFChild(phandle device_id);
phandle OFParent(phandle device_id);
-long OFGetproplen(phandle device_id, char *name);
-long OFGetprop(phandle device_id, char *name, char *buf, ULONG buflen);
-long OFNextprop(phandle device_id, char *name, char *buf);
-long OFSetprop(phandle device_id, char *name, char *buf, ULONG buflen);
+long OFGetproplen(phandle device_id, const char *name);
+long OFGetprop(phandle device_id, const char *name, UCHAR *buf, ULONG buflen);
+long OFNextprop(phandle device_id, const char *name, UCHAR *buf);
+long OFSetprop(phandle device_id, const char *name, UCHAR *buf, ULONG buflen);
phandle OFFinddevice(char *devicename);
ihandle OFOpen(char *devicename);
ihandle OFCreate(char *devicename);
void OFClose(ihandle id);
-long OFRead(ihandle instance_id, char *addr, ULONG len);
-long OFWrite(ihandle instance_id, char *addr, ULONG len);
+long OFRead(ihandle instance_id, UCHAR *addr, ULONG len);
+long OFWrite(ihandle instance_id, UCHAR *addr, ULONG len);
long OFSeek(ihandle instance_id, ULONG poshi, ULONG poslo);
-ULONG OFClaim(char *addr, ULONG size, ULONG align);
-VOID OFRelease(char *addr, ULONG size);
-long OFPackageToPath(phandle device_id, char *addr, ULONG buflen);
+ULONG OFClaim(UCHAR *addr, ULONG size, ULONG align);
+void OFRelease(UCHAR *addr, ULONG size);
+long OFPackageToPath(phandle device_id, UCHAR *addr, ULONG buflen);
phandle OFInstanceToPackage(ihandle ih);
long OFCallMethod(char *method, ihandle id, ULONG arg);
-long OFInterpret0(char *cmd);
-ULONG OFMilliseconds(VOID);
+long OFInterpret0(const char *cmd);
+ULONG OFMilliseconds(void);
void (*OFSetCallback(void (*func)(void)))(void);
-long OFBoot(char *bootspec);
-VOID OFEnter(VOID);
-VOID OFExit(VOID);
+void OFBoot(char *bootspec);
+void OFEnter(void);
+#ifdef __GNUC__
+void OFExit(void) __attribute__((noreturn));
+#else
+void OFExit(void);
+#endif
long OFCallMethodV(char *method, ihandle id, int nargs, int nrets, ...);
long OFInterpretV(char *cmd, int nargs, int nrets, ...);
+#endif // __1275_h__
+
// LICENSE_BEGIN
// Copyright (c) 2006 FirmWorks
//
@@ -101,3 +124,4 @@
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// LICENSE_END
+
Modified: clients/lib/arm/makefile
==============================================================================
--- clients/lib/arm/makefile Tue Mar 27 02:14:21 2012 (r2918)
+++ clients/lib/arm/makefile Tue Mar 27 02:22:52 2012 (r2919)
@@ -18,56 +18,56 @@
CFLAGS += -fno-stack-protector
endif
+# DEVELOPER = $(shell xcode-select -print-path)
+# SDK = $(shell xcodebuild -showsdks | grep iphoneos | head -1 | sed 's/.*-sdk //')
+# CC = xcrun -sdk ${SDK} gcc
+#
+# Rationale for these flags:
+# -Oz optimizes for smallest possible size. (Apple-specific)
+# -fno-toplevel-reorder keeps inflate() as the first entry point.
+# -ffreestanding means don't assume standard libraries, inlines, and builtins
+# -thumb gives 30%-50% improvement over ARM32.
+# -arch armv7 uses more powerful instructions for less space.
+# -static -nostartfiles allows us to link this as a static text image.
+# CFLAGS = -I.. -Oz -arch armv7 -mthumb -static -nostartfiles \
+# -I$(DEVELOPER)/Platforms/iPhoneOS.platform/Developer/SDKs/$(SDK).sdk/usr/include \
+# -fno-toplevel-reorder -ffreestanding
+#
+LIBOBJS = cellprop.o \
+ debug.o \
+ intprop.o \
+ lib.o \
+ malloc.o \
+ mem.o \
+ printf.o \
+ regprop.o \
+ strings.o \
+ strprop.o \
+ wrappers.o
+
all: libobp.a hello start.o
-libobp.a: lib.o printf.o wrappers.o malloc.o strings.o printf.o debug.o main.o intprop.o regprop.o strprop.o mem.o
- ar rcv libobp.a lib.o malloc.o wrappers.o strings.o printf.o debug.o main.o intprop.o regprop.o strprop.o mem.o
+libobp.a: ${LIBOBJS}
+ ar rcv libobp.a ${LIBOBJS}
ranlib libobp.a
# Build machine-independent library routines
-main.o: ../main.c
- ${CC} ${CFLAGS} -c ../main.c
-
-lib.o: ../lib.c
- ${CC} ${CFLAGS} -c ../lib.c
-
-printf.o: ../printf.c
- ${CC} ${CFLAGS} -c ../printf.c
-
-debug.o: ../debug.c
- ${CC} ${CFLAGS} -c ../debug.c
-
-strings.o: ../strings.c
- ${CC} ${CFLAGS} -c ../strings.c
-
-mem.o: ../mem.c
- ${CC} ${CFLAGS} -c ../mem.c
-
-intprop.o: ../intprop.c
- ${CC} ${CFLAGS} -c ../intprop.c
-
-regprop.o: ../regprop.c
- ${CC} ${CFLAGS} -c ../regprop.c
-
-strprop.o: ../strprop.c
- ${CC} ${CFLAGS} -c ../strprop.c
-
-wrappers.o: ../wrappers.c
- ${CC} ${CFLAGS} -c ../wrappers.c
-
-malloc.o: ../malloc.c
- ${CC} ${CFLAGS} -c ../malloc.c
+%.o: ../%.c
+ ${CC} ${CFLAGS} -c $<
# Build processor-specific startup code and call gateway
start.o: start.c
${CC} ${CFLAGS} -c start.c
+# start.o: start.s
+# ${CC} ${CFLAGS} -c start.s
+
# Hello is a demo program that uses the stdio library
hello: libobp.a start.o hello.o
- ld -Bstatic -oformat elf32-powerpc -T ofclient.lds -Ttext 0x100000 -o hello start.o hello.o -L. -lobp
+ ${CC} ${CFLAGS} -e _start -o hello start.o hello.o -L. -lobp
hello.o: ../../hello/hello.c
${CC} ${CFLAGS} -c ../../hello/hello.c
@@ -75,6 +75,5 @@
clean:
rm -f *~ *.o hello* *.a
-
dist:
(cd ../..; tar cfh /tmp/lib.tar lib/*.c lib/*.h lib/ppcgcc/*.c lib/ppcgcc/*.lds lib/ppcgcc/makefile hello)
Modified: clients/lib/arm/start.c
==============================================================================
--- clients/lib/arm/start.c Tue Mar 27 02:14:21 2012 (r2918)
+++ clients/lib/arm/start.c Tue Mar 27 02:22:52 2012 (r2919)
@@ -13,7 +13,11 @@
extern void OFExit();
void
+#ifdef __GNUC__
_start(void *promptr)
+#else
+start(void *promptr)
+#endif
{
cif_handler = (int (*)()) promptr;
ofw_setup();
Added: clients/lib/cellprop.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ clients/lib/cellprop.c Tue Mar 27 02:22:52 2012 (r2919)
@@ -0,0 +1,66 @@
+// See license at end of file
+
+/* For gcc, compile with -fno-builtin to suppress warnings */
+
+#include "1275.h"
+
+cell_t
+decode_cell(UCHAR *p)
+{
+ int i;
+ cell_t res = 0;
+
+ for (i = 0; i < sizeof(cell_t); i++)
+ res = (res << 8) + p[i];
+ return res;
+}
+
+cell_t
+get_cell_prop(phandle node, char *key)
+{
+ cell_t res;
+ UCHAR buf[sizeof(cell_t)];
+
+ res = OFGetprop(node, key, buf, sizeof(cell_t));
+ if (res != sizeof(cell_t)) {
+ return(-1);
+ }
+ return(decode_cell((UCHAR *) buf));
+}
+
+cell_t
+get_cell_prop_def(phandle node, char *key, cell_t defval)
+{
+ cell_t res;
+ UCHAR buf[sizeof(cell_t)];
+
+ res = OFGetprop(node, key, buf, sizeof(cell_t));
+ if (res != sizeof(cell_t)) {
+ return(defval);
+ }
+ return(decode_cell((UCHAR *) buf));
+}
+
+// LICENSE_BEGIN
+// Copyright (c) 2006 FirmWorks
+//
+// Permission is hereby granted, free of charge, to any person obtaining
+// a copy of this software and associated documentation files (the
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+//
+// LICENSE_END
Modified: clients/lib/debug.c
==============================================================================
--- clients/lib/debug.c Tue Mar 27 02:14:21 2012 (r2918)
+++ clients/lib/debug.c Tue Mar 27 02:22:52 2012 (r2919)
@@ -10,7 +10,7 @@
int Debug = 0;
-VOID
+void
debug(int debug_level, char *fmt, ...)
{
va_list args;
Modified: clients/lib/intprop.c
==============================================================================
--- clients/lib/intprop.c Tue Mar 27 02:14:21 2012 (r2918)
+++ clients/lib/intprop.c Tue Mar 27 02:22:52 2012 (r2919)
@@ -17,7 +17,7 @@
get_int_prop(phandle node, char *key)
{
int res;
- char buf[sizeof(int)];
+ UCHAR buf[sizeof(int)];
res = OFGetprop(node, key, buf, sizeof(int));
if (res != sizeof(int)) {
@@ -34,7 +34,7 @@
get_int_prop_def(phandle node, char *key, int defval)
{
int res;
- char buf[sizeof(int)];
+ UCHAR buf[sizeof(int)];
res = OFGetprop(node, key, buf, sizeof(int));
if (res != sizeof(int)) {
Modified: clients/lib/lib.c
==============================================================================
--- clients/lib/lib.c Tue Mar 27 02:14:21 2012 (r2918)
+++ clients/lib/lib.c Tue Mar 27 02:22:52 2012 (r2919)
@@ -3,13 +3,8 @@
/* For gcc, compile with -fno-builtin to suppress warnings */
#include "1275.h"
-
-extern void *malloc();
-extern char *get_str_prop();
-extern int get_int_prop();
-extern int get_int_prop_def();
-
#include "stdio.h"
+#include "string.h"
FILE _stdin = { -1, 0, 0};
FILE _stdout = { -1, 0, 0};
@@ -30,12 +25,13 @@
OFExit();
}
-VOID
+void
sleep(ULONG delay)
{
- delay = (delay * 1000) + OFMilliseconds();
- while ((OFMilliseconds() - delay) < 0)
- ;
+ ULONG now = OFMilliseconds();
+ delay *= 1000;
+ while ((OFMilliseconds() - now) < delay)
+ ;
}
/* files */
@@ -48,6 +44,7 @@
return(_homedir);
}
+void
parse_homedir(char *progname)
{
char *p, *q, c;
@@ -72,28 +69,31 @@
static char *argv[10];
phandle ph;
char *argstr;
- int i;
+ int i = 0;
+ extern int main(int, char**);
if ((ph = OFFinddevice("/chosen")) == -1)
abort() ;
- stdin->id = get_int_prop(ph, "stdin");
- stdout->id = get_int_prop(ph, "stdout");
+ stdin->id = get_cell_prop(ph, "stdin");
+ stdout->id = get_cell_prop(ph, "stdout");
argv[0] = get_str_prop(ph, "bootpath", ALLOC);
+ if (argv[0] != NULL)
+ parse_homedir(argv[0]);
argstr = get_str_prop(ph, "bootargs", ALLOC);
-
- for (i = 1; i < 10;) {
- if (*argstr == '\0')
- break;
- argv[i++] = argstr;
- while (*argstr != ' ' && *argstr != '\0')
- ++argstr;
- if (*argstr == '\0')
- break;
- *argstr++ = '\0';
+ if (argstr != NULL) {
+ for (i = 1; i < 10;) {
+ if (*argstr == '\0')
+ break;
+ argv[i++] = argstr;
+ while (*argstr != ' ' && *argstr != '\0')
+ ++argstr;
+ if (*argstr == '\0')
+ break;
+ *argstr++ = '\0';
+ }
}
- parse_homedir(argv[0]);
- main(i, argv);
+ return main(i, argv);
}
FILE *
@@ -202,11 +202,11 @@
}
int
-fclose (FILE *fp)
+fclose(FILE *fp)
{
fflush(fp);
OFClose(fp->id);
- free(fp);
+ free((UCHAR *)fp);
return(0);
}
@@ -216,13 +216,22 @@
return(fgetc(stdin));
}
-VOID
-putchar(char c)
+void
+putchar(UCHAR c)
{
fputc(c, stdout);
}
int
+fputs(char *s, FILE *f)
+{
+ char c;
+ while ((c = *s++) != 0)
+ fputc(c, f);
+ return(0);
+}
+
+int
puts(char *s)
{
fputs(s, stdout);
@@ -230,7 +239,7 @@
return(0);
}
-VOID
+void
gets(char *buf)
{
while ((*buf = getchar()) != '\r')
@@ -238,15 +247,6 @@
*buf = '\0';
}
-int
-fputs(char *s, FILE *f)
-{
- register char c;
- while(c = *s++)
- fputc(c, f);
- return(0);
-}
-
char *
fgets(char *buf, int n, FILE *f)
{
@@ -260,23 +260,24 @@
return(buf);
}
+int
unlink(char *filename)
{
return(-1);
/* XXX Implement me */
}
-system(char *str)
+int
+system(const char *str)
{
- OFInterpret0(str);
+ return (int)OFInterpret0(str);
}
#define MAXENV 256
char *
-getenv(char *str)
+getenv(const char *str)
{
phandle ph;
- int res;
if ((ph = OFFinddevice("/options")) == -1)
return(NULL);
Modified: clients/lib/malloc.c
==============================================================================
--- clients/lib/malloc.c Tue Mar 27 02:14:21 2012 (r2918)
+++ clients/lib/malloc.c Tue Mar 27 02:22:52 2012 (r2919)
@@ -28,9 +28,7 @@
#define MALLOC
#include "malloc.h"
-#ifndef NULL
-#define NULL 0
-#endif
+
#ifdef debug
# define ASSERT(p,q) if (!(p)) fatal(q)
#else
@@ -43,16 +41,18 @@
*/
#define PAGE_SIZE (ULONG)0x1000
-#define ULONG unsigned long
-char *
-malloc(nbytes)
- unsigned nbytes;
+static ULONG _log2(ULONG n);
+static void insque(struct qelem *, struct qelem *);
+static void remque(struct qelem *);
+
+void *
+malloc(size_t nbytes)
{
extern ULONG OFClaim();
- register struct overhead *p, *q;
- register int surplus;
- register struct qelem *bucket;
+ struct overhead *p, *q;
+ int surplus;
+ struct qelem *bucket;
nbytes = ALIGN(nbytes, NALIGN) + sizeof(struct overhead);
bucket = &buckets[_log2(nbytes-1) + 1]; /* log2 rounded up */
for (p = NULL; bucket < &buckets[NBUCKETS]; bucket++) {
@@ -68,7 +68,7 @@
}
if (p == NULL) {
#ifdef USE_SBRK
- register int i;
+ int i;
p = (struct overhead *)CURBRK;
if ((int)p == -1)
return(NULL);
@@ -80,7 +80,7 @@
q = (struct overhead *)CURBRK;
if ((int)q == -1)
return(NULL);
- p->ov_length = (char *)q - (char *)p;
+ p->ov_length = (UCHAR *)q - (UCHAR *)p;
surplus = p->ov_length - nbytes;
/* add to end of adjacency chain */
ASSERT((FROMADJ(adjhead.q_back)) < p, "\nmalloc: Entry in \
@@ -110,7 +110,7 @@
}
if (surplus > sizeof(struct overhead)) {
/* if big enough, split it up */
- q = (struct overhead *)( (char *)p + nbytes);
+ q = (struct overhead *)( (UCHAR *)p + nbytes);
q->ov_length = surplus;
p->ov_length = nbytes;
q->ov_magic = MAGIC_FREE;
@@ -120,14 +120,13 @@
insque(TOBUK(q),&buckets[_log2(surplus)]);
}
p->ov_magic = MAGIC_BUSY;
- return((char*)p + sizeof(struct overhead));
+ return((void *)p + sizeof(struct overhead));
}
void
-free(mem)
-register char *mem;
+free(void *mem)
{
- register struct overhead *p, *q;
+ struct overhead *p, *q;
if (mem == NULL)
return;
p = (struct overhead *)(mem - sizeof(struct overhead));
@@ -142,14 +141,14 @@
a lower adjacent free area,\n addresses were found out of order!\n");
/* If lower segment can be merged */
if ( q->ov_magic == MAGIC_FREE
- && (char *)q + q->ov_length == (char *)p
+ && (UCHAR *)q + q->ov_length == (UCHAR *)p
) {
/* remove lower address area from bucket chain */
remque(TOBUK(q));
/* remove upper address area from adjacency chain */
remque(TOADJ(p));
q->ov_length += p->ov_length;
- p->ov_magic = NULL;
+ p->ov_magic = 0;
p = q;
}
}
@@ -159,20 +158,20 @@
ASSERT(q > p, "\nfree: While trying to merge a free area with \
a higher adjacent free area,\n addresses were found out of order!\n");
if ( q->ov_magic == MAGIC_FREE
- && (char *)p + p->ov_length == (char *)q
+ && (UCHAR *)p + p->ov_length == (UCHAR *)q
) {
/* remove upper from bucket chain */
remque(TOBUK(q));
/* remove upper from adjacency chain */
remque(TOADJ(q));
p->ov_length += q->ov_length;
- q->ov_magic = NULL;
+ q->ov_magic = 0;
}
}
#ifdef USE_SBRK
if ( /* freed area is at end of memory */
endfree && adjhead.q_back == TOADJ(p)
- && (char*)p + p->ov_length == (char *)CURBRK
+ && (UCHAR*)p + p->ov_length == (UCHAR *)CURBRK
) {
/* remove from end of adjacency chain */
remque(adjhead.q_back);
@@ -187,16 +186,16 @@
return;
}
-char *
-realloc(mem,nbytes)
-register char *mem; unsigned nbytes;
-{
- register char *newmem;
- register struct overhead *p, *q;
- register int surplus;
+void *
+realloc(void *old, size_t nbytes)
+{
+ UCHAR *mem = (UCHAR *)old;
+ UCHAR *newmem;
+ struct overhead *p, *q;
+ int surplus;
if (mem == NULL)
return(malloc(nbytes));
- if(mem > (char*)FROMADJ(adjhead.q_back) + sizeof(struct overhead))
+ if (mem > (UCHAR *)FROMADJ(adjhead.q_back) + sizeof(struct overhead))
return(NULL);
p = (struct overhead *)(mem - sizeof(struct overhead));
@@ -215,14 +214,14 @@
#ifdef USE_SBRK
if ( /* freed area is at end of memory */
endfree && adjhead.q_back == TOADJ(p)
- && (char*)p + p->ov_length == (char *)CURBRK
+ && (UCHAR*)p + p->ov_length == (UCHAR *)CURBRK
) {
/* release memory to system */
sbrk(-surplus);
} else
#endif
{
- q = (struct overhead *)( (char *)p + nbytes);
+ q = (struct overhead *)( (UCHAR *)p + nbytes);
q->ov_length = surplus;
q->ov_magic = MAGIC_FREE;
insque(TOADJ(q),TOADJ(p));
@@ -238,32 +237,30 @@
}
newmem = malloc(nbytes);
if (newmem != mem && newmem != NULL) {
- register int n;
+ int n;
if (p->ov_magic == MAGIC_BUSY || p->ov_magic == MAGIC_FREE) {
n = p->ov_length - sizeof(struct overhead);
nbytes = (nbytes < n) ? nbytes : n ;
}
- memcpy(newmem,mem,nbytes);
+ memcpy(newmem, mem, nbytes);
}
if (p->ov_magic == MAGIC_BUSY)
free(mem);
return(newmem);
}
-_log2(n)
-register int n;
+static ULONG _log2(ULONG n)
{
- register int i = 0;
+ int i = 0;
while ((n >>= 1) > 0)
i++;
return(i);
}
-void
-insque(item,queu)
-register struct qelem *item, *queu;
+static void
+insque(struct qelem *item, struct qelem *queu)
{
- register struct qelem *pueu;
+ struct qelem *pueu;
pueu = queu->q_forw;
item->q_forw = pueu;
item->q_back = queu;
@@ -271,11 +268,10 @@
pueu->q_back = item;
}
-void
-remque(item)
-register struct qelem *item;
+static void
+remque(struct qelem *item)
{
- register struct qelem *queu, *pueu;
+ struct qelem *queu, *pueu;
pueu = item->q_forw;
queu = item->q_back;
queu->q_forw = pueu;
Modified: clients/lib/malloc.h
==============================================================================
--- clients/lib/malloc.h Tue Mar 27 02:14:21 2012 (r2918)
+++ clients/lib/malloc.h Tue Mar 27 02:22:52 2012 (r2919)
@@ -4,6 +4,8 @@
* A "smarter" malloc William L. Sebok
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
+#include "1275.h"
+
#define MAGIC_FREE 0x548a934c
#define MAGIC_BUSY 0xc139569a
@@ -26,30 +28,30 @@
char endfree = 0;
struct qelem adjhead = { &adjhead, &adjhead };
struct qelem buckets[NBUCKETS] = {
- &buckets[0], &buckets[0],
- &buckets[1], &buckets[1],
- &buckets[2], &buckets[2],
- &buckets[3], &buckets[3],
- &buckets[4], &buckets[4],
- &buckets[5], &buckets[5],
- &buckets[6], &buckets[6],
- &buckets[7], &buckets[7],
- &buckets[8], &buckets[8],
- &buckets[9], &buckets[9],
- &buckets[10], &buckets[10],
- &buckets[11], &buckets[11],
- &buckets[12], &buckets[12],
- &buckets[13], &buckets[13],
- &buckets[14], &buckets[14],
- &buckets[15], &buckets[15],
- &buckets[16], &buckets[16],
- &buckets[17], &buckets[17],
- &buckets[18], &buckets[18],
- &buckets[19], &buckets[19],
- &buckets[20], &buckets[20],
- &buckets[21], &buckets[21],
- &buckets[22], &buckets[22],
- &buckets[23], &buckets[23],
+ { &buckets[0], &buckets[0] },
+ { &buckets[1], &buckets[1] },
+ { &buckets[2], &buckets[2] },
+ { &buckets[3], &buckets[3] },
+ { &buckets[4], &buckets[4] },
+ { &buckets[5], &buckets[5] },
+ { &buckets[6], &buckets[6] },
+ { &buckets[7], &buckets[7] },
+ { &buckets[8], &buckets[8] },
+ { &buckets[9], &buckets[9] },
+ { &buckets[10], &buckets[10] },
+ { &buckets[11], &buckets[11] },
+ { &buckets[12], &buckets[12] },
+ { &buckets[13], &buckets[13] },
+ { &buckets[14], &buckets[14] },
+ { &buckets[15], &buckets[15] },
+ { &buckets[16], &buckets[16] },
+ { &buckets[17], &buckets[17] },
+ { &buckets[18], &buckets[18] },
+ { &buckets[19], &buckets[19] },
+ { &buckets[20], &buckets[20] },
+ { &buckets[21], &buckets[21] },
+ { &buckets[22], &buckets[22] },
+ { &buckets[23], &buckets[23] },
};
#else
extern char endfree;
@@ -68,9 +70,6 @@
#define CURBRK sbrk(0)
#endif
-extern void insque(), remque();
-extern char *malloc(), *realloc();
-
// LICENSE_BEGIN
// Copyright (c) 2006 FirmWorks
//
Modified: clients/lib/mem.c
==============================================================================
--- clients/lib/mem.c Tue Mar 27 02:14:21 2012 (r2918)
+++ clients/lib/mem.c Tue Mar 27 02:22:52 2012 (r2919)
@@ -2,26 +2,26 @@
#include "1275.h"
-VOID
-memcpy(char *to, char *from, int len)
+void
+memcpy(void *to, void *from, size_t len)
{
- while (len--)
- *to++ = *from++;
+ while (len-- > 0)
+ *(UCHAR *)to++ = *(UCHAR *)from++;
}
-VOID
-memset(char *cp, int c, int len)
+void
+memset(void *cp, int c, size_t len)
{
- while (len--)
- *(cp + len) = c;
+ while (len-- > 0)
+ *((UCHAR *)cp + len) = c;
}
int
-memcmp(const void *s1, const void *s2, int n)
+memcmp(const void *s1, const void *s2, size_t n)
{
int diff;
- while (n--) {
- diff = *(unsigned char *)s1++ - *(unsigned char *)s2++;
+ while (n-- > 0) {
+ diff = *(UCHAR *)s1++ - *(UCHAR *)s2++;
if (diff)
return (diff < 0) ? -1 : 1;
}
Modified: clients/lib/printf.c
==============================================================================
--- clients/lib/printf.c Tue Mar 27 02:14:21 2012 (r2918)
+++ clients/lib/printf.c Tue Mar 27 02:22:52 2012 (r2919)
@@ -16,7 +16,7 @@
int digit;
const char *send = s+len;
- if (s != send && *s == '+' || *s == '-') {
+ if (s != send && (*s == '+' || *s == '-')) {
minus = *s == '-';
s++;
}
@@ -69,7 +69,7 @@
return (int)strtol(s, NULL, 10);
}
-STATIC int
+static int
printbase(ULONG x, int base, int fieldlen, char padchar, int upcase)
{
static char lc_digits[] = "0123456789abcdef";
@@ -80,7 +80,7 @@
memset(buf, 32, 0);
- if (base == 10 && (LONG) x < 0) {
+ if (base == 10 && (long) x < 0) {
*s++ = '-';
x = -x;
}
@@ -92,7 +92,6 @@
x /= base;
} while (x);
-cvtdone:
for (fieldlen -= (s-buf); fieldlen > 0; --fieldlen) {
putchar(padchar);
n++;
@@ -116,7 +115,7 @@
unsigned long mask;
char padchar;
- while (c = *fmt++) {
+ while ((c = *fmt++)) {
if (c != '%') {
putchar(c);
n++;
@@ -149,7 +148,7 @@
goto out;
}
while (c == 'h') { // Mask for short modifier
- if (mask = 0xffff)
+ if (mask == 0xffff)
mask = 0xff;
else
mask = 0xffff;
@@ -209,7 +208,7 @@
return (i);
}
-VOID
+void
warn(char *fmt, ...)
{
va_list args;
@@ -219,7 +218,7 @@
va_end(args);
}
-VOID
+void
fatal(char *fmt, ...)
{
va_list args;
Modified: clients/lib/regprop.c
==============================================================================
--- clients/lib/regprop.c Tue Mar 27 02:14:21 2012 (r2918)
+++ clients/lib/regprop.c Tue Mar 27 02:22:52 2012 (r2919)
@@ -9,7 +9,6 @@
{
static reg staticreg;
reg *sregp;
- int i;
if (buflen)
staticreg.hi = decode_int(buf);
@@ -24,11 +23,11 @@
get_reg_prop(phandle node, char *key)
{
int res;
- char *buf;
+ UCHAR *buf;
reg *regp;
int len = OFGetproplen(node, key);
- buf = (char *)malloc(len);
+ buf = (UCHAR *)malloc(len);
res = OFGetprop(node, key, buf, len);
if (res != len) {
fatal("get_reg_prop(node %x, key '%s', len %x) returned %x\n",
Added: clients/lib/string.h
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ clients/lib/string.h Tue Mar 27 02:22:52 2012 (r2919)
@@ -0,0 +1,18 @@
+#define ISUPPER(c) ((c) >= 'A' && (c) <= 'Z')
+#define TOLOWER(c) ((c) - 'A' + 'a')
+
+int strcmp(const char *s, const char *t);
+int strncmp(const char *s, const char *t, size_t len);
+int strcasecmp(const char *s, const char *t);
+int strncasecmp(const char *s, const char *t, size_t len);
+int strlen(const char *s);
+int strnlen(const char *s, size_t maxlen);
+char *strcpy(char *to, const char *from);
+char *strncpy(char *to, const char *from, size_t maxlen);
+char *strcat(char *to, const char *from);
+char *strchr(char *s, int c);
+char *strctok(char *s, const char sep);
+char *strstr(const char *haystack, const char *needle);
+char *strcasestr(const char *haystack, const char *needle);
+const void *memchr(const void *s, int c, size_t len);
+int toupper(int c);
Modified: clients/lib/strings.c
==============================================================================
--- clients/lib/strings.c Tue Mar 27 02:14:21 2012 (r2918)
+++ clients/lib/strings.c Tue Mar 27 02:22:52 2012 (r2919)
@@ -3,9 +3,7 @@
/* For gcc, compile with -fno-builtin to suppress warnings */
#include "1275.h"
-
-#define ISUPPER(c) ((c) >= 'A' && (c) <= 'Z')
-#define TOLOWER(c) ((c) + 'a' - 'A')
+#include "string.h"
int
strcmp(const char *s, const char *t)
@@ -22,7 +20,7 @@
}
int
-strncmp(const char *s, const char *t, int len)
+strncmp(const char *s, const char *t, size_t len)
{
int diff = 0;
int i;
@@ -58,7 +56,7 @@
}
int
-strncasecmp(const char *s, const char *t, int len)
+strncasecmp(const char *s, const char *t, size_t len)
{
char sc, tc;
int diff = 0;
@@ -89,7 +87,7 @@
}
int
-strnlen(const char *s, int maxlen)
+strnlen(const char *s, size_t maxlen)
{
int i;
@@ -103,13 +101,13 @@
{
int i = 0;
- while (to[i] = from[i])
+ while ((to[i] = from[i]))
i += 1;
return to;
}
char *
-strncpy(char *to, const char *from, int maxlen)
+strncpy(char *to, const char *from, size_t maxlen)
{
int i = 0;
@@ -190,7 +188,7 @@
return NULL;
}
-const void *memchr(const void *s, int c, int len)
+const void *memchr(const void *s, int c, size_t len)
{
const unsigned char *p = s;
while (len--) {
Modified: clients/lib/strprop.c
==============================================================================
--- clients/lib/strprop.c Tue Mar 27 02:14:21 2012 (r2918)
+++ clients/lib/strprop.c Tue Mar 27 02:22:52 2012 (r2919)
@@ -4,33 +4,34 @@
#include "1275.h"
-extern void *malloc();
-VOID *
-zalloc(int size)
+void *
+zalloc(size_t size)
{
- VOID *vp;
+ void *vp;
- vp = (void *)malloc(size);
+ vp = malloc(size);
memset(vp, size, 0);
return (vp);
}
char *
-get_str_prop(phandle node, char *key, allocflag alloc)
+get_str_prop(phandle node, const char *key, allocflag alloc)
{
- int len, res;
- static char *priv_buf, priv_buf_len = 0;
+ ULONG len;
+ int res;
+ static char *priv_buf;
+ static ULONG priv_buf_len = 0;
char *cp;
len = OFGetproplen(node, key);
- if (len == -1 || len == 0)
- return((char *) 0);
-
/*
- * Leave room for a null terminator, on the off chance that the
- * property isn't null-terminated.
+ * Properly encoded properties have a null terminator,
+ * so if len == 1 we have a null string.
*/
- len += 1;
+ if (len == -1 || len == 0 || len == 1) {
+ return((char *) 0);
+ }
+
if (alloc == ALLOC)
cp = (char *) zalloc(len);
else {
@@ -40,12 +41,11 @@
priv_buf = (char *) zalloc(len);
priv_buf_len = len;
} else
- memset(priv_buf, len, 0);
+ memset((void *)priv_buf, len, 0);
cp = priv_buf;
}
- len -= 1;
- res = OFGetprop(node, key, cp, len);
+ res = OFGetprop(node, key, (UCHAR *)cp, len);
if (res != len) {
fatal(
"get_str_prop(node %x, key '%s', len %x) returned len %x\n",
Modified: clients/lib/wrappers.c
==============================================================================
--- clients/lib/wrappers.c Tue Mar 27 02:14:21 2012 (r2918)
+++ clients/lib/wrappers.c Tue Mar 27 02:22:52 2012 (r2919)
@@ -53,11 +53,7 @@
phandle
OFPeer(phandle device_id)
{
-#ifdef CIF64
- ULONG argarray[] = { 0,(ULONG)"peer", 0,1, 0,1, 0,0, 0,0};
-#else
cell_t argarray[] = { (cell_t)"peer",1,1,0,0};
-#endif
argarray[CIF_HANDLER_IN+LOW(0)] = device_id;
if (call_firmware(argarray) != 0)
{
@@ -69,11 +65,7 @@
phandle
OFChild(phandle device_id)
{
-#ifdef CIF64
- ULONG argarray[] = { 0,(ULONG)"child", 0,1, 0,1, 0,0, 0,0};
-#else
cell_t argarray[] = { (cell_t)"child",1,1,0,0};
-#endif
argarray[CIF_HANDLER_IN+LOW(0)] = device_id;
if (call_firmware(argarray) != 0)
{
@@ -85,11 +77,7 @@
phandle
OFParent(phandle device_id)
{
-#ifdef CIF64
- ULONG argarray[] = { 0,(ULONG)"parent", 0,1, 0,1, 0,0, 0,0};
-#else
cell_t argarray[] = { (cell_t)"parent", 1,1,0,0};
-#endif
argarray[CIF_HANDLER_IN+LOW(0)] = device_id;
if (call_firmware(argarray) != 0)
{
@@ -101,14 +89,10 @@
long
OFGetproplen(
phandle device_id,
- char *name
+ const char *name
)
{
-#ifdef CIF64
- ULONG argarray[] = { 0,(ULONG)"getproplen", 0,2, 0,1, 0,0, 0,0, 0,0};
-#else
cell_t argarray[] = { (cell_t)"getproplen", 2,1,0,0,0};
-#endif
argarray[CIF_HANDLER_IN+LOW(0)] = (long)device_id;
argarray[CIF_HANDLER_IN+LOW(1)] = (long)name;
if (call_firmware(argarray) != 0)
@@ -121,16 +105,12 @@
long
OFGetprop(
phandle device_id,
- char *name,
- char *buf,
+ const char *name,
+ UCHAR *buf,
ULONG buflen
)
{
-#ifdef CIF64
- ULONG argarray[] = { 0,(ULONG)"getprop", 0,4, 0,1, 0,0, 0,0, 0,0, 0,0, 0,0};
-#else
cell_t argarray[] = { (cell_t)"getprop", 4,1,0,0,0,0,0};
-#endif
argarray[CIF_HANDLER_IN+LOW(0)] = (long)device_id;
argarray[CIF_HANDLER_IN+LOW(1)] = (long)name;
argarray[CIF_HANDLER_IN+LOW(2)] = (long)buf;
@@ -145,15 +125,11 @@
long
OFNextprop(
phandle device_id,
- char *name,
- char *buf
+ const char *name,
+ UCHAR *buf
)
{
-#ifdef CIF64
- ULONG argarray[] = { 0,(ULONG)"nextprop", 0,3, 0,1, 0,0, 0,0, 0,0, 0,0};
-#else
cell_t argarray[] = { (cell_t)"nextprop", 3,1,0,0,0,0};
-#endif
argarray[CIF_HANDLER_IN+LOW(0)] = (long)device_id;
argarray[CIF_HANDLER_IN+LOW(1)] = (long)name;
argarray[CIF_HANDLER_IN+LOW(2)] = (long)buf;
@@ -167,16 +143,12 @@
long
OFSetprop(
phandle device_id,
- char *name,
- char *buf,
+ const char *name,
+ UCHAR *buf,
ULONG buflen
)
{
-#ifdef CIF64
- ULONG argarray[] = { 0,(ULONG)"setprop", 0,4, 0,1, 0,0, 0,0, 0,0, 0,0, 0,0};
-#else
cell_t argarray[] = { (cell_t)"setprop", 4,1,0,0,0,0,0};
-#endif
argarray[CIF_HANDLER_IN+LOW(0)] = (long)device_id;
argarray[CIF_HANDLER_IN+LOW(1)] = (long)name;
argarray[CIF_HANDLER_IN+LOW(2)] = (long)buf;
@@ -191,11 +163,7 @@
phandle
OFFinddevice( char *devicename)
{
-#ifdef CIF64
- ULONG argarray[] = { 0,(ULONG)"finddevice", 0,1, 0,1, 0,0, 0,0};
-#else
cell_t argarray[] = { (cell_t)"finddevice", 1,1,0,0};
-#endif
argarray[CIF_HANDLER_IN+LOW(0)] = (long)devicename;
if (call_firmware(argarray) != 0)
@@ -208,11 +176,7 @@
ihandle
OFOpen( char *devicename)
{
-#ifdef CIF64
- ULONG argarray[] = { 0,(ULONG)"open", 0,1, 0,1, 0,0, 0,0};
-#else
cell_t argarray[] = { (cell_t)"open", 1,1,0,0};
-#endif
argarray[CIF_HANDLER_IN+LOW(0)] = (long)devicename;
if (call_firmware(argarray) != 0)
@@ -226,11 +190,7 @@
ihandle
OFCreate( char *devicename)
{
-#ifdef CIF64
- ULONG argarray[] = { 0,(ULONG)"firmworks,create", 0,1, 0,1, 0,0, 0,0};
-#else
cell_t argarray[] = { (cell_t)"firmworks,create", 1,1,0,0};
-#endif
argarray[CIF_HANDLER_IN+LOW(0)] = (long)devicename;
if (call_firmware(argarray) != 0)
@@ -243,11 +203,7 @@
void
OFClose(ihandle id)
{
-#ifdef CIF64
- ULONG argarray[] = { 0,(ULONG)"close", 0,1, 0,1, 0,0, 0,0};
-#else
cell_t argarray[] = { (cell_t)"close", 1,1,0,0};
-#endif
argarray[CIF_HANDLER_IN+LOW(0)] = (long)id;
if (call_firmware(argarray) != 0)
{
@@ -261,15 +217,11 @@
long
OFRead(
ihandle instance_id,
- char *addr,
+ UCHAR *addr,
ULONG len
)
{
-#ifdef CIF64
- ULONG argarray[] = { 0,(ULONG)"read", 0,3, 0,1, 0,0, 0,0, 0,0, 0,0};
-#else
cell_t argarray[] = { (cell_t)"read", 3,1,0,0,0,0};
-#endif
argarray[CIF_HANDLER_IN+LOW(0)] = (long) instance_id;
argarray[CIF_HANDLER_IN+LOW(1)] = (cell_t)addr;
@@ -284,15 +236,11 @@
long
OFWrite(
ihandle instance_id,
- char *addr,
+ UCHAR *addr,
ULONG len
)
{
-#ifdef CIF64
- ULONG argarray[] = { 0,(ULONG)"write", 0,3, 0,1, 0,0, 0,0, 0,0, 0,0};
-#else
cell_t argarray[] = { (cell_t)"write", 3,1,0,0,0,0};
-#endif
argarray[CIF_HANDLER_IN+LOW(0)] = (long) instance_id;
argarray[CIF_HANDLER_IN+LOW(1)] = (cell_t)addr;
@@ -311,11 +259,7 @@
ULONG poslo
)
{
-#ifdef CIF64
- ULONG argarray[] = { 0,(ULONG)"seek", 0,3, 0,1, 0,0, 0,0, 0,0, 0,0};
-#else
cell_t argarray[] = { (cell_t)"seek", 3,1,0,0,0,0};
-#endif
argarray[CIF_HANDLER_IN+LOW(0)] = (long) instance_id;
argarray[CIF_HANDLER_IN+LOW(1)] = poshi;
@@ -328,16 +272,12 @@
ULONG
OFClaim(
- char *addr,
+ UCHAR *addr,
ULONG size,
ULONG align
)
{
-#ifdef CIF64
- ULONG argarray[] = { 0,(ULONG)"claim", 0,3, 0,1, 0,0, 0,0, 0,0, 0,0};
-#else
cell_t argarray[] = { (cell_t)"claim", 3,1,0,0,0,0};
-#endif
argarray[CIF_HANDLER_IN+LOW(0)] = (cell_t)addr;
argarray[CIF_HANDLER_IN+LOW(1)] = size;
@@ -349,17 +289,13 @@
return (argarray[CIF_HANDLER_IN+LOW(3)]);
}
-VOID
+void
OFRelease(
- char *addr,
+ UCHAR *addr,
ULONG size
)
{
-#ifdef CIF64
- ULONG argarray[] = { 0,(ULONG)"release", 0,2, 0,0, 0,0, 0,0};
-#else
cell_t argarray[] = { (cell_t)"release", 2,0,0,0};
-#endif
argarray[CIF_HANDLER_IN+LOW(0)] = (cell_t)addr;
argarray[CIF_HANDLER_IN+LOW(1)] = size;
call_firmware(argarray);
@@ -368,15 +304,11 @@
long
OFPackageToPath(
phandle device_id,
- char *addr,
+ UCHAR *addr,
ULONG buflen
)
{
-#ifdef CIF64
- ULONG argarray[] = { 0,(ULONG)"package-to-path", 0,3, 0,1, 0,0, 0,0, 0,0, 0,0};
-#else
cell_t argarray[] = { (cell_t)"package-to-path", 3,1,0,0,0,0};
-#endif
argarray[CIF_HANDLER_IN+LOW(0)] = (cell_t)device_id;
argarray[CIF_HANDLER_IN+LOW(1)] = (cell_t)addr;
@@ -385,24 +317,20 @@
{
return (-1);
}
- return ((LONG)argarray[CIF_HANDLER_IN+LOW(3)]);
+ return ((ULONG)argarray[CIF_HANDLER_IN+LOW(3)]);
}
phandle
OFInstanceToPackage(ihandle ih)
{
-#ifdef CIF64
- ULONG argarray[] = { 0,(ULONG)"instance-to-package", 0,1, 0,1, 0,0, 0,0};
-#else
cell_t argarray[] = { (cell_t)"instance-to-package", 1,1,0,0};
-#endif
argarray[CIF_HANDLER_IN+LOW(0)] = (cell_t)ih;
if (call_firmware(argarray) != 0)
{
return (-1);
}
- return ((LONG)argarray[CIF_HANDLER_IN+LOW(1)]);
+ return ((ULONG)argarray[CIF_HANDLER_IN+LOW(1)]);
}
long
@@ -412,11 +340,7 @@
ULONG arg
)
{
-#ifdef CIF64
- ULONG argarray[] = { 0,(ULONG)"call-method", 0,3, 0,1, 0,0, 0,0, 0,0, 0,0};
-#else
cell_t argarray[] = { (cell_t)"call-method", 3,1,0,0,0,0};
-#endif
argarray[CIF_HANDLER_IN+LOW(0)] = (cell_t)method;
argarray[CIF_HANDLER_IN+LOW(1)] = (cell_t)id;
@@ -425,7 +349,7 @@
{
return (-1);
}
- return ((LONG)argarray[CIF_HANDLER_IN+LOW(3)]);
+ return ((ULONG)argarray[CIF_HANDLER_IN+LOW(3)]);
}
#include <stdarg.h>
@@ -440,16 +364,11 @@
...
)
{
-#ifdef CIF64
- ULONG argarray[(MAXARGS+6)*2] = { 0 };
-#else
cell_t argarray[MAXARGS+6] = { 0 };
-#endif
va_list ap;
int retval;
int *intp;
int argnum = 0;
- unsigned long flags;
argarray[LOW(argnum++)] = (cell_t)"call-method";
argarray[LOW(argnum++)] = (cell_t)numargs+2;
@@ -480,21 +399,17 @@
long
OFInterpret0(
- char *cmd
+ const char *cmd
)
{
-#ifdef CIF64
- ULONG argarray[] = { 0,(ULONG)"interpret", 0,1, 0,1, 0,0, 0,0};
-#else
cell_t argarray[] = { (cell_t)"interpret", 1,1,0,0};
-#endif
argarray[CIF_HANDLER_IN+LOW(0)] = (cell_t)cmd;
if (call_firmware(argarray) != 0)
{
return (-1);
}
- return ((LONG)argarray[CIF_HANDLER_IN+LOW(1)]);
+ return ((ULONG)argarray[CIF_HANDLER_IN+LOW(1)]);
}
long
@@ -505,16 +420,11 @@
...
)
{
-#ifdef CIF64
- ULONG argarray[(MAXARGS+5)*2] = { 0 };
-#else
cell_t argarray[MAXARGS+5] = { 0 };
-#endif
va_list ap;
int retval;
int *intp;
int argnum = 0;
- unsigned long flags;
argarray[LOW(argnum++)] = (cell_t)"interpret";
argarray[LOW(argnum++)] = (cell_t)numargs+1;
@@ -544,13 +454,9 @@
ULONG
-OFMilliseconds( VOID )
+OFMilliseconds( void )
{
-#ifdef CIF64
- ULONG argarray[] = { 0,(ULONG)"milliseconds", 0,0, 0,1, 0,0};
-#else
cell_t argarray[] = { (cell_t)"milliseconds", 0,1,0};
-#endif
if (call_firmware(argarray) != 0)
{
return (ULONG)0;
@@ -560,11 +466,7 @@
void (*OFSetCallback(void (*func)(void)))(void)
{
-#ifdef CIF64
- ULONG argarray[] = { 0,(ULONG)"set-callback", 0,1, 0,1, 0,0, 0,0};
-#else
cell_t argarray[] = { (cell_t)"set-callback", 1,1,0,0};
-#endif
argarray[CIF_HANDLER_IN+LOW(0)] = (cell_t)func;
if (call_firmware(argarray) != 0)
@@ -574,43 +476,32 @@
return ((void (*)(void))argarray[CIF_HANDLER_IN+LOW(1)]);
}
-long
+void
OFBoot(
char *bootspec
)
{
-#ifdef CIF64
- ULONG argarray[] = { 0,(ULONG)"boot", 0,1, 0,0, 0,0};
-#else
cell_t argarray[] = { (cell_t)"boot", 1,0,0};
-#endif
argarray[CIF_HANDLER_IN+LOW(0)] = (cell_t)bootspec;
call_firmware(argarray);
}
-VOID
-OFEnter( VOID )
+void
+OFEnter( void )
{
-#ifdef CIF64
- ULONG argarray[] = { 0,(ULONG)"enter", 0,0, 0,0};
-#else
cell_t argarray[] = { (cell_t)"enter", 0,0};
-#endif
call_firmware(argarray);
}
-/* volatile VOID */
- VOID
-OFExit( VOID )
-{
-#ifdef CIF64
- ULONG argarray[] = { 0,(ULONG)"exit", 0,0, 0,0};
-#else
+/* volatile void */
+ void
+OFExit( void )
+{
cell_t argarray[] = { (cell_t)"exit", 0,0};
-#endif
call_firmware(argarray);
+ while (1);
}
// LICENSE_BEGIN
Modified: clients/lib/x86/makefile
==============================================================================
--- clients/lib/x86/makefile Tue Mar 27 02:14:21 2012 (r2918)
+++ clients/lib/x86/makefile Tue Mar 27 02:22:52 2012 (r2919)
@@ -1,15 +1,27 @@
-# This makefile has been tested on a FreeBSD 2.2.5 system with GCC
+# This makefile has been tested on OS X 10.6 with GCC
-# -fno-builtin has the effect of suppressing some warnings about
-# functions that conflict with gcc builtins
CC=gcc
-CFLAGS=-g -m32 -fno-builtin -fno-stack-limit -fno-stack-protector
+#CFLAGS=-g -m32 -fno-builtin -fno-stack-limit -fno-stack-protector
+CFLAGS=-g -m32 -nostdlib -nostartfiles -fno-builtin -ffreestanding -fno-stack-protector -I..
+LFLAGS=-L.
-all: libobp.a hello hello.elf start.o
+#all: libobp.a hello hello.elf start.o
+all: libobp.a hello start.o
# Create a library file containing all the library routines
-OBJS=lib.o printf.o wrappers.o malloc.o strings.o printf.o debug.o main.o intprop.o regprop.o strprop.o mem.o callofw.o
+OBJS= callofw.o \
+ cellprop.o \
+ debug.o \
+ intprop.o \
+ lib.o \
+ malloc.o \
+ mem.o \
+ printf.o \
+ regprop.o \
+ strings.o \
+ strprop.o \
+ wrappers.o
libobp.a: ${OBJS}
ar rcv libobp.a ${OBJS}
@@ -22,21 +34,21 @@
# Build processor-specific startup code and call gateway
-start.o: start.s
- ${CC} ${CFLAGS} -c start.s
+start.o: start.S
+ ${CC} ${CFLAGS} -c start.S
# Hello is a demo program that uses the stdio library
-hello.elf: libobp.a start.o hello.o
- ld -melf_i386 -Bstatic -N -Ttext 0x100000 -o $@ start.o hello.o libobp.a -lc
- cp hello.elf hello.syms
- strip hello.elf
+#hello.elf: libobp.a start.o hello.o
+# ld -melf_i386 -Bstatic -N -Ttext 0x100000 -o $@ start.o hello.o libobp.a -lc
+# cp hello.elf hello.syms
+# strip hello.elf
hello.o: ../../hello/hello.c
${CC} ${CFLAGS} -c ../../hello/hello.c
-hello: hello.o
- ${CC} -m32 $< -o $@
+hello: start.o hello.o libobp.a
+ ${CC} ${CFLAGS} ${LFLAGS} start.o hello.o -o $@ -lobp
# Binary to ELF converter program
Added: clients/lib/x86/start.S
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ clients/lib/x86/start.S Tue Mar 27 02:22:52 2012 (r2919)
@@ -0,0 +1,88 @@
+# See license at end of file
+
+ .file "start.s"
+.data
+ .align 2
+#ifdef __GNUC__
+ .type _cifentry, at object
+ .size _cifentry,4
+#endif
+_cifentry:
+ .long 0
+
+LEB0:
+ .ascii "exit\0"
+
+#ifdef __GNUC__
+ .type _exitblock, at object
+ .size _exitblock,12
+#endif
+_exitblock:
+ .long LEB0
+ .long 0
+ .long 0
+
+.text
+ .align 2
+#ifdef __GNUC__
+ .globl _start
+_start:
+#else
+ .globl start
+start:
+#endif
+# pushl %ebp
+# movl %esp,%ebp
+ movl %eax,_cifentry
+
+#ifdef __GNUC__
+ call ofw_setup
+#else
+ call _ofw_setup
+#endif
+ lea _exitblock, %eax
+ movl _cifentry,%ebx
+ call *%ebx
+# jmp L1
+# .align 2,0x90
+#L1:
+# leave
+ ret
+
+#ifdef __GNUC__
+ .globl call_firmware
+call_firmware:
+#else
+ .globl _call_firmware
+_call_firmware:
+#endif
+ movl 4(%esp),%eax
+ push %ebx
+ movl _cifentry,%ebx
+ call *%ebx
+ pop %ebx
+ ret
+
+# LICENSE_BEGIN
+# Copyright (c) 2006 FirmWorks
+#
+# Permission is hereby granted, free of charge, to any person obtaining
+# a copy of this software and associated documentation files (the
+# "Software"), to deal in the Software without restriction, including
+# without limitation the rights to use, copy, modify, merge, publish,
+# distribute, sublicense, and/or sell copies of the Software, and to
+# permit persons to whom the Software is furnished to do so, subject to
+# the following conditions:
+#
+# The above copyright notice and this permission notice shall be
+# included in all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+#
+# LICENSE_END
Modified: clients/lib/x86/start.s
==============================================================================
--- clients/lib/x86/start.s Tue Mar 27 02:14:21 2012 (r2918)
+++ clients/lib/x86/start.s Tue Mar 27 02:22:52 2012 (r2919)
@@ -1,54 +1,75 @@
+# 1 "../../../clients/lib/x86/start.S"
+# 1 "<built-in>"
+# 1 "<command-line>"
+# 1 "../../../clients/lib/x86/start.S"
# See license at end of file
- .file "start.s"
+ .file "start.s"
.data
- .align 2
- .type _cifentry, at object
- .size _cifentry,4
+ .align 2
+
+ .type _cifentry, at object
+ .size _cifentry,4
+
_cifentry:
- .long 0
+ .long 0
LEB0:
- .ascii "exit\0"
+ .ascii "exit\0"
+
+
+ .type _exitblock, at object
+ .size _exitblock,12
- .type _exitblock, at object
- .size _exitblock,12
_exitblock:
- .long LEB0
- .long 0
- .long 0
+ .long LEB0
+ .long 0
+ .long 0
.text
- .align 2
-.globl _start
- .type _start, at function
+ .align 2
+
+ .globl _start
_start:
-# pushl %ebp
-# movl %esp,%ebp
- movl %eax,_cifentry
- call ofw_setup
- lea _exitblock, %eax
- movl _cifentry,%ebx
- call *%ebx
-# jmp L1
-# .align 2,0x90
+
+
+
+
+# pushl %ebp
+# movl %esp,%ebp
+ movl %eax,_cifentry
+
+
+ call ofw_setup
+
+
+
+ lea _exitblock, %eax
+ movl _cifentry,%ebx
+ call *%ebx
+# jmp L1
+# .align 2,0x90
#L1:
-# leave
- ret
+# leave
+ ret
+
-.globl call_firmware
- .type call_firmware, at function
+ .globl call_firmware
call_firmware:
- movl 4(%esp),%eax
- push %ebx
- movl _cifentry,%ebx
- call *%ebx
- pop %ebx
- ret
+
+
+
+
+ movl 4(%esp),%eax
+ push %ebx
+ movl _cifentry,%ebx
+ call *%ebx
+ pop %ebx
+ ret
# LICENSE_BEGIN
# Copyright (c) 2006 FirmWorks
-#
+
# Permission is hereby granted, free of charge, to any person obtaining
# a copy of this software and associated documentation files (the
# "Software"), to deal in the Software without restriction, including
@@ -56,10 +77,10 @@
# distribute, sublicense, and/or sell copies of the Software, and to
# permit persons to whom the Software is furnished to do so, subject to
# the following conditions:
-#
+
# The above copyright notice and this permission notice shall be
# included in all copies or substantial portions of the Software.
-#
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
@@ -67,5 +88,5 @@
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
-#
+
# LICENSE_END
More information about the openfirmware
mailing list