Subversion Repositories Kolibri OS

Rev

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. 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. void   STDCALL SetMouseData(int btn, int x, int y,
  60.                             int z, int h)__asm__("SetMouseData");
  61.  
  62. static u32_t PciApi(int cmd);
  63.  
  64. u8_t  STDCALL PciRead8 (u32_t bus, u32_t devfn, u32_t reg)__asm__("PciRead8");
  65. u16_t STDCALL PciRead16(u32_t bus, u32_t devfn, u32_t reg)__asm__("PciRead16");
  66. u32_t STDCALL PciRead32(u32_t bus, u32_t devfn, u32_t reg)__asm__("PciRead32");
  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 pciReadByte(tag, reg) \
  73.         PciRead8(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg))
  74.  
  75. #define pciReadWord(tag, reg) \
  76.         PciRead16(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg))
  77.  
  78. #define pciReadLong(tag, reg) \
  79.         PciRead32(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg))
  80.  
  81. #define pciWriteByte(tag, reg, val) \
  82.         PciWrite8(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg),(val))
  83.  
  84. #define pciWriteWord(tag, reg, val) \
  85.         PciWrite16(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg),(val))
  86.  
  87. #define pciWriteLong(tag, reg, val) \
  88.         PciWrite32(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg),(val))
  89.  
  90.  
  91. ///////////////////////////////////////////////////////////////////////////////
  92.  
  93. int dbg_open(char *path);
  94. int dbgprintf(const char* format, ...);
  95.  
  96. ///////////////////////////////////////////////////////////////////////////////
  97.  
  98. extern inline int GetScreenSize()
  99. {
  100.   int retval;
  101.  
  102.   asm("int $0x40"
  103.       :"=a"(retval)
  104.       :"a"(61), "b"(1));
  105.   return retval;
  106. }
  107.  
  108. extern inline int GetScreenBpp()
  109. {
  110.   int retval;
  111.  
  112.   asm("int $0x40"
  113.       :"=a"(retval)
  114.       :"a"(61), "b"(2));
  115.   return retval;
  116. }
  117.  
  118. extern inline int GetScreenPitch()
  119. {
  120.   int retval;
  121.  
  122.   asm("int $0x40"
  123.       :"=a"(retval)
  124.       :"a"(61), "b"(3));
  125.   return retval;
  126. }
  127.  
  128. extern inline u32_t GetPgAddr(void *mem)
  129. {
  130.      u32_t retval;
  131.  
  132.      __asm__ __volatile__ (
  133.      "call *__imp__GetPgAddr \n\t"
  134.      :"=eax" (retval)
  135.      :"a" (mem) );
  136.      return retval;
  137. };
  138.  
  139. extern inline void CommitPages(void *mem, u32_t page, u32_t size)
  140. {
  141.      size = (size+4095) & ~4095;
  142.      __asm__ __volatile__ (
  143.      "call *__imp__CommitPages"
  144.      ::"a" (page), "b"(mem),"c"(size>>12)
  145.      :"edx" );
  146.      __asm__ __volatile__ ("":::"eax","ebx","ecx");
  147. };
  148.  
  149. extern inline void UnmapPages(void *mem, size_t size)
  150. {
  151.      size = (size+4095) & ~4095;
  152.      __asm__ __volatile__ (
  153.      "call *__imp__UnmapPages"
  154.      ::"a" (mem), "c"(size>>12)
  155.      :"edx");
  156.      __asm__ __volatile__ ("":::"eax","ecx");
  157. };
  158.  
  159. extern inline void usleep(u32_t delay)
  160. {
  161.      if( !delay )
  162.         delay++;
  163.      delay*=1000;
  164.  
  165.      while(delay--)
  166.      __asm__ __volatile__ (
  167.      "xorl %%eax, %%eax \n\t"
  168.      "cpuid \n\t"
  169.         :::"eax","ebx","ecx","edx");
  170. };
  171.  
  172. extern inline u32_t __PciApi(int cmd)
  173. {
  174.      u32_t retval;
  175.  
  176.      __asm__ __volatile__ (
  177.      "call *__imp__PciApi"
  178.      :"=a" (retval)
  179.      :"a" (cmd)
  180.      :"memory");
  181.      return retval;
  182. };
  183.  
  184. extern inline void* __CreateObject(u32_t pid, size_t size)
  185. {
  186.      void *retval;
  187.  
  188.      __asm__ __volatile__ (
  189.      "call *__imp__CreateObject \n\t"
  190.      :"=a" (retval)
  191.      :"a" (size),"b"(pid)
  192.      :"esi","edi", "memory");
  193.      return retval;
  194. }
  195.  
  196. extern inline void *__DestroyObject(void *obj)
  197. {
  198.      __asm__ __volatile__ (
  199.      "call *__imp__DestroyObject"
  200.      :
  201.      :"a" (obj)
  202.      :"ebx","edx","esi","edi", "memory");
  203. }
  204.  
  205.  
  206. /*
  207. u32 __RegService(char *name, srv_proc_t proc)
  208. {
  209.   u32 retval;
  210.  
  211.   asm __volatile__
  212.   (
  213.     "pushl %%eax \n\t"
  214.     "pushl %%ebx \n\t"
  215.     "call *__imp__RegService \n\t"
  216.     :"=eax" (retval)
  217.     :"a" (proc), "b" (name)
  218.     :"memory"
  219.   );
  220.   return retval;
  221. };
  222. */
  223.  
  224. extern inline u32_t safe_cli(void)
  225. {
  226.      u32_t ifl;
  227.      __asm__ __volatile__ (
  228.      "pushf\n\t"
  229.      "popl %0\n\t"
  230.      "cli\n"
  231.      : "=r" (ifl));
  232.     return ifl;
  233. }
  234.  
  235. extern inline void safe_sti(u32_t ifl)
  236. {
  237.      __asm__ __volatile__ (
  238.      "pushl %0\n\t"
  239.      "popf\n"
  240.      : : "r" (ifl)
  241.         );
  242. }
  243.  
  244. extern inline void __clear (void * dst, unsigned len)
  245. {
  246.      u32_t tmp;
  247.      __asm__ __volatile__ (
  248. //     "xorl %%eax, %%eax \n\t"
  249.      "cld \n\t"
  250.      "rep stosb \n"
  251.      :"=c"(tmp),"=D"(tmp)
  252.      :"a"(0),"c"(len),"D"(dst));
  253.      __asm__ __volatile__ ("":::"ecx","edi");
  254. };
  255.  
  256. extern inline void out8(const u16_t port, const u8_t val)
  257. {
  258.     __asm__ __volatile__
  259.     ("outb  %1, %0\n" : : "dN"(port), "a"(val));
  260. }
  261.  
  262. extern inline void out16(const u16_t port, const u16_t val)
  263. {
  264.     __asm__ __volatile__
  265.     ("outw  %1, %0\n" : : "dN"(port), "a"(val));
  266. }
  267.  
  268. extern inline void out32(const u16_t port, const u32_t val)
  269. {
  270.     __asm__ __volatile__
  271.     ("outl  %1, %0\n" : : "dN"(port), "a"(val));
  272. }
  273.  
  274. extern inline u16_t in16(const u16_t port)
  275. {
  276.     u16_t tmp;
  277.     __asm__ __volatile__
  278.     ("inw %1, %0\n" : "=a"(tmp) : "dN"(port));
  279.     return tmp;
  280. };
  281.  
  282. extern inline u32_t in32(const u16_t port)
  283. {
  284.     u32_t tmp;
  285.     __asm__ __volatile__
  286.     ("inl %1, %0\n" : "=a"(tmp) : "dN"(port));
  287.     return tmp;
  288. };
  289.  
  290. extern inline void delay(int time)
  291. {
  292.      __asm__ __volatile__ (
  293.      "call *__imp__Delay"
  294.      ::"b" (time));
  295.      __asm__ __volatile__ (
  296.      "":::"ebx");
  297.  
  298. }
  299.  
  300.