Subversion Repositories Kolibri OS

Rev

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. #define pciReadLong(tag, reg) \
  67.         PciRead32(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg))
  68.  
  69. #define pciReadByte(tag, reg) \
  70.         PciRead8(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg))
  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 pciWriteByte(tag, reg, val) \
  77.         PciWrite8(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg),(val))
  78.  
  79. #define pciWriteWord(tag, reg, val) \
  80.         PciWrite16(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg),(val))
  81.  
  82. #define pciWriteLong(tag, reg, val) \
  83.         PciWrite32(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg),(val))
  84.  
  85.  
  86. ///////////////////////////////////////////////////////////////////////////////
  87.  
  88. int dbg_open(char *path);
  89. int dbgprintf(const char* format, ...);
  90.  
  91. ///////////////////////////////////////////////////////////////////////////////
  92.  
  93. extern inline int GetScreenSize()
  94. {
  95.   int retval;
  96.  
  97.   asm("int $0x40"
  98.       :"=a"(retval)
  99.       :"a"(61), "b"(1));
  100.   return retval;
  101. }
  102.  
  103. extern inline int GetScreenBpp()
  104. {
  105.   int retval;
  106.  
  107.   asm("int $0x40"
  108.       :"=a"(retval)
  109.       :"a"(61), "b"(2));
  110.   return retval;
  111. }
  112.  
  113. extern inline int GetScreenPitch()
  114. {
  115.   int retval;
  116.  
  117.   asm("int $0x40"
  118.       :"=a"(retval)
  119.       :"a"(61), "b"(3));
  120.   return retval;
  121. }
  122.  
  123. extern inline u32_t GetPgAddr(void *mem)
  124. {
  125.      u32_t retval;
  126.  
  127.      __asm__ __volatile__ (
  128.      "call *__imp__GetPgAddr \n\t"
  129.      :"=eax" (retval)
  130.      :"a" (mem) );
  131.      return retval;
  132. };
  133.  
  134. extern inline void CommitPages(void *mem, u32_t page, u32_t size)
  135. {
  136.      size = (size+4095) & ~4095;
  137.      __asm__ __volatile__ (
  138.      "call *__imp__CommitPages"
  139.      ::"a" (page), "b"(mem),"c"(size>>12)
  140.      :"edx" );
  141.      __asm__ __volatile__ ("":::"eax","ebx","ecx");
  142. };
  143.  
  144. extern inline void UnmapPages(void *mem, size_t size)
  145. {
  146.      size = (size+4095) & ~4095;
  147.      __asm__ __volatile__ (
  148.      "call *__imp__UnmapPages"
  149.      ::"a" (mem), "c"(size>>12)
  150.      :"edx");
  151.      __asm__ __volatile__ ("":::"eax","ecx");
  152. };
  153.  
  154. extern inline void usleep(u32_t delay)
  155. {
  156.      if( !delay )
  157.         delay++;
  158.      delay*=2000;
  159.  
  160.      __asm__ __volatile__ (
  161.      "1:\n\t"
  162.      "xorl %%eax, %%eax \n\t"
  163.      "cpuid \n\t"
  164.      "decl %%edi \n\t"
  165.      "jnz 1b"
  166.      :
  167.      :"D"(delay)
  168.      :"eax","ebx","ecx","edx");
  169. };
  170.  
  171. extern inline u32_t __PciApi(int cmd)
  172. {
  173.      u32_t retval;
  174.  
  175.      __asm__ __volatile__ (
  176.      "call *__imp__PciApi"
  177.      :"=a" (retval)
  178.      :"a" (cmd)
  179.      :"memory");
  180.      return retval;
  181. };
  182.  
  183. extern inline void* __CreateObject(u32_t pid, size_t size)
  184. {
  185.      void *retval;
  186.  
  187.      __asm__ __volatile__ (
  188.      "call *__imp__CreateObject \n\t"
  189.      :"=a" (retval)
  190.      :"a" (size),"b"(pid)
  191.      :"esi","edi", "memory");
  192.      return retval;
  193. }
  194.  
  195. extern inline void *__DestroyObject(void *obj)
  196. {
  197.      __asm__ __volatile__ (
  198.      "call *__imp__DestroyObject"
  199.      :
  200.      :"a" (obj)
  201.      :"ebx","edx","esi","edi", "memory");
  202. }
  203.  
  204.  
  205. /*
  206. u32 __RegService(char *name, srv_proc_t proc)
  207. {
  208.   u32 retval;
  209.  
  210.   asm __volatile__
  211.   (
  212.     "pushl %%eax \n\t"
  213.     "pushl %%ebx \n\t"
  214.     "call *__imp__RegService \n\t"
  215.     :"=eax" (retval)
  216.     :"a" (proc), "b" (name)
  217.     :"memory"
  218.   );
  219.   return retval;
  220. };
  221. */
  222.  
  223. extern inline u32_t safe_cli(void)
  224. {
  225.      u32_t ifl;
  226.      __asm__ __volatile__ (
  227.      "pushf\n\t"
  228.      "popl %0\n\t"
  229.      "cli\n"
  230.      : "=r" (ifl));
  231.     return ifl;
  232. }
  233.  
  234. extern inline void safe_sti(u32_t ifl)
  235. {
  236.      __asm__ __volatile__ (
  237.      "pushl %0\n\t"
  238.      "popf\n"
  239.      : : "r" (ifl)
  240.         );
  241. }
  242.  
  243. extern inline void __clear (void * dst, unsigned len)
  244. {
  245.      u32_t tmp;
  246.      __asm__ __volatile__ (
  247. //     "xorl %%eax, %%eax \n\t"
  248.      "cld \n\t"
  249.      "rep stosb \n"
  250.      :"=c"(tmp),"=D"(tmp)
  251.      :"a"(0),"c"(len),"D"(dst));
  252.      __asm__ __volatile__ ("":::"ecx","edi");
  253. };
  254.  
  255.