Subversion Repositories Kolibri OS

Rev

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