当前位置:网站首页>Abnormal mode of ARM processor
Abnormal mode of ARM processor
2022-07-04 12:34:00 【sydyh43】
1、ARM The processor has various exception modes , For response ARM Different states appear . When something unusual happens , Will then enter the relevant exception vector , meanwhile CPSR The register of will also be set to the specific mode .
example : When there is an interruption , No matter what kind of interruption , Will jump to 0x18 This main entrance address ( It could be 0xFFFFFF18, Look at the virtual address of the system initialization , It doesn't matter ), Then execute the specific interrupt registration function through the interrupt number .
At the same time, I will put CPSR The register is set to the corresponding mode .
When switching from one mode to another , You need to put the previous mode HW context Save up , For example, from user mode to kernel mode , Because in the new mode , Memory area division is different . Here's the picture , The general register in each mode is the same , In two modes , It can be used to transmit information , But like sp,lr Space related registers will be independent .
2、 When something unusual happens , How to enter exception mode
2.1、 In the kernel boot phase , Initialize the exception vector table .
start_kernel
setup_arch
early_trap_init
void __init early_trap_init(void *vectors_base)
{
unsigned long vectors = (unsigned long)vectors_base;
extern char __stubs_start[], __stubs_end[];
extern char __vectors_start[], __vectors_end[];
unsigned i;
vectors_page = vectors_base;
......
/*
* Copy the vectors, stubs and kuser helpers (in entry-armv.S)
* into the vector page, mapped at 0xffff0000, and ensure these
* are visible to the instruction stream.
*/
memcpy((void *)vectors, __vectors_start, __vectors_end - __vectors_start);
memcpy((void *)vectors + 0x1000, __stubs_start, __stubs_end - __stubs_start);
......
}
The exception vector address is saved in vectors_base Variable (CONFIG_VECTORS_BASE=0xffff0000) in .
Exception vector address __vectors_start stay entry-armv.S - arch/arm/kernel/entry-armv.S - Linux source code (v5.16.9) - Bootlin Implement initialization .
At compile time , The address has been determined
grep "__vectors" System.map -nR
When it starts , You can see the address distribution of the exception vector .
2.2、 When something unusual happens , Jump to the exception vector entry __vectors_start, Different exceptions correspond to different offsets , From the picture 1 It can be seen that software interrrupt Corresponding to the third term of the anomaly vector , namely W(ldr) pc, .L__vectors_start + 0x1000 Corresponding software interrupt Entrance .
.L__vectors_start:
W(b) vector_rst
W(b) vector_und
W(ldr) pc, .L__vectors_start + 0x1000
W(b) vector_pabt
W(b) vector_dabt
W(b) vector_addrexcptn
W(b) vector_irq
W(b) vector_fiq
.data
.align 2
.globl cr_alignment
Subsequently, it will jump to the specific exception vector processing process according to the macro definition .
.macro vector_stub, name, mode, correction=0
.align 5
vector_\name:
.if \correction
sub lr, lr, #\correction
.endif
@
@ Save r0, lr_<exception> (parent PC) and spsr_<exception>
@ (parent CPSR)
@
stmia sp, {r0, lr} @ save r0, lr
mrs lr, spsr
str lr, [sp, #8] @ save spsr
@
@ Prepare for SVC32 mode. IRQs remain disabled.
@
mrs r0, cpsr
eor r0, r0, #(\mode ^ SVC_MODE | PSR_ISETSTATE)
msr spsr_cxsf, r0
@
@ the branch table must immediately follow this code
@
and lr, lr, #0x0f
THUMB( adr r0, 1f )
THUMB( ldr lr, [r0, lr, lsl #2] )
mov r0, sp
ARM( ldr lr, [pc, lr, lsl #2] )
movs pc, lr @ branch to handler in SVC mode
ENDPROC(vector_\name)
边栏推荐
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 19
- (2021-08-20) web crawler learning 2
- Exness: positive I win, negative you lose
- The latest idea activation cracking tutorial, idea permanent activation code, the strongest in history
- Flet教程之 按钮控件 ElevatedButton入门(教程含源码)
- Realize cross tenant Vnet connection through azure virtual Wan
- Global and Chinese markets of digital PCR and real-time PCR 2022-2028: Research Report on technology, participants, trends, market size and share
- Alibaba cloud server connection intranet operation
- Netgear switch basic configuration command set
- Global and Chinese market for naval vessel maintenance 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 19
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 23
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 11
Practical dry goods: deploy mini version message queue based on redis6.0
Summary of Shanghai Jiaotong University postgraduate entrance examination module -- cryptography
How to create a new virtual machine
Leetcode: 408 sliding window median
French Data Protection Agency: using Google Analytics or violating gdpr
2018 meisai modeling summary +latex standard meisai template sharing
Bottom Logic -- Mind Map
随机推荐
8.8.1-PointersOnC-20220214
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 21
2021-08-09
Ultimate bug finding method - two points
Reptile learning 4 winter vacation learning series (1)
(August 9, 2021) example exercise of air quality index calculation (I)
How to realize the function of Sub Ledger of applet?
Leetcode: 408 sliding window median
Netgear switch basic configuration command set
AI should take code agriculture? Deepmind offers a programming version of "Alpha dog" alphacode that surpasses nearly half of programmers!
Servlet learning notes
Talk about "in C language"
Memory computing integration: AI chip architecture in the post Moorish Era
[the way of programmer training] - 2 Perfect number calculation
It's hard to hear C language? Why don't you take a look at this (V) pointer
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 11
When synchronized encounters this thing, there is a big hole, pay attention!
Uva536 binary tree reconstruction tree recovery
ASP. Net razor – introduction to VB loops and arrays
The frost peel off the purple dragon scale, and the xiariba people will talk about database SQL optimization and the principle of indexing (primary / secondary / clustered / non clustered)