2 * include/asm-v850/flat.h -- uClinux flat-format executables
4 * Copyright (C) 2002,03 NEC Electronics Corporation
5 * Copyright (C) 2002,03 Miles Bader <miles@gnu.org>
7 * This file is subject to the terms and conditions of the GNU General
8 * Public License. See the file COPYING in the main directory of this
9 * archive for more details.
11 * Written by Miles Bader <miles@gnu.org>
14 #ifndef __V850_FLAT_H__
15 #define __V850_FLAT_H__
17 /* The amount by which a relocation can exceed the program image limits
18 without being regarded as an error. On the v850, the relocations of
19 some base-pointers can be offset by 0x8000 (to allow better usage of the
20 space offered by 16-bit signed offsets -- in most cases the offsets used
21 with such a base-pointer will be negative). */
23 #define flat_reloc_valid(reloc, size) ((reloc) <= (size + 0x8000))
25 #define flat_stack_align(sp) /* nothing needed */
26 #define flat_argvp_envp_on_stack() 0
27 #define flat_old_ram_flag(flags) (flags)
29 /* We store the type of relocation in the top 4 bits of the `relval.' */
31 /* Convert a relocation entry into an address. */
32 static inline unsigned long
33 flat_get_relocate_addr (unsigned long relval)
35 return relval & 0x0fffffff; /* Mask out top 4-bits */
38 #define flat_v850_get_reloc_type(relval) ((relval) >> 28)
40 #define FLAT_V850_R_32 0 /* Normal 32-bit reloc */
41 #define FLAT_V850_R_HI16S_LO15 1 /* High 16-bits + signed 15-bit low field */
42 #define FLAT_V850_R_HI16S_LO16 2 /* High 16-bits + signed 16-bit low field */
44 /* Extract the address to be relocated from the symbol reference at RP;
45 RELVAL is the raw relocation-table entry from which RP is derived.
46 For the v850, RP should always be half-word aligned. */
47 static inline unsigned long flat_get_addr_from_rp (unsigned long *rp,
50 short *srp = (short *)rp;
52 switch (flat_v850_get_reloc_type (relval))
55 /* Simple 32-bit address. */
56 return srp[0] | (srp[1] << 16);
58 case FLAT_V850_R_HI16S_LO16:
59 /* The high and low halves of the address are in the 16
60 bits at RP, and the 2nd word of the 32-bit instruction
61 following that, respectively. The low half is _signed_
62 so we have to sign-extend it and add it to the upper
63 half instead of simply or-ing them together.
65 Unlike most relocated address, this one is stored in
66 native (little-endian) byte-order to avoid problems with
67 trashing the low-order bit, so we have to convert to
68 network-byte-order before returning, as that's what the
70 return htonl ((srp[0] << 16) + srp[2]);
72 case FLAT_V850_R_HI16S_LO15:
73 /* The high and low halves of the address are in the 16
74 bits at RP, and the upper 15 bits of the 2nd word of the
75 32-bit instruction following that, respectively. The
76 low half is _signed_ so we have to sign-extend it and
77 add it to the upper half instead of simply or-ing them
78 together. The lowest bit is always zero.
80 Unlike most relocated address, this one is stored in
81 native (little-endian) byte-order to avoid problems with
82 trashing the low-order bit, so we have to convert to
83 network-byte-order before returning, as that's what the
85 return htonl ((srp[0] << 16) + (srp[2] & ~0x1));
88 return ~0; /* bogus value */
92 /* Insert the address ADDR into the symbol reference at RP;
93 RELVAL is the raw relocation-table entry from which RP is derived.
94 For the v850, RP should always be half-word aligned. */
95 static inline void flat_put_addr_at_rp (unsigned long *rp, unsigned long addr,
98 short *srp = (short *)rp;
100 switch (flat_v850_get_reloc_type (relval)) {
102 /* Simple 32-bit address. */
103 srp[0] = addr & 0xFFFF;
104 srp[1] = (addr >> 16);
107 case FLAT_V850_R_HI16S_LO16:
108 /* The high and low halves of the address are in the 16
109 bits at RP, and the 2nd word of the 32-bit instruction
110 following that, respectively. The low half is _signed_
111 so we must carry its sign bit to the upper half before
112 writing the upper half. */
113 srp[0] = (addr >> 16) + ((addr >> 15) & 0x1);
114 srp[2] = addr & 0xFFFF;
117 case FLAT_V850_R_HI16S_LO15:
118 /* The high and low halves of the address are in the 16
119 bits at RP, and the upper 15 bits of the 2nd word of the
120 32-bit instruction following that, respectively. The
121 low half is _signed_ so we must carry its sign bit to
122 the upper half before writing the upper half. The
123 lowest bit we preserve from the existing instruction. */
124 srp[0] = (addr >> 16) + ((addr >> 15) & 0x1);
125 srp[2] = (addr & 0xFFFE) | (srp[2] & 0x1);
130 #endif /* __V850_FLAT_H__ */