/* SPDX-License-Identifier: GPL-2.0 */1/*2* uClinux flat-format executables3*4* Copyright (C) 2005 John Williams <[email protected]>5*/67#ifndef _ASM_MICROBLAZE_FLAT_H8#define _ASM_MICROBLAZE_FLAT_H910#include <linux/unaligned.h>1112/*13* Microblaze works a little differently from other arches, because14* of the MICROBLAZE_64 reloc type. Here, a 32 bit address is split15* over two instructions, an 'imm' instruction which provides the top16* 16 bits, then the instruction "proper" which provides the low 1617* bits.18*/1920/*21* Crack open a symbol reference and extract the address to be22* relocated. rp is a potentially unaligned pointer to the23* reference24*/2526static inline int flat_get_addr_from_rp(u32 __user *rp, u32 relval, u32 flags,27u32 *addr)28{29u32 *p = (__force u32 *)rp;3031/* Is it a split 64/32 reference? */32if (relval & 0x80000000) {33/* Grab the two halves of the reference */34u32 val_hi, val_lo;3536val_hi = get_unaligned(p);37val_lo = get_unaligned(p+1);3839/* Crack the address out */40*addr = ((val_hi & 0xffff) << 16) + (val_lo & 0xffff);41} else {42/* Get the address straight out */43*addr = get_unaligned(p);44}4546return 0;47}4849/*50* Insert an address into the symbol reference at rp. rp is potentially51* unaligned.52*/5354static inline int55flat_put_addr_at_rp(u32 __user *rp, u32 addr, u32 relval)56{57u32 *p = (__force u32 *)rp;58/* Is this a split 64/32 reloc? */59if (relval & 0x80000000) {60/* Get the two "halves" */61unsigned long val_hi = get_unaligned(p);62unsigned long val_lo = get_unaligned(p + 1);6364/* insert the address */65val_hi = (val_hi & 0xffff0000) | addr >> 16;66val_lo = (val_lo & 0xffff0000) | (addr & 0xffff);6768/* store the two halves back into memory */69put_unaligned(val_hi, p);70put_unaligned(val_lo, p+1);71} else {72/* Put it straight in, no messing around */73put_unaligned(addr, p);74}75return 0;76}7778#define flat_get_relocate_addr(rel) (rel & 0x7fffffff)7980#endif /* _ASM_MICROBLAZE_FLAT_H */818283