Subversion Repositories Kolibri OS

Rev

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