• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022-2022 Huawei Technologies Co., Ltd. All rights reserved.
3  *
4  * UniProton is licensed under Mulan PSL v2.
5  * You can use this software according to the terms and conditions of the Mulan PSL v2.
6  * You may obtain a copy of Mulan PSL v2 at:
7  *          http://license.coscl.org.cn/MulanPSL2
8  * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
9  * EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
10  * MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
11  * See the Mulan PSL v2 for more details.
12  * Create: 2022-11-22
13  * Description: cpu架构相关的外部头文件
14  */
15 #ifndef OS_CPU_ARMV8_H
16 #define OS_CPU_ARMV8_H
17 
18 #include "prt_typedef.h"
19 
20 #ifdef __cplusplus
21 #if __cplusplus
22 extern "C" {
23 #endif /* __cpluscplus */
24 #endif /* __cpluscplus */
25 
26 // CurrentEl等级
27 #define CURRENT_EL_2       0x8
28 #define CURRENT_EL_1       0x4
29 #define CURRENT_EL_0       0x0
30 
31 #define DAIF_DBG_BIT      (1U << 3)
32 #define DAIF_ABT_BIT      (1U << 2)
33 #define DAIF_IRQ_BIT      (1U << 1)
34 #define DAIF_FIQ_BIT      (1U << 0)
35 
36 #define INT_MASK          (1U << 7)
37 #define OS_CORE_ID_MASK          0xFFU
38 #define OS_CORE_MPID_CPUID(mpid) (((mpid) | ((mpid) >> 8)) & OS_CORE_ID_MASK)
39 
40 /*
41  * 任务上下文的结构体定义。
42  */
43 struct TskContext {
44     /* *< 当前物理寄存器R0-R12 */
45     uintptr_t elr;               // 返回地址
46     uintptr_t spsr;
47     uintptr_t far;
48     uintptr_t esr;
49     uintptr_t xzr;
50     uintptr_t x30;
51     uintptr_t x29;
52     uintptr_t x28;
53     uintptr_t x27;
54     uintptr_t x26;
55     uintptr_t x25;
56     uintptr_t x24;
57     uintptr_t x23;
58     uintptr_t x22;
59     uintptr_t x21;
60     uintptr_t x20;
61     uintptr_t x19;
62     uintptr_t x18;
63     uintptr_t x17;
64     uintptr_t x16;
65     uintptr_t x15;
66     uintptr_t x14;
67     uintptr_t x13;
68     uintptr_t x12;
69     uintptr_t x11;
70     uintptr_t x10;
71     uintptr_t x09;
72     uintptr_t x08;
73     uintptr_t x07;
74     uintptr_t x06;
75     uintptr_t x05;
76     uintptr_t x04;
77     uintptr_t x03;
78     uintptr_t x02;
79     uintptr_t x01;
80     uintptr_t x00;
81 };
82 
83 /*
84  *  描述: 读取当前核号
85  *        使用mpidr 寄存器 (64bit) 根据核的线程模式获取核号
86  *        bit 63-40 39-32   31  30 29~25  24 23-16  15-8   7~0
87  *             res0  aff3  res1  u  res0  mt  aff2  aff1  aff0
88  */
OsGetCoreID(void)89 OS_SEC_ALW_INLINE INLINE U32 OsGetCoreID(void)
90 {
91     U64 mpid;
92     OS_EMBED_ASM("MRS  %0, MPIDR_EL1" : "=r"(mpid)::"memory", "cc");
93     OS_EMBED_ASM("dmb sy" ::: "memory");
94     /* single-thread 模式下,核号取AFF0 AF1为0 */
95     /* muti-thread 模式下,核号取AFF1 AF0为0 */
96     /* 综上核号计算采用AFF0 + AFF1 */
97     return OS_CORE_MPID_CPUID(mpid);
98 }
99 
100 /*
101  * 获取当前核ID
102  */
PRT_GetCoreID(void)103 OS_SEC_ALW_INLINE INLINE U32 PRT_GetCoreID(void)
104 {
105     return OsGetCoreID();
106 }
107 
108 #define PRT_DSB() OS_EMBED_ASM("DSB sy" : : : "memory")
109 #define PRT_DMB() OS_EMBED_ASM("DMB sy" : : : "memory")
110 #define PRT_ISB() OS_EMBED_ASM("ISB" : : : "memory")
111 
112 #ifdef __cplusplus
113 #if __cplusplus
114 }
115 #endif /* __cpluscplus */
116 #endif /* __cpluscplus */
117 
118 #endif /* OS_CPU_ARMV8_H */
119