The role of system mode in arm

Publisher:纯真年代Latest update time:2016-06-22 Source: eefocusKeywords:arm Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
I have learned a lot of arm details these days, but I don't really go into it in depth.

Only after paying money and being forced to learn, will you work hard to study it. It's really cheap.

I knew before that arm has 7 basic working modes:
FIQ, IRQ enter by interruption,
UNDEF, ABORT enter by program exception,
SVC enter by power-on and soft interrupt
, user enters by SVC handler
But there is also a system, which uses the same registers as user, but does not have SPSR, and can also execute privileged instructions
Such an alternative, it is not safe for OS to use it as user, and there is no automatic entry method when it is used as an exception or interrupt It is awkward
no matter how you look at it, of course, this is also realized after understanding, system is used to solve the problem of reentrant interrupts in arm

I searched and found that there is only one explanation about reentrant interrupts in arm on the Internet, and it does not consider it completely http://blog.chinaunix.net/u1/58640/showart_513501.html
The default interrupt handling function will push lr to the stack first, this article does not consider this point, and thinks the damage is serious

Such theoretical knowledge is rarely used in practice. Only those who pursue professionalism will delve into it, so that they can meet special requirements and do things that ordinary people cannot do.

First of all, the armcc keyword __irq cannot be used to write reentrant interrupts.
When the interrupt is reentrant, use BL to call the sub-function in the interrupt handling function. At this time, the problem comes. There are two situations.
If the sub-function is not declared in the __irq way and does not have the habit of pushing lr on the stack, then if there is another irq interrupt at this time, lr_irq will be flushed by the new value
, and it will fall into an endless loop.
If the sub-function is a good kid who will actively push lr on the stack, then only when the instruction of pushing lr is executed, the irq interrupt will cause the above problem, but the conditions for triggering the problem become very harsh.

So, at this time, the system mode is needed to save the world.
To write a reentrant interrupt, you must use the following assembly code

IRQHandler
        ;LR_IRQ ,SPSR_IRQ,r12 is pushed onto the stack to prevent the next IRQ interrupt from flushing it
        sub lr,lr,#4
        stmfd sp!,{lr}
        mrs r14,spsr
        STMFD sp!,{r12,r14}  

        ; Read and clear interrupt controller interrupt source
        ; omit related code         
        mov r12,#IntBase
        LDR r12,[r12,#IntSource]

        ;Switch to system mode and enable IRQ
        mrs r14,cpsr
        bic r14,r14,#0x9f
        orr r14,r14,#0x1f
        msr ​​CPSR_c,r14

        ;Save r0-r3,LR_user to the user stack, then call the c subroutine, and pass the interrupt source r0 as a parameter to the c processing function
        BL C_irq_handler;Looking at the name, you know that this c program is declared in the __irq form
                                ; it is a good kid who can push LR on the stack by itself
        LDMFD sp!,{r0-r3,lr}

        ;Switch to IRQ mode and disable IRQ
        mrs r12,cpsr
        bic r12,r12,#0x1f
        orr r12,r12,#0x92
        msr CPSR_c,r12

        ;Restore LR_irq, SPSR_irq and working register r12, then exit IRQ
        LDMFD sp!,{r12,r14}
        msr SPSR_csxf,r14
        LDMFD sp!,{PC}^

Keywords:arm Reference address:The role of system mode in arm

Previous article:Nestable IRQ routines in traditional ARM
Next article:The role of R0-R15 registers in arm

Recommended ReadingLatest update time:2024-11-15 16:36

ARM920T MMU-CP15 coprocessor registers
ARM microprocessors can support up to 16 coprocessors for various coprocessing operations. During program execution, each coprocessor only executes coprocessing instructions for itself and ignores instructions from the ARM processor and other coprocessors. ARM coprocessor instructions are mainly used by the ARM process
[Microcontroller]
Design and application of embedded SMI network converter based on ARM and uC/OS
    introduction     At present, with the rapid development of the Internet and embedded systems, more and more industrial measurement and control equipment have adopted network access functions as their default configuration to achieve remote monitoring of equipment and distributed information processing. However,
[Microcontroller]
Design and application of embedded SMI network converter based on ARM and uC/OS
ARM addressing mode experiment
1. Experimental Purpose 1.            Understand various addressing modes: immediate value; register; register shift; register indirect addressing; indexed addressing. 2.            Consolidate and improve the basic skills of using assembly language for programming in the ADS environment.   2. Experimental Content
[Microcontroller]
Basic knowledge of the overall analysis of the running process of ucos on s3c2410 - ARM9 chip knowledge
Before reading these contents, I hope you have a simple concept of computers. It is best to have studied the principles of computer composition and know some of the most basic concepts. If you have studied the 51 series of single-chip microcomputers and have done some development using the 51 series of single-chip mic
[Microcontroller]
The difference between cross compilers arm-linux-gnueabi and arm-linux-gnueabihf
I have never figured out what the problems are with these two cross-compilers, so I googled them and summarized them as follows. I hope it can help brothers who have the same confusion as me... I. What is ABI and EABI 1) ABI: Application Binary Interface (ABI) for the ARM Architecture In computers, the application bin
[Microcontroller]
Implementation of network remote monitoring of embedded Boa server based on ARM9 processor
    As high-tech technology is gradually integrated into traditional agricultural and sideline industries, greenhouse cultivation has become a way to produce off-season crops. This paper introduces the design of a greenhouse monitoring and control system based on the S3C2410 processor, and designs a network remote mon
[Microcontroller]
Implementation of network remote monitoring of embedded Boa server based on ARM9 processor
Sources say Nvidia and AMD will manufacture ARM-based PC chips to challenge Intel and Apple
According to news on October 24, Reuters reported that artificial intelligence chip giant Nvidia has begun designing a central processing unit (CPU) that can run Microsoft's Windows operating system and use Arm's technology. Sources revealed that AMD also plans to manufacture Arm-based PC chips. The chips are expected
[Home Electronics]
ARM - Stack
1 Stack: A stack is a data organization method with last-in-first-out, that is, the last stored data is taken out first, and the first stored data is taken out last. The bottom of the stack is the location of the first data pushed into the stack, and the top of the stack is the location of the last data pushed into
[Microcontroller]
ARM - Stack
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号