Subversion Repositories Kolibri OS

Rev

Rev 1222 | 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 AllocPages(count_t count)__asm__("AllocPages");
  56.  
  57. void* STDCALL CreateRingBuffer(size_t size, u32_t map)__asm__("CreateRingBuffer");
  58.  
  59. u32_t STDCALL RegService(char *name, srv_proc_t proc)__asm__("RegService");
  60.  
  61. int   STDCALL AttachIntHandler(int irq, void *handler, u32_t access) __asm__("AttachIntHandler");
  62.  
  63.  
  64. ///////////////////////////////////////////////////////////////////////////////
  65.  
  66. void   STDCALL SetMouseData(int btn, int x, int y,
  67.                             int z, int h)__asm__("SetMouseData");
  68.  
  69. static u32_t PciApi(int cmd);
  70.  
  71. u8_t  STDCALL PciRead8 (u32_t bus, u32_t devfn, u32_t reg)__asm__("PciRead8");
  72. u16_t STDCALL PciRead16(u32_t bus, u32_t devfn, u32_t reg)__asm__("PciRead16");
  73. u32_t STDCALL PciRead32(u32_t bus, u32_t devfn, u32_t reg)__asm__("PciRead32");
  74.  
  75. u32_t STDCALL PciWrite8 (u32_t bus, u32_t devfn, u32_t reg,u8_t val) __asm__("PciWrite8");
  76. u32_t STDCALL PciWrite16(u32_t bus, u32_t devfn, u32_t reg,u16_t val)__asm__("PciWrite16");
  77. u32_t STDCALL PciWrite32(u32_t bus, u32_t devfn, u32_t reg,u32_t val)__asm__("PciWrite32");
  78.  
  79. #define pciReadByte(tag, reg) \
  80.         PciRead8(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg))
  81.  
  82. #define pciReadWord(tag, reg) \
  83.         PciRead16(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg))
  84.  
  85. #define pciReadLong(tag, reg) \
  86.         PciRead32(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg))
  87.  
  88. #define pciWriteByte(tag, reg, val) \
  89.         PciWrite8(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg),(val))
  90.  
  91. #define pciWriteWord(tag, reg, val) \
  92.         PciWrite16(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg),(val))
  93.  
  94. #define pciWriteLong(tag, reg, val) \
  95.         PciWrite32(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg),(val))
  96.  
  97.  
  98. ///////////////////////////////////////////////////////////////////////////////
  99.  
  100. int dbg_open(char *path);
  101. int dbgprintf(const char* format, ...);
  102.  
  103. ///////////////////////////////////////////////////////////////////////////////
  104.  
  105. extern inline int GetScreenSize()
  106. {
  107.   int retval;
  108.  
  109.   asm("int $0x40"
  110.       :"=a"(retval)
  111.       :"a"(61), "b"(1));
  112.   return retval;
  113. }
  114.  
  115. extern inline int GetScreenBpp()
  116. {
  117.   int retval;
  118.  
  119.   asm("int $0x40"
  120.       :"=a"(retval)
  121.       :"a"(61), "b"(2));
  122.   return retval;
  123. }
  124.  
  125. extern inline int GetScreenPitch()
  126. {
  127.   int retval;
  128.  
  129.   asm("int $0x40"
  130.       :"=a"(retval)
  131.       :"a"(61), "b"(3));
  132.   return retval;
  133. }
  134.  
  135. extern inline u32_t GetPgAddr(void *mem)
  136. {
  137.      u32_t retval;
  138.  
  139.      __asm__ __volatile__ (
  140.      "call *__imp__GetPgAddr \n\t"
  141.      :"=eax" (retval)
  142.      :"a" (mem) );
  143.      return retval;
  144. };
  145.  
  146. extern inline void CommitPages(void *mem, u32_t page, u32_t size)
  147. {
  148.      size = (size+4095) & ~4095;
  149.      __asm__ __volatile__ (
  150.      "call *__imp__CommitPages"
  151.      ::"a" (page), "b"(mem),"c"(size>>12)
  152.      :"edx" );
  153.      __asm__ __volatile__ ("":::"eax","ebx","ecx");
  154. };
  155.  
  156. extern inline void UnmapPages(void *mem, size_t size)
  157. {
  158.      size = (size+4095) & ~4095;
  159.      __asm__ __volatile__ (
  160.      "call *__imp__UnmapPages"
  161.      ::"a" (mem), "c"(size>>12)
  162.      :"edx");
  163.      __asm__ __volatile__ ("":::"eax","ecx");
  164. };
  165.  
  166. extern inline void usleep(u32_t delay)
  167. {
  168.      if( !delay )
  169.         delay++;
  170.      delay*= 256;
  171.  
  172.      while(delay--)
  173.         __asm__ __volatile__(
  174.         "xorl %%eax, %%eax \n\t"
  175.         "cpuid \n\t"
  176.         :::"eax","ebx","ecx","edx");
  177.      };
  178.  
  179. static inline void udelay(u32_t delay)
  180. {
  181.     if(!delay) delay++;
  182.     delay*= 256;
  183.  
  184.     while(delay--)
  185.     {
  186.         __asm__ __volatile__(
  187.         "xorl %%eax, %%eax \n\t"
  188.         "cpuid"
  189.         :::"eax","ebx","ecx","edx" );
  190.     }
  191. }
  192.  
  193. static inline void mdelay(u32_t time)
  194. {
  195.     time /= 10;
  196.     if(!time) time = 1;
  197.  
  198.      __asm__ __volatile__ (
  199.      "call *__imp__Delay"
  200.      ::"b" (time));
  201.      __asm__ __volatile__ (
  202.      "":::"ebx");
  203.  
  204. };
  205.  
  206.  
  207. static inline u32_t __PciApi(int cmd)
  208. {
  209.      u32_t retval;
  210.  
  211.      __asm__ __volatile__ (
  212.      "call *__imp__PciApi"
  213.      :"=a" (retval)
  214.      :"a" (cmd)
  215.      :"memory");
  216.      return retval;
  217. };
  218.  
  219. static inline void* __CreateObject(u32_t pid, size_t size)
  220. {
  221.      void *retval;
  222.  
  223.      __asm__ __volatile__ (
  224.      "call *__imp__CreateObject \n\t"
  225.      :"=a" (retval)
  226.      :"a" (size),"b"(pid)
  227.      :"esi","edi", "memory");
  228.      return retval;
  229. }
  230.  
  231. static inline void *__DestroyObject(void *obj)
  232. {
  233.      __asm__ __volatile__ (
  234.      "call *__imp__DestroyObject"
  235.      :
  236.      :"a" (obj)
  237.      :"ebx","edx","esi","edi", "memory");
  238. }
  239.  
  240.  
  241. /*
  242. u32 __RegService(char *name, srv_proc_t proc)
  243. {
  244.   u32 retval;
  245.  
  246.   asm __volatile__
  247.   (
  248.     "pushl %%eax \n\t"
  249.     "pushl %%ebx \n\t"
  250.     "call *__imp__RegService \n\t"
  251.     :"=eax" (retval)
  252.     :"a" (proc), "b" (name)
  253.     :"memory"
  254.   );
  255.   return retval;
  256. };
  257. */
  258.  
  259. static inline u32_t safe_cli(void)
  260. {
  261.      u32_t ifl;
  262.      __asm__ __volatile__ (
  263.      "pushf\n\t"
  264.      "popl %0\n\t"
  265.      "cli\n"
  266.      : "=r" (ifl));
  267.     return ifl;
  268. }
  269.  
  270. static inline void safe_sti(u32_t ifl)
  271. {
  272.      __asm__ __volatile__ (
  273.      "pushl %0\n\t"
  274.      "popf\n"
  275.      : : "r" (ifl)
  276.         );
  277. }
  278.  
  279. static inline void __clear (void * dst, unsigned len)
  280. {
  281.      u32_t tmp;
  282.      __asm__ __volatile__ (
  283. //     "xorl %%eax, %%eax \n\t"
  284.      "cld \n\t"
  285.      "rep stosb \n"
  286.      :"=c"(tmp),"=D"(tmp)
  287.      :"a"(0),"c"(len),"D"(dst));
  288.      __asm__ __volatile__ ("":::"ecx","edi");
  289. };
  290.  
  291. static inline void out8(const u16_t port, const u8_t val)
  292. {
  293.     __asm__ __volatile__
  294.     ("outb  %1, %0\n" : : "dN"(port), "a"(val));
  295. }
  296.  
  297. static inline void out16(const u16_t port, const u16_t val)
  298. {
  299.     __asm__ __volatile__
  300.     ("outw  %1, %0\n" : : "dN"(port), "a"(val));
  301. }
  302.  
  303. static inline void out32(const u16_t port, const u32_t val)
  304. {
  305.     __asm__ __volatile__
  306.     ("outl  %1, %0\n" : : "dN"(port), "a"(val));
  307. }
  308.  
  309. static inline u8_t in8(const u16_t port)
  310. {
  311.     u8_t tmp;
  312.     __asm__ __volatile__
  313.     ("inb %1, %0\n" : "=a"(tmp) : "dN"(port));
  314.     return tmp;
  315. };
  316.  
  317. static inline u16_t in16(const u16_t port)
  318. {
  319.     u16_t tmp;
  320.     __asm__ __volatile__
  321.     ("inw %1, %0\n" : "=a"(tmp) : "dN"(port));
  322.     return tmp;
  323. };
  324.  
  325. static inline u32_t in32(const u16_t port)
  326. {
  327.     u32_t tmp;
  328.     __asm__ __volatile__
  329.     ("inl %1, %0\n" : "=a"(tmp) : "dN"(port));
  330.     return tmp;
  331. };
  332.  
  333. static inline void delay(int time)
  334. {
  335.      __asm__ __volatile__ (
  336.      "call *__imp__Delay"
  337.      ::"b" (time));
  338.      __asm__ __volatile__ (
  339.      "":::"ebx");
  340.  
  341. }
  342.  
  343. static inline void change_task()
  344. {
  345.      __asm__ __volatile__ (
  346.      "call *__imp__ChangeTask");
  347. }
  348.  
  349. int drm_order(unsigned long size);
  350.  
  351. #endif
  352.