Subversion Repositories Kolibri OS

Rev

Rev 3031 | Rev 3391 | 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. void   STDCALL MapPage(void *vaddr, addr_t paddr, u32_t flags)__asm__("MapPage");
  43.  
  44.  
  45. void* STDCALL CreateRingBuffer(size_t size, u32_t map)__asm__("CreateRingBuffer");
  46.  
  47. u32_t STDCALL RegService(char *name, srv_proc_t proc)__asm__("RegService");
  48.  
  49. int   STDCALL AttachIntHandler(int irq, void *handler, u32_t access) __asm__("AttachIntHandler");
  50.  
  51. void  FASTCALL MutexInit(struct mutex*)__asm__("MutexInit");
  52. void  FASTCALL MutexLock(struct mutex*)__asm__("MutexLock");
  53. void  FASTCALL MutexUnlock(struct mutex*)__asm__("MutexUnlock");
  54.  
  55. addr_t IMPORT  GetStackBase(void)__asm__("GetStackBase");
  56. u32_t  IMPORT  GetPid(void)__asm__("GetPid");
  57.  
  58. u32 STDCALL TimerHs(u32 delay, u32 interval,
  59.                     void *fn, void *data)asm("TimerHs");
  60.  
  61. ///////////////////////////////////////////////////////////////////////////////
  62.  
  63. void   STDCALL SetMouseData(int btn, int x, int y,
  64.                             int z, int h)__asm__("SetMouseData");
  65.  
  66. void   FASTCALL SetKeyboardData(u32_t data)__asm__("SetKeyboardData");
  67.  
  68.  
  69. u8_t  STDCALL PciRead8 (u32_t bus, u32_t devfn, u32_t reg)__asm__("PciRead8");
  70. u16_t STDCALL PciRead16(u32_t bus, u32_t devfn, u32_t reg)__asm__("PciRead16");
  71. u32_t STDCALL PciRead32(u32_t bus, u32_t devfn, u32_t reg)__asm__("PciRead32");
  72.  
  73. u32_t STDCALL PciWrite8 (u32_t bus, u32_t devfn, u32_t reg,u8_t val) __asm__("PciWrite8");
  74. u32_t STDCALL PciWrite16(u32_t bus, u32_t devfn, u32_t reg,u16_t val)__asm__("PciWrite16");
  75. u32_t STDCALL PciWrite32(u32_t bus, u32_t devfn, u32_t reg,u32_t val)__asm__("PciWrite32");
  76.  
  77. #define pciReadByte(tag, reg) \
  78.         PciRead8(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg))
  79.  
  80. #define pciReadWord(tag, reg) \
  81.         PciRead16(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg))
  82.  
  83. #define pciReadLong(tag, reg) \
  84.         PciRead32(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg))
  85.  
  86. #define pciWriteByte(tag, reg, val) \
  87.         PciWrite8(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg),(val))
  88.  
  89. #define pciWriteWord(tag, reg, val) \
  90.         PciWrite16(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg),(val))
  91.  
  92. #define pciWriteLong(tag, reg, val) \
  93.         PciWrite32(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg),(val))
  94.  
  95. static inline int pci_read_config_byte(struct pci_dev *dev, int where,
  96.                     u8 *val)
  97. {
  98.     *val = PciRead8(dev->busnr, dev->devfn, where);
  99.     return 1;
  100. }
  101.  
  102. static inline int pci_read_config_word(struct pci_dev *dev, int where,
  103.                     u16 *val)
  104. {
  105.     *val = PciRead16(dev->busnr, dev->devfn, where);
  106.     return 1;
  107. }
  108.  
  109. static inline int pci_read_config_dword(struct pci_dev *dev, int where,
  110.                     u32 *val)
  111. {
  112.     *val = PciRead32(dev->busnr, dev->devfn, where);
  113.     return 1;
  114. }
  115.  
  116. static inline int pci_write_config_byte(struct pci_dev *dev, int where,
  117.                     u8 val)
  118. {
  119.     PciWrite8(dev->busnr, dev->devfn, where, val);
  120.     return 1;
  121. }
  122.  
  123. static inline int pci_write_config_word(struct pci_dev *dev, int where,
  124.                     u16 val)
  125. {
  126.     PciWrite16(dev->busnr, dev->devfn, where, val);
  127.     return 1;
  128. }
  129.  
  130. static inline int pci_write_config_dword(struct pci_dev *dev, int where,
  131.                     u32 val)
  132. {
  133.     PciWrite32(dev->busnr, dev->devfn, where, val);
  134.     return 1;
  135. }
  136.  
  137. ///////////////////////////////////////////////////////////////////////////////
  138.  
  139. int dbg_open(char *path);
  140. int dbgprintf(const char* format, ...);
  141.  
  142. ///////////////////////////////////////////////////////////////////////////////
  143.  
  144. static inline evhandle_t CreateEvent(kevent_t *ev, u32_t flags)
  145. {
  146.      evhandle_t evh;
  147.  
  148.      __asm__ __volatile__ (
  149.      "call *__imp__CreateEvent"
  150.      :"=A"(evh.raw)
  151.      :"S" (ev), "c"(flags)
  152.      :"memory");
  153.      __asm__ __volatile__ ("":::"ebx","ecx","edx","esi", "edi");
  154.  
  155.      return evh;
  156. };
  157.  
  158. static inline void RaiseEvent(evhandle_t evh, u32_t flags, kevent_t *ev)
  159. {
  160.      __asm__ __volatile__ (
  161.      "call *__imp__RaiseEvent"
  162.      ::"a"(evh.handle),"b"(evh.euid),"d"(flags),"S" (ev)
  163.      :"memory");
  164.      __asm__ __volatile__ ("":::"ebx","ecx","edx","esi","edi");
  165.  
  166. };
  167.  
  168. static inline void WaitEvent(evhandle_t evh)
  169. {
  170.      __asm__ __volatile__ (
  171.      "call *__imp__WaitEvent"
  172.      ::"a"(evh.handle),"b"(evh.euid));
  173.      __asm__ __volatile__ ("":::"ebx","ecx","edx","esi","edi");
  174. };
  175.  
  176. static inline void DestroyEvent(evhandle_t evh)
  177. {
  178.      __asm__ __volatile__ (
  179.      "call *__imp__DestroyEvent"
  180.      ::"a"(evh.handle),"b"(evh.euid));
  181.      __asm__ __volatile__ ("":::"ebx","ecx","edx","esi","edi");
  182. };
  183.  
  184. static inline u32_t GetEvent(kevent_t *ev)
  185. {
  186.     u32_t  handle;
  187.  
  188.     __asm__ __volatile__ (
  189.     "call *__imp__GetEvent"
  190.     :"=a"(handle)
  191.     :"D"(ev)
  192.     :"memory");
  193.     __asm__ __volatile__ ("":::"ebx","ecx","edx", "esi","edi");
  194.      return handle;
  195. };
  196.  
  197.  
  198. static inline int GetScreenSize(void)
  199. {
  200.   int retval;
  201.  
  202.   asm("int $0x40"
  203.       :"=a"(retval)
  204.       :"a"(61), "b"(1));
  205.   return retval;
  206. }
  207.  
  208. static inline int GetScreenBpp(void)
  209. {
  210.   int retval;
  211.  
  212.   asm("int $0x40"
  213.       :"=a"(retval)
  214.       :"a"(61), "b"(2));
  215.   return retval;
  216. }
  217.  
  218. static inline int GetScreenPitch(void)
  219. {
  220.   int retval;
  221.  
  222.   asm("int $0x40"
  223.       :"=a"(retval)
  224.       :"a"(61), "b"(3));
  225.   return retval;
  226. }
  227.  
  228. static inline u32_t GetPgAddr(void *mem)
  229. {
  230.      u32_t retval;
  231.  
  232.      __asm__ __volatile__ (
  233.      "call *__imp__GetPgAddr \n\t"
  234.      :"=a" (retval)
  235.      :"a" (mem) );
  236.      return retval;
  237. };
  238.  
  239. static inline void CommitPages(void *mem, u32_t page, u32_t size)
  240. {
  241.      size = (size+4095) & ~4095;
  242.      __asm__ __volatile__ (
  243.      "call *__imp__CommitPages"
  244.      ::"a" (page), "b"(mem),"c"(size>>12)
  245.      :"edx" );
  246.      __asm__ __volatile__ ("":::"eax","ebx","ecx");
  247. };
  248.  
  249. static inline void UnmapPages(void *mem, size_t size)
  250. {
  251.      size = (size+4095) & ~4095;
  252.      __asm__ __volatile__ (
  253.      "call *__imp__UnmapPages"
  254.      ::"a" (mem), "c"(size>>12)
  255.      :"edx");
  256.      __asm__ __volatile__ ("":::"eax","ecx");
  257. };
  258.  
  259. static inline void usleep(u32_t delay)
  260. {
  261.      if( !delay )
  262.         delay++;
  263.      delay*= 500;
  264.  
  265.      while(delay--)
  266.         __asm__ __volatile__(
  267.         "xorl %%eax, %%eax \n\t"
  268.         "cpuid \n\t"
  269.         :::"eax","ebx","ecx","edx");
  270.      };
  271.  
  272. static inline void udelay(u32_t delay)
  273. {
  274.     if(!delay) delay++;
  275.     delay*= 100;
  276.  
  277.     while(delay--)
  278.     {
  279.         __asm__ __volatile__(
  280.         "xorl %%eax, %%eax \n\t"
  281.         "cpuid"
  282.         :::"eax","ebx","ecx","edx" );
  283.     }
  284. }
  285.  
  286. static inline void msleep(unsigned int msecs)
  287. {
  288.     msecs /= 10;
  289.     if(!msecs) msecs = 1;
  290.  
  291.      __asm__ __volatile__ (
  292.      "call *__imp__Delay"
  293.      ::"b" (msecs));
  294.      __asm__ __volatile__ (
  295.      "":::"ebx");
  296.  
  297. };
  298.  
  299. static inline void mdelay(u32_t time)
  300. {
  301.     time /= 10;
  302.     if(!time) time = 1;
  303.  
  304.      __asm__ __volatile__ (
  305.      "call *__imp__Delay"
  306.      ::"b" (time));
  307.      __asm__ __volatile__ (
  308.      "":::"ebx");
  309.  
  310. };
  311.  
  312. static inline u32_t __PciApi(int cmd)
  313. {
  314.      u32_t retval;
  315.  
  316.      __asm__ __volatile__ (
  317.      "call *__imp__PciApi \n\t"
  318.      "movzxb %%al, %%eax"
  319.      :"=a" (retval)
  320.      :"a" (cmd)
  321.      :"cc");
  322.  
  323.      return retval;
  324. };
  325.  
  326. static inline void* __CreateObject(u32_t pid, size_t size)
  327. {
  328.      void *retval;
  329.  
  330.      __asm__ __volatile__ (
  331.      "call *__imp__CreateObject \n\t"
  332.      :"=a" (retval)
  333.      :"a" (size),"b"(pid)
  334.      :"esi","edi", "memory");
  335.      return retval;
  336. }
  337.  
  338. static inline void __DestroyObject(void *obj)
  339. {
  340.      __asm__ __volatile__ (
  341.      "call *__imp__DestroyObject \n\t"
  342.      :
  343.      :"a" (obj));
  344.      __asm__ __volatile__ (
  345.      ""
  346.      :::"eax","ebx","ecx","edx","esi","edi","cc","memory");
  347. }
  348.  
  349. static inline u32_t GetService(const char *name)
  350. {
  351.     u32_t handle;
  352.  
  353.     __asm__ __volatile__
  354.     (
  355.      "pushl %%eax \n\t"
  356.      "call *__imp__GetService"
  357.      :"=a" (handle)
  358.      :"a" (name)
  359.      :"ebx","ecx","edx","esi", "edi"
  360.   );
  361.   return handle;
  362. };
  363.  
  364. static inline u32_t safe_cli(void)
  365. {
  366.      u32_t ifl;
  367.      __asm__ __volatile__ (
  368.      "pushf\n\t"
  369.      "popl %0\n\t"
  370.      "cli\n"
  371.      : "=r" (ifl));
  372.     return ifl;
  373. }
  374.  
  375. static inline void safe_sti(u32_t efl)
  376. {
  377.      if (efl & (1<<9))
  378.         __asm__ __volatile__ ("sti");
  379. }
  380.  
  381. static inline u32_t get_eflags(void)
  382. {
  383.     u32_t val;
  384.     asm volatile (
  385.     "pushfl\n\t"
  386.     "popl %0\n"
  387.     : "=r" (val));
  388.     return val;
  389. }
  390.  
  391. static inline void __clear (void * dst, unsigned len)
  392. {
  393.      u32_t tmp;
  394.      __asm__ __volatile__ (
  395.      "cld \n\t"
  396.      "rep stosb \n"
  397.      :"=c"(tmp),"=D"(tmp)
  398.      :"a"(0),"c"(len),"D"(dst));
  399.      __asm__ __volatile__ ("":::"ecx","edi");
  400. };
  401.  
  402. static inline void out8(const u16_t port, const u8_t val)
  403. {
  404.     __asm__ __volatile__
  405.     ("outb  %1, %0\n" : : "dN"(port), "a"(val));
  406. }
  407.  
  408. static inline void out16(const u16_t port, const u16_t val)
  409. {
  410.     __asm__ __volatile__
  411.     ("outw  %1, %0\n" : : "dN"(port), "a"(val));
  412. }
  413.  
  414. static inline void out32(const u16_t port, const u32_t val)
  415. {
  416.     __asm__ __volatile__
  417.     ("outl  %1, %0\n" : : "dN"(port), "a"(val));
  418. }
  419.  
  420. static inline u8_t in8(const u16_t port)
  421. {
  422.     u8_t tmp;
  423.     __asm__ __volatile__
  424.     ("inb %1, %0\n" : "=a"(tmp) : "dN"(port));
  425.     return tmp;
  426. };
  427.  
  428. static inline u16_t in16(const u16_t port)
  429. {
  430.     u16_t tmp;
  431.     __asm__ __volatile__
  432.     ("inw %1, %0\n" : "=a"(tmp) : "dN"(port));
  433.     return tmp;
  434. };
  435.  
  436. static inline u32_t in32(const u16_t port)
  437. {
  438.     u32_t tmp;
  439.     __asm__ __volatile__
  440.     ("inl %1, %0\n" : "=a"(tmp) : "dN"(port));
  441.     return tmp;
  442. };
  443.  
  444. static inline void delay(int time)
  445. {
  446.      __asm__ __volatile__ (
  447.      "call *__imp__Delay"
  448.      ::"b" (time));
  449.      __asm__ __volatile__ (
  450.      "":::"ebx");
  451.  
  452. }
  453.  
  454. static inline void change_task(void)
  455. {
  456.      __asm__ __volatile__ (
  457.      "call *__imp__ChangeTask");
  458. }
  459.  
  460. static inline void sysSetScreen(int width, int height, int pitch)
  461. {
  462.     __asm__ __volatile__
  463.     (
  464.         "call *__imp__SetScreen"
  465.         :
  466.         :"a" (width-1),"d"(height-1), "c"(pitch)
  467.     );
  468.     __asm__ __volatile__
  469.     ("" :::"eax","ecx","edx");
  470. }
  471.  
  472. int drm_order(unsigned long size);
  473.  
  474. static inline void __iomem *ioremap(uint32_t offset, size_t size)
  475. {
  476.     return (void __iomem*) MapIoMem(offset, size, PG_SW|PG_NOCACHE);
  477. }
  478.  
  479. static inline void iounmap(void *addr)
  480. {
  481.     FreeKernelSpace(addr);
  482. }
  483.  
  484. static inline void __SysMsgBoardStr(char *text)
  485. {
  486.     __asm__ __volatile__(
  487.     "call *__imp__SysMsgBoardStr"
  488.     ::"S" (text));
  489. };
  490.  
  491. #define rmb()   asm volatile("lfence":::"memory")
  492.  
  493. static inline void *vzalloc(unsigned long size)
  494. {
  495.     void *mem;
  496.  
  497.     mem = KernelAlloc(size);
  498.     if(mem)
  499.         memset(mem, 0, size);
  500.  
  501.    return mem;
  502. };
  503.  
  504. static inline void vfree(void *addr)
  505. {
  506.     KernelFree(addr);
  507. }
  508.  
  509. static inline int power_supply_is_system_supplied(void) { return -1; }
  510.  
  511. #define RWSEM_UNLOCKED_VALUE            0x00000000
  512. #define RWSEM_ACTIVE_BIAS               0x00000001
  513. #define RWSEM_ACTIVE_MASK               0x0000ffff
  514. #define RWSEM_WAITING_BIAS              (-0x00010000)
  515. #define RWSEM_ACTIVE_READ_BIAS          RWSEM_ACTIVE_BIAS
  516. #define RWSEM_ACTIVE_WRITE_BIAS         (RWSEM_WAITING_BIAS + RWSEM_ACTIVE_BIAS)
  517.  
  518.  
  519. //static void init_rwsem(struct rw_semaphore *sem)
  520. //{
  521. //    sem->count = RWSEM_UNLOCKED_VALUE;
  522. //    spin_lock_init(&sem->wait_lock);
  523. //    INIT_LIST_HEAD(&sem->wait_list);
  524. //}
  525.  
  526. #endif
  527.