Apply_r_mips_26_rel() relocates instructions like j, jal and etc. These
instructions consist of 6bits function field and 26bits address field.
The value of target_addr as follows,
=================================================================
| high 4bits | low 28bits |
=================================================================
|the high 4bits of this PC | the low 26bits of instructions << 2|
=================================================================
Thus, loc_orig and log_new both need high 4bits ranther than high 6bits.
Replace 0x3ffffff with 0xfffffff.
Signed-off-by: Jinyang He <[email protected]>
---
arch/mips/kernel/relocate.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/mips/kernel/relocate.c b/arch/mips/kernel/relocate.c
index 3d80a51..709cfa0 100644
--- a/arch/mips/kernel/relocate.c
+++ b/arch/mips/kernel/relocate.c
@@ -95,7 +95,7 @@ static int __init apply_r_mips_26_rel(u32 *loc_orig, u32 *loc_new, long offset)
/* Original target address */
target_addr <<= 2;
- target_addr += (unsigned long)loc_orig & ~0x03ffffff;
+ target_addr += (unsigned long)loc_orig & ~0x0fffffff;
/* Get the new target address */
target_addr += offset;
@@ -105,7 +105,7 @@ static int __init apply_r_mips_26_rel(u32 *loc_orig, u32 *loc_new, long offset)
return -ENOEXEC;
}
- target_addr -= (unsigned long)loc_new & ~0x03ffffff;
+ target_addr -= (unsigned long)loc_new & ~0x0fffffff;
target_addr >>= 2;
*loc_new = (*loc_new & ~0x03ffffff) | (target_addr & 0x03ffffff);
--
2.1.0
On Thu, Nov 19, 2020 at 10:29:12AM +0800, Jinyang He wrote:
> Apply_r_mips_26_rel() relocates instructions like j, jal and etc. These
> instructions consist of 6bits function field and 26bits address field.
> The value of target_addr as follows,
> =================================================================
> | high 4bits | low 28bits |
> =================================================================
> |the high 4bits of this PC | the low 26bits of instructions << 2|
> =================================================================
> Thus, loc_orig and log_new both need high 4bits ranther than high 6bits.
rather
> Replace 0x3ffffff with 0xfffffff.
>
> Signed-off-by: Jinyang He <[email protected]>
> ---
> arch/mips/kernel/relocate.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/arch/mips/kernel/relocate.c b/arch/mips/kernel/relocate.c
> index 3d80a51..709cfa0 100644
> --- a/arch/mips/kernel/relocate.c
> +++ b/arch/mips/kernel/relocate.c
> @@ -95,7 +95,7 @@ static int __init apply_r_mips_26_rel(u32 *loc_orig, u32 *loc_new, long offset)
>
> /* Original target address */
> target_addr <<= 2;
> - target_addr += (unsigned long)loc_orig & ~0x03ffffff;
> + target_addr += (unsigned long)loc_orig & ~0x0fffffff;
how about using
target_addr += (unsigned long)log_orig & 0xf0000000;
which makes it IMHO even clearer what this does ?
Thomas.
--
Crap can work. Given enough thrust pigs will fly, but it's not necessarily a
good idea. [ RFC1925, 2.3 ]
Hi,
On 11/19/2020 08:36 PM, Thomas Bogendoerfer wrote:
> On Thu, Nov 19, 2020 at 10:29:12AM +0800, Jinyang He wrote:
>> Apply_r_mips_26_rel() relocates instructions like j, jal and etc. These
>> instructions consist of 6bits function field and 26bits address field.
>> The value of target_addr as follows,
>> =================================================================
>> | high 4bits | low 28bits |
>> =================================================================
>> |the high 4bits of this PC | the low 26bits of instructions << 2|
>> =================================================================
>> Thus, loc_orig and log_new both need high 4bits ranther than high 6bits.
> rather
>
>> Replace 0x3ffffff with 0xfffffff.
>>
>> Signed-off-by: Jinyang He <[email protected]>
>> ---
>> arch/mips/kernel/relocate.c | 4 ++--
>> 1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/arch/mips/kernel/relocate.c b/arch/mips/kernel/relocate.c
>> index 3d80a51..709cfa0 100644
>> --- a/arch/mips/kernel/relocate.c
>> +++ b/arch/mips/kernel/relocate.c
>> @@ -95,7 +95,7 @@ static int __init apply_r_mips_26_rel(u32 *loc_orig, u32 *loc_new, long offset)
>>
>> /* Original target address */
>> target_addr <<= 2;
>> - target_addr += (unsigned long)loc_orig & ~0x03ffffff;
>> + target_addr += (unsigned long)loc_orig & ~0x0fffffff;
> how about using
>
> target_addr += (unsigned long)log_orig & 0xf0000000;
>
> which makes it IMHO even clearer what this does ?
That sounds good. I'll send v2 later.
Thanks,
Jinyang.
> Thomas.
>