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

浏览源代码.

结构体

struct  TaskContext
 
struct  IrqContext
 

函数

VOID * OsTaskStackInit (UINT32 taskID, UINT32 stackSize, VOID *topStack, BOOL initFlag)
 内核态任务运行栈初始化 更多...
 
VOID OsUserCloneParentStack (VOID *childStack, UINTPTR parentTopOfStask, UINT32 parentStackSize)
 把父任务上下文克隆给子任务 更多...
 
VOID OsUserTaskStackInit (TaskContext *context, UINTPTR taskEntry, UINTPTR stack)
 用户态运行栈初始化,此时上下文还在内核区 更多...
 
VOID OsInitSignalContext (const VOID *sp, VOID *signalContext, UINTPTR sigHandler, UINT32 signo, UINT32 param)
 初始化信号上下文 更多...
 
void arm_clean_cache_range (UINTPTR start, UINTPTR end)
 
void arm_inv_cache_range (UINTPTR start, UINTPTR end)
 

函数说明

◆ arm_clean_cache_range()

void arm_clean_cache_range ( UINTPTR  start,
UINTPTR  end 
)
这是这个函数的调用关系图:

◆ arm_inv_cache_range()

void arm_inv_cache_range ( UINTPTR  start,
UINTPTR  end 
)
这是这个函数的调用关系图:

◆ 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
这是这个函数的调用关系图:

◆ OsTaskStackInit()

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()

VOID OsUserCloneParentStack ( VOID *  childStack,
UINTPTR  parentTopOfStask,
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()

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
这是这个函数的调用关系图: