Subversion Repositories Kolibri OS

Rev

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