Subversion Repositories Kolibri OS

Rev

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

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