Subversion Repositories Kolibri OS

Rev

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