ARM V7 切换上下文的规范
在ARM
Linux中,在切换用户进程的时候,会切换页目录表。对于V7的Processor,切换的具体的代码是:
41
ENTRY(cpu_v7_switch_mm)
42 #ifdef CONFIG_MMU
43
mov r2, #0
44
ldr r1, [r1,
#MM_CONTEXT_ID] @ get
mm->context.id
45
ALT_SMP(orr r0, r0, #TTB_FLAGS_SMP)
46
ALT_UP(orr r0, r0, #TTB_FLAGS_UP)
47 #ifdef CONFIG_ARM_ERRATA_430973
48
mcr p15, 0, r2, c7, c5,
6 @ flush BTAC/BTB
49 #endif
50 #ifdef CONFIG_ARM_ERRATA_754322
51
dsb
52 #endif
53
mcr p15, 0, r2, c13, c0,
1 @ set reserved context
ID
54
isb @ flush the pipeline
55 1:
mcr p15, 0, r0, c2, c0,
0 @ set TTBR 0
56
isb
57 #ifdef CONFIG_ARM_ERRATA_754322
58
dsb
59 #endif
60
mcr p15, 0, r1, c13, c0,
1 @ set context ID
61
isb
62 #endif
63
mov pc, lr
64 ENDPROC(cpu_v7_switch_mm)
44行,从task_struct中获取要调度进程的contextID
45,46,准备PGD的属性
53~56,写入TTBR0
60行,写入新的contextID.
63行,返回
在这个函数中,有疑问的地方在于53行,为什么要在写入新的TTBR0之前,要先把contextID的register写入0。在ARM
reference中,是这样写的:
Synchronization is necessary to avoid either:
• the old ASID being associated with translation table walks from
the new translation tables
• the new ASID being associated with translation table walks from
the old translation tables.
在ARM的reference中,举了3个可以避免冲突的例子。这三个例子如下:
Change ASID to 0
ISB
Change Translation Table Base Register
ISB
Change ASID to new value
Change Translation Table Base Register
to the global-only mappings
ISB
Change ASID to new value
ISB
Change Translation Table Base Register
to new value
Set TTBCR.PD0 = 1
ISB
Change ASID to new value
Change Translation Table Base Register
to new value
ISB
Set TTBCR.PD0 = 0
评论
发表评论