Commit graph

30 commits

Author SHA1 Message Date
Johan Hedberg 7d71c0656f printk: Add padding support to string format specifiers
The numeric format specifiers already have this support, but strings
didn't. This makes it possible to add padding after strings, using
format specifiers such as %-10s.

Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2017-11-14 21:32:20 +02:00
Leandro Pereira 6f99bdb02a kernel: Provide only one _SYSCALL_HANDLER() macro
Use some preprocessor trickery to automatically deduce the amount of
arguments for the various _SYSCALL_HANDLERn() macros.  Makes the grunt
work of converting a bunch of kernel APIs to system calls slightly
easier.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-10-16 13:42:15 -04:00
Andrew Boie ef2b138130 printk: only do buffering in user mode
This has extra stack overhead, no need to impose this on the caller
unless it's needed to avoid doing a system call for every
character.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-10-13 12:56:14 -07:00
Andrew Boie 225e4c0e76 kernel: greatly simplify syscall handlers
We now have macros which should significantly reduce the amount of
boilerplate involved with defining system call handlers.

- Macros which define the proper prototype based on number of arguments
- "SIMPLE" variants which create handlers that don't need anything
  other than object verification

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-10-12 16:26:28 -05:00
Andrew Boie 756f907274 misc: userspace support for printk()
To avoid making a system call for every character emitted, there is now
a small line buffer if userspace is enabled. The interface to the kernel
is a new system call which takes a sized buffer of console data.

If userspace is not enabled this works like before.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-10-11 09:23:57 -07:00
Anas Nashif 397d29db42 linker: move all linker headers to include/linker
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-06-18 09:24:04 -05:00
Andrew Boie 5963904e4c printk: fix printing of long long types
64-bit types were not being handled properly and depending on the
calling convention could result in garbage values being printed.

We still truncate these to 32-bit values, the predominant use-case
is printing timestamp delta values which generally fit in a 32-bit
value. However we are no longer printing random stuff.

Test case for printk() updated appripriately to catch this regression.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-05-30 19:42:22 -04:00
Maciek Borzecki fed96bf1bc misc: _char_out can be a static symbol
Fixes sparse warning:
<snip>/zephyr/zephyr/misc/printk.c:50:5: warning: symbol '_char_out' was not declared. Should it be static?

Change-Id: I5af0860e9f8f827002ae9a142b5924d3de8d51b6
Signed-off-by: Maciek Borzecki <maciek.borzecki@gmail.com>
2017-05-18 12:41:56 -05:00
Marti Bolivar dc91536855 printk: add vprintk()
This is needed by application code that wants to print formatted
strings, but only has a fmt and va_list, and lacks memory to spare for
"buf" and something like:

	 vsnprintk(buf, sizeof(buf), fmt, ap);
	 printk("%s", buf);

Change-Id: Ic9cc915ec7e5f8f9492c730667f39788ecae65f6
Signed-off-by: Marti Bolivar <marti.bolivar@linaro.org>
2017-04-22 14:29:33 +00:00
Leandro Pereira 99a7168b08 misc: Support left-justification in printk()
This is supported by printf(), and is an important formatting feature
to print out some complex, nicely-formatted information.  This is
accomplished by using a negative padding in the formatting string.

The following code:

      printk("none:         |%u| |%x|\n", 12345, 12345);
      printk("zero_before:  |%08u| |%08x|\n", 12345, 12345);
      printk("space_before: |%8u| |%8x|\n", 12345, 12345);
      printk("space_after:  |%-8u| |%-8x|\n", 12345, 12345);

Will produce the following output:

      none:         |12345| |3039|
      zero_before:  |00012345| |0000000000003039|
      space_before: |   12345| |            3039|
      space_after:  |12345   | |3039            |

Change-Id: I9c2d85a1790087d53b52b7713854adaf99282f09
Jira: ZEP-1599
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-04-21 11:06:16 +00:00
Tomasz Bursztyka a7e82666bc misc/printk: Add a function to get the current hook function.
This can be necessary at run-time if a switch of one console to
another has to be made, with the possibility to reinstall the former
hook at some point.

Change-Id: I60efc74b1c94953bdc2585b99cc4816c46715372
Signed-off-by: Tomasz Bursztyka <tomasz.bursztyka@linux.intel.com>
2017-01-27 12:35:52 +02:00
David B. Kinder ac74d8b652 license: Replace Apache boilerplate with SPDX tag
Replace the existing Apache 2.0 boilerplate header with an SPDX tag
throughout the zephyr code tree. This patch was generated via a
script run over the master branch.

Also updated doc/porting/application.rst that had a dependency on
line numbers in a literal include.

Manually updated subsys/logging/sys_log.c that had a malformed
header in the original file.  Also cleanup several cases that already
had a SPDX tag and we either got a duplicate or missed updating.

Jira: ZEP-1457

Change-Id: I6131a1d4ee0e58f5b938300c2d2fc77d2e69572c
Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-01-19 03:50:58 +00:00
Johan Hedberg 244a4dfe73 printk: Export _vprintk similar to how _prf is exported
There are some corner cases where direct access to the formatter
function is needed. Export _vprintk() so code can use it in a similar
way that _prf() can be directly used.

Change-Id: I9dfb68f87f310e900c662dc8beb320bb4ff7d8b2
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-11 04:26:05 +00:00
Johan Hedberg c899cd0d12 printk: Add APIs to print into strings instead of default output
These correspond to the libc snprintf and vsnprintf APIs.

Change-Id: If3944972ed95934a4967756593bb2932c3359b72
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-05 20:08:40 +00:00
Johan Hedberg 3ab60466de printk: Refactor to allow passing a parsing context around
Pass a parsing context around, allowing counting the number of
characters written, which is then returned in the return value of
printk(). This makes printk more similar to printf and prepares the
way to extend the implementation to support printing to strings.

Change-Id: Ib28a18a4f36fc58b98b228fd5763b2c05f5af7bc
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-12-05 20:08:39 +00:00
Szymon Janc bde20d5447 printk: Add basic support for width modifier and zero padding
This adds basic support for width modifier when printing integers.
Supported specifiers are u,i,d,x,X. Width '*' is not supported.
Flag '0' for left-pading number with zero is also supported.

examples:
printk("0x%x 0x%02x 0x%04x 0x%08x\n", 1, 1, 1, 1);
0x1 0x01 0x0001 0x00000001

printk("0x%x 0x%2x 0x%4x 0x%8x\n", 1, 1, 1, 1);
0x1 0x 1 0x   1 0x       1

This should make printk usable for pretty printing u8 and u16 integers.

Change-Id: I58fa869e9c295a052f97fbf052291ef4d132811e
Signed-off-by: Szymon Janc <szymon.janc@codecoup.pl>
2016-11-27 19:26:55 +00:00
Andrew Boie a811cc5085 printk: make _char_out globally accessible
This is to support a printf test case where we need to know
the existing value so we can chain it.

Change-Id: I671429aa7dab1391840f49f54cc6c23baccf265c
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2016-08-28 07:47:28 -04:00
Andrew Boie 4c64805336 printk: print leading '0x' for %p
Change-Id: I0140d1721ecaef47245e0fab61300c1dd44b9aff
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2016-08-28 07:47:28 -04:00
Andrew Boie 907a99933a printk: "support" some modifier codes
We now allow modifier codes h, l, and z, although at the
moment they are simply dropped. This is to allow us to warn on
incorrect printk() usage by the compiler. These arguments get
promoted to int when they are passed as arguments so this
may never need to be addressed, although there may be implications
for (future) support for systems with 16-bit integers.
We still don't print 64-bit integers properly. but this is
nothing new.

Change-Id: I112d1257c4ec70c3fa7ae65dc56a6076ff29a8c0
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2016-08-28 07:47:28 -04:00
Allan Stephens 1e03a8efc9 printk: Standardize support for %%
Tweaks printk() internals to avoid unnecessary special case handling
of %% formatting.

Change-Id: I816b04b458f416a45fd06b5a7b3bebf27453c722
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-02-05 20:24:36 -05:00
Allan Stephens a1d47ba539 printk: Add support for %c
printk() now supports format strings containing %c.

Change-Id: I3de290db59cb1ae5a65a928842e7a74bbf8ecce8
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-02-05 20:24:36 -05:00
Javier B Perez Hernandez f7fffae8aa Change BSD-3 licenses to Apache 2
Change all the Intel and Wind River code license from BSD-3 to Apache 2.

Change-Id: Id8be2c1c161a06ea8a0b9f38e17660e11dbb384b
Signed-off-by: Javier B Perez Hernandez <javier.b.perez.hernandez@linux.intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-02-05 20:24:29 -05:00
Andrew Boie af7d3fb116 misc: remove old printk() stub
It was never being used due to the obj-$(CONFIG_PRINTK) in the
Makefile, and the new method using a static inline function in
the printk.h header performs better since there won't be
function call overhead.

Change-Id: I7536515432e274fde2099eb04d4c1fb0e9d380ef
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2016-02-05 20:15:20 -05:00
Peter Mitsis 8ff6904084 Remove references to BSP from misc/ directory
Replaces references to obsolete BSP terminology with platforms.

Change-Id: Id5f7760e2d14353a19c020afd8f87d9033ddbf69
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:14:43 -05:00
Anas Nashif 212146d5b4 doxygen: fix comments in printk.c
Change-Id: Ia76b2ef1798999057d8b3a8f1e100e930702d179
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:14:39 -05:00
Anas Nashif f367f071b6 doxygen: add @brief and capitalize
Remove function name from comment and add @brief instead.
Also capitilize first letter.

Change-Id: Ib708b49bf02e5bc89b0066637a55874e659637e0
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:14:33 -05:00
Anas Nashif 1362e3c162 doxygen: RETURNS: -> @return
Previous comment style used RETRURNS:, use @return to comply
with javadoc style.

Change-Id: Ib1dffd92da1d97d60063ec5309b08049828f6661
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:14:32 -05:00
Anas Nashif ea0d0b220c doxygen: change comment style to match javadoc
The change replaces multiple asterisks to ** at
the beginning of comments and adds a space before
the asterisks at the beginning of lines.

Change-Id: I7656bde3bf4d9a31e38941e43b580520432dabc1
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:14:32 -05:00
Yonattan Louise 5b5f4eb948 Fix checkpatch issue - WARNING:LINE_SPACING
Adding a line after variable declaration in order to comply with
the defined coding style.

Change-Id: Id41af88404bd37227bfd59a2d71ce08d0d6ce005
Signed-off-by: Yonattan Louise <yonattan.a.louise.mendoza@intel.com>
2016-02-05 20:13:39 -05:00
Inaky Perez-Gonzalez 8ddf82cf70 First commit
Signed-off-by:  <inaky.perez-gonzalez@intel.com>
2015-04-10 16:44:37 -07:00