Subversion Repositories Kolibri OS

Rev

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

  1.  
  2. #ifndef __SYSCALL_H__
  3. #define __SYSCALL_H__
  4.  
  5.  
  6. #define OS_BASE   0x80000000
  7.  
  8. typedef struct
  9. {
  10.   u32_t      handle;
  11.   u32_t      io_code;
  12.   void       *input;
  13.   int        inp_size;
  14.   void       *output;
  15.   int        out_size;
  16. }ioctl_t;
  17.  
  18. typedef int (__stdcall *srv_proc_t)(ioctl_t *);
  19.  
  20. #define ERR_OK       0
  21. #define ERR_PARAM   -1
  22.  
  23.  
  24. u32_t drvEntry(int, char *)__asm__("_drvEntry");
  25.  
  26. ///////////////////////////////////////////////////////////////////////////////
  27.  
  28. #define STDCALL __attribute__ ((stdcall)) __attribute__ ((dllimport))
  29. #define IMPORT __attribute__ ((dllimport))
  30.  
  31. ///////////////////////////////////////////////////////////////////////////////
  32.  
  33. #define SysMsgBoardStr  __SysMsgBoardStr
  34. #define PciApi          __PciApi
  35. //#define RegService      __RegService
  36. #define CreateObject    __CreateObject
  37. #define DestroyObject   __DestroyObject
  38.  
  39. ///////////////////////////////////////////////////////////////////////////////
  40.  
  41. #define PG_SW       0x003
  42. #define PG_NOCACHE  0x018
  43.  
  44. void*  STDCALL AllocKernelSpace(size_t size)__asm__("AllocKernelSpace");
  45. void   STDCALL FreeKernelSpace(void *mem)__asm__("FreeKernelSpace");
  46. addr_t STDCALL MapIoMem(addr_t base, size_t size, u32_t flags)__asm__("MapIoMem");
  47. void*  STDCALL KernelAlloc(size_t size)__asm__("KernelAlloc");
  48. void*  STDCALL KernelFree(void *mem)__asm__("KernelFree");
  49. void*  STDCALL UserAlloc(size_t size)__asm__("UserAlloc");
  50. int    STDCALL UserFree(void *mem)__asm__("UserFree");
  51.  
  52. addr_t STDCALL AllocPages(count_t count)__asm__("AllocPages");
  53.  
  54. void* STDCALL CreateRingBuffer(size_t size, u32_t map)__asm__("CreateRingBuffer");
  55.  
  56. u32_t STDCALL RegService(char *name, srv_proc_t proc)__asm__("RegService");
  57.  
  58. int   STDCALL AttachIntHandler(int irq, void *handler, u32_t access) __asm__("AttachIntHandler");
  59.  
  60.  
  61. ///////////////////////////////////////////////////////////////////////////////
  62.  
  63. void   STDCALL SetMouseData(int btn, int x, int y,
  64.                             int z, int h)__asm__("SetMouseData");
  65.  
  66. static u32_t PciApi(int cmd);
  67.  
  68. u8_t  STDCALL PciRead8 (u32_t bus, u32_t devfn, u32_t reg)__asm__("PciRead8");
  69. u16_t STDCALL PciRead16(u32_t bus, u32_t devfn, u32_t reg)__asm__("PciRead16");
  70. u32_t STDCALL PciRead32(u32_t bus, u32_t devfn, u32_t reg)__asm__("PciRead32");
  71.  
  72. u32_t STDCALL PciWrite8 (u32_t bus, u32_t devfn, u32_t reg,u8_t val) __asm__("PciWrite8");
  73. u32_t STDCALL PciWrite16(u32_t bus, u32_t devfn, u32_t reg,u16_t val)__asm__("PciWrite16");
  74. u32_t STDCALL PciWrite32(u32_t bus, u32_t devfn, u32_t reg,u32_t val)__asm__("PciWrite32");
  75.  
  76. #define pciReadByte(tag, reg) \
  77.         PciRead8(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg))
  78.  
  79. #define pciReadWord(tag, reg) \
  80.         PciRead16(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg))
  81.  
  82. #define pciReadLong(tag, reg) \
  83.         PciRead32(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg))
  84.  
  85. #define pciWriteByte(tag, reg, val) \
  86.         PciWrite8(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg),(val))
  87.  
  88. #define pciWriteWord(tag, reg, val) \
  89.         PciWrite16(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg),(val))
  90.  
  91. #define pciWriteLong(tag, reg, val) \
  92.         PciWrite32(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg),(val))
  93.  
  94.  
  95. ///////////////////////////////////////////////////////////////////////////////
  96.  
  97. int dbg_open(char *path);
  98. int dbgprintf(const char* format, ...);
  99.  
  100. ///////////////////////////////////////////////////////////////////////////////
  101.  
  102. extern inline int GetScreenSize()
  103. {
  104.   int retval;
  105.  
  106.   asm("int $0x40"
  107.       :"=a"(retval)
  108.       :"a"(61), "b"(1));
  109.   return retval;
  110. }
  111.  
  112. extern inline int GetScreenBpp()
  113. {
  114.   int retval;
  115.  
  116.   asm("int $0x40"
  117.       :"=a"(retval)
  118.       :"a"(61), "b"(2));
  119.   return retval;
  120. }
  121.  
  122. extern inline int GetScreenPitch()
  123. {
  124.   int retval;
  125.  
  126.   asm("int $0x40"
  127.       :"=a"(retval)
  128.       :"a"(61), "b"(3));
  129.   return retval;
  130. }
  131.  
  132. extern inline u32_t GetPgAddr(void *mem)
  133. {
  134.      u32_t retval;
  135.  
  136.      __asm__ __volatile__ (
  137.      "call *__imp__GetPgAddr \n\t"
  138.      :"=eax" (retval)
  139.      :"a" (mem) );
  140.      return retval;
  141. };
  142.  
  143. extern inline void CommitPages(void *mem, u32_t page, u32_t size)
  144. {
  145.      size = (size+4095) & ~4095;
  146.      __asm__ __volatile__ (
  147.      "call *__imp__CommitPages"
  148.      ::"a" (page), "b"(mem),"c"(size>>12)
  149.      :"edx" );
  150.      __asm__ __volatile__ ("":::"eax","ebx","ecx");
  151. };
  152.  
  153. extern inline void UnmapPages(void *mem, size_t size)
  154. {
  155.      size = (size+4095) & ~4095;
  156.      __asm__ __volatile__ (
  157.      "call *__imp__UnmapPages"
  158.      ::"a" (mem), "c"(size>>12)
  159.      :"edx");
  160.      __asm__ __volatile__ ("":::"eax","ecx");
  161. };
  162.  
  163. extern inline void usleep(u32_t delay)
  164. {
  165.      if( !delay )
  166.         delay++;
  167.      delay*= 128;
  168.  
  169.      while(delay--)
  170.      {
  171.         __asm__ __volatile__(
  172.         "xorl %%eax, %%eax \n\t"
  173.         "cpuid \n\t"
  174.         "xorl %%eax, %%eax"
  175.         :::"ebx","ecx","edx");
  176.      };
  177. };
  178.  
  179. static inline void udelay(u32_t delay)
  180. {
  181.     if(!delay) delay++;
  182.     delay*= 128;
  183.  
  184.     while(delay--)
  185.     {
  186.         __asm__ __volatile__(
  187.         "xorl %%eax, %%eax \n\t"
  188.         "cpuid \n\t"
  189.         "xorl %%eax, %%eax"
  190.         :::"ebx","ecx","edx" );
  191.     }
  192. }
  193.  
  194. static inline void mdelay(u32_t time)
  195. {
  196.     time /= 10;
  197.     if(!time) time = 1;
  198.  
  199.      __asm__ __volatile__ (
  200.      "call *__imp__Delay"
  201.      ::"b" (time));
  202.      __asm__ __volatile__ (
  203.      "":::"ebx");
  204.  
  205. };
  206.  
  207.  
  208. static inline u32_t __PciApi(int cmd)
  209. {
  210.      u32_t retval;
  211.  
  212.      __asm__ __volatile__ (
  213.      "call *__imp__PciApi"
  214.      :"=a" (retval)
  215.      :"a" (cmd)
  216.      :"memory");
  217.      return retval;
  218. };
  219.  
  220. static inline void* __CreateObject(u32_t pid, size_t size)
  221. {
  222.      void *retval;
  223.  
  224.      __asm__ __volatile__ (
  225.      "call *__imp__CreateObject \n\t"
  226.      :"=a" (retval)
  227.      :"a" (size),"b"(pid)
  228.      :"esi","edi", "memory");
  229.      return retval;
  230. }
  231.  
  232. static inline void *__DestroyObject(void *obj)
  233. {
  234.      __asm__ __volatile__ (
  235.      "call *__imp__DestroyObject"
  236.      :
  237.      :"a" (obj)
  238.      :"ebx","edx","esi","edi", "memory");
  239. }
  240.  
  241.  
  242. /*
  243. u32 __RegService(char *name, srv_proc_t proc)
  244. {
  245.   u32 retval;
  246.  
  247.   asm __volatile__
  248.   (
  249.     "pushl %%eax \n\t"
  250.     "pushl %%ebx \n\t"
  251.     "call *__imp__RegService \n\t"
  252.     :"=eax" (retval)
  253.     :"a" (proc), "b" (name)
  254.     :"memory"
  255.   );
  256.   return retval;
  257. };
  258. */
  259.  
  260. static inline u32_t safe_cli(void)
  261. {
  262.      u32_t ifl;
  263.      __asm__ __volatile__ (
  264.      "pushf\n\t"
  265.      "popl %0\n\t"
  266.      "cli\n"
  267.      : "=r" (ifl));
  268.     return ifl;
  269. }
  270.  
  271. static inline void safe_sti(u32_t ifl)
  272. {
  273.      __asm__ __volatile__ (
  274.      "pushl %0\n\t"
  275.      "popf\n"
  276.      : : "r" (ifl)
  277.         );
  278. }
  279.  
  280. static inline void __clear (void * dst, unsigned len)
  281. {
  282.      u32_t tmp;
  283.      __asm__ __volatile__ (
  284. //     "xorl %%eax, %%eax \n\t"
  285.      "cld \n\t"
  286.      "rep stosb \n"
  287.      :"=c"(tmp),"=D"(tmp)
  288.      :"a"(0),"c"(len),"D"(dst));
  289.      __asm__ __volatile__ ("":::"ecx","edi");
  290. };
  291.  
  292. static inline void out8(const u16_t port, const u8_t val)
  293. {
  294.     __asm__ __volatile__
  295.     ("outb  %1, %0\n" : : "dN"(port), "a"(val));
  296. }
  297.  
  298. static inline void out16(const u16_t port, const u16_t val)
  299. {
  300.     __asm__ __volatile__
  301.     ("outw  %1, %0\n" : : "dN"(port), "a"(val));
  302. }
  303.  
  304. static inline void out32(const u16_t port, const u32_t val)
  305. {
  306.     __asm__ __volatile__
  307.     ("outl  %1, %0\n" : : "dN"(port), "a"(val));
  308. }
  309.  
  310. static inline u8_t in8(const u16_t port)
  311. {
  312.     u8_t tmp;
  313.     __asm__ __volatile__
  314.     ("inb %1, %0\n" : "=a"(tmp) : "dN"(port));
  315.     return tmp;
  316. };
  317.  
  318. static inline u16_t in16(const u16_t port)
  319. {
  320.     u16_t tmp;
  321.     __asm__ __volatile__
  322.     ("inw %1, %0\n" : "=a"(tmp) : "dN"(port));
  323.     return tmp;
  324. };
  325.  
  326. static inline u32_t in32(const u16_t port)
  327. {
  328.     u32_t tmp;
  329.     __asm__ __volatile__
  330.     ("inl %1, %0\n" : "=a"(tmp) : "dN"(port));
  331.     return tmp;
  332. };
  333.  
  334. static inline void delay(int time)
  335. {
  336.      __asm__ __volatile__ (
  337.      "call *__imp__Delay"
  338.      ::"b" (time));
  339.      __asm__ __volatile__ (
  340.      "":::"ebx");
  341.  
  342. }
  343.  
  344. static inline void change_task()
  345. {
  346.      __asm__ __volatile__ (
  347.      "call *__imp__ChangeTask");
  348. }
  349.  
  350. int drm_order(unsigned long size);
  351.  
  352. #endif
  353.