[architecture]-ARMV7架构下Linux Kernel的Userspace进程切换时保存和恢复哪些寄存器
生活随笔
收集整理的這篇文章主要介紹了
[architecture]-ARMV7架构下Linux Kernel的Userspace进程切换时保存和恢复哪些寄存器
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
★★★ 個人博客導讀首頁—點擊此處 ★★★
.
文章目錄
- 1、armv7的通用寄存器簡介
- 2、寄存器的保存和恢復
- 3、Linux Kernel參考代碼
1、armv7的通用寄存器簡介
ARMV7處理器有40個32位寄存器,包括:通用寄存器32個、狀態寄存器7個(CPSR和SPSR)、程序計數器一個(PC).
ARMV7有7-9種模式, 詳細的寄存器如下圖所示,帶顏色的為該模式下的私有寄存器(或者叫banked寄存器)
2、寄存器的保存和恢復
在進行userspace進程切換時,會對共有寄存器進行保存和回復,具體會保存和恢復哪些寄存器呢,如下圖所示
3、Linux Kernel參考代碼
(linux_5.9/arch/arm/kernel/entry-armv.S)/** Register switch for ARMv3 and ARMv4 processors* r0 = previous task_struct, r1 = previous thread_info, r2 = next thread_info* previous and next are guaranteed not to be the same.*/ ENTRY(__switch_to)UNWIND(.fnstart )UNWIND(.cantunwind )add ip, r1, #TI_CPU_SAVEARM( stmia ip!, {r4 - sl, fp, sp, lr} ) @ Store most regs on stackTHUMB( stmia ip!, {r4 - sl, fp} ) @ Store most regs on stackTHUMB( str sp, [ip], #4 )THUMB( str lr, [ip], #4 )ldr r4, [r2, #TI_TP_VALUE]ldr r5, [r2, #TI_TP_VALUE + 4] #ifdef CONFIG_CPU_USE_DOMAINSmrc p15, 0, r6, c3, c0, 0 @ Get domain registerstr r6, [r1, #TI_CPU_DOMAIN] @ Save old domain registerldr r6, [r2, #TI_CPU_DOMAIN] #endifswitch_tls r1, r4, r5, r3, r7 #if defined(CONFIG_STACKPROTECTOR) && !defined(CONFIG_SMP)ldr r7, [r2, #TI_TASK]ldr r8, =__stack_chk_guard.if (TSK_STACK_CANARY > IMM12_MASK)add r7, r7, #TSK_STACK_CANARY & ~IMM12_MASK.endifldr r7, [r7, #TSK_STACK_CANARY & IMM12_MASK] #endif #ifdef CONFIG_CPU_USE_DOMAINSmcr p15, 0, r6, c3, c0, 0 @ Set domain register #endifmov r5, r0add r4, r2, #TI_CPU_SAVEldr r0, =thread_notify_headmov r1, #THREAD_NOTIFY_SWITCHbl atomic_notifier_call_chain #if defined(CONFIG_STACKPROTECTOR) && !defined(CONFIG_SMP)str r7, [r8] #endifTHUMB( mov ip, r4 )mov r0, r5ARM( ldmia r4, {r4 - sl, fp, sp, pc} ) @ Load all regs saved previouslyTHUMB( ldmia ip!, {r4 - sl, fp} ) @ Load all regs saved previouslyTHUMB( ldr sp, [ip], #4 )THUMB( ldr pc, [ip] )UNWIND(.fnend ) ENDPROC(__switch_to)總結
以上是生活随笔為你收集整理的[architecture]-ARMV7架构下Linux Kernel的Userspace进程切换时保存和恢复哪些寄存器的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: [How TO]-How to Inst
- 下一篇: [architecture]-ARMV7