Subversion Repositories Kolibri OS

Rev

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