2015-04-11 01:44:37 +02:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014 Wind River Systems, Inc.
|
|
|
|
*
|
2017-01-19 02:01:01 +01:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2015-04-11 01:44:37 +02:00
|
|
|
*/
|
|
|
|
|
2015-12-04 16:09:39 +01:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* @brief Full C support initialization
|
|
|
|
*
|
2015-10-20 18:42:33 +02:00
|
|
|
*
|
|
|
|
* Initialization of full C support: zero the .bss, copy the .data if XIP,
|
2019-03-08 22:19:05 +01:00
|
|
|
* call z_cstart().
|
2015-10-20 18:42:33 +02:00
|
|
|
*
|
|
|
|
* Stack is available in this module, but not the global data/bss until their
|
|
|
|
* initialization is performed.
|
2015-07-01 23:22:39 +02:00
|
|
|
*/
|
2015-04-11 01:44:37 +02:00
|
|
|
|
Introduce new sized integer typedefs
This is a start to move away from the C99 {u}int{8,16,32,64}_t types to
Zephyr defined u{8,16,32,64}_t and s{8,16,32,64}_t. This allows Zephyr
to define the sized types in a consistent manor across all the
architectures we support and not conflict with what various compilers
and libc might do with regards to the C99 types.
We introduce <zephyr/types.h> as part of this and have it include
<stdint.h> for now until we transition all the code away from the C99
types.
We go with u{8,16,32,64}_t and s{8,16,32,64}_t as there are some
existing variables defined u8 & u16 as well as to be consistent with
Zephyr naming conventions.
Jira: ZEP-2051
Change-Id: I451fed0623b029d65866622e478225dfab2c0ca8
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-19 17:32:08 +02:00
|
|
|
#include <zephyr/types.h>
|
2022-05-06 10:49:15 +02:00
|
|
|
#include <zephyr/toolchain.h>
|
|
|
|
#include <zephyr/linker/linker-defs.h>
|
|
|
|
#include <zephyr/arch/arc/v2/aux_regs.h>
|
2022-06-24 19:51:36 +02:00
|
|
|
#include <zephyr/arch/arc/cluster.h>
|
2022-05-06 10:49:15 +02:00
|
|
|
#include <zephyr/kernel_structs.h>
|
2018-01-31 05:41:47 +01:00
|
|
|
#include <kernel_internal.h>
|
2015-04-11 01:44:37 +02:00
|
|
|
|
2016-11-29 23:09:31 +01:00
|
|
|
/* XXX - keep for future use in full-featured cache APIs */
|
|
|
|
#if 0
|
2016-05-23 22:30:55 +02:00
|
|
|
/**
|
|
|
|
* @brief Disable the i-cache if present
|
|
|
|
*
|
|
|
|
* For those ARC CPUs that have a i-cache present,
|
|
|
|
* invalidate the i-cache and then disable it.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void disable_icache(void)
|
|
|
|
{
|
|
|
|
unsigned int val;
|
|
|
|
|
2019-03-08 22:19:05 +01:00
|
|
|
val = z_arc_v2_aux_reg_read(_ARC_V2_I_CACHE_BUILD);
|
2016-05-23 22:30:55 +02:00
|
|
|
val &= 0xff; /* version field */
|
|
|
|
if (val == 0) {
|
|
|
|
return; /* skip if i-cache is not present */
|
|
|
|
}
|
2019-03-08 22:19:05 +01:00
|
|
|
z_arc_v2_aux_reg_write(_ARC_V2_IC_IVIC, 0);
|
2020-07-20 17:14:58 +02:00
|
|
|
__builtin_arc_nop();
|
2019-03-08 22:19:05 +01:00
|
|
|
z_arc_v2_aux_reg_write(_ARC_V2_IC_CTRL, 1);
|
2016-05-23 22:30:55 +02:00
|
|
|
}
|
|
|
|
|
2016-05-09 23:26:28 +02:00
|
|
|
/**
|
|
|
|
* @brief Invalidate the data cache if present
|
|
|
|
*
|
|
|
|
* For those ARC CPUs that have a data cache present,
|
|
|
|
* invalidate the data cache.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static void invalidate_dcache(void)
|
|
|
|
{
|
|
|
|
unsigned int val;
|
|
|
|
|
2019-03-08 22:19:05 +01:00
|
|
|
val = z_arc_v2_aux_reg_read(_ARC_V2_D_CACHE_BUILD);
|
2016-05-09 23:26:28 +02:00
|
|
|
val &= 0xff; /* version field */
|
|
|
|
if (val == 0) {
|
|
|
|
return; /* skip if d-cache is not present */
|
|
|
|
}
|
2019-03-08 22:19:05 +01:00
|
|
|
z_arc_v2_aux_reg_write(_ARC_V2_DC_IVDC, 1);
|
2016-05-09 23:26:28 +02:00
|
|
|
}
|
2016-11-29 23:09:31 +01:00
|
|
|
#endif
|
2016-05-09 23:26:28 +02:00
|
|
|
|
2022-06-24 19:51:36 +02:00
|
|
|
#ifdef CONFIG_ISA_ARCV3
|
|
|
|
/* NOTE: it will be called from early C code - we must NOT use global / static variables in it! */
|
|
|
|
static void arc_cluster_scm_enable(void)
|
|
|
|
{
|
|
|
|
unsigned int cluster_version;
|
|
|
|
|
|
|
|
/* Check that we have cluster and its version is supported */
|
|
|
|
cluster_version = z_arc_v2_aux_reg_read(_ARC_REG_CLN_BCR) & _ARC_CLN_BCR_VER_MAJOR_MASK;
|
|
|
|
if (cluster_version < _ARC_REG_CLN_BCR_VER_MAJOR_ARCV3_MIN) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Check that we have shared cache in cluster */
|
|
|
|
if (!(z_arc_v2_aux_reg_read(_ARC_CLNR_BCR_0) & _ARC_CLNR_BCR_0_HAS_SCM)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable SCM, just in case. */
|
|
|
|
arc_cln_write_reg_nolock(ARC_CLN_CACHE_STATUS, 0);
|
|
|
|
|
|
|
|
/* Invalidate SCM before enabling. */
|
|
|
|
arc_cln_write_reg_nolock(ARC_CLN_CACHE_CMD,
|
|
|
|
ARC_CLN_CACHE_CMD_OP_REG_INV | ARC_CLN_CACHE_CMD_INCR);
|
|
|
|
while (arc_cln_read_reg_nolock(ARC_CLN_CACHE_STATUS) & ARC_CLN_CACHE_STATUS_BUSY)
|
|
|
|
;
|
|
|
|
|
|
|
|
arc_cln_write_reg_nolock(ARC_CLN_CACHE_STATUS, ARC_CLN_CACHE_STATUS_EN);
|
|
|
|
}
|
|
|
|
#endif /* CONFIG_ISA_ARCV3 */
|
|
|
|
|
2023-11-17 11:27:46 +01:00
|
|
|
#ifdef __CCAC__
|
|
|
|
extern char __device_states_start[];
|
|
|
|
extern char __device_states_end[];
|
|
|
|
/**
|
|
|
|
* @brief Clear device_states section
|
|
|
|
*
|
|
|
|
* This routine clears the device_states section,
|
|
|
|
* as MW compiler marks the section with NOLOAD flag.
|
|
|
|
*/
|
|
|
|
static void dev_state_zero(void)
|
|
|
|
{
|
|
|
|
z_early_memset(__device_states_start, 0, __device_states_end - __device_states_start);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2019-03-08 22:19:05 +01:00
|
|
|
extern FUNC_NORETURN void z_cstart(void);
|
2015-07-01 23:22:39 +02:00
|
|
|
/**
|
2015-07-01 23:51:40 +02:00
|
|
|
* @brief Prepare to and run C code
|
2015-07-01 23:22:39 +02:00
|
|
|
*
|
|
|
|
* This routine prepares for the execution of and runs C code.
|
|
|
|
*/
|
2015-04-11 01:44:37 +02:00
|
|
|
|
2023-12-08 13:55:21 +01:00
|
|
|
void z_prep_c(void)
|
2015-04-11 01:44:37 +02:00
|
|
|
{
|
2022-06-24 19:51:36 +02:00
|
|
|
#ifdef CONFIG_ISA_ARCV3
|
|
|
|
arc_cluster_scm_enable();
|
|
|
|
#endif
|
|
|
|
|
2019-03-08 22:19:05 +01:00
|
|
|
z_bss_zero();
|
2023-11-17 11:27:46 +01:00
|
|
|
#ifdef __CCAC__
|
|
|
|
dev_state_zero();
|
|
|
|
#endif
|
2019-03-08 22:19:05 +01:00
|
|
|
z_data_copy();
|
|
|
|
z_cstart();
|
2015-04-11 01:44:37 +02:00
|
|
|
CODE_UNREACHABLE;
|
|
|
|
}
|