public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Siarhei Siamashka <siarhei.siamashka@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 05/24] SPL: tiny-printf: add "l" modifier
Date: Thu, 24 Nov 2016 05:19:08 +0200	[thread overview]
Message-ID: <20161124051908.35417f08@i7> (raw)
In-Reply-To: <1479653838-3574-6-git-send-email-andre.przywara@arm.com>

On Sun, 20 Nov 2016 14:56:59 +0000
Andre Przywara <andre.przywara@arm.com> wrote:

> tiny-printf does not know about the "l" modifier so far, which breaks
> the crash dump on AArch64, because it uses %lx to print the registers.
> Add an easy way of handling longs correctly.

I can't help but notice that the changes of this kind are in a way
defeating the original purpose of tiny-printf. And it is surely not
the first patch adding features to tiny-printf. I guess, in the end
we may end up with a large and bloated printf implementation again :-)

A possible solution might be just a strict check when parsing format
modifiers and abort with an error message (yeah, this will introduce
some size increase, but hopefully the last one). This way we
acknowledge the fact that tiny-printf is a reduced incomplete
implementation, and that the callers need to take this into account.

As for the "l" modifier. How much does it add to the code size? IMHO
this information should be mentioned in the commit message. Can the
AArch64 crash dump code be modified to avoid using it? Or can we have
the "l" modifier supported on 64-bit platforms only?

> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> ---
>  lib/tiny-printf.c | 43 +++++++++++++++++++++++++++++++++----------
>  1 file changed, 33 insertions(+), 10 deletions(-)
> 
> diff --git a/lib/tiny-printf.c b/lib/tiny-printf.c
> index 30ac759..b01099d 100644
> --- a/lib/tiny-printf.c
> +++ b/lib/tiny-printf.c
> @@ -38,8 +38,8 @@ static void out_dgt(struct printf_info *info, char dgt)
>  	info->zs = 1;
>  }
>  
> -static void div_out(struct printf_info *info, unsigned int *num,
> -		    unsigned int div)
> +static void div_out(struct printf_info *info, unsigned long *num,
> +		    unsigned long div)
>  {
>  	unsigned char dgt = 0;
>  
> @@ -56,9 +56,9 @@ int _vprintf(struct printf_info *info, const char *fmt, va_list va)
>  {
>  	char ch;
>  	char *p;
> -	unsigned int num;
> +	unsigned long num;
>  	char buf[12];
> -	unsigned int div;
> +	unsigned long div;
>  
>  	while ((ch = *(fmt++))) {
>  		if (ch != '%') {
> @@ -66,8 +66,12 @@ int _vprintf(struct printf_info *info, const char *fmt, va_list va)
>  		} else {
>  			bool lz = false;
>  			int width = 0;
> +			bool islong = false;
>  
>  			ch = *(fmt++);
> +			if (ch == '-')
> +				ch = *(fmt++);
> +
>  			if (ch == '0') {
>  				ch = *(fmt++);
>  				lz = 1;
> @@ -80,6 +84,11 @@ int _vprintf(struct printf_info *info, const char *fmt, va_list va)
>  					ch = *fmt++;
>  				}
>  			}
> +			if (ch == 'l') {
> +				ch = *(fmt++);
> +				islong = true;
> +			}
> +
>  			info->bf = buf;
>  			p = info->bf;
>  			info->zs = 0;
> @@ -89,24 +98,38 @@ int _vprintf(struct printf_info *info, const char *fmt, va_list va)
>  				goto abort;
>  			case 'u':
>  			case 'd':
> -				num = va_arg(va, unsigned int);
> -				if (ch == 'd' && (int)num < 0) {
> -					num = -(int)num;
> +				div = 1000000000;
> +				if (islong) {
> +					num = va_arg(va, unsigned long);
> +					if (sizeof(long) > 4)
> +						div *= div * 10;
> +				} else {
> +					num = va_arg(va, unsigned int);
> +				}
> +
> +				if (ch == 'd' && (long)num < 0) {
> +					num = -(long)num;
>  					out(info, '-');
>  				}
>  				if (!num) {
>  					out_dgt(info, 0);
>  				} else {
> -					for (div = 1000000000; div; div /= 10)
> +					for (; div; div /= 10)
>  						div_out(info, &num, div);
>  				}
>  				break;
>  			case 'x':
> -				num = va_arg(va, unsigned int);
> +				if (islong) {
> +					num = va_arg(va, unsigned long);
> +					div = 1UL << (sizeof(long) * 8 - 4);
> +				} else {
> +					num = va_arg(va, unsigned int);
> +					div = 0x10000000;
> +				}
>  				if (!num) {
>  					out_dgt(info, 0);
>  				} else {
> -					for (div = 0x10000000; div; div /= 0x10)
> +					for (; div; div /= 0x10)
>  						div_out(info, &num, div);
>  				}
>  				break;



-- 
Best regards,
Siarhei Siamashka

  parent reply	other threads:[~2016-11-24  3:19 UTC|newest]

Thread overview: 61+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-20 14:56 [U-Boot] [PATCH 00/24] sunxi: Allwinner A64: SPL support Andre Przywara
2016-11-20 14:56 ` [U-Boot] [PATCH 01/24] drivers: SPI: sunxi SPL: fix warning Andre Przywara
2016-11-21  9:37   ` Jagan Teki
2016-11-21 15:28   ` Alexander Graf
2016-11-20 14:56 ` [U-Boot] [PATCH 02/24] sun6i: Restrict some register initialization to Allwinner A31 SoC Andre Przywara
2016-11-21 18:07   ` Jagan Teki
2016-11-24  3:01   ` Siarhei Siamashka
2016-11-24 10:18     ` Andre Przywara
2016-12-03  1:43       ` André Przywara
2016-11-20 14:56 ` [U-Boot] [PATCH 03/24] armv8: prevent using THUMB Andre Przywara
2016-11-21 15:29   ` Alexander Graf
2016-11-20 14:56 ` [U-Boot] [PATCH 04/24] armv8: add lowlevel_init.S Andre Przywara
2016-11-21 15:34   ` Alexander Graf
2016-11-21 15:49     ` Andre Przywara
2016-11-21 15:54       ` Alexander Graf
2016-11-20 14:56 ` [U-Boot] [PATCH 05/24] SPL: tiny-printf: add "l" modifier Andre Przywara
2016-11-21 15:42   ` Alexander Graf
2016-11-21 15:56     ` Andre Przywara
2016-11-21 16:05       ` Alexander Graf
2016-11-24  3:19   ` Siarhei Siamashka [this message]
2016-11-27 17:02     ` Simon Glass
2016-11-28  0:22       ` André Przywara
2016-11-29  1:13         ` André Przywara
2016-11-30  0:32           ` Simon Glass
2016-11-28  0:12     ` André Przywara
2016-11-20 14:57 ` [U-Boot] [PATCH 06/24] move UL() macro from armv8/mmu.h into common.h Andre Przywara
2016-11-21 15:45   ` Alexander Graf
2016-11-20 14:57 ` [U-Boot] [PATCH 07/24] SPL: make struct spl_image 64-bit safe Andre Przywara
2016-11-21 15:48   ` Alexander Graf
2016-11-21 16:20     ` york sun
2016-11-20 14:57 ` [U-Boot] [PATCH 08/24] armv8: add simple sdelay implementation Andre Przywara
2016-11-21 15:52   ` Alexander Graf
2016-11-24  1:33     ` Siarhei Siamashka
2016-11-24  1:25   ` Siarhei Siamashka
2016-11-24  1:29     ` André Przywara
2016-11-20 14:57 ` [U-Boot] [PATCH 09/24] armv8: move reset branch into boot hook Andre Przywara
2016-11-20 14:57 ` [U-Boot] [PATCH 10/24] ARM: boot0 hook: remove macro, include whole header file Andre Przywara
2016-11-20 14:57 ` [U-Boot] [PATCH 11/24] sunxi: introduce extra config option for boot0 header Andre Przywara
2016-11-21  7:27   ` Maxime Ripard
2016-11-21  9:29     ` Andre Przywara
2016-11-21 14:42       ` Maxime Ripard
2016-11-20 14:57 ` [U-Boot] [PATCH 12/24] sunxi: A64: do an RMR switch if started in AArch32 mode Andre Przywara
2016-11-21 16:34   ` Alexander Graf
2016-11-21 16:37     ` Andre Przywara
2016-11-20 14:57 ` [U-Boot] [PATCH 13/24] sunxi: provide default DRAM config for sun50i in Kconfig Andre Przywara
2016-11-20 14:57 ` [U-Boot] [PATCH 14/24] sunxi: H3: add and rename some DRAM contoller registers Andre Przywara
2016-11-20 14:57 ` [U-Boot] [PATCH 15/24] sunxi: H3: add DRAM controller single bit delay support Andre Przywara
2016-11-20 14:57 ` [U-Boot] [PATCH 16/24] sunxi: A64: use H3 DRAM initialization code for A64 Andre Przywara
2016-11-20 14:57 ` [U-Boot] [PATCH 17/24] sunxi: H3/A64: fix non-ODT setting Andre Przywara
2016-11-20 14:57 ` [U-Boot] [PATCH 18/24] sunxi: DRAM: fix H3 DRAM size display on aarch64 Andre Przywara
2016-11-21 16:36   ` Alexander Graf
2016-11-20 14:57 ` [U-Boot] [PATCH 19/24] sunxi: A64: enable SPL Andre Przywara
2016-11-21 16:37   ` Alexander Graf
2016-11-21 16:42     ` Andre Przywara
2016-11-20 14:57 ` [U-Boot] [PATCH 20/24] SPL: read and store arch property from U-Boot image Andre Przywara
2016-11-24  2:20   ` Simon Glass
2016-11-20 14:57 ` [U-Boot] [PATCH 21/24] Makefile: use "arm64" architecture for U-Boot image files Andre Przywara
2016-11-20 14:57 ` [U-Boot] [PATCH 22/24] ARM: SPL/FIT: differentiate between arm and arm64 arch properties Andre Przywara
2016-11-24  2:20   ` Simon Glass
2016-11-20 14:57 ` [U-Boot] [PATCH 23/24] sunxi: introduce RMR switch to enter payloads in 64-bit mode Andre Przywara
2016-11-20 14:57 ` [U-Boot] [PATCH 24/24] sunxi: A64: add 32-bit SPL support Andre Przywara

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20161124051908.35417f08@i7 \
    --to=siarhei.siamashka@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox