Subversion Repositories Kolibri OS

Rev

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