Subversion Repositories Kolibri OS

Rev

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