[RFC] libopenbios: Adapt CIF handling for ppc64

On ppc64 neither long nor pointers can be used for the client interface. Introduce new types prom_[u]arg_t to abstract this and add helpers get_service() and arg2pointer() as well as format strings. Signed-off-by: Andreas Färber <andreas.faerber@web.de> --- libopenbios/client.c | 302 ++++++++++++++++++++++++++++---------------------- 1 files changed, 170 insertions(+), 132 deletions(-) diff --git a/libopenbios/client.c b/libopenbios/client.c index d8a9fdf..d986226 100644 --- a/libopenbios/client.c +++ b/libopenbios/client.c @@ -30,13 +30,47 @@ * (it doesn't) or if the function is unimplemented. */ +#ifdef CONFIG_PPC64 +typedef int prom_arg_t; +typedef unsigned int prom_uarg_t; +#define PRIdARG "d" +#define PRIxARG "x" +#define FMT_arg "%" PRIdARG +#define FMT_argx "%08" PRIxARG +#else +typedef long prom_arg_t; +typedef unsigned long prom_uarg_t; +#define PRIdARG "ld" +#define PRIxARG "lx" +#define FMT_arg "%" PRIdARG +#define FMT_argx "%08" PRIxARG +#endif + #define PROM_MAX_ARGS 10 typedef struct prom_args { - const char *service; - long nargs; - long nret; - unsigned long args[PROM_MAX_ARGS]; -} prom_args_t; +#ifdef CONFIG_PPC64 + prom_uarg_t service; +#else + const char *service; +#endif + prom_arg_t nargs; + prom_arg_t nret; + prom_uarg_t args[PROM_MAX_ARGS]; +} __attribute__((packed)) prom_args_t; + +static inline void* arg2pointer(prom_uarg_t value) +{ + return (void*)(uintptr_t)value; +} + +static inline const char* get_service(prom_args_t *pb) +{ +#ifdef CONFIG_PPC64 + return arg2pointer(pb->service); +#else + return pb->service; +#endif +} #ifdef DEBUG_CIF static void memdump(const char *mem, unsigned long size) @@ -73,83 +107,84 @@ static void memdump(const char *mem, unsigned long size) static void dump_service(prom_args_t *pb) { int i; - if (strcmp(pb->service, "test") == 0) { - printk("test(\"%s\") = ", (char*)pb->args[0]); - } else if (strcmp(pb->service, "peer") == 0) { - printk("peer(0x%08lx) = ", pb->args[0]); - } else if (strcmp(pb->service, "child") == 0) { - printk("child(0x%08lx) = ", pb->args[0]); - } else if (strcmp(pb->service, "parent") == 0) { - printk("parent(0x%08lx) = ", pb->args[0]); - } else if (strcmp(pb->service, "instance-to-package") == 0) { - printk("instance-to-package(0x%08lx) = ", pb->args[0]); - } else if (strcmp(pb->service, "getproplen") == 0) { - printk("getproplen(0x%08lx, \"%s\") = ", - pb->args[0], (char*)pb->args[1]); - } else if (strcmp(pb->service, "getprop") == 0) { - printk("getprop(0x%08lx, \"%s\", 0x%08lx, %ld) = ", - pb->args[0], (char*)pb->args[1], + const char *service = get_service(pb); + if (strcmp(service, "test") == 0) { + printk("test(\"%s\") = ", (char*)arg2pointer(pb->args[0])); + } else if (strcmp(service, "peer") == 0) { + printk("peer(0x" FMT_argx ") = ", pb->args[0]); + } else if (strcmp(service, "child") == 0) { + printk("child(0x" FMT_argx ") = ", pb->args[0]); + } else if (strcmp(service, "parent") == 0) { + printk("parent(0x" FMT_argx ") = ", pb->args[0]); + } else if (strcmp(service, "instance-to-package") == 0) { + printk("instance-to-package(0x" FMT_argx ") = ", pb->args[0]); + } else if (strcmp(service, "getproplen") == 0) { + printk("getproplen(0x" FMT_argx ", \"%s\") = ", + pb->args[0], (char*)arg2pointer(pb->args[1])); + } else if (strcmp(service, "getprop") == 0) { + printk("getprop(0x" FMT_argx ", \"%s\", 0x" FMT_argx ", " FMT_arg ") = ", + pb->args[0], (char*)arg2pointer(pb->args[1]), pb->args[2], pb->args[3]); - } else if (strcmp(pb->service, "nextprop") == 0) { - printk("nextprop(0x%08lx, \"%s\", 0x%08lx) = ", - pb->args[0], (char*)pb->args[1], pb->args[2]); - } else if (strcmp(pb->service, "setprop") == 0) { - printk("setprop(0x%08lx, \"%s\", 0x%08lx, %ld)\n", - pb->args[0], (char*)pb->args[1], + } else if (strcmp(service, "nextprop") == 0) { + printk("nextprop(0x" FMT_argx ", \"%s\", 0x" FMT_argx ") = ", + pb->args[0], (char*)arg2pointer(pb->args[1]), pb->args[2]); + } else if (strcmp(service, "setprop") == 0) { + printk("setprop(0x" FMT_argx ", \"%s\", 0x" FMT_argx ", " FMT_arg ")\n", + pb->args[0], (char*)arg2pointer(pb->args[1]), pb->args[2], pb->args[3]); - memdump((char*)pb->args[2], pb->args[3]); + memdump((char*)arg2pointer(pb->args[2]), pb->args[3]); printk(" = "); - } else if (strcmp(pb->service, "canon") == 0) { - printk("canon(\"%s\", 0x%08lx, %ld)\n", - (char*)pb->args[0], pb->args[1], pb->args[2]); - } else if (strcmp(pb->service, "finddevice") == 0) { - printk("finddevice(\"%s\") = ", (char*)pb->args[0]); - } else if (strcmp(pb->service, "instance-to-path") == 0) { - printk("instance-to-path(0x%08lx, 0x%08lx, %ld) = ", + } else if (strcmp(service, "canon") == 0) { + printk("canon(\"%s\", 0x" FMT_argx ", " FMT_arg ")\n", + (char*)arg2pointer(pb->args[0]), pb->args[1], pb->args[2]); + } else if (strcmp(service, "finddevice") == 0) { + printk("finddevice(\"%s\") = ", (char*)arg2pointer(pb->args[0])); + } else if (strcmp(service, "instance-to-path") == 0) { + printk("instance-to-path(0x" FMT_argx ", 0x" FMT_argx ", " FMT_arg ") = ", pb->args[0], pb->args[1], pb->args[2]); - } else if (strcmp(pb->service, "package-to-path") == 0) { - printk("package-to-path(0x%08lx, 0x%08lx, %ld) = ", + } else if (strcmp(service, "package-to-path") == 0) { + printk("package-to-path(0x" FMT_argx ", 0x" FMT_argx ", " FMT_arg ") = ", pb->args[0], pb->args[1], pb->args[2]); - } else if (strcmp(pb->service, "open") == 0) { - printk("open(\"%s\") = ", (char*)pb->args[0]); - } else if (strcmp(pb->service, "close") == 0) { - printk("close(0x%08lx)\n", pb->args[0]); - } else if (strcmp(pb->service, "read") == 0) { + } else if (strcmp(service, "open") == 0) { + printk("open(\"%s\") = ", (char*)arg2pointer(pb->args[0])); + } else if (strcmp(service, "close") == 0) { + printk("close(0x" FMT_argx ")\n", pb->args[0]); + } else if (strcmp(service, "read") == 0) { #ifdef DUMP_IO - printk("read(0x%08lx, 0x%08lx, %ld) = ", + printk("read(0x" FMT_argx ", 0x" FMT_argx ", " FMT_arg ") = ", pb->args[0], pb->args[1], pb->args[2]); #endif - } else if (strcmp(pb->service, "write") == 0) { + } else if (strcmp(service, "write") == 0) { #ifdef DUMP_IO - printk("write(0x%08lx, 0x%08lx, %ld)\n", + printk("write(0x" FMT_argx ", 0x" FMT_argx ", " FMT_arg ")\n", pb->args[0], pb->args[1], pb->args[2]); - memdump((char*)pb->args[1], pb->args[2]); + memdump((char*)arg2pointer(pb->args[1]), pb->args[2]); printk(" = "); #endif - } else if (strcmp(pb->service, "seek") == 0) { + } else if (strcmp(service, "seek") == 0) { #ifdef DUMP_IO - printk("seek(0x%08lx, 0x%08lx, 0x%08lx) = ", + printk("seek(0x" FMT_argx ", 0x" FMT_argx ", 0x" FMT_argx ") = ", pb->args[0], pb->args[1], pb->args[2]); #endif - } else if (strcmp(pb->service, "claim") == 0) { - printk("claim(0x%08lx, %ld, %ld) = ", + } else if (strcmp(service, "claim") == 0) { + printk("claim(0x" FMT_argx ", " FMT_arg ", " FMT_arg ") = ", pb->args[0], pb->args[1], pb->args[2]); - } else if (strcmp(pb->service, "release") == 0) { - printk("release(0x%08lx, %ld)\n", + } else if (strcmp(service, "release") == 0) { + printk("release(0x" FMT_argx ", " FMT_arg ")\n", pb->args[0], pb->args[1]); - } else if (strcmp(pb->service, "boot") == 0) { - printk("boot \"%s\"\n", (char*)pb->args[0]); - } else if (strcmp(pb->service, "enter") == 0) { + } else if (strcmp(service, "boot") == 0) { + printk("boot \"%s\"\n", (char*)arg2pointer(pb->args[0])); + } else if (strcmp(service, "enter") == 0) { printk("enter()\n"); - } else if (strcmp(pb->service, "exit") == 0) { + } else if (strcmp(service, "exit") == 0) { printk("exit()\n"); - } else if (strcmp(pb->service, "test-method") == 0) { - printk("test-method(0x%08lx, \"%s\") = ", - pb->args[0], (char*)pb->args[1]); + } else if (strcmp(service, "test-method") == 0) { + printk("test-method(0x" FMT_argx ", \"%s\") = ", + pb->args[0], (char*)arg2pointer(pb->args[1])); } else { - printk("of_client_interface: %s ", pb->service ); + printk("of_client_interface: %s", service); for( i = 0; i < pb->nargs; i++ ) - printk("%lx ", pb->args[i] ); + printk(" %" PRIxARG, pb->args[i]); printk("\n"); } } @@ -157,71 +192,72 @@ static void dump_service(prom_args_t *pb) static void dump_return(prom_args_t *pb) { int i; - if (strcmp(pb->service, "test") == 0) { - printk(" %ld\n", pb->args[pb->nargs]); - } else if (strcmp(pb->service, "peer") == 0) { - printk("0x%08lx\n", pb->args[pb->nargs]); - } else if (strcmp(pb->service, "child") == 0) { - printk("0x%08lx\n", pb->args[pb->nargs]); - } else if (strcmp(pb->service, "parent") == 0) { - printk("0x%08lx\n", pb->args[pb->nargs]); - } else if (strcmp(pb->service, "instance-to-package") == 0) { - printk("0x%08lx\n", pb->args[pb->nargs]); - } else if (strcmp(pb->service, "getproplen") == 0) { - printk("0x%08lx\n", pb->args[pb->nargs]); - } else if (strcmp(pb->service, "getprop") == 0) { - printk("%ld\n", pb->args[pb->nargs]); - if ((long)pb->args[pb->nargs] != -1) - memdump((char*)pb->args[2], MIN(pb->args[3], pb->args[pb->nargs])); - } else if (strcmp(pb->service, "nextprop") == 0) { - printk("%ld\n", pb->args[pb->nargs]); - memdump((char*)pb->args[2], pb->args[pb->nargs]); - } else if (strcmp(pb->service, "setprop") == 0) { - printk("%ld\n", pb->args[pb->nargs]); - } else if (strcmp(pb->service, "canon") == 0) { - printk("%ld\n", pb->args[pb->nargs]); - memdump((char*)pb->args[1], pb->args[pb->nargs]); - } else if (strcmp(pb->service, "finddevice") == 0) { - printk("0x%08lx\n", pb->args[pb->nargs]); - } else if (strcmp(pb->service, "instance-to-path") == 0) { - printk("%ld\n", pb->args[pb->nargs]); - memdump((char*)pb->args[1], pb->args[pb->nargs]); - } else if (strcmp(pb->service, "package-to-path") == 0) { - printk("%ld\n", pb->args[pb->nargs]); - memdump((char*)pb->args[1], pb->args[pb->nargs]); - } else if (strcmp(pb->service, "open") == 0) { - printk("0x%08lx\n", pb->args[pb->nargs]); - } else if (strcmp(pb->service, "close") == 0) { + const char *service = get_service(pb); + if (strcmp(service, "test") == 0) { + printk(FMT_arg "\n", pb->args[pb->nargs]); + } else if (strcmp(service, "peer") == 0) { + printk("0x" FMT_argx "\n", pb->args[pb->nargs]); + } else if (strcmp(service, "child") == 0) { + printk("0x" FMT_argx "\n", pb->args[pb->nargs]); + } else if (strcmp(service, "parent") == 0) { + printk("0x" FMT_argx "\n", pb->args[pb->nargs]); + } else if (strcmp(service, "instance-to-package") == 0) { + printk("0x" FMT_argx "\n", pb->args[pb->nargs]); + } else if (strcmp(service, "getproplen") == 0) { + printk("0x" FMT_argx "\n", pb->args[pb->nargs]); + } else if (strcmp(service, "getprop") == 0) { + printk(FMT_arg "\n", pb->args[pb->nargs]); + if ((prom_arg_t)pb->args[pb->nargs] != -1) + memdump((char*)arg2pointer(pb->args[2]), MIN(pb->args[3], pb->args[pb->nargs])); + } else if (strcmp(service, "nextprop") == 0) { + printk(FMT_arg "\n", pb->args[pb->nargs]); + memdump((char*)arg2pointer(pb->args[2]), pb->args[pb->nargs]); + } else if (strcmp(service, "setprop") == 0) { + printk(FMT_arg "\n", pb->args[pb->nargs]); + } else if (strcmp(service, "canon") == 0) { + printk(FMT_arg "\n", pb->args[pb->nargs]); + memdump((char*)arg2pointer(pb->args[1]), pb->args[pb->nargs]); + } else if (strcmp(service, "finddevice") == 0) { + printk("0x" FMT_argx "\n", pb->args[pb->nargs]); + } else if (strcmp(service, "instance-to-path") == 0) { + printk(FMT_arg "\n", pb->args[pb->nargs]); + memdump((char*)arg2pointer(pb->args[1]), pb->args[pb->nargs]); + } else if (strcmp(service, "package-to-path") == 0) { + printk(FMT_arg "\n", pb->args[pb->nargs]); + memdump((char*)arg2pointer(pb->args[1]), pb->args[pb->nargs]); + } else if (strcmp(service, "open") == 0) { + printk("0x" FMT_argx "\n", pb->args[pb->nargs]); + } else if (strcmp(service, "close") == 0) { /* do nothing */ - } else if (strcmp(pb->service, "read") == 0) { + } else if (strcmp(service, "read") == 0) { #ifdef DUMP_IO - printk("%ld\n", pb->args[pb->nargs]); - memdump((char*)pb->args[1], pb->args[pb->nargs]); + printk(FMT_arg "\n", pb->args[pb->nargs]); + memdump((char*)arg2pointer(pb->args[1]), pb->args[pb->nargs]); #endif - } else if (strcmp(pb->service, "write") == 0) { + } else if (strcmp(service, "write") == 0) { #ifdef DUMP_IO - printk("%ld\n", pb->args[pb->nargs]); + printk(FMT_arg "\n", pb->args[pb->nargs]); #endif - } else if (strcmp(pb->service, "seek") == 0) { + } else if (strcmp(service, "seek") == 0) { #ifdef DUMP_IO - printk("%ld\n", pb->args[pb->nargs]); + printk(FMT_arg "\n", pb->args[pb->nargs]); #endif - } else if (strcmp(pb->service, "claim") == 0) { - printk("0x%08lx\n", pb->args[pb->nargs]); - } else if (strcmp(pb->service, "release") == 0) { + } else if (strcmp(service, "claim") == 0) { + printk("0x" FMT_argx "\n", pb->args[pb->nargs]); + } else if (strcmp(service, "release") == 0) { /* do nothing */ - } else if (strcmp(pb->service, "boot") == 0) { + } else if (strcmp(service, "boot") == 0) { /* do nothing */ - } else if (strcmp(pb->service, "enter") == 0) { + } else if (strcmp(service, "enter") == 0) { /* do nothing */ - } else if (strcmp(pb->service, "exit") == 0) { + } else if (strcmp(service, "exit") == 0) { /* do nothing */ - } else if (strcmp(pb->service, "test-method") == 0) { - printk("0x%08lx\n", pb->args[pb->nargs]); + } else if (strcmp(service, "test-method") == 0) { + printk("0x" FMT_argx "\n", pb->args[pb->nargs]); } else { printk("of_client_interface return:"); for (i = 0; i < pb->nret; i++) { - printk(" %lx", pb->args[pb->nargs + i]); + printk(" %" PRIxARG, pb->args[pb->nargs + i]); } printk("\n"); } @@ -233,17 +269,18 @@ static int handle_calls( prom_args_t *pb ) { int i, dstacksave = dstackcnt; - long val; + prom_uarg_t val; #ifdef DEBUG_CIF - printk("%s %s ([%ld] -- [%ld])\n", pb->service, (char *)pb->args[0], - pb->nargs, pb->nret); + printk("%s %s ([" FMT_arg "] -- [" FMT_arg "])\n", get_service(pb), + (char *)arg2pointer(pb->args[0]), + pb->nargs, pb->nret); #endif for( i=pb->nargs-1; i>=0; i-- ) PUSH( pb->args[i] ); - push_str( pb->service ); + push_str(get_service(pb)); fword("client-call-iface"); /* Drop the return code from client-call-iface (status is handled by the @@ -260,17 +297,18 @@ handle_calls( prom_args_t *pb ) } #ifdef DEBUG_CIF - /* useful for debug but not necessarily an error */ - if( i != pb->nret || dstackcnt != dstacksave ) { - printk("%s '%s': possible argument error (%ld--%ld) got %d\n", - pb->service, (char*)pb->args[0], pb->nargs-2, pb->nret, i ); - } - - printk("handle_calls return: "); - for (i = 0; i < pb->nret; i++) { - printk("%lx ", pb->args[pb->nargs + i]); - } - printk("\n"); + /* useful for debug but not necessarily an error */ + if (i != pb->nret || dstackcnt != dstacksave) { + printk("%s '%s': possible argument error (" FMT_arg "--" FMT_arg ") got %d\n", + get_service(pb), (char*)arg2pointer(pb->args[0]), + pb->nargs - 2, pb->nret, i); + } + + printk("handle_calls return:"); + for (i = 0; i < pb->nret; i++) { + printk(" %" PRIxARG, pb->args[pb->nargs + i]); + } + printk("\n"); #endif dstackcnt = dstacksave; @@ -292,21 +330,21 @@ of_client_interface( int *params ) #endif /* call-method exceptions are special */ - if( !strcmp("call-method", pb->service) || !strcmp("interpret", pb->service) ) + if (!strcmp("call-method", get_service(pb)) || !strcmp("interpret", get_service(pb))) return handle_calls( pb ); dstacksave = dstackcnt; for( i=pb->nargs-1; i>=0; i-- ) PUSH( pb->args[i] ); - push_str( pb->service ); + push_str(get_service(pb)); fword("client-iface"); if( (val=POP()) ) { dstackcnt = dstacksave; if( val == -1 ) - printk("Unimplemented service %s ([%ld] -- [%ld])\n", - pb->service, pb->nargs, pb->nret ); + printk("Unimplemented service %s ([" FMT_arg "] -- [" FMT_arg "])\n", + get_service(pb), pb->nargs, pb->nret ); #ifdef DEBUG_CIF else printk("ERROR!\n"); @@ -320,7 +358,7 @@ of_client_interface( int *params ) if( dstackcnt != dstacksave ) { #ifdef DEBUG_CIF printk("service %s: possible argument error (%d %d)\n", - pb->service, i, dstackcnt - dstacksave ); + get_service(pb), i, dstackcnt - dstacksave ); #endif /* Some clients request less parameters than the CIF method returns, e.g. getprop with OpenSolaris. Hence we drop any -- 1.7.3

On Sat, Dec 18, 2010 at 1:09 AM, Andreas Färber <andreas.faerber@web.de> wrote:
On ppc64 neither long nor pointers can be used for the client interface. Introduce new types prom_[u]arg_t to abstract this and add helpers get_service() and arg2pointer() as well as format strings.
Signed-off-by: Andreas Färber <andreas.faerber@web.de> --- libopenbios/client.c | 302 ++++++++++++++++++++++++++++---------------------- 1 files changed, 170 insertions(+), 132 deletions(-)
diff --git a/libopenbios/client.c b/libopenbios/client.c index d8a9fdf..d986226 100644 --- a/libopenbios/client.c +++ b/libopenbios/client.c @@ -30,13 +30,47 @@ * (it doesn't) or if the function is unimplemented. */
+#ifdef CONFIG_PPC64 +typedef int prom_arg_t; +typedef unsigned int prom_uarg_t; +#define PRIdARG "d" +#define PRIxARG "x" +#define FMT_arg "%" PRIdARG +#define FMT_argx "%08" PRIxARG +#else +typedef long prom_arg_t; +typedef unsigned long prom_uarg_t; +#define PRIdARG "ld" +#define PRIxARG "lx" +#define FMT_arg "%" PRIdARG +#define FMT_argx "%08" PRIxARG
This should be "%016" for Sparc64 since long is 64 bits. Maybe these should be moved to a common header instead.
+#endif + #define PROM_MAX_ARGS 10 typedef struct prom_args { - const char *service; - long nargs; - long nret; - unsigned long args[PROM_MAX_ARGS]; -} prom_args_t; +#ifdef CONFIG_PPC64 + prom_uarg_t service; +#else + const char *service; +#endif + prom_arg_t nargs; + prom_arg_t nret; + prom_uarg_t args[PROM_MAX_ARGS]; +} __attribute__((packed)) prom_args_t; + +static inline void* arg2pointer(prom_uarg_t value) +{ + return (void*)(uintptr_t)value; +}
Perhaps the the type of the return value should be const char * instead, that may reduce the number of casts.
+ +static inline const char* get_service(prom_args_t *pb) +{ +#ifdef CONFIG_PPC64 + return arg2pointer(pb->service); +#else + return pb->service; +#endif
I don't think arg2pointer() has any effect for non-PPC64 hosts, so you could also unconditionally use arg2pointer().
+}
#ifdef DEBUG_CIF static void memdump(const char *mem, unsigned long size) @@ -73,83 +107,84 @@ static void memdump(const char *mem, unsigned long size) static void dump_service(prom_args_t *pb) { int i; - if (strcmp(pb->service, "test") == 0) { - printk("test(\"%s\") = ", (char*)pb->args[0]); - } else if (strcmp(pb->service, "peer") == 0) { - printk("peer(0x%08lx) = ", pb->args[0]); - } else if (strcmp(pb->service, "child") == 0) { - printk("child(0x%08lx) = ", pb->args[0]); - } else if (strcmp(pb->service, "parent") == 0) { - printk("parent(0x%08lx) = ", pb->args[0]); - } else if (strcmp(pb->service, "instance-to-package") == 0) { - printk("instance-to-package(0x%08lx) = ", pb->args[0]); - } else if (strcmp(pb->service, "getproplen") == 0) { - printk("getproplen(0x%08lx, \"%s\") = ", - pb->args[0], (char*)pb->args[1]); - } else if (strcmp(pb->service, "getprop") == 0) { - printk("getprop(0x%08lx, \"%s\", 0x%08lx, %ld) = ", - pb->args[0], (char*)pb->args[1], + const char *service = get_service(pb); + if (strcmp(service, "test") == 0) { + printk("test(\"%s\") = ", (char*)arg2pointer(pb->args[0])); + } else if (strcmp(service, "peer") == 0) { + printk("peer(0x" FMT_argx ") = ", pb->args[0]); + } else if (strcmp(service, "child") == 0) { + printk("child(0x" FMT_argx ") = ", pb->args[0]); + } else if (strcmp(service, "parent") == 0) { + printk("parent(0x" FMT_argx ") = ", pb->args[0]); + } else if (strcmp(service, "instance-to-package") == 0) { + printk("instance-to-package(0x" FMT_argx ") = ", pb->args[0]); + } else if (strcmp(service, "getproplen") == 0) { + printk("getproplen(0x" FMT_argx ", \"%s\") = ", + pb->args[0], (char*)arg2pointer(pb->args[1])); + } else if (strcmp(service, "getprop") == 0) { + printk("getprop(0x" FMT_argx ", \"%s\", 0x" FMT_argx ", " FMT_arg ") = ", + pb->args[0], (char*)arg2pointer(pb->args[1]), pb->args[2], pb->args[3]); - } else if (strcmp(pb->service, "nextprop") == 0) { - printk("nextprop(0x%08lx, \"%s\", 0x%08lx) = ", - pb->args[0], (char*)pb->args[1], pb->args[2]); - } else if (strcmp(pb->service, "setprop") == 0) { - printk("setprop(0x%08lx, \"%s\", 0x%08lx, %ld)\n", - pb->args[0], (char*)pb->args[1], + } else if (strcmp(service, "nextprop") == 0) { + printk("nextprop(0x" FMT_argx ", \"%s\", 0x" FMT_argx ") = ", + pb->args[0], (char*)arg2pointer(pb->args[1]), pb->args[2]); + } else if (strcmp(service, "setprop") == 0) { + printk("setprop(0x" FMT_argx ", \"%s\", 0x" FMT_argx ", " FMT_arg ")\n", + pb->args[0], (char*)arg2pointer(pb->args[1]), pb->args[2], pb->args[3]); - memdump((char*)pb->args[2], pb->args[3]); + memdump((char*)arg2pointer(pb->args[2]), pb->args[3]); printk(" = "); - } else if (strcmp(pb->service, "canon") == 0) { - printk("canon(\"%s\", 0x%08lx, %ld)\n", - (char*)pb->args[0], pb->args[1], pb->args[2]); - } else if (strcmp(pb->service, "finddevice") == 0) { - printk("finddevice(\"%s\") = ", (char*)pb->args[0]); - } else if (strcmp(pb->service, "instance-to-path") == 0) { - printk("instance-to-path(0x%08lx, 0x%08lx, %ld) = ", + } else if (strcmp(service, "canon") == 0) { + printk("canon(\"%s\", 0x" FMT_argx ", " FMT_arg ")\n", + (char*)arg2pointer(pb->args[0]), pb->args[1], pb->args[2]); + } else if (strcmp(service, "finddevice") == 0) { + printk("finddevice(\"%s\") = ", (char*)arg2pointer(pb->args[0])); + } else if (strcmp(service, "instance-to-path") == 0) { + printk("instance-to-path(0x" FMT_argx ", 0x" FMT_argx ", " FMT_arg ") = ", pb->args[0], pb->args[1], pb->args[2]); - } else if (strcmp(pb->service, "package-to-path") == 0) { - printk("package-to-path(0x%08lx, 0x%08lx, %ld) = ", + } else if (strcmp(service, "package-to-path") == 0) { + printk("package-to-path(0x" FMT_argx ", 0x" FMT_argx ", " FMT_arg ") = ", pb->args[0], pb->args[1], pb->args[2]); - } else if (strcmp(pb->service, "open") == 0) { - printk("open(\"%s\") = ", (char*)pb->args[0]); - } else if (strcmp(pb->service, "close") == 0) { - printk("close(0x%08lx)\n", pb->args[0]); - } else if (strcmp(pb->service, "read") == 0) { + } else if (strcmp(service, "open") == 0) { + printk("open(\"%s\") = ", (char*)arg2pointer(pb->args[0])); + } else if (strcmp(service, "close") == 0) { + printk("close(0x" FMT_argx ")\n", pb->args[0]); + } else if (strcmp(service, "read") == 0) { #ifdef DUMP_IO - printk("read(0x%08lx, 0x%08lx, %ld) = ", + printk("read(0x" FMT_argx ", 0x" FMT_argx ", " FMT_arg ") = ", pb->args[0], pb->args[1], pb->args[2]); #endif - } else if (strcmp(pb->service, "write") == 0) { + } else if (strcmp(service, "write") == 0) { #ifdef DUMP_IO - printk("write(0x%08lx, 0x%08lx, %ld)\n", + printk("write(0x" FMT_argx ", 0x" FMT_argx ", " FMT_arg ")\n", pb->args[0], pb->args[1], pb->args[2]); - memdump((char*)pb->args[1], pb->args[2]); + memdump((char*)arg2pointer(pb->args[1]), pb->args[2]); printk(" = "); #endif - } else if (strcmp(pb->service, "seek") == 0) { + } else if (strcmp(service, "seek") == 0) { #ifdef DUMP_IO - printk("seek(0x%08lx, 0x%08lx, 0x%08lx) = ", + printk("seek(0x" FMT_argx ", 0x" FMT_argx ", 0x" FMT_argx ") = ", pb->args[0], pb->args[1], pb->args[2]); #endif - } else if (strcmp(pb->service, "claim") == 0) { - printk("claim(0x%08lx, %ld, %ld) = ", + } else if (strcmp(service, "claim") == 0) { + printk("claim(0x" FMT_argx ", " FMT_arg ", " FMT_arg ") = ", pb->args[0], pb->args[1], pb->args[2]); - } else if (strcmp(pb->service, "release") == 0) { - printk("release(0x%08lx, %ld)\n", + } else if (strcmp(service, "release") == 0) { + printk("release(0x" FMT_argx ", " FMT_arg ")\n", pb->args[0], pb->args[1]); - } else if (strcmp(pb->service, "boot") == 0) { - printk("boot \"%s\"\n", (char*)pb->args[0]); - } else if (strcmp(pb->service, "enter") == 0) { + } else if (strcmp(service, "boot") == 0) { + printk("boot \"%s\"\n", (char*)arg2pointer(pb->args[0])); + } else if (strcmp(service, "enter") == 0) { printk("enter()\n"); - } else if (strcmp(pb->service, "exit") == 0) { + } else if (strcmp(service, "exit") == 0) { printk("exit()\n"); - } else if (strcmp(pb->service, "test-method") == 0) { - printk("test-method(0x%08lx, \"%s\") = ", - pb->args[0], (char*)pb->args[1]); + } else if (strcmp(service, "test-method") == 0) { + printk("test-method(0x" FMT_argx ", \"%s\") = ", + pb->args[0], (char*)arg2pointer(pb->args[1])); } else { - printk("of_client_interface: %s ", pb->service ); + printk("of_client_interface: %s", service); for( i = 0; i < pb->nargs; i++ ) - printk("%lx ", pb->args[i] ); + printk(" %" PRIxARG, pb->args[i]); printk("\n"); } } @@ -157,71 +192,72 @@ static void dump_service(prom_args_t *pb) static void dump_return(prom_args_t *pb) { int i; - if (strcmp(pb->service, "test") == 0) { - printk(" %ld\n", pb->args[pb->nargs]); - } else if (strcmp(pb->service, "peer") == 0) { - printk("0x%08lx\n", pb->args[pb->nargs]); - } else if (strcmp(pb->service, "child") == 0) { - printk("0x%08lx\n", pb->args[pb->nargs]); - } else if (strcmp(pb->service, "parent") == 0) { - printk("0x%08lx\n", pb->args[pb->nargs]); - } else if (strcmp(pb->service, "instance-to-package") == 0) { - printk("0x%08lx\n", pb->args[pb->nargs]); - } else if (strcmp(pb->service, "getproplen") == 0) { - printk("0x%08lx\n", pb->args[pb->nargs]); - } else if (strcmp(pb->service, "getprop") == 0) { - printk("%ld\n", pb->args[pb->nargs]); - if ((long)pb->args[pb->nargs] != -1) - memdump((char*)pb->args[2], MIN(pb->args[3], pb->args[pb->nargs])); - } else if (strcmp(pb->service, "nextprop") == 0) { - printk("%ld\n", pb->args[pb->nargs]); - memdump((char*)pb->args[2], pb->args[pb->nargs]); - } else if (strcmp(pb->service, "setprop") == 0) { - printk("%ld\n", pb->args[pb->nargs]); - } else if (strcmp(pb->service, "canon") == 0) { - printk("%ld\n", pb->args[pb->nargs]); - memdump((char*)pb->args[1], pb->args[pb->nargs]); - } else if (strcmp(pb->service, "finddevice") == 0) { - printk("0x%08lx\n", pb->args[pb->nargs]); - } else if (strcmp(pb->service, "instance-to-path") == 0) { - printk("%ld\n", pb->args[pb->nargs]); - memdump((char*)pb->args[1], pb->args[pb->nargs]); - } else if (strcmp(pb->service, "package-to-path") == 0) { - printk("%ld\n", pb->args[pb->nargs]); - memdump((char*)pb->args[1], pb->args[pb->nargs]); - } else if (strcmp(pb->service, "open") == 0) { - printk("0x%08lx\n", pb->args[pb->nargs]); - } else if (strcmp(pb->service, "close") == 0) { + const char *service = get_service(pb); + if (strcmp(service, "test") == 0) { + printk(FMT_arg "\n", pb->args[pb->nargs]); + } else if (strcmp(service, "peer") == 0) { + printk("0x" FMT_argx "\n", pb->args[pb->nargs]); + } else if (strcmp(service, "child") == 0) { + printk("0x" FMT_argx "\n", pb->args[pb->nargs]); + } else if (strcmp(service, "parent") == 0) { + printk("0x" FMT_argx "\n", pb->args[pb->nargs]); + } else if (strcmp(service, "instance-to-package") == 0) { + printk("0x" FMT_argx "\n", pb->args[pb->nargs]); + } else if (strcmp(service, "getproplen") == 0) { + printk("0x" FMT_argx "\n", pb->args[pb->nargs]); + } else if (strcmp(service, "getprop") == 0) { + printk(FMT_arg "\n", pb->args[pb->nargs]); + if ((prom_arg_t)pb->args[pb->nargs] != -1) + memdump((char*)arg2pointer(pb->args[2]), MIN(pb->args[3], pb->args[pb->nargs])); + } else if (strcmp(service, "nextprop") == 0) { + printk(FMT_arg "\n", pb->args[pb->nargs]); + memdump((char*)arg2pointer(pb->args[2]), pb->args[pb->nargs]); + } else if (strcmp(service, "setprop") == 0) { + printk(FMT_arg "\n", pb->args[pb->nargs]); + } else if (strcmp(service, "canon") == 0) { + printk(FMT_arg "\n", pb->args[pb->nargs]); + memdump((char*)arg2pointer(pb->args[1]), pb->args[pb->nargs]); + } else if (strcmp(service, "finddevice") == 0) { + printk("0x" FMT_argx "\n", pb->args[pb->nargs]); + } else if (strcmp(service, "instance-to-path") == 0) { + printk(FMT_arg "\n", pb->args[pb->nargs]); + memdump((char*)arg2pointer(pb->args[1]), pb->args[pb->nargs]); + } else if (strcmp(service, "package-to-path") == 0) { + printk(FMT_arg "\n", pb->args[pb->nargs]); + memdump((char*)arg2pointer(pb->args[1]), pb->args[pb->nargs]); + } else if (strcmp(service, "open") == 0) { + printk("0x" FMT_argx "\n", pb->args[pb->nargs]); + } else if (strcmp(service, "close") == 0) { /* do nothing */ - } else if (strcmp(pb->service, "read") == 0) { + } else if (strcmp(service, "read") == 0) { #ifdef DUMP_IO - printk("%ld\n", pb->args[pb->nargs]); - memdump((char*)pb->args[1], pb->args[pb->nargs]); + printk(FMT_arg "\n", pb->args[pb->nargs]); + memdump((char*)arg2pointer(pb->args[1]), pb->args[pb->nargs]); #endif - } else if (strcmp(pb->service, "write") == 0) { + } else if (strcmp(service, "write") == 0) { #ifdef DUMP_IO - printk("%ld\n", pb->args[pb->nargs]); + printk(FMT_arg "\n", pb->args[pb->nargs]); #endif - } else if (strcmp(pb->service, "seek") == 0) { + } else if (strcmp(service, "seek") == 0) { #ifdef DUMP_IO - printk("%ld\n", pb->args[pb->nargs]); + printk(FMT_arg "\n", pb->args[pb->nargs]); #endif - } else if (strcmp(pb->service, "claim") == 0) { - printk("0x%08lx\n", pb->args[pb->nargs]); - } else if (strcmp(pb->service, "release") == 0) { + } else if (strcmp(service, "claim") == 0) { + printk("0x" FMT_argx "\n", pb->args[pb->nargs]); + } else if (strcmp(service, "release") == 0) { /* do nothing */ - } else if (strcmp(pb->service, "boot") == 0) { + } else if (strcmp(service, "boot") == 0) { /* do nothing */ - } else if (strcmp(pb->service, "enter") == 0) { + } else if (strcmp(service, "enter") == 0) { /* do nothing */ - } else if (strcmp(pb->service, "exit") == 0) { + } else if (strcmp(service, "exit") == 0) { /* do nothing */ - } else if (strcmp(pb->service, "test-method") == 0) { - printk("0x%08lx\n", pb->args[pb->nargs]); + } else if (strcmp(service, "test-method") == 0) { + printk("0x" FMT_argx "\n", pb->args[pb->nargs]); } else { printk("of_client_interface return:"); for (i = 0; i < pb->nret; i++) { - printk(" %lx", pb->args[pb->nargs + i]); + printk(" %" PRIxARG, pb->args[pb->nargs + i]);
" " FMT_arg?

Am 18.12.2010 um 17:09 schrieb Blue Swirl:
On Sat, Dec 18, 2010 at 1:09 AM, Andreas Färber <andreas.faerber@web.de
wrote: On ppc64 neither long nor pointers can be used for the client interface. Introduce new types prom_[u]arg_t to abstract this and add helpers get_service() and arg2pointer() as well as format strings.
Signed-off-by: Andreas Färber <andreas.faerber@web.de> --- libopenbios/client.c | 302 +++++++++++++++++++++++++++ +---------------------- 1 files changed, 170 insertions(+), 132 deletions(-)
diff --git a/libopenbios/client.c b/libopenbios/client.c index d8a9fdf..d986226 100644 --- a/libopenbios/client.c +++ b/libopenbios/client.c @@ -30,13 +30,47 @@ * (it doesn't) or if the function is unimplemented. */
+#ifdef CONFIG_PPC64 +typedef int prom_arg_t; +typedef unsigned int prom_uarg_t; +#define PRIdARG "d" +#define PRIxARG "x" +#define FMT_arg "%" PRIdARG +#define FMT_argx "%08" PRIxARG +#else +typedef long prom_arg_t; +typedef unsigned long prom_uarg_t; +#define PRIdARG "ld" +#define PRIxARG "lx" +#define FMT_arg "%" PRIdARG +#define FMT_argx "%08" PRIxARG
This should be "%016" for Sparc64 since long is 64 bits.
The original code used %08 so I left it that way. We could check #if BITS == 64.
Maybe these should be moved to a common header instead.
In that case we need longer names - e.g., FMT_promarg.
#define PROM_MAX_ARGS 10 typedef struct prom_args { - const char *service; - long nargs; - long nret; - unsigned long args[PROM_MAX_ARGS]; -} prom_args_t; +#ifdef CONFIG_PPC64 + prom_uarg_t service; +#else + const char *service; +#endif + prom_arg_t nargs; + prom_arg_t nret; + prom_uarg_t args[PROM_MAX_ARGS]; +} __attribute__((packed)) prom_args_t; + +static inline void* arg2pointer(prom_uarg_t value) +{ + return (void*)(uintptr_t)value; +}
Perhaps the the type of the return value should be const char * instead, that may reduce the number of casts.
Will try. I followed the cell2pointer() model.
+ +static inline const char* get_service(prom_args_t *pb) +{ +#ifdef CONFIG_PPC64 + return arg2pointer(pb->service); +#else + return pb->service; +#endif
I don't think arg2pointer() has any effect for non-PPC64 hosts, so you could also unconditionally use arg2pointer().
OK.
printk("of_client_interface return:"); for (i = 0; i < pb->nret; i++) { - printk(" %lx", pb->args[pb->nargs + i]); + printk(" %" PRIxARG, pb->args[pb->nargs + i]);
" " FMT_arg?
That would change the output to decimal. Intentional? If I used FMT_argx, we'd introduce zero-padding. Andreas

Am 18.12.2010 um 18:02 schrieb Andreas Färber:
Am 18.12.2010 um 17:09 schrieb Blue Swirl:
On Sat, Dec 18, 2010 at 1:09 AM, Andreas Färber <andreas.faerber@web.de
wrote: #define PROM_MAX_ARGS 10 typedef struct prom_args { - const char *service; - long nargs; - long nret; - unsigned long args[PROM_MAX_ARGS]; -} prom_args_t; +#ifdef CONFIG_PPC64 + prom_uarg_t service; +#else + const char *service; +#endif + prom_arg_t nargs; + prom_arg_t nret; + prom_uarg_t args[PROM_MAX_ARGS]; +} __attribute__((packed)) prom_args_t; + +static inline void* arg2pointer(prom_uarg_t value) +{ + return (void*)(uintptr_t)value; +}
Perhaps the the type of the return value should be const char * instead, that may reduce the number of casts.
Will try. I followed the cell2pointer() model.
+ +static inline const char* get_service(prom_args_t *pb) +{ +#ifdef CONFIG_PPC64 + return arg2pointer(pb->service); +#else + return pb->service; +#endif
I don't think arg2pointer() has any effect for non-PPC64 hosts, so you could also unconditionally use arg2pointer().
CC target/libopenbios/client.o cc1: warnings being treated as errors ../libopenbios/client.c: In function 'get_service': ../libopenbios/client.c:72:5: error: passing argument 1 of 'arg2pointer' makes integer from pointer without a cast ../libopenbios/client.c:65:21: note: expected 'prom_uarg_t' but argument is of type 'const char *' make[1]: *** [target/libopenbios/client.o] Error 1 A possible solution would be to always declare the service field as prom_uarg_t but then it cannot easily be inspected in gdb. Andreas

On ppc64, neither long nor pointers can be used for the client interface. Introduce new types prom_[u]arg_t to abstract this and add helpers get_service() and arg2pointer() as well as format strings. v2: * Move format strings to arch-specific headers. * Always declare 'service' as prom_uarg_t for consistency. This keeps arch-specific code out. * Let arg2pointer() return const char* to avoid casts. Suggested by Blue. * Use zero-padded hexadecimal format string for unknown services. Cc: Blue Swirl <blauwirbel@gmail.com> Signed-off-by: Andreas Färber <andreas.faerber@web.de> --- include/arch/amd64/types.h | 10 ++ include/arch/ia64/types.h | 10 ++ include/arch/ppc/types.h | 14 ++ include/arch/sparc32/types.h | 14 ++ include/arch/sparc64/types.h | 14 ++ include/arch/x86/types.h | 10 ++ libopenbios/client.c | 279 ++++++++++++++++++++++-------------------- 7 files changed, 219 insertions(+), 132 deletions(-) diff --git a/include/arch/amd64/types.h b/include/arch/amd64/types.h index 44d2182..7b4f587 100644 --- a/include/arch/amd64/types.h +++ b/include/arch/amd64/types.h @@ -31,6 +31,16 @@ typedef __uint128_t ducell; #define FMT_ucellx "%016llx" +typedef int64_t prom_arg_t; +typedef uint64_t prom_uarg_t; + +#define PRIdPROMARG PRId64 +#define PRIuPROMARG PRIu64 +#define PRIxPROMARG PRIx64 +#define FMT_prom_arg "%" PRIdPROMARG +#define FMT_prom_uarg "%" PRIuPROMARG +#define FMT_prom_uargx "%016" PRIxPROMARG + #define FMT_elf "%#x" #define bitspercell (sizeof(cell)<<3) diff --git a/include/arch/ia64/types.h b/include/arch/ia64/types.h index 3bd2edb..ce5bbb1 100644 --- a/include/arch/ia64/types.h +++ b/include/arch/ia64/types.h @@ -30,6 +30,16 @@ typedef uint64_t ucell; typedef __int128_t dcell; typedef __uint128_t ducell; +typedef int64_t prom_arg_t; +typedef uint64_t prom_uarg_t; + +#define PRIdPROMARG PRId64 +#define PRIuPROMARG PRIu64 +#define PRIxPROMARG PRIx64 +#define FMT_prom_arg "%" PRIdPROMARG +#define FMT_prom_uarg "%" PRIuPROMARG +#define FMT_prom_uargx "%016" PRIxPROMARG + #define bitspercell (sizeof(cell)<<3) #define bitsperdcell (sizeof(dcell)<<3) diff --git a/include/arch/ppc/types.h b/include/arch/ppc/types.h index ed9100c..b596428 100644 --- a/include/arch/ppc/types.h +++ b/include/arch/ppc/types.h @@ -26,7 +26,11 @@ typedef int int32_t; typedef long long int64_t; typedef long intptr_t; +#define PRId32 "d" +#define PRIu32 "u" #define PRIx32 "x" +#define PRId64 "lld" +#define PRIu64 "llu" #define PRIx64 "llx" #endif @@ -54,6 +58,16 @@ typedef uint64_t ducell; #define FMT_ucellx "%08x" #define FMT_ucellX "%08X" +typedef int32_t prom_arg_t; +typedef uint32_t prom_uarg_t; + +#define PRIdPROMARG PRId32 +#define PRIuPROMARG PRIu32 +#define PRIxPROMARG PRIx32 +#define FMT_prom_arg "%" PRIdPROMARG +#define FMT_prom_uarg "%" PRIuPROMARG +#define FMT_prom_uargx "%08" PRIxPROMARG + #define FMT_elf "%#x" #define FMT_sizet "%lx" #define FMT_aout_ehdr "%lx" diff --git a/include/arch/sparc32/types.h b/include/arch/sparc32/types.h index 444d648..e3a96ff 100644 --- a/include/arch/sparc32/types.h +++ b/include/arch/sparc32/types.h @@ -26,7 +26,11 @@ typedef int int32_t; typedef long long int64_t; typedef long intptr_t; +#define PRId32 "d" +#define PRIu32 "u" #define PRIx32 "x" +#define PRId64 "lld" +#define PRIu64 "llu" #define PRIx64 "llx" #endif @@ -51,6 +55,16 @@ typedef unsigned long long ducell; #define FMT_ucellx "%08x" #define FMT_ucellX "%08X" +typedef int32_t prom_arg_t; +typedef uint32_t prom_uarg_t; + +#define PRIdPROMARG PRId32 +#define PRIuPROMARG PRIu32 +#define PRIxPROMARG PRIx32 +#define FMT_prom_arg "%" PRIdPROMARG +#define FMT_prom_uarg "%" PRIuPROMARG +#define FMT_prom_uargx "%08" PRIxPROMARG + #define FMT_elf "%#x" #define FMT_sizet "%lx" #define FMT_aout_ehdr "%lx" diff --git a/include/arch/sparc64/types.h b/include/arch/sparc64/types.h index 14d0e41..d5a3fca 100644 --- a/include/arch/sparc64/types.h +++ b/include/arch/sparc64/types.h @@ -26,7 +26,11 @@ typedef int int32_t; typedef long long int64_t; typedef long intptr_t; +#define PRId32 "d" +#define PRIu32 "u" #define PRIx32 "x" +#define PRId64 "lld" +#define PRIu64 "llu" #define PRIx64 "llx" #endif @@ -47,6 +51,16 @@ typedef unsigned long long ucell; #define FMT_ucellx "%016llx" #define FMT_ucellX "%016llX" +typedef int64_t prom_arg_t; +typedef uint64_t prom_uarg_t; + +#define PRIdPROMARG PRId64 +#define PRIuPROMARG PRIu64 +#define PRIxPROMARG PRIx64 +#define FMT_prom_arg "%" PRIdPROMARG +#define FMT_prom_uarg "%" PRIuPROMARG +#define FMT_prom_uargx "%016" PRIxPROMARG + #define FMT_elf "%#llx" #define FMT_sizet "%lx" #define FMT_aout_ehdr "%x" diff --git a/include/arch/x86/types.h b/include/arch/x86/types.h index 3b1b331..f533397 100644 --- a/include/arch/x86/types.h +++ b/include/arch/x86/types.h @@ -35,6 +35,16 @@ typedef uint64_t ducell; #define FMT_ucellx "%08x" #define FMT_ucellX "%08X" +typedef int32_t prom_arg_t; +typedef uint32_t prom_uarg_t; + +#define PRIdPROMARG PRId32 +#define PRIuPROMARG PRIu32 +#define PRIxPROMARG PRIx32 +#define FMT_prom_arg "%" PRIdPROMARG +#define FMT_prom_uarg "%" PRIuPROMARG +#define FMT_prom_uargx "%08" PRIxPROMARG + #define FMT_elf "%#x" #define bitspercell (sizeof(cell)<<3) diff --git a/libopenbios/client.c b/libopenbios/client.c index d8a9fdf..ad9ccdc 100644 --- a/libopenbios/client.c +++ b/libopenbios/client.c @@ -32,11 +32,23 @@ #define PROM_MAX_ARGS 10 typedef struct prom_args { - const char *service; - long nargs; - long nret; - unsigned long args[PROM_MAX_ARGS]; -} prom_args_t; + prom_uarg_t service; + prom_arg_t nargs; + prom_arg_t nret; + prom_uarg_t args[PROM_MAX_ARGS]; +} __attribute__((packed)) prom_args_t; + +static inline const char * +arg2pointer(prom_uarg_t value) +{ + return (char*)(uintptr_t)value; +} + +static inline const char * +get_service(prom_args_t *pb) +{ + return arg2pointer(pb->service); +} #ifdef DEBUG_CIF static void memdump(const char *mem, unsigned long size) @@ -73,83 +85,84 @@ static void memdump(const char *mem, unsigned long size) static void dump_service(prom_args_t *pb) { int i; - if (strcmp(pb->service, "test") == 0) { - printk("test(\"%s\") = ", (char*)pb->args[0]); - } else if (strcmp(pb->service, "peer") == 0) { - printk("peer(0x%08lx) = ", pb->args[0]); - } else if (strcmp(pb->service, "child") == 0) { - printk("child(0x%08lx) = ", pb->args[0]); - } else if (strcmp(pb->service, "parent") == 0) { - printk("parent(0x%08lx) = ", pb->args[0]); - } else if (strcmp(pb->service, "instance-to-package") == 0) { - printk("instance-to-package(0x%08lx) = ", pb->args[0]); - } else if (strcmp(pb->service, "getproplen") == 0) { - printk("getproplen(0x%08lx, \"%s\") = ", - pb->args[0], (char*)pb->args[1]); - } else if (strcmp(pb->service, "getprop") == 0) { - printk("getprop(0x%08lx, \"%s\", 0x%08lx, %ld) = ", - pb->args[0], (char*)pb->args[1], + const char *service = get_service(pb); + if (strcmp(service, "test") == 0) { + printk("test(\"%s\") = ", arg2pointer(pb->args[0])); + } else if (strcmp(service, "peer") == 0) { + printk("peer(0x" FMT_prom_uargx ") = ", pb->args[0]); + } else if (strcmp(service, "child") == 0) { + printk("child(0x" FMT_prom_uargx ") = ", pb->args[0]); + } else if (strcmp(service, "parent") == 0) { + printk("parent(0x" FMT_prom_uargx ") = ", pb->args[0]); + } else if (strcmp(service, "instance-to-package") == 0) { + printk("instance-to-package(0x" FMT_prom_uargx ") = ", pb->args[0]); + } else if (strcmp(service, "getproplen") == 0) { + printk("getproplen(0x" FMT_prom_uargx ", \"%s\") = ", + pb->args[0], arg2pointer(pb->args[1])); + } else if (strcmp(service, "getprop") == 0) { + printk("getprop(0x" FMT_prom_uargx ", \"%s\", 0x" FMT_prom_uargx ", " FMT_prom_arg ") = ", + pb->args[0], arg2pointer(pb->args[1]), pb->args[2], pb->args[3]); - } else if (strcmp(pb->service, "nextprop") == 0) { - printk("nextprop(0x%08lx, \"%s\", 0x%08lx) = ", - pb->args[0], (char*)pb->args[1], pb->args[2]); - } else if (strcmp(pb->service, "setprop") == 0) { - printk("setprop(0x%08lx, \"%s\", 0x%08lx, %ld)\n", - pb->args[0], (char*)pb->args[1], + } else if (strcmp(service, "nextprop") == 0) { + printk("nextprop(0x" FMT_prom_uargx ", \"%s\", 0x" FMT_prom_uargx ") = ", + pb->args[0], arg2pointer(pb->args[1]), pb->args[2]); + } else if (strcmp(service, "setprop") == 0) { + printk("setprop(0x" FMT_prom_uargx ", \"%s\", 0x" FMT_prom_uargx ", " FMT_prom_arg ")\n", + pb->args[0], arg2pointer(pb->args[1]), pb->args[2], pb->args[3]); - memdump((char*)pb->args[2], pb->args[3]); + memdump(arg2pointer(pb->args[2]), pb->args[3]); printk(" = "); - } else if (strcmp(pb->service, "canon") == 0) { - printk("canon(\"%s\", 0x%08lx, %ld)\n", - (char*)pb->args[0], pb->args[1], pb->args[2]); - } else if (strcmp(pb->service, "finddevice") == 0) { - printk("finddevice(\"%s\") = ", (char*)pb->args[0]); - } else if (strcmp(pb->service, "instance-to-path") == 0) { - printk("instance-to-path(0x%08lx, 0x%08lx, %ld) = ", + } else if (strcmp(service, "canon") == 0) { + printk("canon(\"%s\", 0x" FMT_prom_uargx ", " FMT_prom_arg ")\n", + arg2pointer(pb->args[0]), pb->args[1], pb->args[2]); + } else if (strcmp(service, "finddevice") == 0) { + printk("finddevice(\"%s\") = ", arg2pointer(pb->args[0])); + } else if (strcmp(service, "instance-to-path") == 0) { + printk("instance-to-path(0x" FMT_prom_uargx ", 0x" FMT_prom_uargx ", " FMT_prom_arg ") = ", pb->args[0], pb->args[1], pb->args[2]); - } else if (strcmp(pb->service, "package-to-path") == 0) { - printk("package-to-path(0x%08lx, 0x%08lx, %ld) = ", + } else if (strcmp(service, "package-to-path") == 0) { + printk("package-to-path(0x" FMT_prom_uargx ", 0x" FMT_prom_uargx ", " FMT_prom_arg ") = ", pb->args[0], pb->args[1], pb->args[2]); - } else if (strcmp(pb->service, "open") == 0) { - printk("open(\"%s\") = ", (char*)pb->args[0]); - } else if (strcmp(pb->service, "close") == 0) { - printk("close(0x%08lx)\n", pb->args[0]); - } else if (strcmp(pb->service, "read") == 0) { + } else if (strcmp(service, "open") == 0) { + printk("open(\"%s\") = ", arg2pointer(pb->args[0])); + } else if (strcmp(service, "close") == 0) { + printk("close(0x" FMT_prom_uargx ")\n", pb->args[0]); + } else if (strcmp(service, "read") == 0) { #ifdef DUMP_IO - printk("read(0x%08lx, 0x%08lx, %ld) = ", + printk("read(0x" FMT_prom_uargx ", 0x" FMT_prom_uargx ", " FMT_prom_arg ") = ", pb->args[0], pb->args[1], pb->args[2]); #endif - } else if (strcmp(pb->service, "write") == 0) { + } else if (strcmp(service, "write") == 0) { #ifdef DUMP_IO - printk("write(0x%08lx, 0x%08lx, %ld)\n", + printk("write(0x" FMT_prom_uargx ", 0x" FMT_prom_uargx ", " FMT_prom_arg ")\n", pb->args[0], pb->args[1], pb->args[2]); - memdump((char*)pb->args[1], pb->args[2]); + memdump(arg2pointer(pb->args[1]), pb->args[2]); printk(" = "); #endif - } else if (strcmp(pb->service, "seek") == 0) { + } else if (strcmp(service, "seek") == 0) { #ifdef DUMP_IO - printk("seek(0x%08lx, 0x%08lx, 0x%08lx) = ", + printk("seek(0x" FMT_prom_uargx ", 0x" FMT_prom_uargx ", 0x" FMT_prom_uargx ") = ", pb->args[0], pb->args[1], pb->args[2]); #endif - } else if (strcmp(pb->service, "claim") == 0) { - printk("claim(0x%08lx, %ld, %ld) = ", + } else if (strcmp(service, "claim") == 0) { + printk("claim(0x" FMT_prom_uargx ", " FMT_prom_arg ", " FMT_prom_arg ") = ", pb->args[0], pb->args[1], pb->args[2]); - } else if (strcmp(pb->service, "release") == 0) { - printk("release(0x%08lx, %ld)\n", + } else if (strcmp(service, "release") == 0) { + printk("release(0x" FMT_prom_uargx ", " FMT_prom_arg ")\n", pb->args[0], pb->args[1]); - } else if (strcmp(pb->service, "boot") == 0) { - printk("boot \"%s\"\n", (char*)pb->args[0]); - } else if (strcmp(pb->service, "enter") == 0) { + } else if (strcmp(service, "boot") == 0) { + printk("boot \"%s\"\n", arg2pointer(pb->args[0])); + } else if (strcmp(service, "enter") == 0) { printk("enter()\n"); - } else if (strcmp(pb->service, "exit") == 0) { + } else if (strcmp(service, "exit") == 0) { printk("exit()\n"); - } else if (strcmp(pb->service, "test-method") == 0) { - printk("test-method(0x%08lx, \"%s\") = ", - pb->args[0], (char*)pb->args[1]); + } else if (strcmp(service, "test-method") == 0) { + printk("test-method(0x" FMT_prom_uargx ", \"%s\") = ", + pb->args[0], arg2pointer(pb->args[1])); } else { - printk("of_client_interface: %s ", pb->service ); + printk("of_client_interface: %s", service); for( i = 0; i < pb->nargs; i++ ) - printk("%lx ", pb->args[i] ); + printk(" " FMT_prom_uargx, pb->args[i]); printk("\n"); } } @@ -157,71 +170,72 @@ static void dump_service(prom_args_t *pb) static void dump_return(prom_args_t *pb) { int i; - if (strcmp(pb->service, "test") == 0) { - printk(" %ld\n", pb->args[pb->nargs]); - } else if (strcmp(pb->service, "peer") == 0) { - printk("0x%08lx\n", pb->args[pb->nargs]); - } else if (strcmp(pb->service, "child") == 0) { - printk("0x%08lx\n", pb->args[pb->nargs]); - } else if (strcmp(pb->service, "parent") == 0) { - printk("0x%08lx\n", pb->args[pb->nargs]); - } else if (strcmp(pb->service, "instance-to-package") == 0) { - printk("0x%08lx\n", pb->args[pb->nargs]); - } else if (strcmp(pb->service, "getproplen") == 0) { - printk("0x%08lx\n", pb->args[pb->nargs]); - } else if (strcmp(pb->service, "getprop") == 0) { - printk("%ld\n", pb->args[pb->nargs]); - if ((long)pb->args[pb->nargs] != -1) - memdump((char*)pb->args[2], MIN(pb->args[3], pb->args[pb->nargs])); - } else if (strcmp(pb->service, "nextprop") == 0) { - printk("%ld\n", pb->args[pb->nargs]); - memdump((char*)pb->args[2], pb->args[pb->nargs]); - } else if (strcmp(pb->service, "setprop") == 0) { - printk("%ld\n", pb->args[pb->nargs]); - } else if (strcmp(pb->service, "canon") == 0) { - printk("%ld\n", pb->args[pb->nargs]); - memdump((char*)pb->args[1], pb->args[pb->nargs]); - } else if (strcmp(pb->service, "finddevice") == 0) { - printk("0x%08lx\n", pb->args[pb->nargs]); - } else if (strcmp(pb->service, "instance-to-path") == 0) { - printk("%ld\n", pb->args[pb->nargs]); - memdump((char*)pb->args[1], pb->args[pb->nargs]); - } else if (strcmp(pb->service, "package-to-path") == 0) { - printk("%ld\n", pb->args[pb->nargs]); - memdump((char*)pb->args[1], pb->args[pb->nargs]); - } else if (strcmp(pb->service, "open") == 0) { - printk("0x%08lx\n", pb->args[pb->nargs]); - } else if (strcmp(pb->service, "close") == 0) { + const char *service = get_service(pb); + if (strcmp(service, "test") == 0) { + printk(FMT_prom_arg "\n", pb->args[pb->nargs]); + } else if (strcmp(service, "peer") == 0) { + printk("0x" FMT_prom_uargx "\n", pb->args[pb->nargs]); + } else if (strcmp(service, "child") == 0) { + printk("0x" FMT_prom_uargx "\n", pb->args[pb->nargs]); + } else if (strcmp(service, "parent") == 0) { + printk("0x" FMT_prom_uargx "\n", pb->args[pb->nargs]); + } else if (strcmp(service, "instance-to-package") == 0) { + printk("0x" FMT_prom_uargx "\n", pb->args[pb->nargs]); + } else if (strcmp(service, "getproplen") == 0) { + printk("0x" FMT_prom_uargx "\n", pb->args[pb->nargs]); + } else if (strcmp(service, "getprop") == 0) { + printk(FMT_prom_arg "\n", pb->args[pb->nargs]); + if ((prom_arg_t)pb->args[pb->nargs] != -1) + memdump(arg2pointer(pb->args[2]), MIN(pb->args[3], pb->args[pb->nargs])); + } else if (strcmp(service, "nextprop") == 0) { + printk(FMT_prom_arg "\n", pb->args[pb->nargs]); + memdump(arg2pointer(pb->args[2]), pb->args[pb->nargs]); + } else if (strcmp(service, "setprop") == 0) { + printk(FMT_prom_arg "\n", pb->args[pb->nargs]); + } else if (strcmp(service, "canon") == 0) { + printk(FMT_prom_arg "\n", pb->args[pb->nargs]); + memdump(arg2pointer(pb->args[1]), pb->args[pb->nargs]); + } else if (strcmp(service, "finddevice") == 0) { + printk("0x" FMT_prom_uargx "\n", pb->args[pb->nargs]); + } else if (strcmp(service, "instance-to-path") == 0) { + printk(FMT_prom_arg "\n", pb->args[pb->nargs]); + memdump(arg2pointer(pb->args[1]), pb->args[pb->nargs]); + } else if (strcmp(service, "package-to-path") == 0) { + printk(FMT_prom_arg "\n", pb->args[pb->nargs]); + memdump(arg2pointer(pb->args[1]), pb->args[pb->nargs]); + } else if (strcmp(service, "open") == 0) { + printk("0x" FMT_prom_uargx "\n", pb->args[pb->nargs]); + } else if (strcmp(service, "close") == 0) { /* do nothing */ - } else if (strcmp(pb->service, "read") == 0) { + } else if (strcmp(service, "read") == 0) { #ifdef DUMP_IO - printk("%ld\n", pb->args[pb->nargs]); - memdump((char*)pb->args[1], pb->args[pb->nargs]); + printk(FMT_prom_arg "\n", pb->args[pb->nargs]); + memdump(arg2pointer(pb->args[1]), pb->args[pb->nargs]); #endif - } else if (strcmp(pb->service, "write") == 0) { + } else if (strcmp(service, "write") == 0) { #ifdef DUMP_IO - printk("%ld\n", pb->args[pb->nargs]); + printk(FMT_prom_arg "\n", pb->args[pb->nargs]); #endif - } else if (strcmp(pb->service, "seek") == 0) { + } else if (strcmp(service, "seek") == 0) { #ifdef DUMP_IO - printk("%ld\n", pb->args[pb->nargs]); + printk(FMT_prom_arg "\n", pb->args[pb->nargs]); #endif - } else if (strcmp(pb->service, "claim") == 0) { - printk("0x%08lx\n", pb->args[pb->nargs]); - } else if (strcmp(pb->service, "release") == 0) { + } else if (strcmp(service, "claim") == 0) { + printk("0x" FMT_prom_uargx "\n", pb->args[pb->nargs]); + } else if (strcmp(service, "release") == 0) { /* do nothing */ - } else if (strcmp(pb->service, "boot") == 0) { + } else if (strcmp(service, "boot") == 0) { /* do nothing */ - } else if (strcmp(pb->service, "enter") == 0) { + } else if (strcmp(service, "enter") == 0) { /* do nothing */ - } else if (strcmp(pb->service, "exit") == 0) { + } else if (strcmp(service, "exit") == 0) { /* do nothing */ - } else if (strcmp(pb->service, "test-method") == 0) { - printk("0x%08lx\n", pb->args[pb->nargs]); + } else if (strcmp(service, "test-method") == 0) { + printk("0x" FMT_prom_uargx "\n", pb->args[pb->nargs]); } else { printk("of_client_interface return:"); for (i = 0; i < pb->nret; i++) { - printk(" %lx", pb->args[pb->nargs + i]); + printk(" " FMT_prom_uargx, pb->args[pb->nargs + i]); } printk("\n"); } @@ -233,17 +247,17 @@ static int handle_calls( prom_args_t *pb ) { int i, dstacksave = dstackcnt; - long val; + prom_uarg_t val; #ifdef DEBUG_CIF - printk("%s %s ([%ld] -- [%ld])\n", pb->service, (char *)pb->args[0], - pb->nargs, pb->nret); + printk("%s %s ([" FMT_prom_arg "] -- [" FMT_prom_arg "])\n", + get_service(pb), arg2pointer(pb->args[0]), pb->nargs, pb->nret); #endif for( i=pb->nargs-1; i>=0; i-- ) PUSH( pb->args[i] ); - push_str( pb->service ); + push_str(get_service(pb)); fword("client-call-iface"); /* Drop the return code from client-call-iface (status is handled by the @@ -260,17 +274,18 @@ handle_calls( prom_args_t *pb ) } #ifdef DEBUG_CIF - /* useful for debug but not necessarily an error */ - if( i != pb->nret || dstackcnt != dstacksave ) { - printk("%s '%s': possible argument error (%ld--%ld) got %d\n", - pb->service, (char*)pb->args[0], pb->nargs-2, pb->nret, i ); - } - - printk("handle_calls return: "); - for (i = 0; i < pb->nret; i++) { - printk("%lx ", pb->args[pb->nargs + i]); - } - printk("\n"); + /* useful for debug but not necessarily an error */ + if (i != pb->nret || dstackcnt != dstacksave) { + printk("%s '%s': possible argument error (" FMT_prom_arg "--" FMT_prom_arg ") got %d\n", + get_service(pb), arg2pointer(pb->args[0]), + pb->nargs - 2, pb->nret, i); + } + + printk("handle_calls return:"); + for (i = 0; i < pb->nret; i++) { + printk(" " FMT_prom_uargx, pb->args[pb->nargs + i]); + } + printk("\n"); #endif dstackcnt = dstacksave; @@ -292,21 +307,21 @@ of_client_interface( int *params ) #endif /* call-method exceptions are special */ - if( !strcmp("call-method", pb->service) || !strcmp("interpret", pb->service) ) + if (!strcmp("call-method", get_service(pb)) || !strcmp("interpret", get_service(pb))) return handle_calls( pb ); dstacksave = dstackcnt; for( i=pb->nargs-1; i>=0; i-- ) PUSH( pb->args[i] ); - push_str( pb->service ); + push_str(get_service(pb)); fword("client-iface"); if( (val=POP()) ) { dstackcnt = dstacksave; if( val == -1 ) - printk("Unimplemented service %s ([%ld] -- [%ld])\n", - pb->service, pb->nargs, pb->nret ); + printk("Unimplemented service %s ([" FMT_prom_arg "] -- [" FMT_prom_arg "])\n", + get_service(pb), pb->nargs, pb->nret ); #ifdef DEBUG_CIF else printk("ERROR!\n"); @@ -320,7 +335,7 @@ of_client_interface( int *params ) if( dstackcnt != dstacksave ) { #ifdef DEBUG_CIF printk("service %s: possible argument error (%d %d)\n", - pb->service, i, dstackcnt - dstacksave ); + get_service(pb), i, dstackcnt - dstacksave ); #endif /* Some clients request less parameters than the CIF method returns, e.g. getprop with OpenSolaris. Hence we drop any -- 1.7.3

Always define [u]cell in terms of fixed-width types, so that their PRI* macros can be reused. Signed-off-by: Andreas Färber <andreas.faerber@web.de> --- include/arch/amd64/types.h | 10 +++++----- include/arch/ppc/types.h | 12 +++++++----- include/arch/sparc32/types.h | 12 +++++++----- include/arch/sparc64/types.h | 16 +++++++++------- include/arch/x86/types.h | 10 +++++----- kernel/cross.h | 8 ++++---- 6 files changed, 37 insertions(+), 31 deletions(-) diff --git a/include/arch/amd64/types.h b/include/arch/amd64/types.h index 7b4f587..83fd3e1 100644 --- a/include/arch/amd64/types.h +++ b/include/arch/amd64/types.h @@ -11,7 +11,7 @@ #ifndef __TYPES_H #define __TYPES_H -#include <stdint.h> +#include <inttypes.h> /* endianess */ #include "autoconf.h" @@ -24,12 +24,12 @@ typedef uint64_t phys_addr_t; /* cell based types */ -typedef long long cell; -typedef unsigned long long ucell; -typedef __int128_t dcell; +typedef int64_t cell; +typedef uint64_t ucell; +typedef __int128_t dcell; typedef __uint128_t ducell; -#define FMT_ucellx "%016llx" +#define FMT_ucellx "%016" PRIx64 typedef int64_t prom_arg_t; typedef uint64_t prom_uarg_t; diff --git a/include/arch/ppc/types.h b/include/arch/ppc/types.h index b596428..cb1cc28 100644 --- a/include/arch/ppc/types.h +++ b/include/arch/ppc/types.h @@ -12,7 +12,7 @@ #include "mconfig.h" #ifdef BOOTSTRAP -#include <stdint.h> +#include <inttypes.h> #else typedef unsigned char uint8_t; typedef unsigned short uint16_t; @@ -29,9 +29,11 @@ typedef long intptr_t; #define PRId32 "d" #define PRIu32 "u" #define PRIx32 "x" +#define PRIX32 "X" #define PRId64 "lld" #define PRIu64 "llu" #define PRIx64 "llx" +#define PRIX64 "llX" #endif /* endianess */ @@ -53,10 +55,10 @@ typedef uint32_t ucell; typedef int64_t dcell; typedef uint64_t ducell; -#define FMT_cell "%d" -#define FMT_ucell "%u" -#define FMT_ucellx "%08x" -#define FMT_ucellX "%08X" +#define FMT_cell "%" PRId32 +#define FMT_ucell "%" PRIu32 +#define FMT_ucellx "%08" PRIx32 +#define FMT_ucellX "%08" PRIX32 typedef int32_t prom_arg_t; typedef uint32_t prom_uarg_t; diff --git a/include/arch/sparc32/types.h b/include/arch/sparc32/types.h index e3a96ff..f765874 100644 --- a/include/arch/sparc32/types.h +++ b/include/arch/sparc32/types.h @@ -12,7 +12,7 @@ #include "mconfig.h" #ifdef BOOTSTRAP -#include <stdint.h> +#include <inttypes.h> #else typedef unsigned char uint8_t; typedef unsigned short uint16_t; @@ -29,9 +29,11 @@ typedef long intptr_t; #define PRId32 "d" #define PRIu32 "u" #define PRIx32 "x" +#define PRIX32 "X" #define PRId64 "lld" #define PRIu64 "llu" #define PRIx64 "llx" +#define PRIX64 "llX" #endif /* endianess */ @@ -50,10 +52,10 @@ typedef uint32_t ucell; typedef long long dcell; typedef unsigned long long ducell; -#define FMT_cell "%ld" -#define FMT_ucell "%lu" -#define FMT_ucellx "%08x" -#define FMT_ucellX "%08X" +#define FMT_cell "%" PRId32 +#define FMT_ucell "%" PRIu32 +#define FMT_ucellx "%08" PRIx32 +#define FMT_ucellX "%08" PRIX32 typedef int32_t prom_arg_t; typedef uint32_t prom_uarg_t; diff --git a/include/arch/sparc64/types.h b/include/arch/sparc64/types.h index d5a3fca..8784331 100644 --- a/include/arch/sparc64/types.h +++ b/include/arch/sparc64/types.h @@ -12,7 +12,7 @@ #include "mconfig.h" #ifdef BOOTSTRAP -#include <stdint.h> +#include <inttypes.h> #else typedef unsigned char uint8_t; typedef unsigned short uint16_t; @@ -29,9 +29,11 @@ typedef long intptr_t; #define PRId32 "d" #define PRIu32 "u" #define PRIx32 "x" +#define PRIX32 "X" #define PRId64 "lld" #define PRIu64 "llu" #define PRIx64 "llx" +#define PRIX64 "llX" #endif /* endianess */ @@ -43,13 +45,13 @@ typedef uint64_t phys_addr_t; #define FMT_plx "%016" PRIx64 /* cell based types */ -typedef long long cell; -typedef unsigned long long ucell; +typedef int64_t cell; +typedef uint64_t ucell; -#define FMT_cell "%lld" -#define FMT_ucell "%llu" -#define FMT_ucellx "%016llx" -#define FMT_ucellX "%016llX" +#define FMT_cell "%" PRId64 +#define FMT_ucell "%" PRIu64 +#define FMT_ucellx "%016" PRIx64 +#define FMT_ucellX "%016" PRIX64 typedef int64_t prom_arg_t; typedef uint64_t prom_uarg_t; diff --git a/include/arch/x86/types.h b/include/arch/x86/types.h index f533397..e06ab9b 100644 --- a/include/arch/x86/types.h +++ b/include/arch/x86/types.h @@ -11,7 +11,7 @@ #ifndef __TYPES_H #define __TYPES_H -#include <stdint.h> +#include <inttypes.h> /* endianess */ @@ -30,10 +30,10 @@ typedef uint32_t ucell; typedef int64_t dcell; typedef uint64_t ducell; -#define FMT_cell "%ld" -#define FMT_ucell "%lu" -#define FMT_ucellx "%08x" -#define FMT_ucellX "%08X" +#define FMT_cell "%" PRId32 +#define FMT_ucell "%" PRIu32 +#define FMT_ucellx "%08" PRIx32 +#define FMT_ucellX "%08" PRIX32 typedef int32_t prom_arg_t; typedef uint32_t prom_uarg_t; diff --git a/kernel/cross.h b/kernel/cross.h index 50d55e7..9dd656f 100644 --- a/kernel/cross.h +++ b/kernel/cross.h @@ -103,11 +103,11 @@ /* bit width handling */ #if BITS==32 -#define FMT_CELL_x "x" -#define FMT_CELL_d "d" +#define FMT_CELL_x PRIx32 +#define FMT_CELL_d PRId32 #else -#define FMT_CELL_x "llx" -#define FMT_CELL_d "lld" +#define FMT_CELL_x PRIx64 +#define FMT_CELL_d PRId64 #endif #ifdef NATIVE_BITWIDTH_SMALLER_THAN_HOST_BITWIDTH -- 1.7.3

Blue Swirl wrote:
+#ifdef CONFIG_PPC64 +typedef int prom_arg_t; +typedef unsigned int prom_uarg_t; +#define PRIdARG "d" +#define PRIxARG "x" +#define FMT_arg "%" PRIdARG +#define FMT_argx "%08" PRIxARG +#else +typedef long prom_arg_t; +typedef unsigned long prom_uarg_t; +#define PRIdARG "ld" +#define PRIxARG "lx" +#define FMT_arg "%" PRIdARG +#define FMT_argx "%08" PRIxARG
This should be "%016" for Sparc64 since long is 64 bits. Maybe these should be moved to a common header instead.
Yeah - I'd like to try and keep all of the format definitions in one place, such as include/arch/<arch>/types.h if possible. ATB, Mark. -- Mark Cave-Ayland - Senior Technical Architect PostgreSQL - PostGIS Sirius Corporation plc - control through freedom http://www.siriusit.co.uk t: +44 870 608 0063 Sirius Labs: http://www.siriusit.co.uk/labs
participants (3)
-
Andreas Färber
-
Blue Swirl
-
Mark Cave-Ayland