Skip to content

Commit b511d75

Browse files
Nicolas PitreRussell King
authored andcommitted
ARM: 6747/1: P2V: Thumb2 support
Adding Thumb2 support to the runtime patching of the virt_to_phys and phys_to_virt opcodes. Tested both the 8-bit and the 16-bit fixups, using different placements in memory to exercize all code paths. Signed-off-by: Nicolas Pitre <nicolas.pitre@linaro.org> Reviewed-by: Dave Martin <dave.martin@linaro.org> Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
1 parent 80f0aad commit b511d75

2 files changed

Lines changed: 50 additions & 3 deletions

File tree

‎arch/arm/Kconfig‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,13 @@ config VECTORS_BASE
194194
config ARM_PATCH_PHYS_VIRT
195195
bool "Patch physical to virtual translations at runtime (EXPERIMENTAL)"
196196
depends on EXPERIMENTAL
197-
depends on !XIP_KERNEL && !THUMB2_KERNEL && MMU
197+
depends on !XIP_KERNEL && MMU
198198
depends on !ARCH_REALVIEW || !SPARSEMEM
199199
help
200200
Patch phys-to-virt translation functions at runtime according to
201201
the position of the kernel in system memory.
202202

203-
This can only be used with non-XIP, non-Thumb2, MMU kernels where
203+
This can only be used with non-XIP with MMU kernels where
204204
the base of physical memory is at a 16MB boundary.
205205

206206
config ARM_PATCH_PHYS_VIRT_16BIT

‎arch/arm/kernel/head.S‎

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -461,14 +461,16 @@ __fixup_pv_table:
461461
sub r3, r0, r3 @ PHYS_OFFSET - PAGE_OFFSET
462462
add r4, r4, r3 @ adjust table start address
463463
add r5, r5, r3 @ adjust table end address
464-
str r8, [r7, r3]! @ save computed PHYS_OFFSET to __pv_phys_offset
464+
add r7, r7, r3 @ adjust __pv_phys_offset address
465+
str r8, [r7] @ save computed PHYS_OFFSET to __pv_phys_offset
465466
#ifndef CONFIG_ARM_PATCH_PHYS_VIRT_16BIT
466467
mov r6, r3, lsr #24 @ constant for add/sub instructions
467468
teq r3, r6, lsl #24 @ must be 16MiB aligned
468469
#else
469470
mov r6, r3, lsr #16 @ constant for add/sub instructions
470471
teq r3, r6, lsl #16 @ must be 64kiB aligned
471472
#endif
473+
THUMB( it ne @ cross section branch )
472474
bne __error
473475
str r6, [r7, #4] @ save to __pv_offset
474476
b __fixup_a_pv_table
@@ -482,6 +484,50 @@ ENDPROC(__fixup_pv_table)
482484

483485
.text
484486
__fixup_a_pv_table:
487+
#ifdef CONFIG_THUMB2_KERNEL
488+
#ifdef CONFIG_ARM_PATCH_PHYS_VIRT_16BIT
489+
lsls r0, r6, #24
490+
lsr r6, #8
491+
beq 1f
492+
clz r7, r0
493+
lsr r0, #24
494+
lsl r0, r7
495+
bic r0, 0x0080
496+
lsrs r7, #1
497+
orrcs r0, #0x0080
498+
orr r0, r0, r7, lsl #12
499+
#endif
500+
1: lsls r6, #24
501+
beq 4f
502+
clz r7, r6
503+
lsr r6, #24
504+
lsl r6, r7
505+
bic r6, #0x0080
506+
lsrs r7, #1
507+
orrcs r6, #0x0080
508+
orr r6, r6, r7, lsl #12
509+
orr r6, #0x4000
510+
b 4f
511+
2: @ at this point the C flag is always clear
512+
add r7, r3
513+
#ifdef CONFIG_ARM_PATCH_PHYS_VIRT_16BIT
514+
ldrh ip, [r7]
515+
tst ip, 0x0400 @ the i bit tells us LS or MS byte
516+
beq 3f
517+
cmp r0, #0 @ set C flag, and ...
518+
biceq ip, 0x0400 @ immediate zero value has a special encoding
519+
streqh ip, [r7] @ that requires the i bit cleared
520+
#endif
521+
3: ldrh ip, [r7, #2]
522+
and ip, 0x8f00
523+
orrcc ip, r6 @ mask in offset bits 31-24
524+
orrcs ip, r0 @ mask in offset bits 23-16
525+
strh ip, [r7, #2]
526+
4: cmp r4, r5
527+
ldrcc r7, [r4], #4 @ use branch for delay slot
528+
bcc 2b
529+
bx lr
530+
#else
485531
#ifdef CONFIG_ARM_PATCH_PHYS_VIRT_16BIT
486532
and r0, r6, #255 @ offset bits 23-16
487533
mov r6, r6, lsr #8 @ offset bits 31-24
@@ -499,6 +545,7 @@ __fixup_a_pv_table:
499545
ldrcc r7, [r4], #4 @ use branch for delay slot
500546
bcc 2b
501547
mov pc, lr
548+
#endif
502549
ENDPROC(__fixup_a_pv_table)
503550

504551
ENTRY(fixup_pv_table)

0 commit comments

Comments
 (0)