Subversion Repositories Kolibri OS

Rev

Rev 5345 | 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
 
6082 serge 9
typedef struct
10
{
11
  int width;
12
  int height;
13
  int bpp;
14
  int freq;
15
}videomode_t;
16
 
1029 serge 17
///////////////////////////////////////////////////////////////////////////////
18
 
1434 serge 19
#define STDCALL  __attribute__ ((stdcall)) __attribute__ ((dllimport))
20
#define FASTCALL __attribute__ ((fastcall)) __attribute__ ((dllimport))
1029 serge 21
 
1434 serge 22
#define IMPORT   __attribute__ ((dllimport))
23
 
1029 serge 24
///////////////////////////////////////////////////////////////////////////////
25
 
26
#define SysMsgBoardStr  __SysMsgBoardStr
27
#define PciApi          __PciApi
28
#define CreateObject    __CreateObject
29
#define DestroyObject   __DestroyObject
30
 
1872 serge 31
#define _alloca(x) __builtin_alloca((x))
32
 
1029 serge 33
///////////////////////////////////////////////////////////////////////////////
34
 
35
 
36
void*  STDCALL AllocKernelSpace(size_t size)__asm__("AllocKernelSpace");
1408 serge 37
void   STDCALL FreeKernelSpace(void *mem)__asm__("FreeKernelSpace");
5270 serge 38
addr_t STDCALL MapIoMem(addr_t base, size_t size, u32 flags)__asm__("MapIoMem");
1029 serge 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
 
1613 serge 44
void*  STDCALL GetDisplay(void)__asm__("GetDisplay");
1408 serge 45
 
5270 serge 46
u32  IMPORT  GetTimerTicks(void)__asm__("GetTimerTicks");
6082 serge 47
u64  IMPORT  GetClockNs(void)__asm__("GetClockNs");
1408 serge 48
 
1613 serge 49
addr_t STDCALL AllocPage(void)__asm__("AllocPage");
1029 serge 50
addr_t STDCALL AllocPages(count_t count)__asm__("AllocPages");
2967 Serge 51
void   IMPORT  __attribute__((regparm(1)))
52
               FreePage(addr_t page)__asm__("FreePage");
5270 serge 53
void   STDCALL MapPage(void *vaddr, addr_t paddr, u32 flags)__asm__("MapPage");
1029 serge 54
 
2967 Serge 55
 
5270 serge 56
void* STDCALL CreateRingBuffer(size_t size, u32 map)__asm__("CreateRingBuffer");
1029 serge 57
 
5270 serge 58
u32 STDCALL RegService(char *name, srv_proc_t proc)__asm__("RegService");
1029 serge 59
 
5270 serge 60
int   STDCALL AttachIntHandler(int irq, void *handler, u32 access) __asm__("AttachIntHandler");
1029 serge 61
 
1434 serge 62
void  FASTCALL MutexInit(struct mutex*)__asm__("MutexInit");
63
void  FASTCALL MutexLock(struct mutex*)__asm__("MutexLock");
64
void  FASTCALL MutexUnlock(struct mutex*)__asm__("MutexUnlock");
1029 serge 65
 
5345 serge 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
 
1872 serge 72
addr_t IMPORT  GetStackBase(void)__asm__("GetStackBase");
5270 serge 73
u32  IMPORT  GetPid(void)__asm__("GetPid");
1872 serge 74
 
4125 Serge 75
u32 STDCALL TimerHS(u32 delay, u32 interval,
76
                    void *fn, void *data)asm("TimerHS");
2967 Serge 77
 
4125 Serge 78
void STDCALL CancelTimerHS(u32 handle)asm("CancelTimerHS");
79
 
3482 Serge 80
u64 IMPORT GetCpuFreq()__asm__("GetCpuFreq");
81
 
1029 serge 82
///////////////////////////////////////////////////////////////////////////////
83
 
84
void   STDCALL SetMouseData(int btn, int x, int y,
85
                            int z, int h)__asm__("SetMouseData");
86
 
5270 serge 87
void   FASTCALL SetKeyboardData(u32 data)__asm__("SetKeyboardData");
1872 serge 88
 
89
 
5270 serge 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");
1029 serge 93
 
5270 serge 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");
1029 serge 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
 
3031 serge 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
 
1029 serge 158
///////////////////////////////////////////////////////////////////////////////
159
 
160
int dbg_open(char *path);
161
int dbgprintf(const char* format, ...);
162
 
163
///////////////////////////////////////////////////////////////////////////////
164
 
4110 Serge 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
 
5270 serge 178
static inline evhandle_t CreateEvent(kevent_t *ev, u32 flags)
1029 serge 179
{
1616 serge 180
     evhandle_t evh;
1613 serge 181
 
182
     __asm__ __volatile__ (
183
     "call *__imp__CreateEvent"
1616 serge 184
     :"=A"(evh.raw)
185
     :"S" (ev), "c"(flags)
186
     :"memory");
2005 serge 187
     __asm__ __volatile__ ("":::"ebx","ecx","edx","esi", "edi");
1613 serge 188
 
1616 serge 189
     return evh;
190
};
1613 serge 191
 
5270 serge 192
static inline void RaiseEvent(evhandle_t evh, u32 flags, kevent_t *ev)
1616 serge 193
{
194
     __asm__ __volatile__ (
195
     "call *__imp__RaiseEvent"
196
     ::"a"(evh.handle),"b"(evh.euid),"d"(flags),"S" (ev)
197
     :"memory");
2005 serge 198
     __asm__ __volatile__ ("":::"ebx","ecx","edx","esi","edi");
1616 serge 199
 
200
};
201
 
2005 serge 202
static inline void WaitEvent(evhandle_t evh)
1616 serge 203
{
204
     __asm__ __volatile__ (
205
     "call *__imp__WaitEvent"
2005 serge 206
     ::"a"(evh.handle),"b"(evh.euid));
207
     __asm__ __volatile__ ("":::"ebx","ecx","edx","esi","edi");
1616 serge 208
};
209
 
3391 Serge 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
 
2967 Serge 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
 
5270 serge 229
static inline u32 GetEvent(kevent_t *ev)
1616 serge 230
{
5270 serge 231
    u32  handle;
1616 serge 232
 
233
    __asm__ __volatile__ (
234
    "call *__imp__GetEvent"
235
    :"=a"(handle)
236
    :"D"(ev)
237
    :"memory");
238
    __asm__ __volatile__ ("":::"ebx","ecx","edx", "esi","edi");
1613 serge 239
     return handle;
240
};
241
 
1616 serge 242
 
1613 serge 243
static inline int GetScreenSize(void)
244
{
1029 serge 245
  int retval;
246
 
247
  asm("int $0x40"
248
      :"=a"(retval)
249
      :"a"(61), "b"(1));
250
  return retval;
251
}
252
 
1613 serge 253
static inline int GetScreenBpp(void)
1029 serge 254
{
255
  int retval;
256
 
257
  asm("int $0x40"
258
      :"=a"(retval)
259
      :"a"(61), "b"(2));
260
  return retval;
261
}
262
 
1613 serge 263
static inline int GetScreenPitch(void)
1029 serge 264
{
265
  int retval;
266
 
267
  asm("int $0x40"
268
      :"=a"(retval)
269
      :"a"(61), "b"(3));
270
  return retval;
271
}
272
 
5270 serge 273
static inline u32 GetPgAddr(void *mem)
1029 serge 274
{
5270 serge 275
     u32 retval;
1029 serge 276
 
277
     __asm__ __volatile__ (
278
     "call *__imp__GetPgAddr \n\t"
2967 Serge 279
     :"=a" (retval)
1029 serge 280
     :"a" (mem) );
281
     return retval;
282
};
283
 
5270 serge 284
static inline void CommitPages(void *mem, u32 page, u32 size)
1029 serge 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
 
1408 serge 294
static inline void UnmapPages(void *mem, size_t size)
1029 serge 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
 
5270 serge 304
static inline void usleep(u32 delay)
1029 serge 305
{
306
     if( !delay )
307
        delay++;
1408 serge 308
     delay*= 500;
1029 serge 309
 
310
     while(delay--)
1408 serge 311
        __asm__ __volatile__(
312
        "xorl %%eax, %%eax \n\t"
313
        "cpuid \n\t"
314
        :::"eax","ebx","ecx","edx");
315
     };
316
 
5270 serge 317
static inline void udelay1(u32 delay)
1408 serge 318
{
319
    if(!delay) delay++;
2967 Serge 320
    delay*= 100;
1408 serge 321
 
322
    while(delay--)
323
    {
324
        __asm__ __volatile__(
325
        "xorl %%eax, %%eax \n\t"
326
        "cpuid"
327
        :::"eax","ebx","ecx","edx" );
328
    }
329
}
330
 
5270 serge 331
static inline void msleep1(unsigned int msecs)
1964 serge 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
 
5270 serge 344
static inline void mdelay1(u32 time)
1408 serge 345
{
346
    time /= 10;
347
    if(!time) time = 1;
348
 
1029 serge 349
     __asm__ __volatile__ (
1408 serge 350
     "call *__imp__Delay"
351
     ::"b" (time));
352
     __asm__ __volatile__ (
353
     "":::"ebx");
354
 
1029 serge 355
};
356
 
5270 serge 357
static inline u32 __PciApi(int cmd)
1029 serge 358
{
5270 serge 359
     u32 retval;
1029 serge 360
 
361
     __asm__ __volatile__ (
1616 serge 362
     "call *__imp__PciApi \n\t"
363
     "movzxb %%al, %%eax"
1029 serge 364
     :"=a" (retval)
365
     :"a" (cmd)
1630 serge 366
     :"cc");
367
 
1029 serge 368
     return retval;
369
};
370
 
5270 serge 371
static inline void* __CreateObject(u32 pid, size_t size)
1029 serge 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
 
1408 serge 383
static inline void __DestroyObject(void *obj)
1029 serge 384
{
385
     __asm__ __volatile__ (
1408 serge 386
     "call *__imp__DestroyObject \n\t"
1029 serge 387
     :
1408 serge 388
     :"a" (obj));
389
     __asm__ __volatile__ (
390
     ""
391
     :::"eax","ebx","ecx","edx","esi","edi","cc","memory");
1029 serge 392
}
393
 
5270 serge 394
static inline u32 GetService(const char *name)
1029 serge 395
{
5270 serge 396
    u32 handle;
1408 serge 397
 
398
    __asm__ __volatile__
399
    (
400
     "pushl %%eax \n\t"
401
     "call *__imp__GetService"
2967 Serge 402
     :"=a" (handle)
1408 serge 403
     :"a" (name)
404
     :"ebx","ecx","edx","esi", "edi"
405
  );
406
  return handle;
407
};
408
 
5270 serge 409
static inline u32 safe_cli(void)
1408 serge 410
{
5270 serge 411
     u32 ifl;
1029 serge 412
     __asm__ __volatile__ (
413
     "pushf\n\t"
414
     "popl %0\n\t"
415
     "cli\n"
416
     : "=r" (ifl));
417
    return ifl;
418
}
419
 
5270 serge 420
static inline void safe_sti(u32 efl)
1029 serge 421
{
1616 serge 422
     if (efl & (1<<9))
423
        __asm__ __volatile__ ("sti");
1029 serge 424
}
425
 
5270 serge 426
static inline u32 get_eflags(void)
1613 serge 427
{
5270 serge 428
    u32 val;
1613 serge 429
    asm volatile (
430
    "pushfl\n\t"
431
    "popl %0\n"
432
    : "=r" (val));
433
    return val;
434
}
435
 
1408 serge 436
static inline void __clear (void * dst, unsigned len)
1029 serge 437
{
5270 serge 438
     u32 tmp;
1029 serge 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
 
5270 serge 447
static inline void out8(const u16 port, const u8 val)
1029 serge 448
{
449
    __asm__ __volatile__
450
    ("outb  %1, %0\n" : : "dN"(port), "a"(val));
451
}
452
 
5270 serge 453
static inline void out16(const u16 port, const u16 val)
1029 serge 454
{
455
    __asm__ __volatile__
456
    ("outw  %1, %0\n" : : "dN"(port), "a"(val));
457
}
458
 
5270 serge 459
static inline void out32(const u16 port, const u32 val)
1029 serge 460
{
461
    __asm__ __volatile__
462
    ("outl  %1, %0\n" : : "dN"(port), "a"(val));
463
}
464
 
5270 serge 465
static inline u8 in8(const u16 port)
1029 serge 466
{
5270 serge 467
    u8 tmp;
1029 serge 468
    __asm__ __volatile__
469
    ("inb %1, %0\n" : "=a"(tmp) : "dN"(port));
470
    return tmp;
471
};
472
 
5270 serge 473
static inline u16 in16(const u16 port)
1029 serge 474
{
5270 serge 475
    u16 tmp;
1029 serge 476
    __asm__ __volatile__
477
    ("inw %1, %0\n" : "=a"(tmp) : "dN"(port));
478
    return tmp;
479
};
480
 
5270 serge 481
static inline u32 in32(const u16 port)
1029 serge 482
{
5270 serge 483
    u32 tmp;
1029 serge 484
    __asm__ __volatile__
485
    ("inl %1, %0\n" : "=a"(tmp) : "dN"(port));
486
    return tmp;
487
};
488
 
1408 serge 489
static inline void delay(int time)
1029 serge 490
{
491
     __asm__ __volatile__ (
492
     "call *__imp__Delay"
493
     ::"b" (time));
494
     __asm__ __volatile__ (
495
     "":::"ebx");
496
 
497
}
498
 
1613 serge 499
static inline void change_task(void)
1029 serge 500
{
501
     __asm__ __volatile__ (
502
     "call *__imp__ChangeTask");
503
}
504
 
1613 serge 505
static inline void sysSetScreen(int width, int height, int pitch)
1408 serge 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
 
5270 serge 519
static inline void __iomem *ioremap(u32 offset, size_t size)
1408 serge 520
{
4538 Serge 521
    return (void __iomem*) MapIoMem(offset, size, PG_SW|PG_NOCACHE|0x100);
1408 serge 522
}
523
 
6082 serge 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
 
5270 serge 529
static inline void __iomem *ioremap_wc(u32 offset, size_t size)
3391 Serge 530
{
6082 serge 531
    return (void __iomem*) MapIoMem(offset, size, PG_SW|PG_WRITEC|0x100);
3391 Serge 532
}
533
 
534
 
1408 serge 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
 
3031 serge 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
 
6082 serge 563
static inline int power_supply_is_system_supplied(void) { return -1; };
3031 serge 564
 
565
 
1408 serge 566
#endif