1 /* ----------------------------------------------------------------------- *
3 * Copyright 2007-2008 H. Peter Anvin - All Rights Reserved
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, Inc., 53 Temple Place Ste 330,
8 * Boston MA 02111-1307, USA; either version 2 of the License, or
9 * (at your option) any later version; incorporated herein by reference.
11 * ----------------------------------------------------------------------- */
18 #if defined(__386__) || defined(__i386__) || defined(__x86_64__)
19 # define X86_MEM 1 /* Littleendian and unaligned safe */
25 * Access functions for littleendian numbers, possibly misaligned.
27 static inline uint8_t get_8(const uint8_t * p)
32 static inline uint16_t get_16(const uint16_t * p)
35 /* Littleendian and unaligned-capable */
38 const uint8_t *pp = (const uint8_t *)p;
39 return pp[0] + ((uint16_t)pp[1] << 8);
43 static inline uint32_t get_32(const uint32_t * p)
46 /* Littleendian and unaligned-capable */
49 const uint16_t *pp = (const uint16_t *)p;
50 return get_16(pp[0]) + (uint32_t)get_16(pp[1]);
54 static inline uint64_t get_64(const uint64_t * p)
57 /* Littleendian and unaligned-capable */
60 const uint32_t *pp = (const uint32_t *)p;
61 return get_32(pp[0]) + (uint64_t)get_32(pp[1]);
65 static inline void set_8(uint8_t *p, uint8_t v)
70 static inline void set_16(uint16_t *p, uint16_t v)
73 /* Littleendian and unaligned-capable */
76 uint8_t *pp = (uint8_t *) p;
78 pp[1] = ((v >> 8) & 0xff);
82 static inline void set_32(uint32_t *p, uint32_t v)
85 /* Littleendian and unaligned-capable */
88 uint8_t *pp = (uint8_t *) p;
90 pp[1] = ((v >> 8) & 0xff);
91 pp[2] = ((v >> 16) & 0xff);
92 pp[3] = ((v >> 24) & 0xff);
96 static inline void set_64(uint64_t *p, uint64_t v)
99 /* Littleendian and unaligned-capable */
102 uint32_t *pp = (uint32_t *) p;
104 set_32(pp[1], v >> 32);
109 * Special handling for the MS-DOS derivative: syslinux_ldlinux
110 * is a "far" object...
114 extern uint16_t ldlinux_seg; /* Defined in dos/syslinux.c */
116 static inline __attribute__ ((const))
120 asm("movw %%ds,%0":"=rm"(v));
124 static inline void *set_fs(const void *p)
128 seg = ldlinux_seg + ((size_t) p >> 4);
129 asm volatile ("movw %0,%%fs"::"rm" (seg));
130 return (void *)((size_t) p & 0xf);
133 uint8_t get_8_sl(const uint8_t * p);
134 uint16_t get_16_sl(const uint16_t * p);
135 uint32_t get_32_sl(const uint32_t * p);
136 uint64_t get_64_sl(const uint64_t * p);
137 void set_8_sl(uint8_t * p, uint8_t v);
138 void set_16_sl(uint16_t * p, uint16_t v);
139 void set_32_sl(uint32_t * p, uint32_t v);
140 void set_64_sl(uint64_t * p, uint64_t v);
141 void memcpy_to_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)
158 #define LDLINUX_MAGIC 0x3eb202fe
160 /* Patch area for disk-based installers */
162 uint32_t magic; /* LDLINUX_MAGIC */
163 uint32_t instance; /* Per-version value */
164 uint16_t data_sectors;
165 uint16_t adv_sectors;
168 uint16_t maxtransfer;
169 uint16_t epaoffset; /* Pointer to the extended patch area */
172 struct ext_patch_area {
173 uint16_t advptroffset; /* ADV pointers */
174 uint16_t diroffset; /* Current directory field */
175 uint16_t dirlen; /* Length of current directory field */
176 uint16_t subvoloffset; /* Subvolume field */
177 uint16_t subvollen; /* Length of subvolume field */
178 uint16_t secptroffset; /* Sector extent pointers */
179 uint16_t secptrcnt; /* Number of sector extent pointers */
181 uint16_t sect1ptr0; /* Boot sector offset of sector 1 ptr LSW */
182 uint16_t sect1ptr1; /* Boot sector offset of sector 1 ptr MSW */
183 uint16_t raidpatch; /* Boot sector RAID mode patch pointer */
187 struct syslinux_extent {
190 } __attribute__((packed));
192 /* FAT bootsector format, also used by other disk-based derivatives */
196 uint16_t bsBytesPerSec;
197 uint8_t bsSecPerClust;
198 uint16_t bsResSectors;
200 uint16_t bsRootDirEnts;
204 uint16_t bsSecPerTrack;
206 uint32_t bsHiddenSecs;
207 uint32_t bsHugeSectors;
213 uint8_t BootSignature;
215 char VolumeLabel[11];
218 } __attribute__ ((packed)) bs16;
226 uint8_t Reserved0[12];
229 uint8_t BootSignature;
231 char VolumeLabel[11];
234 } __attribute__ ((packed)) bs32;
235 } __attribute__ ((packed));
237 uint16_t bsSignature;
238 } __attribute__ ((packed));
240 #define bsHead bsJump
241 #define bsHeadLen offsetof(struct boot_sector, bsBytesPerSec)
242 #define bsCode bs32.Code /* The common safe choice */
243 #define bsCodeLen (offsetof(struct boot_sector, bsSignature) - \
244 offsetof(struct boot_sector, bsCode))
246 #endif /* SYSLXINT_H */