Subversion Repositories Kolibri OS

Rev

Rev 1222 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1222 Rev 1230
1
#ifndef __SYSCALL_H__
1
#ifndef __SYSCALL_H__
2
#define __SYSCALL_H__
2
#define __SYSCALL_H__
3
 
3
 
4
 
4
 
5
#define OS_BASE   0x80000000
5
#define OS_BASE   0x80000000
6
 
6
 
7
typedef struct
7
typedef struct
8
{
8
{
9
  u32_t      handle;
9
  u32_t      handle;
10
  u32_t      io_code;
10
  u32_t      io_code;
11
  void       *input;
11
  void       *input;
12
  int        inp_size;
12
  int        inp_size;
13
  void       *output;
13
  void       *output;
14
  int        out_size;
14
  int        out_size;
15
}ioctl_t;
15
}ioctl_t;
16
 
16
 
17
typedef int (__stdcall *srv_proc_t)(ioctl_t *);
17
typedef int (__stdcall *srv_proc_t)(ioctl_t *);
18
 
18
 
19
#define ERR_OK       0
19
#define ERR_OK       0
20
#define ERR_PARAM   -1
20
#define ERR_PARAM   -1
21
 
21
 
22
 
22
 
23
u32_t drvEntry(int, char *)__asm__("_drvEntry");
23
u32_t drvEntry(int, char *)__asm__("_drvEntry");
24
 
24
 
25
///////////////////////////////////////////////////////////////////////////////
25
///////////////////////////////////////////////////////////////////////////////
26
 
26
 
27
#define STDCALL __attribute__ ((stdcall)) __attribute__ ((dllimport))
27
#define STDCALL __attribute__ ((stdcall)) __attribute__ ((dllimport))
28
#define IMPORT __attribute__ ((dllimport))
28
#define IMPORT __attribute__ ((dllimport))
29
 
29
 
30
///////////////////////////////////////////////////////////////////////////////
30
///////////////////////////////////////////////////////////////////////////////
31
 
31
 
32
#define SysMsgBoardStr  __SysMsgBoardStr
32
#define SysMsgBoardStr  __SysMsgBoardStr
33
#define PciApi          __PciApi
33
#define PciApi          __PciApi
34
//#define RegService      __RegService
34
//#define RegService      __RegService
35
#define CreateObject    __CreateObject
35
#define CreateObject    __CreateObject
36
#define DestroyObject   __DestroyObject
36
#define DestroyObject   __DestroyObject
37
 
37
 
38
///////////////////////////////////////////////////////////////////////////////
38
///////////////////////////////////////////////////////////////////////////////
39
 
39
 
40
#define PG_SW       0x003
40
#define PG_SW       0x003
41
#define PG_NOCACHE  0x018
41
#define PG_NOCACHE  0x018
42
 
42
 
43
void*  STDCALL AllocKernelSpace(size_t size)__asm__("AllocKernelSpace");
43
void*  STDCALL AllocKernelSpace(size_t size)__asm__("AllocKernelSpace");
44
void   STDCALL FreeKernelSpace(void *mem)__asm__("FreeKernelSpace");
44
void   STDCALL FreeKernelSpace(void *mem)__asm__("FreeKernelSpace");
45
addr_t STDCALL MapIoMem(addr_t base, size_t size, u32_t flags)__asm__("MapIoMem");
45
addr_t STDCALL MapIoMem(addr_t base, size_t size, u32_t flags)__asm__("MapIoMem");
46
void*  STDCALL KernelAlloc(size_t size)__asm__("KernelAlloc");
46
void*  STDCALL KernelAlloc(size_t size)__asm__("KernelAlloc");
47
void*  STDCALL KernelFree(void *mem)__asm__("KernelFree");
47
void*  STDCALL KernelFree(void *mem)__asm__("KernelFree");
48
void*  STDCALL UserAlloc(size_t size)__asm__("UserAlloc");
48
void*  STDCALL UserAlloc(size_t size)__asm__("UserAlloc");
49
int    STDCALL UserFree(void *mem)__asm__("UserFree");
49
int    STDCALL UserFree(void *mem)__asm__("UserFree");
50
 
50
 
-
 
51
void*  STDCALL GetDisplay()__asm__("GetDisplay");
-
 
52
 
-
 
53
 
51
addr_t STDCALL AllocPages(count_t count)__asm__("AllocPages");
54
addr_t STDCALL AllocPages(count_t count)__asm__("AllocPages");
52
 
55
 
53
void* STDCALL CreateRingBuffer(size_t size, u32_t map)__asm__("CreateRingBuffer");
56
void* STDCALL CreateRingBuffer(size_t size, u32_t map)__asm__("CreateRingBuffer");
54
 
57
 
55
u32_t STDCALL RegService(char *name, srv_proc_t proc)__asm__("RegService");
58
u32_t STDCALL RegService(char *name, srv_proc_t proc)__asm__("RegService");
56
 
59
 
57
int   STDCALL AttachIntHandler(int irq, void *handler, u32_t access) __asm__("AttachIntHandler");
60
int   STDCALL AttachIntHandler(int irq, void *handler, u32_t access) __asm__("AttachIntHandler");
58
 
61
 
59
 
62
 
60
///////////////////////////////////////////////////////////////////////////////
63
///////////////////////////////////////////////////////////////////////////////
61
 
64
 
62
void   STDCALL SetMouseData(int btn, int x, int y,
65
void   STDCALL SetMouseData(int btn, int x, int y,
63
                            int z, int h)__asm__("SetMouseData");
66
                            int z, int h)__asm__("SetMouseData");
64
 
67
 
65
static u32_t PciApi(int cmd);
68
static u32_t PciApi(int cmd);
66
 
69
 
67
u8_t  STDCALL PciRead8 (u32_t bus, u32_t devfn, u32_t reg)__asm__("PciRead8");
70
u8_t  STDCALL PciRead8 (u32_t bus, u32_t devfn, u32_t reg)__asm__("PciRead8");
68
u16_t STDCALL PciRead16(u32_t bus, u32_t devfn, u32_t reg)__asm__("PciRead16");
71
u16_t STDCALL PciRead16(u32_t bus, u32_t devfn, u32_t reg)__asm__("PciRead16");
69
u32_t STDCALL PciRead32(u32_t bus, u32_t devfn, u32_t reg)__asm__("PciRead32");
72
u32_t STDCALL PciRead32(u32_t bus, u32_t devfn, u32_t reg)__asm__("PciRead32");
70
 
73
 
71
u32_t STDCALL PciWrite8 (u32_t bus, u32_t devfn, u32_t reg,u8_t val) __asm__("PciWrite8");
74
u32_t STDCALL PciWrite8 (u32_t bus, u32_t devfn, u32_t reg,u8_t val) __asm__("PciWrite8");
72
u32_t STDCALL PciWrite16(u32_t bus, u32_t devfn, u32_t reg,u16_t val)__asm__("PciWrite16");
75
u32_t STDCALL PciWrite16(u32_t bus, u32_t devfn, u32_t reg,u16_t val)__asm__("PciWrite16");
73
u32_t STDCALL PciWrite32(u32_t bus, u32_t devfn, u32_t reg,u32_t val)__asm__("PciWrite32");
76
u32_t STDCALL PciWrite32(u32_t bus, u32_t devfn, u32_t reg,u32_t val)__asm__("PciWrite32");
74
 
77
 
75
#define pciReadByte(tag, reg) \
78
#define pciReadByte(tag, reg) \
76
        PciRead8(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg))
79
        PciRead8(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg))
77
 
80
 
78
#define pciReadWord(tag, reg) \
81
#define pciReadWord(tag, reg) \
79
        PciRead16(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg))
82
        PciRead16(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg))
80
 
83
 
81
#define pciReadLong(tag, reg) \
84
#define pciReadLong(tag, reg) \
82
        PciRead32(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg))
85
        PciRead32(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg))
83
 
86
 
84
#define pciWriteByte(tag, reg, val) \
87
#define pciWriteByte(tag, reg, val) \
85
        PciWrite8(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg),(val))
88
        PciWrite8(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg),(val))
86
 
89
 
87
#define pciWriteWord(tag, reg, val) \
90
#define pciWriteWord(tag, reg, val) \
88
        PciWrite16(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg),(val))
91
        PciWrite16(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg),(val))
89
 
92
 
90
#define pciWriteLong(tag, reg, val) \
93
#define pciWriteLong(tag, reg, val) \
91
        PciWrite32(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg),(val))
94
        PciWrite32(PCI_BUS_FROM_TAG(tag),PCI_DFN_FROM_TAG(tag),(reg),(val))
92
 
95
 
93
 
96
 
94
///////////////////////////////////////////////////////////////////////////////
97
///////////////////////////////////////////////////////////////////////////////
95
 
98
 
96
int dbg_open(char *path);
99
int dbg_open(char *path);
97
int dbgprintf(const char* format, ...);
100
int dbgprintf(const char* format, ...);
98
 
101
 
99
///////////////////////////////////////////////////////////////////////////////
102
///////////////////////////////////////////////////////////////////////////////
100
 
103
 
101
extern inline int GetScreenSize()
104
extern inline int GetScreenSize()
102
{
105
{
103
  int retval;
106
  int retval;
104
 
107
 
105
  asm("int $0x40"
108
  asm("int $0x40"
106
      :"=a"(retval)
109
      :"=a"(retval)
107
      :"a"(61), "b"(1));
110
      :"a"(61), "b"(1));
108
  return retval;
111
  return retval;
109
}
112
}
110
 
113
 
111
extern inline int GetScreenBpp()
114
extern inline int GetScreenBpp()
112
{
115
{
113
  int retval;
116
  int retval;
114
 
117
 
115
  asm("int $0x40"
118
  asm("int $0x40"
116
      :"=a"(retval)
119
      :"=a"(retval)
117
      :"a"(61), "b"(2));
120
      :"a"(61), "b"(2));
118
  return retval;
121
  return retval;
119
}
122
}
120
 
123
 
121
extern inline int GetScreenPitch()
124
extern inline int GetScreenPitch()
122
{
125
{
123
  int retval;
126
  int retval;
124
 
127
 
125
  asm("int $0x40"
128
  asm("int $0x40"
126
      :"=a"(retval)
129
      :"=a"(retval)
127
      :"a"(61), "b"(3));
130
      :"a"(61), "b"(3));
128
  return retval;
131
  return retval;
129
}
132
}
130
 
133
 
131
extern inline u32_t GetPgAddr(void *mem)
134
extern inline u32_t GetPgAddr(void *mem)
132
{
135
{
133
     u32_t retval;
136
     u32_t retval;
134
 
137
 
135
     __asm__ __volatile__ (
138
     __asm__ __volatile__ (
136
     "call *__imp__GetPgAddr \n\t"
139
     "call *__imp__GetPgAddr \n\t"
137
     :"=eax" (retval)
140
     :"=eax" (retval)
138
     :"a" (mem) );
141
     :"a" (mem) );
139
     return retval;
142
     return retval;
140
};
143
};
141
 
144
 
142
extern inline void CommitPages(void *mem, u32_t page, u32_t size)
145
extern inline void CommitPages(void *mem, u32_t page, u32_t size)
143
{
146
{
144
     size = (size+4095) & ~4095;
147
     size = (size+4095) & ~4095;
145
     __asm__ __volatile__ (
148
     __asm__ __volatile__ (
146
     "call *__imp__CommitPages"
149
     "call *__imp__CommitPages"
147
     ::"a" (page), "b"(mem),"c"(size>>12)
150
     ::"a" (page), "b"(mem),"c"(size>>12)
148
     :"edx" );
151
     :"edx" );
149
     __asm__ __volatile__ ("":::"eax","ebx","ecx");
152
     __asm__ __volatile__ ("":::"eax","ebx","ecx");
150
};
153
};
151
 
154
 
152
extern inline void UnmapPages(void *mem, size_t size)
155
extern inline void UnmapPages(void *mem, size_t size)
153
{
156
{
154
     size = (size+4095) & ~4095;
157
     size = (size+4095) & ~4095;
155
     __asm__ __volatile__ (
158
     __asm__ __volatile__ (
156
     "call *__imp__UnmapPages"
159
     "call *__imp__UnmapPages"
157
     ::"a" (mem), "c"(size>>12)
160
     ::"a" (mem), "c"(size>>12)
158
     :"edx");
161
     :"edx");
159
     __asm__ __volatile__ ("":::"eax","ecx");
162
     __asm__ __volatile__ ("":::"eax","ecx");
160
};
163
};
161
 
164
 
162
extern inline void usleep(u32_t delay)
165
extern inline void usleep(u32_t delay)
163
{
166
{
164
     if( !delay )
167
     if( !delay )
165
        delay++;
168
        delay++;
166
     delay*= 256;
169
     delay*= 256;
167
 
170
 
168
     while(delay--)
171
     while(delay--)
169
        __asm__ __volatile__(
172
        __asm__ __volatile__(
170
        "xorl %%eax, %%eax \n\t"
173
        "xorl %%eax, %%eax \n\t"
171
        "cpuid \n\t"
174
        "cpuid \n\t"
172
        :::"eax","ebx","ecx","edx");
175
        :::"eax","ebx","ecx","edx");
173
     };
176
     };
174
 
177
 
175
static inline void udelay(u32_t delay)
178
static inline void udelay(u32_t delay)
176
{
179
{
177
    if(!delay) delay++;
180
    if(!delay) delay++;
178
    delay*= 256;
181
    delay*= 256;
179
 
182
 
180
    while(delay--)
183
    while(delay--)
181
    {
184
    {
182
        __asm__ __volatile__(
185
        __asm__ __volatile__(
183
        "xorl %%eax, %%eax \n\t"
186
        "xorl %%eax, %%eax \n\t"
184
        "cpuid"
187
        "cpuid"
185
        :::"eax","ebx","ecx","edx" );
188
        :::"eax","ebx","ecx","edx" );
186
    }
189
    }
187
}
190
}
188
 
191
 
189
static inline void mdelay(u32_t time)
192
static inline void mdelay(u32_t time)
190
{
193
{
191
    time /= 10;
194
    time /= 10;
192
    if(!time) time = 1;
195
    if(!time) time = 1;
193
 
196
 
194
     __asm__ __volatile__ (
197
     __asm__ __volatile__ (
195
     "call *__imp__Delay"
198
     "call *__imp__Delay"
196
     ::"b" (time));
199
     ::"b" (time));
197
     __asm__ __volatile__ (
200
     __asm__ __volatile__ (
198
     "":::"ebx");
201
     "":::"ebx");
199
 
202
 
200
};
203
};
201
 
204
 
202
 
205
 
203
static inline u32_t __PciApi(int cmd)
206
static inline u32_t __PciApi(int cmd)
204
{
207
{
205
     u32_t retval;
208
     u32_t retval;
206
 
209
 
207
     __asm__ __volatile__ (
210
     __asm__ __volatile__ (
208
     "call *__imp__PciApi"
211
     "call *__imp__PciApi"
209
     :"=a" (retval)
212
     :"=a" (retval)
210
     :"a" (cmd)
213
     :"a" (cmd)
211
     :"memory");
214
     :"memory");
212
     return retval;
215
     return retval;
213
};
216
};
214
 
217
 
215
static inline void* __CreateObject(u32_t pid, size_t size)
218
static inline void* __CreateObject(u32_t pid, size_t size)
216
{
219
{
217
     void *retval;
220
     void *retval;
218
 
221
 
219
     __asm__ __volatile__ (
222
     __asm__ __volatile__ (
220
     "call *__imp__CreateObject \n\t"
223
     "call *__imp__CreateObject \n\t"
221
     :"=a" (retval)
224
     :"=a" (retval)
222
     :"a" (size),"b"(pid)
225
     :"a" (size),"b"(pid)
223
     :"esi","edi", "memory");
226
     :"esi","edi", "memory");
224
     return retval;
227
     return retval;
225
}
228
}
226
 
229
 
227
static inline void *__DestroyObject(void *obj)
230
static inline void *__DestroyObject(void *obj)
228
{
231
{
229
     __asm__ __volatile__ (
232
     __asm__ __volatile__ (
230
     "call *__imp__DestroyObject"
233
     "call *__imp__DestroyObject"
231
     :
234
     :
232
     :"a" (obj)
235
     :"a" (obj)
233
     :"ebx","edx","esi","edi", "memory");
236
     :"ebx","edx","esi","edi", "memory");
234
}
237
}
235
 
238
 
236
 
239
 
237
/*
240
/*
238
u32 __RegService(char *name, srv_proc_t proc)
241
u32 __RegService(char *name, srv_proc_t proc)
239
{
242
{
240
  u32 retval;
243
  u32 retval;
241
 
244
 
242
  asm __volatile__
245
  asm __volatile__
243
  (
246
  (
244
    "pushl %%eax \n\t"
247
    "pushl %%eax \n\t"
245
    "pushl %%ebx \n\t"
248
    "pushl %%ebx \n\t"
246
    "call *__imp__RegService \n\t"
249
    "call *__imp__RegService \n\t"
247
    :"=eax" (retval)
250
    :"=eax" (retval)
248
    :"a" (proc), "b" (name)
251
    :"a" (proc), "b" (name)
249
    :"memory"
252
    :"memory"
250
  );
253
  );
251
  return retval;
254
  return retval;
252
};
255
};
253
*/
256
*/
254
 
257
 
255
static inline u32_t safe_cli(void)
258
static inline u32_t safe_cli(void)
256
{
259
{
257
     u32_t ifl;
260
     u32_t ifl;
258
     __asm__ __volatile__ (
261
     __asm__ __volatile__ (
259
     "pushf\n\t"
262
     "pushf\n\t"
260
     "popl %0\n\t"
263
     "popl %0\n\t"
261
     "cli\n"
264
     "cli\n"
262
     : "=r" (ifl));
265
     : "=r" (ifl));
263
    return ifl;
266
    return ifl;
264
}
267
}
265
 
268
 
266
static inline void safe_sti(u32_t ifl)
269
static inline void safe_sti(u32_t ifl)
267
{
270
{
268
     __asm__ __volatile__ (
271
     __asm__ __volatile__ (
269
     "pushl %0\n\t"
272
     "pushl %0\n\t"
270
     "popf\n"
273
     "popf\n"
271
     : : "r" (ifl)
274
     : : "r" (ifl)
272
	);
275
	);
273
}
276
}
274
 
277
 
275
static inline void __clear (void * dst, unsigned len)
278
static inline void __clear (void * dst, unsigned len)
276
{
279
{
277
     u32_t tmp;
280
     u32_t tmp;
278
     __asm__ __volatile__ (
281
     __asm__ __volatile__ (
279
//     "xorl %%eax, %%eax \n\t"
282
//     "xorl %%eax, %%eax \n\t"
280
     "cld \n\t"
283
     "cld \n\t"
281
     "rep stosb \n"
284
     "rep stosb \n"
282
     :"=c"(tmp),"=D"(tmp)
285
     :"=c"(tmp),"=D"(tmp)
283
     :"a"(0),"c"(len),"D"(dst));
286
     :"a"(0),"c"(len),"D"(dst));
284
     __asm__ __volatile__ ("":::"ecx","edi");
287
     __asm__ __volatile__ ("":::"ecx","edi");
285
};
288
};
286
 
289
 
287
static inline void out8(const u16_t port, const u8_t val)
290
static inline void out8(const u16_t port, const u8_t val)
288
{
291
{
289
    __asm__ __volatile__
292
    __asm__ __volatile__
290
    ("outb  %1, %0\n" : : "dN"(port), "a"(val));
293
    ("outb  %1, %0\n" : : "dN"(port), "a"(val));
291
}
294
}
292
 
295
 
293
static inline void out16(const u16_t port, const u16_t val)
296
static inline void out16(const u16_t port, const u16_t val)
294
{
297
{
295
    __asm__ __volatile__
298
    __asm__ __volatile__
296
    ("outw  %1, %0\n" : : "dN"(port), "a"(val));
299
    ("outw  %1, %0\n" : : "dN"(port), "a"(val));
297
}
300
}
298
 
301
 
299
static inline void out32(const u16_t port, const u32_t val)
302
static inline void out32(const u16_t port, const u32_t val)
300
{
303
{
301
    __asm__ __volatile__
304
    __asm__ __volatile__
302
    ("outl  %1, %0\n" : : "dN"(port), "a"(val));
305
    ("outl  %1, %0\n" : : "dN"(port), "a"(val));
303
}
306
}
304
 
307
 
305
static inline u8_t in8(const u16_t port)
308
static inline u8_t in8(const u16_t port)
306
{
309
{
307
    u8_t tmp;
310
    u8_t tmp;
308
    __asm__ __volatile__
311
    __asm__ __volatile__
309
    ("inb %1, %0\n" : "=a"(tmp) : "dN"(port));
312
    ("inb %1, %0\n" : "=a"(tmp) : "dN"(port));
310
    return tmp;
313
    return tmp;
311
};
314
};
312
 
315
 
313
static inline u16_t in16(const u16_t port)
316
static inline u16_t in16(const u16_t port)
314
{
317
{
315
    u16_t tmp;
318
    u16_t tmp;
316
    __asm__ __volatile__
319
    __asm__ __volatile__
317
    ("inw %1, %0\n" : "=a"(tmp) : "dN"(port));
320
    ("inw %1, %0\n" : "=a"(tmp) : "dN"(port));
318
    return tmp;
321
    return tmp;
319
};
322
};
320
 
323
 
321
static inline u32_t in32(const u16_t port)
324
static inline u32_t in32(const u16_t port)
322
{
325
{
323
    u32_t tmp;
326
    u32_t tmp;
324
    __asm__ __volatile__
327
    __asm__ __volatile__
325
    ("inl %1, %0\n" : "=a"(tmp) : "dN"(port));
328
    ("inl %1, %0\n" : "=a"(tmp) : "dN"(port));
326
    return tmp;
329
    return tmp;
327
};
330
};
328
 
331
 
329
static inline void delay(int time)
332
static inline void delay(int time)
330
{
333
{
331
     __asm__ __volatile__ (
334
     __asm__ __volatile__ (
332
     "call *__imp__Delay"
335
     "call *__imp__Delay"
333
     ::"b" (time));
336
     ::"b" (time));
334
     __asm__ __volatile__ (
337
     __asm__ __volatile__ (
335
     "":::"ebx");
338
     "":::"ebx");
336
 
339
 
337
}
340
}
338
 
341
 
339
static inline void change_task()
342
static inline void change_task()
340
{
343
{
341
     __asm__ __volatile__ (
344
     __asm__ __volatile__ (
342
     "call *__imp__ChangeTask");
345
     "call *__imp__ChangeTask");
343
}
346
}
344
 
347
 
345
int drm_order(unsigned long size);
348
int drm_order(unsigned long size);
346
 
349
 
347
#endif
350
#endif