更新日期: 2022/06/01 来源: https://gitee.com/weharmony/kernel_liteos_a_note
los_hw.c 文件参考

浏览源代码.

函数

LITE_OS_SEC_TEXT_INIT VOID OsTaskExit (VOID)
 
STATIC VOID OsTaskEntrySetupLoopFrame (UINT32)
 
LITE_OS_SEC_TEXT_INIT VOID * OsTaskStackInit (UINT32 taskID, UINT32 stackSize, VOID *topStack, BOOL initFlag)
 内核态任务运行栈初始化 更多...
 
LITE_OS_SEC_TEXT VOID OsUserCloneParentStack (VOID *childStack, UINTPTR parentTopOfStack, UINT32 parentStackSize)
 把父任务上下文克隆给子任务 更多...
 
LITE_OS_SEC_TEXT_INIT VOID OsUserTaskStackInit (TaskContext *context, UINTPTR taskEntry, UINTPTR stack)
 用户态运行栈初始化,此时上下文还在内核区 更多...
 
VOID OsInitSignalContext (const VOID *sp, VOID *signalContext, UINTPTR sigHandler, UINT32 signo, UINT32 param)
 初始化信号上下文 更多...
 
DEPRECATED VOID Dmb (VOID)
 
DEPRECATED VOID Dsb (VOID)
 
DEPRECATED VOID Isb (VOID)
 
VOID FlushICache (VOID)
 Invalidate instruction cache. 更多...
 
VOID DCacheFlushRange (UINT32 start, UINT32 end)
 
VOID DCacheInvRange (UINT32 start, UINT32 end)
 

变量

CpuVendor g_cpuTable []
 
UINT64 g_cpuMap [LOSCFG_KERNEL_CORE_NUM]
 

函数说明

◆ DCacheFlushRange()

VOID DCacheFlushRange ( UINT32  start,
UINT32  end 
)

在文件 los_hw.c170 行定义.

171{
172 arm_clean_cache_range(start, end);
173}
void arm_clean_cache_range(UINTPTR start, UINTPTR end)
函数调用图:
这是这个函数的调用关系图:

◆ DCacheInvRange()

VOID DCacheInvRange ( UINT32  start,
UINT32  end 
)

在文件 los_hw.c175 行定义.

176{
177 arm_inv_cache_range(start, end);
178}
void arm_inv_cache_range(UINTPTR start, UINTPTR end)
函数调用图:

◆ Dmb()

DEPRECATED VOID Dmb ( VOID  )

在文件 los_hw.c146 行定义.

147{
148 __asm__ __volatile__ ("dmb" : : : "memory");
149}

◆ Dsb()

DEPRECATED VOID Dsb ( VOID  )

在文件 los_hw.c151 行定义.

152{
153 __asm__ __volatile__("dsb" : : : "memory");
154}

◆ Isb()

DEPRECATED VOID Isb ( VOID  )

在文件 los_hw.c156 行定义.

157{
158 __asm__ __volatile__("isb" : : : "memory");
159}

◆ OsInitSignalContext()

VOID OsInitSignalContext ( const VOID *  sp,
VOID *  signalContext,
UINTPTR  sigHandler,
UINT32  signo,
UINT32  param 
)

初始化信号上下文

在文件 los_hw.c138 行定义.

139{
140 IrqContext *newSp = (IrqContext *)signalContext;
141 (VOID)memcpy_s(signalContext, sizeof(IrqContext), sp, sizeof(IrqContext));
142 newSp->PC = sigHandler; //信号处理函数
143 newSp->R0 = signo; //sigHandler 参数一
144 newSp->R1 = param; //sigHandler 参数二
145}
macro EXC_SP_SET reg1 mrc 获取CPU信息 and mov mul reg0 计算当前CPU栈的偏移位置 ldr reg1 相减得到栈顶 mov sp
Definition: asm.h:57
UINT32 R0
Definition: los_hw_pri.h:87
UINT32 PC
Definition: los_hw_pri.h:93
UINT32 R1
Definition: los_hw_pri.h:88
这是这个函数的调用关系图:

◆ OsTaskEntrySetupLoopFrame()

STATIC VOID OsTaskEntrySetupLoopFrame ( UINT32  )

在文件 los_hw.c57 行定义.

59{
60 asm volatile("\tsub fp, sp, #0x4\n"
61 "\tpush {fp, lr}\n"
62 "\tadd fp, sp, #0x4\n"
63 "\tpush {fp, lr}\n"
64
65 "\tadd fp, sp, #0x4\n"
66 "\tbl OsTaskEntry\n"
67
68 "\tpop {fp, lr}\n"
69 "\tpop {fp, pc}\n");
70}
这是这个函数的调用关系图:

◆ OsTaskExit()

LITE_OS_SEC_TEXT_INIT VOID OsTaskExit ( VOID  )

在文件 los_hw.c51 行定义.

52{// swi {cond} <immed_24>
53 __asm__ __volatile__("swi 0");//处理器产生软中断异常,swi指令的低24位存放的是0
54}//该指令可以产生SWI异常,ARM通过该指令从用户模式切到SVC模式.
这是这个函数的调用关系图:

◆ OsTaskStackInit()

LITE_OS_SEC_TEXT_INIT VOID * OsTaskStackInit ( UINT32  taskID,
UINT32  stackSize,
VOID *  topStack,
BOOL  initFlag 
)

内核态任务运行栈初始化

在文件 los_hw.c73 行定义.

74{
75 if (initFlag == TRUE) {
76 OsStackInit(topStack, stackSize);
77 }
78 TaskContext *taskContext = (TaskContext *)(((UINTPTR)topStack + stackSize) - sizeof(TaskContext));//上下文存放在栈的底部
79
80 /* initialize the task context */ //初始化任务上下文
81#ifdef LOSCFG_GDB
82 taskContext->PC = (UINTPTR)OsTaskEntrySetupLoopFrame;
83#else
84 taskContext->PC = (UINTPTR)OsTaskEntry;//内核态任务有统一的入口地址.
85#endif
86 taskContext->LR = (UINTPTR)OsTaskExit; /* LR should be kept, to distinguish it's THUMB or ARM instruction */
87 taskContext->R0 = taskID; /* R0 */
88
89#ifdef LOSCFG_THUMB
90 taskContext->regCPSR = PSR_MODE_SVC_THUMB; /* CPSR (Enable IRQ and FIQ interrupts, THUMNB-mode) */
91#else //用于设置CPSR寄存器
92 taskContext->regCPSR = PSR_MODE_SVC_ARM; /* CPSR (Enable IRQ and FIQ interrupts, ARM-mode) */
93#endif
94
95#if !defined(LOSCFG_ARCH_FPU_DISABLE)
96 /* 0xAAA0000000000000LL : float reg initialed magic word */
97 for (UINT32 index = 0; index < FP_REGS_NUM; index++) {
98 taskContext->D[index] = 0xAAA0000000000000LL + index; /* D0 - D31 */
99 }
100 taskContext->regFPSCR = 0;
101 taskContext->regFPEXC = FP_EN;
102#endif
103
104 return (VOID *)taskContext;
105}
macro EXC_SP_SET stackSize
Definition: asm.h:50
LITE_OS_SEC_TEXT_INIT VOID OsTaskExit(VOID)
Definition: los_hw.c:51
STATIC VOID OsTaskEntrySetupLoopFrame(UINT32)
Definition: los_hw.c:57
VOID OsStackInit(VOID *stacktop, UINT32 stacksize)
task栈的初始化,设置固定的值. 0xcccccccc 和 0xcacacaca
LITE_OS_SEC_TEXT_INIT VOID OsTaskEntry(UINT32 taskID)
Definition: los_task.c:493
unsigned long UINTPTR
Definition: los_typedef.h:68
unsigned int UINT32
Definition: los_typedef.h:57
UINT32 regCPSR
Definition: los_hw_pri.h:79
UINT32 LR
Definition: los_hw_pri.h:77
UINT64 D[FP_REGS_NUM]
Definition: los_hw_pri.h:54
UINT32 R0
Definition: los_hw_pri.h:72
UINT32 PC
Definition: los_hw_pri.h:78
UINT32 regFPSCR
Definition: los_hw_pri.h:55
UINT32 regFPEXC
Definition: los_hw_pri.h:56
函数调用图:
这是这个函数的调用关系图:

◆ OsUserCloneParentStack()

LITE_OS_SEC_TEXT VOID OsUserCloneParentStack ( VOID *  childStack,
UINTPTR  parentTopOfStack,
UINT32  parentStackSize 
)

把父任务上下文克隆给子任务

在文件 los_hw.c107 行定义.

108{
109 LosTaskCB *task = OsCurrTaskGet();
110 sig_cb *sigcb = &task->sig;
111 VOID *cloneStack = NULL;
112
113 if (sigcb->sigContext != NULL) {
114 cloneStack = (VOID *)((UINTPTR)sigcb->sigContext - sizeof(TaskContext));
115 } else {//cloneStack指向 TaskContext
116 cloneStack = (VOID *)(((UINTPTR)parentTopOfStack + parentStackSize) - sizeof(TaskContext));
117 }
118 (VOID)memcpy_s(childStack, sizeof(TaskContext), cloneStack, sizeof(TaskContext));//直接把任务上下文拷贝了一份
119 ((TaskContext *)childStack)->R0 = 0;//R0寄存器为0,这个很重要!!! pid = fork() pid == 0 是子进程返回.
120}
STATIC INLINE LosTaskCB * OsCurrTaskGet(VOID)
sig_cb sig
信号控制块,用于异步通信,类似于 linux singal模块
信号控制块(描述符)
Definition: los_signal.h:220
void * sigContext
信号上下文
Definition: los_signal.h:230
函数调用图:
这是这个函数的调用关系图:

◆ OsUserTaskStackInit()

LITE_OS_SEC_TEXT_INIT VOID OsUserTaskStackInit ( TaskContext context,
UINTPTR  taskEntry,
UINTPTR  stack 
)

用户态运行栈初始化,此时上下文还在内核区

在文件 los_hw.c123 行定义.

124{
125 LOS_ASSERT(context != NULL);
126
127#ifdef LOSCFG_THUMB
128 context->regCPSR = PSR_MODE_USR_THUMB;
129#else
130 context->regCPSR = PSR_MODE_USR_ARM;
131#endif
132 context->R0 = stack;//将用户态栈指针保存到上下文R0处
133 context->USP = TRUNCATE(stack, LOSCFG_STACK_POINT_ALIGN_SIZE);//改变 上下文的SP值,指向用户栈空间
134 context->ULR = 0;//保存子程序返回地址 例如 a call b ,在b中保存 a地址
135 context->PC = (UINTPTR)taskEntry;//入口函数,由外部传入,由上层应用指定,固然每个都不一样.
136}
UINT32 ULR
Definition: los_hw_pri.h:71
UINT32 USP
Definition: los_hw_pri.h:70
这是这个函数的调用关系图:

变量说明

◆ g_cpuMap

UINT64 g_cpuMap[LOSCFG_KERNEL_CORE_NUM]
初始值:
= {
[0 ... LOSCFG_KERNEL_CORE_NUM - 1] = (UINT64)(-1)
}
long unsigned int UINT64
Definition: los_typedef.h:66

在文件 los_hw.c45 行定义.

◆ g_cpuTable

CpuVendor g_cpuTable[]
初始值:
= {
{ 0xc07, "Cortex-A7" },
{ 0xc09, "Cortex-A9" },
{ 0, NULL }
}

在文件 los_hw.c37 行定义.