Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:23:02

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