Subversion Repositories Kolibri OS

Rev

Rev 1230 | 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. extern 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. extern 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. extern 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. extern 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. extern 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. extern 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. extern inline void usleep(u32_t delay)
  168. {
  169.      if( !delay )
  170.         delay++;
  171.      delay*= 256;
  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*= 256;
  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. static inline u32_t safe_cli(void)
  261. {
  262.      u32_t ifl;
  263.      __asm__ __volatile__ (
  264.      "pushf\n\t"
  265.      "popl %0\n\t"
  266.      "cli\n"
  267.      : "=r" (ifl));
  268.     return ifl;
  269. }
  270.  
  271. static inline void safe_sti(u32_t ifl)
  272. {
  273.      __asm__ __volatile__ (
  274.      "pushl %0\n\t"
  275.      "popf\n"
  276.      : : "r" (ifl)
  277.         );
  278. }
  279.  
  280. static inline void __clear (void * dst, unsigned len)
  281. {
  282.      u32_t tmp;
  283.      __asm__ __volatile__ (
  284. //     "xorl %%eax, %%eax \n\t"
  285.      "cld \n\t"
  286.      "rep stosb \n"
  287.      :"=c"(tmp),"=D"(tmp)
  288.      :"a"(0),"c"(len),"D"(dst));
  289.      __asm__ __volatile__ ("":::"ecx","edi");
  290. };
  291.  
  292. static inline void out8(const u16_t port, const u8_t val)
  293. {
  294.     __asm__ __volatile__
  295.     ("outb  %1, %0\n" : : "dN"(port), "a"(val));
  296. }
  297.  
  298. static inline void out16(const u16_t port, const u16_t val)
  299. {
  300.     __asm__ __volatile__
  301.     ("outw  %1, %0\n" : : "dN"(port), "a"(val));
  302. }
  303.  
  304. static inline void out32(const u16_t port, const u32_t val)
  305. {
  306.     __asm__ __volatile__
  307.     ("outl  %1, %0\n" : : "dN"(port), "a"(val));
  308. }
  309.  
  310. static inline u8_t in8(const u16_t port)
  311. {
  312.     u8_t tmp;
  313.     __asm__ __volatile__
  314.     ("inb %1, %0\n" : "=a"(tmp) : "dN"(port));
  315.     return tmp;
  316. };
  317.  
  318. static inline u16_t in16(const u16_t port)
  319. {
  320.     u16_t tmp;
  321.     __asm__ __volatile__
  322.     ("inw %1, %0\n" : "=a"(tmp) : "dN"(port));
  323.     return tmp;
  324. };
  325.  
  326. static inline u32_t in32(const u16_t port)
  327. {
  328.     u32_t tmp;
  329.     __asm__ __volatile__
  330.     ("inl %1, %0\n" : "=a"(tmp) : "dN"(port));
  331.     return tmp;
  332. };
  333.  
  334. static inline void delay(int time)
  335. {
  336.      __asm__ __volatile__ (
  337.      "call *__imp__Delay"
  338.      ::"b" (time));
  339.      __asm__ __volatile__ (
  340.      "":::"ebx");
  341.  
  342. }
  343.  
  344. static inline void change_task()
  345. {
  346.      __asm__ __volatile__ (
  347.      "call *__imp__ChangeTask");
  348. }
  349.  
  350. static inline sysSetScreen(int width, int height, int pitch)
  351. {
  352.     __asm__ __volatile__
  353.     (
  354.         "call *__imp__SetScreen"
  355.         :
  356.         :"a" (width-1),"d"(height-1), "c"(pitch)
  357.     );
  358.     __asm__ __volatile__
  359.     ("" :::"eax","ecx","edx");
  360. }
  361.  
  362. int drm_order(unsigned long size);
  363.  
  364. static inline void __iomem *ioremap(uint32_t offset, size_t size)
  365. {
  366.     return (void __iomem*) MapIoMem(offset, size, 3);
  367. }
  368.  
  369. static inline void iounmap(void *addr)
  370. {
  371.     FreeKernelSpace(addr);
  372. }
  373.  
  374. #endif
  375.