summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2013-05-02 11:41:22 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2013-05-03 17:30:55 +0200
commitecf7dd95647c689c123f2635f5f7e892ae305487 (patch)
treee9f30720b37f2cbdd6c981a2248a2f548784c0a0
parentbsps/arm: Support ARMv7 VMSA sections and control (diff)
downloadrtems-ecf7dd95647c689c123f2635f5f7e892ae305487.tar.bz2
bsps/arm: Move CP15 start initialization
-rw-r--r--c/src/lib/libbsp/arm/lpc32xx/Makefile.am1
-rw-r--r--c/src/lib/libbsp/arm/lpc32xx/preinstall.am4
-rw-r--r--c/src/lib/libbsp/arm/lpc32xx/startup/bspstarthooks.c140
-rw-r--r--c/src/lib/libbsp/arm/shared/include/arm-cp15-start.h116
4 files changed, 140 insertions, 121 deletions
diff --git a/c/src/lib/libbsp/arm/lpc32xx/Makefile.am b/c/src/lib/libbsp/arm/lpc32xx/Makefile.am
index 166870c88a..1489efce3e 100644
--- a/c/src/lib/libbsp/arm/lpc32xx/Makefile.am
+++ b/c/src/lib/libbsp/arm/lpc32xx/Makefile.am
@@ -34,6 +34,7 @@ include_bsp_HEADERS += ../../shared/include/stackalloc.h
include_bsp_HEADERS += ../../shared/include/uart-output-char.h
include_bsp_HEADERS += ../../shared/tod.h
include_bsp_HEADERS += ../shared/include/start.h
+include_bsp_HEADERS += ../shared/include/arm-cp15-start.h
include_bsp_HEADERS += ../shared/lpc/include/lpc-timer.h
include_bsp_HEADERS += ../shared/lpc/include/lpc-dma.h
include_bsp_HEADERS += ../shared/lpc/include/lpc-i2s.h
diff --git a/c/src/lib/libbsp/arm/lpc32xx/preinstall.am b/c/src/lib/libbsp/arm/lpc32xx/preinstall.am
index 43eb71b39a..fd69c55c4f 100644
--- a/c/src/lib/libbsp/arm/lpc32xx/preinstall.am
+++ b/c/src/lib/libbsp/arm/lpc32xx/preinstall.am
@@ -90,6 +90,10 @@ $(PROJECT_INCLUDE)/bsp/start.h: ../shared/include/start.h $(PROJECT_INCLUDE)/bsp
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp/start.h
PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/start.h
+$(PROJECT_INCLUDE)/bsp/arm-cp15-start.h: ../shared/include/arm-cp15-start.h $(PROJECT_INCLUDE)/bsp/$(dirstamp)
+ $(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp/arm-cp15-start.h
+PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/arm-cp15-start.h
+
$(PROJECT_INCLUDE)/bsp/lpc-timer.h: ../shared/lpc/include/lpc-timer.h $(PROJECT_INCLUDE)/bsp/$(dirstamp)
$(INSTALL_DATA) $< $(PROJECT_INCLUDE)/bsp/lpc-timer.h
PREINSTALL_FILES += $(PROJECT_INCLUDE)/bsp/lpc-timer.h
diff --git a/c/src/lib/libbsp/arm/lpc32xx/startup/bspstarthooks.c b/c/src/lib/libbsp/arm/lpc32xx/startup/bspstarthooks.c
index e828d8899c..03520624c8 100644
--- a/c/src/lib/libbsp/arm/lpc32xx/startup/bspstarthooks.c
+++ b/c/src/lib/libbsp/arm/lpc32xx/startup/bspstarthooks.c
@@ -7,10 +7,10 @@
*/
/*
- * Copyright (c) 2009-2011 embedded brains GmbH. All rights reserved.
+ * Copyright (c) 2009-2013 embedded brains GmbH. All rights reserved.
*
* embedded brains GmbH
- * Obere Lagerstr. 30
+ * Dornierstr. 4
* 82178 Puchheim
* Germany
* <rtems@embedded-brains.de>
@@ -24,6 +24,7 @@
#include <bsp/start.h>
#include <bsp/lpc32xx.h>
#include <bsp/mmu.h>
+#include <bsp/arm-cp15-start.h>
#include <bsp/linker-symbols.h>
#include <bsp/uart-output-char.h>
@@ -41,26 +42,8 @@
#define LPC32XX_MMU_CODE LPC32XX_MMU_READ_ONLY_CACHED
#endif
-static BSP_START_TEXT_SECTION void clear_bss(void)
-{
- const int *end = (const int *) bsp_section_bss_end;
- int *out = (int *) bsp_section_bss_begin;
-
- /* Clear BSS */
- while (out != end) {
- *out = 0;
- ++out;
- }
-}
-
#ifndef LPC32XX_DISABLE_MMU
- typedef struct {
- uint32_t begin;
- uint32_t end;
- uint32_t flags;
- } lpc32xx_mmu_config;
-
- static const BSP_START_DATA_SECTION lpc32xx_mmu_config
+ static const BSP_START_DATA_SECTION arm_cp15_start_section_config
lpc32xx_mmu_config_table [] = {
{
.begin = (uint32_t) bsp_section_fast_text_begin,
@@ -130,68 +113,26 @@ static BSP_START_TEXT_SECTION void clear_bss(void)
.flags = LPC32XX_MMU_READ_WRITE_DATA
}
};
-
- static BSP_START_TEXT_SECTION void set_translation_table_entries(
- uint32_t *ttb,
- const lpc32xx_mmu_config *config
- )
- {
- uint32_t i = ARM_MMU_SECT_GET_INDEX(config->begin);
- uint32_t iend =
- ARM_MMU_SECT_GET_INDEX(ARM_MMU_SECT_MVA_ALIGN_UP(config->end));
-
- if (config->begin != config->end) {
- while (i < iend) {
- ttb [i] = (i << ARM_MMU_SECT_BASE_SHIFT) | config->flags;
- ++i;
- }
- }
- }
-
- static BSP_START_TEXT_SECTION void
- setup_translation_table_and_enable_mmu(uint32_t ctrl)
- {
- uint32_t const dac =
- ARM_CP15_DAC_DOMAIN(LPC32XX_MMU_CLIENT_DOMAIN, ARM_CP15_DAC_CLIENT);
- uint32_t *const ttb = (uint32_t *) bsp_translation_table_base;
- size_t const config_entry_count =
- sizeof(lpc32xx_mmu_config_table) / sizeof(lpc32xx_mmu_config_table [0]);
- size_t i = 0;
-
- arm_cp15_set_domain_access_control(dac);
- arm_cp15_set_translation_table_base(ttb);
-
- /* Initialize translation table with invalid entries */
- for (i = 0; i < ARM_MMU_TRANSLATION_TABLE_ENTRY_COUNT; ++i) {
- ttb [i] = 0;
- }
-
- for (i = 0; i < config_entry_count; ++i) {
- set_translation_table_entries(ttb, &lpc32xx_mmu_config_table [i]);
- }
-
- /* Enable MMU and cache */
- ctrl |= ARM_CP15_CTRL_I | ARM_CP15_CTRL_C | ARM_CP15_CTRL_M;
- arm_cp15_set_control(ctrl);
- }
#endif
static BSP_START_TEXT_SECTION void setup_mmu_and_cache(void)
{
- uint32_t ctrl = 0;
-
- /* Disable MMU and cache, basic settings */
- ctrl = arm_cp15_get_control();
- ctrl &= ~(ARM_CP15_CTRL_I | ARM_CP15_CTRL_R | ARM_CP15_CTRL_C
- | ARM_CP15_CTRL_V | ARM_CP15_CTRL_M);
- ctrl |= ARM_CP15_CTRL_S | ARM_CP15_CTRL_A;
- arm_cp15_set_control(ctrl);
+ uint32_t ctrl = arm_cp15_start_setup_mmu_and_cache(
+ ARM_CP15_CTRL_I | ARM_CP15_CTRL_R | ARM_CP15_CTRL_C
+ | ARM_CP15_CTRL_V | ARM_CP15_CTRL_M,
+ ARM_CP15_CTRL_S | ARM_CP15_CTRL_A
+ );
arm_cp15_cache_invalidate();
- arm_cp15_tlb_invalidate();
#ifndef LPC32XX_DISABLE_MMU
- setup_translation_table_and_enable_mmu(ctrl);
+ arm_cp15_start_setup_translation_table_and_enable_mmu(
+ ctrl,
+ (uint32_t *) bsp_translation_table_base,
+ LPC32XX_MMU_CLIENT_DOMAIN,
+ &lpc32xx_mmu_config_table [0],
+ RTEMS_ARRAY_SIZE(lpc32xx_mmu_config_table)
+ );
#endif
}
@@ -241,7 +182,6 @@ static BSP_START_TEXT_SECTION void setup_pll(void)
BSP_START_TEXT_SECTION void bsp_start_hook_0(void)
{
setup_pll();
- setup_mmu_and_cache();
}
static BSP_START_TEXT_SECTION void stop_dma_activities(void)
@@ -290,51 +230,9 @@ static BSP_START_TEXT_SECTION void setup_timer(void)
BSP_START_TEXT_SECTION void bsp_start_hook_1(void)
{
stop_dma_activities();
+ bsp_start_copy_sections();
+ setup_mmu_and_cache();
setup_uarts();
setup_timer();
-
- /* Copy .text section */
- arm_cp15_instruction_cache_invalidate();
- bsp_start_memcpy(
- (int *) bsp_section_text_begin,
- (const int *) bsp_section_text_load_begin,
- (size_t) bsp_section_text_size
- );
-
- /* Copy .rodata section */
- arm_cp15_instruction_cache_invalidate();
- bsp_start_memcpy(
- (int *) bsp_section_rodata_begin,
- (const int *) bsp_section_rodata_load_begin,
- (size_t) bsp_section_rodata_size
- );
-
- /* Copy .data section */
- arm_cp15_instruction_cache_invalidate();
- bsp_start_memcpy(
- (int *) bsp_section_data_begin,
- (const int *) bsp_section_data_load_begin,
- (size_t) bsp_section_data_size
- );
-
- /* Copy .fast_text section */
- arm_cp15_instruction_cache_invalidate();
- bsp_start_memcpy(
- (int *) bsp_section_fast_text_begin,
- (const int *) bsp_section_fast_text_load_begin,
- (size_t) bsp_section_fast_text_size
- );
-
- /* Copy .fast_data section */
- arm_cp15_instruction_cache_invalidate();
- bsp_start_memcpy(
- (int *) bsp_section_fast_data_begin,
- (const int *) bsp_section_fast_data_load_begin,
- (size_t) bsp_section_fast_data_size
- );
-
- /* Clear .bss section */
- clear_bss();
-
- /* At this point we can use objects outside the .start section */
+ bsp_start_clear_bss();
}
diff --git a/c/src/lib/libbsp/arm/shared/include/arm-cp15-start.h b/c/src/lib/libbsp/arm/shared/include/arm-cp15-start.h
new file mode 100644
index 0000000000..6fb822667c
--- /dev/null
+++ b/c/src/lib/libbsp/arm/shared/include/arm-cp15-start.h
@@ -0,0 +1,116 @@
+/*
+ * Copyright (c) 2009-2013 embedded brains GmbH. All rights reserved.
+ *
+ * embedded brains GmbH
+ * Dornierstr. 4
+ * 82178 Puchheim
+ * Germany
+ * <info@embedded-brains.de>
+ *
+ * The license and distribution terms for this file may be
+ * found in the file LICENSE in this distribution or at
+ * http://www.rtems.com/license/LICENSE.
+ */
+
+#ifndef LIBBSP_ARM_SHARED_ARM_CP15_START_H
+#define LIBBSP_ARM_SHARED_ARM_CP15_START_H
+
+#include <libcpu/arm-cp15.h>
+
+#include <bsp/start.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+BSP_START_TEXT_SECTION static inline void
+arm_cp15_set_domain_access_control(uint32_t val);
+
+BSP_START_TEXT_SECTION static inline void
+arm_cp15_set_translation_table_base(uint32_t *base);
+
+BSP_START_TEXT_SECTION static inline void
+arm_cp15_set_control(uint32_t val);
+
+BSP_START_TEXT_SECTION static inline uint32_t
+arm_cp15_get_control(void);
+
+BSP_START_TEXT_SECTION static inline void
+arm_cp15_cache_invalidate(void);
+
+BSP_START_TEXT_SECTION static inline void
+arm_cp15_tlb_invalidate(void);
+
+typedef struct {
+ uint32_t begin;
+ uint32_t end;
+ uint32_t flags;
+} arm_cp15_start_section_config;
+
+BSP_START_TEXT_SECTION static inline void
+arm_cp15_start_set_translation_table_entries(
+ uint32_t *ttb,
+ const arm_cp15_start_section_config *config
+)
+{
+ uint32_t i = ARM_MMU_SECT_GET_INDEX(config->begin);
+ uint32_t iend =
+ ARM_MMU_SECT_GET_INDEX(ARM_MMU_SECT_MVA_ALIGN_UP(config->end));
+
+ if (config->begin != config->end) {
+ while (i < iend) {
+ ttb [i] = (i << ARM_MMU_SECT_BASE_SHIFT) | config->flags;
+ ++i;
+ }
+ }
+}
+
+BSP_START_TEXT_SECTION static void
+arm_cp15_start_setup_translation_table_and_enable_mmu(
+ uint32_t ctrl,
+ uint32_t *ttb,
+ uint32_t client_domain,
+ const arm_cp15_start_section_config *config_table,
+ size_t config_count
+)
+{
+ uint32_t dac = ARM_CP15_DAC_DOMAIN(client_domain, ARM_CP15_DAC_CLIENT);
+ size_t i;
+
+ arm_cp15_set_domain_access_control(dac);
+ arm_cp15_set_translation_table_base(ttb);
+
+ /* Initialize translation table with invalid entries */
+ for (i = 0; i < ARM_MMU_TRANSLATION_TABLE_ENTRY_COUNT; ++i) {
+ ttb [i] = 0;
+ }
+
+ for (i = 0; i < config_count; ++i) {
+ arm_cp15_start_set_translation_table_entries(ttb, &config_table [i]);
+ }
+
+ /* Enable MMU and cache */
+ ctrl |= ARM_CP15_CTRL_I | ARM_CP15_CTRL_C | ARM_CP15_CTRL_M;
+ arm_cp15_set_control(ctrl);
+}
+
+BSP_START_TEXT_SECTION static inline uint32_t
+arm_cp15_start_setup_mmu_and_cache(uint32_t ctrl_clear, uint32_t ctrl_set)
+{
+ uint32_t ctrl = arm_cp15_get_control();
+
+ ctrl &= ~ctrl_clear;
+ ctrl |= ctrl_set;
+
+ arm_cp15_set_control(ctrl);
+
+ arm_cp15_tlb_invalidate();
+
+ return ctrl;
+}
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* LIBBSP_ARM_SHARED_ARM_CP15_START_H */