Subversion Repositories Kolibri OS

Rev

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