Subversion Repositories Kolibri OS

Rev

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