注解:CPSR(当前程序的状态寄存器)各位表示什么含义 ? 如何读取这个寄存器 ?

    搜索 @note_pic 可查看绘制的全部字符图
    搜索 @note_why 是尚未看明白的地方,有看明白的,请Pull Request完善
    搜索 @note_thinking 是一些的思考和建议
    搜索 @note_#if0 是由第三方项目提供不在内核源码中定义的极为重要结构体,为方便理解而添加的。
    搜索 @note_good 是给源码点赞的地方
上级 0667f6aa
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _ARCH_CONFIG_H
#define _ARCH_CONFIG_H
//ARM处理器一共有7种工作模式
#include "menuconfig.h"
//CPSR 当前程序的状态寄存器
#define CPSR_INT_DISABLE 0xC0 /* Disable both FIQ and IRQ */ //禁止中断
#define CPSR_IRQ_DISABLE 0x80 /* IRQ disabled when =1 */ //只禁止IRQ 中断
#define CPSR_FIQ_DISABLE 0x40 /* FIQ disabled when =1 */ //禁止 FIQ中断
#define CPSR_THUMB_ENABLE 0x20 /* Thumb mode when =1 */ //模式 1:CPU处于Thumb状态, 0:CPU处于ARM状态
#define CPSR_USER_MODE 0x10 //用户模式,除了用户模式,其余模式也叫特权模式,特权模式中除了系统模式以外的其余5种模式称为异常模式;
#define CPSR_FIQ_MODE 0x11 //快中断模式 用于高速数据传输或通道处理
#define CPSR_IRQ_MODE 0x12 //中断模式 用于通用的中断处理
#define CPSR_SVC_MODE 0x13 //管理模式 操作系统使用的保护模式
#define CPSR_ABT_MODE 0x17 //ABT模式 当数据或指令预取终止时进入该模式,用于虚拟存储及存储保护
#define CPSR_UNDEF_MODE 0x1B //未定义模式(其他模式)当未定义的指令执行时进入该模式,用于支持硬件协处理器的软件仿真
#define CPSR_MASK_MODE 0x1F
/* Define exception type ID */ //ARM处理器一共有7种工作模式,除了用户和系统模式其余都叫异常工作模式
#define OS_EXCEPT_RESET 0x00 //重置功能,例如:开机就进入CPSR_SVC_MODE模式
#define OS_EXCEPT_UNDEF_INSTR 0x01 //未定义的异常,就是others
#define OS_EXCEPT_SWI 0x02 //软件定时器中断
#define OS_EXCEPT_PREFETCH_ABORT 0x03 //预取异常(取指异常), 指令三步骤: 取指,译码,执行,
#define OS_EXCEPT_DATA_ABORT 0x04 //数据异常
#define OS_EXCEPT_FIQ 0x05 //快中断异常
#define OS_EXCEPT_ADDR_ABORT 0x06 //地址异常
#define OS_EXCEPT_IRQ 0x07 //普通中断异常
/* Define core num */
#ifdef LOSCFG_KERNEL_SMP
#define CORE_NUM LOSCFG_KERNEL_SMP_CORE_NUM //CPU 核数
#else
#define CORE_NUM 1
#endif
/* Initial bit32 stack value. */
#define OS_STACK_INIT 0xCACACACA //栈指针初始化值 0b 1010 1010 1010
/* Bit32 stack top magic number. */
#define OS_STACK_MAGIC_WORD 0xCCCCCCCC //用于栈顶值,可标识为栈是否被溢出过,神奇的 "烫烫烫烫"的根源所在! 0b 1100 1100 1100
/*************************************************************************** @note_pic
* 鸿蒙虚拟内存-栈空间运行时图
* 鸿蒙源码分析系列篇: https://blog.csdn.net/kuangyufei
https://my.oschina.net/u/3751245
****************************************************************************
+-------------------+0x00000000 <---- stack top == OS_STACK_MAGIC_WORD
| 0xCCCCCCCC |
+-------------------+0x00000004 == OS_STACK_INIT
| 0xCACACACA |
+-------------------+0x00000008
| 0xCACACACA |
+-------------------+ //1.一个栈初始化时 栈顶为 0xCCCCCCCC 其余空间全为 0xCACACACA 这样很容易通过值得比较知道栈有没有溢出
| 0xCACACACA | //2.在虚拟地址的序列上 栈底是高于栈顶的
+-------------------+ //3.sp在初始位置是指向栈底的
| 0xCACACACA | //4.还有多少0xCACACACA就代表使用的最高峰 peak used
+-------------------+ //5.一旦栈顶不是0xCCCCCCCC,说明已经溢出了,检测栈的溢出就是通过 栈顶值是否等于0xCCCCCCCC
| 0xCACACACA |
+-------------------+0x000000FF8 <--- sp
| 0xC32F9876 |
+-------------------+0x000000FFB
| 0x6543EB6 |
+-------------------+0x000001000 <---- stack bottom
*/
#ifdef LOSCFG_GDB
#define OS_EXC_UNDEF_STACK_SIZE 512
#define OS_EXC_ABT_STACK_SIZE 512
#else
#define OS_EXC_UNDEF_STACK_SIZE 40
#define OS_EXC_ABT_STACK_SIZE 40
#endif
#define OS_EXC_FIQ_STACK_SIZE 64
#define OS_EXC_IRQ_STACK_SIZE 64
#define OS_EXC_SVC_STACK_SIZE 0x2000
#define OS_EXC_STACK_SIZE 0x1000
#define REG_R0 0
#define REG_R1 1
#define REG_R2 2
#define REG_R3 3
#define REG_R4 4
#define REG_R5 5
#define REG_R6 6
#define REG_R7 7
#define REG_R8 8
#define REG_R9 9
#define REG_R10 10
#define REG_R11 11
#define REG_R12 12
#define REG_R13 13
#define REG_R14 14
#define REG_R15 15
#define REG_CPSR 16 //程序状态寄存器(current program status register) (当前程序状态寄存器)
#define REG_SP REG_R13 //堆栈指针 当不使用堆栈时,R13 也可以用做通用数据寄存器
#define REG_LR REG_R14 //连接寄存器。当执行子程序或者异常中断时,跳转指令会自动将当前地址存入LR寄存器中,当执行完子程 序或者中断后,根据LR中的值,恢复或者说是返回之前被打断的地址继续执行
#define REG_PC REG_R15 //指令寄存器
#endif
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _ARCH_CONFIG_H
#define _ARCH_CONFIG_H
//ARM处理器一共有7种工作模式
#include "menuconfig.h"
/******************************************************************************
CPSR(current program status register)当前程序的状态寄存器
CPSR有4个8位区域:标志域(F)、状态域(S)、扩展域(X)、控制域(C)
32 位的程序状态寄存器可分为4 个域:
1) 位[31:24]为条件标志位域,用f 表示;
2) 位[23:16]为状态位域,用s 表示;
3) 位[15:8]为扩展位域,用x 表示;
4) 位[7:0]为控制位域,用c 表示;
CPSR和其他寄存器不一样,其他寄存器是用来存放数据的,都是整个寄存器具有一个含义.
而CPSR寄存器是按位起作用的,也就是说,它的每一位都有专门的含义,记录特定的信息.
CPSR的低8位(包括I、F、T和M[4:0])称为控制位,程序无法修改,
除非CPU运行于特权模式下,程序才能修改控制位
N、Z、C、V均为条件码标志位。它们的内容可被算术或逻辑运算的结果所改变,
并且可以决定某条指令是否被执行!意义重大!
CPSR的第31位是 N,符号标志位。它记录相关指令执行后,其结果是否为负.
如果为负 N = 1,如果是非负数 N = 0.
CPSR的第30位是Z,0标志位。它记录相关指令执行后,其结果是否为0.
如果结果为0.那么Z = 1.如果结果不为0,那么Z = 0.
CPSR的第29位是C,进位标志位(Carry)。一般情况下,进行无符号数的运算。
加法运算:当运算结果产生了进位时(无符号数溢出),C=1,否则C=0。
减法运算(包括CMP):当运算时产生了借位时(无符号数溢出),C=0,否则C=1。
CPSR的第28位是V,溢出标志位(Overflow)。在进行有符号数运算的时候,
如果超过了机器所能标识的范围,称为溢出。
MSR{条件} 程序状态寄存器(CPSR 或SPSR)_<域>,操作数
MSR 指令用于将操作数的内容传送到程序状态寄存器的特定域中
示例如下:
MSR CPSR,R0 @传送R0 的内容到CPSR
MSR SPSR,R0 @传送R0 的内容到SPSR
MSR CPSR_c,R0 @传送R0 的内容到CPSR,但仅仅修改CPSR中的控制位域
MRS{条件} 通用寄存器,程序状态寄存器(CPSR 或SPSR)
MRS 指令用于将程序状态寄存器的内容传送到通用寄存器中。该指令一般用在以下两种情况:
1) 当需要改变程序状态寄存器的内容时,可用MRS 将程序状态寄存器的内容读入通用寄存器,修改后再写回程序状态寄存器。
2) 当在异常处理或进程切换时,需要保存程序状态寄存器的值,可先用该指令读出程序状态寄存器的值,然后保存。
示例如下:
MRS R0,CPSR @传送CPSR 的内容到R0
MRS R0,SPSR @传送SPSR 的内容到R0
@MRS指令是唯一可以直接读取CPSR和SPSR寄存器的指令
******************************************************************************/
#define CPSR_INT_DISABLE 0xC0 /* Disable both FIQ and IRQ */ //禁止IRQ和FIQ中断,因为0xC0 = 0x80 + 0x40
#define CPSR_IRQ_DISABLE 0x80 /* IRQ disabled when =1 */ //只禁止IRQ 中断
#define CPSR_FIQ_DISABLE 0x40 /* FIQ disabled when =1 */ //禁止 FIQ中断
#define CPSR_THUMB_ENABLE 0x20 /* Thumb mode when =1 */ //模式 1:CPU处于Thumb状态, 0:CPU处于ARM状态
#define CPSR_USER_MODE 0x10 //用户模式,除了用户模式,其余模式也叫特权模式,特权模式中除了系统模式以外的其余5种模式称为异常模式;
#define CPSR_FIQ_MODE 0x11 //快中断模式 用于高速数据传输或通道处理
#define CPSR_IRQ_MODE 0x12 //中断模式 用于通用的中断处理
#define CPSR_SVC_MODE 0x13 //管理模式 操作系统使用的保护模式
#define CPSR_ABT_MODE 0x17 //ABT模式 当数据或指令预取终止时进入该模式,用于虚拟存储及存储保护
#define CPSR_UNDEF_MODE 0x1B //未定义模式(其他模式)当未定义的指令执行时进入该模式,用于支持硬件协处理器的软件仿真
#define CPSR_MASK_MODE 0x1F
/* Define exception type ID */ //ARM处理器一共有7种工作模式,除了用户和系统模式其余都叫异常工作模式
#define OS_EXCEPT_RESET 0x00 //重置功能,例如:开机就进入CPSR_SVC_MODE模式
#define OS_EXCEPT_UNDEF_INSTR 0x01 //未定义的异常,就是others
#define OS_EXCEPT_SWI 0x02 //软件定时器中断
#define OS_EXCEPT_PREFETCH_ABORT 0x03 //预取异常(取指异常), 指令三步骤: 取指,译码,执行,
#define OS_EXCEPT_DATA_ABORT 0x04 //数据异常
#define OS_EXCEPT_FIQ 0x05 //快中断异常
#define OS_EXCEPT_ADDR_ABORT 0x06 //地址异常
#define OS_EXCEPT_IRQ 0x07 //普通中断异常
/* Define core num */
#ifdef LOSCFG_KERNEL_SMP
#define CORE_NUM LOSCFG_KERNEL_SMP_CORE_NUM //CPU 核数
#else
#define CORE_NUM 1
#endif
/* Initial bit32 stack value. */
#define OS_STACK_INIT 0xCACACACA //栈指针初始化值 0b 1010 1010 1010
/* Bit32 stack top magic number. */
#define OS_STACK_MAGIC_WORD 0xCCCCCCCC //用于栈顶值,可标识为栈是否被溢出过,神奇的 "烫烫烫烫"的根源所在! 0b 1100 1100 1100
/*************************************************************************** @note_pic
* 鸿蒙虚拟内存-栈空间运行时图
* 鸿蒙源码分析系列篇: https://blog.csdn.net/kuangyufei
https://my.oschina.net/u/3751245
****************************************************************************
+-------------------+0x00000000 <---- stack top == OS_STACK_MAGIC_WORD
| 0xCCCCCCCC |
+-------------------+0x00000004 == OS_STACK_INIT
| 0xCACACACA |
+-------------------+0x00000008
| 0xCACACACA |
+-------------------+ //1.一个栈初始化时 栈顶为 0xCCCCCCCC 其余空间全为 0xCACACACA 这样很容易通过值得比较知道栈有没有溢出
| 0xCACACACA | //2.在虚拟地址的序列上 栈底是高于栈顶的
+-------------------+ //3.sp在初始位置是指向栈底的
| 0xCACACACA | //4.还有多少0xCACACACA就代表使用的最高峰 peak used
+-------------------+ //5.一旦栈顶不是0xCCCCCCCC,说明已经溢出了,检测栈的溢出就是通过 栈顶值是否等于0xCCCCCCCC
| 0xCACACACA |
+-------------------+0x000000FF8 <--- sp
| 0xC32F9876 |
+-------------------+0x000000FFB
| 0x6543EB6 |
+-------------------+0x000001000 <---- stack bottom
*/
#ifdef LOSCFG_GDB
#define OS_EXC_UNDEF_STACK_SIZE 512
#define OS_EXC_ABT_STACK_SIZE 512
#else
#define OS_EXC_UNDEF_STACK_SIZE 40
#define OS_EXC_ABT_STACK_SIZE 40
#endif
#define OS_EXC_FIQ_STACK_SIZE 64
#define OS_EXC_IRQ_STACK_SIZE 64
#define OS_EXC_SVC_STACK_SIZE 0x2000
#define OS_EXC_STACK_SIZE 0x1000
#define REG_R0 0
#define REG_R1 1
#define REG_R2 2
#define REG_R3 3
#define REG_R4 4
#define REG_R5 5
#define REG_R6 6
#define REG_R7 7
#define REG_R8 8
#define REG_R9 9
#define REG_R10 10
#define REG_R11 11
#define REG_R12 12
#define REG_R13 13
#define REG_R14 14
#define REG_R15 15
#define REG_CPSR 16 //程序状态寄存器(current program status register) (当前程序状态寄存器)
#define REG_SP REG_R13 //堆栈指针 当不使用堆栈时,R13 也可以用做通用数据寄存器
#define REG_LR REG_R14 //连接寄存器。当执行子程序或者异常中断时,跳转指令会自动将当前地址存入LR寄存器中,当执行完子程 序或者中断后,根据LR中的值,恢复或者说是返回之前被打断的地址继续执行
#define REG_PC REG_R15 //指令寄存器
#endif
......@@ -91,9 +91,9 @@
/* R0: new task */
OsStartToRun:
MSR CPSR_c, #(CPSR_INT_DISABLE | CPSR_SVC_MODE)
MSR CPSR_c, #(CPSR_INT_DISABLE | CPSR_SVC_MODE) @禁止中断并切到管理模式
LDRH R1, [R0, #4]
LDRH R1, [R0, #4] @将存储器地址为R0+4 的低16位数据读入寄存器R1,并将R1 的高16 位清零
ORR R1, #OS_TASK_STATUS_RUNNING
STRH R1, [R0, #4]
......
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _LOS_SEM_PRI_H
#define _LOS_SEM_PRI_H
#include "los_sem.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/**
* @ingroup los_sem
* Semaphore control structure.
*/
typedef struct {
UINT8 semStat; /**< Semaphore state *///信号量的状态
UINT16 semCount; /**< Number of available semaphores *///有效信号量的数量
UINT16 maxSemCount; /**< Max number of available semaphores *///有效信号量的最大数量
UINT32 semID; /**< Semaphore control structure ID *///信号ID
LOS_DL_LIST semList; /**< Queue of tasks that are waiting on a semaphore *///等待信号量的任务队列,作为一个节点挂上去
} LosSemCB;
/**
* @ingroup los_sem
* The semaphore is not in use.
*
*/
#define OS_SEM_UNUSED 0
/**
* @ingroup los_sem
* The semaphore is used.
*
*/
#define OS_SEM_USED 1
/**
* @ingroup los_sem
* Obtain the head node in a semaphore doubly linked list.
*
*/
#define GET_SEM_LIST(ptr) LOS_DL_LIST_ENTRY(ptr, LosSemCB, semList)
extern LosSemCB *g_allSem;
/**
* @ingroup los_sem
* COUNT | INDEX split bit
*/
#define SEM_SPLIT_BIT 16
/**
* @ingroup los_sem
* Set the semaphore id
*/
#define SET_SEM_ID(count, semID) (((count) << SEM_SPLIT_BIT) | (semID))
/**
* @ingroup los_sem
* get the semaphore index
*/
#define GET_SEM_INDEX(semID) ((semID) & ((1U << SEM_SPLIT_BIT) - 1))
/**
* @ingroup los_sem
* get the semaphore count
*/
#define GET_SEM_COUNT(semID) ((semID) >> SEM_SPLIT_BIT)
/**
* @ingroup los_sem
* Obtain a semaphore ID.
*
*/
#define GET_SEM(semID) (((LosSemCB *)g_allSem) + GET_SEM_INDEX(semID))
/**
* @ingroup los_sem
* Maximum value of task information.
*
*/
#define OS_MAX_PENDTASK_INFO 4
extern UINT32 OsSemInit(VOID);
extern UINT32 OsSemPostUnsafe(UINT32 semHandle, BOOL *needSched);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_SEM_PRI_H */
/*
* Copyright (c) 2013-2019, Huawei Technologies Co., Ltd. All rights reserved.
* Copyright (c) 2020, Huawei Device Co., Ltd. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification,
* are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* 3. Neither the name of the copyright holder nor the names of its contributors may be used
* to endorse or promote products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _LOS_SEM_PRI_H
#define _LOS_SEM_PRI_H
#include "los_sem.h"
#ifdef __cplusplus
#if __cplusplus
extern "C" {
#endif /* __cplusplus */
#endif /* __cplusplus */
/**
* @ingroup los_sem
* Semaphore control structure.
*/
typedef struct {
UINT8 semStat; /**< Semaphore state *///信号量的状态
UINT16 semCount; /**< Number of available semaphores *///有效信号量的数量
UINT16 maxSemCount; /**< Max number of available semaphores *///有效信号量的最大数量
UINT32 semID; /**< Semaphore control structure ID *///信号量索引号
LOS_DL_LIST semList; /**< Queue of tasks that are waiting on a semaphore *///等待信号量的任务队列,任务通过阻塞节点挂上去
} LosSemCB;
/**
* @ingroup los_sem
* The semaphore is not in use.
*
*/
#define OS_SEM_UNUSED 0
/**
* @ingroup los_sem
* The semaphore is used.
*
*/
#define OS_SEM_USED 1
/**
* @ingroup los_sem
* Obtain the head node in a semaphore doubly linked list.
*
*/
#define GET_SEM_LIST(ptr) LOS_DL_LIST_ENTRY(ptr, LosSemCB, semList)
extern LosSemCB *g_allSem;
/**
* @ingroup los_sem
* COUNT | INDEX split bit
*/
#define SEM_SPLIT_BIT 16
/**
* @ingroup los_sem
* Set the semaphore id
*/
#define SET_SEM_ID(count, semID) (((count) << SEM_SPLIT_BIT) | (semID))
/**
* @ingroup los_sem
* get the semaphore index
*/
#define GET_SEM_INDEX(semID) ((semID) & ((1U << SEM_SPLIT_BIT) - 1))
/**
* @ingroup los_sem
* get the semaphore count
*/
#define GET_SEM_COUNT(semID) ((semID) >> SEM_SPLIT_BIT)
/**
* @ingroup los_sem
* Obtain a semaphore ID.
*
*/
#define GET_SEM(semID) (((LosSemCB *)g_allSem) + GET_SEM_INDEX(semID))
/**
* @ingroup los_sem
* Maximum value of task information.
*
*/
#define OS_MAX_PENDTASK_INFO 4
extern UINT32 OsSemInit(VOID);
extern UINT32 OsSemPostUnsafe(UINT32 semHandle, BOOL *needSched);
#ifdef __cplusplus
#if __cplusplus
}
#endif /* __cplusplus */
#endif /* __cplusplus */
#endif /* _LOS_SEM_PRI_H */
......@@ -856,19 +856,19 @@ STATIC INLINE VOID OsMemClearNode(LosMemDynNode *node)
/*
* Description : merge this node and pre node, then clear this node info
* Input : node --- Pointer to node which will be merged
*/ //合并指定动态内存节点
*/ //将指定动态内存节点和前节点合并
STATIC INLINE VOID OsMemMergeNode(LosMemDynNode *node)
{
LosMemDynNode *nextNode = NULL;
node->selfNode.preNode->selfNode.sizeAndFlag += node->selfNode.sizeAndFlag;
nextNode = (LosMemDynNode *)((UINTPTR)node + node->selfNode.sizeAndFlag);
nextNode->selfNode.preNode = node->selfNode.preNode;
node->selfNode.preNode->selfNode.sizeAndFlag += node->selfNode.sizeAndFlag;//前节点大小变大
nextNode = (LosMemDynNode *)((UINTPTR)node + node->selfNode.sizeAndFlag);//找到node的后节点
nextNode->selfNode.preNode = node->selfNode.preNode;//后节点指向前节点,如此完成了合并
#ifdef LOSCFG_MEM_HEAD_BACKUP
OsMemNodeSave(node->selfNode.preNode);
OsMemNodeSave(nextNode);
#endif
OsMemClearNode(node);
OsMemClearNode(node);//清空节点
}
//是否是一个扩展内存池
STATIC INLINE BOOL IsExpandPoolNode(VOID *pool, LosMemDynNode *node)
......@@ -1306,11 +1306,11 @@ STATIC INLINE VOID OsMemSetMagicNumAndTaskID(LosMemDynNode *node)
* If the operation occured before task initialization(runTask was not assigned)
* or in interrupt, make the value of taskid of node to 0xffffffff
*/
if ((runTask != NULL) && OS_INT_INACTIVE) {
OS_MEM_TASKID_SET(node, runTask->taskID);
} else {
if ((runTask != NULL) && OS_INT_INACTIVE) {//当前没有中断发生时
OS_MEM_TASKID_SET(node, runTask->taskID);//设置节点的使用任务
} else {//发生中断的情况 @note_why 为何中断发生时不能设置任务?
/* If the task mode does not initialize, the field is the 0xffffffff */
node->selfNode.freeNodeInfo.pstNext = (LOS_DL_LIST *)OS_NULL_INT;
node->selfNode.freeNodeInfo.pstNext = (LOS_DL_LIST *)OS_NULL_INT;//如果任务模式没有初始化,设置为 0xffffffff
}
}
......
git add -A
git commit -m '注解:最佳适应算法解决了什么问题? 内核是如何实现动态内存的最佳分配的?
git commit -m '注解:CPSR(当前程序的状态寄存器)各位表示什么含义 ? 如何读取这个寄存器 ?
搜索 @note_pic 可查看绘制的全部字符图
搜索 @note_why 是尚未看明白的地方,有看明白的,请Pull Request完善
搜索 @note_thinking 是一些的思考和建议
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册