Subversion Repositories Kolibri OS

Rev

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