Subversion Repositories Kolibri OS

Rev

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