Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:22:42

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup aarch64_start
0007  *
0008  * @brief Aarch64 system low level start.
0009  */
0010 
0011 /*
0012  * Copyright (C) 2020 On-Line Applications Research Corporation (OAR)
0013  * Written by Kinsey Moore <kinsey.moore@oarcorp.com>
0014  *
0015  * Redistribution and use in source and binary forms, with or without
0016  * modification, are permitted provided that the following conditions
0017  * are met:
0018  * 1. Redistributions of source code must retain the above copyright
0019  *    notice, this list of conditions and the following disclaimer.
0020  * 2. Redistributions in binary form must reproduce the above copyright
0021  *    notice, this list of conditions and the following disclaimer in the
0022  *    documentation and/or other materials provided with the distribution.
0023  *
0024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0025  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0026  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0027  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0028  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0029  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0030  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0031  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0032  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0033  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0034  * POSSIBILITY OF SUCH DAMAGE.
0035  */
0036 
0037 #ifndef LIBBSP_AARCH64_SHARED_START_H
0038 #define LIBBSP_AARCH64_SHARED_START_H
0039 
0040 #include <string.h>
0041 
0042 #include <bsp/linker-symbols.h>
0043 
0044 #ifdef __cplusplus
0045 extern "C" {
0046 #endif /* __cplusplus */
0047 
0048 /**
0049  * @defgroup aarch64_start System Start
0050  *
0051  * @ingroup RTEMSBSPsAArch64Shared
0052  *
0053  * @brief Aarch64 system low level start.
0054  *
0055  * @{
0056  */
0057 
0058 #define BSP_START_TEXT_SECTION __attribute__((section(".bsp_start_text")))
0059 
0060 #define BSP_START_DATA_SECTION __attribute__((section(".bsp_start_data")))
0061 
0062 /**
0063 * @brief System start entry.
0064 */
0065 void _start(void);
0066 
0067 /**
0068 * @brief Start entry hook 0.
0069 *
0070 * This hook will be called from the start entry code after all modes and
0071 * stack pointers are initialized but before the copying of the exception
0072 * vectors.
0073 */
0074 void bsp_start_hook_0(void);
0075 
0076 /**
0077 * @brief Start entry hook 1.
0078 *
0079 * This hook will be called from the start entry code after copying of the
0080 * exception vectors but before the call to boot_card().
0081 */
0082 void bsp_start_hook_1(void);
0083 
0084 BSP_START_TEXT_SECTION static inline void
0085 bsp_start_memcpy_libc(void *dest, const void *src, size_t n)
0086 {
0087   if (dest != src) {
0088     memcpy(dest, src, n);
0089   }
0090 }
0091 
0092 /**
0093  * @brief Copies all standard sections from the load to the runtime area.
0094  */
0095 BSP_START_TEXT_SECTION static inline void bsp_start_copy_sections(void)
0096 {
0097   /* Copy .text section */
0098   bsp_start_memcpy_libc(
0099     (int *) bsp_section_text_begin,
0100     (const int *) bsp_section_text_load_begin,
0101     (size_t) bsp_section_text_size
0102   );
0103 
0104   /* Copy .rodata section */
0105   bsp_start_memcpy_libc(
0106     (int *) bsp_section_rodata_begin,
0107     (const int *) bsp_section_rodata_load_begin,
0108     (size_t) bsp_section_rodata_size
0109   );
0110 
0111   /* Copy .data section */
0112   bsp_start_memcpy_libc(
0113     (int *) bsp_section_data_begin,
0114     (const int *) bsp_section_data_load_begin,
0115     (size_t) bsp_section_data_size
0116   );
0117 
0118   /* Copy .fast_text section */
0119   bsp_start_memcpy_libc(
0120     (int *) bsp_section_fast_text_begin,
0121     (const int *) bsp_section_fast_text_load_begin,
0122     (size_t) bsp_section_fast_text_size
0123   );
0124 
0125   /* Copy .fast_data section */
0126   bsp_start_memcpy_libc(
0127     (int *) bsp_section_fast_data_begin,
0128     (const int *) bsp_section_fast_data_load_begin,
0129     (size_t) bsp_section_fast_data_size
0130   );
0131 }
0132 
0133 /**
0134  * @brief Copies the .data, .fast_text and .fast_data sections from the load to
0135  * the runtime area using the C library memcpy().
0136  *
0137  * Works only in case the .start, .text and .rodata sections reside in one
0138  * memory region.
0139  */
0140 BSP_START_TEXT_SECTION static inline void bsp_start_copy_sections_compact(void)
0141 {
0142   /* Copy .data section */
0143   bsp_start_memcpy_libc(
0144     bsp_section_data_begin,
0145     bsp_section_data_load_begin,
0146     (size_t) bsp_section_data_size
0147   );
0148 
0149   /* Copy .fast_text section */
0150   bsp_start_memcpy_libc(
0151     bsp_section_fast_text_begin,
0152     bsp_section_fast_text_load_begin,
0153     (size_t) bsp_section_fast_text_size
0154   );
0155 
0156   /* Copy .fast_data section */
0157   bsp_start_memcpy_libc(
0158     bsp_section_fast_data_begin,
0159     bsp_section_fast_data_load_begin,
0160     (size_t) bsp_section_fast_data_size
0161   );
0162 }
0163 
0164 BSP_START_TEXT_SECTION static inline void bsp_start_clear_bss(void)
0165 {
0166   memset(bsp_section_bss_begin, 0, (size_t) bsp_section_bss_size);
0167 }
0168 
0169 BSP_START_TEXT_SECTION static inline void
0170 AArch64_start_set_vector_base(void)
0171 {
0172   __asm__ volatile (
0173     "msr VBAR_EL1, %[vtable]\n"
0174     : : [vtable] "r" (bsp_start_vector_table_begin)
0175   );
0176 }
0177 
0178 /** @} */
0179 
0180 #ifdef __cplusplus
0181 }
0182 #endif /* __cplusplus */
0183 
0184 #endif /* LIBBSP_AARCH64_SHARED_START_H */