xref: /openbmc/linux/arch/microblaze/include/asm/flat.h (revision b8d312aa)
1 /*
2  * uClinux flat-format executables
3  *
4  * Copyright (C) 2005 John Williams <jwilliams@itee.uq.edu.au>
5  *
6  * This file is subject to the terms and conditions of the GNU General
7  * Public License. See the file COPYING in the main directory of this
8  * archive for more details.
9  */
10 
11 #ifndef _ASM_MICROBLAZE_FLAT_H
12 #define _ASM_MICROBLAZE_FLAT_H
13 
14 #include <asm/unaligned.h>
15 
16 /*
17  * Microblaze works a little differently from other arches, because
18  * of the MICROBLAZE_64 reloc type. Here, a 32 bit address is split
19  * over two instructions, an 'imm' instruction which provides the top
20  * 16 bits, then the instruction "proper" which provides the low 16
21  * bits.
22  */
23 
24 /*
25  * Crack open a symbol reference and extract the address to be
26  * relocated. rp is a potentially unaligned pointer to the
27  * reference
28  */
29 
30 static inline int flat_get_addr_from_rp(u32 __user *rp, u32 relval, u32 flags,
31 					u32 *addr)
32 {
33 	u32 *p = (__force u32 *)rp;
34 
35 	/* Is it a split 64/32 reference? */
36 	if (relval & 0x80000000) {
37 		/* Grab the two halves of the reference */
38 		u32 val_hi, val_lo;
39 
40 		val_hi = get_unaligned(p);
41 		val_lo = get_unaligned(p+1);
42 
43 		/* Crack the address out */
44 		*addr = ((val_hi & 0xffff) << 16) + (val_lo & 0xffff);
45 	} else {
46 		/* Get the address straight out */
47 		*addr = get_unaligned(p);
48 	}
49 
50 	return 0;
51 }
52 
53 /*
54  * Insert an address into the symbol reference at rp. rp is potentially
55  * unaligned.
56  */
57 
58 static inline int
59 flat_put_addr_at_rp(u32 __user *rp, u32 addr, u32 relval)
60 {
61 	u32 *p = (__force u32 *)rp;
62 	/* Is this a split 64/32 reloc? */
63 	if (relval & 0x80000000) {
64 		/* Get the two "halves" */
65 		unsigned long val_hi = get_unaligned(p);
66 		unsigned long val_lo = get_unaligned(p + 1);
67 
68 		/* insert the address */
69 		val_hi = (val_hi & 0xffff0000) | addr >> 16;
70 		val_lo = (val_lo & 0xffff0000) | (addr & 0xffff);
71 
72 		/* store the two halves back into memory */
73 		put_unaligned(val_hi, p);
74 		put_unaligned(val_lo, p+1);
75 	} else {
76 		/* Put it straight in, no messing around */
77 		put_unaligned(addr, p);
78 	}
79 	return 0;
80 }
81 
82 #define	flat_get_relocate_addr(rel)	(rel & 0x7fffffff)
83 
84 #endif /* _ASM_MICROBLAZE_FLAT_H */
85