Subversion Repositories Kolibri OS

Rev

Rev 9827 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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