Subversion Repositories Kolibri OS

Rev

Rev 6346 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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