Releasing debian version 4.06+dfsg-2.
[syslinux-debian/hramrach.git] / dos / getsetsl.c
blob67e954d17ed1d467bf56b00839f5c7ed6150c564
1 /*
2 * Special handling for the MS-DOS derivative: syslinux_ldlinux
3 * is a "far" object...
4 */
6 #define _XOPEN_SOURCE 500 /* Required on glibc 2.x */
7 #define _BSD_SOURCE
8 #include <inttypes.h>
9 #include <string.h>
10 #include <stddef.h>
11 #include <stdlib.h>
13 #include "syslxint.h"
15 #define __noinline __attribute__((noinline))
17 #if 0 /* unused */
18 uint8_t get_8_sl(const uint8_t * p)
20 uint8_t v;
22 p = set_fs(p);
23 asm volatile("movb %%fs:%1,%0":"=q" (v):"m"(*p));
24 return v;
26 #endif
28 uint16_t get_16_sl(const uint16_t * p)
30 uint16_t v;
32 p = set_fs(p);
33 asm volatile("movw %%fs:%1,%0":"=r" (v):"m"(*p));
34 return v;
37 uint32_t get_32_sl(const uint32_t * p)
39 uint32_t v;
41 p = set_fs(p);
42 asm volatile("movl %%fs:%1,%0":"=r" (v):"m"(*p));
43 return v;
46 #if 0 /* unused */
47 uint64_t get_64_sl(const uint64_t * p)
49 uint32_t v0, v1;
50 const uint32_t *pp = (const uint32_t *)set_fs(p);
52 asm volatile("movl %%fs:%1,%0" : "=r" (v0) : "m" (pp[0]));
53 asm volatile("movl %%fs:%1,%0" : "=r" (v1) : "m" (pp[1]));
54 return v0 + ((uint64_t)v1 << 32);
56 #endif
58 #if 0 /* unused */
59 void set_8_sl(uint8_t * p, uint8_t v)
61 p = set_fs(p);
62 asm volatile("movb %1,%%fs:%0":"=m" (*p):"qi"(v));
64 #endif
66 void set_16_sl(uint16_t * p, uint16_t v)
68 p = set_fs(p);
69 asm volatile("movw %1,%%fs:%0":"=m" (*p):"ri"(v));
72 void set_32_sl(uint32_t * p, uint32_t v)
74 p = set_fs(p);
75 asm volatile("movl %1,%%fs:%0":"=m" (*p):"ri"(v));
78 void set_64_sl(uint64_t * p, uint64_t v)
80 uint32_t *pp = (uint32_t *)set_fs(p);
81 asm volatile("movl %1,%%fs:%0" : "=m" (pp[0]) : "ri"((uint32_t)v));
82 asm volatile("movl %1,%%fs:%0" : "=m" (pp[1]) : "ri"((uint32_t)(v >> 32)));
85 void memcpy_to_sl(void *dst, const void *src, size_t len)
87 uint16_t seg;
88 uint16_t off;
90 seg = ds() + ((size_t)dst >> 4);
91 off = (size_t)dst & 15;
93 asm volatile("pushw %%es ; "
94 "movw %3,%%es ; "
95 "rep ; movsb ; "
96 "popw %%es"
97 : "+D" (off), "+S" (src), "+c" (len)
98 : "r" (seg)
99 : "memory");
102 void memcpy_from_sl(void *dst, const void *src, size_t len)
104 uint16_t seg;
105 uint16_t off;
107 seg = ds() + ((size_t)src >> 4);
108 off = (size_t)src & 15;
110 asm volatile("pushw %%ds ; "
111 "movw %3,%%ds ; "
112 "rep ; movsb ; "
113 "popw %%ds"
114 : "+D" (dst), "+S" (off), "+c" (len)
115 : "r" (seg)
116 : "memory");