Commit graph

265 commits

Author SHA1 Message Date
Andrew Boie
17ce822ed9 app_shmem: create generic libc partition
We need a generic name for the partition containing
essential C library globals. We're going to need to
add the stack canary guard to this area so user mode
can read it.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-22 18:50:43 -05:00
Andrew Boie
41f6011c36 userspace: remove APPLICATION_MEMORY feature
This was never a long-term solution, more of a gross hack
to get test cases working until we could figure out a good
end-to-end solution for memory domains that generated
appropriate linker sections. Now that we have this with
the app shared memory feature, and have converted all tests
to remove it, delete this feature.

To date all userspace APIs have been tagged as 'experimental'
which sidesteps deprecation policies.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-08 07:04:30 -05:00
Andrew Boie
4b4f773484 libc: set up memory partitions
* Newlib now defines a special z_newlib_partition containing
  all globals relevant to newlib. Most of these are in libc.a
  with a heap tracking variable in newlib's hooks.

* Both C libraries now expose a k_mem_partition containing the
  bounds of the malloc heap arena. Threads that want to use
  libc malloc() will need to add this to their memory domain.

* z_newlib_get_heap_bounds has been removed, in favor of the
  memory partition for the heap arena

* ztest now includes the C library partitions in its memory
  domain.

* The mem_alloc test now runs in user mode to prove that this
  all works for both C libraries.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-08 07:04:30 -05:00
Andy Ross
b69d0da82d arch/x86_64: New architecture added
This patch adds a x86_64 architecture and qemu_x86_64 board to Zephyr.
Only the basic architecture support needed to run 64 bit code is
added; no drivers are added, though a low-level console exists and is
wired to printk().

The support is built on top of a "X86 underkernel" layer, which can be
built in isolation as a unit test on a Linux host.

Limitations:

+ Right now the SDK lacks an x86_64 toolchain.  The build will fall
  back to a host toolchain if it finds no cross compiler defined,
  which is tested to work on gcc 8.2.1 right now.

+ No x87/SSE/AVX usage is allowed.  This is a stronger limitation than
  other architectures where the instructions work from one thread even
  if the context switch code doesn't support it.  We are passing
  -no-sse to prevent gcc from automatically generating SSE
  instructions for non-floating-point purposes, which has the side
  effect of changing the ABI.  Future work to handle the FPU registers
  will need to be combined with an "application" ABI distinct from the
  kernel one (or just to require USERSPACE).

+ Paging is enabled (it has to be in long mode), but is a 1:1 mapping
  of all memory.  No MMU/USERSPACE support yet.

+ We are building with -mno-red-zone for stack size reasons, but this
  is a valuable optimization.  Enabling it requires automatic stack
  switching, which requires a TSS, which means it has to happen after
  MMU support.

+ The OS runs in 64 bit mode, but for compatibility reasons is
  compiled to the 32 bit "X32" ABI.  So while the full 64 bit
  registers and instruction set are available, C pointers are 32 bits
  long and Zephyr is constrained to run in the bottom 4G of memory.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-01-11 15:18:52 -05:00
Alistair Francis
41dfc4d478 libc: riscv: Fix the RISC-V ifdef
Following the standard GCC RISC-V convetion use __riscv for the RISC-V
specific define:
41d6b10e96/gcc/config/riscv/riscv-c.c (L37)

Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2019-01-03 18:15:53 -05:00
Paul Sokolovsky
4a04ed20fd lib/fdtable: Add ioctl() and fcntl() implementations
ioctl() just dispatches to the corresponding vmethod of an fd.
fcntl() handles fdtable-level operations (so far doesn't handle
actually, returning "not implemented" error), and forwards
fd-specific operations to ioctl vmethod just the same (i.e.
ioctl and fcntl operations share the same namespace, but otherwise
disjoint).

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-12-14 13:21:31 +02:00
Patrik Flykt
186fb94bcb lib: Add 'U' to unsigned variable assignments
Add 'U' to a value when assigning it to an unsigned variable.
MISRA-C rule 7.2

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-12-04 22:51:56 -05:00
Flavio Ceolin
1f176e485a libc: ctype: Fix isxdigit function
The last check was never true since 'a' > 'A'.
So, things like isxdigit(Z) would return true.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-11-29 15:28:21 -08:00
Andrzej Głąbek
20202902f2 dts_fixups: Use DT_ prefix in all defined labels not related to Kconfig
These changes were obtained by running a script  created by
Ulf Magnusson <Ulf.Magnusson@nordicsemi.no> for the following
specification:

1. Read the contents of all dts_fixup.h files in Zephyr
2. Check the left-hand side of the #define macros (i.e. the X in
   #define X Y)
3. Check if that name is also the name of a Kconfig option
   3.a If it is, then do nothing
   3.b If it is not, then replace CONFIG_ with DT_ or add DT_ if it
       has neither of these two prefixes
4. Replace the use of the changed #define in the code itself
   (.c, .h, .ld)

Additionally, some tweaks had to be added to this script to catch some
of the macros used in the code in a parameterized form, e.g.:
- CONFIG_GPIO_STM32_GPIO##__SUFFIX##_BASE_ADDRESS
- CONFIG_UART_##idx##_TX_PIN
- I2C_SBCON_##_num##_BASE_ADDR
and to prevent adding DT_ prefix to the following symbols:
- FLASH_START
- FLASH_SIZE
- SRAM_START
- SRAM_SIZE
- _ROM_ADDR
- _ROM_SIZE
- _RAM_ADDR
- _RAM_SIZE
which are surprisingly also defined in some dts_fixup.h files.

Finally, some manual corrections had to be done as well:
- name##_IRQ -> DT_##name##_IRQ in uart_stm32.c

Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
2018-11-13 10:44:42 -06:00
Flavio Ceolin
19301849e8 lib: Normalize if/else statements
Enforce braces in all if/else statements. This is part of MISRA-C rule
15.6.

MISRA-C rule 15.6

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-11-06 16:20:15 -05:00
Paul Sokolovsky
b2fd1a27ac libc: newlib: libc-hooks: s/CONFIG_POSIX_FS/CONFIG_POSIX_API/
read/write/etc. are defined in case CONFIG_POSIX_API is defined, and
we shouldn't provide duplicates.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-11-04 22:04:11 +01:00
Kumar Gala
54bdd7aee0 Revert "libc: minimal: Add error codes for key management"
This reverts commit 25fb2302f1.

The bluetooth l2cap code was using these errno values but changed to
using more standard EPERM instead, so lets remove the defines since
nothing uses them.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-10-29 10:12:23 +00:00
Paul Sokolovsky
52aa8061c0 libc: newlib: libc-hooks: Consistently use const void* as arg to write
write() function is not supposed to change buffer passed to it, so
propagate const pointer param to all write-like functions used/defined
in this file.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-10-22 15:01:12 +01:00
Paul Sokolovsky
5955996e7a libc: minimal: fcntl.h: Fix include guards for the current path
The file was moved, but include guards still referred to the old
path.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-10-10 16:38:13 -04:00
Paul Sokolovsky
c80f61a1a7 libc: minimal: Add dummy sys/stat.h [REVERTME]
Some third-party components include this file without really needing
any symbols from it. Presence of this file allows to build them
against minimal libc, whereas previously they forced Newlib.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-10-10 13:31:00 -04:00
Paul Sokolovsky
8e1d78c357 libc: minimal: Make fcntl.h be at top level, not sys/fcntl.h
Placing it at sys/fcntl.h was due to mimicking internal newlib's
layout, but what we need is this file at the standard location,
for reuse.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-10-09 15:44:59 -04:00
Anas Nashif
f8d439d36e kernel: move malloc handling to new logger
Make this part of the kernel log domain, it is used by the kernel.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-10-08 17:49:12 -04:00
Mark Ruvald Pedersen
d67096da05 portability: Avoid void* arithmetics which is a GNU extension
Under GNU C, sizeof(void) = 1. This commit merely makes it explicit u8.

Pointer arithmetics over void types is:
 * A GNU C extension
 * Not supported by Clang
 * Illegal across all ISO C standards

See also: https://gcc.gnu.org/onlinedocs/gcc/Pointer-Arith.html

Signed-off-by: Mark Ruvald Pedersen <mped@oticon.com>
2018-09-28 07:57:28 +05:30
Nils Montenegro
25fb2302f1 libc: minimal: Add error codes for key management
This adds EKEY* codes, as defined by Linux, using the same numeric
values as Linux.

Signed-off-by: Nils Montenegro <nils.montenegro@nordicsemi.no>
2018-09-26 00:55:21 +05:30
Flavio Ceolin
4218d5f8f0 kernel: Make If statement have essentially Boolean type
Make if statement using pointers explicitly check whether the value is
NULL or not.

The C standard does not say that the null pointer is the same as the
pointer to memory address 0 and because of this is a good practice
always compare with the macro NULL.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-18 13:57:15 -04:00
Flavio Ceolin
67ca176754 headers: Fix headers across the project
Any word started with underscore followed by and uppercase letter or a
second underscore is a reserved word according with C99.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-17 15:49:26 -04:00
Flavio Ceolin
da49f2e440 coccicnelle: Ignore return of memset
The return of memset is never checked. This patch explicitly ignore
the return to avoid MISRA-C violations.

The only directory excluded directory was ext/* since it contains
only imported code.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-14 16:55:37 -04:00
Paul Sokolovsky
da4c00c021 libc: minimal: Add sys/fcntl.h enough to compile net/lib/sockets
Contains defines enough to compile BSD Sockets subsystem. Values are
compatible with Newlib.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-09-13 14:29:17 -04:00
Flavio Ceolin
5c79101f30 constants: Use uppercase to indicate long
Several code guidelines recommend using uppercase L instead of letter
l (ell) because it can easily be confused with the digit 1 (one).

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-08-16 19:47:41 -07:00
Ulf Magnusson
8cf8db3a73 Kconfig: Use a short, consistent style for prompts
Consistently use

    config FOO
            bool/int/hex/string "Prompt text"

instead of

    config FOO
            bool/int/hex/string
            prompt "Prompt text"

(...and a bunch of other variations that e.g. swapped the order of the
type and the 'prompt', or put other properties between them).

The shorthand is fully equivalent to using 'prompt'. It saves lines and
avoids tricking people into thinking there is some semantic difference.

Most of the grunt work was done by a modified version of
https://unix.stackexchange.com/questions/26284/
how-can-i-use-sed-to-replace-a-multi-line-string/26290#26290, but some
of the rarer variations had to be converted manually.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-08-15 04:10:10 -07:00
Andrew Boie
3641c25df9 libc: minimal: fix calloc()
calloc() wasn't zeroing out the allocated memory as it
is supposed to.

Fixes: #9221

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-08-01 19:40:57 -07:00
Andrew Boie
12e6aadcb0 lib: newlib: add read/write syscalls
The read/write implementations call directly into the console drivers
using the hook mechanism, causing faults if invoked from user mode.

Add system calls for read() and write() such that we do a privilege
elevation first.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-07-25 14:57:51 -04:00
Andrew Boie
bc94cc1832 libc: minimal: add console system calls
The stdout console implementations for minimal libc call directly into
the various console drivers (depending on what specifc hooks are
registered) causing faults when invoked from user mode. This happens,
for example, when using printf() which eventually ends up calling
fputc().

The proper solution is to ensure privileges have been elevated before
the _stdout_hook is called. This was already done for printk().

puts() and fputs() have now been re-defined in terms of the
fputc() and fwrite() functions, which are now system calls.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-07-25 14:57:51 -04:00
Andrew Boie
6a8649f806 libc: minimal: add malloc functions
We base the malloc() implementation on a common sys_mem_pool whose
size is specified by Kconfig.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-07-20 11:41:08 -07:00
Andrew Boie
7f4d006959 kernel: fix errno access for user mode
The errno "variable" is required to be thread-specific.
It gets defined to a macro which dereferences a pointer
returned by a kernel function.

In user mode, we cannot simply read/write the thread struct.
We do not have thread-local storage mechanism, so for now
use the lowest address of the thread stack to store this
value, since this is guaranteed to be read/writable by
a user thread.

The downside of this approach is potential stack corruption
if the stack pointer goes down this far but does not exceed
the location, since a fault won't be generated in this case.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-07-19 16:44:59 -07:00
Kumar Gala
16ff8ca2c2 libc: newlib: Enable extended linux errno defines
We utilize defines like -ESHUTDOWN in the network stack.  To support
this errno value with newlib we need to enable
__LINUX_ERRNO_EXTENSIONS__.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-07-16 11:33:07 -05:00
Kumar Gala
e66da3f9e0 libc: minimal: Add support for %F conversion specifiers
For some reason %F wasn't supported initially.  Its simple enough to
handle the case difference in infinity and NaN handling to add support
for %F.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-07-12 14:57:52 -05:00
Kumar Gala
409c9e751f libc: minimal: Fix support for -nan
We were only handling the sign bit for infinity, but not NaN.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-07-12 14:57:52 -05:00
Kumar Gala
96ea7ab7d1 libc: minimal: Fix handling of %f conversion specifiers for inf & nan
The C standard says that %f should use '[-]inf' or '[-]infinity' (which
style is implementation defined) for infinity handling and '[-]nan' for
NaN.

We where adding a '+' and had the wrong case for 'inf' and 'nan'.

Before -> After

+INF -> inf
-INF -> -inf
 NaN -> nan

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-07-12 14:57:52 -05:00
Kumar Gala
e6f4f623b7 libc: minimal: Fix handling of floating point exponent
For %{e,E,g,G} conversion specifiers the C standard says the exponent
contains at least two digits, and only as many digits are necessary.  So
instead of 1.234000e-001 we should have 1.234000e-01.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-07-12 14:57:52 -05:00
Ulf Magnusson
0785b79ebe lib: kconfig: Remove redundant 'default n' properties
Bool symbols implicitly default to 'n'.

A 'default n' can make sense e.g. in a Kconfig.defconfig file, if you
want to override a 'default y' on the base definition of the symbol. It
isn't used like that on any of these symbols though.

Also simplify the default on STDOUT_CONSOLE. Defaults can be arbitrary
expressions, not just fixed values.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-06-22 15:12:48 -04:00
Leandro Pereira
2d71236a36 lib: libc: minimal: Get rid of the bit (256-byte) charmap table
The charmap table used by strncasecmp() not only used precious 256
bytes of ROM, it also had wrong mappings outside the ASCII range
(123..218).

Rewrite strncasecmp() to call tolower() instead; might be a tiny wee
little bit slower than the current version, but it's not used in any
performance-sensitive parts of the code to justify the waste.

This reduces the ROM footprint for the ws_echo_server sample by ~224
bytes.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2018-06-19 14:33:34 -07:00
Paul Sokolovsky
6245d6c47b libc: minimal: Add typedefs for "least" types
Based on feedback integrating with TI SimpleLink HAL.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-06-18 10:23:05 -04:00
Yasushi SHOJI
2e0af08e55 build: remove unused CMakeLists.txt
lib/libc/minimal/source/CMakeLists.txt and
lib/libc/minimal/source/stdout/CMakeLists.txt was introduced in
12f8f7616 but it is not used by the build system.  CMakeLists.txt in
the parent dir lib/libc/minimal/CMakeLists.txt adds C files to the
target with the lines like:

    ${CMAKE_CURRENT_SOURCE_DIR}/source/stdlib/atoi.c
    ${CMAKE_CURRENT_SOURCE_DIR}/source/stdlib/strtol.c

To make other empty CMakeLists.txt explicit, this commit adds a
comment line to them.

Signed-off-by: Yasushi SHOJI <y-shoji@ispace-inc.com>
2018-06-14 15:02:02 -04:00
Sebastian Bøe
d94231f66e cmake: libc: minimal: Move sources from 'app' to a new CMake library
The minimal libc source files have been added to 'app'. The Zephyr
build system should not be adding source files to the 'app' library
unless necessary.

This patch creates a new Zephyr CMake Library in lib/libc/minimal and
adds the sources to it.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-06-11 17:11:00 -04:00
Kumar Gala
dd78ab0513 newlib: Fix typo in Kconfig related to NEWLIB_LIBC_ALIGNED_HEAP_SIZE
When we introduced NEWLIB_LIBC_ALIGNED_HEAP_SIZE in commit
42a2c96422.  We accidently had the Kconfig
symbol depend on CONFIG_MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT the leading
'CONFIG_' shouldn't exist.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-05-23 12:10:15 -04:00
Leandro Pereira
0f1d30aa67 lib: posix: Do not redefine PATH_MAX in unistd.h
This constant should be defined in limits.h.  Define it in limits.h in
the minimal libc, and use the definition found in newlib's includes.
Values in newlib includes range from 1024 to 4096.

The rationale is that all code should use the same value; having
buffers specified with different sizes will lead to interoperability
and out of bounds array writes.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2018-05-19 06:59:40 +03:00
Ramakrishna Pallala
eb0aaca64d lib: posix: Add Posix Style File System API support
Add IEEE 1003.1 Posix Style file system API support.
These API's will internally use corresponding Zephyr
File System API's.

Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com>
2018-05-18 13:32:36 +03:00
Florian Vaussard
2514f3c837 libc: minimal: fix fwrite()
The implementation of fwrite() in the minimal libc does not increment
the source pointer, and thus always print the same character.

Signed-off-by: Florian Vaussard <florian.vaussard@gmail.com>
2018-05-17 07:53:44 -07:00
Andrew Boie
42a2c96422 newlib: fix heap user mode access for MPU devices
MPU devices that enforce power-of-two alignment now
specify the size of the buffer used for the newlib heap.
This buffer will be properly aligned and a pointer
exposed in a kernel header, such that it can be added
to a user thread's memory domain configuration if
necessary.

MPU devices that don't have these restrictions allocate
the heap as normal.

In all cases, if an MPU/MMU region needs to be programmed,
the z_newlib_get_heap_bounds() API will return the necessary
information.

Given how precious MPU regions are, no automatic programming
of the MPU is done; applications will need to do this as
needed in their memory domain configurations.

On x86, the x86 MMU-specific code has been moved to arch/x86
using the new z_newlib_get_heap_bounds() API.

Fixes: #6814

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-05-10 15:09:02 -07:00
Andrew Boie
fc76839b6b x86: grant user mode access to newlib heap
Newlib uses any RAM between _end and the bounds of physical
RAM for the _sbrk() heap. Set up a user-writable region
so that this works properly on x86.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-05-09 16:36:36 -07:00
Paul Sokolovsky
a85321229a newlib: libc-hooks: Print "exit" message with newline
Calling POSIX exit() function in Zephyr w/newlib leads to printing
"exit" to stdout followed by infinite loop. That message was
printed without a newline though, leading to confusing artifacts
in the console output.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-05-05 20:13:46 -04:00
Anas Nashif
7ee8bb9677 build: deprecate ZEPHYR_GCC_VARIANT
We want to support other toolchain not based on GCC, so the variable is
confusing, use ZEPHYR_TOOLCHAIN_VARIANT instead.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-02-13 07:44:45 -08:00
Paul Sokolovsky
323e8cf069 libc: Kconfig: Enable STDOUT_CONSOLE by default if NEWLIB_LIBC.
Enable stdio to work by default if Newlib is used as libc - it's
reasonable expectation that if full-fledged libc (like Newlib) is
selected, then printf() works out of the box.

Fixes: #5566

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-02-05 07:05:12 -08:00
Vincent Veron
6083939174 lib: add abs function to minimal libc
Add abs function to the minimal libc. This is present in
NEWLIB_LIBC, but adding it here avoid to make a dependency
with NEWLIB_LIBC.

Signed-off-by: Vincent Veron <vincent.veron@st.com>
2018-01-23 10:14:49 -06:00
Sebastian Bøe
15ca6da4c8 cmake: Re-introduce support for CROSS_COMPILE
CROSS_COMPILE is a KBuild feature that was dropped during the CMake
migration. It is now re-introduced. Documentation for it is still
lacking, but at least it now behaves as expected.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-01-12 08:37:41 -05:00
Paul Sokolovsky
84e3d3e7e8 libc: Kconfig: Move STDOUT_CONSOLE from subsys/debug
This option is clearly not related to debugging, but affects libc
features.

Fixes: #5566

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2018-01-11 12:47:10 -05:00
ce3b2edef3 libc: add EILSEQ for use in reporting checksum failure.
This code is commonly used in the Linux kernel for reporting a
retryable error like a failed CRC.  This name and value is already
present in Linux and newlib.

Signed-off-by: Michael Hope <mlhx@google.com>
2018-01-07 14:12:56 -05:00
Anas Nashif
95cd063280 libc: some architectures do not require baremetal libc
When building a native application, we use the host provided libc, so do
not build minimal libc or newlib.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-27 14:16:08 -05:00
Anas Nashif
429c2a4d9d kconfig: fix help syntax and add spaces
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-12-13 17:43:28 -06:00
Sebastian Bøe
0829ddfe9a kbuild: Removed KBuild
Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
Sebastian Bøe
12f8f76165 Introduce cmake-based rewrite of KBuild
Introducing CMake is an important step in a larger effort to make
Zephyr easy to use for application developers working on different
platforms with different development environment needs.

Simplified, this change retains Kconfig as-is, and replaces all
Makefiles with CMakeLists.txt. The DSL-like Make language that KBuild
offers is replaced by a set of CMake extentions. These extentions have
either provided simple one-to-one translations of KBuild features or
introduced new concepts that replace KBuild concepts.

This is a breaking change for existing test infrastructure and build
scripts that are maintained out-of-tree. But for FW itself, no porting
should be necessary.

For users that just want to continue their work with minimal
disruption the following should suffice:

Install CMake 3.8.2+

Port any out-of-tree Makefiles to CMake.

Learn the absolute minimum about the new command line interface:

$ cd samples/hello_world
$ mkdir build && cd build
$ cmake -DBOARD=nrf52_pca10040 ..

$ cd build
$ make

PR: zephyrproject-rtos#4692
docs: http://docs.zephyrproject.org/getting_started/getting_started.html

Signed-off-by: Sebastian Boe <sebastian.boe@nordicsemi.no>
2017-11-08 20:00:22 -05:00
Thiago Macieira
034b458141 libc: Add support for static_assert
The C11 standard requires this. From 7.2 "Diagnostics <assert.h>"
paragraph 1:
> The header <assert.h> defines the assert and static_assert macros...

paragraph 3:
> The macro
>     static_assert
> expands to _Static_assert.

Since static_assert is a keyword in C++11, don't define it if C++.

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2017-10-25 10:43:38 -07:00
Thiago Macieira
eb7848a1df libc: Make no-debug assert() conform to C requirements
The C standard requires assert() to be a void result, so you
could write something like:

  return assert(x), x;

From the C11 standard (7.2 Diagnostic <assert.h>):
> If NDEBUG is defined as a macro name at the point in the source file
> where <assert.h> is included, the assert macro is defined simply as
>    #define assert(ignore) ((void)0)

Signed-off-by: Thiago Macieira <thiago.macieira@intel.com>
2017-10-25 10:43:38 -07:00
Kumar Gala
090a6d4f4e libc: minimal: Add typedefs for fast types
Some of the HALs in ext require fast types to be defined.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-10-19 12:16:11 -05:00
Aska Wu
1f7a6766d3 newlib: xtensa: Fix a newlib link error
xtensa linker script defines "_heap_sentry" but newlib references
"__heap_sentry".

Signed-off-by: Aska Wu <aska.wu@linaro.org>
2017-08-10 09:33:13 -05:00
Leandro Pereira
07d8ef008a libc: minimal: Add empty sys/cdefs.h
This header is included by some files provided by ESP-IDF.  Nothing
from this header file is actually used: it's only being added allow
things to compile with the minimal libc.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-06-21 12:35:49 -04: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
614db776dc libc: minimal: fix xtensa build
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-05-19 16:33:16 -04:00
Paul Sokolovsky
8cc6f6ddd6 kernel: errno: Use per-thread accessor function compatible with Newlib
Newlib names this function __errno(), so if we want Zephyr to work
with Newlib seamlessly, it's better to just follow Newlib's naming
convention for Zephyr's own minimal libc.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2017-05-10 20:54:56 -04:00
Kumar Gala
91e9f87499 libc: attribute minimal libc printf style functions with __printf_like
Add __printf_like attribute to printf style functions in minimal libc to
enable the compiler checking this provides.  We fixup the associated
issues that are now found by utilizing these checks.

Change-Id: I74ac0d0345782463d9fb454f7161d6b4af211ba5
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-03-02 08:46:30 -06:00
Leandro Pereira
1b8f824975 libc: Add isalnum() to ctype.h
The isalnum() primitive is used by the NATS protocol implementation to
vaildate some of the inputs.

This uses primitives that were already in place.

Change-Id: Ib53eeb7ae002a42f5b6aa8d4fc61baca029a042d
Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-02-17 20:39:44 +00:00
Anas Nashif
15a6598691 Merge "Merge remote-tracking branch 'origin/core'" 2017-02-15 04:33:25 +00:00
Sergio Rodriguez
f054d3e897 libc/include: Adding time.h
Dummy time.h to fulfill the compilations requirements of certain
libraries i.e. mbedTLS

Change-Id: I07e66dbf07337b935dabe9eecdf1be3850bbf394
Signed-off-by: Sergio Rodriguez <sergio.sf.rodriguez@intel.com>
2017-02-14 08:30:35 +02:00
Mazen NEIFER
44a98fb5fd Xtensa port: Fixed defintion of MAX_HEAP_SIZE, thus, compilation of new_lib.
Xtensa linker script defines _heap_sentry which helps computing the heap size.

Change-Id: Ic35db3c98aaaebe575370fb5479de1a58e6e441e
Signed-off-by: Mazen NEIFER <mazen@nestwave.com>
2017-02-13 11:39:02 -08:00
Anas Nashif
cebc7f95aa newlib: make sure the chain of includes has generated_dts_board.h
Change-Id: I2021a30e1bc16e3eb9fdcc793b908bd0e610d01d
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-02-11 07:00:39 +00:00
Andy Gross
c30b400a16 libc-hooks: Fix include file for arch ARM
This patch adds in the include to get the CONFIG_SRAM definitions on
systems which are using device tree generation.

Change-Id: Ie61efbcdfc900a2c682a2fb8bbaecb61071a20f8
Signed-off-by: Andy Gross <andy.gross@linaro.org>
2017-02-10 23:42:31 +00:00
Andrew Boie
c2a91b1b2e libc: minimal: rename private macro
As it turns out Xtensa SDK headers also define _Restrict, causing
havoc. As this was intended to be a private macro, rename it to something
less likely to cause a collision.

Change-Id: I0a7501a1af8cf87efb096872a91a7b44bd2bbdca
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-02-04 19:22:07 +00:00
Marcus Shawcroft
458e2ed133 libc/minimal: Fix definition of ssize_t
Each GCC target backend is at liberty to define its own SIZE_TYPE. GCC
uses this for various purposes, not lease it drives the machinery that
spits out format specifier diagnostics when format specifiers are
applied to objects with inappropriate type.  GCC exposes the current
definition of SIZE_TYPE via the preprocessor symbol __SIZE_TYPE__.
The GCC build processes also generates various standard library header
files that directyle expose stanard types in a form consistent with
the current configuration of GCC.  Conventionally standard library
build processes (for glibc and newlib) pick up the header files
generated by the GCC build.

In the minimal libc we have no such build process, we don't pick up
the header files that the GCC build process generated.  Instead we
define our own alternative header files and align them with GCC
manually.

The current definition of ssize_t in minimal libc is out of step with
GCC which means that any use of the %z[du] format modifier will issue
a diagnostic.

We replace the open coded architecture detection in minimal libc and
use GCCs __SIZE_TYPE__ directly.

Change-Id: I63b5e17bee4f4ab83d49e492e58efd3bafe76807
Signed-off-by: Marcus Shawcroft <marcus.shawcroft@arm.com>

tests: fs: Fix printf warning when using newlib

Current code uses %ld format specifier to print data of
type ssize_t. This causes type warnings when built with
newlib. The correct format specifier to be used for
ssize_t is %zd.

Change-Id: I02a3c628e3d6e8a36a09cd694220406d8faf1730
Signed-off-by: Ramesh Thomas <ramesh.thomas@intel.com>
2017-02-01 13:57:43 -08: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
Anas Nashif
9f418fe944 libc: add support for risc v
Change-Id: Iaaf87ef48057c52478816771836d8d40b2b05554
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-01-13 19:57:19 +00:00
Jean-Paul Etienne
716d25e1e2 libc-hooks: added USED_RAM_SIZE and MAX_HEAP_SIZE definitions for riscv32
added USED_RAM_SIZE and MAX_HEAP_SIZE definitions for
SOC_RISCV32_QEMU and SOC_RISCV32_PULPINO.

Otherwise, not passing sanitycheck

Change-Id: Ia32b12e1694dc472e9f7f9eb10c5f2e12e928c3a
Signed-off-by: Jean-Paul Etienne <fractalclone@gmail.com>
2017-01-13 19:56:44 +00:00
Anas Nashif
fe958df4dd libc: rework libc selection and reduce Kconfigs
Moved all libc Kconfigs to where the code is and remove the default
Kconfig for selecting the minimal libc. Minimal libc is now the default
if nothing else is configured in.

Removed the options for extended libc, this obviously was restricting
features in the minimal libc without a good reason, most of the
functions are available directly when using newlib, so there is no
reason why we need to restrict those in minimal libc.

Jira: ZEP-1440
Change-Id: If0a3adf4314e2ebdf0e139dee3eb4f47ce07aa89
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-12-15 22:31:28 +00:00
Inaky Perez-Gonzalez
b53e6d7774 libc/minimal: snprintf(): KILL negative len parameter
snprintf() implements the ability to foce a negative value through the
(unsigned) size_t len parameter to allow the formatter to use a
maximum size string.

This is point less, we don't have as much memory and this is a recipe
for all kinds of vulnerabilities.

Kill the whole thing, the testcase it represents and thank Coverity
for finding this thing. Whatever use it had before, it has no more.

Change-Id: If422246548664699d8aa328a1b9304ef13cab7ea
Coverity-ID: 131625
Coverity-ID: 131626
Signed-off-by: Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
2016-11-28 20:49:37 +00:00
Inaky Perez-Gonzalez
11a52750d3 libc: remove useless code in _prf()
Coverity reported a block of deadcode in _prf() that seems to be a
leftover carcass from a previous time. Replaced with a comment in case
someone decides it was needed back.

Change-Id: Id97e84f3279f807e6188371f27f6af157e6d5038
Coverity-ID: 131631
Signed-off-by: Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
2016-11-23 00:57:48 +00:00
Inaky Perez-Gonzalez
c41d88fd11 libc: atoi() avoid fallthroughs in switch cases
This is a tentative fix for CID 93807, a valid Coverity warning;
however the code is valid too.

We can choose to silence the warning or rewrite the code in a way that
makes it more verbose but keeps Coverity happy.

Coverity complains about doing an implicit fallthrough in switch case
statement. I prefer patching the code to make it explicit, as the
compiler will optimize out, to avoid having to constantly filter out
the checker's warnings.

Coverity-CID: 93807
Change-Id: I7be334d48567bf52fc2b21de043310e0f73b72db
Signed-off-by: Inaky Perez-Gonzalez <inaky.perez-gonzalez@intel.com>
2016-11-16 22:05:53 +00:00
Jaakko Hannikainen
24a2fb19f9 lib: Add implementation for strrchr
Signed-off-by: Jaakko Hannikainen <jaakko.hannikainen@intel.com>
Change-Id: I57c549fae0fa8b2321794e9256da63b0a2fe6eaf
2016-11-04 16:53:50 +00:00
Anas Nashif
c83e6a1f48 libc: define EWOULDBLOCK to be the same as EAGAIN
EWOULDBLOCK is an old error code from BSD. Not much uses it, and on basically
all modern systems it's defined to the same value as EAGAIN, which is the
System V value for the same condition.

Jira: ZEP-982
Change-Id: I5435ce55fa47f5bd2fac5d881b5b195b025f48a2
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-10-03 02:29:42 +00:00
Qiu Peiyang
c53fe299c0 libc: replace null.h and size_t.h with stddef.h
According to commit b71a8a4591 and Jira: ZEP-733
(libc: remove stddef.h which is provided by the compiler),
the stddef.h in zephyr code is removed and it's provided
by the compiler. The original stddef.h includes two head
files, null.h and size_t.h, which are also useless now.
So remove these two deprecated files, in case conflicting
definition.

Change-Id: Ie7163fdbd23c32759425b50f3deff2a57cc051a9
Signed-off-by: Qiu Peiyang <peiyangx.qiu@intel.com>
2016-09-13 10:21:10 +08:00
Andy Ross
5729235b57 libc/printf: Use compiler-provided 64 bit math, phase 2
Remove the function wrappers around the 64 bit math and just use C
syntax natively, combining ops where appropriate (e.g. there was a
sequence implementing "(x<<2+x)<<2" to do "multiply by 10").  The
_ldiv5 and _rlrshift routines are non-standard ops that provide useful
abstraction, so they remain as separate functions.

Change-Id: I4d83847348fdd7be09887b833c8ccbd2aa1e4182
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2016-09-10 00:49:01 +00:00
Andy Ross
d06eea4eda libc/printf: Use compiler-provided 64 bit math, phase 1
The _to_float() implementation had a somewhat kludgey hand-written 64
bit math implementation, which is unhelpful on Zephyr as all our
toolchains provide a working uint64_t runtime.  This is at best just
dupicated code from libgcc, and at worst less efficient.

This patch replaces the existing 64 bit minilibrary but keeps the
uint32_t[2] API as is for ease of validation and review.

One exception is _ldiv5, a specialized divide-by-five implementation.
The 64 bit division routines are large on some architectures (ARM and
ARC in particular), not pulled in by a default Zephyr build, and will
swamp the benefit from this patch.  So this includes a
refactored/improved _ldiv5 which leverages libgcc for multiword shifts
instead of just using raw division.

Note also the "noinline" attribute on _ladd().  This is a workaround
for an apparent compiler bug when built with -Og or -Os (hand-hacking
the Makefiles to build with -O0 works), perhaps due to my aliasing the
int array with a long long.  This will go away in phase 2.

Change-Id: I63e8c82dabe2bfaa75b63ddb59e5f11d51be538e
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2016-09-10 00:49:00 +00:00
Andy Ross
073cfddd0f libc/printf: Remove vestigial "full" parameter to _to_float()
The _to_float routine was apparently written to be able to take a 32
bit float bit representationa as well as a 64 bit double.  But in a
printf routine, that can never happen per the C standard (where floats
are always promoted to doubles in varargs context).

This was just hard-configured to 1 at the top of the file, and nothing
else in the project sets "DOUBLE" to try to change it.  Just remove
it.  If we ever want code to convert a float to a double in memory so
we can use this routine, we have it in libgcc.  Or even in hardware on
the FPU where available.

Change-Id: I796814c0fce3ce96faa34fde8da411a28c826699
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2016-09-10 00:49:00 +00:00
Andy Ross
a4537cb0d3 libc/printf: Unify & simplify number printing
Hex, octal and decimal all had separately implemented reduction loops
to generate strings.  With only a little work these can all be unified
to a single implementation that works with an arbitrary base.

Performance is probably a little lower owing to the fact that
hex/octal now requires a division per character, and the extra
"reverse the string" trick at the end of the conversion.  But code
size savings are substantial.

Change-Id: I11ff376aeca1483f974d328271e19918221b2a41
Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2016-09-10 00:48:59 +00:00
Anas Nashif
b71a8a4591 libc: remove stddef.h which is provided by the compiler
Jira: ZEP-733
Change-Id: I26ba720377826bfa662c61e46c0358f05218524b
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-09-09 11:57:41 +00:00
Johan Hedberg
65a8e3c1c9 libc: printf: Add support for 'z' length specifier
The 'z' length specifier is the appropriate one to be used with size_t
(%zu) and ssize_t (%zd) types. Having support for this in our libc
means that we can utilize the compiler format string checks
(__printf_like) without getting warnings of incorrect format
specifiers for size_t and ssize_t variables.

Change-Id: I73fec0145692e0a59934cab548caf24c1c16a3df
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-09-07 15:10:57 +00:00
Andrew Boie
ad9d5265c3 libc: minimal: add reduced inttypes.h
This implements a subset of the standard inttypes.h, based on what
other functionality exists in minimal libc.

Change-Id: Ib5685a6da13768ee46acbfca734d145f7018b9e0
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2016-08-28 11:33:15 +00:00
Carles Cufi
1980b7bb0f lib: Use offsetof() builtin with GCC
The default offsetof() implementation generates a warning
(variably modified <variable> at file scope) when used in
to define the size of an array. By using this builtin with
GCC we avoid the warning and make sure no variable-size
arrays are used.

Change-Id: Iae215f777241f7daaa061067230086dffaa8311d
Signed-off-by: Carles Cufi <carles.cufi@nordicsemi.no>
2016-08-27 18:29:27 +00:00
Maureen Helm
0a9e0d0a5e libc: Add assert.h to minimal libc
This is an adaptation of
net/ip/tinydtls/platform-specific/config-zephyr.h to allow external
imports such as KSDK to include assert.h.

Change-Id: I0afee37deb79447363037ba6b4bb9cdbc629be3a
Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2016-07-21 02:09:44 +00:00
Sergio Rodriguez
6d5981bf28 lib: Adding the strstr() function
The strstr function finds the first occurrence of a substring
in another string, null terminated strings are not compared, this
function is added for compability for porting other libraries (like
mbedtls)

Jira: ZEP-327

Origin: http://www.leidinger.net/freebsd/dox/libkern/html/d3/d29/
strstr_8c_source.html

Change-Id: I52aac218ce0bd86373ec60f5afc49a92c85f6319
Signed-off-by: Sergio Rodriguez <sergio.sf.rodriguez@intel.com>
2016-07-19 22:35:21 +00:00
Andrew Boie
00365c188c nios2: Kconfig: remove some unused config options
We get these out of system.h instead. A clause in libc-hooks.c
for newlib added since we don't get RAM size from
CONFIG_SRAM_BASE_ADDRESS.

Change-Id: Ic35113395b951f625e8e29658afe19c525037964
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2016-06-10 15:22:42 +00:00
Kumar Gala
7fdd4f758d newlib: Support both namespace protected & nonprotected stubs
Some variants of newlib build and expect namespace protected stubs
(typically having an underscore prefix).  To support such newlib variants
change all the stubs to the namespace protect version and use function
aliases to support the nonprotected namespace version.

Change-Id: I6a4162eca949afec96b152ffe6f60b87c4496c4d
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2016-06-09 16:22:28 +00:00
Kumar Gala
ab5614ed9e newlib: Drop _fstat implementation
We only need to implement fstat(), so drop the _fstat implementation and
have fstat() match the newlib docs for minimal implementation and only
set st_mode = S_IFCHR.

Change-Id: Iba9042707d1ee5975ab98293cfe20e2996b17c05
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2016-06-09 16:22:27 +00:00
Andrew Boie
3395211a0b newlib: treat x86 as the special case
Although it's unclear why x86 has a different naming convention,
this scales better.

Change-Id: I939b9d4d04b1833391304700a7c12c9c8607192f
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2016-05-09 18:09:29 +00:00
Bogdan Davidoaia
c2216c7088 libc: newlib: fix RAM config names for ARC
The RAM config symbols need to be updated as they were named by the
commit:
	1a1f7fd arc: make SRAM/DCCM values configurable

Change-Id: Ieeb06de2f77b4c9e10a0bc32d8318834ce150f5e
Signed-off-by: Bogdan Davidoaia <bogdan.m.davidoaia@intel.com>
2016-05-05 14:08:50 +00:00
Andrew Boie
9433895954 nios2: basic build, non-functional
Basic build framework for Nios2. Everything is stubbed out,
we just want to have a build going so that we can start to
parallelize implementation tasks.

This patch is not intended to be functional, but should be
able to produce a binary for all the nanokernel-based
sanity checks.

Change-Id: I12dd8ca4a2273f7662bee46175822c9bbd99202a
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2016-05-03 23:18:45 +00:00
Benjamin Walsh
f557d71b52 libc: add strncat() to minimal libc
Change-Id: I0a44e1bb80c815ff89d8c9648d6e5db70e911fd2
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-04-16 05:29:21 +00:00
Peter Mitsis
7f14e706ec printf: Limit width modifier to [0..MAXFLD]
When capping the the absolute value of the width modifier in printf(),
it must first be cast to an 'unsigned'. This stems from the fact that
in two's complement, not all negative numbers have a positive counterpart.

Change-Id: I3e6f92f68ab1b8dab48bbf883c5ad4b078a93f87
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-03-19 11:03:54 +00:00
Johan Hedberg
41f8a33555 libc: Add off_t definition
Add definition for the POSIX standard off_t type.

Change-Id: I1142428a3d226d641a8628cbba71cb3ea341ef92
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-03-11 01:09:56 +00:00
Johan Hedberg
6692e98298 libc: Move ssize_t definition to sys/types.h
There's no need to have a separate file for this, and we'll be adding
other types like off_t here soon as well.

Change-Id: I40629a5a0fba7af44828eaeead294e4e55844bb0
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-03-11 01:09:56 +00:00
Iván Briano
4370b5da6c libc-hooks: Provide the 'open()' syscall
Some parts of Newlib, notably the locale handling stuff, will try to
call open(), and if it's not provided, any application that for some
reason is bringing in that code will fail to link.
Having a non-working implementation keeps that code working.

Change-Id: I28345dabb93431d6b80c839b23a46b7f99dc8734
Signed-off-by: Iván Briano <ivan.briano@intel.com>
2016-03-10 23:28:15 +00:00
Jithu Joseph
4ad7f2a5a3 libc-hooks: newlib's heap may use entire unused RAM
Use linker symbol and board configs to determine the start
and extent of remaining RAM present in a board and use
it as newlib's heap.

Change-Id: I7128cf2857664331d83f212f27e8af7ad3bb8936
Signed-off-by: Jithu Joseph <jithu.joseph@intel.com>
2016-02-27 09:57:19 +00:00
Iván Briano
428d51b5db libc-hooks: Make newlib's heap size configurable
While we don't have a proper heap that can make use of all the
available RAM, make it possible for applications using Newlib to
configure the size of the heap exposed via the sbrk() hook.

Change-Id: I4e3193c1f2df0ace1dbc5b1f6ceb2cdc61479762
Signed-off-by: Iván Briano <ivan.briano@intel.com>
2016-02-20 14:57:53 +00:00
Johan Hedberg
da1552a923 libc: Add definition for ssize_t
Add definition for ssize_t that may be useful to represent sizes with
variables that also need to be able to have negative values (e.g. to
represent errors).

Change-Id: I52ec69591ccfd760021dad38f5ba1b1ebe707ea5
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-20 14:15:26 +00:00
Peter Mitsis
8413e1f872 doc: Fix misuse of @file doxygen tag
Summary lines follow the @brief tag instead of the @file tag.

This prevents doxygen build warnings such as ...

    The name xxx supplied as the second argument in the \file
    statement is not an input file

Change-Id: I1014586ad21be12e14aa1d2a942e6b8a11211795
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-11 20:11:03 +00:00
Peter Mitsis
08b353b8b4 minimal libc: stdlib.h no longer includes ctype.h
The libc 'ctype.h' header file is not supposed to be automatically
included when including 'stdlib.h'.

Change-Id: I821a9946894572a7b82804b1569b7b18c24316db
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-09 23:41:59 +00:00
Peter Mitsis
df3c6b13ab c++: Update minimal libc headers
Updates the minimal libc headers for differences between the C and C++
languages.  This includes ...
   1. Conditionally defining "bool", "true" and "false" as they are
      already keywords in C++.
   2. Making the definition of NULL language dependent.
   3. Using the _Restrict macro instead of the restrict keyword as
      restrict exists in C, but not in C++.
   4. Changing the definition of size_t so that it is compatible with
      what the compiler expects when building the new operator stubs
      (as it varies by architecture).

Change-Id: I37ff058a60b90a05f96e9dd6f61d454d143041ce
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:25:22 -05:00
Peter Mitsis
497d0e53c4 libc: Consolidate size_t definitions
Consolidates the definitions of size_t in the minimal libc library.
This prevents code duplication.

Change-Id: I996990ad9093ebec1f9ba0045d14319e1a243e70
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:25:22 -05:00
Peter Mitsis
b111d6c932 libc: Consolidate NULL definitions
Consolidates definitions of NULL in the minimal libc library.
This prevents code duplication.

Change-Id: Ia4a2bde1329d66e7c83afeab806a39b22704ab48
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:25:22 -05:00
Peter Mitsis
a0e4568760 c++: Add extern "C" { } block to header files
Adds extern "C" { } blocks to header files so that they can be
safely used by C++ source files.

Change-Id: Ia4db0c36a5dac5d3de351184a297d2af0df64532
Signed-off-by: Peter Mitsis <peter.mitsis@windriver.com>
2016-02-05 20:25:22 -05:00
Andre Guedes
aa47bd8d6c newlib: Rename exit to _exit
This patch renames the 'exit' function from newlib/libc-hooks.c to
'_exit' since this is the correct name of the newlib system call.

This patch fixes some linking errors that occur when an applications
uses abort() or assert().

Change-Id: I593e5ec5dc0f84dbbebe4aceb38703256e140914
Signed-off-by: Andre Guedes <andre.guedes@intel.com>
2016-02-05 20:25:16 -05:00
Vlad Lungu
8de1dac833 Add isgraph()/isprint()/isxdigit()/toupper()
Needed for porting various software

Change-Id: Ic5e89f4e606e46bd0c6de67cebb5b8e3159ab90e
Signed-off-by: Vlad Lungu <vlad.lungu@windriver.com>
2016-02-05 20:25:06 -05:00
Johan Hedberg
26484222ef lib/libc: Add implementation for isprint()
Add a simple implementation of isprint() which is used to test for a
printable character.

Change-Id: I0ebca10ec0f8e43ee245f6508c5b82c6e207bd32
Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
2016-02-05 20:25:03 -05:00
Benjamin Walsh
fc1c0c3345 libc/minimal: use per-thread errno implementation
Provides proper access to the per-thread errno variable, by using the
_get_errno() call.

Users can now do:

  errno = EINVAL;
  printk("errno: %d\n", errno);

Change-Id: I0ef365199656d002623b39b7f45f14f561501375
Signed-off-by: Benjamin Walsh <benjamin.walsh@windriver.com>
2016-02-05 20:24:58 -05:00
Allan Stephens
bf223a8838 stdio: Fix bug in fputs()
The previous implementation mistakenly kept outputting the first
character of the string endlessly.

Change-Id: I299c627a52158218be8e88c952935edb87a636fe
Suggested-by: Tom Yeon <tom.yeon@windriver.com>
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-02-05 20:24:44 -05:00
Dan Kalowsky
070a6e3ec9 checkpatch: error - trailing_whitespace
Change-Id: Id096b9eabcd8468e9343ceae5444c7726a1c539e
Signed-off-by: Dan Kalowsky <daniel.kalowsky@intel.com>
2016-02-05 20:24:35 -05:00
Dan Kalowsky
72f0a1314e checkpatch: warning - unnecssary_else
Change-Id: I6cc45cfcf09448b8fc988dc56219ea7560636af4
Signed-off-by: Dan Kalowsky <daniel.kalowsky@intel.com>
2016-02-05 20:24:35 -05:00
Dan Kalowsky
e45956c9a0 checkpatch: warning - leading_space
Change-Id: I34a54230bc4a63c8a4391d03ff530835910c3705
Signed-off-by: Dan Kalowsky <daniel.kalowsky@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:24:33 -05:00
Dan Kalowsky
a92e48890c checkpatch: error - global_initialisers
Change-Id: Ib3f69be9f9273e57952a3ebceebc82d84c607c64
Signed-off-by: Dan Kalowsky <daniel.kalowsky@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:24:33 -05:00
Dan Kalowsky
da67b29569 checkpatch: warning - block_comment_style
Change-Id: I6da43e41f9c6efee577b70513ec368ae3cce0144
Signed-off-by: Dan Kalowsky <daniel.kalowsky@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:24:33 -05:00
Dan Kalowsky
e4bb957a00 checkpatch: error - pointer_location
Change-Id: I9ce224cb75ba21caecffd6747833257f748b5ecf
Signed-off-by: Dan Kalowsky <daniel.kalowsky@intel.com>
2016-02-05 20:24:31 -05:00
Dan Kalowsky
a60c866c70 checkpatch: error - open_brace
Change-Id: I434037ce969bcd1fc08bd4b407f9508773e64b1e
Signed-off-by: Dan Kalowsky <daniel.kalowsky@intel.com>
2016-02-05 20:24:31 -05:00
Dan Kalowsky
d04ae83e11 checkpatch: error - return_parentheses
Change-Id: If1964349a115043fa54bf48ebfe4b3c0a414ed57
Signed-off-by: Dan Kalowsky <daniel.kalowsky@intel.com>
2016-02-05 20:24:31 -05:00
Dan Kalowsky
39063598db checkpatch: error - spacing
Change-Id: Ie6e1c43581dd4b0734625b3a4e59a4ca79619e99
Signed-off-by: Dan Kalowsky <daniel.kalowsky@intel.com>
2016-02-05 20:24:31 -05:00
Dan Kalowsky
3bc4039601 checkpatch: error - switch_case_indent_level
Change-Id: I9cbd6ab80b0c0f170626bb1c6b2d07498038fb8f
Signed-off-by: Dan Kalowsky <daniel.kalowsky@intel.com>
2016-02-05 20:24:31 -05:00
Dan Kalowsky
7cfc703711 checkpatch: error - trailing statements
Change-Id: I461134536da0288261b90f605a904ab3ea466340
Signed-off-by: Dan Kalowsky <daniel.kalowsky@intel.com>
2016-02-05 20:24:31 -05:00
Dan Kalowsky
978851fb6a checkpatch: code_indent failures
Corrects the checkpatch code_indent failures

Change-Id: I2ff93b8907d3eddbaa543ccbd12aecef8af7f698
Signed-off-by: Dan Kalowsky <daniel.kalowsky@intel.com>
2016-02-05 20:24:31 -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
Anas Nashif
196bb2e17f libc: use isdigit from ctype.h
Do not use local _isdigit function, use public isdigit
instead.

Change-Id: Ifc2721fc2def429de4934c9855f08dae30326694
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:16:15 -05:00
Anas Nashif
f3f7eac765 Add MINIMAL_LIBC_EXTENDED to limit libc builds
This option adds optional libc functions that are not directly
used by the kernel but can be used for testing purposes.

This option is experimental.

Change-Id: Ia4dba718359c4f381047a5b52ebddb26d87ea75a
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:16:15 -05:00
Anas Nashif
751d90da85 libc: add support for strncasecmp function
Add function for comparing two strings ignoring case.

Change-Id: I2fc78c0a0d0f53e23566ffacd8dca3b23e386c26
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:16:15 -05:00
Anas Nashif
3e02a4a107 libc: add atoi to minimal libc
Change-Id: I589fe6599dec1a93e9700005742b8b34b42dee64
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:16:15 -05:00
Anas Nashif
9d648ebc48 libc: add strcat to minimal libc
Change-Id: Ifae9da3abb60d061a4211e0fac20037f72ca90e2
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:16:15 -05:00
Anas Nashif
bddd72602c libc: add strtol and strtoul to minimal libc
Change-Id: Ia6198cd34ff486d8eb9d978a59d885cae06b60d3
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:16:15 -05:00
Anas Nashif
17f666bd89 libc: update ctype.h with isdigit, isspace, isalpha, isupper
Change-Id: Id8d865cde04d66367ddcf26995780767ad1b05f8
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:16:15 -05:00
Dirk Brandewie
6bc71f5933 libc: added errno global variable
Change-Id: I42ae30fe5826828cc4696f155caeb186a31f913b
Signed-off-by: Fabien Chereau <fabien.chereau@intel.com>
Signed-off-by: Dirk Brandewie <dirk.j.brandewie@intel.com>
2016-02-05 20:16:01 -05:00
Jukka Rissanen
efed446bee libc: Add memchr implementation
Needed by CoAP implementation in net/ip/er-coap

Change-Id: I724bc7569a29c35f386bbc301d883a000882de78
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:15:32 -05:00
Anas Nashif
42fbd4afd2 cleanup libc kconfig and use choice
This will allow adding more libc implementations in the future.
Also use the location of the include directory from the toolchain
settings.

Change-Id: Idae5e4ffd9b1bcb5e924da156df56e81f10c8842
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:15:25 -05:00
Anas Nashif
8d00ec5c4e build: build libc as object, not kbuild library (lib.a)
The way we build the libc files is not a real library that can be
used as a libc and makes managing the source files a bit
difficult, so lets revert back to building the c function files
like everything else in the system to avoid any confusion.

Change-Id: I4e998e37bc376522fe253c4aefefe7804597f0f2
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:14:45 -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
Jukka Rissanen
d639bb8c99 libc: Add tolower implementation
Add a tolower implementation that may be used in various parts of the
operating system.

Change-Id: I5aa855b41e2a09fcb077860b4580dbe1e6d4a093
Signed-off-by: Jukka Rissanen <jukka.rissanen@linux.intel.com>
2016-02-05 20:14:14 -05:00
Allan Stephens
5a4be58707 Eliminate non-standard boolean type support
Revises kernel so that it uses the standard boolean type library
defined for C99, rather than having its own custom boolean type.

Also revises sample projects that used the non-standard type.

Change-Id: Ib41b7f836da25352aa5ae9dfbbfdd29739017b6f
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-02-05 20:14:14 -05:00
Anas Nashif
987d64c9ba newlib: Fix coding style and checkpatch warnings/errors
Change-Id: I96d2fc5232b5babdb5d849b603dcd2fa44c50de1
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2016-02-05 20:14:14 -05:00
Allan Stephens
b52a09f536 Optimize performance of memset() and memcpy()
Builds upon the approach taken by the x86 version of k_memset()
and k_memcpy() APIs, which uses word-sized operations for greater
efficiency when manipulating large buffers. The algorithms used
here are architecture-independent.

Change-Id: I01ea8b22c8e6028f881e9b61ccc3a01e8ba4c02b
Signed-off-by: Allan Stephens <allan.stephens@windriver.com>
2016-02-05 20:14:12 -05:00