Subversion Repositories Kolibri OS

Rev

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