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. 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. static u32_t PciApi(int cmd);
  58.  
  59. u8_t  STDCALL PciRead8 (u32_t bus, u32_t devfn, u32_t reg)__asm__("PciRead8");
  60. u16_t STDCALL PciRead16(u32_t bus, u32_t devfn, u32_t reg)__asm__("PciRead16");
  61. u32_t STDCALL PciRead32(u32_t bus, u32_t devfn, u32_t reg)__asm__("PciRead32");
  62.  
  63. u32_t STDCALL PciWrite8 (u32_t bus, u32_t devfn, u32_t reg,u8_t val) __asm__("PciWrite8");
  64. u32_t STDCALL PciWrite16(u32_t bus, u32_t devfn, u32_t reg,u16_t val)__asm__("PciWrite16");
  65. u32_t STDCALL PciWrite32(u32_t bus, u32_t devfn, u32_t reg,u32_t val)__asm__("PciWrite32");
  66.  
  67. ///////////////////////////////////////////////////////////////////////////////
  68.  
  69. int dbg_open(char *path);
  70. int dbgprintf(const char* format, ...);
  71.  
  72. ///////////////////////////////////////////////////////////////////////////////
  73.  
  74. extern inline u32_t GetPgAddr(void *mem)
  75. {
  76.      u32_t retval;
  77.  
  78.      __asm__ __volatile__ (
  79.      "call *__imp__GetPgAddr \n\t"
  80.      :"=eax" (retval)
  81.      :"a" (mem) );
  82.      return retval;
  83. };
  84.  
  85. extern inline void CommitPages(void *mem, u32_t page, u32_t size)
  86. {
  87.      size = (size+4095) & ~4095;
  88.      __asm__ __volatile__ (
  89.      "call *__imp__CommitPages"
  90.      ::"a" (page), "b"(mem),"c"(size>>12)
  91.      :"edx" );
  92.      __asm__ __volatile__ ("":::"eax","ebx","ecx");
  93. };
  94.  
  95. extern inline void UnmapPages(void *mem, size_t size)
  96. {
  97.      size = (size+4095) & ~4095;
  98.      __asm__ __volatile__ (
  99.      "call *__imp__UnmapPages"
  100.      ::"a" (mem), "c"(size>>12)
  101.      :"edx");
  102.      __asm__ __volatile__ ("":::"eax","ecx");
  103. };
  104.  
  105. extern inline void usleep(u32_t delay)
  106. {
  107.      if( !delay )
  108.         delay++;
  109.      delay*=2000;
  110.  
  111.      __asm__ __volatile__ (
  112.      "1:\n\t"
  113.      "xorl %%eax, %%eax \n\t"
  114.      "cpuid \n\t"
  115.      "decl %%edi \n\t"
  116.      "jnz 1b"
  117.      :
  118.      :"D"(delay)
  119.      :"eax","ebx","ecx","edx");
  120. };
  121.  
  122. extern inline u32_t __PciApi(int cmd)
  123. {
  124.      u32_t retval;
  125.  
  126.      __asm__ __volatile__ (
  127.      "call *__imp__PciApi"
  128.      :"=a" (retval)
  129.      :"a" (cmd)
  130.      :"memory");
  131.      return retval;
  132. };
  133.  
  134. extern inline void* __CreateObject(u32_t pid, size_t size)
  135. {
  136.      void *retval;
  137.  
  138.      __asm__ __volatile__ (
  139.      "call *__imp__CreateObject \n\t"
  140.      :"=a" (retval)
  141.      :"a" (size),"b"(pid)
  142.      :"esi","edi", "memory");
  143.      return retval;
  144. }
  145.  
  146. extern inline void *__DestroyObject(void *obj)
  147. {
  148.      __asm__ __volatile__ (
  149.      "call *__imp__DestroyObject"
  150.      :
  151.      :"a" (obj)
  152.      :"ebx","edx","esi","edi", "memory");
  153. }
  154.  
  155.  
  156. /*
  157. u32 __RegService(char *name, srv_proc_t proc)
  158. {
  159.   u32 retval;
  160.  
  161.   asm __volatile__
  162.   (
  163.     "pushl %%eax \n\t"
  164.     "pushl %%ebx \n\t"
  165.     "call *__imp__RegService \n\t"
  166.     :"=eax" (retval)
  167.     :"a" (proc), "b" (name)
  168.     :"memory"
  169.   );
  170.   return retval;
  171. };
  172. */
  173.  
  174. extern inline u32_t safe_cli(void)
  175. {
  176.      u32_t ifl;
  177.      __asm__ __volatile__ (
  178.      "pushf\n\t"
  179.      "popl %0\n\t"
  180.      "cli\n"
  181.      : "=r" (ifl));
  182.     return ifl;
  183. }
  184.  
  185. extern inline void safe_sti(u32_t ifl)
  186. {
  187.      __asm__ __volatile__ (
  188.      "pushl %0\n\t"
  189.      "popf\n"
  190.      : : "r" (ifl)
  191.         );
  192. }
  193.  
  194. extern inline void __clear (void * dst, unsigned len)
  195. {
  196.      u32_t tmp;
  197.      __asm__ __volatile__ (
  198. //     "xorl %%eax, %%eax \n\t"
  199.      "cld \n\t"
  200.      "rep stosb \n"
  201.      :"=c"(tmp),"=D"(tmp)
  202.      :"a"(0),"c"(len),"D"(dst));
  203.      __asm__ __volatile__ ("":::"ecx","edi");
  204. };
  205.  
  206.