Commit graph

978 commits

Author SHA1 Message Date
Ioannis Glaropoulos 518bfa39e3 arch: arm: introduce macro to describe the privilege stack alignment
We introduce a new define to describe the alignment for a
privilege stack buffer. This macro definition is used by the
privilege stack generation script, to determine the required
alignment of threads' privilege stacks when building with
support for user mode.

We cannot use Z_THREAD_MIN_STACK_ALIGN in this case, because
the privilege stacks do not need to respect the minimum MPU
region alignment requirement, unless, of course, this is
enforced via the MPU Stack Guard feature.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-06-24 10:16:57 -07:00
Ioannis Glaropoulos e0db39447b arch: arm: re-organize thread stack macro defines in arch.h
This commit re-organizes the macro definitions in arch.h for
the ARM architecture. In particular, the commit:
- defines the minimum alignment requirement for thread stacks,
  that is, excluding alignment requirement for (possible)
  MPU stack guards.
- defines convenience macros for the MPU stack guard align and
  size for threads using the FP services under Shared registers
  mode (CONFIG_FP_SHARING=y). For that, a hidden Kconfig option
  is defined in arch/arm/core/cortex_m/mpu/Kconfig.
- enforces stack alignment with a wide MPU stack guard (128
  bytes) under CONFIG_FP_SHARING=y for the ARMv7-M architecture,
  which requires start address alignment with power-of-two and
  region size.

The commit does not change the amount of stack that is reserved
with K_THREAD_STACK_DEFINE; it only determines the stack buffer
alignment as explained above.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-06-24 10:16:57 -07:00
Charles E. Youse ef736f77c2 arch/x86: relocate and rename SYS_X86_RST_* constants
These constants do not need global exposure, as they're only
referenced in the reboot API implementation. Also their names
are trimmed to fit into the X86-arch-specific namespace.

Signed-off-by: Charles E. Youse <charles.youse@intel.com>
2019-06-24 07:46:24 -07:00
Anas Nashif f2cb20c772 docs: fix misspelling across the tree
Found a few annoying typos and figured I better run script and
fix anything it can find, here are the results...

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-19 15:34:13 -05:00
Charles E. Youse 8013277cd6 arch/x86/Kconfig: remove CONFIG_CMOV
The only we support cores that don't have CMOV insns are the MINUTEIAs,
so we simply check for that rather this using a layer of indirection.

Signed-off-by: Charles E. Youse <charles.youse@intel.com>
2019-06-14 05:49:13 -04:00
Ioannis Glaropoulos d840d1cbb5 arch: implement arch-specific float disable routines
This commit adds the architecture-specific implementation
of k_float_disable() for ARM and x86.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-06-12 09:17:45 -07:00
Charles E. Youse 9a1e92735c drivers/interrupt_controller/loapic_intr.c: enable x2APIC support
When CONFIG_X2APIC is enabled, twiddle the appropriate MSR during
initialization to enable x2APIC mode.

Signed-off-by: Charles E. Youse <charles.youse@intel.com>
2019-06-08 15:41:36 -04:00
Charles E. Youse 53b370a7c6 arch/x86: add x2APIC-aware accessors for local APIC access
MSRs related to x2APIC will never be accessed directly by name, but
rather via an offset from a base MSR, so the definitions are removed
from msr.h.

New local APIC accessor functions, which are sensitive to xAPIC vs
x2APIC mode (CONFIG_X2APIC), are added to include/drivers/loapic.h.
These accessors use the MSR definitions as modified above.

Signed-off-by: Charles E. Youse <charles.youse@intel.com>
2019-06-08 15:41:36 -04:00
Charles E. Youse ba516e8ea8 arch/x86: do not redefine MSR regs in crt0.S
The real-mode startup code is trivially changed to refer to MSR
definitions in include/arch/x86/msr.h, rather than its ad-hoc ones.

Signed-off-by: Charles E. Youse <charles.youse@intel.com>
2019-06-08 15:41:36 -04:00
Charles E. Youse 0e166fa2a8 arch/x86: move MSR definitions to include/arch/x86/msr.h
Light reorganization. All MSR definitions and manipulation functions
are consolidated into one header. The names are changed to use an
X86_* prefix instead of IA32_* which is misleading/incorrect.

Signed-off-by: Charles E. Youse <charles.youse@intel.com>
2019-06-08 15:41:36 -04:00
Charles E. Youse 4c63e29aec arch/x86: drivers/display: add framebuffer driver w/ multiboot support
A basic display driver is added for a generic 32-bpp framebuffer.
Glue logic is added to the x86 arch to request the intitialization
of a linear framebuffer by the Multiboot loader (GRUB) and connect
it to this generic driver.

Signed-off-by: Charles E. Youse <charles.youse@intel.com>
2019-06-06 10:47:29 -07:00
Charles E. Youse a1a3a4fced arch/x86: add support for Multiboot boot information structure
When booting using GRUB, some useful information about the environment
is given to us via a boot information structure. We've not made any
use of this information so far, but the x86 framebuffer driver will.

A skeletal definition of the structure is given, and provisions are
made to preserve its contents at boot if the configuration requires it.

Signed-off-by: Charles E. Youse <charles.youse@intel.com>
2019-06-06 10:47:29 -07:00
Paul Sokolovsky f7810d4a3c include: arch: arc: Minor punctuation fix
Add missing space after comma.

Signed-off-by: Paul Sokolovsky <paul.sokolovsky@linaro.org>
2019-06-05 07:39:56 -04:00
Anas Nashif 0227cdaed7 include: arch: rename xtensa_irq.h to irq.h
Rename file to match all other architectures. Minor cleanup to exc.h
header.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-03 21:09:24 -04:00
Anas Nashif b0fb9ec61a include: arch: remove empty nios2 asm.h
File is empty and being referenced in multiple locations. Remove
completely.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-03 21:09:24 -04:00
Anas Nashif d647751bbc include: arch: move addr_types to common location
All architectures declare those variables the same way, no need to
define them per arch, instead put them in common. If someone deviates,
they can create their own header.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-03 21:09:24 -04:00
Anas Nashif b01568c2cd include: arch: move bits_portable.h to arch/common
We had architectures doing this differently, some had a dedicated
sys_io.h file, some not. Unify how it is done by splitting the arch
specific sys_io implementation into a sys_io file and include it
instead.

Move bits_portable.h to arch/common and split the file so more
architecture can reuse some of the definitions here instead of
duplicating code.

Where applicable use the common sys_io/ffs definitions.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-03 21:09:24 -04:00
Andy Ross e6af0f8caa arch/*: Add z_arch_irq_unlocked() predicate and test
It's useful to be able to inspect the key returned from
z_arch_irq_unlock() to see if interrupts were enabled at the point
where z_arch_irq_lock() was called.  Architectures tend to represent
this is a simple way that doesn't require platform assembly to
inspect.

Adds a simple test to kernel/common that validates this predicate with
a nested lock.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-06-03 12:03:48 -07:00
Anas Nashif 76d9d7806d x86: remove unused and x86 only latency benchmark
We do have a multi-architecture latency benchmark now, this one was x86
only, was never used or compiled in and is out-dated.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-06-03 09:42:00 -07:00
Erwan Gouriou c6ebfad7a7 include/arch/arm: linker.ld: Add shared memory sections definitions
STM32WB HCI driver requires definition of 2 RAM regions to support
use of 3 shared memory sections: MAPPING_TABLE, MB_MEM1 and MB_MEM2.
In linker.ld, under conditions of HCI driver to be enabled,
define SRAM1 and SRAM2 based on input defined in stm32wb linker.
Then define the 3 sections MAPPING_TABLE, MB_MEM1 and MB_MEM

Signed-off-by: Erwan Gouriou <erwan.gouriou@linaro.org>
2019-06-03 09:38:19 -04:00
Wentong Wu 82d703debc testsuite: coverage: port GCOV linker code to CMake for X86
port GCOV linker code to CMake for X86 platfrom, from linker.ld
to coverage_ram.ld.

Fixes: #16501.

Signed-off-by: Wentong Wu <wentong.wu@intel.com>
2019-05-31 10:49:19 -04:00
Ioannis Glaropoulos 45a147c271 arch: arm: mpu: move internal API inside arch/arm/cortex_m/mpu
arm_core_mpu_dev.h is an internal API, and is not supposed to
be directly called by kernel / application functions, therefore,
we can move it inside arch/arm/core/cortex_m/mpu directory.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-05-30 09:00:05 -05:00
Øyvind Rønningstad 42f9e0c6db linker: Move sgstubs section to the very end and fix for nrf91
Add ifdefs to handle the nrf91 case. This change will dynamically
place and size the NSC region according to nrf91 HW limitations.

Add Cmake check of NSC offset if manually set.

Signed-off-by: Øyvind Rønningstad <oyvind.ronningstad@nordicsemi.no>
2019-05-30 13:18:04 +02:00
Jan Van Winkel 7a246c30bd dts: posix: Add DTS support for POSIX architecture
Added device tree support for POSIX architecture based boards.

Signed-off-by: Jan Van Winkel <jan.van_winkel@dxplore.eu>
2019-05-28 21:14:19 -04:00
Wentong Wu 7b3dc920dd linker: add no-flash system support
Non-XIP system with FLASH_SIZE = 0 is no-flash system. And no-flash
system makes text, rodata, and data all in SRAM, so define the marco
ROM_ADDR to RAM_ADDR.

Fixes: #16027.

Signed-off-by: Wentong Wu <wentong.wu@intel.com>
2019-05-27 09:21:42 -04:00
Wentong Wu 743a184b2d scripts: mpu align for ro section of new memory region on non-XIP system
on non-XIP system, SRAM is the default region, and relocated .data
section and .bss section of SRAM shouldn't be inserted between
_image_rom_start and _image_rom_end, because the memory region between
_image_rom_start and _image_rom_end will construct the mpu ro region.
Also for the newly added memory region on non-XIP system, the
relocated .text secition and .rodata section should also be mpu aligned.

Fixes: #16090.

Signed-off-by: Wentong Wu <wentong.wu@intel.com>
2019-05-21 15:28:59 -04:00
Øyvind Rønningstad fb0faaa123 testsuite: coverage: Port GCOV linker code to Cmake.
From linker.ld and common-rom.ld

Signed-off-by: Øyvind Rønningstad <oyvind.ronningstad@nordicsemi.no>
2019-05-20 22:28:28 -04:00
Øyvind Rønningstad c760ca02eb arch: Put intlist.ld into Cmake
Remove from linker.ld

Signed-off-by: Øyvind Rønningstad <oyvind.ronningstad@nordicsemi.no>
2019-05-20 22:28:28 -04:00
Øyvind Rønningstad 1d3b6e7c9c arch: arm: cortex_m: Port some vector_relay linker code to Cmake
Sections before the vector table remain in linker.ld

Signed-off-by: Øyvind Rønningstad <oyvind.ronningstad@nordicsemi.no>
2019-05-20 22:28:28 -04:00
Øyvind Rønningstad e4024e274b arch: port nocache linker code to use Cmake function
Remove from linker.ld

Signed-off-by: Øyvind Rønningstad <oyvind.ronningstad@nordicsemi.no>
2019-05-20 22:28:28 -04:00
Øyvind Rønningstad 6d0039444c arch: Port the ramfunc section to the Cmake function
Remove it from linker.ld

Signed-off-by: Øyvind Rønningstad <oyvind.ronningstad@nordicsemi.no>
2019-05-20 22:28:28 -04:00
Øyvind Rønningstad 000103906a soc: arm: st_stm32: Port CCM sections to use the Cmake function
Remove them from linker.ld

Signed-off-by: Øyvind Rønningstad <oyvind.ronningstad@nordicsemi.no>
2019-05-20 22:28:28 -04:00
Øyvind Rønningstad f2a1572ac2 cmake: Add function for adding snippets to the linker file
Allows snippets to be placed in different locations:
 - The noinit, rwdata and rodata output sections
 - Two different locations for placing custom output sections,
   one location for RAM and another for all other sections.

Signed-off-by: Øyvind Rønningstad <oyvind.ronningstad@nordicsemi.no>
2019-05-20 22:28:28 -04:00
Anton Gerasimov ac4eb32293 arch: arm: fix "template with C linkage" in cmsis.h
The error manifests itself when including cmsis.h from C++ code

Signed-off-by: Anton Gerasimov <agerasimov@twilio.com>
2019-05-20 11:58:39 -04:00
Bradley Bolen 6b51ef731d arch: arm: Fix check of Kconfig option
The compiler was generating errors of the form
error: "CONFIG_ZERO_LATENCY_IRQS" is not defined, evaluates to 0
[-Werror=undef] when -Wundef is used and the config option was turned
off.  Change check to ifdef.

Signed-off-by: Bradley Bolen <bbolen@lexmark.com>
2019-05-17 15:46:18 -07:00
Filip Kokosinski e0a825003d riscv32: use device tree defines in linker
Delete memory-related configs from defconfig and use device tree based
macros in general riscv32 linker script instead of Kconfig ones.

Signed-off-by: Filip Kokosinski <fkokosinski@internships.antmicro.com>
Signed-off-by: Mateusz Holenko <mholenko@antmicro.com>
2019-05-10 10:34:31 -05:00
Ioannis Glaropoulos 6f19d00659 arch: arm: add internal structure to ESF
The ARM Cortex-M Exception Stack Frame (ESF) may consist of
several stack frame contexts (basic state context, additional
state context, FP context, etc.). To reflect these structural
properties, this commit re-factors the ESF, splitting out the
basic stack frame, holding the state context, into its own
struct container. The commit does not introduce behavioral
changes.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-05-07 19:21:46 -04:00
Ioannis Glaropoulos 9b00be3d17 arch: arm: remove FP-context from ESF in unshared FP registers mode
Under Unshared FP register mode we are not stacking the
FP context in exception entries, so we do not need to
include the FP registers bank in the exception stack
frame structure.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-05-03 14:25:22 -04:00
Andrew Boie ff1952cc44 arc: arm: fix support for MPUs on non-XIP systems
The size of the ROM region is now rounded up to the
nearest power of two; we no longer assume that RAM
is in a different part of memory.

Fixes: #15558

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-04-28 13:32:35 -04:00
Andrew Boie 4cf4040af0 arc: print human-readable exception info
Right now only numerical values are printed which must
be looked up in the Designware ARCv2 ISA Programmer's
Reference, which is not public.

Add a non-default Kconfig to print more information at
the expense of footprint, and enable it for all the simulator
targets.

We only print code/parameter details for machine check and
protection violations, more may be added later as desired.
This should cover all the exceptions we commonly encounter
for memory protection.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-04-17 09:16:27 -07:00
Wayne Ren 5bc307e60f arch: arc: optimize the macros of thread stack
* clean up and optimzie the macros of thread stack

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2019-04-09 18:39:48 -04:00
Wayne Ren 290aa59ada arch: arc: fix the bug of mpu stack guard when no USERSPACE
* fix the stack allocation and initialization
  for mpu stack guard when USERSPACE is not configured
* fixes #15163

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2019-04-09 18:39:48 -04:00
Patrik Flykt 7c0a245d32 arch: Rename reserved function names
Rename reserved function names in arch/ subdirectory. The Python
script gen_priv_stacks.py was updated to follow the 'z_' prefix
naming.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-04-03 17:31:00 -04:00
Patrik Flykt 97b3bd11a7 drivers: Rename reserved function names
Rename reserved function names in drivers/ subdirectory. Update
function macros concatenatenating function names with '##'. As
there is a conflict between the existing gpio_sch_manage_callback()
and _gpio_sch_manage_callback() names, leave the latter unmodified.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-04-03 17:31:00 -04:00
Andrew Boie 00a8818da2 arc: fix Z_ARCH_THREAD_STACK_MEMBER()
Unlike the others, this macro was not taking into
account minimum MPU region sizes by filtering through
STACK_SIZE_ALIGN().

Fixes: #15130

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-04-03 13:48:20 -04:00
Patrik Flykt 24d71431e9 all: Add 'U' suffix when using unsigned variables
Add a 'U' suffix to values when computing and comparing against
unsigned variables.

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-28 17:15:58 -05:00
Flavio Ceolin b2b4f09bed include: Add U for unsigned constants
Add U for integer constants to avoid an implicit cast.

MISRA-C rule 10.1

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2019-03-26 14:31:29 -04:00
Flavio Ceolin 063a9ce8c3 include: Make statements evaluate boolean expressions
MISRA-C requires that the if statement has essentially Boolean type.

MISRA-C rule 14.4

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2019-03-26 14:31:29 -04:00
Flavio Ceolin 39a50f6392 arch: x86: Use proper essential types in operands
MISRA defines a serie of essential types, boolean, signed/unsigned
integers, float, ... and operations must respect these essential types.

MISRA-C rule 10.1

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2019-03-26 14:31:29 -04:00
Flavio Ceolin 95eb2b4fed include: Use macro BIT for shift operations
Use a macro BIT when dealing with bit shift operations.

MISRA-C rule 10.1

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2019-03-26 14:31:29 -04:00
Andrew Boie 575abc0150 kernel: add K_THREAD_STACK_RESERVED
This is used to have each arch canonically state how much
room in the stack object is reserved for non-thread use.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-03-20 13:59:26 -07:00
Andrew Boie 02f64c6846 arm: remove duplicate stack macro docs
These intefaces are already documented in kernel.h.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-03-20 13:59:26 -07:00
Ioannis Glaropoulos a0851c47aa arch: arm: introduce barriers when disabling interrupts
The ARM Cortex-M 321 application note is stressing that if
we disable interrupts by executing CPSID i(f), or by MSR
instructions (on PRIMASK, FAULTMASK registers), there is no
requirement to add barrier instructions after disabling
interupts. However, in ARMv7-M (and ARMv8-M Mainline) we use
BASEPRI, instead. Therefore, if we need the effect of disabling
interrupts to be recongnized immediately we should add barrier
instructions. This commit adds DSB and ISB barriers when
disabling interrupt using BASEPRI in the generic
arm _irq_lock() function as well as in the PendSV handler,
where we need to access kernel globals right after the interrups
are disabled.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-03-18 11:38:19 -05:00
Kumar Gala 4da0f8b796 linker: Remove unused (OPTIONAL) from linker scripts
(OPTIONAL) was a vestiage from the initial import of the Zephyr code
base and we dont utilize it with the GNU linker.  Additionally, the way
(OPTIONAL) gets defined to nothing creates a linker script that lld
(from llvm) doesn't like.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-03-15 06:42:02 -05:00
Wayne Ren a1c2159acb arch: arc: refactor the ARC MPU driver
* separate the ARC MPU driver into 2 parts
  * arc_mpu_v2_internal.h for ARC MPUv2
  * arc_mpu_v3_internal.h for ARC MPUv3
* For ARC MPUv2, keep the main design, but update and optimize the code
* For ARC MPUv3, implement mpu region split to supprt MPU region overlap
* misc updates and bug fixes

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2019-03-14 23:53:16 -07:00
Kumar Gala ea5d54c61b arm: asm: Fix inline asm in Z_ARCH_EXCEPT for clang
The clang ARM assembler is a bit stricter than GNU as.  Change mov to
movs for ARMv6 case of Z_ARCH_EXCEPT.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-03-15 06:02:34 +01:00
Ioannis Glaropoulos c686dd5064 kernel: enhance documentation of z_arch_buffer_validate
This commit enhances the documentation of z_arch_buffer_validate
describing the cases where the validation is performed
successfully, as well as the cases where the result is
undefined.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-03-13 15:36:15 -07:00
Daniel Leung 8328d6df76 linker: nios2: align rodata section
During testing with sorting section by alignment with qemu_nios2,
if rodata section is not aligned on 4-byte boundary and its size
not of multiple of 4, it would never boot correctly. So align
the rodata here. This is in preparation to enable the linker
option to sort sections by alignment.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2019-03-13 15:54:29 -05:00
Daniel Leung e8a2348fac linker: move app_smem.ld into include/linker
The app_smem.ld is also being used by architectures other than ARM.
So move the linker script out of include/arch/arm and into
include/linker.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2019-03-13 18:26:51 +01:00
Ioannis Glaropoulos 58e24f37fb arch: arm: introduce sync barriers in _arch_irq_unlock()
The ARM Cortex-M 321 application note is stressing that
when enabling interrupts by executing CPSIE i(f), or by MSR
instructions (on PRIMASK, FAULTMASK, or BASEPRI registers),
there is a need for synchronization barrier instructions,
if there is a requirement for the effect of enabling
interrupts to be recongnized immediately. _arch_irq_unlock()
is invoked in several places, therefore, we add the
barriers to make the interrupt enabling function
applicable to all usage scenarios.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-03-12 12:01:49 -07:00
Patrik Flykt 4344e27c26 all: Update reserved function names
Update reserved function names starting with one underscore, replacing
them as follows:
   '_k_' with 'z_'
   '_K_' with 'Z_'
   '_handler_' with 'z_handl_'
   '_Cstart' with 'z_cstart'
   '_Swap' with 'z_swap'

This renaming is done on both global and those static function names
in kernel/include and include/. Other static function names in kernel/
are renamed by removing the leading underscore. Other function names
not starting with any prefix listed above are renamed starting with
a 'z_' or 'Z_' prefix.

Function names starting with two or three leading underscores are not
automatcally renamed since these names will collide with the variants
with two or three leading underscores.

Various generator scripts have also been updated as well as perf,
linker and usb files. These are
   drivers/serial/uart_handlers.c
   include/linker/kobject-text.ld
   kernel/include/syscall_handler.h
   scripts/gen_kobject_list.py
   scripts/gen_syscall_header.py

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2019-03-11 13:48:42 -04:00
Ioannis Glaropoulos 8cbba1e2ee arch: arm: documentation improvements for _ARCH_THREAD_STACK_SIZEOF()
This commit corrects and improves the documentation for the
convenience macro _ARCH_THREAD_STACK_SIZEOF(sym). It stresses
that the returned size is guaranteed to match the amount of
stack that is available for the thread, that is, excluding any
areas not directly usable, e.g. a Stack Guard.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-03-09 11:57:24 -08:00
Ioannis Glaropoulos 9611c9ab4d arch: arm: pointer argument to MPU region re-programming functions
This commit refactors the MPU region re-programming functions,
to take as argument an array of pointers to memory partition
structures, instead of the whole array of the partitions. In
this way the stack usage can be minimized, if the actual
partition information is kept in statically allocated memory.

instead of the map itself.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-03-07 19:20:30 -08:00
Ioannis Glaropoulos 823d86097f arch: arm: MPU-align GCOV section, only if CONFIG_USERSPACE=y
The GCOV section is programmed as a static MPU region, only
in builds with support for User Mode, otherwise it is not
programmed into an MPU region at all. To reflect this in the
linker, the MPU-alignment for GCOV section is enforced only
under CONFIG_USERSPACE=y. Otherwise, single-word alignment
is enforced.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-03-04 16:52:59 +01:00
Andrew Boie d3c89fea4f kernel: move CONFIG_RETPOLINE definition
Retpolines were never completely implemented, even on x86.
Move this particular Kconfig to only concern itself with
the assembly code, and don't default it on ever since we
prefer SSBD instead.

We can restore the common kernel-wide CONFIG_RETPOLINE once
we have an end-to-end implementation.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-03-01 12:35:04 -08:00
Anas Nashif 29f04767e9 arch: move common app_data_alignment.ld file
This file is being used by different architectures and is not ARC
specific.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-02-28 08:53:16 -08:00
Andrew Boie 4ce652e4b2 userspace: remove APP_SHARED_MEM Kconfig
This is an integral part of userspace and cannot be used
on its own. Fold into the main userspace configuration.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-23 07:43:55 -05:00
Aurelien Jarno 992f29a1bc arch: make __ramfunc support transparent
Instead of having to enable ramfunc support manually, just make it
transparently available to users, keeping the MPU region disabled if not
used to not waste a MPU region. This however wastes 24 bytes of code
area when the MPU is disabled and 48 bytes when it is enabled, and
probably a dozen of CPU cycles during boot. I believe it is something
acceptable.

Note that when XIP is used, code is already in RAM, so the __ramfunc
keyword does nothing, but does not generate an error.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2019-02-22 11:36:50 -08:00
qianfan Zhao e1cc657941 arm: Placing the functions which holds __ramfunc into '.ramfunc'
Using __ramfunc to places a function in RAM instead of Flash.
Code that for example reprograms flash at runtime can't execute
from flash, in that case must placing code into RAM.

This commit create a new section named '.ramfunc' in link scripts,
all functions has __ramfunc keyword saved in thats sections and
will load from flash to sram after the system booted.

Fixes: #10253

Signed-off-by: qianfan Zhao <qianfanguijin@163.com>
2019-02-22 11:36:50 -08:00
Ioannis Glaropoulos 7c09f82b43 arch: arm: enhance built-time rule to check for start addr alignment
Slightly enhance the build-time ASSERT rule for memory
partitions sanity on ARMv8-M platforms, to check,
additionally, for proper (32-byte) alignment of the start
address.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-02-21 10:03:23 -08:00
Sebastian Bøe d515315a86 ld: Change the name of input section irq_vectors_alloc_data
The arch/x86/CMakeLists.txt build scripts names five sections that are
generated from .bin files. Two of them are named the same as the .bin
file, and the other three are named inconsistently.

To be consistent, we will rename the three that are named inconistenly
to align with the two that are named as the .bin file.

Being consistent simplifies the system and fosters code-reuse.

This patch renames irq_vectors_alloc_data.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-02-19 10:00:14 -08:00
Sebastian Bøe c5837eabcb ld: Change the name of input section .gdt_ram_data to gdt
The arch/x86/CMakeLists.txt build scripts names five sections that are
generated from .bin files. Two of them are named the same as the .bin
file, and the other three are named inconsistently.

To be consistent, we will rename the three that are named inconistenly
to align with the two that are named as the .bin file.

Being consistent simplifies the system and fosters code-reuse.

This patch renames gdt.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-02-19 10:00:14 -08:00
Sebastian Bøe d1a14b7eb2 ld: Change the name of section .user_mmu_data to user_mmu_tables
The arch/x86/CMakeLists.txt build scripts names five sections that are
generated from .bin files. Two of them are named the same as the .bin
file, and the other three are named inconsistently.

To be consistent, we will rename the three that are named inconistenly
to align with the two that are named as the .bin file.

Being consistent simplifies the system and fosters code-reuse.

This patch renames user_mmu_tables.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-02-19 10:00:14 -08:00
Sebastian Bøe d5ea49bcbd ld: Change the name of input section .mmu_data to mmu_tables
The arch/x86/CMakeLists.txt build scripts names five sections that are
generated from .bin files. Two of them are named the same as the .bin
file, and the other three are named inconsistently.

To be consistent, we will rename the three that are named inconistenly
to align with the two that are named as the .bin file.

Being consistent simplifies the system and fosters code-reuse.

This patch renames mmu_tables.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2019-02-19 10:00:14 -08:00
Andrew Boie 5f4683db34 x86: fix ROM permissions
Only the text area now has execute permissions,
instead of both text and rodata.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-15 13:10:18 -08:00
Kumar Gala 10f2bdfc57 linker: riscv32: Fix .riscv.attributes orphan sections warning
Add similar fix to riscv32 linker scripts that we have on ARM for
.riscv.attributes section.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-15 12:37:21 -05:00
Carlos Stuart 75f77db432 include: misc: util.h: Rename min/max to MIN/MAX
There are issues using lowercase min and max macros when compiling a C++
application with a third-party toolchain such as GNU ARM Embedded when
using some STL headers i.e. <chrono>.

This is because there are actual C++ functions called min and max
defined in some of the STL headers and these macros interfere with them.
By changing the macros to UPPERCASE, which is consistent with almost all
other pre-processor macros this naming conflict is avoided.

All files that use these macros have been updated.

Signed-off-by: Carlos Stuart <carlosstuart1970@gmail.com>
2019-02-14 22:16:03 -05:00
Andrew Boie 2cfeba8507 x86: implement interrupt stack trampoline
Upon hard/soft irq or exception entry/exit, handle transitions
off or onto the trampoline stack, which is the only stack that
can be used on the kernel side when the shadow page table
is active. We swap page tables when on this stack.

Adjustments to page tables are now as follows:

- Any adjustments for stack memory access now are always done
  to the user page tables

- Any adjustments for memory domains are now always done to
  the user page tables

- With KPTI, resetting a page now clears the present bit

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-14 12:46:36 -05:00
Andrew Boie eea0f93a83 x86: generate user mode page tables
If kernel page table isolation is enabled, we generate a second
set of page tables. These tables, except for the shared page, have
all non-user pages marked as non-present.

The MMU generation script has been refactored:

- Debugging output has been make significantly simpler and less
  verbose

- Useless globals removed or adjusted

- MMU region list is validated as it is read

- Some tuples unpacked into individual variables to make the
  code easier to read.

- Useless command line option for output binary endian-ness
  remobved

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-14 12:46:36 -05:00
Andrew Boie f093285345 x86: modify MMU APIs for multiple page tables
Current set of APIs and macros assumed that only one set
of page tables would ever be in use.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-14 12:46:36 -05:00
Andrew Boie db6acbfb95 x86: set up shared kernel page
KPTI requires that there exist one kernel page marked
'present', because switching between the kernel and the
shadow page tables is not done automatically and certain
other CPU data structures must always be in a present page.

Move IDT, GDT, all TSS to this page, and set up a small
trampoline stack as a safe landing area when doing
privilege level transitions.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-14 12:46:36 -05:00
Kumar Gala bfaaa6bbe9 dts: Convert CONFIG_CCM to DT_CCM
Since we know do DTS before Kconfig we should try and remove dts from
creating Kconfig namespaced symbols and leave that to Kconfig.  So
rename CONFIG_CCM_<FOO> to DT_CCM_<FOO>.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-08 10:29:57 -06:00
Kumar Gala 68d9ac0ab5 arch: arm: mpu: Remove dead Kconfig reference
CONFIG_APPLICATION_MEMORY doesn't exist anymore, so the bit of code in
arm_core_mpu_dev.h related to it is dead and should be removed.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2019-02-08 09:30:43 -06: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 7adff462e7 app_shmem: overhaul partition specification
* K_APP_DMEM_SECTION/K_MEM_BMEM_SECTION macros now exist
  to specifically define the name of the sections for data
  and bss respectively.

* All boards now use the gen_app_partitions.py script, the
  padding hacks for non-power-of-two arches didn't work right
  in all cases. Linker scripts have been updated.

* The defined k_mem_partition is now completely initialized
  at build time. The region data structures now only exist
  to zero BSS.

Based on some work submitted by Adithya Baglody
<adithya.baglody@intel.com>

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-08 07:04:30 -05:00
Adithya Baglody 9bebf4cb23 x86: fix app shared memory if XIP enabled
This is a separate data section which needs to be copied into
RAM.

Most arches just use the kernel's _data_copy(), but x86 has its
own optimized copying code.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-08 07:04:30 -05:00
Ioannis Glaropoulos 083968454b arch: arm: minor style fixes in funtion and headers' documentation
Replace Cortex-M3 with Cortex-M architecture family
in the header documentation of kernel_arch_data.h and
kernel_arch_func.h, which are generic header files for
the entire familty of ARM Cortex-M CPUs. The commit
adds some more minor style fixes in functions'
documentation.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-02-07 11:15:52 -06:00
Ioannis Glaropoulos 08f00c11a0 arch: arm: improve documentation of _arch_irq_lock(..)
This commit improves the documentation of internal ARM core
function _arch_irq_lock(..), adding a more detailed description
of its impact on the different Cortex-M processors.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-02-07 11:15:52 -06:00
Wayne Ren bfc66346b8 arch: arc: add the handling of APP_SHARED_MEM
add the handling of APP_SHARED_MEM.
privileged threads can access all the mem
explictly defined in user mode, i.e., APP_MEM & APP_SHARED_MEM

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2019-02-06 08:23:11 -05:00
Andrew Boie 2d9bbdf5f3 x86: remove support for non-PAE page tables
PAE tables introduce the NX bit which is very desirable
from a security perspetive, back in 1995.

PAE tables are larger, but we are not targeting x86 memory
protection for RAM constrained devices.

Remove the old style 32-bit tables to make the x86 port
easier to maintain.

Renamed some verbosely named data structures, and fixed
incorrect number of entries for the page directory
pointer table.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2019-02-05 20:51:21 -08:00
Ioannis Glaropoulos aa826960d8 arch: arm: mpu: align NXP MPU implementation with ARM MPU
This commit re-works the NXP MPU driver implementation so that
it aligns with the implementation for ARMv7-M and ARMv8-M MPU
architectures.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-02-05 09:28:59 -08:00
Ioannis Glaropoulos 8d381a8b88 arch: arm: mpu: remove unnecessary MPU region type definitions
This commit removes the unnecessary MPU region type definitions
from arm_core_mpu_dev.h, as they are not used any more in any of
the architecture-specific MPU implementations (ARMv7-M, NXP, and
ARMv8-M MPU).

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-02-05 09:28:59 -08:00
Ioannis Glaropoulos a96643eb20 arch: arm: clean up depreciated implementation and API definition
This commit removes obsolete ARM CORE MPU API definitions
and related implementation from arm_mpu.c, in the wake of
the transition to the new ARM MPU design.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-02-05 09:28:59 -08:00
Ioannis Glaropoulos ab18719e83 arch: arm: mpu: implement API for memory domains in ARM (core) MPU
This commit updates the ARM Core MPU API for memory domains,
to align with the principle of de-coupling the partitioning
and the access attribution with the architecture-specific
MPU driver implementation.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-02-05 09:28:59 -08:00
Ioannis Glaropoulos 01775c98f4 arch: arm: mpu: internal API for re-configuring active partitions
This commit introduces an internal ARM MPU API that allows the
user to re-configure a memory partition in run-time.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-02-05 09:28:59 -08:00
Ioannis Glaropoulos e93b9d59c3 arch: arm: introduce/implement API to configure dynamic MPU regions
This commit introduces an ARM API that allows the user to
program a set of dynamic MPU regions at run-time. The API
function is invoked every time the memory map needs to be
re-programmed (for example at thread context-switch). The
functionality is implementated in arm_core_mpu.c.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-02-05 09:28:59 -08:00
Ioannis Glaropoulos ff573e6133 arch: arm: mpu: internal API for configuring dynamic memory regions
This commit introduces and documents the internal ARM MPU
API to configure the dynamic memory regions at run-time.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-02-05 09:28:59 -08:00
Ioannis Glaropoulos d3952b7916 arch: arm: mpu: internal API for configuring static memory regions
This commit introduces and documents the internal ARM MPU
API to configure the static memory regions at boot time.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-02-05 09:28:59 -08:00
Ioannis Glaropoulos bcc0226e49 arch: arm: mpu: update K_MEM_PARTITION_ macros for ARMv7-M
The ARM core MPU API now uses solely k_mem_partition_attr_t
objects to represent memory region attributes. The objects
now include all attribution properties (including cache-
ability and share-ability). This commit updates the macro
definitions to comply with the new ARM Core MPU standard.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-02-05 09:28:59 -08:00
Ioannis Glaropoulos d6e70da746 arch: arm: introduce/implement API for configuring static MPU regions
This commit introduces the generic ARM (core) API, which allows
the user to program a set of static (fixed) MPU regions at boot
time. The API function is invoked upon initialization, in the
ARM-specific call of _arch_switch_to_main_thread(). The API
implementation is provided in arm_core_mpu.c.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2019-02-05 09:28:59 -08:00
Anas Nashif a93651085e boards: remove pulpino board
This board is unmaintained and unsupported. It is not known to work and
has lots of conditional code across the tree that makes code
unmaintainable.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-01-31 22:47:18 -05:00
Anas Nashif 1ee7b0dc5a linker: x86: add orphan linker sections
Add missing linker section to avoid warning about orphans when building
with host compiler.

Fixes #12719

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-01-26 09:21:17 -05:00
Nathaniel Graff 0289a410ba riscv32: linker: Link .srodata section
Building tests/kernel/common/kernel.common with the new crosstools
SDK-ng resulted in an orphan short read-only data section. Fix this by
adding the .srodata section to the RISC-V linker script.

Signed-off-by: Nathaniel Graff <nathaniel.graff@sifive.com>
2019-01-23 23:28:03 -05:00
Anas Nashif 9e75a1a872 linker: add .note.GNU-stack to arc linker
When building for ARC this new section appears with gcc 8.2.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-01-17 08:44:19 -05:00
Adithya Baglody cb536111a9 Gcov: Added support for x86.
This patch adds all the required hooks needed in the kernel to
get the coverage reports from x86 SoCs.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2019-01-16 06:12:33 -05:00
Adithya Baglody 9f82eadf23 Gcov: Added support for ARM.
This patch adds all the required hooks needed in the kernel to
get the coverage reports from ARM SoCs.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2019-01-16 06:12:33 -05:00
Anas Nashif 3ba7097e73 linker: add orphan sections to linker script
Add missing sections being reported as orphan with latest compiler
version for x86 and discard them. Do the same on ARM.

Those sections are used for dynamic linking which we do not support in
Zephyr.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2019-01-14 17:10:27 -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
Andy Ross 2399c5bfbe include/arch: Steal native_posix bit manipulation routines
I was half way through typing up my own one of these when I realized
there was one already in the tree.  Move it to a shared header.

(FWIW: I really doubt that most architectures actually benefit from
their own versions of these tools -- GCC's optimizer is really good,
and custom assembly defeats optimization and factorizations of the
expressions in context.)

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2019-01-11 15:18:52 -05:00
Maureen Helm a9389da038 soc: nxp_imx: Add support for device configuration data (DCD)
Adds support for the device configuration data (DCD), which provides a
sequence of commands to the imx rt boot ROM to initialize components
such as an SDRAM.

It is now possible to use the external SDRAM instead of the internal
DTCM on the mimxrt1020_evk, mimxrt1050_evk, and mimxrt1060_evk. Note,
however, that the default board configurations still link data into
internal DTCM, therefore you must use a device tree overlay to override
"zephyr,sram = &sdram0"

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2019-01-09 16:01:25 -06:00
Maureen Helm 8e3004953d soc: nxp_imx: Add support for external xip flash boot header
Adds support for the boot data, image vector table, and FlexSPI NOR
config structures used by the imx rt boot ROM to boot an application
from an external xip flash device.

It is now possible to build and flash a bootable zephyr image to the
external xip flash on the mimxrt1020_evk, mimxrt1050_evk, and
mimxrt1060_evk boards via the 'ninja flash' build target and jlink
runner. Note, however, that the default board configurations still link
code into internal ITCM, therefore you must set CONFIG_CODE_HYPERFLASH=y
or CONFIG_CODE_QSPI=y explicitly to override the default. You must also
set CONFIG_NXP_IMX_RT_BOOT_HEADER=y to build the boot header into the
image.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2019-01-09 16:01:25 -06:00
Kumar Gala cca5b61e84 arc: cleanup linker scripts to include autoconf.h first
The various linker scripts on arc would include autoconf.h in the arch
linker script but might have CONFIG_ symbols referenced in the soc
specific linker script.  Move autoconf.h inclusion to top of the soc
specific linker script out of the arch specific one so we know
autoconf.h is seen before any CONFIG_ references.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-12-17 10:08:02 -06:00
Ioannis Glaropoulos 071a469623 arch: arm: fix initial value of _image_ram_start
For all builds, _image_ram_start is initially set to RAM_ADDR,
before it is (possibly) aligned for MPU.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-12-14 16:21:03 -06:00
Flavio Ceolin b82a339813 kernel: init: Add nop instruction in main
The main function is just a weak function that should be override by the
applications if they need. Just adding a nop instructions to explicitly
says that this function does nothing.

MISRA-C rule 2.2

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-12-14 13:17:36 +01:00
Ioannis Glaropoulos c012a288c3 arch: arm: fix bug in linker symbol definitions for application memory
The definition of __app_ram_end linker symbol has been
erroneously placed outside the last linker section of
application memory. This commit fixes the problem.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-12-10 23:05:03 -05:00
Adithya Baglody 91c5b84cd5 kernel: init.c: Added required hooks for the relocation
This patch splits the text section into 2 parts. The first section
will have some info regarding vector tables and debug info. The
second section will have the complete text section.
This is needed to force the required functions and data variables
the correct locations.
This is due to the behavior of the linker. The linker will only link
once and hence this text section had to be split to make room
for the generated linker script.

Added a new Kconfig CODE_DATA_RELOCATION which when enabled will
invoke the script, which does the required relocation.

Added hooks inside init.c for bss zeroing and data copy operations.
Needed when we have to copy data from ROM to required memory type.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2018-12-07 10:32:41 -05:00
Ioannis Glaropoulos 799b5fe4fd arch: arm: clean-up inclusions in arm_core_mpu
arm_core_mpu.h and arm_core_mpu.c defined and implement kernel
APIs for memory protection, respectively. Therefore, they do not
need to directly include ARM CMSIS headers, or arm_mpu.h (or
nxp_mpu.h) which are supposed to define MPU-related kernel types
and convenience macros for the specific MPU architecture. These
headers are indirectly included by including kernel.h.

Similarly, arm_mpu.h shall not need to include internal/external
headers of memory protection APIs.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-12-05 15:15:07 -05:00
Ioannis Glaropoulos bf34cf9443 arch: arm: mpu: Updates in ARM MPU-related convenience macros
This commit does the following:
- it introduces additional convenience macros for representing
  MPU attributions for no-cacheability, in both ARMv7-M and
  ARMv8-M MPU architectures,
- it adds documentation in K_MEM_PARTITION_IS_WRITABLE/CACHEABLE
  macros in all macro definitions in the different MPU variants
- it moves the type definition of k_mem_partition_attr_t inside
  the architecture-specific MPU headers, so it can be defined
  per-architecture. It generalizes app_mem_domain.h, to be able
  to work with _any_ (struct) type of k_mem_partition_attr_t.
- it refactors the type of k_mem_partition_attr_t for ARMv8-M
  to comply with the MPU register API.
- for NXP MPU, the commit moves the macros for region access
  permissions' attributes inside nxp_mpu.h, to align with what
  we do for ARM MPU.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-12-05 15:15:07 -05:00
Ioannis Glaropoulos 39bf24a9bd kernel: expose k_mem_partition_attr_t outside User mode
This commit exposes k_mem_partition_attr_t outside User Mode, so
we can use struct k_mem_partition for defining memory partitions
outside the scope of user space (for example, to describe thread
stack guards or no-cacheable MPU regions). A requirement is that
the Zephyr build supports Memory protection. To signify this, a
new hidden, all-architecture Kconfig symbol is defined (MPU). In
the wake of exposing k_mem_partition_attr_t, the commit exposes
the MPU architecture-specific access permission attribute macros
outside the User space context (for all ARCHs), so they can be
used in a more generic way.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-12-05 15:15:07 -05:00
Marti Bolivar f4c3163d3b arch: riscv32: provide a general mechanism for saving SoC context
RISC-V permits myriad extensions to the ISA, any of which may imply
additional context that must be saved and restored on ISR entry and
exit. The current in-tree example is the Pulpino core, which has extra
registers used by ISA extensions for running loops that shouldn't get
clobbered by an ISR.

This is currently supported by including pulpino-specific definitions
in the generic architecture code. This works, but it's a bit inelegant
and is something of a layering violation. A more generic mechanism is
required to support other RISC-V SoCs with similar requirements
without cluttering the arch code too much.

Provide that by extending the semantics of the existing
CONFIG_RISCV_SOC_CONTEXT_SAVE option to allow other SoCs to allocate
space for saving and restoring their own state, promoting the
currently pulpino-specific __soc_save_context / __soc_restore_context
routines to a RISC-V arch API.

The cost of making this generic is two more instructions in each ISR
to pass the SoC specific context to these routines in a0 rather than
just assuming the stack points to the right place. This is minimal,
and should have been done anyway to keep with the ABI.

As a first (and currently only in-tree) customer, convert the Pulpino
SoC code to this new mechanism.

Signed-off-by: Marti Bolivar <marti@foundries.io>
2018-12-04 22:54:23 -05:00
Håkon Øye Amundsen d85efe0b10 arch: arm: Add symbol for flash used
Add symbol which contains the number of bytes contained
in the image.

Using '_image_rom_end' will not work, as there are
symbols loaded after its value.

Signed-off-by: Håkon Øye Amundsen <haakon.amundsen@nordicsemi.no>
2018-12-04 14:07:59 +01:00
Aurelien Jarno 6fd1691b94 kernel: Add a "nocache" read-write memory section
Add a "nocache" read-write memory section that is configured to
not be cached. This memory section can be used to perform DMA
transfers when cache coherence issues are not optimal or can not
be solved using cache maintenance operations.

This is currently only supported on ARM Cortex M7 with MPU.

Fixes #2927

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-12-03 09:54:31 -08:00
Ioannis Glaropoulos 5eed503290 arch: arc: add missing macro helper definition
Helper macro, MPU_ALIGN() is used by script
gen_app_partitions.py, so the macro needs to be available,
if the APP Shared memory feature is to be used. This commit
defines MPU_ALIGN() in the ARC linker.ld script.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-11-30 10:54:19 -08:00
Flavio Ceolin 0bf21ca2a9 syscall: Return bool in a boolean function
MISRA-C rule 14.4

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-11-30 08:05:11 -08:00
Ioannis Glaropoulos c15c491199 cmake: move app_data_alignment.ld under ARC sub-directory
This commit moves the app_data_alignment.ld scripts
under arch/arc sub-directory, as it is not not used
at all in ARM builds. The script is still used for
ARC, whose v2 MPU also has the reuquirement for
power-of-two size alignment.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-11-30 15:22:58 +01:00
Ioannis Glaropoulos 92f9b24ac9 arch: arm: make _image_ram_start point to the beginning of sram
Move the definition of _image_ram_start at the beginning
of the RAMMABLE (SRAM) region, so it points to the actual
start of RAM linker sections.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-11-30 15:22:58 +01:00
Ioannis Glaropoulos 62c5894bc1 arch: arm: properly enforce MPU-aware linker section alignment
This commit standardizes and simplifies the way we enforce
linker section alignment, to comply with minimum alignment
requirement for MPU, if we build Zephyr with MPU support:
- it enforces alignment with the minimum MPU granularity at
  the beginning and end of linker sections that require to
  be protected by MPU,
- it enforces alignment with size if required by the MPU
  architecture.

Particularly for the Application Memory section, the commit
simplifies how the proper alignment is enforced, removing
the need of calculating the alignment with a post-linker
python script. It also removes the need for an additional
section for padding.

For the Application Shared Memory section(s), the commit
enforces minimum alignment besides the requirement for
alignment with size (for the respective MPUs) and fixes
a bug where the app_data_align was erronously used in the
scipts for auto-generating the linker scripts.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-11-30 15:22:58 +01:00
Ioannis Glaropoulos 80d38788fc arch: arm: utilize Kconfig option for min ARM MPU region size
The commit enforces the use of ARM_MPU_REGION_MIN_ALIGN_AND_SIZE
in include/arch/arm/arch.h, instead of using 32 as a hard-coded
value. The symbol is also used in arm/thread.c to truncate the
thread stack size to satisfy MPU granularity. The commit does
not introduce behavioral changes.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-11-30 15:22:58 +01:00
Ioannis Glaropoulos 61ccafa8a5 arch: arm: fix the convenience macro for ARMv7-M MPU
This commit fixes a bug in the ARMv7-M convenience macro that
evaluates write-ability of given access permissions attributes.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-11-27 10:11:18 -08:00
Ioannis Glaropoulos d51f138703 arch: arm: mpu: declare and define nxp_mpu_config as const
Declare and define nxp_mpu_config and nxp_mpu_regions
structs as const, as they are not modified in run-time.

Fixes #10320

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-11-21 09:44:21 -05:00
Ioannis Glaropoulos 8204ecbead arch: arm: mpu: declare and define arm_mpu_config as const
Declare and define arm_mpu_config and arm_mpu_regions
structs as const, as they are not modified in run-time.

Fixes #10320

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-11-21 09:44:21 -05:00
Ioannis Glaropoulos f0c459a9c2 arch: arm: mpu: improve documentation of nxp_mpu_config
This commit enhances the documentation of the nxp_mpu_config
element in include/arch/arm/cortex_m/mpu/nxp_mpu.h, stressing
that it intends to store information for fixed MPU regions.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-11-21 09:44:21 -05:00
Savinay Dharmappa eddfd537d2 arch: xtensa: Add I/O functions to read/write.
patch add I/O function to read / write from 16 bit
memory mapped registers

Signed-off-by: Savinay Dharmappa <savinay.dharmappa@intel.com>
2018-11-13 18:49:03 -05: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
Andrew Boie 506f15c381 interrupts: simplify position of sw ISR table
We now place the linker directives for the SW ISR table
in the common linker scripts, instead of repeating it
everywhere.

The table will be placed in RAM if dynamic interrupts are
enabled.

A dedicated section is used, as this data must not move
in between build phases.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-11-10 11:01:22 -05:00
Andrew Boie 7bac15f2ff x86: add dynamic interrupt support
If dynamic interrupts are enabled, a set of trampoline stubs
are generated which transfer control to a common dynamic
interrupt handler function, which then looks up the proper
handler and parameter and then executes the interrupt.

Based on the prior x86 dynamic interrupt implementation which
was removed from the kernel some time ago, and adapted to
changes in the common interrupt handling code, build system,
and IDT generation tools.

An alternative approach could be to read the currently executing
vector out of the APIC, but this is a much slower operation.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-11-10 11:01:22 -05:00
Ioannis Glaropoulos 95a091f962 arch: arm: ensure shared mem and app sram MPU regions don't overlap
This commit contributes a patch to the Arm Cortex-M linker
script, which guarantees that the linker sections for shared
memory and the application memory will have sufficient padding
in between, so that the latter will start from an address that
is 32-byte aligned. This is required for ensuring that the MPU
regions defined using the start and end addresses of the two
sections will not overlap. The patch targets ARMv8-M MPU with
no requirement for power-of-two alignment and size.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-11-09 10:48:07 -05:00
Marek Pieta c99fd5c807 subsys: debug: tracing: Fix interrupt hooks
Change fixes interrupt hooks.

Signed-off-by: Marek Pieta <Marek.Pieta@nordicsemi.no>
2018-11-06 16:15:29 -05:00
Anas Nashif c2c6a6a245 qemu_riscv32: use hifive1 configuration
Use hifive1 configuration for this qemu and set
SYS_CLOCK_HW_CYCLES_PER_SEC to 10000000

Fixes #10043

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-11-05 11:00:38 -05:00
Vitaly Gaiduk abdb8785cb linker: riscv: Disable creating ROM domain by config option.
Patch is useful for RISCV platforms which can not provide ROM memory.
Switching CONFIG_XIP to "n" disables allocating ROM region.

Signed-off-by: Vitaly Gaiduk <vitaly.gaiduk@cloudbear.ru>
2018-11-03 23:00:01 -04:00
Daniel Leung 5a47c60dbf arch: xtensa: include soc.h to fix build errors
There are places where soc.h must be included. So include it.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2018-11-03 12:40:33 -04:00
Kumar Gala 321c8202d2 linker: Fixup warning associated with .ARC.attributes section
With newer linker for ARC we can possibly get a warning like:

   real-ld: warning: orphan section `.ARC.attributes' from `(foo.o)'
   being placed in section `.ARC.attributes'.

Fixes #11060

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-11-02 23:32:32 -04:00
Kumar Gala ec43725562 arch: Remove board.h include from arch files
The arch code doesn't need anything from board.h so lets remove the
include.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-11-01 13:15:18 +01:00
Flavio Ceolin 1fb77d1781 arch: x86: Remove unused struct
struct segment_selector is defined but never used. Besides that, this
tag identifier was clashing with other identifier, what is an undefined
behaviour in C99.

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-10-31 19:43:47 -04:00
Benoit Leforestier 3bbf5af668 Linker: Add ".ARM.extab" section in linker script for Cortex-M
When using C++ exceptions in a Cortex-M, the linker return a warning:
warning: orphan section ".ARM.extab"
.ARM.extab section containing exception unwinding information.
This section is missing in the linker script for Cortex-M.

Signed-off-by: Benoit Leforestier <benoit.leforestier@gmail.com>
2018-10-30 19:04:50 -04:00
Daniel Leung 6600c64331 linker: warn about orphan sections
(Previous patch set was reverted due to issue with priv_stack.
 Resubmitting after fixing the faults caused by priv_stack.noinit
 not at the end of RAM.)

This adds a linker flag and necessary changes to linker scripts
so that linker will warn about orphan sections.

Relates to #5534.

Fixes #10473, #10474, #10515.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2018-10-19 16:11:34 -04:00
Adithya Baglody 1fa8cf9279 linker: arm: place priv.noinit at the end of RAM
This puts the priviledged stack at the end of RAM.
This combines PR #10507 and #10542.

Fixes #10473
Fixes #10474
Fixes #10515

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2018-10-19 16:11:34 -04:00
Daniel Leung 20e2e5bad8 arm: cypress/psoc6: add SoC specific linker input sections
The Cypress PSoC6 specifies some input sections in the startup
scripts. These sections (.heap, .stack, etc.) need to be placed
at correct location.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2018-10-19 16:11:34 -04:00
Daniel Leung 1134e59bd2 linker: allow SoC to insert linker script fragments
This allows the SoC to specify some additional linker script
fragments into the bss, data and read-only data sections.

For example, the Cypress PSOC6 has a few input sections that
must be put into bss and data sections. Without specifying
these in the linker script, they are consider orphan sections
and the placement is based on linker heuristic which is
arbitrary.

POSIX is not supported as the main linker script is
provided by the host system's binutils and we have no control
over it. Also, currently Xtensa SoCs have their own linker
scripts so there is no need to this feature.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2018-10-19 16:11:34 -04:00
Adithya Baglody 441d75770f arch: arc: arcv2_irq_unit.h: MISRA C violation fix.
The function _arc_v2_irq_unit_is_in_isr computes a Boolean
value but the function returns a integer value.
Fix the return type of the function.

This makes the zephyr api _is_in_isr() return a boolean type.
Thereby making it consistent across all the architectures.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2018-10-17 12:17:58 -04:00
Anas Nashif 1d0136ef3b Revert "linker: allow SoC to insert linker script fragments"
This reverts commit 2fed930f4e.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-10-14 12:14:04 -04:00
Anas Nashif a220e2690f Revert "arm: cypress/psoc6: add SoC specific linker input sections"
This reverts commit 08c165f2b0.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-10-14 12:14:04 -04:00
Anas Nashif 0d4b5daeaa Revert "linker: warn about orphan sections"
This reverts commit 8ce758a8ff.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-10-14 12:14:04 -04:00
Anas Nashif ae34d9d4c2 Revert "arch: arm: linker.ld: Fixed incorrect placement of noinit section"
This reverts commit 4f78d86eb7.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-10-14 12:14:04 -04:00
Anas Nashif bb0e49c610 Revert "linker: use wildcards in rel-sections.ld"
This reverts commit 9ae3ea47b0.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-10-14 12:14:04 -04:00
Daniel Leung 9ae3ea47b0 linker: use wildcards in rel-sections.ld
Update rel-sections.ld to use wildcards instead of
spelling out those sections one by one.

Also, for POSIX, don't include this and turns off
the warnings. With different host toolchain across
different OS, it would be maintanence nightmare
to account for all those combinations. So this reverts
the POSIX linker script to before the first orphan
section changes.

Fixes #10493

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2018-10-12 13:21:52 -04:00
Adithya Baglody 4f78d86eb7 arch: arm: linker.ld: Fixed incorrect placement of noinit section
This was causing an incorrect hash for privileged stack.

Fixes: GH-10473
Fixes: GH-10474
Fixes: GH-10475
Fixes: GH-10476

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2018-10-11 09:56:37 -04:00
Ioannis Glaropoulos 2c1837d908 arch: arm: fix K_MEM_PARTITION_IS_WRITABLE definition
In ARMv8-M MPU it is not possible to have the following access
permissions: Privileged RW / Unprivileged RO. So we define
K_MEM_PARTITION_IS_WRITABLE macro separately for v8M and v7M MPU
architectures (in the separate include files).

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-10-09 19:33:24 -04:00
Daniel Leung 8ce758a8ff linker: warn about orphan sections
This adds a linker flag and necessary changes to linker scripts
so that linker will warn about orphan sections.

Relates to #5534.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2018-10-09 08:23:41 -04:00
Daniel Leung 08c165f2b0 arm: cypress/psoc6: add SoC specific linker input sections
The Cypress PSoC6 specifies some input sections in the startup
scripts. These sections (.heap, .stack, etc.) need to be placed
at correct location.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2018-10-09 08:23:41 -04:00
Daniel Leung 2fed930f4e linker: allow SoC to insert linker script fragments
This allows the SoC to specify some additional linker script
fragments into the bss, data and read-only data sections.

For example, the Cypress PSOC6 has a few input sections that
must be put into bss and data sections. Without specifying
these in the linker script, they are consider orphan sections
and the placement is based on linker heuristic which is
arbitrary.

POSIX is not supported as the main linker script is
provided by the host system's binutils and we have no control
over it. Also, currently Xtensa SoCs have their own linker
scripts so there is no need to this feature.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2018-10-09 08:23:41 -04:00
Anas Nashif eb29978a57 userspace: move KOBJECT/PRIVILEGED_STACK_TEXT_AREA to Kconfig
Instead of hardcoding in linker script, use a Kconfig and deal with
dependencies in Kconfig instead of directly in the linker file.

This patch moves both:
PRIVILEGED_STACK_TEXT_AREA
and
KOBJECT_TEXT_AREA

to arch/Kconfig.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-10-08 14:18:26 -04:00
Ioannis Glaropoulos d1757d8d1b arch: arm: improve documentation for ARMv8-M fixed region setup
Improve the documentation of the ARMv8-M MPU convenience macros
for setting up MPU regions at boot time, stressing that the
macros intend to be used for non-overlapping, fixed MPU regions.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-10-02 12:12:08 -05:00
Ioannis Glaropoulos b41934fa21 arch: arm: mpu: improve documentation of mpu_config
This commit enhances the documentation of the mpu_config
element in include/arch/arm/cortex_m/mpu/arm_mpu.h, stressing
that it intends to store information for fixed MPU regions.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-10-02 12:12:08 -05:00
Ioannis Glaropoulos 9a06e9a0d0 arch: arm: remove obsolete inline comment
Remove an inline explanatory comment for the thread
stack region type that is obsolete. The comment had
been been erroneously kept in after the enumeration
of MPU region types was refactored and cleaned up.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-10-02 12:12:08 -05:00
Adithya Baglody 10c6a0c1aa subsys: app_memory: Fixed the build issue wrt ARC.
The linker script is updated to support the new method of size
calculation.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2018-09-28 08:09:23 +05:30
Adithya Baglody 7f4a31794e subsys: app_memory: Fixed incorrect linker syntax.
Any calculation based on linker variables shouldn't be inside
sections.
Also added the linker macro needed for the shared memory.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2018-09-28 08:09:23 +05:30
Flavio Ceolin 10f903722a kernel: Avoid duplicated type definition in x86
According with ISO/IEC 9899:1999 §6.7 Declarations, typedefs name must
be uniques.

C99 clause 6.7
MISRA-C rule 1.1

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-28 07:58:19 +05:30
Flavio Ceolin 6fdc56d286 kernel: Using boolean types for boolean constants
Make boolean expressions use boolean types.

MISRA-C rule 14.4

Signed-off-by: Flavio Ceolin <flavio.ceolin@intel.com>
2018-09-28 06:28:41 +05:30
Ioannis Glaropoulos 12c02448aa arch: arm: style fixes in documentation of MPU region types
Some minor style fixes and rewording of the documentation
for ARM MPU region types.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-09-27 08:10:02 -05:00
Ioannis Glaropoulos 4732328491 arch: arm: group Userspace-related regions together
This commit groups together the MPU region types
that are related to the User-space feature, so that
a single #ifdef USERSPACE is present in the enum.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-09-27 08:10:02 -05:00
Ioannis Glaropoulos 66192618a7 arch: arm: Minor style and typo fixes in inline comments
Several style and typo fixes in inline comments of arm kernel
files and thread.c.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-09-24 04:56:34 -07:00
Adithya Baglody 31c8817d60 include: arm: CMSIS header redefining MPU_PRESENT.
The header should check if the macro _MPU_PRESENT is defined
and create it only if not defined.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2018-09-20 20:35:25 -04:00
Adithya Baglody ae92f2badf subsys: app_memory: Fixed the size calculation for power of 2 MPUs
The size calculation for power of 2 MPUs were incorrect.
The calculation was not taking into account the amount of padding
the linker does when doing the required alignment. Hence the size
being calculated was completely incorrect.

With this patch the code now is optimized and the size of
partitions is now provided by the linker.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2018-09-20 11:25:53 -04:00
Piotr Zięcik 1c16cfcc30 arch: arm: Make ARM_MPU the sole option controlling MPU usage
This commit removes all MPU-related (ARM_CORE_MPU and NXP_MPU)
options exept ARM_MPU, which becomes master switch controlling
MPU support on ARM.

Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2018-09-20 14:16:50 +02: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
Ioannis Glaropoulos 726bda6a60 arch: arm: correct placement of macro documentation
This commit moves the documentation corresponding to
_ARCH_THREAD_STACK_DEFINE(..) macro to the right place.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-09-11 11:38:06 -05:00
Anas Nashif 6b6ecc0803 Revert "kernel: Enable interrupts for MULTITHREADING=n on supported arch's"
This reverts commit 17e9d623b4.

Single thread keep introducing more issues, decided to remove the
feature completely and push any required changes for after 1.13.

See #9808

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-09-06 13:09:26 -04:00
Andy Ross 17e9d623b4 kernel: Enable interrupts for MULTITHREADING=n on supported arch's
Some applications have a use case for a tiny MULTITHREADING=n build
(which lacks most of the kernel) but still want special-purpose
drivers in that mode that might need to handle interupts.  This
creates a chicken and egg problem, as arch code (for obvious reasons)
runs _Cstart() with interrupts disabled, and enables them only on
switching into a newly created thread context.  Zephyr does not have a
"turn interrupts on now, please" API at the architecture level.

So this creates one as an arch-specific wrapper around
_arch_irq_unlock().  It's implemented as an optional macro the arch
can define to enable this behavior, falling back to the previous
scheme (and printing a helpful message) if it doesn't find it defined.
Only ARM and x86 are enabled in this patch.

Fixes #8393

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-08-27 16:15:10 -04:00
Wayne Ren d68c016793 arch: arc: enable stack check when arc is in secure mode
when arc is in secure mode, SSC bit of sec_stat,
not SC bit of status32,is used to enable stack check.

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2018-08-22 07:57:11 -07:00
Anas Nashif 483910ab4b systemview: add support natively using tracing hooks
Add needed hooks as a subsystem that can be enabled in any application.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-08-21 05:45:47 -07:00
Anas Nashif b6304e66f6 tracing: support generic tracing hooks
Define generic interface and hooks for tracing to replace
kernel_event_logger and existing tracing facilities with something more
common.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-08-21 05:45:47 -07:00
Ioannis Glaropoulos 2a1fe6e285 arch: arm: implement ARMv8-M MPU driver
This commit implements and integrates the ARMv8-M MPU driver
into the memory protection system for ARM.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-08-19 11:18:14 -07:00
Ioannis Glaropoulos c8ea36530c arch: arm: type definition for arm mpu attribute container
This commit introduces a type definition for the ARM MPU
region attribute container. This allows to abstract the type
of the attribute container and make the code extendible for
ARMv8-M, where the size and structure of the attribute
container will be different.

Therefore, we can, now, move the definition of the region
data structure in the common arm_mpu.h header.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-08-19 11:18:14 -07:00
Ioannis Glaropoulos db3f6aab02 arch: arm: add option to define an NSC region
This commit adds K-config options that allow the user to
signify an ARM Secure Firmware that contains Secure Entry
functions and to define the starting address of the linker
section that will contain the Secure Entry functions. It
also instructs the linker to append the NSC section if
instructed so by the user.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-08-13 18:58:11 -07:00
Kumar Gala 4b22ba7e4b syscall: Move arch specific syscall code into its own header
Split out the arch specific syscall code to reduce include pollution
from other arch related headers.  For example on ARM its possible to get
errno.h included via SoC specific headers.  Which created an interesting
compile issue because of the order of syscall & errno/errno syscall
inclusion.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-08-02 22:06:49 -05:00
Daniel Leung 615703423e arch/x86: always make BSS section MMU page align if X86_MMU
If MMU is enabled, always make the BSS section MMU page aligned.
According to the comments, it is always aligned anyway.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2018-07-31 22:32:59 -04:00
Alberto Escolar Piedras 550225b668 native: Generalize native tasks
Some drivers or tests need to execute some code before Zephyr is
booted, dynamically register command line arguments, etc.

For this purpose, we generalize the NATIVE_EXIT_TASK to also
provide hooks to run a function at a given point during the startup
of native_posix.

Also, test/boards/native_posix/exit_tasks is generalized to cover
this new functionality.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-07-30 22:13:46 -04:00
Nathaniel Graff 15516ed0ef linker: riscv: Relocate .eh_frame symbol
The .eh_frame symbol was causing __data_rom_start to contain the wrong
offset into the ROM, resulting in corrupt data copied into RAM by
_data_copy(). Fix by placing the .eh_frame in the .text section as is
done in include/arch/x86/linker.ld

Signed-off-by: Nathaniel Graff <nathaniel.graff@sifive.com>
2018-07-30 13:38:31 -05:00
Daniel Leung 0b89920579 arch/x86: update linker definition for x86 real mode
When building the real mode, the linker definition has to place
the real mode entry code at the start of flash area.

Signed-off-by: Daniel Leung <daniel.leung@intel.com>
2018-07-28 08:14:27 -04:00
Shawn Mosley 573f32b6d2 userspace: compartmentalized app memory organization
Summary: revised attempt at addressing issue 6290.  The
following provides an alternative to using
CONFIG_APPLICATION_MEMORY by compartmentalizing data into
Memory Domains.  Dependent on MPU limitations, supports
compartmentalized Memory Domains for 1...N logical
applications.  This is considered an initial attempt at
designing flexible compartmentalized Memory Domains for
multiple logical applications and, with the provided python
script and edited CMakeLists.txt, provides support for power
of 2 aligned MPU architectures.

Overview: The current patch uses qualifiers to group data into
subsections.  The qualifier usage allows for dynamic subsection
creation and affords the developer a large amount of flexibility
in the grouping, naming, and size of the resulting partitions and
domains that are built on these subsections. By additional macro
calls, functions are created that help calculate the size,
address, and permissions for the subsections and enable the
developer to control application data in specified partitions and
memory domains.

Background: Initial attempts focused on creating a single
section in the linker script that then contained internally
grouped variables/data to allow MPU/MMU alignment and protection.
This did not provide additional functionality beyond
CONFIG_APPLICATION_MEMORY as we were unable to reliably group
data or determine their grouping via exported linker symbols.
Thus, the resulting decision was made to dynamically create
subsections using the current qualifier method. An attempt to
group the data by object file was tested, but found that this
broke applications such as ztest where two object files are
created: ztest and main.  This also creates an issue of grouping
the two object files together in the same memory domain while
also allowing for compartmenting other data among threads.

Because it is not possible to know a) the name of the partition
and thus the symbol in the linker, b) the size of all the data
in the subsection, nor c) the overall number of partitions
created by the developer, it was not feasible to align the
subsections at compile time without using dynamically generated
linker script for MPU architectures requiring power of 2
alignment.

In order to provide support for MPU architectures that require a
power of 2 alignment, a python script is run at build prior to
when linker_priv_stacks.cmd is generated.  This script scans the
built object files for all possible partitions and the names given
to them. It then generates a linker file (app_smem.ld) that is
included in the main linker.ld file.  This app_smem.ld allows the
compiler and linker to then create each subsection and align to
the next power of 2.

Usage:
 - Requires: app_memory/app_memdomain.h .
 - _app_dmem(id) marks a variable to be placed into a data
section for memory partition id.
 - _app_bmem(id) marks a variable to be placed into a bss
section for memory partition id.
 - These are seen in the linker.map as "data_smem_id" and
"data_smem_idb".
 - To create a k_mem_partition, call the macro
app_mem_partition(part0) where "part0" is the name then used to
refer to that partition. This macro only creates a function and
necessary data structures for the later "initialization".
 - To create a memory domain for the partition, the macro
app_mem_domain(dom0) is called where "dom0" is the name then
used for the memory domain.
 - To initialize the partition (effectively adding the partition
to a linked list), init_part_part0() is called. This is followed
by init_app_memory(), which walks all partitions in the linked
list and calculates the sizes for each partition.
 - Once the partition is initialized, the domain can be
initialized with init_domain_dom0(part0) which initializes the
domain with partition part0.
 - After the domain has been initialized, the current thread
can be added using add_thread_dom0(k_current_get()).
 - The code used in ztests ans kernel/init has been added under
a conditional #ifdef to isolate the code from other tests.
The userspace test CMakeLists.txt file has commands to insert
the CONFIG_APP_SHARED_MEM definition into the required build
targets.
  Example:
        /* create partition at top of file outside functions */
        app_mem_partition(part0);
        /* create domain */
        app_mem_domain(dom0);
        _app_dmem(dom0) int var1;
        _app_bmem(dom0) static volatile int var2;

        int main()
        {
                init_part_part0();
                init_app_memory();
                init_domain_dom0(part0);
                add_thread_dom0(k_current_get());
                ...
        }

 - If multiple partitions are being created, a variadic
preprocessor macro can be used as provided in
app_macro_support.h:

        FOR_EACH(app_mem_partition, part0, part1, part2);

or, for multiple domains, similarly:

        FOR_EACH(app_mem_domain, dom0, dom1);

Similarly, the init_part_* can also be used in the macro:

        FOR_EACH(init_part, part0, part1, part2);

Testing:
 - This has been successfully tested on qemu_x86 and the
ARM frdm_k64f board.  It compiles and builds power of 2
aligned subsections for the linker script on the 96b_carbon
boards.  These power of 2 alignments have been checked by
hand and are viewable in the zephyr.map file that is
produced during build. However, due to a shortage of
available MPU regions on the 96b_carbon board, we are unable
to test this.
 - When run on the 96b_carbon board, the test suite will
enter execution, but each individaul test will fail due to
an MPU FAULT.  This is expected as the required number of
MPU regions exceeds the number allowed due to the static
allocation. As the MPU driver does not detect this issue,
the fault occurs because the data being accessed has been
placed outside the active MPU region.
 - This now compiles successfully for the ARC boards
em_starterkit_em7d and em_starterkit_em7d_v22. However,
as we lack ARC hardware to run this build on, we are unable
to test this build.

Current known issues:
1) While the script and edited CMakeLists.txt creates the
ability to align to the next power of 2, this does not
address the shortage of available MPU regions on certain
devices (e.g. 96b_carbon).  In testing the APB and PPB
regions were commented out.
2) checkpatch.pl lists several issues regarding the
following:
a) Complex macros. The FOR_EACH macros as defined in
app_macro_support.h are listed as complex macros needing
parentheses.  Adding parentheses breaks their
functionality, and we have otherwise been unable to
resolve the reported error.
b) __aligned() preferred. The _app_dmem_pad() and
_app_bmem_pad() macros give warnings that __aligned()
is preferred. Prior iterations had this implementation,
which resulted in errors due to "complex macros".
c) Trailing semicolon. The macro init_part(name) has
a trailing semicolon as the semicolon is needed for the
inlined macro call that is generated when this macro
expands.

Update: updated to alternative CONFIG_APPLCATION_MEMORY.
Added config option CONFIG_APP_SHARED_MEM to enable a new section
app_smem to contain the shared memory component.  This commit
seperates the Kconfig definition from the definition used for the
conditional code.  The change is in response to changes in the
way the build system treats definitions.  The python script used
to generate a linker script for app_smem was also midified to
simplify the alignment directives.  A default linker script
app_smem.ld was added to remove the conditional includes dependency
on CONFIG_APP_SHARED_MEM.  By addining the default linker script
the prebuild stages link properly prior to the python script running

Signed-off-by: Joshua Domagalski <jedomag@tycho.nsa.gov>
Signed-off-by: Shawn Mosley <smmosle@tycho.nsa.gov>
2018-07-25 12:02:01 -07:00
Ioannis Glaropoulos 90b64489e5 arch: arm: allow processor to ignore/recover from faults
This commit adds the implementation that allows the ARM CPU
to recover from (otherwise fatal) MPU faults. A new error
reason, _NANO_ERR_RECOVERABLE, is introduced. The error
reason is used to suppress fault dump information, if the
error is actually recoverable.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-07-23 10:50:30 -07:00
Andrew Boie 45f069a4bb arc: arch.h: move extern "C" after includes
Shouldn't declare this and then pull in headers, fixes
error like "util.h:41:1: error: template with C linkage"

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-07-19 16:44:59 -07:00
Andrew Boie 362716762b arm: arch.h: move extern "C" after includes
Shouldn't declare this and then pull in headers, fixes
errors like "util.h:41:1: error: template with C linkage"

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-07-19 16:44:59 -07:00
Alberto Escolar Piedras 15d847add8 native: Add NATIVE_EXIT_TASK hooks
Some of the native application components or drivers need to
do a proper cleanup before the executable exits.
So we provide a macro similar to SYS_INIT but which will be
called just before exiting.
This can be used for freeing up resources, closing descriptors,
or doing any neccessary signaling to any other host process.

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-07-18 15:43:12 -04:00
Aurelien Jarno 15d3dfa9b0 arch: arm: mpu: enable WT caching on Flash
Change the REGION_FLASH_ATTR macros to set the cache attributes on Flash
regions to "Outer and inner write-through. No write allocate.". This
matches the cache attributes used when the MPU is disabled.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-07-11 10:55:31 -04:00
Aurelien Jarno 06bb05533d arch: arm: mpu: enable WBWA caching on RAM
Change the REGION_RAM_ATTR macro to set the cache attributes on RAM
regions to "Outer and inner write-back. Write and read allocate". This
matches the cache attributes used when the MPU is disabled.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-07-11 10:55:31 -04:00
Aurelien Jarno f5b00ff60e arch: arm: mpu: fix outer inner WBWA non-shareable macro
Fix NORMAL_OUTER_INNER_WRITE_BACK_WRITE_READ_ALLOCATE_NONSHAREABLE, the
bufferable bit should be set, while the shareable one should not be set.

At the same time, rename it from ..._NONSHAREABLE to _NON_SHAREABLE to
keep the same naming convention for all macro. Given it's not (yet)
used, it should not be an issue.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-07-11 10:55:31 -04:00
Aurelien Jarno 747b90c3da arch: arm: mpu: remove REGION_USER_RAM_ATTR macro
This is currently unused, and all the user regions are set up at runtime
on a per thread basis.

Signed-off-by: Aurelien Jarno <aurelien@aurel32.net>
2018-07-11 10:55:31 -04:00
Maureen Helm 530a71310e arm: nxp: mpu: Consolidate k64 mpu regions
Reduces the number of mpu regions statically reserved at boot time by
one, giving a total of five. We originally sought to reduce the total to
three: 1 background region with lowest precendence for supervisor r/w, 1
flash region, and 1 sram region. However, the nxp mpu hardware does not
give precedence to any region over another, and thus we cannot revoke
access from the background region with a higher priority region. This
means we cannot support hardware stack protection with a single
background region.

Instead, create two background regions that cover the entire address
space, except for sram.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
2018-07-10 12:46:04 -04:00
Ioannis Glaropoulos f93b3d1947 arch: arm: fix linker script title comment
Fix the title comment in the linker.ld script for ARM, to
make it clear that this is the common linker script for all
Cortex-M based platforms.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-07-10 09:12:42 -04:00
Ioannis Glaropoulos 54fbcc08a9 arch: arm: mpu: get REGION_SIZE_<X> defines directly from ARM CMSIS
This commit re-defines the REGION_SIZE_<x> macros, present in
include/arch/arm/cortex_m/mpu/arm_mpu_v7m.h, with the help of
the existing ARM MPU regions size definitions in ARM CMSIS.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-07-05 15:23:37 -05:00
Ioannis Glaropoulos df41ed885a arch: arm: mpu: replace literals with CMSIS bitsets
This commit refactors internal functions in arm_mpu.c to use
bitsets and functions taken directly from ARM CMSIS instead of
hardcoded arithmetic literals. In several internal functions
some part of the implementation is abstracted further in inline
functions or convenience macros, to facilitate extending the
arm_mpu.c for ARMv8-M. In addition, the commit adds minor
improvements in internal function documentation.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-07-04 08:25:02 -04:00
Ioannis Glaropoulos ca6b21b907 arch: arm: move ARMv7-m specific content in corresponding header file
This commit moves the macro definitions and convenience wrappers
for ARM MPU that are specific to ARMv6-m, and ARMv7-m to an
arch-specific MPU header file. It leaves only the generic
content in arm_mpu.h, i.e. the content that is supposed to
be common for ARMv8-M MPU.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-07-03 18:43:10 -04:00
Ioannis Glaropoulos 816100a632 arch: arm: use CMSIS bitset flags for MPU attribute definitions
This commit modifies the interal macro defitions for MPU region
attributes in arm_mpu.h to use bitset flags directly from CMSIS.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-07-03 18:43:10 -04:00
Ioannis Glaropoulos 559249ee01 arch: arm: Remove redundant HAL definition for ARM MPU
This commit removes the redundant HAL definition for the ARM
Cortex-M MPU registers, and modifies the ARM MPU driver
implementation to directly use the provided HAL from CMSIS.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-07-03 18:43:10 -04:00
Sebastian Bøe 347f9a0a2d cmake: LD: Specify the entry point in the linker scripts
The entry point can and therefore should be set by linker
scripts. Whenever possible one should express things in the source
language, be it .c or .ld, and not in code generators or in the build
system.

This patch removes the flag -eCONFIG_KERNEL_ENTRY from the linker's
command line and replaces it with the linker script command

ENTRY(CONFIG_KERNEL_ENTRY)

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-07-03 17:18:14 -04:00
Rajavardhan Gundi d4dd928eaa kernel/stack: Introduce K_THREAD_STACK_LEN macro
This is a public macro which calculates the size to be allocated for
stacks inside a stack array. This is necessitated because of some
internal padding (e.g. for MPU scenarios). This is particularly
useful when a reference to K_THREAD_STACK_ARRAY_DEFINE needs to be
made from within a struct.

Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
2018-07-03 08:44:09 -07:00
Andrew Boie 8bcffefb33 arch: arm: clean up MPU code for ARM and NXP
* We are now *much* better at not reserving unnecessary
system MPU regions based on configuration. The #defines
for intent are now an enumerated type. As a bonus, the
implementation of _get_region_index_by_type() is much
simpler. Previously we were wasting regions for stack guard
and application memory if they were not configured.

* NXP MPU doesn't reserve the last region if HW stack
protection isn't enabled.

* Certain parts of the MPU code are now properly ifdef'd
based on configuration.

* THREAD_STACK_REGION and THREAD_STACK_USER_REGION was a
confusing construction and has now been replaced with
just THREAD_STACK_REGION, which represents the MPU region
for a user mode thread stack. Supervisor mode stacks
do not require an MPU region.

* The bounds of CONFIG_APPLICATION_MEMORY never changes
and we just do it once during initialization instead of
every context switch.

* Assertions have been added to catch out-of-bounds cases.

Fixes: #7384

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-06-27 12:56:38 -07:00
Sebastian Bøe a1e806bf44 gen_isr_tables: Delete the dead code accompanying .intList.num_isrs
intList has been populated with the number of isrs, aka interrupts,
but nothing has not been using this information so we drop it and
everything used to construct it.

Signed-off-by: Sebastian Bøe <sebastian.boe@nordicsemi.no>
2018-06-25 12:54:49 -07:00
Ioannis Glaropoulos 071f5153ac arch: arm: mpu: include CMSIS header in arm_mpu.h
This commit includes the arch/arm/cortex_m/cmsis.h directly
in arm_mpu.h. This is requires as arm_mpu.h uses CMSIS macro
defines directly.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-06-21 22:28:00 +02:00
Yasushi SHOJI 064608b429 include: remove unused macros from include/arch/*/arch.h
All architecture defines OCTET_TO_SIZEOFUNIT and SIZEOFUNIT_TO_OCTET
as identity functions. But the only user is tests/benchmarks/app_kernel.
It's effectively a no-op.  Remove them.

Signed-off-by: Yasushi SHOJI <y-shoji@ispace-inc.com>
2018-06-20 12:07:59 -04:00
Joakim Andersson 5204fd7061 arch: arm: Set Zero Latency IRQ to priority level zero:
Set Zero Latency IRQ to priority level zero and SVCs to priority level
one when Zero Latency IRQ is enabled.
This makes Zero Zatency truly zero latency when the kernel has been
configured with userspace enabled, or when IRQ offloading is used.

Exceptions can still delay Zero Latency IRQ, but this is considered
ok since exceptions indicate a serious error, and the system needs to
recover.

Fixes: #7869

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2018-06-20 18:05:02 +02:00
Karol Gugala 23a5b5d171 riscv32: riscv-privilege: integrate common code
This commit moves code from fe310 platform into RISC-V privilege common
folder. This way the code can be reused by other platforms in future.

signed-off-by: Karol Gugala <kgugala@antmicro.com>
2018-06-20 11:57:07 -04:00
Ioannis Glaropoulos 1547abb57d arch: arm: use CMSIS defines for MPU_RASR register bit setting
This commit removes the macro definitions for MPU_RASR register
bitmasks, defined in arm_mpu.h, and modifies the MPU driver to
directly use the equivalent macros defined in ARM CMSIS.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-06-19 15:18:58 -05:00
Ioannis Glaropoulos 8d52c17166 arch: arm: use CMSIS defines for MPU_RBAR register bit setting
This commit removes the macro definitions for MPU_RBAR register
bitmasks, defined in arm_mpu.h, and modifies the MPU driver to
directly use the equivalent macros defined in ARM CMSIS.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-06-19 15:18:58 -05:00
Ioannis Glaropoulos 0a41e23ac0 arch: arm: use CMSIS macro defines for MPU_CTRL register bit setting
This commit removes the macro definitions for MPU_CTRL register
bitmasks, defined in arm_mpu.h, and modifies the MPU driver to
directly use the equivalent macros defined in ARM CMSIS.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-06-19 15:18:58 -05:00
Savinay Dharmappa b7c4c0302c dts: riscv32: riscv32-qemu: Add device tree support
add device tree support for riscv32-qemu

Signed-off-by: Savinay Dharmappa <savinay.dharmappa@intel.com>
2018-06-13 08:47:52 -04:00
Wayne Ren b829bc78c1 arch: arc: refactor the arc stack check support
* the original stack check codes have no consideration
  for userspace case. This will wrong cause possible stack
  check exception.
* this commit refactors the arc stack check support to
  support the usperspace.

* this commit fixes #7885. All the failed tests in #7885
  are run again to verify this commit. The test results are ok

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2018-06-04 13:31:43 -04:00
Andrew Boie 7a18b083eb x86: align stack buffer sizes
Previously, the stack buffer array wasn't being page-aligned.
If private kernel data was stored after the stack buffer in
the same page, the current thread would incorrectly have
access to it. Round stack sizes up on x86 to prevent this
problem.

Fixes #8118

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-06-02 16:29:46 -04:00
Piotr Zięcik 997a49ade9 arm: userspace: Do not overwrite r7 during syscall.
The r7 register is used as a frame pointer on ARM Thumb. As result, it
cannot be modified by the assembly code in functions using stack frame.

This commit replaces r7 by r8, which is a general purpose register.
Also it fixes #7704.

Signed-off-by: Piotr Zięcik <piotr.ziecik@nordicsemi.no>
2018-06-01 13:07:47 -04:00
Joakim Andersson 45b75dd7ff arch: arm: Fix zero interrupt latency priority level
Change the zero latency interrupt priority level from 2 to 1.
This is the priority level that the kernel has reserved for the
zero latency IRQ feature by the _IRQ_PRIO_OFFSET constant.
The zero latency IRQ will now not be masked by the irq_lock function.

Update comments to reflect the priority levels reserved by the kernel.

Fixes: #8073

Signed-off-by: Joakim Andersson <joakim.andersson@nordicsemi.no>
2018-05-31 14:58:43 -04:00
Wayne Ren 76b1cefda9 arch: arc: fix the bug in STACK_ARRAY defintion.
Because the address alignment of MPUv2, the address should
not only be aligned at the start but also for the array member.

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2018-05-30 20:23:35 -04:00
Ioannis Glaropoulos 24fcba44d3 arch: arm: remove redundant ifdef check
This commit removes a redundant #ifdef check for
CONFIG_CPU_CORTEX_M_HAS_BASEPRI, which is covered
CONFIG_CPU_CORTEX_M_HAS_PROGRAMMABLE_FAULT_PRIOS, present
in the same ifdef check.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-05-25 09:42:42 -07:00
Ulf Magnusson 45221a9706 serial: nsim: Fix impossible-to-enable CONFIG_UART_NSIM
CONFIG_UART_NSIM depends on CONFIG_NSIM, which was removed in commit
9bc69a46fa ("boards: Update arc em_starterkit support from 2.2 to
2.3"). Remove the dependency, and also remove the CONFIG_NSIM=y setting
from the test_nsim test (which should now work).

Also change the condition for EXTERN()ing _VectorTable in
include/arch/arc/v2/linker.ld to check CONFIG_UART_NSIM instead of
CONFIG_NSIM. I'm guessing the EXTERN() is there to make the symbol
visible to nSIM, though I don't know anything about it.

Signed-off-by: Ulf Magnusson <Ulf.Magnusson@nordicsemi.no>
2018-05-24 13:09:28 -04:00
Kumar Gala e653e47824 arch: arm: Fix typo in comment
CONFIG_MPU_REQUIRES_POWER_OF_2_ALIGNMENT should have been
MPU_REQUIRES_POWER_OF_TWO_ALIGNMENT.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-05-23 17:57:06 -04:00
Kumar Gala c2742f66ac arch: arc: Fix typo in comment
Comment had CONFIG_USERPSACE and should be CONFIG_USERSPACE.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2018-05-23 17:57:06 -04:00
Andrew Boie 9731a0cce9 arm: syscalls: fix some register issues
Upon return from a syscall handlers, the r1, r2, and r3 registers
could contain random kernel data that should not be leaked to user
mode. Zero these out before returning from _arm_do_syscall().
Fixes #7753.

The invocation macros need a clobber if r1, r2, or r3 are not used
to carry syscall arguments. This is a partial fix for #7754 but
there appear to be other issues.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-05-22 15:59:07 -07:00
Savinay Dharmappa 8f908f38e0 dts: nios2f: Add device tree support
Add device tree support for nios2f soc

Signed-off-by: Savinay Dharmappa <savinay.dharmappa@intel.com>
2018-05-17 14:09:15 -07:00
Johann Fischer 167efd70b6 arm: mpu: nxp: set bus master 4 to write and read access
Set bus master 4 to write and read access which allows
the USBFSOTG controller read/write access to the memory.

Signed-off-by: Johann Fischer <j.fischer@phytec.de>
2018-05-17 07:00:49 -05:00
Ioannis Glaropoulos 7c91a4a53b arch: arm: fix SecureFault IRQn for non-CMSIS compliant MCUs
This commit fixes the SecureFault IRQ number for non-CMSIS
compliant ARM Cortex-M MCUs. Erroneous IRQ number was introduced
in ec398e87796f8da2529f369746ae9b2b12d48ca4.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-05-15 08:57:16 -05: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
Alberto Escolar Piedras e3efbd54c6 POSIX arch: Fix linker -T warning
Modify the linker script with the command INSERT.
It instructs the linker to augment the default linker script
SECTIONS with the ones provided with the one provided in
this script.
It also modified the meaning of the -T switch, so it no longer
replaces the default linker script

Signed-off-by: Alberto Escolar Piedras <alpi@oticon.com>
2018-05-02 10:19:09 -04:00
Savinay Dharmappa 97f721d928 dts: xtensa: Add device tree support for xtensa
Change-Id: I309bc50c6b575caa84fbc7ab98cc9890771b4274
Signed-off-by: Savinay Dharmappa <savinay.dharmappa@intel.com>
2018-05-01 16:46:41 -04:00
Rajavardhan Gundi dadf9e7a81 xtensa: intel_s1000: implement interrupt mechanism
intel_s1000 has multiple levels of interrupts consisting of core, CAVS
Logic and designware interrupt controller. This patchset modifies
the regular gen_isr mechanism to support these multiple levels.

Change-Id: I0450666d4e601dfbc8cadc9c9d8100afb61a214c
Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-05-01 16:46:41 -04:00
Rajavardhan Gundi 47ff96593f intel_s1000: uart: configure UART for intel_s1000
intel_s1000 uses DesignWare IP for UART. National Semiconductor
16550 (UART) component specification is followed in this IP.

Change-Id: Ied7df1dc178d55b6dbe71d729d6383ba07274ea4
Signed-off-by: Rajavardhan Gundi <rajavardhan.gundi@intel.com>
Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-05-01 16:46:41 -04:00
Adithya Baglody 960e97834f x86: linker: Maintain 4K alignment for application memory.
When MMU is enabled and the SOC we are running doesn't have
execute in-place(XIP) the final image will be a monolith which
sits in RAM. In such situations we need to maintain the alignment
for application memory. If not maintained the MMU boot tables
will not be configured properly.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2018-04-25 14:46:00 -07:00
Leandro Pereira ae7911cce0 arch: x86: segmentation: Remove unused _far_call() and _far_jump()
These functions were not used throughout the Zephyr code base, and
as such has been removed.  They can be reinstated if there's a need,
but will need to be adapted to use retpolines when CONFIG_RETPOLINE
is set.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2018-04-24 04:00:01 +05:30
Leandro Pereira 16472cafcf arch: x86: Use retpolines in core assembly routines
In order to mitigate Spectre variant 2 (branch target injection), use
retpolines for indirect jumps and calls.

The newly-added hidden CONFIG_X86_NO_SPECTRE flag, which is disabled
by default, must be set by a x86 SoC if its CPU performs speculative
execution.  Most targets supported by Zephyr do not, so this is
set to "y" by default.

A new setting, CONFIG_RETPOLINE, has been added to the "Security
Options" sections, and that will be enabled by default if
CONFIG_X86_NO_SPECTRE is disabled.

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2018-04-24 04:00:01 +05:30
Wayne Ren 3d9ba10b5c arch: arc: bug fixes and optimization in exception handling
The original exception handling has space to optimize and
and some bugs need to be fixed.

* define NANO_ESF
   * add the definition of NANO_ESF which is an irq_stack_frame
   * add the corresponding codes in exception entry and handler
   * remove _default_esf
* implement the _ARCH_EXCEPT
   * use trap exception to raise exception by kernel
   * add corresponding trap exception entry
   * add _do_kernel_oops to handle the exception raised by
     _ARCH_EXCEPT.
* add the thread context switch in exception return
   * case: kernel oops may raise thread context switch
   * case: some tests will re-implement SysFatalHandler to raise
     thread context switch.
   * as the exception and isr are handled in kernel isr stack, so
     the thread context switch must be in the return of exception/isr
     , and the exception handler must return, should not be decorated
     with FUNC_NORETURN
* for arc, _is_in_isr should consider the case of exception

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2018-04-17 10:50:12 -07:00
Andy Gross 09a8810b33 arm: userspace: Rework system call arguments
This patch changes the ARM system calls to use registers for passing
or arguments.  This removes the possibility of stack issues when
callers do not adhere to the AAPCS.

Fixes #6802

Signed-off-by: Andy Gross <andy.gross@linaro.org>
2018-04-16 10:13:20 -07:00
Andrew Boie 0a1ea32437 mpu: arm: restrict access to PPB/IO regions
User mode shouldn't be able to read/write to this memory directly,
needs to be done on its behalf by driver system calls.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2018-04-02 19:54:08 -07:00
Anas Nashif 993c350b92 cleanup: replace old jira numbers with GH issues
Replace all references to old JIRA issues (ZEP) with the corrosponding
Github issue ID.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-03-26 13:13:04 -04:00
Ioannis Glaropoulos 65607ee104 arch: arm: SecureFault_IRQn for non-CMSIS-compliant MCUs
Define IRQ number for SecureFault Handler when building Secure
Firmware for non-CMSIS-compliant ARM Cortex-M MCUs.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-03-20 21:34:01 +08:00
Ioannis Glaropoulos bd0ff3092a arch: arm: cmsis: cleanup cmsis.h and update error-code macros
This commit removes the macros for ARM fault flags from
include/arch/arm/cortex_m/cmsis.h header, since they are
defined in the respective core_cmXX.h header files. It also
modifies fault.c to use the updated fault macros taken directly
from ARM CMSIS headers.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-03-10 11:42:25 -06:00
Ioannis Glaropoulos b518d35c4c arch: arm: fix bug in escalted HF dump
This commit fixes a bug in the ARM HardFAult handler, which
prevented from dumping the right UsageFault flags, after a
UsageFault had escalated to HardFault.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-03-08 08:33:08 -06:00
Andy Ross 3f5027f835 xtensa: Fix noreturn attribute on error handlers in asm2
In asm2, the machine exception handler runs in interrupt context (this
is good: it allows us to defer the test against exception type until
after we have done the stack switch and dispatched any true
interrupts), but that means that the user error handler needs to be
invoked and then return through the interrupt exit code.

So the __attribute__(__noreturn__) that it was being decorated with
was incorrect.  And actually fatal, as with gcc xtensa will crash
trying to return from a noreturn call.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-02-16 10:44:29 -05:00
Andy Ross bd72f71ece xtensa: Remove arch-specific (and empty) offsets.h
The xtensa arch code had this empty offsets.h header sitting around.
Its name collides with the autogenerated offsets.h, making it
dangerously dependent on include file path order.  Seems to be benign,
but it's freaking me out.  Remove.

Signed-off-by: Andy Ross <andrew.j.ross@intel.com>
2018-02-16 10:44:29 -05:00
Wayne Ren bb50a88045 arch: arc: apply the new thread stack layout
The new thread stack layout is as follow:

|---------------------|
|  user stack         |
|---------------------|
| stack guard (opt.)  |
|---------------------|
|  privilege stack    |
-----------------------

For MPUv2
  * user stack is aligned to the power of 2 of user stack size
  * the stack guard is 2048 bytes
  * the default size of privileg stack is 256 bytes.
  For user thread, the following MPU regions are needded
    * one region for user stack, no need of stack guard for user stack
    * one region for stack guard when stack guard is enbaled
    * regions for memory domain.
  For kernel thread, the stack guard region will be at the top, adn
  The user stack and privilege stack will be merged.

MPUv3 is the same as V2's layout, except no need of power of 2
alignment.

* reimplement the user mode enter function. Now it's possible for
kernel thread to drop privileg to user thread.

* add a separate entry for user thread

* bug fixes in the cleanup of regs when go to user mode

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2018-02-16 12:20:16 +01:00
Wayne Ren 8d284116b0 arch: arc: modify the linker template for APPLICAITON Memory
The application memory area has a requirement of address alignment,
especially when MPU requires power of 2.

Modify the linker tmemplate to apply application memory address
alignment generation

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2018-02-16 12:20:16 +01:00
Wayne Ren 7ef2506611 arch: arc: enable US bit to check user mode
Enable us bit to check user mode more efficienly.

US is read as zero in user mode. This will allow use mode sleep
instructions, and it enables a form of denial-of-service attack
by putting the processor in sleep mode, but since interrupt
level/mask can't be set from user space that's not worse than
executing a loop without yielding.

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2018-02-16 12:20:16 +01:00
Wayne Ren e91733c78b arch: arc: bug fixes and add user space support in secure mode
* bug fixes
* add user space support in secure mode

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2018-02-16 12:20:16 +01:00
Wayne Ren f81dee0b2b arch: arc: add user space support for arc
* add the implementation of syscall
  * based on 'trap_s' intruction, id = 3
* add the privilege stack
  * the privilege stack is allocted with thread stack
  * for the kernel thread, the privilege stack is also a
    part of thread stack, the start of stack can be configured
    as stack guard
  * for the user thread, no stack guard, when the user stack is
    overflow, it will fall into kernel memory area which requires
    kernel privilege, privilege violation will be raised
* modify the linker template and add MPU_ADDR_ALIGN
* add user space corresponding codes in mpu
* the user sp aux reg will be part of thread context
* When user thread is interruptted for the 1st time, the context is
  saved in user stack (U bit of IRQ_CTLR is set to 1). When nest
  interrupt comes, the context is saved in thread's privilege stack
* the arc_mpu_regions.c is moved to board folder, as it's board
  specific
* the above codes have been tested through tests/kernel/mem_protect/
  userspace for MPU version 2

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2018-02-16 12:20:16 +01:00
Andy Gross 08de82c2f5 arm: mpu: nxp: Set bus master 3 to full access
This patch adjusts the default permissions on the bus master 3 (NET).
Recent changes restricted this to supervisor only, and this caused
issues with the network controllers access to memory.

Restrictions on access should really be enforced on the ARM core bus
master.

Signed-off-by: Andy Gross <andy.gross@linaro.org>
2018-02-15 12:53:16 -05:00
Andy Gross f7ec62eb85 arm: mpu: Enable userspace support for NXP and ARM
This patch set implements the APIs and changed required to support
the user mode thread support.

Signed-off-by: Andy Gross <andy.gross@linaro.org>
2018-02-13 12:42:37 -08:00
Andy Gross 1c047c9bef arm: userspace: Add ARM userspace infrastructure
This patch adds support for userspace on ARM architectures.  Arch
specific calls for transitioning threads to user mode, system calls,
and associated handlers.

Signed-off-by: Andy Gross <andy.gross@linaro.org>
2018-02-13 12:42:37 -08:00
Andy Gross 9ccdcb9be6 arm: mpu: Add user context API placeholder
This patch adds a configure_mpu_user_context API and implements
the required function placeholders in the NXP and ARM MPU files.

Signed-off-by: Andy Gross <andy.gross@linaro.org>
2018-02-13 12:42:37 -08:00
Erwin Rol 581446d8cd linker: arm: add stm32 ccm sections
The STM32 has special Core Coupled Memory, ccm for short, that can
only be accessed through the CPU and can not be use for DMA.

The following 3 sections have been added.
- ccm_bss for zero initialized data
- ccm_data for initialized data
- ccm_noinit for uninitialized data

Signed-off-by: Erwin Rol <erwin@erwinrol.com>
2018-02-13 12:36:22 -06:00
Anas Nashif 11a9625eaf debug: remove DEBUG_INFO option
This feature is X86 only and is not used or being tested. It is legacy
feature and no one can prove it actually works. Remove it until we have
proper documentation and samples and multi architecture support.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2018-02-12 13:58:28 -08:00
Ioannis Glaropoulos 0d6fa4db0a arch: arm: define Cortex-M23, Cortex-M33 CPUs
This commit defines the Kconfig options for
ARM Cortex-M23 and Cortex-M33 CPUs. It also
udpates the generic memory map for M23 and M33
implementations.

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-02-08 12:07:38 -06:00
Ioannis Glaropoulos a0a03d7597 arch: arm: common Armv8-M support
This PR includes the required changes in order to support
conditional compilation for Armv8-M architecture. Two
variants of the Armv8-M architecture are defined:
- the Armv8-M Baseline (backwards compatible with ARMv6-M),
- the Armv8-M Mainline (backwards compatible with ARMv7-M).

Signed-off-by: Ioannis Glaropoulos <Ioannis.Glaropoulos@nordicsemi.no>
2018-02-08 12:07:38 -06:00
Chunlin Han 18560a01a4 arm: Generate privileged stacks
This patch adds the generation and incorporation of privileged stack
regions that are used by ARM user mode threads.  This patch adds the
infrastructure for privileged stacks.  Later patches will utilize the
generated stacks and helper functions.

Signed-off-by: Chunlin Han <chunlin.han@linaro.org>
Signed-off-by: Andy Gross <andy.gross@linaro.org>
2018-02-06 15:31:16 -08:00
Andy Gross e8860fe8be arm: Add app data section alignment constraints
This patch adds application data section alignment constraints
to match the region definition requirements for ARM MPUs.  Most MPUs
require a minimum of 32 bytes of alignment for any regions, but some
require power of two alignment to the size of a region.

This requires that the linker align the application data section to
the size of the section.  This requires a linker pass to determine the
size.  Once this is accomplished the correct value is added to a linker
include file that is utilized in subsequent linker operations.

Signed-off-by: Andy Gross <andy.gross@linaro.org>
2018-02-06 15:31:16 -08:00
Ding Tao bbd307edfd arch: arm: vector_table: Support vector table soft relay
For SoCs that don't support vector table relocation in hardware, may not
support bootloader like mcuboot.

We introduce a way to relocate vector table in software by forwarding
the control of incoming IRQs to a new vector table which address is save
at fixed SRAM address.

User can change the data in that fixed SRAM address in order to relocate
vector table in software way.

Signed-off-by: Ding Tao <miyatsu@qq.com>
2018-01-26 06:57:28 +05:30
Wayne Ren 9a40bf6b7e arch: arc: Add the intial support of memory domain
Refering the ARM's implementation, the initial support of memory
domain in ARC is added:
* changes in MPU drivers
* changes in Kconfig
* codes to configure memory domain during thread swap
* changes in linker script template
* memory domain related macro definitions

the commited codes are simply tested through
samples/mpu/mem_domain_apis_test.

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2018-01-18 11:50:59 -08:00
Neil Armstrong a9b47fc32c arm: cortex_m: linker.ld: fix relocate by moving _vector_start
The _vector_start was placed before the CONFIG_TEXT_SECTION_OFFSET, thus
adding the offset in the relocated vector table, making the table
invalid when relocated with a non null CONFIG_TEXT_SECTION_OFFSET.

This was tested using MCUboot with a 0x200 offset for the image header.

Fixes: eb48a0a73c ("arm: armv6-m: Support relocating vector table")
Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
2018-01-17 08:00:45 -05:00
Alberto Escolar Piedras 76f7644118 arch: native: Run Zephyr natively in a POSIX OS
A new arch (posix) which relies on pthreads to emulate the context
switching
A new soc for it (inf_clock) which emulates a CPU running at an
infinely high clock (so when the CPU is awaken it runs till completion
in 0 time)
A new board, which provides a trivial system tick timer and
irq generation.

Origin: Original

Fixes #1891

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
Adithya Baglody 13ac4d4264 kernel: mem_domain: Add an arch interface to configure memory domain
Add an architecure specfic code for the memory domain
configuration. This is needed to support a memory domain API
k_mem_domain_add_thread.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2017-12-21 11:52:27 -08:00
Wayne Ren 5f349a4d4d arch: arc: fix the comments and coding style
Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2017-12-13 12:05:33 -05:00
Wayne Ren cdfb59a276 arch: arc: add the support of MPU version 3
MPU version 3 is included in em7d of em_starterkit 2.3.

The differences of MPU version 3 and version 2 are:

* different aux reg interface
* The address alignment requirement is 32 bytes
* supports secure mode
* supports SID (option)
* does not support memory region overlap

This commit adds the support MPU version 3 and also make some changes to
MPU version 2 to have an unified interface.

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2017-12-13 12:05:33 -05:00
Wayne Ren 528c960ae7 arch: arc: Add the support of secure mode for em
In ARC's SecureShield, a new secure mode (currently only em) is added.
The secure/normal mode is orthogonal to kernel/user mode. The
differences between secure mode and normal mode are following:

* different irq stack frame. so need to change the definition of
  _irq_stack_frame, assembly code.

* new aux regs, e.g, secure status(SEC_STAT), secure vector base
  (VECT_BASE_S)

* interrupts and exceptions, secure mode has its own vector base;
  interrupt can be configured as secure or normal through the
  interrupt priority aux reg.

* secure timers. Two secure timers (secure timer 0 and timer 1) are
  added.Here, for simplicity and backwards compatibility original
  internal timers (timer 0 and timer1) are used as sys clock of zephyr

* on reset, the processor is in secure mode and secure vector base is
  used.

Note: the mix of secure and normal mode is not supported, i.e. it's
assumed that the processor is always in secure mode.

Signed-off-by: Wayne Ren <wei.ren@synopsys.com>
2017-12-13 12:05:33 -05:00
David B. Kinder 01e59551ab doc: fix doxygen commment in x86/arch.h
API documentation missing @param command

Signed-off-by: David B. Kinder <david.b.kinder@intel.com>
2017-12-04 15:27:46 -05:00
Stephen Smalley 106b1c2050 arm: define _image_rodata_start/end
Define _image_rodata_start/end to match x86 and so that we can
refer to them in the userspace test among others.

Signed-off-by: Stephen Smalley <sds@tycho.nsa.gov>
2017-11-28 12:29:13 -05:00
Chunlin Han d051740ee0 arm: implement API to validate user buffer
Implement API to validate user buffer. This API will iterate
all MPU regions to check if the given buffer is user accessible
or not. For #3832.

Signed-off-by: Chunlin Han <chunlin.han@linaro.org>
2017-11-17 19:01:11 -05:00
Savinay Dharmappa 7c8a23d643 dts: arc: Add dts support for arc
Signed-off-by: Savinay Dharmappa <savinay.dharmappa@intel.com>
2017-11-15 07:21:10 -06:00
Adithya Baglody f7b0731ce4 x86: MMU: Memory domain implementation for x86
Added support for memory domain implementation.

GH-3852

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2017-11-07 12:22:43 -08:00
Adithya Baglody 83bedcc912 ARM: MPU: Arch specific memory domain APIs
Added architecture specific support for memory domain destroy
and remove partition for arm and nxp. An optimized version of
remove partition was also added.

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2017-11-07 12:22:43 -08:00
Andrew Boie 2a8684f60c x86: de-couple user mode and HW stack protection
This is intended for memory-constrained systems and will save
4K per thread, since we will no longer reserve room for or
activate a kernel stack guard page.

If CONFIG_USERSPACE is enabled, stack overflows will still be
caught in some situations:

1) User mode threads overflowing stack, since it crashes into the
kernel stack page
2) Supervisor mode threads overflowing stack, since the kernel
stack page is marked non-present for non-user threads

Stack overflows will not be caught:

1) When handling a system call
2) When the interrupt stack overflows

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-11-07 09:31:49 -08:00
Andrew Boie a705eae315 gen_gdt: add debug statements and simplify logic
This is in preparation for making CONFIG_USERSPACE not
depend on CONFIG_HW_STACK_PROTECTION.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-11-07 09:31:49 -08:00
Gustavo Lima Chaves 97a8716a4f x86: Jailhouse port, tested for UART (# 0, polling) and LOAPIC timer
This is an introductory port for Zephyr to be run as a Jailhouse
hypervisor[1]'s "inmate cell", on x86 64-bit CPUs (running on 32-bit
mode). This was tested with their "tiny-demo" inmate demo cell
configuration, which takes one of the CPUs of the QEMU-VM root cell
config, along with some RAM and serial controller access (it will even
do nice things like reserving some L3 cache for it via Intel CAT) and
Zephyr samples:

   - hello_world
   - philosophers
   - synchronization

The final binary receives an additional boot sequence preamble that
conforms to Jailhouse's expectations (starts at 0x0 in real mode). It
will put the processor in 32-bit protected mode and then proceed to
Zephyr's __start function.

Testing it is just a matter of:
  $ mmake -C samples/<sample_dir> BOARD=x86_jailhouse JAILHOUSE_QEMU_IMG_FILE=<path_to_image.qcow2> run
  $ sudo insmod <path to jailhouse.ko>
  $ sudo jailhouse enable <path to configs/qemu-x86.cell>
  $ sudo jailhouse cell create <path to configs/tiny-demo.cell>
  $ sudo mount -t 9p -o trans/virtio host /mnt
  $ sudo jailhouse cell load tiny-demo /mnt/zephyr.bin
  $ sudo jailhouse cell start tiny-demo
  $ sudo jailhouse cell destroy tiny-demo
  $ sudo jailhouse disable
  $ sudo rmmod jailhouse

For the hello_world demo case, one should then get QEMU's serial port
output similar to:

"""
Created cell "tiny-demo"
Page pool usage after cell creation: mem 275/1480, remap 65607/131072
Cell "tiny-demo" can be loaded
CPU 3 received SIPI, vector 100
Started cell "tiny-demo"
***** BOOTING ZEPHYR OS v1.9.0 - BUILD: Sep 12 2017 20:03:22 *****
Hello World! x86
"""

Note that the Jailhouse's root cell *has to be started in xAPIC
mode* (kernel command line argument 'nox2apic') in order for this to
work. x2APIC support and its reasoning will come on a separate commit.

As a reminder, the make run target introduced for x86_jailhouse board
involves a root cell image with Jailhouse in it, to be launched and then
partitioned (with >= 2 64-bit CPUs in it).

Inmate cell configs with no JAILHOUSE_CELL_PASSIVE_COMMREG flag
set (e.g. apic-demo one) would need extra code in Zephyr to deal with
cell shutdown command responses from the hypervisor.

You may want to fine tune CONFIG_SYS_CLOCK_HW_CYCLES_PER_SEC for your
specific CPU—there is no detection from Zephyr with regard to that.

Other config differences from pristine QEMU defaults worth of mention
are:

   - there is no HPET when running as Jailhouse guest. We use the LOAPIC
     timer, instead
   - there is no PIC_DISABLE, because there is no 8259A PIC when running
     as a Jailhouse guest
   - XIP makes no sense also when running as Jailhouse guest, and both
     PHYS_RAM_ADDR/PHYS_LOAD_ADD are set to zero, what tiny-demo cell
     config is set to

This opens up new possibilities for Zephyr, so that usages beyond just
MCUs come to the table. I see special demand coming from
functional-safety related use cases on industry, automotive, etc.

[1] https://github.com/siemens/jailhouse

Reference to Jailhouse's booting preamble code:

Origin: Jailhouse
License: BSD 2-Clause
URL: https://github.com/siemens/jailhouse
commit: 607251b44397666a3cbbf859d784dccf20aba016
Purpose: Dual-licensing of inmate lib code
Maintained-by: Zephyr

Signed-off-by: Gustavo Lima Chaves <gustavo.lima.chaves@intel.com>
2017-11-07 08:58:49 -05:00
Jan Kiszka 283a0cdafb x86: MMU: Rename gen_mmu script
It's x86-only.

Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
2017-11-03 09:29:39 -07:00
Leandro Pereira b007b64d30 kernel: Add option to ensure writable pages are not executable
This adds CONFIG_EXECUTE_XOR_WRITE, which is enabled by default on
systems that support controlling whether a page can contain executable
code.  This is also known as W^X[1].

Trying to add a memory domain with a page that is both executable and
writable, either for supervisor mode threads, or for user mode threads,
will result in a kernel panic.

There are few cases where a writable page should also be executable
(JIT compilers, which are most likely out of scope for Zephyr), so an
option is provided to disable the check.

Since the memory domain APIs are executed in supervisor mode, a
determined person could bypass these checks with ease.  This is seen
more as a way to avoid people shooting themselves in the foot.

[1] https://en.wikipedia.org/wiki/W%5EX

Signed-off-by: Leandro Pereira <leandro.pereira@intel.com>
2017-11-02 13:40:50 -07:00
Andrew Boie 9d24be8daf nios2: asm_inline_gcc: fix includes
This header needs toolchain.h but wasn't including it directly.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-11-02 13:25:01 -07:00
Andrew Boie 4b0e4f769b x86: apic: don't include headers we don't need
We were unnecessarily pulling in headers which resulted in kernel.h
being pulled in, which is undesirable since arch/cpu.h pulls in
these headers.

Added integral type headers since we do need those.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-11-02 13:25:01 -07:00
Andrew Boie e4eeb09c5d x86: arch.h: remove reverse dependency
kernel.h depends on arch.h, and reverse dependencies need to be
removed. Define k_tid_t as some opaque pointer type so that arch.h
doesn't have to pull in kernel.h.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-11-01 13:13:25 -07:00
Andrew Boie 7d1b1212aa arm_core_mpu_dev.h: include proper headers
This header needs Zephyr's specific type definitions. It also
needs struct k_mem_partition and struct k_mem_domain, but they
are defined opaquely here instead of pulling in kernel.h (which
would create nasty dependency loops)

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-11-01 11:24:00 -07:00
Anas Nashif 780324b8ed cleanup: rename fiber/task -> thread
We still have many places talking about tasks and threads, replace those
with thread terminology.

Signed-off-by: Anas Nashif <anas.nashif@intel.com>
2017-10-30 18:41:15 -04:00
Adithya Baglody 725de70d86 x86: MMU: Create PAE page structures and unions.
Created structures and unions needed to enable the software to
access these tables.
Also updated the helper macros to ease the usage of the MMU page
tables.

JIRA: ZEP-2511

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2017-10-23 10:13:07 -07:00
Bobby Noelte 2f7688bfd3 arch: arm: core: fix vector table relocate write to flash
Some SOCs (e.g. STM32F0) can map the flash to address 0 and
the flash base address at the same time. Prevent writing to
duplicate flash address which stops the SOC.

Allow Cortex M SOCs to create their own vector table relocation
function.

Provide a relocation function for STM32F0x SOCs.

Fixes #3923

Signed-off-by: Bobby Noelte <b0661n0e17e@gmail.com>
Signed-off-by: Neil Armstrong <narmstrong@baylibre.com>
2017-10-23 12:31:47 +02:00
Andrew Boie d7631ec7e4 Revert "x86: MMU: Memory domain implementation for x86"
This reverts commit d0f6ce2d98.
2017-10-20 15:02:59 -04:00
Adithya Baglody d0f6ce2d98 x86: MMU: Memory domain implementation for x86
Added support for memory domain implementation.

GH-3852

Signed-off-by: Adithya Baglody <adithya.nagaraj.baglody@intel.com>
2017-10-20 10:39:51 -07:00
Andrew Boie d95f5374b4 x86: fix _arch_syscall_invoke6
arg6 is treated as a memory constraint. If that memory
address was expressed as an operand to 'mov' in the generated
code as an offset from the stack pointer, then the 'push'
instruction immediately before it could end up causing memory 4
bytes off from what was intended being passed in as the 6th
argument.

Add ESP register to the clobber list to fix this issue.

Fixes issues observed with k_thread_create() passing in a
NULL argument list with CONFIG_DEBUG=y.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-10-18 10:24:25 -07:00
Andrew Boie bca15da650 userspace: treat thread stacks as kernel objects
We need to track permission on stack memory regions like we do
with other kernel objects. We want stacks to live in a memory
area that is outside the scope of memory domain permission
management. We need to be able track what stacks are in use,
and what stacks may be used by user threads trying to call
k_thread_create().

Some special handling is needed because thread stacks appear as
variously-sized arrays of struct _k_thread_stack_element which is
just a char. We need the entire array to be considered an object,
but also properly handle arrays of stacks.

Validation of stacks also requires that the bounds of the stack
are not exceeded. Various approaches were considered. Storing
the size in some header region of the stack itself would not allow
the stack to live in 'noinit'. Having a stack object be a data
structure that points to the stack buffer would confound our
current APIs for declaring stacks as arrays or struct members.
In the end, the struct _k_object was extended to store this size.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-10-16 19:02:00 -07:00
Andrew Boie 8487cd1fe7 x86: fix syscall optimization issue
These needed "memory" clobbers otherwise the compiler would do
unnecessary optimizations for parameters passed in as pointer
values.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-10-09 10:25:36 -07:00
Chunlin Han 607c9aa3cd arch: arm: add new memory partition attributes
Add execution-allowed memory partition attributes for arch arm.

Signed-off-by: Chunlin Han <chunlin.han@linaro.org>
2017-10-03 19:30:28 -04:00
Chunlin Han e9c9702818 kernel: add memory domain APIs
Add the following application-facing memory domain APIs:

k_mem_domain_init() - to initialize a memory domain
k_mem_domain_destroy() - to destroy a memory domain
k_mem_domain_add_partition() - to add a partition into a domain
k_mem_domain_remove_partition() - to remove a partition from a domain
k_mem_domain_add_thread() - to add a thread into a domain
k_mem_domain_remove_thread() - to remove a thread from a domain

A memory domain would contain some number of memory partitions.
A memory partition is a memory region (might be RAM, peripheral
registers, flash...) with specific attributes (access permission,
e.g. privileged read/write, unprivileged read-only, execute never...).
Memory partitions would be defined by set of MPU regions or MMU tables
underneath.
A thread could only belong to a single memory domain any point in time
but a memory domain could contain multiple threads.
Threads in the same memory domain would have the same access permission
to the memory partitions belong to the memory domain.

The memory domain APIs are used by unprivileged threads to share data
to the threads in the same memory and protect sensitive data from
threads outside their domain. It is not only for improving the security
but also useful for debugging (unexpected access would cause exception).

Jira: ZEP-2281

Signed-off-by: Chunlin Han <chunlin.han@linaro.org>
2017-09-29 16:48:53 -07:00
Andrew Boie d279979613 x86: fix _arch_syscall_invoke6()
The compiler was complaining about impossible constraints since register
constraint was provided, but there are no general purpose registers left
available.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-09-29 14:51:27 -07:00
Chunlin Han 95d28e53bb arch: arm: add initial support for CONFIG_USERSPACE
add related configs & (stub) functions for enabling
CONFIG_USERSPACE on arm w/o build errors.

Signed-off-by: Chunlin Han <chunlin.han@linaro.org>
2017-09-26 10:00:53 -07:00
Andrew Boie eeba84b5b5 arm: fix __kernel
This wasn't working properly with CONFIG_APPLICATION_MEMORY enabled as
the sections weren't handled in the linker script.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-09-25 19:22:02 -07:00
Andrew Boie 1956f09590 kernel: allow up to 6 arguments for system calls
A quick look at "man syscall" shows that in Linux, all architectures
support at least 6 argument system calls, with a few supporting 7. We
can at least do 6 in Zephyr.

x86 port modified to use EBP register to carry the 6th system call
argument.

Signed-off-by: Andrew Boie <andrew.p.boie@intel.com>
2017-09-20 09:18:59 -07:00