Subversion Repositories Kolibri OS

Rev

Rev 1631 | Rev 1964 | 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 mdelay(u32_t time)
  230. {
  231.     time /= 10;
  232.     if(!time) time = 1;
  233.  
  234.      __asm__ __volatile__ (
  235.      "call *__imp__Delay"
  236.      ::"b" (time));
  237.      __asm__ __volatile__ (
  238.      "":::"ebx");
  239.  
  240. };
  241.  
  242.  
  243. static inline u32_t __PciApi(int cmd)
  244. {
  245.      u32_t retval;
  246.  
  247.      __asm__ __volatile__ (
  248.      "call *__imp__PciApi \n\t"
  249.      "movzxb %%al, %%eax"
  250.      :"=a" (retval)
  251.      :"a" (cmd)
  252.      :"cc");
  253.  
  254.      return retval;
  255. };
  256.  
  257. static inline void* __CreateObject(u32_t pid, size_t size)
  258. {
  259.      void *retval;
  260.  
  261.      __asm__ __volatile__ (
  262.      "call *__imp__CreateObject \n\t"
  263.      :"=a" (retval)
  264.      :"a" (size),"b"(pid)
  265.      :"esi","edi", "memory");
  266.      return retval;
  267. }
  268.  
  269. static inline void __DestroyObject(void *obj)
  270. {
  271.      __asm__ __volatile__ (
  272.      "call *__imp__DestroyObject \n\t"
  273.      :
  274.      :"a" (obj));
  275.      __asm__ __volatile__ (
  276.      ""
  277.      :::"eax","ebx","ecx","edx","esi","edi","cc","memory");
  278. }
  279.  
  280. static inline u32_t GetService(const char *name)
  281. {
  282.     u32_t handle;
  283.  
  284.     __asm__ __volatile__
  285.     (
  286.      "pushl %%eax \n\t"
  287.      "call *__imp__GetService"
  288.      :"=eax" (handle)
  289.      :"a" (name)
  290.      :"ebx","ecx","edx","esi", "edi"
  291.   );
  292.   return handle;
  293. };
  294.  
  295. static inline u32_t safe_cli(void)
  296. {
  297.      u32_t ifl;
  298.      __asm__ __volatile__ (
  299.      "pushf\n\t"
  300.      "popl %0\n\t"
  301.      "cli\n"
  302.      : "=r" (ifl));
  303.     return ifl;
  304. }
  305.  
  306. static inline void safe_sti(u32_t efl)
  307. {
  308.      if (efl & (1<<9))
  309.         __asm__ __volatile__ ("sti");
  310. }
  311.  
  312. static inline u32_t get_eflags(void)
  313. {
  314.     u32_t val;
  315.     asm volatile (
  316.     "pushfl\n\t"
  317.     "popl %0\n"
  318.     : "=r" (val));
  319.     return val;
  320. }
  321.  
  322. static inline void __clear (void * dst, unsigned len)
  323. {
  324.      u32_t tmp;
  325.      __asm__ __volatile__ (
  326.      "cld \n\t"
  327.      "rep stosb \n"
  328.      :"=c"(tmp),"=D"(tmp)
  329.      :"a"(0),"c"(len),"D"(dst));
  330.      __asm__ __volatile__ ("":::"ecx","edi");
  331. };
  332.  
  333. static inline void out8(const u16_t port, const u8_t val)
  334. {
  335.     __asm__ __volatile__
  336.     ("outb  %1, %0\n" : : "dN"(port), "a"(val));
  337. }
  338.  
  339. static inline void out16(const u16_t port, const u16_t val)
  340. {
  341.     __asm__ __volatile__
  342.     ("outw  %1, %0\n" : : "dN"(port), "a"(val));
  343. }
  344.  
  345. static inline void out32(const u16_t port, const u32_t val)
  346. {
  347.     __asm__ __volatile__
  348.     ("outl  %1, %0\n" : : "dN"(port), "a"(val));
  349. }
  350.  
  351. static inline u8_t in8(const u16_t port)
  352. {
  353.     u8_t tmp;
  354.     __asm__ __volatile__
  355.     ("inb %1, %0\n" : "=a"(tmp) : "dN"(port));
  356.     return tmp;
  357. };
  358.  
  359. static inline u16_t in16(const u16_t port)
  360. {
  361.     u16_t tmp;
  362.     __asm__ __volatile__
  363.     ("inw %1, %0\n" : "=a"(tmp) : "dN"(port));
  364.     return tmp;
  365. };
  366.  
  367. static inline u32_t in32(const u16_t port)
  368. {
  369.     u32_t tmp;
  370.     __asm__ __volatile__
  371.     ("inl %1, %0\n" : "=a"(tmp) : "dN"(port));
  372.     return tmp;
  373. };
  374.  
  375. static inline void delay(int time)
  376. {
  377.      __asm__ __volatile__ (
  378.      "call *__imp__Delay"
  379.      ::"b" (time));
  380.      __asm__ __volatile__ (
  381.      "":::"ebx");
  382.  
  383. }
  384.  
  385. static inline void change_task(void)
  386. {
  387.      __asm__ __volatile__ (
  388.      "call *__imp__ChangeTask");
  389. }
  390.  
  391. static inline void sysSetScreen(int width, int height, int pitch)
  392. {
  393.     __asm__ __volatile__
  394.     (
  395.         "call *__imp__SetScreen"
  396.         :
  397.         :"a" (width-1),"d"(height-1), "c"(pitch)
  398.     );
  399.     __asm__ __volatile__
  400.     ("" :::"eax","ecx","edx");
  401. }
  402.  
  403. int drm_order(unsigned long size);
  404.  
  405. static inline void __iomem *ioremap(uint32_t offset, size_t size)
  406. {
  407.     return (void __iomem*) MapIoMem(offset, size, 3);
  408. }
  409.  
  410. static inline void iounmap(void *addr)
  411. {
  412.     FreeKernelSpace(addr);
  413. }
  414.  
  415. static inline void __SysMsgBoardStr(char *text)
  416. {
  417.     __asm__ __volatile__(
  418.     "call *__imp__SysMsgBoardStr"
  419.     ::"S" (text));
  420. };
  421.  
  422. #endif
  423.