Subversion Repositories Kolibri OS

Rev

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

Rev 6346 Rev 6536
1
#ifndef __KOS_32_SYS_H__
1
#ifndef __KOS_32_SYS_H__
2
#define __KOS_32_SYS_H__
2
#define __KOS_32_SYS_H__
3
 
3
 
4
#include 
4
#include 
5
#include 
5
#include 
6
#include 
6
#include 
7
 
7
 
8
#ifdef __cplusplus
8
#ifdef __cplusplus
9
extern "C" {
9
extern "C" {
10
#endif
10
#endif
11
 
11
 
12
//#ifdef CONFIG_DEBUF
12
//#ifdef CONFIG_DEBUF
13
//  #define DBG(format,...) printf(format,##__VA_ARGS__)
13
//  #define DBG(format,...) printf(format,##__VA_ARGS__)
14
//#else
14
//#else
15
//  #define DBG(format,...)
15
//  #define DBG(format,...)
16
//#endif
16
//#endif
17
 
17
 
18
#define TYPE_3_BORDER_WIDTH  5
18
#define TYPE_3_BORDER_WIDTH  5
19
#define WIN_STATE_MINIMIZED  0x02
19
#define WIN_STATE_MINIMIZED  0x02
20
#define WIN_STATE_ROLLED     0x04
20
#define WIN_STATE_ROLLED     0x04
21
 
21
 
22
typedef  unsigned int color_t;
22
typedef  unsigned int color_t;
23
 
23
 
24
typedef union __attribute__((packed))
24
typedef union __attribute__((packed))
25
{
25
{
26
    uint32_t val;
26
    uint32_t val;
27
    struct
27
    struct
28
    {
28
    {
29
        short  x;
29
        short  x;
30
        short  y;
30
        short  y;
31
    };
31
    };
32
}pos_t;
32
}pos_t;
33
 
33
 
34
typedef union __attribute__((packed))
34
typedef union __attribute__((packed))
35
{
35
{
36
    uint32_t val;
36
    uint32_t val;
37
    struct
37
    struct
38
    {
38
    {
39
        uint8_t   state;
39
        uint8_t   state;
40
        uint8_t   code;
40
        uint8_t   code;
41
        uint16_t  ctrl_key;
41
        uint16_t  ctrl_key;
42
    };
42
    };
43
}oskey_t;
43
}oskey_t;
44
 
44
 
45
typedef struct
45
typedef struct
46
{
46
{
47
  unsigned      handle;
47
  unsigned      handle;
48
  unsigned      io_code;
48
  unsigned      io_code;
49
  void          *input;
49
  void          *input;
50
  int           inp_size;
50
  int           inp_size;
51
  void          *output;
51
  void          *output;
52
  int           out_size;
52
  int           out_size;
53
}ioctl_t;
53
}ioctl_t;
54
 
54
 
55
static inline void begin_draw(void)
55
static inline void begin_draw(void)
56
{
56
{
57
    __asm__ __volatile__(
57
    __asm__ __volatile__(
58
    "int $0x40" ::"a"(12),"b"(1));
58
    "int $0x40" ::"a"(12),"b"(1));
59
};
59
};
60
 
60
 
61
static inline
61
static inline
62
void end_draw(void)
62
void end_draw(void)
63
{
63
{
64
    __asm__ __volatile__(
64
    __asm__ __volatile__(
65
    "int $0x40" ::"a"(12),"b"(2));
65
    "int $0x40" ::"a"(12),"b"(2));
66
};
66
};
67
 
67
 
68
static inline void 
68
static inline void
69
put_image(uint16_t x_coord, uint16_t y_coord,
69
put_image(uint16_t x_coord, uint16_t y_coord,
70
	  uint16_t size_x, uint16_t size_y, void *img)
70
	  uint16_t size_x, uint16_t size_y, void *img)
71
{
71
{
72
    __asm__ __volatile__("int $0x40" 
72
    __asm__ __volatile__("int $0x40"
73
			 ::"a"(25),
73
			 ::"a"(25),
74
			  "b"(img),
74
			  "b"(img),
75
			  "c"(size_x<<16 | size_y),
75
			  "c"(size_x<<16 | size_y),
76
			  "d"(x_coord<<16 | y_coord));
76
			  "d"(x_coord<<16 | y_coord));
77
};
77
};
78
 
78
 
79
 
79
 
80
static inline
80
static inline
81
void sys_create_window(int x, int y, int w, int h, const char *name,
81
void sys_create_window(int x, int y, int w, int h, const char *name,
82
                       color_t workcolor, uint32_t style)
82
                       color_t workcolor, uint32_t style)
83
{
83
{
84
    __asm__ __volatile__(
84
    __asm__ __volatile__(
85
    "int $0x40"
85
    "int $0x40"
86
    ::"a"(0),
86
    ::"a"(0),
87
     "b"((x << 16) | ((w-1) & 0xFFFF)),
87
     "b"((x << 16) | ((w-1) & 0xFFFF)),
88
     "c"((y << 16) | ((h-1) & 0xFFFF)),
88
     "c"((y << 16) | ((h-1) & 0xFFFF)),
89
     "d"((style << 24) | (workcolor & 0xFFFFFF)),
89
     "d"((style << 24) | (workcolor & 0xFFFFFF)),
90
     "D"(name),
90
     "D"(name),
91
     "S"(0) : "memory");
91
     "S"(0) : "memory");
92
};
92
};
93
 
93
 
94
static inline
94
static inline
95
void define_button(uint32_t x_w, uint32_t y_h, uint32_t id, uint32_t color)
95
void define_button(uint32_t x_w, uint32_t y_h, uint32_t id, uint32_t color)
96
{
96
{
97
    __asm__ __volatile__(
97
    __asm__ __volatile__(
98
    "int $0x40"
98
    "int $0x40"
99
    ::"a"(8),
99
    ::"a"(8),
100
      "b"(x_w),
100
      "b"(x_w),
101
      "c"(y_h),
101
      "c"(y_h),
102
      "d"(id),
102
      "d"(id),
103
      "S"(color));
103
      "S"(color));
104
};
104
};
105
 
105
 
106
static inline
106
static inline
107
void draw_line(int xs, int ys, int xe, int ye, color_t color)
107
void draw_line(int xs, int ys, int xe, int ye, color_t color)
108
{
108
{
109
    __asm__ __volatile__(
109
    __asm__ __volatile__(
110
    "int $0x40"
110
    "int $0x40"
111
    ::"a"(38), "d"(color),
111
    ::"a"(38), "d"(color),
112
      "b"((xs << 16) | xe),
112
      "b"((xs << 16) | xe),
113
      "c"((ys << 16) | ye));
113
      "c"((ys << 16) | ye));
114
}
114
}
115
 
115
 
116
static inline
116
static inline
117
void draw_bar(int x, int y, int w, int h, color_t color)
117
void draw_bar(int x, int y, int w, int h, color_t color)
118
{
118
{
119
    __asm__ __volatile__(
119
    __asm__ __volatile__(
120
    "int $0x40"
120
    "int $0x40"
121
    ::"a"(13), "d"(color),
121
    ::"a"(13), "d"(color),
122
      "b"((x << 16) | w),
122
      "b"((x << 16) | w),
123
      "c"((y << 16) | h));
123
      "c"((y << 16) | h));
124
}
124
}
125
 
125
 
126
static inline
126
static inline
127
void draw_bitmap(void *bitmap, int x, int y, int w, int h)
127
void draw_bitmap(void *bitmap, int x, int y, int w, int h)
128
{
128
{
129
    __asm__ __volatile__(
129
    __asm__ __volatile__(
130
    "int $0x40"
130
    "int $0x40"
131
    ::"a"(7), "b"(bitmap),
131
    ::"a"(7), "b"(bitmap),
132
      "c"((w << 16) | h),
132
      "c"((w << 16) | h),
133
      "d"((x << 16) | y));
133
      "d"((x << 16) | y));
134
}
134
}
135
 
135
 
136
static inline
136
static inline
137
void draw_text_sys(const char *text, int x, int y, int len, color_t color)
137
void draw_text_sys(const char *text, int x, int y, int len, color_t color)
138
{
138
{
139
    __asm__ __volatile__(
139
    __asm__ __volatile__(
140
    "int $0x40"
140
    "int $0x40"
141
    ::"a"(4),"d"(text),
141
    ::"a"(4),"d"(text),
142
      "b"((x << 16) | y),
142
      "b"((x << 16) | y),
143
      "S"(len),"c"(color)
143
      "S"(len),"c"(color)
144
     :"memory");
144
     :"memory");
145
}
145
}
146
 
146
 
147
static inline
147
static inline
148
uint32_t get_skin_height(void)
148
uint32_t get_skin_height(void)
149
{
149
{
150
    uint32_t height;
150
    uint32_t height;
151
 
151
 
152
    __asm__ __volatile__(
152
    __asm__ __volatile__(
153
    "int $0x40 \n\t"
153
    "int $0x40 \n\t"
154
    :"=a"(height)
154
    :"=a"(height)
155
    :"a"(48),"b"(4));
155
    :"a"(48),"b"(4));
156
    return height;
156
    return height;
157
};
157
};
158
 
158
 
159
static inline void BeginDraw(void) __attribute__ ((alias ("begin_draw")));
159
static inline void BeginDraw(void) __attribute__ ((alias ("begin_draw")));
160
static inline void EndDraw(void) __attribute__ ((alias ("end_draw")));
160
static inline void EndDraw(void) __attribute__ ((alias ("end_draw")));
161
static inline void DrawWindow(int x, int y, int w, int h, const char *name,
161
static inline void DrawWindow(int x, int y, int w, int h, const char *name,
162
                              color_t workcolor, uint32_t style)
162
                              color_t workcolor, uint32_t style)
163
                              __attribute__ ((alias ("sys_create_window")));
163
                              __attribute__ ((alias ("sys_create_window")));
164
static inline void DefineButton(void) __attribute__ ((alias ("define_button")));
164
static inline void DefineButton(void) __attribute__ ((alias ("define_button")));
165
static inline void DrawLine(int xs, int ys, int xe, int ye, color_t color)
165
static inline void DrawLine(int xs, int ys, int xe, int ye, color_t color)
166
                            __attribute__ ((alias ("draw_line")));
166
                            __attribute__ ((alias ("draw_line")));
167
static inline void DrawBar(int x, int y, int w, int h, color_t color)
167
static inline void DrawBar(int x, int y, int w, int h, color_t color)
168
                           __attribute__ ((alias ("draw_bar")));
168
                           __attribute__ ((alias ("draw_bar")));
169
static inline void DrawBitmap(void *bitmap, int x, int y, int w, int h)
169
static inline void DrawBitmap(void *bitmap, int x, int y, int w, int h)
170
                              __attribute__ ((alias ("draw_bitmap")));
170
                              __attribute__ ((alias ("draw_bitmap")));
171
static inline uint32_t GetSkinHeight(void) __attribute__ ((alias ("get_skin_height")));
171
static inline uint32_t GetSkinHeight(void) __attribute__ ((alias ("get_skin_height")));
172
 
172
 
173
 
173
 
174
#define POS_SCREEN 0
174
#define POS_SCREEN 0
175
#define POS_WINDOW 1
175
#define POS_WINDOW 1
176
 
176
 
177
static inline
177
static inline
178
pos_t get_mouse_pos(int origin)
178
pos_t get_mouse_pos(int origin)
179
{
179
{
180
    pos_t val;
180
    pos_t val;
181
 
181
 
182
    __asm__ __volatile__(
182
    __asm__ __volatile__(
183
    "int $0x40 \n\t"
183
    "int $0x40 \n\t"
184
    "rol $16, %%eax"
184
    "rol $16, %%eax"
185
    :"=a"(val)
185
    :"=a"(val)
186
    :"a"(37),"b"(origin));
186
    :"a"(37),"b"(origin));
187
    return val;
187
    return val;
188
}
188
}
189
 
189
 
190
static inline
190
static inline
191
uint32_t get_mouse_buttons(void)
191
uint32_t get_mouse_buttons(void)
192
{
192
{
193
    uint32_t val;
193
    uint32_t val;
194
 
194
 
195
    __asm__ __volatile__(
195
    __asm__ __volatile__(
196
    "int $0x40"
196
    "int $0x40"
197
    :"=a"(val)
197
    :"=a"(val)
198
    :"a"(37),"b"(2));
198
    :"a"(37),"b"(2));
199
    return val;
199
    return val;
200
};
200
};
201
 
201
 
202
static inline
202
static inline
203
uint32_t get_mouse_wheels(void)
203
uint32_t get_mouse_wheels(void)
204
{
204
{
205
    uint32_t val;
205
    uint32_t val;
206
 
206
 
207
    __asm__ __volatile__(
207
    __asm__ __volatile__(
208
    "int $0x40 \n\t"
208
    "int $0x40 \n\t"
209
    :"=a"(val)
209
    :"=a"(val)
210
    :"a"(37),"b"(7));
210
    :"a"(37),"b"(7));
211
    return val;
211
    return val;
212
};
212
};
213
 
213
 
214
static inline uint32_t load_cursor(void *path, uint32_t flags)
214
static inline uint32_t load_cursor(void *path, uint32_t flags)
215
{
215
{
216
    uint32_t  val;
216
    uint32_t  val;
217
    __asm__ __volatile__(
217
    __asm__ __volatile__(
218
    "int $0x40"
218
    "int $0x40"
219
    :"=a"(val)
219
    :"=a"(val)
220
    :"a"(37), "b"(4), "c"(path), "d"(flags));
220
    :"a"(37), "b"(4), "c"(path), "d"(flags));
221
    return val;
221
    return val;
222
}
222
}
223
 
223
 
224
static inline uint32_t  set_cursor(uint32_t  cursor)
224
static inline uint32_t  set_cursor(uint32_t  cursor)
225
{
225
{
226
    uint32_t  old;
226
    uint32_t  old;
227
    __asm__ __volatile__(
227
    __asm__ __volatile__(
228
    "int $0x40"
228
    "int $0x40"
229
    :"=a"(old)
229
    :"=a"(old)
230
    :"a"(37), "b"(5), "c"(cursor));
230
    :"a"(37), "b"(5), "c"(cursor));
231
    return old;
231
    return old;
232
};
232
};
233
 
233
 
234
static inline uint32_t set_wanted_events_mask(uint32_t event_mask)
234
static inline uint32_t set_wanted_events_mask(uint32_t event_mask)
235
{
235
{
236
  uint32_t  old_event_mask;
236
  uint32_t  old_event_mask;
237
    __asm__ __volatile__(
237
    __asm__ __volatile__(
238
    "int $0x40"
238
    "int $0x40"
239
    :"=a"(old_event_mask)
239
    :"=a"(old_event_mask)
240
    :"a"(40));
240
    :"a"(40),"b"(event_mask));
241
 
241
 
242
    return old_event_mask;
242
    return old_event_mask;
243
};
243
};
244
 
244
 
245
static inline int destroy_cursor(uint32_t cursor)
245
static inline int destroy_cursor(uint32_t cursor)
246
{
246
{
247
    int ret;
247
    int ret;
248
    __asm__ __volatile__(
248
    __asm__ __volatile__(
249
    "int $0x40"
249
    "int $0x40"
250
    :"=a"(ret)
250
    :"=a"(ret)
251
    :"a"(37), "b"(6), "c"(cursor)
251
    :"a"(37), "b"(6), "c"(cursor)
252
    :"memory");
252
    :"memory");
253
    return ret;
253
    return ret;
254
};
254
};
255
 
255
 
256
static inline pos_t GetMousePos(int origin) __attribute__ ((alias ("get_mouse_pos")));
256
static inline pos_t GetMousePos(int origin) __attribute__ ((alias ("get_mouse_pos")));
257
static inline uint32_t GetMouseButtons(void) __attribute__ ((alias ("get_mouse_buttons")));
257
static inline uint32_t GetMouseButtons(void) __attribute__ ((alias ("get_mouse_buttons")));
258
static inline uint32_t GetMouseWheels(void) __attribute__ ((alias ("get_mouse_wheels")));
258
static inline uint32_t GetMouseWheels(void) __attribute__ ((alias ("get_mouse_wheels")));
259
 
259
 
260
static inline uint32_t  LoadCursor(void *path, uint32_t flags) __attribute__ ((alias ("load_cursor")));
260
static inline uint32_t  LoadCursor(void *path, uint32_t flags) __attribute__ ((alias ("load_cursor")));
261
static inline uint32_t SetCursor(uint32_t  cursor) __attribute__ ((alias ("set_cursor")));
261
static inline uint32_t SetCursor(uint32_t  cursor) __attribute__ ((alias ("set_cursor")));
262
static inline int DestroyCursor(uint32_t cursor) __attribute__ ((alias ("destroy_cursor")));
262
static inline int DestroyCursor(uint32_t cursor) __attribute__ ((alias ("destroy_cursor")));
263
 
263
 
264
 
264
 
265
static inline
265
static inline
266
uint32_t wait_for_event(uint32_t time)
266
uint32_t wait_for_event(uint32_t time)
267
{
267
{
268
    uint32_t val;
268
    uint32_t val;
269
    __asm__ __volatile__(
269
    __asm__ __volatile__(
270
    "int $0x40"
270
    "int $0x40"
271
    :"=a"(val)
271
    :"=a"(val)
272
    :"a"(23), "b"(time));
272
    :"a"(23), "b"(time));
273
    return val;
273
    return val;
274
};
274
};
275
 
275
 
276
static inline uint32_t check_os_event()
276
static inline uint32_t check_os_event(void)
277
{
277
{
278
    uint32_t val;
278
    uint32_t val;
279
    __asm__ __volatile__(
279
    __asm__ __volatile__(
280
    "int $0x40"
280
    "int $0x40"
281
    :"=a"(val)
281
    :"=a"(val)
282
    :"a"(11));
282
    :"a"(11));
283
    return val;
283
    return val;
284
};
284
};
285
 
285
 
286
static inline uint32_t get_os_event()
286
static inline uint32_t get_os_event(void)
287
{
287
{
288
    uint32_t val;
288
    uint32_t val;
289
    __asm__ __volatile__(
289
    __asm__ __volatile__(
290
    "int $0x40"
290
    "int $0x40"
291
    :"=a"(val)
291
    :"=a"(val)
292
    :"a"(10));
292
    :"a"(10));
293
    return val;
293
    return val;
294
};
294
};
295
static inline uint32_t GetOsEvent(void) __attribute__ ((alias ("get_os_event")));
295
static inline uint32_t GetOsEvent(void) __attribute__ ((alias ("get_os_event")));
296
 
296
 
297
static inline
297
static inline
298
uint32_t get_tick_count(void)
298
uint32_t get_tick_count(void)
299
{
299
{
300
    uint32_t val;
300
    uint32_t val;
301
    __asm__ __volatile__(
301
    __asm__ __volatile__(
302
    "int $0x40"
302
    "int $0x40"
303
    :"=a"(val)
303
    :"=a"(val)
304
    :"a"(26),"b"(9));
304
    :"a"(26),"b"(9));
305
    return val;
305
    return val;
306
};
306
};
307
 
307
 
308
static inline
308
static inline
309
uint64_t get_ns_count(void)
309
uint64_t get_ns_count(void)
310
{
310
{
311
    uint64_t val;
311
    uint64_t val;
312
    __asm__ __volatile__(
312
    __asm__ __volatile__(
313
    "int $0x40"
313
    "int $0x40"
314
    :"=A"(val)
314
    :"=A"(val)
315
    :"a"(26), "b"(10));
315
    :"a"(26), "b"(10));
316
    return val;
316
    return val;
317
};
317
};
318
 
318
 
319
static inline
319
static inline
320
oskey_t get_key(void)
320
oskey_t get_key(void)
321
{
321
{
322
    oskey_t val;
322
    oskey_t val;
323
    __asm__ __volatile__(
323
    __asm__ __volatile__(
324
    "int $0x40"
324
    "int $0x40"
325
    :"=a"(val)
325
    :"=a"(val)
326
    :"a"(2));
326
    :"a"(2));
327
    return val;
327
    return val;
328
}
328
}
329
 
329
 
330
static inline
330
static inline
331
uint32_t get_os_button()
331
uint32_t get_os_button(void)
332
{
332
{
333
    uint32_t val;
333
    uint32_t val;
334
    __asm__ __volatile__(
334
    __asm__ __volatile__(
335
    "int $0x40"
335
    "int $0x40"
336
    :"=a"(val)
336
    :"=a"(val)
337
    :"a"(17));
337
    :"a"(17));
338
    return val>>8;
338
    return val>>8;
339
};
339
};
340
 
340
 
341
static inline uint32_t get_service(char *name)
341
static inline uint32_t get_service(char *name)
342
{
342
{
343
    uint32_t retval = 0;
343
    uint32_t retval = 0;
344
    __asm__ __volatile__(
344
    __asm__ __volatile__(
345
    "int $0x40"
345
    "int $0x40"
346
    :"=a"(retval)
346
    :"=a"(retval)
347
    :"a"(68),"b"(16),"c"(name)
347
    :"a"(68),"b"(16),"c"(name)
348
    :"memory");
348
    :"memory");
349
 
349
 
350
    return retval;
350
    return retval;
351
};
351
};
352
 
352
 
353
static inline int call_service(ioctl_t *io)
353
static inline int call_service(ioctl_t *io)
354
{
354
{
355
    int retval;
355
    int retval;
356
 
356
 
357
    __asm__ __volatile__(
357
    __asm__ __volatile__(
358
    "int $0x40"
358
    "int $0x40"
359
    :"=a"(retval)
359
    :"=a"(retval)
360
    :"a"(68),"b"(17),"c"(io)
360
    :"a"(68),"b"(17),"c"(io)
361
    :"memory","cc");
361
    :"memory","cc");
362
 
362
 
363
    return retval;
363
    return retval;
364
};
364
};
365
 
365
 
366
 
366
 
367
static inline void yield(void)
367
static inline void yield(void)
368
{
368
{
369
    __asm__ __volatile__(
369
    __asm__ __volatile__(
370
    "int $0x40"
370
    "int $0x40"
371
    ::"a"(68), "b"(1));
371
    ::"a"(68), "b"(1));
372
};
372
};
373
 
373
 
374
static inline void delay(uint32_t time)
374
static inline void delay(uint32_t time)
375
{
375
{
376
    __asm__ __volatile__(
376
    __asm__ __volatile__(
377
    "int $0x40"
377
    "int $0x40"
378
    ::"a"(5), "b"(time)
378
    ::"a"(5), "b"(time)
379
    :"memory");
379
    :"memory");
380
};
380
};
381
 
381
 
382
static inline
382
static inline
383
void *user_alloc(size_t size)
383
void *user_alloc(size_t size)
384
{
384
{
385
    void  *val;
385
    void  *val;
386
    __asm__ __volatile__(
386
    __asm__ __volatile__(
387
    "int $0x40"
387
    "int $0x40"
388
    :"=a"(val)
388
    :"=a"(val)
389
    :"a"(68),"b"(12),"c"(size));
389
    :"a"(68),"b"(12),"c"(size));
390
    return val;
390
    return val;
391
}
391
}
392
 
392
 
393
static inline
393
static inline
394
int user_free(void *mem)
394
int user_free(void *mem)
395
{
395
{
396
    int  val;
396
    int  val;
397
    __asm__ __volatile__(
397
    __asm__ __volatile__(
398
    "int $0x40"
398
    "int $0x40"
399
    :"=a"(val)
399
    :"=a"(val)
400
    :"a"(68),"b"(13),"c"(mem));
400
    :"a"(68),"b"(13),"c"(mem));
401
    return val;
401
    return val;
402
}
402
}
403
 
403
 
404
static inline
404
static inline
405
void* user_realloc(void *mem, size_t size)
405
void* user_realloc(void *mem, size_t size)
406
{
406
{
407
    void *val;
407
    void *val;
408
    __asm__ __volatile__(
408
    __asm__ __volatile__(
409
    "int $0x40"
409
    "int $0x40"
410
    :"=a"(val)
410
    :"=a"(val)
411
    :"a"(68),"b"(20),"c"(size),"d"(mem)
411
    :"a"(68),"b"(20),"c"(size),"d"(mem)
412
    :"memory");
412
    :"memory");
413
 
413
 
414
    return val;
414
    return val;
415
};
415
};
416
 
416
 
417
static inline
417
static inline
418
int *user_unmap(void *base, size_t offset, size_t size)
418
int *user_unmap(void *base, size_t offset, size_t size)
419
{
419
{
420
    int  *val;
420
    int  *val;
421
    __asm__ __volatile__(
421
    __asm__ __volatile__(
422
    "int $0x40"
422
    "int $0x40"
423
    :"=a"(val)
423
    :"=a"(val)
424
    :"a"(68),"b"(26),"c"(base),"d"(offset),"S"(size));
424
    :"a"(68),"b"(26),"c"(base),"d"(offset),"S"(size));
425
    return val;
425
    return val;
426
};
426
};
427
 
427
 
428
static inline void *UserAlloc(size_t size) __attribute__ ((alias ("user_alloc")));
428
static inline void *UserAlloc(size_t size) __attribute__ ((alias ("user_alloc")));
429
static inline int UserFree(void *mem) __attribute__ ((alias ("user_free")));
429
static inline int UserFree(void *mem) __attribute__ ((alias ("user_free")));
430
static inline void* UserRealloc(void *mem, size_t size) __attribute__ ((alias ("user_realloc")));
430
static inline void* UserRealloc(void *mem, size_t size) __attribute__ ((alias ("user_realloc")));
431
static inline int *UserUnmap(void *base, size_t offset, size_t size) __attribute__ ((alias ("user_unmap")));
431
static inline int *UserUnmap(void *base, size_t offset, size_t size) __attribute__ ((alias ("user_unmap")));
432
 
432
 
433
typedef union
433
typedef union
434
{
434
{
435
    struct
435
    struct
436
    {
436
    {
437
        void   *data;
437
        void   *data;
438
        size_t  size;
438
        size_t  size;
439
    };
439
    };
440
    unsigned long long raw;
440
    unsigned long long raw;
441
}ufile_t;
441
}ufile_t;
442
 
442
 
443
static inline ufile_t load_file(const char *path)
443
static inline ufile_t load_file(const char *path)
444
{
444
{
445
    ufile_t uf;
445
    ufile_t uf;
446
 
446
 
447
    __asm__ __volatile__ (
447
    __asm__ __volatile__ (
448
    "int $0x40"
448
    "int $0x40"
449
    :"=A"(uf.raw)
449
    :"=A"(uf.raw)
450
    :"a" (68), "b"(27),"c"(path));
450
    :"a" (68), "b"(27),"c"(path));
451
 
451
 
452
    return uf;
452
    return uf;
453
};
453
};
454
static inline ufile_t LoadFile(const char *path) __attribute__ ((alias ("load_file")));
454
static inline ufile_t LoadFile(const char *path) __attribute__ ((alias ("load_file")));
455
 
455
 
456
static inline int GetScreenSize()
456
static inline int GetScreenSize(void)
457
{
457
{
458
    int retval;
458
    int retval;
459
 
459
 
460
    __asm__ __volatile__(
460
    __asm__ __volatile__(
461
    "int $0x40"
461
    "int $0x40"
462
    :"=a"(retval)
462
    :"=a"(retval)
463
    :"a"(61), "b"(1));
463
    :"a"(61), "b"(1));
464
    return retval;
464
    return retval;
465
}
465
}
466
 
466
 
467
 
467
 
468
static inline void get_proc_info(char *info)
468
static inline void get_proc_info(char *info)
469
{
469
{
470
    __asm__ __volatile__(
470
    __asm__ __volatile__(
471
    "int $0x40"
471
    "int $0x40"
472
    :
472
    :
473
    :"a"(9), "b"(info), "c"(-1)
473
    :"a"(9), "b"(info), "c"(-1)
474
    :"memory");
474
    :"memory");
475
};
475
};
476
static inline void GetProcInfo(char *info) __attribute__ ((alias ("get_proc_info")));
476
static inline void GetProcInfo(char *info) __attribute__ ((alias ("get_proc_info")));
477
 
477
 
478
 
478
 
479
struct blit_call
479
struct blit_call
480
{
480
{
481
    int dstx;
481
    int dstx;
482
    int dsty;
482
    int dsty;
483
    int w;
483
    int w;
484
    int h;
484
    int h;
485
 
485
 
486
    int srcx;
486
    int srcx;
487
    int srcy;
487
    int srcy;
488
    int srcw;
488
    int srcw;
489
    int srch;
489
    int srch;
490
 
490
 
491
    void *bitmap;
491
    void *bitmap;
492
    int   stride;
492
    int   stride;
493
};
493
};
494
 
494
 
495
static inline void Blit(void *bitmap, int dst_x, int dst_y,
495
static inline void Blit(void *bitmap, int dst_x, int dst_y,
496
                        int src_x, int src_y, int w, int h,
496
                        int src_x, int src_y, int w, int h,
497
                        int src_w, int src_h, int stride)
497
                        int src_w, int src_h, int stride)
498
{
498
{
499
    volatile struct blit_call bc;
499
    volatile struct blit_call bc;
500
 
500
 
501
    bc.dstx = dst_x;
501
    bc.dstx = dst_x;
502
    bc.dsty = dst_y;
502
    bc.dsty = dst_y;
503
    bc.w    = w;
503
    bc.w    = w;
504
    bc.h    = h;
504
    bc.h    = h;
505
    bc.srcx = src_x;
505
    bc.srcx = src_x;
506
    bc.srcy = src_y;
506
    bc.srcy = src_y;
507
    bc.srcw = src_w;
507
    bc.srcw = src_w;
508
    bc.srch = src_h;
508
    bc.srch = src_h;
509
    bc.stride = stride;
509
    bc.stride = stride;
510
    bc.bitmap = bitmap;
510
    bc.bitmap = bitmap;
511
 
511
 
512
    __asm__ __volatile__(
512
    __asm__ __volatile__(
513
    "int $0x40"
513
    "int $0x40"
514
    ::"a"(73),"b"(0),"c"(&bc.dstx));
514
    ::"a"(73),"b"(0),"c"(&bc.dstx));
515
};
515
};
-
 
516
 
-
 
517
#define TLS_KEY_PID         0
-
 
518
#define TLS_KEY_TID         4
-
 
519
#define TLS_KEY_LOW_STACK   8
-
 
520
#define TLS_KEY_HIGH_STACK 12
-
 
521
#define TLS_KEY_LIBC       16
-
 
522
 
-
 
523
unsigned int tls_alloc(void);
-
 
524
int tls_free(unsigned int key);
-
 
525
 
-
 
526
static inline int tls_set(unsigned int key, void *val)
-
 
527
{
-
 
528
    int ret = -1;
-
 
529
    if(key < 4096)
-
 
530
    {
-
 
531
        __asm__ __volatile__(
-
 
532
        "movl %0, %%fs:(%1)"
-
 
533
        ::"r"(val),"r"(key));
-
 
534
        ret = 0;
-
 
535
    }
-
 
536
    return ret;
-
 
537
};
-
 
538
 
-
 
539
static inline void *tls_get(unsigned int key)
-
 
540
{
-
 
541
    void *val = (void*)-1;
-
 
542
    if(key < 4096)
-
 
543
    {
-
 
544
        __asm__ __volatile__(
-
 
545
        "movl %%fs:(%1), %0"
-
 
546
        :"=r"(val)
-
 
547
        :"r"(key));
-
 
548
    };
-
 
549
    return val;
-
 
550
}
-
 
551
 
516
 
552
 
517
int create_thread(int (*proc)(void *param), void *param, int stack_size);
553
int create_thread(int (*proc)(void *param), void *param, int stack_size);
518
 
554
 
519
void* load_library(const char *name);
555
void* load_library(const char *name);
520
 
556
 
521
void* get_proc_address(void *handle, const char *proc_name);
557
void* get_proc_address(void *handle, const char *proc_name);
522
 
558
 
523
void enumerate_libraries(int (*callback)(void *handle, const char* name,
559
void enumerate_libraries(int (*callback)(void *handle, const char* name,
524
                                         uint32_t base, uint32_t size, void *user_data),
560
                                         uint32_t base, uint32_t size, void *user_data),
525
                         void *user_data);
561
                         void *user_data);
526
 
562
 
527
#ifdef __cplusplus
563
#ifdef __cplusplus
528
}
564
}
529
#endif
565
#endif
530
 
566
 
531
 
567
 
532
#endif
568
#endif