Subversion Repositories Kolibri OS

Rev

Rev 5272 | Rev 6102 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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