Subversion Repositories Kolibri OS

Rev

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