diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/cpus/aarch64/dsu_helpers.S | 24 | ||||
-rw-r--r-- | lib/el3_runtime/aarch64/context_mgmt.c | 2 | ||||
-rw-r--r-- | lib/libc/assert.c | 8 | ||||
-rw-r--r-- | lib/libc/exit.c | 4 | ||||
-rw-r--r-- | lib/libc/printf.c | 62 | ||||
-rw-r--r-- | lib/libc/puts.c | 5 | ||||
-rw-r--r-- | lib/libc/snprintf.c | 57 |
7 files changed, 98 insertions, 64 deletions
diff --git a/lib/cpus/aarch64/dsu_helpers.S b/lib/cpus/aarch64/dsu_helpers.S index 293ed24bf..152a3da26 100644 --- a/lib/cpus/aarch64/dsu_helpers.S +++ b/lib/cpus/aarch64/dsu_helpers.S @@ -8,15 +8,19 @@ #include <dsu_def.h> #include <errata_report.h> -/* - * DSU erratum 936184 - * Check the DSU variant, revision and configuration to determine if the - * erratum applies. This erratum was fixed in r2p0. +/* ----------------------------------------------------------------------- + * DSU erratum 936184 check function + * Checks the DSU variant, revision and configuration to determine if + * the erratum applies. Erratum applies if ACP interface is present + * in the DSU and revision-variant < r2p0. + * + * The erratum was fixed in r2p0. * * This function is called from both assembly and C environment. So it * follows AAPCS. * * Clobbers: x0-x3 + * ----------------------------------------------------------------------- */ .globl check_errata_dsu_936184 .globl errata_dsu_936184_wa @@ -25,7 +29,7 @@ func check_errata_dsu_936184 mov x2, #ERRATA_NOT_APPLIES mov x3, #ERRATA_APPLIES - /* Erratum applies only if ACP interface is present in DSU */ + /* Erratum applies only if DSU has the ACP interface */ mov x0, x2 mrs x1, CLUSTERCFR_EL1 ubfx x1, x1, #CLUSTERCFR_ACP_SHIFT, #1 @@ -44,8 +48,14 @@ func check_errata_dsu_936184 ret endfunc check_errata_dsu_936184 +/* -------------------------------------------------- + * Errata Workaround for DSU erratum #936184. + * + * Can clobber only: x0-x17 + * -------------------------------------------------- + */ func errata_dsu_936184_wa - mov x20, x30 + mov x17, x30 bl check_errata_dsu_936184 cbz x0, 1f @@ -56,5 +66,5 @@ func errata_dsu_936184_wa msr CLUSTERACTLR_EL1, x0 isb 1: - ret x20 + ret x17 endfunc errata_dsu_936184_wa diff --git a/lib/el3_runtime/aarch64/context_mgmt.c b/lib/el3_runtime/aarch64/context_mgmt.c index 2812bdaab..ee5fe4f9d 100644 --- a/lib/el3_runtime/aarch64/context_mgmt.c +++ b/lib/el3_runtime/aarch64/context_mgmt.c @@ -105,7 +105,7 @@ void cm_setup_context(cpu_context_t *ctx, const entry_point_info_t *ep) if (EP_GET_ST(ep->h.attr)) scr_el3 |= SCR_ST_BIT; -#ifndef HANDLE_EA_EL3_FIRST +#if !HANDLE_EA_EL3_FIRST /* * SCR_EL3.EA: Do not route External Abort and SError Interrupt External * to EL3 when executing at a lower EL. When executing at EL3, External diff --git a/lib/libc/assert.c b/lib/libc/assert.c index fa12cb6b0..8fa8f7212 100644 --- a/lib/libc/assert.c +++ b/lib/libc/assert.c @@ -20,19 +20,23 @@ void __assert(const char *file, unsigned int line, const char *assertion) { printf("ASSERT: %s:%d:%s\n", file, line, assertion); - console_flush(); + backtrace("assert"); + (void)console_flush(); plat_panic_handler(); } #elif PLAT_LOG_LEVEL_ASSERT >= LOG_LEVEL_INFO void __assert(const char *file, unsigned int line) { printf("ASSERT: %s:%d\n", file, line); - console_flush(); + backtrace("assert"); + (void)console_flush(); plat_panic_handler(); } #else void __assert(void) { + backtrace("assert"); + (void)console_flush(); plat_panic_handler(); } #endif diff --git a/lib/libc/exit.c b/lib/libc/exit.c index b2fde9ca2..f4ffe27cf 100644 --- a/lib/libc/exit.c +++ b/lib/libc/exit.c @@ -10,7 +10,7 @@ static void (*exitfun)(void); void exit(int status) { - if (exitfun) + if (exitfun != NULL) (*exitfun)(); for (;;) ; @@ -18,7 +18,7 @@ void exit(int status) int atexit(void (*fun)(void)) { - if (exitfun) + if (exitfun != NULL) return -1; exitfun = fun; diff --git a/lib/libc/printf.c b/lib/libc/printf.c index 4f4a722f7..4480e94db 100644 --- a/lib/libc/printf.c +++ b/lib/libc/printf.c @@ -6,28 +6,27 @@ #include <assert.h> #include <debug.h> #include <stdarg.h> +#include <stdbool.h> #include <stdint.h> -/*********************************************************** - * The printf implementation for all BL stages - ***********************************************************/ +#define get_num_va_args(_args, _lcount) \ + (((_lcount) > 1) ? va_arg(_args, long long int) : \ + (((_lcount) == 1) ? va_arg(_args, long int) : \ + va_arg(_args, int))) -#define get_num_va_args(_args, _lcount) \ - (((_lcount) > 1) ? va_arg(_args, long long int) : \ - ((_lcount) ? va_arg(_args, long int) : va_arg(_args, int))) - -#define get_unum_va_args(_args, _lcount) \ - (((_lcount) > 1) ? va_arg(_args, unsigned long long int) : \ - ((_lcount) ? va_arg(_args, unsigned long int) : va_arg(_args, unsigned int))) +#define get_unum_va_args(_args, _lcount) \ + (((_lcount) > 1) ? va_arg(_args, unsigned long long int) : \ + (((_lcount) == 1) ? va_arg(_args, unsigned long int) : \ + va_arg(_args, unsigned int))) static int string_print(const char *str) { int count = 0; - assert(str); + assert(str != NULL); - while (*str) { - putchar(*str++); + for ( ; *str != '\0'; str++) { + (void)putchar(*str); count++; } @@ -38,26 +37,30 @@ static int unsigned_num_print(unsigned long long int unum, unsigned int radix, char padc, int padn) { /* Just need enough space to store 64 bit decimal integer */ - unsigned char num_buf[20]; - int i = 0, rem, count = 0; + char num_buf[20]; + int i = 0, count = 0; + unsigned int rem; do { rem = unum % radix; if (rem < 0xa) - num_buf[i++] = '0' + rem; + num_buf[i] = '0' + rem; else - num_buf[i++] = 'a' + (rem - 0xa); - } while (unum /= radix); + num_buf[i] = 'a' + (rem - 0xa); + i++; + unum /= radix; + } while (unum > 0U); if (padn > 0) { - while (i < padn--) { - putchar(padc); + while (i < padn) { + (void)putchar(padc); count++; + padn--; } } while (--i >= 0) { - putchar(num_buf[i]); + (void)putchar(num_buf[i]); count++; } @@ -90,11 +93,11 @@ int vprintf(const char *fmt, va_list args) long long int num; unsigned long long int unum; char *str; - char padc = 0; /* Padding character */ + char padc = '\0'; /* Padding character */ int padn; /* Number of characters to pad */ int count = 0; /* Number of printed characters */ - while (*fmt) { + while (*fmt != '\0') { l_count = 0; padn = 0; @@ -107,7 +110,7 @@ loop: case 'd': num = get_num_va_args(args, l_count); if (num < 0) { - putchar('-'); + (void)putchar('-'); unum = (unsigned long long int)-num; padn--; } else @@ -122,7 +125,7 @@ loop: break; case 'p': unum = (uintptr_t)va_arg(args, void *); - if (unum) { + if (unum > 0U) { count += string_print("0x"); padn -= 2; } @@ -136,7 +139,7 @@ loop: padc, padn); break; case 'z': - if (sizeof(size_t) == 8) + if (sizeof(size_t) == 8U) l_count = 2; fmt++; @@ -155,9 +158,9 @@ loop: padn = 0; fmt++; - while (1) { + for (;;) { char ch = *fmt; - if (ch < '0' || ch > '9') { + if ((ch < '0') || (ch > '9')) { goto loop; } padn = (padn * 10) + (ch - '0'); @@ -170,7 +173,8 @@ loop: fmt++; continue; } - putchar(*fmt++); + (void)putchar(*fmt); + fmt++; count++; } diff --git a/lib/libc/puts.c b/lib/libc/puts.c index 717b5228e..2a0ca11c6 100644 --- a/lib/libc/puts.c +++ b/lib/libc/puts.c @@ -10,9 +10,10 @@ int puts(const char *s) { int count = 0; - while (*s) { - if (putchar(*s++) == EOF) + while (*s != '\0') { + if (putchar(*s) == EOF) return EOF; + s++; count++; } diff --git a/lib/libc/snprintf.c b/lib/libc/snprintf.c index 0738a8696..9bc07b2cb 100644 --- a/lib/libc/snprintf.c +++ b/lib/libc/snprintf.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved. + * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved. * * SPDX-License-Identifier: BSD-3-Clause */ @@ -11,9 +11,12 @@ static void string_print(char **s, size_t n, size_t *chars_printed, const char *str) { - while (*str) { - if (*chars_printed < n) - *(*s)++ = *str; + while (*str != '\0') { + if (*chars_printed < n) { + *(*s) = *str; + (*s)++; + } + (*chars_printed)++; str++; } @@ -23,17 +26,22 @@ static void unsigned_dec_print(char **s, size_t n, size_t *chars_printed, unsigned int unum) { /* Enough for a 32-bit unsigned decimal integer (4294967295). */ - unsigned char num_buf[10]; - int i = 0, rem; + char num_buf[10]; + int i = 0; + unsigned int rem; do { - rem = unum % 10; + rem = unum % 10U; num_buf[i++] = '0' + rem; - } while (unum /= 10); + unum /= 10U; + } while (unum > 0U); while (--i >= 0) { - if (*chars_printed < n) - *(*s)++ = num_buf[i]; + if (*chars_printed < n) { + *(*s) = num_buf[i]; + (*s)++; + } + (*chars_printed)++; } } @@ -58,19 +66,21 @@ int snprintf(char *s, size_t n, const char *fmt, ...) int num; unsigned int unum; char *str; - size_t chars_printed = 0; + size_t chars_printed = 0U; - if (n == 1) { + if (n == 0U) { + /* There isn't space for anything. */ + } else if (n == 1U) { /* Buffer is too small to actually write anything else. */ *s = '\0'; - n = 0; - } else if (n >= 2) { + n = 0U; + } else { /* Reserve space for the terminator character. */ n--; } va_start(args, fmt); - while (*fmt) { + while (*fmt != '\0') { if (*fmt == '%') { fmt++; @@ -81,8 +91,10 @@ int snprintf(char *s, size_t n, const char *fmt, ...) num = va_arg(args, int); if (num < 0) { - if (chars_printed < n) - *s++ = '-'; + if (chars_printed < n) { + *s = '-'; + s++; + } chars_printed++; unum = (unsigned int)-num; @@ -110,16 +122,19 @@ int snprintf(char *s, size_t n, const char *fmt, ...) continue; } - if (chars_printed < n) - *s++ = *fmt; + if (chars_printed < n) { + *s = *fmt; + s++; + } + fmt++; chars_printed++; } va_end(args); - if (n > 0) + if (n > 0U) *s = '\0'; - return chars_printed; + return (int)chars_printed; } |