Subversion Repositories Kolibri OS

Rev

Rev 829 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. #define OS_BASE   0x80000000
  3.  
  4. #include "xmd.h"
  5.  
  6. #define NULL (void*)(0)
  7.  
  8. #define FALSE   0
  9. #define TRUE    1
  10.  
  11. typedef void *pointer;
  12.  
  13. typedef unsigned int   Bool;
  14.  
  15. typedef unsigned char  u8;
  16. typedef unsigned short u16;
  17. typedef unsigned int   u32;
  18.  
  19. typedef unsigned char   u8_t;
  20. typedef unsigned short u16_t;
  21. typedef unsigned int   u32_t;
  22.  
  23. typedef unsigned int memType;
  24. typedef unsigned int size_t;
  25.  
  26. typedef struct { float hi, lo; } range;
  27.  
  28.  
  29. typedef struct
  30. {
  31.   unsigned      handle;
  32.   unsigned      io_code;
  33.   void          *input;
  34.   int           inp_size;
  35.   void          *output;
  36.   int           out_size;
  37. }ioctl_t;
  38.  
  39. typedef int (_stdcall *srv_proc_t)(ioctl_t *);
  40.  
  41. #define ERR_OK       0
  42. #define ERR_PARAM   -1
  43.  
  44.  
  45. u32_t __stdcall drvEntry(int)__asm__("_drvEntry");
  46.  
  47. ///////////////////////////////////////////////////////////////////////////////
  48.  
  49. #define STDCALL __attribute__ ((stdcall)) __attribute__ ((dllimport))
  50. #define IMPORT __attribute__ ((dllimport))
  51.  
  52. ///////////////////////////////////////////////////////////////////////////////
  53.  
  54. #define PG_SW       0x003
  55. #define PG_NOCACHE  0x018
  56.  
  57. void*  STDCALL AllocKernelSpace(size_t size)__asm__("AllocKernelSpace");
  58. void*  STDCALL KernelAlloc(size_t size)__asm__("KernelAlloc");
  59. void*  STDCALL UserAlloc(size_t size)__asm__("UserAlloc");
  60. int    STDCALL UserFree(void *mem)__asm__("UserFree");
  61.  
  62.  
  63. int KernelFree(void *);
  64.  
  65. void* STDCALL CreateRingBuffer(size_t size, u32 map)__asm__("CreateRingBuffer");
  66.  
  67. u32 STDCALL RegService(char *name, srv_proc_t proc)__asm__("RegService");
  68.  
  69. //void *CreateObject(u32 pid, size_t size);
  70. //void *DestroyObject(void *obj);
  71.  
  72. CARD32 STDCALL MapIoMem(CARD32 Base,CARD32 size,CARD32 flags)__asm__("MapIoMem");
  73.  
  74. static inline u32_t GetPgAddr(void *mem)
  75. {
  76.   u32_t retval;
  77.  
  78.         asm volatile (
  79.     "call *__imp__GetPgAddr \n\t"
  80.     :"=eax" (retval)
  81.     :"a" (mem)
  82.         );
  83.   return retval;
  84. }
  85.  
  86. static inline void CommitPages(void *mem, u32_t page, u32_t size)
  87. {
  88.   size = (size+4095) & ~4095;
  89.         asm volatile (
  90.     "call *__imp__CommitPages"
  91.     :
  92.     :"a" (page), "b"(mem),"c"(size>>12)
  93.     :"edx"
  94.   );
  95.   asm volatile (
  96.     ""
  97.     :
  98.     :
  99.     :"eax","ebx","ecx"
  100.         );
  101.  
  102.  
  103. }
  104. static inline void UnmapPages(void *mem, size_t size)
  105. {
  106.   size = (size+4095) & ~4095;
  107.         asm volatile (
  108.     "call *__imp__UnmapPages"
  109.     :
  110.     :"a" (mem), "c"(size>>12)
  111.     :"edx"
  112.         );
  113.   asm volatile ("":::"eax","ecx");
  114.  
  115. }
  116. ///////////////////////////////////////////////////////////////////////////////
  117.  
  118. u32 PciApi(int cmd);
  119.  
  120. u8  STDCALL PciRead8 (u32 bus, u32 devfn, u32 reg)__asm__("PciRead8");
  121. u16 STDCALL PciRead16(u32 bus, u32 devfn, u32 reg)__asm__("PciRead16");
  122. u32 STDCALL PciRead32(u32 bus, u32 devfn, u32 reg)__asm__("PciRead32");
  123.  
  124. u32 STDCALL PciWrite8 (u32 bus, u32 devfn, u32 reg,u8 val) __asm__("PciWrite8");
  125. u32 STDCALL PciWrite16(u32 bus, u32 devfn, u32 reg,u16 val)__asm__("PciWrite16");
  126. u32 STDCALL PciWrite32(u32 bus, u32 devfn, u32 reg,u32 val)__asm__("PciWrite32");
  127.  
  128. ///////////////////////////////////////////////////////////////////////////////
  129.  
  130. #define SysMsgBoardStr  __SysMsgBoardStr
  131. #define PciApi          __PciApi
  132. //#define RegService      __RegService
  133. #define CreateObject    __CreateObject
  134. #define DestroyObject   __DestroyObject
  135.  
  136. ///////////////////////////////////////////////////////////////////////////////
  137.  
  138. void *malloc(size_t);
  139. void *calloc( size_t num, size_t size );
  140. void *realloc(void*, size_t);
  141. void free(void*);
  142.  
  143. #define kmalloc malloc
  144. #define kfree   free
  145.  
  146. #define xcalloc calloc
  147.  
  148. ///////////////////////////////////////////////////////////////////////////////
  149.  
  150. int memcmp(const void *s1, const void *s2, size_t n);
  151. void * memcpy(void * _dest, const void *_src, size_t _n);
  152. char * strcpy(char *to, const char *from);
  153. char * strcat(char *s, const char *append);
  154. int strcmp(const char *s1, const char *s2);
  155. size_t strlen(const char *str);
  156. char * strdup(const char *_s);
  157. char * strchr(const char *s, int c);
  158.  
  159. ///////////////////////////////////////////////////////////////////////////////
  160.  
  161. int snprintf(char *s, size_t n, const char *format, ...);
  162. int printf(const char* format, ...);
  163. int dbg_open(char *path);
  164. int dbgprintf(const char* format, ...);
  165.  
  166. ///////////////////////////////////////////////////////////////////////////////
  167.  
  168.  
  169. void usleep(u32 delay);
  170.  
  171. static int __attribute__ ((always_inline))
  172. abs (int i)
  173. {
  174.   return i < 0 ? -i : i;
  175. };
  176.  
  177. static void __attribute__ ((always_inline))
  178. __clear (void * dst, unsigned len)
  179. { u32 tmp;
  180.   asm __volatile__
  181.   (
  182.     "xorl %%eax, %%eax \n\t"
  183.     "cld \n\t"
  184.     "rep stosb \n"
  185.     :"=c"(tmp),"=D"(tmp)
  186.     :"c"(len),"D"(dst)
  187.     :"eax"
  188.   );
  189.   asm volatile ("":::"ecx","edi");
  190.  
  191. };
  192.  
  193.  
  194. static inline u32 safe_cli(void)
  195. {
  196.   u32 tmp;
  197.         asm volatile (
  198.                 "pushf\n\t"
  199.                 "popl %0\n\t"
  200.                 "cli\n"
  201.     : "=r" (tmp)
  202.         );
  203.   return tmp;
  204. }
  205.  
  206. static inline void safe_sti(u32 ipl)
  207. {
  208.         asm volatile (
  209.                 "pushl %0\n\t"
  210.                 "popf\n"
  211.                 : : "r" (ipl)
  212.         );
  213. }
  214.  
  215. ///////////////////////////////////////////////////////////////////////////////
  216.  
  217. int _stdcall srv_cursor(ioctl_t *io);
  218. int _stdcall srv_2d(ioctl_t *io);
  219.  
  220.  
  221.  
  222.