Subversion Repositories Kolibri OS

Rev

Rev 5345 | Rev 6102 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. #ifndef __SYSCALL_H__
  2. #define __SYSCALL_H__
  3.  
  4. #include <ddk.h>
  5.  
  6. typedef u32 addr_t;
  7. typedef u32 count_t;
  8.  
  9. typedef struct
  10. {
  11.   int width;
  12.   int height;
  13.   int bpp;
  14.   int freq;
  15. }videomode_t;
  16.  
  17. ///////////////////////////////////////////////////////////////////////////////
  18.  
  19. #define STDCALL  __attribute__ ((stdcall)) __attribute__ ((dllimport))
  20. #define FASTCALL __attribute__ ((fastcall)) __attribute__ ((dllimport))
  21.  
  22. #define IMPORT   __attribute__ ((dllimport))
  23.  
  24. ///////////////////////////////////////////////////////////////////////////////
  25.  
  26. #define SysMsgBoardStr  __SysMsgBoardStr
  27. #define PciApi          __PciApi
  28. #define CreateObject    __CreateObject
  29. #define DestroyObject   __DestroyObject
  30.  
  31. #define _alloca(x) __builtin_alloca((x))
  32.  
  33. ///////////////////////////////////////////////////////////////////////////////
  34.  
  35.  
  36. void*  STDCALL AllocKernelSpace(size_t size)__asm__("AllocKernelSpace");
  37. void   STDCALL FreeKernelSpace(void *mem)__asm__("FreeKernelSpace");
  38. addr_t STDCALL MapIoMem(addr_t base, size_t size, u32 flags)__asm__("MapIoMem");
  39. void*  STDCALL KernelAlloc(size_t size)__asm__("KernelAlloc");
  40. void*  STDCALL KernelFree(void *mem)__asm__("KernelFree");
  41. void*  STDCALL UserAlloc(size_t size)__asm__("UserAlloc");
  42. int    STDCALL UserFree(void *mem)__asm__("UserFree");
  43.  
  44. void*  STDCALL GetDisplay(void)__asm__("GetDisplay");
  45.  
  46. u32  IMPORT  GetTimerTicks(void)__asm__("GetTimerTicks");
  47. u64  IMPORT  GetClockNs(void)__asm__("GetClockNs");
  48.  
  49. addr_t STDCALL AllocPage(void)__asm__("AllocPage");
  50. addr_t STDCALL AllocPages(count_t count)__asm__("AllocPages");
  51. void   IMPORT  __attribute__((regparm(1)))
  52.                FreePage(addr_t page)__asm__("FreePage");
  53. void   STDCALL MapPage(void *vaddr, addr_t paddr, u32 flags)__asm__("MapPage");
  54.  
  55.  
  56. void* STDCALL CreateRingBuffer(size_t size, u32 map)__asm__("CreateRingBuffer");
  57.  
  58. u32 STDCALL RegService(char *name, srv_proc_t proc)__asm__("RegService");
  59.  
  60. int   STDCALL AttachIntHandler(int irq, void *handler, u32 access) __asm__("AttachIntHandler");
  61.  
  62. void  FASTCALL MutexInit(struct mutex*)__asm__("MutexInit");
  63. void  FASTCALL MutexLock(struct mutex*)__asm__("MutexLock");
  64. void  FASTCALL MutexUnlock(struct mutex*)__asm__("MutexUnlock");
  65.  
  66. void  FASTCALL InitRwsem(struct rw_semaphore *sem)__asm__("InitRwsem");
  67. void  FASTCALL DownRead(struct rw_semaphore *sem)__asm__("DownRead");
  68. void  FASTCALL DownWrite(struct rw_semaphore *sem)__asm__("DownWrite");
  69. void  FASTCALL UpRead(struct rw_semaphore *sem)__asm__("UpRead");
  70. void  FASTCALL UpWrite(struct rw_semaphore *sem)__asm__("UpWrite");
  71.  
  72. addr_t IMPORT  GetStackBase(void)__asm__("GetStackBase");
  73. u32  IMPORT  GetPid(void)__asm__("GetPid");
  74.  
  75. u32 STDCALL TimerHS(u32 delay, u32 interval,
  76.                     void *fn, void *data)asm("TimerHS");
  77.  
  78. void STDCALL CancelTimerHS(u32 handle)asm("CancelTimerHS");
  79.  
  80. u64 IMPORT GetCpuFreq()__asm__("GetCpuFreq");
  81.  
  82. ///////////////////////////////////////////////////////////////////////////////
  83.  
  84. void   STDCALL SetMouseData(int btn, int x, int y,
  85.                             int z, int h)__asm__("SetMouseData");
  86.  
  87. void   FASTCALL SetKeyboardData(u32 data)__asm__("SetKeyboardData");
  88.  
  89.  
  90. u8  STDCALL PciRead8 (u32 bus, u32 devfn, u32 reg)__asm__("PciRead8");
  91. u16 STDCALL PciRead16(u32 bus, u32 devfn, u32 reg)__asm__("PciRead16");
  92. u32 STDCALL PciRead32(u32 bus, u32 devfn, u32 reg)__asm__("PciRead32");
  93.  
  94. u32 STDCALL PciWrite8 (u32 bus, u32 devfn, u32 reg,u8 val) __asm__("PciWrite8");
  95. u32 STDCALL PciWrite16(u32 bus, u32 devfn, u32 reg,u16 val)__asm__("PciWrite16");
  96. u32 STDCALL PciWrite32(u32 bus, u32 devfn, u32 reg,u32 val)__asm__("PciWrite32");
  97.  
  98. #define pciReadByte(tag, reg) \
  99.         PciRead8(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg))
  100.  
  101. #define pciReadWord(tag, reg) \
  102.         PciRead16(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg))
  103.  
  104. #define pciReadLong(tag, reg) \
  105.         PciRead32(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg))
  106.  
  107. #define pciWriteByte(tag, reg, val) \
  108.         PciWrite8(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg),(val))
  109.  
  110. #define pciWriteWord(tag, reg, val) \
  111.         PciWrite16(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg),(val))
  112.  
  113. #define pciWriteLong(tag, reg, val) \
  114.         PciWrite32(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg),(val))
  115.  
  116. static inline int pci_read_config_byte(struct pci_dev *dev, int where,
  117.                     u8 *val)
  118. {
  119.     *val = PciRead8(dev->busnr, dev->devfn, where);
  120.     return 1;
  121. }
  122.  
  123. static inline int pci_read_config_word(struct pci_dev *dev, int where,
  124.                     u16 *val)
  125. {
  126.     *val = PciRead16(dev->busnr, dev->devfn, where);
  127.     return 1;
  128. }
  129.  
  130. static inline int pci_read_config_dword(struct pci_dev *dev, int where,
  131.                     u32 *val)
  132. {
  133.     *val = PciRead32(dev->busnr, dev->devfn, where);
  134.     return 1;
  135. }
  136.  
  137. static inline int pci_write_config_byte(struct pci_dev *dev, int where,
  138.                     u8 val)
  139. {
  140.     PciWrite8(dev->busnr, dev->devfn, where, val);
  141.     return 1;
  142. }
  143.  
  144. static inline int pci_write_config_word(struct pci_dev *dev, int where,
  145.                     u16 val)
  146. {
  147.     PciWrite16(dev->busnr, dev->devfn, where, val);
  148.     return 1;
  149. }
  150.  
  151. static inline int pci_write_config_dword(struct pci_dev *dev, int where,
  152.                     u32 val)
  153. {
  154.     PciWrite32(dev->busnr, dev->devfn, where, val);
  155.     return 1;
  156. }
  157.  
  158. ///////////////////////////////////////////////////////////////////////////////
  159.  
  160. int dbg_open(char *path);
  161. int dbgprintf(const char* format, ...);
  162.  
  163. ///////////////////////////////////////////////////////////////////////////////
  164.  
  165. static inline int CreateKernelThread(void *entry)
  166. {
  167.     int pid;
  168.      __asm__ __volatile__ (
  169.      "call *__imp__CreateThread"
  170.      :"=a"(pid)
  171.      :"b"(1),"c"(entry),"d"(0)
  172.      :"memory");
  173.      __asm__ __volatile__ ("":::"ebx","ecx","edx","esi","edi");
  174.      return pid;
  175. };
  176.  
  177.  
  178. static inline evhandle_t CreateEvent(kevent_t *ev, u32 flags)
  179. {
  180.      evhandle_t evh;
  181.  
  182.      __asm__ __volatile__ (
  183.      "call *__imp__CreateEvent"
  184.      :"=A"(evh.raw)
  185.      :"S" (ev), "c"(flags)
  186.      :"memory");
  187.      __asm__ __volatile__ ("":::"ebx","ecx","edx","esi", "edi");
  188.  
  189.      return evh;
  190. };
  191.  
  192. static inline void RaiseEvent(evhandle_t evh, u32 flags, kevent_t *ev)
  193. {
  194.      __asm__ __volatile__ (
  195.      "call *__imp__RaiseEvent"
  196.      ::"a"(evh.handle),"b"(evh.euid),"d"(flags),"S" (ev)
  197.      :"memory");
  198.      __asm__ __volatile__ ("":::"ebx","ecx","edx","esi","edi");
  199.  
  200. };
  201.  
  202. static inline void WaitEvent(evhandle_t evh)
  203. {
  204.      __asm__ __volatile__ (
  205.      "call *__imp__WaitEvent"
  206.      ::"a"(evh.handle),"b"(evh.euid));
  207.      __asm__ __volatile__ ("":::"ebx","ecx","edx","esi","edi");
  208. };
  209.  
  210. static inline int WaitEventTimeout(evhandle_t evh, int timeout)
  211. {
  212.     int retval;
  213.     __asm__ __volatile__ (
  214.     "call *__imp__WaitEventTimeout"
  215.     :"=a"(retval)
  216.     :"a"(evh.handle),"b"(evh.euid), "c"(timeout));
  217.     __asm__ __volatile__ ("":::"ebx","ecx","edx","esi","edi");
  218.     return retval;
  219. };
  220.  
  221. static inline void DestroyEvent(evhandle_t evh)
  222. {
  223.      __asm__ __volatile__ (
  224.      "call *__imp__DestroyEvent"
  225.      ::"a"(evh.handle),"b"(evh.euid));
  226.      __asm__ __volatile__ ("":::"ebx","ecx","edx","esi","edi");
  227. };
  228.  
  229. static inline u32 GetEvent(kevent_t *ev)
  230. {
  231.     u32  handle;
  232.  
  233.     __asm__ __volatile__ (
  234.     "call *__imp__GetEvent"
  235.     :"=a"(handle)
  236.     :"D"(ev)
  237.     :"memory");
  238.     __asm__ __volatile__ ("":::"ebx","ecx","edx", "esi","edi");
  239.      return handle;
  240. };
  241.  
  242.  
  243. static inline int GetScreenSize(void)
  244. {
  245.   int retval;
  246.  
  247.   asm("int $0x40"
  248.       :"=a"(retval)
  249.       :"a"(61), "b"(1));
  250.   return retval;
  251. }
  252.  
  253. static inline int GetScreenBpp(void)
  254. {
  255.   int retval;
  256.  
  257.   asm("int $0x40"
  258.       :"=a"(retval)
  259.       :"a"(61), "b"(2));
  260.   return retval;
  261. }
  262.  
  263. static inline int GetScreenPitch(void)
  264. {
  265.   int retval;
  266.  
  267.   asm("int $0x40"
  268.       :"=a"(retval)
  269.       :"a"(61), "b"(3));
  270.   return retval;
  271. }
  272.  
  273. static inline u32 GetPgAddr(void *mem)
  274. {
  275.      u32 retval;
  276.  
  277.      __asm__ __volatile__ (
  278.      "call *__imp__GetPgAddr \n\t"
  279.      :"=a" (retval)
  280.      :"a" (mem) );
  281.      return retval;
  282. };
  283.  
  284. static inline void CommitPages(void *mem, u32 page, u32 size)
  285. {
  286.      size = (size+4095) & ~4095;
  287.      __asm__ __volatile__ (
  288.      "call *__imp__CommitPages"
  289.      ::"a" (page), "b"(mem),"c"(size>>12)
  290.      :"edx" );
  291.      __asm__ __volatile__ ("":::"eax","ebx","ecx");
  292. };
  293.  
  294. static inline void UnmapPages(void *mem, size_t size)
  295. {
  296.      size = (size+4095) & ~4095;
  297.      __asm__ __volatile__ (
  298.      "call *__imp__UnmapPages"
  299.      ::"a" (mem), "c"(size>>12)
  300.      :"edx");
  301.      __asm__ __volatile__ ("":::"eax","ecx");
  302. };
  303.  
  304. static inline void usleep(u32 delay)
  305. {
  306.      if( !delay )
  307.         delay++;
  308.      delay*= 500;
  309.  
  310.      while(delay--)
  311.         __asm__ __volatile__(
  312.         "xorl %%eax, %%eax \n\t"
  313.         "cpuid \n\t"
  314.         :::"eax","ebx","ecx","edx");
  315.      };
  316.  
  317. static inline void udelay1(u32 delay)
  318. {
  319.     if(!delay) delay++;
  320.     delay*= 100;
  321.  
  322.     while(delay--)
  323.     {
  324.         __asm__ __volatile__(
  325.         "xorl %%eax, %%eax \n\t"
  326.         "cpuid"
  327.         :::"eax","ebx","ecx","edx" );
  328.     }
  329. }
  330.  
  331. static inline void msleep1(unsigned int msecs)
  332. {
  333.     msecs /= 10;
  334.     if(!msecs) msecs = 1;
  335.  
  336.      __asm__ __volatile__ (
  337.      "call *__imp__Delay"
  338.      ::"b" (msecs));
  339.      __asm__ __volatile__ (
  340.      "":::"ebx");
  341.  
  342. };
  343.  
  344. static inline void mdelay1(u32 time)
  345. {
  346.     time /= 10;
  347.     if(!time) time = 1;
  348.  
  349.      __asm__ __volatile__ (
  350.      "call *__imp__Delay"
  351.      ::"b" (time));
  352.      __asm__ __volatile__ (
  353.      "":::"ebx");
  354.  
  355. };
  356.  
  357. static inline u32 __PciApi(int cmd)
  358. {
  359.      u32 retval;
  360.  
  361.      __asm__ __volatile__ (
  362.      "call *__imp__PciApi \n\t"
  363.      "movzxb %%al, %%eax"
  364.      :"=a" (retval)
  365.      :"a" (cmd)
  366.      :"cc");
  367.  
  368.      return retval;
  369. };
  370.  
  371. static inline void* __CreateObject(u32 pid, size_t size)
  372. {
  373.      void *retval;
  374.  
  375.      __asm__ __volatile__ (
  376.      "call *__imp__CreateObject \n\t"
  377.      :"=a" (retval)
  378.      :"a" (size),"b"(pid)
  379.      :"esi","edi", "memory");
  380.      return retval;
  381. }
  382.  
  383. static inline void __DestroyObject(void *obj)
  384. {
  385.      __asm__ __volatile__ (
  386.      "call *__imp__DestroyObject \n\t"
  387.      :
  388.      :"a" (obj));
  389.      __asm__ __volatile__ (
  390.      ""
  391.      :::"eax","ebx","ecx","edx","esi","edi","cc","memory");
  392. }
  393.  
  394. static inline u32 GetService(const char *name)
  395. {
  396.     u32 handle;
  397.  
  398.     __asm__ __volatile__
  399.     (
  400.      "pushl %%eax \n\t"
  401.      "call *__imp__GetService"
  402.      :"=a" (handle)
  403.      :"a" (name)
  404.      :"ebx","ecx","edx","esi", "edi"
  405.   );
  406.   return handle;
  407. };
  408.  
  409. static inline u32 safe_cli(void)
  410. {
  411.      u32 ifl;
  412.      __asm__ __volatile__ (
  413.      "pushf\n\t"
  414.      "popl %0\n\t"
  415.      "cli\n"
  416.      : "=r" (ifl));
  417.     return ifl;
  418. }
  419.  
  420. static inline void safe_sti(u32 efl)
  421. {
  422.      if (efl & (1<<9))
  423.         __asm__ __volatile__ ("sti");
  424. }
  425.  
  426. static inline u32 get_eflags(void)
  427. {
  428.     u32 val;
  429.     asm volatile (
  430.     "pushfl\n\t"
  431.     "popl %0\n"
  432.     : "=r" (val));
  433.     return val;
  434. }
  435.  
  436. static inline void __clear (void * dst, unsigned len)
  437. {
  438.      u32 tmp;
  439.      __asm__ __volatile__ (
  440.      "cld \n\t"
  441.      "rep stosb \n"
  442.      :"=c"(tmp),"=D"(tmp)
  443.      :"a"(0),"c"(len),"D"(dst));
  444.      __asm__ __volatile__ ("":::"ecx","edi");
  445. };
  446.  
  447. static inline void out8(const u16 port, const u8 val)
  448. {
  449.     __asm__ __volatile__
  450.     ("outb  %1, %0\n" : : "dN"(port), "a"(val));
  451. }
  452.  
  453. static inline void out16(const u16 port, const u16 val)
  454. {
  455.     __asm__ __volatile__
  456.     ("outw  %1, %0\n" : : "dN"(port), "a"(val));
  457. }
  458.  
  459. static inline void out32(const u16 port, const u32 val)
  460. {
  461.     __asm__ __volatile__
  462.     ("outl  %1, %0\n" : : "dN"(port), "a"(val));
  463. }
  464.  
  465. static inline u8 in8(const u16 port)
  466. {
  467.     u8 tmp;
  468.     __asm__ __volatile__
  469.     ("inb %1, %0\n" : "=a"(tmp) : "dN"(port));
  470.     return tmp;
  471. };
  472.  
  473. static inline u16 in16(const u16 port)
  474. {
  475.     u16 tmp;
  476.     __asm__ __volatile__
  477.     ("inw %1, %0\n" : "=a"(tmp) : "dN"(port));
  478.     return tmp;
  479. };
  480.  
  481. static inline u32 in32(const u16 port)
  482. {
  483.     u32 tmp;
  484.     __asm__ __volatile__
  485.     ("inl %1, %0\n" : "=a"(tmp) : "dN"(port));
  486.     return tmp;
  487. };
  488.  
  489. static inline void delay(int time)
  490. {
  491.      __asm__ __volatile__ (
  492.      "call *__imp__Delay"
  493.      ::"b" (time));
  494.      __asm__ __volatile__ (
  495.      "":::"ebx");
  496.  
  497. }
  498.  
  499. static inline void change_task(void)
  500. {
  501.      __asm__ __volatile__ (
  502.      "call *__imp__ChangeTask");
  503. }
  504.  
  505. static inline void sysSetScreen(int width, int height, int pitch)
  506. {
  507.     __asm__ __volatile__
  508.     (
  509.         "call *__imp__SetScreen"
  510.         :
  511.         :"a" (width-1),"d"(height-1), "c"(pitch)
  512.     );
  513.     __asm__ __volatile__
  514.     ("" :::"eax","ecx","edx");
  515. }
  516.  
  517. int drm_order(unsigned long size);
  518.  
  519. static inline void __iomem *ioremap(u32 offset, size_t size)
  520. {
  521.     return (void __iomem*) MapIoMem(offset, size, PG_SW|PG_NOCACHE|0x100);
  522. }
  523.  
  524. static inline void __iomem *ioremap_nocache(u32 offset, size_t size)
  525. {
  526.     return (void __iomem*) MapIoMem(offset, size, PG_SW|PG_NOCACHE|0x100);
  527. }
  528.  
  529. static inline void __iomem *ioremap_wc(u32 offset, size_t size)
  530. {
  531.     return (void __iomem*) MapIoMem(offset, size, PG_SW|PG_WRITEC|0x100);
  532. }
  533.  
  534.  
  535. static inline void iounmap(void *addr)
  536. {
  537.     FreeKernelSpace(addr);
  538. }
  539.  
  540. static inline void __SysMsgBoardStr(char *text)
  541. {
  542.     __asm__ __volatile__(
  543.     "call *__imp__SysMsgBoardStr"
  544.     ::"S" (text));
  545. };
  546.  
  547. static inline void *vzalloc(unsigned long size)
  548. {
  549.     void *mem;
  550.  
  551.     mem = KernelAlloc(size);
  552.     if(mem)
  553.         memset(mem, 0, size);
  554.  
  555.    return mem;
  556. };
  557.  
  558. static inline void vfree(void *addr)
  559. {
  560.     KernelFree(addr);
  561. }
  562.  
  563. static inline int power_supply_is_system_supplied(void) { return -1; };
  564.  
  565.  
  566. #endif
  567.