Subversion Repositories Kolibri OS

Rev

Rev 5272 | Rev 6102 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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