Subversion Repositories Kolibri OS

Rev

Rev 817 | 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 (
  114.     ""
  115.     :
  116.     :
  117.     :"eax","ecx"
  118.         );
  119.  
  120. }
  121. ///////////////////////////////////////////////////////////////////////////////
  122.  
  123. u32 PciApi(int cmd);
  124.  
  125. u8  STDCALL PciRead8 (u32 bus, u32 devfn, u32 reg)__asm__("PciRead8");
  126. u16 STDCALL PciRead16(u32 bus, u32 devfn, u32 reg)__asm__("PciRead16");
  127. u32 STDCALL PciRead32(u32 bus, u32 devfn, u32 reg)__asm__("PciRead32");
  128.  
  129. u32 STDCALL PciWrite8 (u32 bus, u32 devfn, u32 reg,u8 val) __asm__("PciWrite8");
  130. u32 STDCALL PciWrite16(u32 bus, u32 devfn, u32 reg,u16 val)__asm__("PciWrite16");
  131. u32 STDCALL PciWrite32(u32 bus, u32 devfn, u32 reg,u32 val)__asm__("PciWrite32");
  132.  
  133. ///////////////////////////////////////////////////////////////////////////////
  134.  
  135. #define SysMsgBoardStr  __SysMsgBoardStr
  136. #define PciApi          __PciApi
  137. //#define RegService      __RegService
  138. #define CreateObject    __CreateObject
  139. #define DestroyObject   __DestroyObject
  140.  
  141. ///////////////////////////////////////////////////////////////////////////////
  142.  
  143. void *malloc(size_t);
  144. void *calloc( size_t num, size_t size );
  145. void *realloc(void*, size_t);
  146. void free(void*);
  147.  
  148. #define kmalloc malloc
  149. #define kfree   free
  150.  
  151. ///////////////////////////////////////////////////////////////////////////////
  152.  
  153. int memcmp(const void *s1, const void *s2, size_t n);
  154. void * memcpy(void * _dest, const void *_src, size_t _n);
  155. char * strcpy(char *to, const char *from);
  156. char * strcat(char *s, const char *append);
  157. int strcmp(const char *s1, const char *s2);
  158. size_t strlen(const char *str);
  159. char * strdup(const char *_s);
  160. char * strchr(const char *s, int c);
  161.  
  162. ///////////////////////////////////////////////////////////////////////////////
  163.  
  164. int snprintf(char *s, size_t n, const char *format, ...);
  165. int printf(const char* format, ...);
  166. int dbg_open(char *path);
  167. int dbgprintf(const char* format, ...);
  168.  
  169. ///////////////////////////////////////////////////////////////////////////////
  170.  
  171.  
  172. void usleep(u32 delay);
  173.  
  174. static int __attribute__ ((always_inline))
  175. abs (int i)
  176. {
  177.   return i < 0 ? -i : i;
  178. };
  179.  
  180. static void __attribute__ ((always_inline))
  181. __clear (void * dst, unsigned len)
  182. { u32 tmp;
  183.   asm __volatile__
  184.   (
  185.     "xorl %%eax, %%eax \n\t"
  186.     "cld \n\t"
  187.     "rep stosb \n"
  188.     :"=c"(tmp),"=D"(tmp)
  189.     :"c"(len),"D"(dst)
  190.     :"memory","eax","cc"
  191.   );
  192. };
  193.  
  194.  
  195. static inline u32 safe_cli(void)
  196. {
  197.   u32 tmp;
  198.         asm volatile (
  199.                 "pushf\n\t"
  200.                 "popl %0\n\t"
  201.                 "cli\n"
  202.     : "=r" (tmp)
  203.         );
  204.   return tmp;
  205. }
  206.  
  207. static inline void safe_sti(u32 ipl)
  208. {
  209.         asm volatile (
  210.                 "pushl %0\n\t"
  211.                 "popf\n"
  212.                 : : "r" (ipl)
  213.         );
  214. }
  215.  
  216. ///////////////////////////////////////////////////////////////////////////////
  217.  
  218. int _stdcall srv_cursor(ioctl_t *io);
  219. int _stdcall srv_2d(ioctl_t *io);
  220.  
  221.  
  222.  
  223.