Subversion Repositories Kolibri OS

Rev

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