2 * Special handling for the MS-DOS derivative: syslinux_ldlinux
6 #define _XOPEN_SOURCE 500 /* Required on glibc 2.x */
8 /* glibc 2.20 deprecates _BSD_SOURCE in favour of _DEFAULT_SOURCE */
9 #define _DEFAULT_SOURCE 1
18 static inline void *set_fs_sl(const void *p
)
22 seg
= ds() + ((size_t) p
>> 4);
24 return (void *)((size_t) p
& 0xf);
28 uint8_t get_8_sl(const uint8_t * p
)
33 asm volatile("movb %%fs:%1,%0":"=q" (v
):"m"(*p
));
38 uint16_t get_16_sl(const uint16_t * p
)
43 asm volatile("movw %%fs:%1,%0":"=r" (v
):"m"(*p
));
47 uint32_t get_32_sl(const uint32_t * p
)
52 asm volatile("movl %%fs:%1,%0":"=r" (v
):"m"(*p
));
57 uint64_t get_64_sl(const uint64_t * p
)
60 const uint32_t *pp
= (const uint32_t *)set_fs_sl(p
);
62 asm volatile("movl %%fs:%1,%0" : "=r" (v0
) : "m" (pp
[0]));
63 asm volatile("movl %%fs:%1,%0" : "=r" (v1
) : "m" (pp
[1]));
64 return v0
+ ((uint64_t)v1
<< 32);
69 void set_8_sl(uint8_t * p
, uint8_t v
)
72 asm volatile("movb %1,%%fs:%0":"=m" (*p
):"qi"(v
));
76 void set_16_sl(uint16_t * p
, uint16_t v
)
79 asm volatile("movw %1,%%fs:%0":"=m" (*p
):"ri"(v
));
82 void set_32_sl(uint32_t * p
, uint32_t v
)
85 asm volatile("movl %1,%%fs:%0":"=m" (*p
):"ri"(v
));
88 void set_64_sl(uint64_t * p
, uint64_t v
)
90 uint32_t *pp
= (uint32_t *)set_fs_sl(p
);
91 asm volatile("movl %1,%%fs:%0" : "=m" (pp
[0]) : "ri"((uint32_t)v
));
92 asm volatile("movl %1,%%fs:%0" : "=m" (pp
[1]) : "ri"((uint32_t)(v
>> 32)));
95 void memcpy_to_sl(void *dst
, const void *src
, size_t len
)
100 seg
= ds() + ((size_t)dst
>> 4);
101 off
= (size_t)dst
& 15;
103 asm volatile("pushw %%es ; "
107 : "+D" (off
), "+S" (src
), "+c" (len
)
112 void memcpy_from_sl(void *dst
, const void *src
, size_t len
)
117 seg
= ds() + ((size_t)src
>> 4);
118 off
= (size_t)src
& 15;
120 asm volatile("pushw %%ds ; "
124 : "+D" (dst
), "+S" (off
), "+c" (len
)
129 void memset_sl(void *dst
, int c
, size_t len
)
134 seg
= ds() + ((size_t)dst
>> 4);
135 off
= (size_t)dst
& 15;
137 asm volatile("pushw %%es ; "
141 : "+D" (off
), "+c" (len
)