Author: wmb Date: 2008-09-30 22:15:44 +0200 (Tue, 30 Sep 2008) New Revision: 947
Modified: clients/lib/1275.h clients/lib/lib.c clients/lib/printf.c clients/lib/stdio.h clients/lib/wrappers.c Log: Client library improvments in support of the multicast NAND updater.
Modified: clients/lib/1275.h =================================================================== --- clients/lib/1275.h 2008-09-26 01:02:15 UTC (rev 946) +++ clients/lib/1275.h 2008-09-30 20:15:44 UTC (rev 947) @@ -24,6 +24,60 @@
#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, ...); + +#ifdef CIF64 +#define CIF_HANDLER_IN 6 +#else +#define CIF_HANDLER_IN 3 +#endif + +extern int call_firmware(ULONG *); +extern void warn(char *fmt, ...); +int atoi(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); +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 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); +phandle OFInstanceToPackage(ihandle ih); +long OFCallMethod(char *method, ihandle id, ULONG arg); +long OFInterpret0(char *cmd); +ULONG OFMilliseconds(VOID); +void (*OFSetCallback(void (*func)(void)))(void); +long OFBoot(char *bootspec); +VOID OFEnter(VOID); +VOID OFExit(VOID); +long OFCallMethodV(char *method, ihandle id, int nargs, int nrets, ...); +long OFInterpretV(char *cmd, int nargs, int nrets, ...); + // LICENSE_BEGIN // Copyright (c) 2006 FirmWorks //
Modified: clients/lib/lib.c =================================================================== --- clients/lib/lib.c 2008-09-26 01:02:15 UTC (rev 946) +++ clients/lib/lib.c 2008-09-30 20:15:44 UTC (rev 947) @@ -9,15 +9,24 @@ extern int get_int_prop(); extern int get_int_prop_def();
+#include "stdio.h" + +FILE _stdin = { -1, 0, 0}; +FILE _stdout = { -1, 0, 0}; +FILE *stdin = &_stdin; +FILE *stdout = &_stdout; + void abort() { + fflush(stdout); OFExit(); }
void -exit() +exit(int code) { + fflush(stdout); OFExit(); }
@@ -31,13 +40,6 @@
/* files */
-#include "stdio.h" - -FILE _stdin = { -1, 0, 0}; -FILE _stdout = { -1, 0, 0}; -FILE *stdin = &_stdin; -FILE *stdout = &_stdout; - char _homedir[128];
char *
Modified: clients/lib/printf.c =================================================================== --- clients/lib/printf.c 2008-09-26 01:02:15 UTC (rev 946) +++ clients/lib/printf.c 2008-09-30 20:15:44 UTC (rev 947) @@ -83,6 +83,7 @@ char c, *s; int n = 0; int fieldlen; + unsigned long mask; char padchar;
while (c = *fmt++) { @@ -91,6 +92,7 @@ n++; continue; } + mask = 0xffffffff; if ((c = *fmt++) == '\0') goto out; @@ -112,21 +114,34 @@ goto out; }
+ if (c == 'l') { // Ignore "long" modifier + if ((c = *fmt++) == '\0') + goto out; + } + while (c == 'h') { // Mask for short modifier + if (mask = 0xffff) + mask = 0xff; + else + mask = 0xffff; + if ((c = *fmt++) == '\0') + goto out; + } + switch (c) { case 'x': - x = va_arg(args, ULONG); + x = va_arg(args, ULONG) & mask; n += printbase(x, 16, fieldlen, padchar, 0); break; case 'X': - x = va_arg(args, ULONG); + x = va_arg(args, ULONG) & mask; n += printbase(x, 16, fieldlen, padchar, 1); break; case 'o': - x = va_arg(args, ULONG); + x = va_arg(args, ULONG) & mask; n += printbase(x, 8, fieldlen, padchar, 0); break; case 'd': - x = va_arg(args, ULONG); + x = va_arg(args, ULONG) & mask; n += printbase(x, 10, fieldlen, padchar, 0); break; case 'c': @@ -180,8 +195,8 @@
va_start(args, fmt); (void)_printf(fmt, args); - OFExit(); va_end(args); + exit(); }
// LICENSE_BEGIN
Modified: clients/lib/stdio.h =================================================================== --- clients/lib/stdio.h 2008-09-26 01:02:15 UTC (rev 946) +++ clients/lib/stdio.h 2008-09-30 20:15:44 UTC (rev 947) @@ -15,6 +15,8 @@ #define EOF -1 extern FILE *fopen();
+void fflush (FILE *fp); +int printf(char *fmt, ...);
// LICENSE_BEGIN // Copyright (c) 2006 FirmWorks
Modified: clients/lib/wrappers.c =================================================================== --- clients/lib/wrappers.c 2008-09-26 01:02:15 UTC (rev 946) +++ clients/lib/wrappers.c 2008-09-30 20:15:44 UTC (rev 947) @@ -36,27 +36,6 @@
#include "1275.h"
-#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, ...); - -#ifdef CIF64 -#define CIF_HANDLER_IN 6 -#else -#define CIF_HANDLER_IN 3 -#endif - // Device tree routines
// @@ -449,7 +428,57 @@ return ((LONG)argarray[CIF_HANDLER_IN+LOW(3)]); }
+#include <stdarg.h> + +#define MAXARGS 12 long +OFCallMethodV( + char *method, + ihandle id, + int numargs, + int numres, + ... + ) +{ +#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; + argarray[LOW(argnum++)] = (cell_t)numres+1; + argarray[LOW(argnum++)] = (cell_t)method; + argarray[LOW(argnum++)] = (cell_t)id; + + if ((numargs + numres) > MAXARGS) + return -1; + + va_start(ap, numres); + while (numargs--) + argarray[LOW(argnum++)] = va_arg(ap, int); + + retval = call_firmware(argarray); + if (retval == 0) { + retval = argarray[LOW(argnum++)]; // Catch result + if (retval == 0) { + while (numres--) { + intp = va_arg(ap, int *); + *intp = argarray[LOW(argnum++)]; + } + } + } + va_end(ap); + return retval; +} + +long OFInterpret0( char *cmd ) @@ -468,6 +497,52 @@ return ((LONG)argarray[CIF_HANDLER_IN+LOW(1)]); }
+long +OFInterpretV( + char *cmd, + int numargs, + int numres, + ... + ) +{ +#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; + argarray[LOW(argnum++)] = (cell_t)numres+1; + argarray[LOW(argnum++)] = (cell_t)cmd; + + if ((numargs + numres) > MAXARGS) + return -1; + + va_start(ap, numres); + while (numargs--) + argarray[LOW(argnum++)] = va_arg(ap, int); + + retval = call_firmware(argarray); + if (retval == 0) { + retval = argarray[LOW(argnum++)]; // Catch result + if (retval == 0) { + while (numres--) { + intp = va_arg(ap, int *); + *intp = argarray[LOW(argnum++)]; + } + } + } + va_end(ap); + return retval; +} + + ULONG OFMilliseconds( VOID ) {
openfirmware@openfirmware.info