当前位置:网站首页>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)
边栏推荐
- R语言--readr包读写数据
- [Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 24
- (August 9, 2021) example exercise of air quality index calculation (I)
- 'using an alias column in the where clause in PostgreSQL' - using an alias column in the where clause in PostgreSQL
- Flet教程之 按钮控件 ElevatedButton入门(教程含源码)
- How do std:: function and function pointer assign values to each other
- Practical dry goods: deploy mini version message queue based on redis6.0
- C language memory layout
- Process communication and thread explanation
- [Chongqing Guangdong education] National Open University spring 2019 2727 tax basis reference questions
猜你喜欢
Entitas learning [iv] other common knowledge points
Fastlane 一键打包/发布APP - 使用记录及踩坑
记一次 Showing Recent Errors Only Command /bin/sh failed with exit code 1 问题
Lecture 9
Single spa, Qiankun, Friday access practice
Memory computing integration: AI chip architecture in the post Moorish Era
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 16
Exness: positive I win, negative you lose
The detailed installation process of Ninja security penetration system (Ninjitsu OS V3). Both old and new VM versions can be installed through personal testing, with download sources
DVC use case (VI): Data Registry
随机推荐
Pat 1059 prime factors (25 points) prime table
Entitas learning [3] multi context system
Lecture 9
MySQL advanced review
8.8.1-PointersOnC-20220214
Iframe to only show a certain part of the page
Translation D29 (with AC code POJ 27:mode of sequence)
IPv6 experiment
Introduction to random and threadlocalrandom analysis
22 API design practices
Single spa, Qiankun, Friday access practice
Global and Chinese markets of NOx analyzers 2022-2028: Research Report on technology, participants, trends, market size and share
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 16
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 11
[Yunju entrepreneurial foundation notes] Chapter II entrepreneur test 8
What if the chat record is gone? How to restore wechat chat records on Apple Mobile
Global and Chinese market of cardiac monitoring 2022-2028: Research Report on technology, participants, trends, market size and share
How to create a new virtual machine
03_ Armv8 instruction set introduction load and store instructions
Using terminal connection in different modes of virtual machine