代码:

#define __ASM            __asm                                      /*!< asm keyword for ARM Compiler          */
#define __INLINE         __inline                                   /*!< inline keyword for ARM Compiler       */
#define __STATIC_INLINE  static __inline

/** \brief Set Priority Mask

This function assigns the given value to the Priority Mask Register.

\param [in] priMask Priority Mask
*/
__STATIC_INLINE void __set_PRIMASK(uint32_t priMask)
{
    register uint32_t __regPriMask         __ASM("primask");
    __regPriMask = (priMask);
}

参见armcc.chm文件9.155 Named register variables一节。

9.155 Named register variables

The compiler enables you to access registers of an ARM architecture-based processor or coprocessor using named register variables.

Syntax

register type var-name __asm(reg);
Where:
type
is the type of the named register variable.
Any type of the same size as the register being named can be used in the declaration of a named register variable. The type can be a structure, but bitfield layout is sensitive to endianness.
var-name
is the name of the named register variable.
reg
is a character string denoting the name of a register on an ARM architecture-based processor, or for coprocessor registers, a string syntax that identifies the coprocessor and corresponds with how you intend to use the variable.
Registers available for use with named register variables on ARM architecture-based processors are shown in the following table.

Table 9-19 Named registers available on ARM architecture-based processors

Register Character string for __asm Processors
APSR "apsr" All processors
CPSR "cpsr" All processors, apart from Cortex-M series processors.
BASEPRI "basepri" ARMv7-M processors
BASEPRI_MAX "basepri_max" ARMv7-M processors
CONTROL "control" ARMv6-M and ARMv7-M processors
DSP "dsp" ARMv6-M and ARMv7-M processors
EAPSR "eapsr" ARMv6-M and ARMv7-M processors
EPSR "epsr" ARMv6-M and ARMv7-M processors
FAULTMASK "faultmask" ARMv7-M processors
IAPSR "iapsr" ARMv6-M and ARMv7-M processors
IEPSR "iepsr" ARMv6-M and ARMv7-M processors
IPSR "ipsr" ARMv6-M and ARMv7-M processors
MSP "msp" ARMv6-M and ARMv7-M processors
PRIMASK "primask" ARMv6-M and ARMv7-M processors
PSP "psp" ARMv6-M and ARMv7-M processors
PSR "psr" ARMv6-M and ARMv7-M processors
r0 to r12 "r0" to "r12" All processors
r13 or sp "r13" or "sp" All processors
r14 or lr "r14" or "lr" All processors
r15 or pc "r15" or "pc" All processors
SPSR
"spsr"
All processors, apart from Cortex-M series processors.
XPSR "xpsr" ARMv6-M and ARMv7-M processors
 On targets with floating-point hardware, the registers listed in the following table are also available for use with named register variables.

Table 9-20 Named registers available on targets with floating-point hardware

Register Character string for __asm
FPSID "fpsid"
FPSCR "fpscr"
FPEXC "fpexc"
FPINST "fpinst"
FPINST2 "fpinst2"
FPSR "fpsr"
MVFR0 "mvfr0"
MVFR1 "mvfr1"

Note

Some registers are not available on some architectures.
 

Usage

You must declare core registers as global rather than local named register variables. Your program might still compile if you declare them locally, but you risk unexpected runtime behavior if you do. There is no restriction on the scope of named register variables for other registers.

Note

A global named register variable is global to the source file in which it is declared, not global to the program. It has no effect on other files, unless you use multifile compilation or you declare it in a header file.

Restrictions

Declaring a core register as a named register variable means that register is not available to the compiler for other operations. If you declare too many named register variables, code size increases significantly. In some cases, your program might not compile, for example if there are insufficient registers available to compute a particular expression.
Register usage defined by the Procedure Call Standard for the ARM Architecture (AAPCS) is not affected by declaring named register variables. For example, r0 is always used to return result values from functions even if it is declared as a named register variable.
Named register variables are a compiler-only feature. With the exception of r12, tools such as linkers do not change register usage in object files. The AAPCS reserves r12 as the inter-procedural scratch register. You must not declare r12 as a named register variable if you require its value to be preserved across function calls.

Examples

In the following example, apsr is declared as a named register variable for the "apsr" register:
register unsigned int apsr __asm("apsr");
apsr = ~(~apsr | 0x40);
This generates the following instruction sequence:
MRS r0,APSR ; formerly CPSR
BIC r0,r0,#0x40
MSR CPSR_c, r0
In the following example, PMCR is declared as a register variable associated with coprocessor cp15, with CRn = c9, CRm = c12, opcode1 = 0, and opcode2 = 0, in an MCR or an MRC instruction:
register unsigned int PMCR __asm("cp15:0:c9:c12:0");
__inline void __reset_cycle_counter(void)
{
    PMCR = 4;
}
The disassembled output is as follows:
__reset_cycle_counter PROC
    MOV    r0,#4
    MCR    p15,#0x0,r0,c9,c12,#0
    BX     lr
    ENDP
In the following example, cp15_control is declared as a register variable for accessing a coprocessor register. This example enables the MMU using CP15:
register unsigned int cp15_control __asm("cp15:0:c1:c0:0");
cp15_control |= 0x1;
The following instruction sequence is generated:
MRC  p15,#0x0,r0,c1,c0,#0
ORR  r0,r0,#1
MCR  p15,#0x0,r0,c1,c0,#0
The following example for Cortex-M3 declares _msp, _control and _psp as named register variables to set up stack pointers:
register unsigned int _control __asm("control");
register unsigned int _msp     __asm("msp");
register unsigned int _psp     __asm("psp");void init(void)
{
  _msp = 0x30000000;        // set up Main Stack Pointer
  _control = _control | 3;  // switch to User Mode with Process Stack
  _psp = 0x40000000;        // set up Process Stack Pointer
}
This generates the following instruction sequence:
init
  MOV r0,#0x30000000
  MSR MSP,r0
  MRS r0,CONTROL
  ORR r0,r0,#3
  MSR CONTROL,r0
  MOV r0,#0x40000000
  MSR PSP,r0
  BX lr

类似register uint32_t __regPriMask __ASM("primask");的代码分析的更多相关文章

  1. wifi display代码 分析

    转自:http://blog.csdn.net/lilian0118/article/details/23168531 这一章中我们来看Wifi Display连接过程的建立,包含P2P的部分和RTS ...

  2. Linux内核中的GPIO系统之(3):pin controller driver代码分析

    一.前言 对于一个嵌入式软件工程师,我们的软件模块经常和硬件打交道,pin control subsystem也不例外,被它驱动的硬件叫做pin controller(一般ARM soc的datash ...

  3. Linux时间子系统之(十七):ARM generic timer驱动代码分析

    专题文档汇总目录 Notes:ARM平台Clock/Timer架构:System counter.Timer以及两者之间关系:Per cpu timer通过CP15访问,System counter通 ...

  4. CC2431 代码分析③-忍辱负重的CC2430

    这节主要分析CC2430的代码,是参考节点的代码,协调器代码我们放到最后分析. 代码分析的原则是事件为导向,我们从CC2431 盲节点code的分析中发现CC2431 向CC2430参考节点发送的信息 ...

  5. start_kernel之前的汇编代码分析

    start_kernel之前的汇编代码分析 Boot中执行下面两句话之后,进入uclinux内核. theKernel = (void (*)(int, int, unsigned int))((ui ...

  6. C++反汇编代码分析–函数调用

    转载:http://shitouer.cn/2010/06/method-called/ 代码如下:#include “stdlib.h” int sum(int a,int b,int m,int ...

  7. Linux时间子系统(十七) ARM generic timer驱动代码分析

    一.前言 关注ARM平台上timer driver(clocksource chip driver和clockevent chip driver)的驱动工程师应该会注意到timer硬件的演化过程.在单 ...

  8. STM32F103 ucLinux开发之二(内核启动汇编代码分析)

    start_kernel之前的汇编代码分析 Boot中执行下面两句话之后,进入uclinux内核. theKernel = (void (*)(int, int, unsigned int))((ui ...

  9. Linux内核中的GPIO系统之(3):pin controller driver代码分析--devm_kzalloc使用【转】

    转自:http://www.wowotech.net/linux_kenrel/pin-controller-driver.html 一.前言 对于一个嵌入式软件工程师,我们的软件模块经常和硬件打交道 ...

随机推荐

  1. SQL Server ->> ColumnStore Index(列存储索引)

    Columnstored index是SQL Server 2012后加入的重大特性,数据不再以heap或者B Tree的形式存储(row level)存储在每一个数据库文件的页里面,而是以列为单位存 ...

  2. C# winfrom界面跳转闪烁问题解决方法

    在窗体的构造函数中添加代码: SetStyle(ControlStyles.UserPaint, true); SetStyle(ControlStyles.AllPaintingInWmPaint, ...

  3. 查询login什么时候过期

    -- Show all logins where the password is over 60 days old --查看60天没改密码的login SELECT name, LOGINPROPER ...

  4. 安装SCOM Gateway Server

    安装SCOM Gateway Server 1.为SCOM Gateway Server申请证书,导入CA证书链2.将安装介质Support Tools下AMD64下的 Microsoft.Enter ...

  5. dADas

    Linux(Centos)之安装Nginx及注意事项 - Kencery - 博客园   怪才(Kencery) 菜鸟的里程中只有奋斗,别无其他 博客园 首页 新随笔 联系 订阅 管理   Linux ...

  6. PHPWAMP自启异常,服务器重启后Apache等服务不会自动重启的原因分析

    在使用“PHPWAMP自动任务”时,不少学生遇到如下问题: “phpwamp绿色集成环境重启动电脑(服务器)后,不会自动启动网站服务” (如果是其他环境或是自己搭建时遇到此问题,也是可以用此法解决) ...

  7. 常用算法的C++实现

    常用算法的C++实现 // // DZAppDelegate.m // AlgorithmTest // // Created by dzpqzb on 13-8-4. // Copyright (c ...

  8. Linux中配置ftp服务器

    1. 先用rpm -qa| grep vsftpd命令检查是否已经安装,如果ftp没有安装,使用yum  -y  install vsftpd 安装,(ubuntu 下使用apt-get instal ...

  9. java多线程--实现Runnable接口方式

    因为java类只能继承一个类可以实现多个接口的特性,所以一般情况下不推荐使用继承Thread类实现多线程,下面是实现Runnable接口方式的简单多线程代码 package text; /** * 多 ...

  10. BZOJ1861:[ZJOI2006]书架(Splay)

    Description 小T有一个很大的书柜.这个书柜的构造有些独特,即书柜里的书是从上至下堆放成一列.她用1到n的正整数给每本书都编了号. 小T在看书的时候,每次取出一本书,看完后放回书柜然后再拿下 ...