zephyr/arch/nios2/core/crt0.S
Stephanos Ioannidis 2d7460482d headers: Refactor kernel and arch headers.
This commit refactors kernel and arch headers to establish a boundary
between private and public interface headers.

The refactoring strategy used in this commit is detailed in the issue

This commit introduces the following major changes:

1. Establish a clear boundary between private and public headers by
  removing "kernel/include" and "arch/*/include" from the global
  include paths. Ideally, only kernel/ and arch/*/ source files should
  reference the headers in these directories. If these headers must be
  used by a component, these include paths shall be manually added to
  the CMakeLists.txt file of the component. This is intended to
  discourage applications from including private kernel and arch
  headers either knowingly and unknowingly.

  - kernel/include/ (PRIVATE)
    This directory contains the private headers that provide private
   kernel definitions which should not be visible outside the kernel
   and arch source code. All public kernel definitions must be added
   to an appropriate header located under include/.

  - arch/*/include/ (PRIVATE)
    This directory contains the private headers that provide private
   architecture-specific definitions which should not be visible
   outside the arch and kernel source code. All public architecture-
   specific definitions must be added to an appropriate header located
   under include/arch/*/.

  - include/ AND include/sys/ (PUBLIC)
    This directory contains the public headers that provide public
   kernel definitions which can be referenced by both kernel and
   application code.

  - include/arch/*/ (PUBLIC)
    This directory contains the public headers that provide public
   architecture-specific definitions which can be referenced by both
   kernel and application code.

2. Split arch_interface.h into "kernel-to-arch interface" and "public
  arch interface" divisions.

  - kernel/include/kernel_arch_interface.h
    * provides private "kernel-to-arch interface" definition.
    * includes arch/*/include/kernel_arch_func.h to ensure that the
     interface function implementations are always available.
    * includes sys/arch_interface.h so that public arch interface
     definitions are automatically included when including this file.

  - arch/*/include/kernel_arch_func.h
    * provides architecture-specific "kernel-to-arch interface"
     implementation.
    * only the functions that will be used in kernel and arch source
     files are defined here.

  - include/sys/arch_interface.h
    * provides "public arch interface" definition.
    * includes include/arch/arch_inlines.h to ensure that the
     architecture-specific public inline interface function
     implementations are always available.

  - include/arch/arch_inlines.h
    * includes architecture-specific arch_inlines.h in
     include/arch/*/arch_inline.h.

  - include/arch/*/arch_inline.h
    * provides architecture-specific "public arch interface" inline
     function implementation.
    * supersedes include/sys/arch_inline.h.

3. Refactor kernel and the existing architecture implementations.

  - Remove circular dependency of kernel and arch headers. The
   following general rules should be observed:

    * Never include any private headers from public headers
    * Never include kernel_internal.h in kernel_arch_data.h
    * Always include kernel_arch_data.h from kernel_arch_func.h
    * Never include kernel.h from kernel_struct.h either directly or
     indirectly. Only add the kernel structures that must be referenced
     from public arch headers in this file.

  - Relocate syscall_handler.h to include/ so it can be used in the
   public code. This is necessary because many user-mode public codes
   reference the functions defined in this header.

  - Relocate kernel_arch_thread.h to include/arch/*/thread.h. This is
   necessary to provide architecture-specific thread definition for
   'struct k_thread' in kernel.h.

  - Remove any private header dependencies from public headers using
   the following methods:

    * If dependency is not required, simply omit
    * If dependency is required,
      - Relocate a portion of the required dependencies from the
       private header to an appropriate public header OR
      - Relocate the required private header to make it public.

This commit supersedes #20047, addresses #19666, and fixes #3056.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
2019-11-06 16:07:32 -08:00

146 lines
4.1 KiB
ArmAsm

/*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <toolchain.h>
#include <linker/sections.h>
/* exports */
GTEXT(__start)
GTEXT(__reset)
/* imports */
GTEXT(_PrepC)
GTEXT(_interrupt_stack)
/* Allow use of r1/at (the assembler temporary register) in this
* code, normally reserved for internal assembler use
*/
.set noat
#if CONFIG_INCLUDE_RESET_VECTOR
/*
* Reset vector entry point into the system. Placed into special 'reset'
* section so that the linker puts this at ALT_CPU_RESET_ADDR defined in
* system.h
*
* This code can be at most 0x20 bytes, since the exception vector for Nios II
* is usually configured to be 0x20 past the reset vector.
*/
SECTION_FUNC(reset, __reset)
#if ALT_CPU_ICACHE_SIZE > 0
/* Aside from the instruction cache line associated with the reset
* vector, the contents of the cache memories are indeterminate after
* reset. To ensure cache coherency after reset, the reset handler
* located at the reset vector must immediately initialize the
* instruction cache. Next, either the reset handler or a subsequent
* routine should proceed to initialize the data cache.
*
* The cache memory sizes are *always* a power of 2.
*/
#if ALT_CPU_ICACHE_SIZE > 0x8000
movhi r2, %hi(ALT_CPU_ICACHE_SIZE)
#else
movui r2, ALT_CPU_ICACHE_SIZE
#endif
0:
/* If ECC present, need to execute initd for each word address
* to ensure ECC parity bits in data RAM get initialized
*/
#ifdef ALT_CPU_ECC_PRESENT
subi r2, r2, 4
#else
subi r2, r2, ALT_CPU_ICACHE_LINE_SIZE
#endif
initi r2
bgt r2, zero, 0b
#endif /* ALT_CPU_ICACHE_SIZE > 0 */
/* Done all we need to do here, jump to __text_start */
movhi r1, %hi(__start)
ori r1, r1, %lo(__start)
jmp r1
#endif /* CONFIG_INCLUDE_RESET_VECTOR */
/* Remainder of asm-land initialization code before we can jump into
* the C domain
*/
SECTION_FUNC(TEXT, __start)
/* TODO if shadow register sets enabled, ensure we are in set 0
* GH-1821
*/
/* Initialize the data cache if booting from bare metal. If
* we're not booting from our reset vector, either by a bootloader
* or JTAG, assume caches already initialized.
*/
#if ALT_CPU_DCACHE_SIZE > 0 && defined(CONFIG_INCLUDE_RESET_VECTOR)
/* Per documentation data cache size is always a power of two. */
#if ALT_CPU_DCACHE_SIZE > 0x8000
movhi r2, %hi(ALT_CPU_DCACHE_SIZE)
#else
movui r2, ALT_CPU_DCACHE_SIZE
#endif
0:
/* If ECC present, need to execute initd for each word address
* to ensure ECC parity bits in data RAM get initialized
*/
#ifdef ALT_CPU_ECC_PRESENT
subi r2, r2, 4
#else
subi r2, r2, ALT_CPU_DCACHE_LINE_SIZE
#endif
initd 0(r2)
bgt r2, zero, 0b
#endif /* ALT_CPU_DCACHE_SIZE && defined(CONFIG_INCLUDE_RESET_VECTOR) */
#ifdef CONFIG_INIT_STACKS
/* Pre-populate all bytes in _interrupt_stack with 0xAA
* init.c enforces that the _interrupt_stack pointer
* and CONFIG_ISR_STACK_SIZE are a multiple of STACK_ALIGN (4) */
movhi r1, %hi(_interrupt_stack)
ori r1, r1, %lo(_interrupt_stack)
movhi r2, %hi(CONFIG_ISR_STACK_SIZE)
ori r2, r2, %lo(CONFIG_ISR_STACK_SIZE)
/* Put constant 0xaaaaaaaa in r3 */
movhi r3, 0xaaaa
ori r3, r3, 0xaaaa
1:
/* Loop through the _interrupt_stack treating it as an array of
* u32_t, setting each element to r3 */
stw r3, (r1)
subi r2, r2, 4
addi r1, r1, 4
blt r0, r2, 1b
#endif
/* Set up the initial stack pointer to the interrupt stack, safe
* to use this as the CPU boots up with interrupts disabled and we
* don't turn them on until much later, when the kernel is on
* the main stack */
movhi sp, %hi(_interrupt_stack)
ori sp, sp, %lo(_interrupt_stack)
addi sp, sp, CONFIG_ISR_STACK_SIZE
#if defined(CONFIG_GP_LOCAL) || defined(CONFIG_GP_GLOBAL) || \
defined(CONFIG_GP_ALL_DATA)
/* Initialize global pointer with the linker variable we set */
movhi gp, %hi(_gp)
ori gp, gp, %lo(_gp)
#endif
/* TODO if shadow register sets enabled, interate through them to set
* up. Need to clear r0, write gp, set the exception stack pointer
* GH-1821
*/
/* Jump into C domain. _PrepC zeroes BSS, copies rw data into RAM,
* and then enters z_cstart */
call _PrepC