Principle of software interruption in the lpc2103 Operating System

Source: Internet
Author: User

Recently I checked the startup code of the lpc2103 and stopped the software interruption. I analyzed it carefully and thought it was so understandable (if the analysis is incorrect, I hope Daniel can correct it ):

The Code contains a section (startup. s ):

; Soft Interrupt
SWI_Handler
CMP R0, #4
Ldrlo pc, [PC, R0, LSL #2]
Movs pc, LR

; Timeout ;------------------------------------------------------------------------------------------------
SwiFunction
DCD IRQDisable; 0
DCD IRQEnable; 1
DCD FIQDisable; 2
DCD FIQEable; 3

Obviously SWI_Handler is the entry to the soft interrupt service program, while the SwiFunction Soft Interrupt vector table. Obviously, the soft interrupt service program is very simple, and there is no Soft Interrupt Processing Program for handling different Soft Interrupt numbers at all (I mean the same processing for all Soft Interrupt numbers ). Because I regard the Red Section R0 as a function parameter rather than a Soft Interrupt number.
The following code is available in (target. h:

_ Swi (0x00) void SwiHandle1 (int Handle );

# Define IRQDisable () SwiHandle1 (0)
# Define IRQEnable () SwiHandle1 (1)
# Define FIQDisable () SwiHandle1 (2)
# Define FIQEnable () SwiHandle1 (3)

That is, I understand R0 as a parameter of the SwiHandle1 function. So where is the Soft Interrupt No. 0x00?

(Blog.csdn.net/jianshe999/archive/2008/02/28/2126014.aspx)

**************************************** **************************************** **************************************** ********

Software interruption is triggered by a Special Soft Interrupt command SWI. The SWI command is followed by an interrupt number,
To identify multiple software interruptions that may coexist.
To call software interruptions in a C program, you need to use the compiler's extended functions, using the keyword "_ swi"
To declare the interrupt function. Note that the Soft Interrupt number is also specified when the function is defined.
_ Swi (0x24) void my_swi (void );
In this way, when the function my_swi is called, "SWI 0x24" will be used to replace normal function calls.
Use "BL my_swi ".

It can be found that the software interruption also has the problem of the interruption branch, that is, the root
Different handlers are called Based on the interrupt number. The Soft Interrupt number only exists in the SWI instruction code,
Therefore, you need to read the instruction code that triggers the interrupt in the interrupt processing program, extract the interrupt number information, and perform further processing.

The encoding format of Soft Interrupt commands is as follows:
The SWI instruction encoding format in the ARM state, with 32-bit length. The 24-bit lower is the interrupt number.
The encoding format of the SWI command in the Thumb state, with a 16-bit length. The 8-bit lower is the interrupt number.

To obtain the SWI instruction address in the interrupt handler, you can use the LR register. Each
When a SWI is returned, the processor automatically saves and adjusts the LR register
Point to the address of the next SWI command.
The SWI command address. Note that when the invocation status of the SWI command is different
Make the address interval is different, if the SWI before the execution is in the ARM state, you need to through the LR-4
Get the SWI command address, if it is in the Thumb state, then just the LR-2.

The following is a routine for extracting SWI interrupt numbers:
MRS R0, SPSR; check the status before the SWI response
TST R0, # T_bit; is it ARM or Thumb? # T_bit = 0x20
LDRNEH R0, [LR, #-2]; it is Thumb, and the SWI instruction code is read back.
BICNE R0, R0, #0xff00; low 8-bit Extraction
LDREQ R0, [LR, #-4]; it is an ARM, and the SWI instruction code is read back.
BICEQ R0, R0, #0xff000000; 24-bit low Extraction
The content in register R0 is the correct Soft Interrupt number

**************************************** **************************************** **************************************** ********

In fact, the above analysis is exactly what the Soft Interrupt service program should do. This is similar to the practice of the IRQ interrupt service program, and the corresponding interrupt processing program should be found based on the corresponding interrupt number. Okay. Let's see the difference between the Soft Interrupt number and the parameter.

 

For your security, please only open the URL with reliable source

Open website {
Function onclick ()
{
Share. safelink. close (); return false;
}
} "Href =" http://writeblog.csdn.net/# "> cancel

From: http://hi.baidu.com/xinghun%5F4/blog/item/405133d65e0ed6d6a144dfc7.html

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.