From bb6bd2f7ea37c471c9a6747e1473c7ad1f00a499 Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Sun, 19 Jun 2011 14:17:53 +0200 Subject: Reduced amount of #ifdef'ed code --- common/debug.h | 12 ++++++++++++ ext2load/ext2io.c | 21 ++++++--------------- ext2load/loader.c | 19 ++++++------------- tip22/tftpload.c | 27 +++++++++++---------------- 4 files changed, 35 insertions(+), 44 deletions(-) create mode 100644 common/debug.h diff --git a/common/debug.h b/common/debug.h new file mode 100644 index 0000000..465ca03 --- /dev/null +++ b/common/debug.h @@ -0,0 +1,12 @@ +/* + * Debugging macros + */ + +#ifdef DEBUG +#define debug_print(fmt,...) \ + printf(fmt, ##__VA_ARGS__) +#else +#define debug_printf(fmt,...) \ + do { } while (0) +#endif /* !DEBUG */ + diff --git a/ext2load/ext2io.c b/ext2load/ext2io.c index aa4b4c0..9f16473 100644 --- a/ext2load/ext2io.c +++ b/ext2load/ext2io.c @@ -17,6 +17,7 @@ #include #include #include +#include /* * All About the Cache @@ -596,9 +597,7 @@ arc_read_blk(io_channel channel, unsigned long block, int count, void *buf) priv = (struct arc_private_data *) channel->private_data; EXT2_CHECK_MAGIC(priv, EXT2_ET_BAD_MAGIC); -#ifdef DEBUG - printf("req %lu id %lu count %u\n\r", block, priv->fileID, count); -#endif + debug_printf("req %lu id %lu count %u\n\r", block, priv->fileID, count); /* Odd-sized reads can't be cached. */ if (count < 0) @@ -607,9 +606,7 @@ arc_read_blk(io_channel channel, unsigned long block, int count, void *buf) while (count > 0) { if ((cache = find_cached_block(priv, block)) == NULL) break; -#ifdef DEBUG - printf("Cache hit on block %lu\n\r", block); -#endif + debug_printf("Cache hit on block %lu\n\r", block); memcpy(cbuf, cache->buf, channel->block_size); count--; block++; @@ -626,15 +623,11 @@ arc_read_blk(io_channel channel, unsigned long block, int count, void *buf) * for reads we expect are not part of a sequential set. */ while (count > 0) { -#ifdef DEBUG - printf("Cache miss on block %lu (readahead %u)\n\r", + debug_printf("Cache miss on block %lu (readahead %u)\n\r", block, CACHE_SG_MAX); -#endif if ((cb_alloc = alloc_sg_blocks(channel, priv, block, CACHE_SG_MAX)) == 0) { -#ifdef DEBUG - printf("%s\n\r", "Cache error: can't alloc any blocks"); -#endif + debug_printf("%s\n\r", "Cache error: can't alloc any blocks"); /* Cache is broken, so do the raw read. */ cache_invalidate(channel, priv); status = raw_read_blk(channel, priv, block, count, @@ -643,10 +636,8 @@ arc_read_blk(io_channel channel, unsigned long block, int count, void *buf) } if ((status = fill_sg_blocks(channel, priv, cb_alloc)) != 0) { -#ifdef DEBUG - printf("Cache error (status %lu at block %lu(%u)\n\r", + debug_printf("Cache error (status %lu at block %lu(%u)\n\r", (unsigned long) status, block, count); -#endif /* Cache is broken, so do the raw read. */ cache_invalidate(channel, priv); status = raw_read_blk(channel, priv, block, count, diff --git a/ext2load/loader.c b/ext2load/loader.c index 44203b6..1feb6ba 100644 --- a/ext2load/loader.c +++ b/ext2load/loader.c @@ -20,6 +20,7 @@ #include "arcboot.h" #include +#include #define KSEG0ADDR(addr) (((addr) & 0x1fffffff) | 0x80000000) @@ -76,9 +77,7 @@ void InitMalloc(void) { MEMORYDESCRIPTOR *current = NULL; ULONG stack = (ULONG) ¤t; -#ifdef DEBUG - printf("stack starts at: 0x%lx\n\r", stack); -#endif + debug_printf("stack starts at: 0x%lx\n\r", stack); current = ArcGetMemoryDescriptor(current); if(! current ) { @@ -96,10 +95,8 @@ void InitMalloc(void) ULONG start = KSEG0ADDR(current->BasePage * PAGE_SIZE); ULONG end = start + (current->PageCount * PAGE_SIZE); -#if DEBUG - printf("Free Memory(%u) segment found at (0x%lx,0x%lx).\n\r", + debug_printf("Free Memory(%u) segment found at (0x%lx,0x%lx).\n\r", current->Type, start, end); -#endif /* Leave some space for our stack */ if ((stack >= start) && (stack < end)) @@ -118,10 +115,8 @@ void InitMalloc(void) + kernel_load[SUBARCH].reserved ))) end = kernel_load[SUBARCH].base; if (end > start) { -#ifdef DEBUG - printf("Adding %lu bytes at 0x%lx to the list of available memory\n\r", + debug_printf("Adding %lu bytes at 0x%lx to the list of available memory\n\r", end-start, start); -#endif arclib_malloc_add(start, end - start); } } @@ -561,10 +556,8 @@ void _start(LONG argc, CHAR *argv[], CHAR *envp[]) if (OSLoadPartition == NULL) Fatal("Invalid load partition\n\r"); -#if DEBUG - printf("OSLoadPartition: %s\n\r", OSLoadPartition); - printf("OSLoadFilename: %s\n\r", OSLoadFilename); -#endif + debug_printf("OSLoadPartition: %s\n\r", OSLoadPartition); + debug_printf("OSLoadFilename: %s\n\r", OSLoadFilename); /* * XXX: let's play stupid for now: assume /etc/arcboot.conf * is on OSLoadPartition diff --git a/tip22/tftpload.c b/tip22/tftpload.c index 37ca7d1..a41b051 100644 --- a/tip22/tftpload.c +++ b/tip22/tftpload.c @@ -18,6 +18,7 @@ #include #include +#include #define KSEG0ADDR(addr) (((addr) & 0x1fffffff) | 0x80000000) @@ -63,9 +64,7 @@ static void InitMalloc(void) { MEMORYDESCRIPTOR *current = NULL; ULONG stack = (ULONG) & current; -#ifdef DEBUG - printf("stack starts at: 0x%lx\n\r", stack); -#endif + debug_printf("stack starts at: 0x%lx\n\r", stack); current = ArcGetMemoryDescriptor(current); if(! current ) { @@ -83,10 +82,8 @@ static void InitMalloc(void) ULONG start = KSEG0ADDR(current->BasePage * PAGE_SIZE); ULONG end = start + (current->PageCount * PAGE_SIZE); -#if DEBUG - printf("Free Memory(%u) segment found at (0x%lx,0x%lx).\n\r", + debug_printf("Free Memory(%u) segment found at (0x%lx,0x%lx).\n\r", current->Type, start, end); -#endif /* Leave some space for our stack */ if ((stack >= start) && (stack < end)) @@ -105,10 +102,8 @@ static void InitMalloc(void) + kernel_load[SUBARCH].reserved ))) end = kernel_load[SUBARCH].base; if (end > start) { -#ifdef DEBUG - printf("Adding %lu bytes at 0x%lx to the list of available memory\n\r", + debug_printf("Adding %lu bytes at 0x%lx to the list of available memory\n\r", end-start, start); -#endif arclib_malloc_add(start, end - start); } } @@ -302,21 +297,21 @@ void _start(LONG argc, CHAR * argv[], CHAR * envp[]) void (*kernel_entry)(int argc, CHAR * argv[], CHAR * envp[]); /* Print identification */ + printf(ANSI_CLEAR "\n\r" #if (SUBARCH == IP22) - printf(ANSI_CLEAR "\n\rtip22: IP22 Linux tftpboot loader " __ARCSBOOT_VERSION__ "\n\r"); + "tip22: IP22" #elif (SUBARCH == IP32) - printf(ANSI_CLEAR "\n\rtip32: IP32 Linux tftpboot loader " __ARCSBOOT_VERSION__ "\n\r"); + "tip32: IP32" #endif + " Linux tftpboot loader " __ARCSBOOT_VERSION__ "\n\r"); InitMalloc(); /* copy kernel and ramdisk to its load addresses */ -#ifdef DEBUG - printf("Embedded kernel image starts 0x%p, ends 0x%p\n\r", + debug_printf("Embedded kernel image starts 0x%p, ends 0x%p\n\r", &__kernel_start, &__kernel_end); - printf("Embedded ramdisk image starts 0x%p, ends 0x%p\n\r", + debug_printf("Embedded ramdisk image starts 0x%p, ends 0x%p\n\r", &__rd_start, &__rd_end); -#endif kernel_entry = (void (*)(int, CHAR *[], CHAR *[]))CopyKernel(&kernel_end); /* align to page boundary */ @@ -343,8 +338,8 @@ void _start(LONG argc, CHAR * argv[], CHAR * envp[]) nargc++; } + debug_printf("Arguments passed to kernel:\n\r"); #ifdef DEBUG - printf("Arguments passed to kernel:\n\r"); for(i = 0; i < nargc; i++ ) printf("%u: %s\n\r", i, nargv[i]); Wait("\n\r--- Debug: press to boot kernel ---"); -- cgit v1.2.3