Releasing debian version 6.02~pre7+dfsg-1.
[syslinux-debian/hramrach.git] / dos / getsetsl.c
blobfadef43876ef3257662a6e4090a9c23c003e2889
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"
14 #include "mystuff.h"
16 static inline void *set_fs_sl(const void *p)
18 uint16_t seg;
20 seg = ds() + ((size_t) p >> 4);
21 set_fs(seg);
22 return (void *)((size_t) p & 0xf);
25 #if 0 /* unused */
26 uint8_t get_8_sl(const uint8_t * p)
28 uint8_t v;
30 p = set_fs_sl(p);
31 asm volatile("movb %%fs:%1,%0":"=q" (v):"m"(*p));
32 return v;
34 #endif
36 uint16_t get_16_sl(const uint16_t * p)
38 uint16_t v;
40 p = set_fs_sl(p);
41 asm volatile("movw %%fs:%1,%0":"=r" (v):"m"(*p));
42 return v;
45 uint32_t get_32_sl(const uint32_t * p)
47 uint32_t v;
49 p = set_fs_sl(p);
50 asm volatile("movl %%fs:%1,%0":"=r" (v):"m"(*p));
51 return v;
54 #if 0 /* unused */
55 uint64_t get_64_sl(const uint64_t * p)
57 uint32_t v0, v1;
58 const uint32_t *pp = (const uint32_t *)set_fs_sl(p);
60 asm volatile("movl %%fs:%1,%0" : "=r" (v0) : "m" (pp[0]));
61 asm volatile("movl %%fs:%1,%0" : "=r" (v1) : "m" (pp[1]));
62 return v0 + ((uint64_t)v1 << 32);
64 #endif
66 #if 0 /* unused */
67 void set_8_sl(uint8_t * p, uint8_t v)
69 p = set_fs_sl(p);
70 asm volatile("movb %1,%%fs:%0":"=m" (*p):"qi"(v));
72 #endif
74 void set_16_sl(uint16_t * p, uint16_t v)
76 p = set_fs_sl(p);
77 asm volatile("movw %1,%%fs:%0":"=m" (*p):"ri"(v));
80 void set_32_sl(uint32_t * p, uint32_t v)
82 p = set_fs_sl(p);
83 asm volatile("movl %1,%%fs:%0":"=m" (*p):"ri"(v));
86 void set_64_sl(uint64_t * p, uint64_t v)
88 uint32_t *pp = (uint32_t *)set_fs_sl(p);
89 asm volatile("movl %1,%%fs:%0" : "=m" (pp[0]) : "ri"((uint32_t)v));
90 asm volatile("movl %1,%%fs:%0" : "=m" (pp[1]) : "ri"((uint32_t)(v >> 32)));
93 void memcpy_to_sl(void *dst, const void *src, size_t len)
95 uint16_t seg;
96 uint16_t off;
98 seg = ds() + ((size_t)dst >> 4);
99 off = (size_t)dst & 15;
101 asm volatile("pushw %%es ; "
102 "movw %3,%%es ; "
103 "rep ; movsb ; "
104 "popw %%es"
105 : "+D" (off), "+S" (src), "+c" (len)
106 : "r" (seg)
107 : "memory");
110 void memcpy_from_sl(void *dst, const void *src, size_t len)
112 uint16_t seg;
113 uint16_t off;
115 seg = ds() + ((size_t)src >> 4);
116 off = (size_t)src & 15;
118 asm volatile("pushw %%ds ; "
119 "movw %3,%%ds ; "
120 "rep ; movsb ; "
121 "popw %%ds"
122 : "+D" (dst), "+S" (off), "+c" (len)
123 : "r" (seg)
124 : "memory");