Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. /* special version for libc - uses %gs instead of %fs.  Ignore comments */
  2.  
  3. /* Copyright (C) 1995 DJ Delorie, see COPYING.DJ for details */
  4. /* Copyright (c) 1995 DJ Delorie.  Permission granted to use for any
  5.    purpose, provided this copyright remains attached and unmodified.
  6.  
  7.    THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  8.    IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  9.    WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  10.  
  11. ╔═══════════════════════════════════════════════════════════════════════╗
  12. ║               Far Pointer Simulation Functions                        ║
  13. ╚═══════════════════════════════════════════════════════════════════════╝
  14.  
  15. This file attempts to make up for the lack of a "far" keyword in GCC.
  16. Although it doesn't provide access to far call APIs (like Windows), it
  17. does allow you to do far pointer data access without the overhead of
  18. movedata() or dosmemget/dosmemput().
  19.  
  20. You should *always* include this file when using these functions and
  21. compile with optimization enabled.  They don't exist as normal functions
  22. in any library, and they compile down to only a few opcodes when used
  23. this way.  They are almost as fast as native pointer operations, and
  24. about as fast as far pointers can get.
  25.  
  26. If you don't use optimization, this file becomes prototypes for
  27. farptr.c, which generates real functions for these when not optimizing.
  28. When optimizing, farptr.c compiles to nothing.
  29.  
  30. There are two types of functions here - standalone and invariant.  The
  31. standalone functions take a selector and offset.  These are used when
  32. you need only a few accesses, time isn't critical, or you don't know
  33. what's in the %gs register.  The invariant ones don't take a selector,
  34. they only take an offset.  These are used inside loops and in
  35. time-critical accesses where the selector doesn't change.  To specify
  36. the selector, use the farsetsel() function.  That selector is used for
  37. all farns*() functions until changed.  You can use _fargetsel() if you
  38. want to temporary change the selector with _farsetsel() and restore
  39. it afterwards.
  40.  
  41. The farpoke* and farpeek* take selectors.
  42.  
  43. The farnspoke* and farnspeek* don't (note the `ns' for `no selector').
  44.  
  45. Warning: These routines all use the %gs register for their accesses.
  46. GCC normally uses only %ds and %es, and libc functions (movedata,
  47. dosmemget, dosmemput) use %gs.  Still, you should be careful about
  48. assumptions concerning whether or not the value you put in %gs will be
  49. preserved across calls to other functions.  If you guess wrong, your
  50. program will crash.  Better safe than sorry.
  51.  
  52. */
  53.  
  54. #ifndef __dj_include_sys_farptr_h_
  55. #define __dj_include_sys_farptr_h_
  56.  
  57. #ifdef __cplusplus
  58. extern "C" {
  59. #endif
  60.  
  61. #ifndef __dj_ENFORCE_ANSI_FREESTANDING
  62.  
  63. #ifndef __STRICT_ANSI__
  64.  
  65. #ifndef _POSIX_SOURCE
  66.  
  67. void _farpokeb(unsigned short, unsigned long, unsigned char);
  68. void _farpokew(unsigned short, unsigned long, unsigned short);
  69. void _farpokel(unsigned short, unsigned long, unsigned long);
  70. unsigned char _farpeekb(unsigned short, unsigned long);
  71. unsigned short _farpeekw(unsigned short, unsigned long);
  72. unsigned long _farpeekl(unsigned short, unsigned long);
  73. void _farsetsel(unsigned short);
  74. unsigned short _fargetsel(void);
  75. void _farnspokeb(unsigned long, unsigned char);
  76. void _farnspokew(unsigned long, unsigned short);
  77. void _farnspokel(unsigned long, unsigned long);
  78. unsigned char _farnspeekb(unsigned long);
  79. unsigned short _farnspeekw(unsigned long);
  80. unsigned long _farnspeekl(unsigned long);
  81.  
  82. extern __inline__ void
  83. _farpokeb(unsigned short selector,
  84.          unsigned long offset,
  85.          unsigned char value)
  86. {
  87.   __asm__ __volatile__ ("movw %w0,%%gs\n"
  88.       " .byte 0x65 \n"
  89.       " movb %b1,(%k2)"
  90.       :
  91.       : "rm" (selector), "qi" (value), "r" (offset));
  92. }
  93.  
  94. extern __inline__ void
  95. _farpokew(unsigned short selector,
  96.          unsigned long offset,
  97.          unsigned short value)
  98. {
  99.   __asm__ __volatile__ ("movw %w0,%%gs \n"
  100.       " .byte 0x65 \n"
  101.       " movw %w1,(%k2)"
  102.       :
  103.       : "rm" (selector), "ri" (value), "r" (offset));
  104. }
  105.  
  106. extern __inline__ void
  107. _farpokel(unsigned short selector,
  108.          unsigned long offset,
  109.          unsigned long value)
  110. {
  111.   __asm__ __volatile__ ("movw %w0,%%gs \n"
  112.       " .byte 0x65 \n"
  113.       " movl %k1,(%k2)"
  114.       :
  115.       : "rm" (selector), "ri" (value), "r" (offset));
  116. }
  117.  
  118. extern __inline__ unsigned char
  119. _farpeekb(unsigned short selector,
  120.          unsigned long offset)
  121. {
  122.   unsigned char result;
  123.   __asm__ __volatile__ ("movw %w1,%%gs \n"
  124.       " .byte 0x65 \n"
  125.       " movb (%k2),%b0"
  126.       : "=q" (result)
  127.       : "rm" (selector), "r" (offset));
  128.   return result;
  129. }
  130.  
  131. extern __inline__ unsigned short
  132. _farpeekw(unsigned short selector,
  133.          unsigned long offset)
  134. {
  135.   unsigned short result;
  136.   __asm__ __volatile__ ("movw %w1, %%gs \n"
  137.       " .byte 0x65 \n"
  138.       " movw (%k2),%w0 \n"
  139.       : "=r" (result)
  140.       : "rm" (selector), "r" (offset));
  141.   return result;
  142. }
  143.  
  144. extern __inline__ unsigned long
  145. _farpeekl(unsigned short selector,
  146.          unsigned long offset)
  147. {
  148.   unsigned long result;
  149.   __asm__ __volatile__ ("movw %w1,%%gs\n"
  150.       " .byte 0x65\n"
  151.       " movl (%k2),%k0"
  152.       : "=r" (result)
  153.       : "rm" (selector), "r" (offset));
  154.   return result;
  155. }
  156.  
  157. extern __inline__ void
  158. _farsetsel(unsigned short selector)
  159. {
  160.   __asm__ __volatile__ ("movw %w0,%%gs"
  161.       :
  162.       : "rm" (selector));
  163. }
  164.  
  165. extern __inline__ unsigned short
  166. _fargetsel(void)
  167. {
  168.   unsigned short selector;
  169.   __asm__ __volatile__ ("movw %%gs,%w0 \n"
  170.       : "=r" (selector)
  171.       : );
  172.   return selector;
  173. }
  174.  
  175. extern __inline__ void
  176. _farnspokeb(unsigned long offset,
  177.          unsigned char value)
  178. {
  179.   __asm__ __volatile__ (".byte 0x65\n"
  180.       " movb %b0,(%k1)"
  181.       :
  182.       : "qi" (value), "r" (offset));
  183. }
  184.  
  185. extern __inline__ void
  186. _farnspokew(unsigned long offset,
  187.          unsigned short value)
  188. {
  189.   __asm__ __volatile__ (".byte 0x65\n"
  190.       " movw %w0,(%k1)"
  191.       :
  192.       : "ri" (value), "r" (offset));
  193. }
  194.  
  195. extern __inline__ void
  196. _farnspokel(unsigned long offset,
  197.          unsigned long value)
  198. {
  199.   __asm__ __volatile__ (".byte 0x65\n"
  200.       " movl %k0,(%k1)"
  201.       :
  202.       : "ri" (value), "r" (offset));
  203. }
  204.  
  205. extern __inline__ unsigned char
  206. _farnspeekb(unsigned long offset)
  207. {
  208.   unsigned char result;
  209.   __asm__ __volatile__ (".byte 0x65\n"
  210.       " movb (%k1),%b0"
  211.       : "=q" (result)
  212.       : "r" (offset));
  213.   return result;
  214. }
  215.  
  216. extern __inline__ unsigned short
  217. _farnspeekw(unsigned long offset)
  218. {
  219.   unsigned short result;
  220.   __asm__ __volatile__ (".byte 0x65\n"
  221.       " movw (%k1),%w0"
  222.       : "=r" (result)
  223.       : "r" (offset));
  224.   return result;
  225. }
  226.  
  227. extern __inline__ unsigned long
  228. _farnspeekl(unsigned long offset)
  229. {
  230.   unsigned long result;
  231.   __asm__ __volatile__ (".byte 0x65\n"
  232.       " movl (%k1),%k0"
  233.       : "=r" (result)
  234.       : "r" (offset));
  235.   return result;
  236. }
  237.  
  238. #endif /* !_POSIX_SOURCE */
  239. #endif /* !__STRICT_ANSI__ */
  240. #endif /* !__dj_ENFORCE_ANSI_FREESTANDING */
  241.  
  242. #ifndef __dj_ENFORCE_FUNCTION_CALLS
  243. #endif /* !__dj_ENFORCE_FUNCTION_CALLS */
  244.  
  245. #ifdef __cplusplus
  246. }
  247. #endif
  248.  
  249. #endif /* !__dj_include_sys_farptr_h_ */
  250.