mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-07-23 15:27:29 +00:00
powerpc: Use a function for reading instructions
Prefixed instructions will mean there are instructions of different length. As a result dereferencing a pointer to an instruction will not necessarily give the desired result. Introduce a function for reading instructions from memory into the instruction data type. Signed-off-by: Jordan Niethe <jniethe5@gmail.com> Signed-off-by: Michael Ellerman <mpe@ellerman.id.au> Reviewed-by: Alistair Popple <alistair@popple.id.au> Link: https://lore.kernel.org/r/20200506034050.24806-13-jniethe5@gmail.com
This commit is contained in:
parent
94afd069d9
commit
f8faaffaa7
9 changed files with 33 additions and 26 deletions
|
@ -348,9 +348,9 @@ static unsigned long branch_bform_target(const struct ppc_inst *instr)
|
|||
|
||||
unsigned long branch_target(const struct ppc_inst *instr)
|
||||
{
|
||||
if (instr_is_branch_iform(*instr))
|
||||
if (instr_is_branch_iform(ppc_inst_read(instr)))
|
||||
return branch_iform_target(instr);
|
||||
else if (instr_is_branch_bform(*instr))
|
||||
else if (instr_is_branch_bform(ppc_inst_read(instr)))
|
||||
return branch_bform_target(instr);
|
||||
|
||||
return 0;
|
||||
|
@ -358,7 +358,8 @@ unsigned long branch_target(const struct ppc_inst *instr)
|
|||
|
||||
int instr_is_branch_to_addr(const struct ppc_inst *instr, unsigned long addr)
|
||||
{
|
||||
if (instr_is_branch_iform(*instr) || instr_is_branch_bform(*instr))
|
||||
if (instr_is_branch_iform(ppc_inst_read(instr)) ||
|
||||
instr_is_branch_bform(ppc_inst_read(instr)))
|
||||
return branch_target(instr) == addr;
|
||||
|
||||
return 0;
|
||||
|
@ -368,13 +369,14 @@ int translate_branch(struct ppc_inst *instr, const struct ppc_inst *dest,
|
|||
const struct ppc_inst *src)
|
||||
{
|
||||
unsigned long target;
|
||||
|
||||
target = branch_target(src);
|
||||
|
||||
if (instr_is_branch_iform(*src))
|
||||
return create_branch(instr, dest, target, ppc_inst_val(*src));
|
||||
else if (instr_is_branch_bform(*src))
|
||||
return create_cond_branch(instr, dest, target, ppc_inst_val(*src));
|
||||
if (instr_is_branch_iform(ppc_inst_read(src)))
|
||||
return create_branch(instr, dest, target,
|
||||
ppc_inst_val(ppc_inst_read(src)));
|
||||
else if (instr_is_branch_bform(ppc_inst_read(src)))
|
||||
return create_cond_branch(instr, dest, target,
|
||||
ppc_inst_val(ppc_inst_read(src)));
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -598,7 +600,7 @@ static void __init test_translate_branch(void)
|
|||
patch_instruction(q, instr);
|
||||
check(instr_is_branch_to_addr(p, addr));
|
||||
check(instr_is_branch_to_addr(q, addr));
|
||||
check(ppc_inst_equal(*q, ppc_inst(0x4a000000)));
|
||||
check(ppc_inst_equal(ppc_inst_read(q), ppc_inst(0x4a000000)));
|
||||
|
||||
/* Maximum positive case, move x to x - 32 MB + 4 */
|
||||
p = buf + 0x2000000;
|
||||
|
@ -609,7 +611,7 @@ static void __init test_translate_branch(void)
|
|||
patch_instruction(q, instr);
|
||||
check(instr_is_branch_to_addr(p, addr));
|
||||
check(instr_is_branch_to_addr(q, addr));
|
||||
check(ppc_inst_equal(*q, ppc_inst(0x49fffffc)));
|
||||
check(ppc_inst_equal(ppc_inst_read(q), ppc_inst(0x49fffffc)));
|
||||
|
||||
/* Jump to x + 16 MB moved to x + 20 MB */
|
||||
p = buf;
|
||||
|
@ -655,7 +657,7 @@ static void __init test_translate_branch(void)
|
|||
patch_instruction(q, instr);
|
||||
check(instr_is_branch_to_addr(p, addr));
|
||||
check(instr_is_branch_to_addr(q, addr));
|
||||
check(ppc_inst_equal(*q, ppc_inst(0x43ff8000)));
|
||||
check(ppc_inst_equal(ppc_inst_read(q), ppc_inst(0x43ff8000)));
|
||||
|
||||
/* Maximum positive case, move x to x - 32 KB + 4 */
|
||||
p = buf + 0x8000;
|
||||
|
@ -667,7 +669,7 @@ static void __init test_translate_branch(void)
|
|||
patch_instruction(q, instr);
|
||||
check(instr_is_branch_to_addr(p, addr));
|
||||
check(instr_is_branch_to_addr(q, addr));
|
||||
check(ppc_inst_equal(*q, ppc_inst(0x43ff7ffc)));
|
||||
check(ppc_inst_equal(ppc_inst_read(q), ppc_inst(0x43ff7ffc)));
|
||||
|
||||
/* Jump to x + 12 KB moved to x + 20 KB */
|
||||
p = buf;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue