1 /* ----------------------------------------------------------------------- *
3 * Copyright 2007-2008 H. Peter Anvin - All Rights Reserved
4 * Copyright 2009-2011 Intel Corporation; author: H. Peter Anvin
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, Inc., 53 Temple Place Ste 330,
9 * Boston MA 02111-1307, USA; either version 2 of the License, or
10 * (at your option) any later version; incorporated herein by reference.
12 * ----------------------------------------------------------------------- */
19 #if defined(__386__) || defined(__i386__) || defined(__x86_64__)
20 # define X86_MEM 1 /* Littleendian and unaligned safe */
26 * Access functions for littleendian numbers, possibly misaligned.
28 static inline uint8_t get_8(const uint8_t * p
)
33 static inline uint16_t get_16(const uint16_t * p
)
36 /* Littleendian and unaligned-capable */
39 const uint8_t *pp
= (const uint8_t *)p
;
40 return pp
[0] + ((uint16_t)pp
[1] << 8);
44 static inline uint32_t get_32(const uint32_t * p
)
47 /* Littleendian and unaligned-capable */
50 const uint16_t *pp
= (const uint16_t *)p
;
51 return get_16(pp
[0]) + (uint32_t)get_16(pp
[1]);
55 static inline uint64_t get_64(const uint64_t * p
)
58 /* Littleendian and unaligned-capable */
61 const uint32_t *pp
= (const uint32_t *)p
;
62 return get_32(pp
[0]) + (uint64_t)get_32(pp
[1]);
66 static inline void set_8(uint8_t *p
, uint8_t v
)
71 static inline void set_16(uint16_t *p
, uint16_t v
)
74 /* Littleendian and unaligned-capable */
77 uint8_t *pp
= (uint8_t *) p
;
79 pp
[1] = ((v
>> 8) & 0xff);
83 static inline void set_32(uint32_t *p
, uint32_t v
)
86 /* Littleendian and unaligned-capable */
89 uint8_t *pp
= (uint8_t *) p
;
91 pp
[1] = ((v
>> 8) & 0xff);
92 pp
[2] = ((v
>> 16) & 0xff);
93 pp
[3] = ((v
>> 24) & 0xff);
97 static inline void set_64(uint64_t *p
, uint64_t v
)
100 /* Littleendian and unaligned-capable */
103 uint32_t *pp
= (uint32_t *) p
;
105 set_32(pp
[1], v
>> 32);
110 * Special handling for the MS-DOS derivative: syslinux_ldlinux
111 * is a "far" object...
115 static inline __attribute__ ((const))
119 asm("movw %%ds,%0":"=rm"(v
));
123 static inline void *set_fs(const void *p
)
127 seg
= ds() + ((size_t) p
>> 4);
128 asm volatile ("movw %0,%%fs"::"rm" (seg
));
129 return (void *)((size_t) p
& 0xf);
132 uint8_t get_8_sl(const uint8_t * p
);
133 uint16_t get_16_sl(const uint16_t * p
);
134 uint32_t get_32_sl(const uint32_t * p
);
135 uint64_t get_64_sl(const uint64_t * p
);
136 void set_8_sl(uint8_t * p
, uint8_t v
);
137 void set_16_sl(uint16_t * p
, uint16_t v
);
138 void set_32_sl(uint32_t * p
, uint32_t v
);
139 void set_64_sl(uint64_t * p
, uint64_t v
);
140 void memcpy_to_sl(void *dst
, const void *src
, size_t len
);
141 void memcpy_from_sl(void *dst
, const void *src
, size_t len
);
145 /* Sane system ... */
146 #define get_8_sl(x) get_8(x)
147 #define get_16_sl(x) get_16(x)
148 #define get_32_sl(x) get_32(x)
149 #define get_64_sl(x) get_64(x)
150 #define set_8_sl(x,y) set_8(x,y)
151 #define set_16_sl(x,y) set_16(x,y)
152 #define set_32_sl(x,y) set_32(x,y)
153 #define set_64_sl(x,y) set_64(x,y)
154 #define memcpy_to_sl(d,s,l) memcpy(d,s,l)
155 #define memcpy_from_sl(d,s,l) memcpy(d,s,l)
159 #define LDLINUX_MAGIC 0x3eb202fe
160 #define BS_MAGIC_VER (0x1b << 9)
162 /* Patch area for disk-based installers */
164 uint32_t magic
; /* LDLINUX_MAGIC */
165 uint32_t instance
; /* Per-version value */
166 uint16_t data_sectors
;
167 uint16_t adv_sectors
;
170 uint16_t maxtransfer
;
171 uint16_t epaoffset
; /* Pointer to the extended patch area */
174 struct ext_patch_area
{
175 uint16_t advptroffset
; /* ADV pointers */
176 uint16_t diroffset
; /* Current directory field */
177 uint16_t dirlen
; /* Length of current directory field */
178 uint16_t subvoloffset
; /* Subvolume field */
179 uint16_t subvollen
; /* Length of subvolume field */
180 uint16_t secptroffset
; /* Sector extent pointers */
181 uint16_t secptrcnt
; /* Number of sector extent pointers */
183 uint16_t sect1ptr0
; /* Boot sector offset of sector 1 ptr LSW */
184 uint16_t sect1ptr1
; /* Boot sector offset of sector 1 ptr MSW */
185 uint16_t raidpatch
; /* Boot sector RAID mode patch pointer */
189 struct syslinux_extent
{
192 } __attribute__((packed
));
194 /* FAT bootsector format, also used by other disk-based derivatives */
198 uint16_t bsBytesPerSec
;
199 uint8_t bsSecPerClust
;
200 uint16_t bsResSectors
;
202 uint16_t bsRootDirEnts
;
206 uint16_t bsSecPerTrack
;
208 uint32_t bsHiddenSecs
;
209 uint32_t bsHugeSectors
;
215 uint8_t BootSignature
;
217 char VolumeLabel
[11];
220 } __attribute__ ((packed
)) bs16
;
228 uint8_t Reserved0
[12];
231 uint8_t BootSignature
;
233 char VolumeLabel
[11];
236 } __attribute__ ((packed
)) bs32
;
237 } __attribute__ ((packed
));
240 uint16_t bsForwardPtr
;
241 uint16_t bsSignature
;
242 } __attribute__ ((packed
));
244 #define bsHead bsJump
245 #define bsHeadLen offsetof(struct boot_sector, bsBytesPerSec)
246 #define bsCode bs32.Code /* The common safe choice */
247 #define bsCodeLen (offsetof(struct boot_sector, bsSignature) - \
248 offsetof(struct boot_sector, bsCode))
250 #endif /* SYSLXINT_H */