Subversion Repositories Kolibri OS

Rev

Rev 948 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. #define OS_BASE   0x80000000
  3.  
  4. typedef struct
  5. {
  6.   u32_t      handle;
  7.   u32_t      io_code;
  8.   void       *input;
  9.   int        inp_size;
  10.   void       *output;
  11.   int        out_size;
  12. }ioctl_t;
  13.  
  14. typedef int (__stdcall *srv_proc_t)(ioctl_t *);
  15.  
  16. #define ERR_OK       0
  17. #define ERR_PARAM   -1
  18.  
  19.  
  20. u32_t __stdcall drvEntry(int)__asm__("_drvEntry");
  21.  
  22. ///////////////////////////////////////////////////////////////////////////////
  23.  
  24. #define STDCALL __attribute__ ((stdcall)) __attribute__ ((dllimport))
  25. #define IMPORT __attribute__ ((dllimport))
  26.  
  27. ///////////////////////////////////////////////////////////////////////////////
  28.  
  29. #define SysMsgBoardStr  __SysMsgBoardStr
  30. #define PciApi          __PciApi
  31. //#define RegService      __RegService
  32. #define CreateObject    __CreateObject
  33. #define DestroyObject   __DestroyObject
  34.  
  35. ///////////////////////////////////////////////////////////////////////////////
  36.  
  37. #define PG_SW       0x003
  38. #define PG_NOCACHE  0x018
  39.  
  40. void*  STDCALL AllocKernelSpace(size_t size)__asm__("AllocKernelSpace");
  41. void*  STDCALL KernelAlloc(size_t size)__asm__("KernelAlloc");
  42. void*  STDCALL KernelFree(void *mem)__asm__("KernelFree");
  43. void*  STDCALL UserAlloc(size_t size)__asm__("UserAlloc");
  44. int    STDCALL UserFree(void *mem)__asm__("UserFree");
  45.  
  46. addr_t STDCALL AllocPages(count_t count)__asm__("AllocPages");
  47.  
  48. void* STDCALL CreateRingBuffer(size_t size, u32_t map)__asm__("CreateRingBuffer");
  49.  
  50. u32_t STDCALL RegService(char *name, srv_proc_t proc)__asm__("RegService");
  51.  
  52. //void *CreateObject(u32 pid, size_t size);
  53. //void *DestroyObject(void *obj);
  54.  
  55. addr_t STDCALL MapIoMem(void* base,size_t size,u32_t flags)__asm__("MapIoMem");
  56.  
  57. ///////////////////////////////////////////////////////////////////////////////
  58.  
  59.  
  60. static u32_t PciApi(int cmd);
  61.  
  62. u8_t  STDCALL PciRead8 (u32_t bus, u32_t devfn, u32_t reg)__asm__("PciRead8");
  63. u16_t STDCALL PciRead16(u32_t bus, u32_t devfn, u32_t reg)__asm__("PciRead16");
  64. u32_t STDCALL PciRead32(u32_t bus, u32_t devfn, u32_t reg)__asm__("PciRead32");
  65.  
  66. u32_t STDCALL PciWrite8 (u32_t bus, u32_t devfn, u32_t reg,u8_t val) __asm__("PciWrite8");
  67. u32_t STDCALL PciWrite16(u32_t bus, u32_t devfn, u32_t reg,u16_t val)__asm__("PciWrite16");
  68. u32_t STDCALL PciWrite32(u32_t bus, u32_t devfn, u32_t reg,u32_t val)__asm__("PciWrite32");
  69.  
  70. #define pciReadByte(tag, reg) \
  71.         PciRead8(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg))
  72.  
  73. #define pciReadWord(tag, reg) \
  74.         PciRead16(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg))
  75.  
  76. #define pciReadLong(tag, reg) \
  77.         PciRead32(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg))
  78.  
  79. #define pciWriteByte(tag, reg, val) \
  80.         PciWrite8(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg),(val))
  81.  
  82. #define pciWriteWord(tag, reg, val) \
  83.         PciWrite16(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg),(val))
  84.  
  85. #define pciWriteLong(tag, reg, val) \
  86.         PciWrite32(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg),(val))
  87.  
  88.  
  89. ///////////////////////////////////////////////////////////////////////////////
  90.  
  91. int dbg_open(char *path);
  92. int dbgprintf(const char* format, ...);
  93.  
  94. ///////////////////////////////////////////////////////////////////////////////
  95.  
  96. extern inline int GetScreenSize()
  97. {
  98.   int retval;
  99.  
  100.   asm("int $0x40"
  101.       :"=a"(retval)
  102.       :"a"(61), "b"(1));
  103.   return retval;
  104. }
  105.  
  106. extern inline int GetScreenBpp()
  107. {
  108.   int retval;
  109.  
  110.   asm("int $0x40"
  111.       :"=a"(retval)
  112.       :"a"(61), "b"(2));
  113.   return retval;
  114. }
  115.  
  116. extern inline int GetScreenPitch()
  117. {
  118.   int retval;
  119.  
  120.   asm("int $0x40"
  121.       :"=a"(retval)
  122.       :"a"(61), "b"(3));
  123.   return retval;
  124. }
  125.  
  126. extern inline u32_t GetPgAddr(void *mem)
  127. {
  128.      u32_t retval;
  129.  
  130.      __asm__ __volatile__ (
  131.      "call *__imp__GetPgAddr \n\t"
  132.      :"=eax" (retval)
  133.      :"a" (mem) );
  134.      return retval;
  135. };
  136.  
  137. extern inline void CommitPages(void *mem, u32_t page, u32_t size)
  138. {
  139.      size = (size+4095) & ~4095;
  140.      __asm__ __volatile__ (
  141.      "call *__imp__CommitPages"
  142.      ::"a" (page), "b"(mem),"c"(size>>12)
  143.      :"edx" );
  144.      __asm__ __volatile__ ("":::"eax","ebx","ecx");
  145. };
  146.  
  147. extern inline void UnmapPages(void *mem, size_t size)
  148. {
  149.      size = (size+4095) & ~4095;
  150.      __asm__ __volatile__ (
  151.      "call *__imp__UnmapPages"
  152.      ::"a" (mem), "c"(size>>12)
  153.      :"edx");
  154.      __asm__ __volatile__ ("":::"eax","ecx");
  155. };
  156.  
  157. extern inline void usleep(u32_t delay)
  158. {
  159.      if( !delay )
  160.         delay++;
  161.      delay*=2000;
  162.  
  163.      __asm__ __volatile__ (
  164.      "1:\n\t"
  165.      "xorl %%eax, %%eax \n\t"
  166.      "cpuid \n\t"
  167.      "decl %%edi \n\t"
  168.      "jnz 1b"
  169.      :
  170.      :"D"(delay)
  171.      :"eax","ebx","ecx","edx");
  172. };
  173.  
  174. extern inline u32_t __PciApi(int cmd)
  175. {
  176.      u32_t retval;
  177.  
  178.      __asm__ __volatile__ (
  179.      "call *__imp__PciApi"
  180.      :"=a" (retval)
  181.      :"a" (cmd)
  182.      :"memory");
  183.      return retval;
  184. };
  185.  
  186. extern inline void* __CreateObject(u32_t pid, size_t size)
  187. {
  188.      void *retval;
  189.  
  190.      __asm__ __volatile__ (
  191.      "call *__imp__CreateObject \n\t"
  192.      :"=a" (retval)
  193.      :"a" (size),"b"(pid)
  194.      :"esi","edi", "memory");
  195.      return retval;
  196. }
  197.  
  198. extern inline void *__DestroyObject(void *obj)
  199. {
  200.      __asm__ __volatile__ (
  201.      "call *__imp__DestroyObject"
  202.      :
  203.      :"a" (obj)
  204.      :"ebx","edx","esi","edi", "memory");
  205. }
  206.  
  207.  
  208. /*
  209. u32 __RegService(char *name, srv_proc_t proc)
  210. {
  211.   u32 retval;
  212.  
  213.   asm __volatile__
  214.   (
  215.     "pushl %%eax \n\t"
  216.     "pushl %%ebx \n\t"
  217.     "call *__imp__RegService \n\t"
  218.     :"=eax" (retval)
  219.     :"a" (proc), "b" (name)
  220.     :"memory"
  221.   );
  222.   return retval;
  223. };
  224. */
  225.  
  226. extern inline u32_t safe_cli(void)
  227. {
  228.      u32_t ifl;
  229.      __asm__ __volatile__ (
  230.      "pushf\n\t"
  231.      "popl %0\n\t"
  232.      "cli\n"
  233.      : "=r" (ifl));
  234.     return ifl;
  235. }
  236.  
  237. extern inline void safe_sti(u32_t ifl)
  238. {
  239.      __asm__ __volatile__ (
  240.      "pushl %0\n\t"
  241.      "popf\n"
  242.      : : "r" (ifl)
  243.         );
  244. }
  245.  
  246. extern inline void __clear (void * dst, unsigned len)
  247. {
  248.      u32_t tmp;
  249.      __asm__ __volatile__ (
  250. //     "xorl %%eax, %%eax \n\t"
  251.      "cld \n\t"
  252.      "rep stosb \n"
  253.      :"=c"(tmp),"=D"(tmp)
  254.      :"a"(0),"c"(len),"D"(dst));
  255.      __asm__ __volatile__ ("":::"ecx","edi");
  256. };
  257.  
  258.