Subversion Repositories Kolibri OS

Rev

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