Subversion Repositories Kolibri OS

Rev

Rev 3243 | Rev 3482 | 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 int WaitEventTimeout(evhandle_t evh, int timeout)
  177. {
  178.     int retval;
  179.     __asm__ __volatile__ (
  180.     "call *__imp__WaitEventTimeout"
  181.     :"=a"(retval)
  182.     :"a"(evh.handle),"b"(evh.euid), "c"(timeout));
  183.     __asm__ __volatile__ ("":::"ebx","ecx","edx","esi","edi");
  184.     return retval;
  185. };
  186.  
  187. static inline void DestroyEvent(evhandle_t evh)
  188. {
  189.      __asm__ __volatile__ (
  190.      "call *__imp__DestroyEvent"
  191.      ::"a"(evh.handle),"b"(evh.euid));
  192.      __asm__ __volatile__ ("":::"ebx","ecx","edx","esi","edi");
  193. };
  194.  
  195. static inline u32_t GetEvent(kevent_t *ev)
  196. {
  197.     u32_t  handle;
  198.  
  199.     __asm__ __volatile__ (
  200.     "call *__imp__GetEvent"
  201.     :"=a"(handle)
  202.     :"D"(ev)
  203.     :"memory");
  204.     __asm__ __volatile__ ("":::"ebx","ecx","edx", "esi","edi");
  205.      return handle;
  206. };
  207.  
  208.  
  209. static inline int GetScreenSize(void)
  210. {
  211.   int retval;
  212.  
  213.   asm("int $0x40"
  214.       :"=a"(retval)
  215.       :"a"(61), "b"(1));
  216.   return retval;
  217. }
  218.  
  219. static inline int GetScreenBpp(void)
  220. {
  221.   int retval;
  222.  
  223.   asm("int $0x40"
  224.       :"=a"(retval)
  225.       :"a"(61), "b"(2));
  226.   return retval;
  227. }
  228.  
  229. static inline int GetScreenPitch(void)
  230. {
  231.   int retval;
  232.  
  233.   asm("int $0x40"
  234.       :"=a"(retval)
  235.       :"a"(61), "b"(3));
  236.   return retval;
  237. }
  238.  
  239. static inline u32_t GetPgAddr(void *mem)
  240. {
  241.      u32_t retval;
  242.  
  243.      __asm__ __volatile__ (
  244.      "call *__imp__GetPgAddr \n\t"
  245.      :"=a" (retval)
  246.      :"a" (mem) );
  247.      return retval;
  248. };
  249.  
  250. static inline void CommitPages(void *mem, u32_t page, u32_t size)
  251. {
  252.      size = (size+4095) & ~4095;
  253.      __asm__ __volatile__ (
  254.      "call *__imp__CommitPages"
  255.      ::"a" (page), "b"(mem),"c"(size>>12)
  256.      :"edx" );
  257.      __asm__ __volatile__ ("":::"eax","ebx","ecx");
  258. };
  259.  
  260. static inline void UnmapPages(void *mem, size_t size)
  261. {
  262.      size = (size+4095) & ~4095;
  263.      __asm__ __volatile__ (
  264.      "call *__imp__UnmapPages"
  265.      ::"a" (mem), "c"(size>>12)
  266.      :"edx");
  267.      __asm__ __volatile__ ("":::"eax","ecx");
  268. };
  269.  
  270. static inline void usleep(u32_t delay)
  271. {
  272.      if( !delay )
  273.         delay++;
  274.      delay*= 500;
  275.  
  276.      while(delay--)
  277.         __asm__ __volatile__(
  278.         "xorl %%eax, %%eax \n\t"
  279.         "cpuid \n\t"
  280.         :::"eax","ebx","ecx","edx");
  281.      };
  282.  
  283. static inline void udelay(u32_t delay)
  284. {
  285.     if(!delay) delay++;
  286.     delay*= 100;
  287.  
  288.     while(delay--)
  289.     {
  290.         __asm__ __volatile__(
  291.         "xorl %%eax, %%eax \n\t"
  292.         "cpuid"
  293.         :::"eax","ebx","ecx","edx" );
  294.     }
  295. }
  296.  
  297. static inline void msleep(unsigned int msecs)
  298. {
  299.     msecs /= 10;
  300.     if(!msecs) msecs = 1;
  301.  
  302.      __asm__ __volatile__ (
  303.      "call *__imp__Delay"
  304.      ::"b" (msecs));
  305.      __asm__ __volatile__ (
  306.      "":::"ebx");
  307.  
  308. };
  309.  
  310. static inline void mdelay(u32_t time)
  311. {
  312.     time /= 10;
  313.     if(!time) time = 1;
  314.  
  315.      __asm__ __volatile__ (
  316.      "call *__imp__Delay"
  317.      ::"b" (time));
  318.      __asm__ __volatile__ (
  319.      "":::"ebx");
  320.  
  321. };
  322.  
  323. static inline u32_t __PciApi(int cmd)
  324. {
  325.      u32_t retval;
  326.  
  327.      __asm__ __volatile__ (
  328.      "call *__imp__PciApi \n\t"
  329.      "movzxb %%al, %%eax"
  330.      :"=a" (retval)
  331.      :"a" (cmd)
  332.      :"cc");
  333.  
  334.      return retval;
  335. };
  336.  
  337. static inline void* __CreateObject(u32_t pid, size_t size)
  338. {
  339.      void *retval;
  340.  
  341.      __asm__ __volatile__ (
  342.      "call *__imp__CreateObject \n\t"
  343.      :"=a" (retval)
  344.      :"a" (size),"b"(pid)
  345.      :"esi","edi", "memory");
  346.      return retval;
  347. }
  348.  
  349. static inline void __DestroyObject(void *obj)
  350. {
  351.      __asm__ __volatile__ (
  352.      "call *__imp__DestroyObject \n\t"
  353.      :
  354.      :"a" (obj));
  355.      __asm__ __volatile__ (
  356.      ""
  357.      :::"eax","ebx","ecx","edx","esi","edi","cc","memory");
  358. }
  359.  
  360. static inline u32_t GetService(const char *name)
  361. {
  362.     u32_t handle;
  363.  
  364.     __asm__ __volatile__
  365.     (
  366.      "pushl %%eax \n\t"
  367.      "call *__imp__GetService"
  368.      :"=a" (handle)
  369.      :"a" (name)
  370.      :"ebx","ecx","edx","esi", "edi"
  371.   );
  372.   return handle;
  373. };
  374.  
  375. static inline u32_t safe_cli(void)
  376. {
  377.      u32_t ifl;
  378.      __asm__ __volatile__ (
  379.      "pushf\n\t"
  380.      "popl %0\n\t"
  381.      "cli\n"
  382.      : "=r" (ifl));
  383.     return ifl;
  384. }
  385.  
  386. static inline void safe_sti(u32_t efl)
  387. {
  388.      if (efl & (1<<9))
  389.         __asm__ __volatile__ ("sti");
  390. }
  391.  
  392. static inline u32_t get_eflags(void)
  393. {
  394.     u32_t val;
  395.     asm volatile (
  396.     "pushfl\n\t"
  397.     "popl %0\n"
  398.     : "=r" (val));
  399.     return val;
  400. }
  401.  
  402. static inline void __clear (void * dst, unsigned len)
  403. {
  404.      u32_t tmp;
  405.      __asm__ __volatile__ (
  406.      "cld \n\t"
  407.      "rep stosb \n"
  408.      :"=c"(tmp),"=D"(tmp)
  409.      :"a"(0),"c"(len),"D"(dst));
  410.      __asm__ __volatile__ ("":::"ecx","edi");
  411. };
  412.  
  413. static inline void out8(const u16_t port, const u8_t val)
  414. {
  415.     __asm__ __volatile__
  416.     ("outb  %1, %0\n" : : "dN"(port), "a"(val));
  417. }
  418.  
  419. static inline void out16(const u16_t port, const u16_t val)
  420. {
  421.     __asm__ __volatile__
  422.     ("outw  %1, %0\n" : : "dN"(port), "a"(val));
  423. }
  424.  
  425. static inline void out32(const u16_t port, const u32_t val)
  426. {
  427.     __asm__ __volatile__
  428.     ("outl  %1, %0\n" : : "dN"(port), "a"(val));
  429. }
  430.  
  431. static inline u8_t in8(const u16_t port)
  432. {
  433.     u8_t tmp;
  434.     __asm__ __volatile__
  435.     ("inb %1, %0\n" : "=a"(tmp) : "dN"(port));
  436.     return tmp;
  437. };
  438.  
  439. static inline u16_t in16(const u16_t port)
  440. {
  441.     u16_t tmp;
  442.     __asm__ __volatile__
  443.     ("inw %1, %0\n" : "=a"(tmp) : "dN"(port));
  444.     return tmp;
  445. };
  446.  
  447. static inline u32_t in32(const u16_t port)
  448. {
  449.     u32_t tmp;
  450.     __asm__ __volatile__
  451.     ("inl %1, %0\n" : "=a"(tmp) : "dN"(port));
  452.     return tmp;
  453. };
  454.  
  455. static inline void delay(int time)
  456. {
  457.      __asm__ __volatile__ (
  458.      "call *__imp__Delay"
  459.      ::"b" (time));
  460.      __asm__ __volatile__ (
  461.      "":::"ebx");
  462.  
  463. }
  464.  
  465. static inline void change_task(void)
  466. {
  467.      __asm__ __volatile__ (
  468.      "call *__imp__ChangeTask");
  469. }
  470.  
  471. static inline void sysSetScreen(int width, int height, int pitch)
  472. {
  473.     __asm__ __volatile__
  474.     (
  475.         "call *__imp__SetScreen"
  476.         :
  477.         :"a" (width-1),"d"(height-1), "c"(pitch)
  478.     );
  479.     __asm__ __volatile__
  480.     ("" :::"eax","ecx","edx");
  481. }
  482.  
  483. int drm_order(unsigned long size);
  484.  
  485. static inline void __iomem *ioremap(uint32_t offset, size_t size)
  486. {
  487.     return (void __iomem*) MapIoMem(offset, size, PG_SW|PG_NOCACHE);
  488. }
  489.  
  490. static inline void __iomem *ioremap_wc(uint32_t offset, size_t size)
  491. {
  492.     return (void __iomem*) MapIoMem(offset, size, PG_SW|PG_NOCACHE);
  493. }
  494.  
  495.  
  496. static inline void iounmap(void *addr)
  497. {
  498.     FreeKernelSpace(addr);
  499. }
  500.  
  501. static inline void __SysMsgBoardStr(char *text)
  502. {
  503.     __asm__ __volatile__(
  504.     "call *__imp__SysMsgBoardStr"
  505.     ::"S" (text));
  506. };
  507.  
  508. #define rmb()   asm volatile("lfence":::"memory")
  509.  
  510. static inline void *vzalloc(unsigned long size)
  511. {
  512.     void *mem;
  513.  
  514.     mem = KernelAlloc(size);
  515.     if(mem)
  516.         memset(mem, 0, size);
  517.  
  518.    return mem;
  519. };
  520.  
  521. static inline void vfree(void *addr)
  522. {
  523.     KernelFree(addr);
  524. }
  525.  
  526. static inline int power_supply_is_system_supplied(void) { return -1; }
  527.  
  528. #define RWSEM_UNLOCKED_VALUE            0x00000000
  529. #define RWSEM_ACTIVE_BIAS               0x00000001
  530. #define RWSEM_ACTIVE_MASK               0x0000ffff
  531. #define RWSEM_WAITING_BIAS              (-0x00010000)
  532. #define RWSEM_ACTIVE_READ_BIAS          RWSEM_ACTIVE_BIAS
  533. #define RWSEM_ACTIVE_WRITE_BIAS         (RWSEM_WAITING_BIAS + RWSEM_ACTIVE_BIAS)
  534.  
  535.  
  536. //static void init_rwsem(struct rw_semaphore *sem)
  537. //{
  538. //    sem->count = RWSEM_UNLOCKED_VALUE;
  539. //    spin_lock_init(&sem->wait_lock);
  540. //    INIT_LIST_HEAD(&sem->wait_list);
  541. //}
  542.  
  543. #endif
  544.