Commit 9b1a735d authored by Michael Ellerman's avatar Michael Ellerman Committed by Paul Mackerras

powerpc: Add logic to patch alternative feature sections

This commit adds the logic to patch alternative sections.  This is fairly
straightforward, except for branches.  Relative branches that jump from
inside the else section to outside of it need to be translated as they're
moved, otherwise they will jump to the wrong location.
Signed-off-by: default avatarMichael Ellerman <michael@ellerman.id.au>
Signed-off-by: default avatarPaul Mackerras <paulus@samba.org>
parent fac23fe4
...@@ -26,24 +26,66 @@ struct fixup_entry { ...@@ -26,24 +26,66 @@ struct fixup_entry {
long alt_end_off; long alt_end_off;
}; };
static void patch_feature_section(unsigned long value, struct fixup_entry *fcur) static unsigned int *calc_addr(struct fixup_entry *fcur, long offset)
{ {
unsigned int *pstart, *pend, *p; /*
* We store the offset to the code as a negative offset from
* the start of the alt_entry, to support the VDSO. This
* routine converts that back into an actual address.
*/
return (unsigned int *)((unsigned long)fcur + offset);
}
static int patch_alt_instruction(unsigned int *src, unsigned int *dest,
unsigned int *alt_start, unsigned int *alt_end)
{
unsigned int instr;
instr = *src;
if (instr_is_relative_branch(*src)) {
unsigned int *target = (unsigned int *)branch_target(src);
/* Branch within the section doesn't need translating */
if (target < alt_start || target >= alt_end) {
instr = translate_branch(dest, src);
if (!instr)
return 1;
}
}
patch_instruction(dest, instr);
return 0;
}
static int patch_feature_section(unsigned long value, struct fixup_entry *fcur)
{
unsigned int *start, *end, *alt_start, *alt_end, *src, *dest;
start = calc_addr(fcur, fcur->start_off);
end = calc_addr(fcur, fcur->end_off);
alt_start = calc_addr(fcur, fcur->alt_start_off);
alt_end = calc_addr(fcur, fcur->alt_end_off);
if ((alt_end - alt_start) > (end - start))
return 1;
if ((value & fcur->mask) == fcur->value) if ((value & fcur->mask) == fcur->value)
return; return 0;
pstart = ((unsigned int *)fcur) + (fcur->start_off / 4); src = alt_start;
pend = ((unsigned int *)fcur) + (fcur->end_off / 4); dest = start;
for (p = pstart; p < pend; p++) { for (; src < alt_end; src++, dest++) {
*p = PPC_NOP_INSTR; if (patch_alt_instruction(src, dest, alt_start, alt_end))
asm volatile ("dcbst 0, %0" : : "r" (p)); return 1;
} }
asm volatile ("sync" : : : "memory");
for (p = pstart; p < pend; p++) for (; dest < end; dest++)
asm volatile ("icbi 0,%0" : : "r" (p)); patch_instruction(dest, PPC_NOP_INSTR);
asm volatile ("sync; isync" : : : "memory");
return 0;
} }
void do_feature_fixups(unsigned long value, void *fixup_start, void *fixup_end) void do_feature_fixups(unsigned long value, void *fixup_start, void *fixup_end)
...@@ -53,6 +95,15 @@ void do_feature_fixups(unsigned long value, void *fixup_start, void *fixup_end) ...@@ -53,6 +95,15 @@ void do_feature_fixups(unsigned long value, void *fixup_start, void *fixup_end)
fcur = fixup_start; fcur = fixup_start;
fend = fixup_end; fend = fixup_end;
for (; fcur < fend; fcur++) for (; fcur < fend; fcur++) {
patch_feature_section(value, fcur); if (patch_feature_section(value, fcur)) {
__WARN();
printk("Unable to patch feature section at %p - %p" \
" with %p - %p\n",
calc_addr(fcur, fcur->start_off),
calc_addr(fcur, fcur->end_off),
calc_addr(fcur, fcur->alt_start_off),
calc_addr(fcur, fcur->alt_end_off));
}
}
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment