Subversion Repositories Kolibri OS

Rev

Rev 1246 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1.  
  2. #ifndef __SYSCALL_H__
  3. #define __SYSCALL_H__
  4.  
  5.  
  6. #define OS_BASE   0x80000000
  7.  
  8. typedef struct
  9. {
  10.   u32_t      handle;
  11.   u32_t      io_code;
  12.   void       *input;
  13.   int        inp_size;
  14.   void       *output;
  15.   int        out_size;
  16. }ioctl_t;
  17.  
  18. typedef int (__stdcall *srv_proc_t)(ioctl_t *);
  19.  
  20. #define ERR_OK       0
  21. #define ERR_PARAM   -1
  22.  
  23.  
  24. u32_t drvEntry(int, char *)__asm__("_drvEntry");
  25.  
  26. ///////////////////////////////////////////////////////////////////////////////
  27.  
  28. #define STDCALL __attribute__ ((stdcall)) __attribute__ ((dllimport))
  29. #define IMPORT __attribute__ ((dllimport))
  30.  
  31. ///////////////////////////////////////////////////////////////////////////////
  32.  
  33. #define SysMsgBoardStr  __SysMsgBoardStr
  34. #define PciApi          __PciApi
  35. //#define RegService      __RegService
  36. #define CreateObject    __CreateObject
  37. #define DestroyObject   __DestroyObject
  38.  
  39. ///////////////////////////////////////////////////////////////////////////////
  40.  
  41. #define PG_SW       0x003
  42. #define PG_NOCACHE  0x018
  43.  
  44. void*  STDCALL AllocKernelSpace(size_t size)__asm__("AllocKernelSpace");
  45. void   STDCALL FreeKernelSpace(void *mem)__asm__("FreeKernelSpace");
  46. addr_t STDCALL MapIoMem(addr_t base, size_t size, u32_t flags)__asm__("MapIoMem");
  47. void*  STDCALL KernelAlloc(size_t size)__asm__("KernelAlloc");
  48. void*  STDCALL KernelFree(void *mem)__asm__("KernelFree");
  49. void*  STDCALL UserAlloc(size_t size)__asm__("UserAlloc");
  50. int    STDCALL UserFree(void *mem)__asm__("UserFree");
  51.  
  52. void*  STDCALL GetDisplay()__asm__("GetDisplay");
  53.  
  54.  
  55. addr_t STDCALL AllocPage()__asm__("AllocPage");
  56. addr_t STDCALL AllocPages(count_t count)__asm__("AllocPages");
  57.  
  58. void* STDCALL CreateRingBuffer(size_t size, u32_t map)__asm__("CreateRingBuffer");
  59.  
  60. u32_t STDCALL RegService(char *name, srv_proc_t proc)__asm__("RegService");
  61.  
  62. int   STDCALL AttachIntHandler(int irq, void *handler, u32_t access) __asm__("AttachIntHandler");
  63.  
  64.  
  65. ///////////////////////////////////////////////////////////////////////////////
  66.  
  67. void   STDCALL SetMouseData(int btn, int x, int y,
  68.                             int z, int h)__asm__("SetMouseData");
  69.  
  70. static u32_t PciApi(int cmd);
  71.  
  72. u8_t  STDCALL PciRead8 (u32_t bus, u32_t devfn, u32_t reg)__asm__("PciRead8");
  73. u16_t STDCALL PciRead16(u32_t bus, u32_t devfn, u32_t reg)__asm__("PciRead16");
  74. u32_t STDCALL PciRead32(u32_t bus, u32_t devfn, u32_t reg)__asm__("PciRead32");
  75.  
  76. u32_t STDCALL PciWrite8 (u32_t bus, u32_t devfn, u32_t reg,u8_t val) __asm__("PciWrite8");
  77. u32_t STDCALL PciWrite16(u32_t bus, u32_t devfn, u32_t reg,u16_t val)__asm__("PciWrite16");
  78. u32_t STDCALL PciWrite32(u32_t bus, u32_t devfn, u32_t reg,u32_t val)__asm__("PciWrite32");
  79.  
  80. #define pciReadByte(tag, reg) \
  81.         PciRead8(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg))
  82.  
  83. #define pciReadWord(tag, reg) \
  84.         PciRead16(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg))
  85.  
  86. #define pciReadLong(tag, reg) \
  87.         PciRead32(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg))
  88.  
  89. #define pciWriteByte(tag, reg, val) \
  90.         PciWrite8(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg),(val))
  91.  
  92. #define pciWriteWord(tag, reg, val) \
  93.         PciWrite16(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg),(val))
  94.  
  95. #define pciWriteLong(tag, reg, val) \
  96.         PciWrite32(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg),(val))
  97.  
  98.  
  99. ///////////////////////////////////////////////////////////////////////////////
  100.  
  101. int dbg_open(char *path);
  102. int dbgprintf(const char* format, ...);
  103.  
  104. ///////////////////////////////////////////////////////////////////////////////
  105.  
  106. static inline int GetScreenSize()
  107. {
  108.   int retval;
  109.  
  110.   asm("int $0x40"
  111.       :"=a"(retval)
  112.       :"a"(61), "b"(1));
  113.   return retval;
  114. }
  115.  
  116. static inline int GetScreenBpp()
  117. {
  118.   int retval;
  119.  
  120.   asm("int $0x40"
  121.       :"=a"(retval)
  122.       :"a"(61), "b"(2));
  123.   return retval;
  124. }
  125.  
  126. static inline int GetScreenPitch()
  127. {
  128.   int retval;
  129.  
  130.   asm("int $0x40"
  131.       :"=a"(retval)
  132.       :"a"(61), "b"(3));
  133.   return retval;
  134. }
  135.  
  136. static inline u32_t GetPgAddr(void *mem)
  137. {
  138.      u32_t retval;
  139.  
  140.      __asm__ __volatile__ (
  141.      "call *__imp__GetPgAddr \n\t"
  142.      :"=eax" (retval)
  143.      :"a" (mem) );
  144.      return retval;
  145. };
  146.  
  147. static inline void CommitPages(void *mem, u32_t page, u32_t size)
  148. {
  149.      size = (size+4095) & ~4095;
  150.      __asm__ __volatile__ (
  151.      "call *__imp__CommitPages"
  152.      ::"a" (page), "b"(mem),"c"(size>>12)
  153.      :"edx" );
  154.      __asm__ __volatile__ ("":::"eax","ebx","ecx");
  155. };
  156.  
  157. static inline void UnmapPages(void *mem, size_t size)
  158. {
  159.      size = (size+4095) & ~4095;
  160.      __asm__ __volatile__ (
  161.      "call *__imp__UnmapPages"
  162.      ::"a" (mem), "c"(size>>12)
  163.      :"edx");
  164.      __asm__ __volatile__ ("":::"eax","ecx");
  165. };
  166.  
  167. static inline void usleep(u32_t delay)
  168. {
  169.      if( !delay )
  170.         delay++;
  171.      delay*= 500;
  172.  
  173.      while(delay--)
  174.         __asm__ __volatile__(
  175.         "xorl %%eax, %%eax \n\t"
  176.         "cpuid \n\t"
  177.         :::"eax","ebx","ecx","edx");
  178.      };
  179.  
  180. static inline void udelay(u32_t delay)
  181. {
  182.     if(!delay) delay++;
  183.     delay*= 500;
  184.  
  185.     while(delay--)
  186.     {
  187.         __asm__ __volatile__(
  188.         "xorl %%eax, %%eax \n\t"
  189.         "cpuid"
  190.         :::"eax","ebx","ecx","edx" );
  191.     }
  192. }
  193.  
  194. static inline void mdelay(u32_t time)
  195. {
  196.     time /= 10;
  197.     if(!time) time = 1;
  198.  
  199.      __asm__ __volatile__ (
  200.      "call *__imp__Delay"
  201.      ::"b" (time));
  202.      __asm__ __volatile__ (
  203.      "":::"ebx");
  204.  
  205. };
  206.  
  207.  
  208. static inline u32_t __PciApi(int cmd)
  209. {
  210.      u32_t retval;
  211.  
  212.      __asm__ __volatile__ (
  213.      "call *__imp__PciApi"
  214.      :"=a" (retval)
  215.      :"a" (cmd)
  216.      :"memory");
  217.      return retval;
  218. };
  219.  
  220. static inline void* __CreateObject(u32_t pid, size_t size)
  221. {
  222.      void *retval;
  223.  
  224.      __asm__ __volatile__ (
  225.      "call *__imp__CreateObject \n\t"
  226.      :"=a" (retval)
  227.      :"a" (size),"b"(pid)
  228.      :"esi","edi", "memory");
  229.      return retval;
  230. }
  231.  
  232. static inline void __DestroyObject(void *obj)
  233. {
  234.      __asm__ __volatile__ (
  235.      "call *__imp__DestroyObject"
  236.      :
  237.      :"a" (obj));
  238.      __asm__ __volatile__ (
  239.      ""
  240.      :::"eax","ebx","ecx","edx","esi","edi","cc","memory");
  241. }
  242.  
  243.  
  244. /*
  245. u32 __RegService(char *name, srv_proc_t proc)
  246. {
  247.   u32 retval;
  248.  
  249.   asm __volatile__
  250.   (
  251.     "pushl %%eax \n\t"
  252.     "pushl %%ebx \n\t"
  253.     "call *__imp__RegService \n\t"
  254.     :"=eax" (retval)
  255.     :"a" (proc), "b" (name)
  256.     :"memory"
  257.   );
  258.   return retval;
  259. };
  260. */
  261.  
  262.  
  263. static inline u32_t GetService(const char *name)
  264. {
  265.     u32_t handle;
  266.  
  267.     __asm__ __volatile__
  268.     (
  269.      "pushl %%eax \n\t"
  270.      "call *__imp__GetService"
  271.      :"=eax" (handle)
  272.      :"a" (name)
  273.      :"ebx","ecx","edx","esi", "edi"
  274.   );
  275.   return handle;
  276. };
  277.  
  278. static inline u32_t safe_cli(void)
  279. {
  280.      u32_t ifl;
  281.      __asm__ __volatile__ (
  282.      "pushf\n\t"
  283.      "popl %0\n\t"
  284.      "cli\n"
  285.      : "=r" (ifl));
  286.     return ifl;
  287. }
  288.  
  289. static inline void safe_sti(u32_t ifl)
  290. {
  291.      __asm__ __volatile__ (
  292.      "pushl %0\n\t"
  293.      "popf\n"
  294.      : : "r" (ifl)
  295.         );
  296. }
  297.  
  298. static inline void __clear (void * dst, unsigned len)
  299. {
  300.      u32_t tmp;
  301.      __asm__ __volatile__ (
  302. //     "xorl %%eax, %%eax \n\t"
  303.      "cld \n\t"
  304.      "rep stosb \n"
  305.      :"=c"(tmp),"=D"(tmp)
  306.      :"a"(0),"c"(len),"D"(dst));
  307.      __asm__ __volatile__ ("":::"ecx","edi");
  308. };
  309.  
  310. static inline void out8(const u16_t port, const u8_t val)
  311. {
  312.     __asm__ __volatile__
  313.     ("outb  %1, %0\n" : : "dN"(port), "a"(val));
  314. }
  315.  
  316. static inline void out16(const u16_t port, const u16_t val)
  317. {
  318.     __asm__ __volatile__
  319.     ("outw  %1, %0\n" : : "dN"(port), "a"(val));
  320. }
  321.  
  322. static inline void out32(const u16_t port, const u32_t val)
  323. {
  324.     __asm__ __volatile__
  325.     ("outl  %1, %0\n" : : "dN"(port), "a"(val));
  326. }
  327.  
  328. static inline u8_t in8(const u16_t port)
  329. {
  330.     u8_t tmp;
  331.     __asm__ __volatile__
  332.     ("inb %1, %0\n" : "=a"(tmp) : "dN"(port));
  333.     return tmp;
  334. };
  335.  
  336. static inline u16_t in16(const u16_t port)
  337. {
  338.     u16_t tmp;
  339.     __asm__ __volatile__
  340.     ("inw %1, %0\n" : "=a"(tmp) : "dN"(port));
  341.     return tmp;
  342. };
  343.  
  344. static inline u32_t in32(const u16_t port)
  345. {
  346.     u32_t tmp;
  347.     __asm__ __volatile__
  348.     ("inl %1, %0\n" : "=a"(tmp) : "dN"(port));
  349.     return tmp;
  350. };
  351.  
  352. static inline void delay(int time)
  353. {
  354.      __asm__ __volatile__ (
  355.      "call *__imp__Delay"
  356.      ::"b" (time));
  357.      __asm__ __volatile__ (
  358.      "":::"ebx");
  359.  
  360. }
  361.  
  362. static inline void change_task()
  363. {
  364.      __asm__ __volatile__ (
  365.      "call *__imp__ChangeTask");
  366. }
  367.  
  368. static inline sysSetScreen(int width, int height, int pitch)
  369. {
  370.     __asm__ __volatile__
  371.     (
  372.         "call *__imp__SetScreen"
  373.         :
  374.         :"a" (width-1),"d"(height-1), "c"(pitch)
  375.     );
  376.     __asm__ __volatile__
  377.     ("" :::"eax","ecx","edx");
  378. }
  379.  
  380. int drm_order(unsigned long size);
  381.  
  382. static inline void __iomem *ioremap(uint32_t offset, size_t size)
  383. {
  384.     return (void __iomem*) MapIoMem(offset, size, 3);
  385. }
  386.  
  387. static inline void iounmap(void *addr)
  388. {
  389.     FreeKernelSpace(addr);
  390. }
  391.  
  392. static inline void *
  393. pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
  394.                       addr_t *dma_handle)
  395. {
  396.     *dma_handle = AllocPages(size >> 12);
  397.     return (void*)MapIoMem(*dma_handle, size, PG_SW+PG_NOCACHE);
  398. }
  399.  
  400. #endif
  401.