Subversion Repositories Kolibri OS

Rev

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