Subversion Repositories Kolibri OS

Rev

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