diff options
author | Reinhard Meyer <u-boot@emk-elektronik.de> | 2010-09-08 12:25:40 +0200 |
---|---|---|
committer | Wolfgang Denk <wd@denx.de> | 2010-09-13 13:15:07 +0200 |
commit | 150f723665674100876c53e0492cd6d2191fe865 (patch) | |
tree | c4930d21ffc2705ea1a51315384cb554fc4212e9 /lib/display_options.c | |
parent | 93ceb4790d8daea992cdebf2c75434d73df9c028 (diff) |
display_buffer: fix misaligned buffer
use a union to cause necessary alignment per architecture
Signed-off-by: Reinhard Meyer <u-boot@emk-elektronik.de>
Diffstat (limited to 'lib/display_options.c')
-rw-r--r-- | lib/display_options.c | 27 |
1 files changed, 15 insertions, 12 deletions
diff --git a/lib/display_options.c b/lib/display_options.c index 20319e64bd..d0480f5105 100644 --- a/lib/display_options.c +++ b/lib/display_options.c @@ -101,10 +101,12 @@ void print_size(unsigned long long size, const char *s) #define DEFAULT_LINE_LENGTH_BYTES (16) int print_buffer (ulong addr, void* data, uint width, uint count, uint linelen) { - uint8_t linebuf[MAX_LINE_LENGTH_BYTES + 1]; - uint32_t *uip = (void*)linebuf; - uint16_t *usp = (void*)linebuf; - uint8_t *ucp = (void*)linebuf; + /* linebuf as a union causes proper alignment */ + union linebuf { + uint32_t ui[MAX_LINE_LENGTH_BYTES/sizeof(uint32_t) + 1]; + uint16_t us[MAX_LINE_LENGTH_BYTES/sizeof(uint16_t) + 1]; + uint8_t uc[MAX_LINE_LENGTH_BYTES/sizeof(uint8_t) + 1]; + } lb; int i; if (linelen*width > MAX_LINE_LENGTH_BYTES) @@ -123,21 +125,22 @@ int print_buffer (ulong addr, void* data, uint width, uint count, uint linelen) for (i = 0; i < linelen; i++) { uint32_t x; if (width == 4) - x = uip[i] = *(volatile uint32_t *)data; + x = lb.ui[i] = *(volatile uint32_t *)data; else if (width == 2) - x = usp[i] = *(volatile uint16_t *)data; + x = lb.us[i] = *(volatile uint16_t *)data; else - x = ucp[i] = *(volatile uint8_t *)data; + x = lb.uc[i] = *(volatile uint8_t *)data; printf(" %0*x", width * 2, x); data += width; } /* Print data in ASCII characters */ - for (i = 0; i < linelen * width; i++) - if (!isprint(ucp[i]) || ucp[i] >= 0x80) - ucp[i] = '.'; - ucp[i] = '\0'; - printf(" %s\n", ucp); + for (i = 0; i < linelen * width; i++) { + if (!isprint(lb.uc[i]) || lb.uc[i] >= 0x80) + lb.uc[i] = '.'; + } + lb.uc[i] = '\0'; + printf(" %s\n", lb.uc); /* update references */ addr += linelen * width; |