Subversion Repositories Kolibri OS

Rev

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

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