Subversion Repositories Kolibri OS

Rev

Rev 1613 | Rev 1630 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1.  
  2. #ifndef __SYSCALL_H__
  3. #define __SYSCALL_H__
  4.  
  5. ///////////////////////////////////////////////////////////////////////////////
  6.  
  7. #define STDCALL  __attribute__ ((stdcall)) __attribute__ ((dllimport))
  8. #define FASTCALL __attribute__ ((fastcall)) __attribute__ ((dllimport))
  9.  
  10. #define IMPORT   __attribute__ ((dllimport))
  11.  
  12. ///////////////////////////////////////////////////////////////////////////////
  13.  
  14. #define SysMsgBoardStr  __SysMsgBoardStr
  15. #define PciApi          __PciApi
  16. #define CreateObject    __CreateObject
  17. #define DestroyObject   __DestroyObject
  18.  
  19. ///////////////////////////////////////////////////////////////////////////////
  20.  
  21.  
  22. void*  STDCALL AllocKernelSpace(size_t size)__asm__("AllocKernelSpace");
  23. void   STDCALL FreeKernelSpace(void *mem)__asm__("FreeKernelSpace");
  24. addr_t STDCALL MapIoMem(addr_t base, size_t size, u32_t flags)__asm__("MapIoMem");
  25. void*  STDCALL KernelAlloc(size_t size)__asm__("KernelAlloc");
  26. void*  STDCALL KernelFree(void *mem)__asm__("KernelFree");
  27. void*  STDCALL UserAlloc(size_t size)__asm__("UserAlloc");
  28. int    STDCALL UserFree(void *mem)__asm__("UserFree");
  29.  
  30. void*  STDCALL GetDisplay(void)__asm__("GetDisplay");
  31.  
  32. u32_t  IMPORT  GetTimerTicks(void)__asm__("GetTimerTicks");
  33.  
  34. addr_t STDCALL AllocPage(void)__asm__("AllocPage");
  35. addr_t STDCALL AllocPages(count_t count)__asm__("AllocPages");
  36.  
  37. void* STDCALL CreateRingBuffer(size_t size, u32_t map)__asm__("CreateRingBuffer");
  38.  
  39. u32_t STDCALL RegService(char *name, srv_proc_t proc)__asm__("RegService");
  40.  
  41. int   STDCALL AttachIntHandler(int irq, void *handler, u32_t access) __asm__("AttachIntHandler");
  42.  
  43. void  FASTCALL MutexInit(struct mutex*)__asm__("MutexInit");
  44. void  FASTCALL MutexLock(struct mutex*)__asm__("MutexLock");
  45. void  FASTCALL MutexUnlock(struct mutex*)__asm__("MutexUnlock");
  46.  
  47. ///////////////////////////////////////////////////////////////////////////////
  48.  
  49. void   STDCALL SetMouseData(int btn, int x, int y,
  50.                             int z, int h)__asm__("SetMouseData");
  51.  
  52. u8_t  STDCALL PciRead8 (u32_t bus, u32_t devfn, u32_t reg)__asm__("PciRead8");
  53. u16_t STDCALL PciRead16(u32_t bus, u32_t devfn, u32_t reg)__asm__("PciRead16");
  54. u32_t STDCALL PciRead32(u32_t bus, u32_t devfn, u32_t reg)__asm__("PciRead32");
  55.  
  56. u32_t STDCALL PciWrite8 (u32_t bus, u32_t devfn, u32_t reg,u8_t val) __asm__("PciWrite8");
  57. u32_t STDCALL PciWrite16(u32_t bus, u32_t devfn, u32_t reg,u16_t val)__asm__("PciWrite16");
  58. u32_t STDCALL PciWrite32(u32_t bus, u32_t devfn, u32_t reg,u32_t val)__asm__("PciWrite32");
  59.  
  60. #define pciReadByte(tag, reg) \
  61.         PciRead8(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg))
  62.  
  63. #define pciReadWord(tag, reg) \
  64.         PciRead16(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg))
  65.  
  66. #define pciReadLong(tag, reg) \
  67.         PciRead32(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg))
  68.  
  69. #define pciWriteByte(tag, reg, val) \
  70.         PciWrite8(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg),(val))
  71.  
  72. #define pciWriteWord(tag, reg, val) \
  73.         PciWrite16(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg),(val))
  74.  
  75. #define pciWriteLong(tag, reg, val) \
  76.         PciWrite32(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg),(val))
  77.  
  78.  
  79. ///////////////////////////////////////////////////////////////////////////////
  80.  
  81. int dbg_open(char *path);
  82. int dbgprintf(const char* format, ...);
  83.  
  84. ///////////////////////////////////////////////////////////////////////////////
  85.  
  86. static inline evhandle_t CreateEvent(kevent_t *ev, u32_t flags)
  87. {
  88.      evhandle_t evh;
  89.  
  90.      __asm__ __volatile__ (
  91.      "call *__imp__CreateEvent"
  92.      :"=A"(evh.raw)
  93.      :"S" (ev), "c"(flags)
  94.      :"memory");
  95.      __asm__ __volatile__ ("":::"ebx","ecx", "esi", "edi");
  96.  
  97.      return evh;
  98. };
  99.  
  100. static inline void RaiseEvent(evhandle_t evh, u32_t flags, kevent_t *ev)
  101. {
  102.      __asm__ __volatile__ (
  103.      "call *__imp__RaiseEvent"
  104.      ::"a"(evh.handle),"b"(evh.euid),"d"(flags),"S" (ev)
  105.      :"memory");
  106.      __asm__ __volatile__ ("":::"ebx","ecx", "esi", "edi");
  107.  
  108. };
  109.  
  110. static inline void WaitEvent(u32_t handle, u32_t euid)
  111. {
  112.      __asm__ __volatile__ (
  113.      "call *__imp__WaitEvent"
  114.      ::"a"(handle),"b"(euid));
  115.      __asm__ __volatile__ ("":::"ecx","edx", "esi");
  116. };
  117.  
  118. static inline u32_t GetEvent(kevent_t *ev)
  119. {
  120.     u32_t  handle;
  121.  
  122.     __asm__ __volatile__ (
  123.     "call *__imp__GetEvent"
  124.     :"=a"(handle)
  125.     :"D"(ev)
  126.     :"memory");
  127.     __asm__ __volatile__ ("":::"ebx","ecx","edx", "esi","edi");
  128.      return handle;
  129. };
  130.  
  131.  
  132. static inline int GetScreenSize(void)
  133. {
  134.   int retval;
  135.  
  136.   asm("int $0x40"
  137.       :"=a"(retval)
  138.       :"a"(61), "b"(1));
  139.   return retval;
  140. }
  141.  
  142. static inline int GetScreenBpp(void)
  143. {
  144.   int retval;
  145.  
  146.   asm("int $0x40"
  147.       :"=a"(retval)
  148.       :"a"(61), "b"(2));
  149.   return retval;
  150. }
  151.  
  152. static inline int GetScreenPitch(void)
  153. {
  154.   int retval;
  155.  
  156.   asm("int $0x40"
  157.       :"=a"(retval)
  158.       :"a"(61), "b"(3));
  159.   return retval;
  160. }
  161.  
  162. static inline u32_t GetPgAddr(void *mem)
  163. {
  164.      u32_t retval;
  165.  
  166.      __asm__ __volatile__ (
  167.      "call *__imp__GetPgAddr \n\t"
  168.      :"=eax" (retval)
  169.      :"a" (mem) );
  170.      return retval;
  171. };
  172.  
  173. static inline void CommitPages(void *mem, u32_t page, u32_t size)
  174. {
  175.      size = (size+4095) & ~4095;
  176.      __asm__ __volatile__ (
  177.      "call *__imp__CommitPages"
  178.      ::"a" (page), "b"(mem),"c"(size>>12)
  179.      :"edx" );
  180.      __asm__ __volatile__ ("":::"eax","ebx","ecx");
  181. };
  182.  
  183. static inline void UnmapPages(void *mem, size_t size)
  184. {
  185.      size = (size+4095) & ~4095;
  186.      __asm__ __volatile__ (
  187.      "call *__imp__UnmapPages"
  188.      ::"a" (mem), "c"(size>>12)
  189.      :"edx");
  190.      __asm__ __volatile__ ("":::"eax","ecx");
  191. };
  192.  
  193. static inline void usleep(u32_t delay)
  194. {
  195.      if( !delay )
  196.         delay++;
  197.      delay*= 500;
  198.  
  199.      while(delay--)
  200.         __asm__ __volatile__(
  201.         "xorl %%eax, %%eax \n\t"
  202.         "cpuid \n\t"
  203.         :::"eax","ebx","ecx","edx");
  204.      };
  205.  
  206. static inline void udelay(u32_t delay)
  207. {
  208.     if(!delay) delay++;
  209.     delay*= 500;
  210.  
  211.     while(delay--)
  212.     {
  213.         __asm__ __volatile__(
  214.         "xorl %%eax, %%eax \n\t"
  215.         "cpuid"
  216.         :::"eax","ebx","ecx","edx" );
  217.     }
  218. }
  219.  
  220. static inline void mdelay(u32_t time)
  221. {
  222.     time /= 10;
  223.     if(!time) time = 1;
  224.  
  225.      __asm__ __volatile__ (
  226.      "call *__imp__Delay"
  227.      ::"b" (time));
  228.      __asm__ __volatile__ (
  229.      "":::"ebx");
  230.  
  231. };
  232.  
  233.  
  234. static inline u32_t __PciApi(int cmd)
  235. {
  236.      u32_t retval;
  237.  
  238.      __asm__ __volatile__ (
  239.      "call *__imp__PciApi \n\t"
  240.      "movzxb %%al, %%eax"
  241.      :"=a" (retval)
  242.      :"a" (cmd)
  243.      :"ebx","ecx","edx");
  244.      return retval;
  245. };
  246.  
  247. static inline void* __CreateObject(u32_t pid, size_t size)
  248. {
  249.      void *retval;
  250.  
  251.      __asm__ __volatile__ (
  252.      "call *__imp__CreateObject \n\t"
  253.      :"=a" (retval)
  254.      :"a" (size),"b"(pid)
  255.      :"esi","edi", "memory");
  256.      return retval;
  257. }
  258.  
  259. static inline void __DestroyObject(void *obj)
  260. {
  261.      __asm__ __volatile__ (
  262.      "call *__imp__DestroyObject \n\t"
  263.      :
  264.      :"a" (obj));
  265.      __asm__ __volatile__ (
  266.      ""
  267.      :::"eax","ebx","ecx","edx","esi","edi","cc","memory");
  268. }
  269.  
  270. static inline u32_t GetService(const char *name)
  271. {
  272.     u32_t handle;
  273.  
  274.     __asm__ __volatile__
  275.     (
  276.      "pushl %%eax \n\t"
  277.      "call *__imp__GetService"
  278.      :"=eax" (handle)
  279.      :"a" (name)
  280.      :"ebx","ecx","edx","esi", "edi"
  281.   );
  282.   return handle;
  283. };
  284.  
  285. static inline u32_t safe_cli(void)
  286. {
  287.      u32_t ifl;
  288.      __asm__ __volatile__ (
  289.      "pushf\n\t"
  290.      "popl %0\n\t"
  291.      "cli\n"
  292.      : "=r" (ifl));
  293.     return ifl;
  294. }
  295.  
  296. static inline void safe_sti(u32_t efl)
  297. {
  298.      if (efl & (1<<9))
  299.         __asm__ __volatile__ ("sti");
  300. }
  301.  
  302. static inline u32_t get_eflags(void)
  303. {
  304.     u32_t val;
  305.     asm volatile (
  306.     "pushfl\n\t"
  307.     "popl %0\n"
  308.     : "=r" (val));
  309.     return val;
  310. }
  311.  
  312. static inline void __clear (void * dst, unsigned len)
  313. {
  314.      u32_t tmp;
  315.      __asm__ __volatile__ (
  316.      "cld \n\t"
  317.      "rep stosb \n"
  318.      :"=c"(tmp),"=D"(tmp)
  319.      :"a"(0),"c"(len),"D"(dst));
  320.      __asm__ __volatile__ ("":::"ecx","edi");
  321. };
  322.  
  323. static inline void out8(const u16_t port, const u8_t val)
  324. {
  325.     __asm__ __volatile__
  326.     ("outb  %1, %0\n" : : "dN"(port), "a"(val));
  327. }
  328.  
  329. static inline void out16(const u16_t port, const u16_t val)
  330. {
  331.     __asm__ __volatile__
  332.     ("outw  %1, %0\n" : : "dN"(port), "a"(val));
  333. }
  334.  
  335. static inline void out32(const u16_t port, const u32_t val)
  336. {
  337.     __asm__ __volatile__
  338.     ("outl  %1, %0\n" : : "dN"(port), "a"(val));
  339. }
  340.  
  341. static inline u8_t in8(const u16_t port)
  342. {
  343.     u8_t tmp;
  344.     __asm__ __volatile__
  345.     ("inb %1, %0\n" : "=a"(tmp) : "dN"(port));
  346.     return tmp;
  347. };
  348.  
  349. static inline u16_t in16(const u16_t port)
  350. {
  351.     u16_t tmp;
  352.     __asm__ __volatile__
  353.     ("inw %1, %0\n" : "=a"(tmp) : "dN"(port));
  354.     return tmp;
  355. };
  356.  
  357. static inline u32_t in32(const u16_t port)
  358. {
  359.     u32_t tmp;
  360.     __asm__ __volatile__
  361.     ("inl %1, %0\n" : "=a"(tmp) : "dN"(port));
  362.     return tmp;
  363. };
  364.  
  365. static inline void delay(int time)
  366. {
  367.      __asm__ __volatile__ (
  368.      "call *__imp__Delay"
  369.      ::"b" (time));
  370.      __asm__ __volatile__ (
  371.      "":::"ebx");
  372.  
  373. }
  374.  
  375. static inline void change_task(void)
  376. {
  377.      __asm__ __volatile__ (
  378.      "call *__imp__ChangeTask");
  379. }
  380.  
  381. static inline void sysSetScreen(int width, int height, int pitch)
  382. {
  383.     __asm__ __volatile__
  384.     (
  385.         "call *__imp__SetScreen"
  386.         :
  387.         :"a" (width-1),"d"(height-1), "c"(pitch)
  388.     );
  389.     __asm__ __volatile__
  390.     ("" :::"eax","ecx","edx");
  391. }
  392.  
  393. int drm_order(unsigned long size);
  394.  
  395. static inline void __iomem *ioremap(uint32_t offset, size_t size)
  396. {
  397.     return (void __iomem*) MapIoMem(offset, size, 3);
  398. }
  399.  
  400. static inline void iounmap(void *addr)
  401. {
  402.     FreeKernelSpace(addr);
  403. }
  404.  
  405. static inline void *
  406. pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
  407.                       addr_t *dma_handle)
  408. {
  409.  
  410.     size = (size + 0x7FFF) & ~0x7FFF;
  411.  
  412.     *dma_handle = AllocPages(size >> 12);
  413.     return (void*)MapIoMem(*dma_handle, size, PG_SW+PG_NOCACHE);
  414. }
  415.  
  416. static inline void __SysMsgBoardStr(char *text)
  417. {
  418.     __asm__ __volatile__(
  419.     "call *__imp__SysMsgBoardStr"
  420.     ::"S" (text));
  421. };
  422.  
  423. #endif
  424.