Subversion Repositories Kolibri OS

Rev

Rev 1239 | Go to most recent revision | Blame | 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.      :"ebx","edx","esi","edi", "memory");
  239. }
  240.  
  241.  
  242. /*
  243. u32 __RegService(char *name, srv_proc_t proc)
  244. {
  245.   u32 retval;
  246.  
  247.   asm __volatile__
  248.   (
  249.     "pushl %%eax \n\t"
  250.     "pushl %%ebx \n\t"
  251.     "call *__imp__RegService \n\t"
  252.     :"=eax" (retval)
  253.     :"a" (proc), "b" (name)
  254.     :"memory"
  255.   );
  256.   return retval;
  257. };
  258. */
  259.  
  260.  
  261. static inline u32_t GetService(const char *name)
  262. {
  263.     u32_t handle;
  264.  
  265.     __asm__ __volatile__
  266.     (
  267.      "pushl %%eax \n\t"
  268.      "call *__imp__GetService"
  269.      :"=eax" (handle)
  270.      :"a" (name)
  271.      :"ebx","ecx","edx","esi", "edi"
  272.   );
  273.   return handle;
  274. };
  275.  
  276. static inline u32_t safe_cli(void)
  277. {
  278.      u32_t ifl;
  279.      __asm__ __volatile__ (
  280.      "pushf\n\t"
  281.      "popl %0\n\t"
  282.      "cli\n"
  283.      : "=r" (ifl));
  284.     return ifl;
  285. }
  286.  
  287. static inline void safe_sti(u32_t ifl)
  288. {
  289.      __asm__ __volatile__ (
  290.      "pushl %0\n\t"
  291.      "popf\n"
  292.      : : "r" (ifl)
  293.         );
  294. }
  295.  
  296. static inline void __clear (void * dst, unsigned len)
  297. {
  298.      u32_t tmp;
  299.      __asm__ __volatile__ (
  300. //     "xorl %%eax, %%eax \n\t"
  301.      "cld \n\t"
  302.      "rep stosb \n"
  303.      :"=c"(tmp),"=D"(tmp)
  304.      :"a"(0),"c"(len),"D"(dst));
  305.      __asm__ __volatile__ ("":::"ecx","edi");
  306. };
  307.  
  308. static inline void out8(const u16_t port, const u8_t val)
  309. {
  310.     __asm__ __volatile__
  311.     ("outb  %1, %0\n" : : "dN"(port), "a"(val));
  312. }
  313.  
  314. static inline void out16(const u16_t port, const u16_t val)
  315. {
  316.     __asm__ __volatile__
  317.     ("outw  %1, %0\n" : : "dN"(port), "a"(val));
  318. }
  319.  
  320. static inline void out32(const u16_t port, const u32_t val)
  321. {
  322.     __asm__ __volatile__
  323.     ("outl  %1, %0\n" : : "dN"(port), "a"(val));
  324. }
  325.  
  326. static inline u8_t in8(const u16_t port)
  327. {
  328.     u8_t tmp;
  329.     __asm__ __volatile__
  330.     ("inb %1, %0\n" : "=a"(tmp) : "dN"(port));
  331.     return tmp;
  332. };
  333.  
  334. static inline u16_t in16(const u16_t port)
  335. {
  336.     u16_t tmp;
  337.     __asm__ __volatile__
  338.     ("inw %1, %0\n" : "=a"(tmp) : "dN"(port));
  339.     return tmp;
  340. };
  341.  
  342. static inline u32_t in32(const u16_t port)
  343. {
  344.     u32_t tmp;
  345.     __asm__ __volatile__
  346.     ("inl %1, %0\n" : "=a"(tmp) : "dN"(port));
  347.     return tmp;
  348. };
  349.  
  350. static inline void delay(int time)
  351. {
  352.      __asm__ __volatile__ (
  353.      "call *__imp__Delay"
  354.      ::"b" (time));
  355.      __asm__ __volatile__ (
  356.      "":::"ebx");
  357.  
  358. }
  359.  
  360. static inline void change_task()
  361. {
  362.      __asm__ __volatile__ (
  363.      "call *__imp__ChangeTask");
  364. }
  365.  
  366. static inline sysSetScreen(int width, int height, int pitch)
  367. {
  368.     __asm__ __volatile__
  369.     (
  370.         "call *__imp__SetScreen"
  371.         :
  372.         :"a" (width-1),"d"(height-1), "c"(pitch)
  373.     );
  374.     __asm__ __volatile__
  375.     ("" :::"eax","ecx","edx");
  376. }
  377.  
  378. int drm_order(unsigned long size);
  379.  
  380. static inline void __iomem *ioremap(uint32_t offset, size_t size)
  381. {
  382.     return (void __iomem*) MapIoMem(offset, size, 3);
  383. }
  384.  
  385. static inline void iounmap(void *addr)
  386. {
  387.     FreeKernelSpace(addr);
  388. }
  389.  
  390. static inline void *
  391. pci_alloc_consistent(struct pci_dev *hwdev, size_t size,
  392.                       addr_t *dma_handle)
  393. {
  394.     *dma_handle = AllocPages(size >> 12);
  395.     return (void*)MapIoMem(*dma_handle, size, PG_SW+PG_NOCACHE);
  396. }
  397.  
  398. #endif
  399.