Subversion Repositories Kolibri OS

Rev

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