summaryrefslogtreecommitdiff
path: root/frontends/kolibrios/kos32sys.h
blob: de4bf6aaeef304a11c7c679b4d49669e9625c90c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
#ifndef __KOS_32_SYS_H__

#define __KOS_32_SYS_H__


#include <newlib.h>

#include <stdint.h>

#include <stddef.h>


#ifdef __cplusplus

extern "C" {
#endif


//#ifdef CONFIG_DEBUF

//  #define DBG(format,...) printf(format,##__VA_ARGS__)

//#else

//  #define DBG(format,...)

//#endif


#define TYPE_3_BORDER_WIDTH  5

#define WIN_STATE_MINIMIZED  0x02

#define WIN_STATE_ROLLED     0x04


typedef  unsigned int color_t;

typedef union __attribute__((packed))
{
    uint32_t val;
    struct
    {
        short  x;
        short  y;
    };
}pos_t;

typedef union __attribute__((packed))
{
    uint32_t val;
    struct
    {
        uint8_t   state;
        uint8_t   code;
        uint16_t  ctrl_key;
    };
}oskey_t;

typedef struct
{
  unsigned      handle;
  unsigned      io_code;
  void          *input;
  int           inp_size;
  void          *output;
  int           out_size;
}ioctl_t;


static inline
void define_button(uint32_t x_w, uint32_t y_h, uint32_t id, uint32_t color)
{
    __asm__ __volatile__(
    "int $0x40"
    ::"a"(8),
      "b"(x_w),
      "c"(y_h),
      "d"(id),
      "S"(color));
};
static inline void DefineButton(void) __attribute__ ((alias ("define_button")));

static inline
uint32_t get_skin_height(void)
{
    uint32_t height;

    __asm__ __volatile__(
    "int $0x40 \n\t"
    :"=a"(height)
    :"a"(48),"b"(4));
    return height;
};
static inline uint32_t GetSkinHeight(void) __attribute__ ((alias ("get_skin_height")));

static inline
void BeginDraw(void)
{
    __asm__ __volatile__(
    "int $0x40" ::"a"(12),"b"(1));
};

static inline
void EndDraw(void)
{
    __asm__ __volatile__(
    "int $0x40" ::"a"(12),"b"(2));
};

static inline void DrawWindow(int x, int y, int w, int h, const char *name,
                       color_t workcolor, uint32_t style)
{

    __asm__ __volatile__(
    "int $0x40"
    ::"a"(0),
     "b"((x << 16) | ((w-1) & 0xFFFF)),
     "c"((y << 16) | ((h-1) & 0xFFFF)),
     "d"((style << 24) | (workcolor & 0xFFFFFF)),
     "D"(name),
     "S"(0) : "memory");
};

#define POS_SCREEN 0

#define POS_WINDOW 1


static inline
pos_t get_mouse_pos(int origin)
{
    pos_t val;

    __asm__ __volatile__(
    "int $0x40 \n\t"
    "rol $16, %%eax"
    :"=a"(val)
    :"a"(37),"b"(origin));
    return val;
}
static inline pos_t GetMousePos(int origin) __attribute__ ((alias ("get_mouse_pos")));

static inline
uint32_t get_mouse_buttons(void)
{
    uint32_t val;

    __asm__ __volatile__(
    "int $0x40"
    :"=a"(val)
    :"a"(37),"b"(2));
    return val;
};
static inline uint32_t GetMouseButtons(void) __attribute__ ((alias ("get_mouse_buttons")));

static inline
uint32_t get_mouse_wheels(void)
{
    uint32_t val;

    __asm__ __volatile__(
    "int $0x40 \n\t"
    :"=a"(val)
    :"a"(37),"b"(7));
    return val;
};
static inline uint32_t GetMouseWheels(void) __attribute__ ((alias ("get_mouse_wheels")));

static inline
uint32_t wait_for_event(uint32_t time)
{
    uint32_t val;
    __asm__ __volatile__(
    "int $0x40"
    :"=a"(val)
    :"a"(23), "b"(time));
    return val;
};

static inline uint32_t check_os_event()
{
    uint32_t val;
    __asm__ __volatile__(
    "int $0x40"
    :"=a"(val)
    :"a"(11));
    return val;
};

static inline uint32_t get_os_event()
{
    uint32_t val;
    __asm__ __volatile__(
    "int $0x40"
    :"=a"(val)
    :"a"(10));
    return val;
};
static inline uint32_t GetOsEvent(void) __attribute__ ((alias ("get_os_event")));

static inline
uint32_t get_tick_count(void)
{
    uint32_t val;
    __asm__ __volatile__(
    "int $0x40"
    :"=a"(val)
    :"a"(26),"b"(9));
    return val;
};

static inline
uint64_t get_ns_count(void)
{
    uint64_t val;
    __asm__ __volatile__(
    "int $0x40"
    :"=A"(val)
    :"a"(26), "b"(10));
    return val;
};

static inline
oskey_t get_key(void)
{
    oskey_t val;
    __asm__ __volatile__(
    "int $0x40"
    :"=a"(val)
    :"a"(2));
    return val;
}

static inline
uint32_t get_os_button()
{
    uint32_t val;
    __asm__ __volatile__(
    "int $0x40"
    :"=a"(val)
    :"a"(17));
    return val>>8;
};

static inline uint32_t get_service(char *name)
{
    uint32_t retval = 0;
    __asm__ __volatile__(
    "int $0x40"
    :"=a"(retval)
    :"a"(68),"b"(16),"c"(name)
    :"memory");

    return retval;
};

static inline int call_service(ioctl_t *io)
{
    int retval;

    __asm__ __volatile__(
    "int $0x40"
    :"=a"(retval)
    :"a"(68),"b"(17),"c"(io)
    :"memory","cc");

    return retval;
};


static inline
void draw_line(int xs, int ys, int xe, int ye, color_t color)
{
    __asm__ __volatile__(
    "int $0x40"
    ::"a"(38), "d"(color),
      "b"((xs << 16) | xe),
      "c"((ys << 16) | ye));
}



static inline
void draw_bar(int x, int y, int w, int h, color_t color)
{
    __asm__ __volatile__(
    "int $0x40"
    ::"a"(13), "d"(color),
      "b"((x << 16) | w),
      "c"((y << 16) | h));
}

static inline
void draw_bitmap(void *bitmap, int x, int y, int w, int h)
{
    __asm__ __volatile__(
    "int $0x40"
    ::"a"(7), "b"(bitmap),
      "c"((w << 16) | h),
      "d"((x << 16) | y));
}

static inline
void draw_text_sys(const char *text, int x, int y, int len, color_t color)
{
    __asm__ __volatile__(
    "int $0x40"
    ::"a"(4),"d"(text),
      "b"((x << 16) | y),
      "S"(len),"c"(color)
     :"memory");
}

static inline void yield(void)
{
    __asm__ __volatile__(
    "int $0x40"
    ::"a"(68), "b"(1));
};

static inline void delay(uint32_t time)
{
    __asm__ __volatile__(
    "int $0x40"
    ::"a"(5), "b"(time)
    :"memory");
};

static inline
void *user_alloc(size_t size)
{
    void  *val;
    __asm__ __volatile__(
    "int $0x40"
    :"=a"(val)
    :"a"(68),"b"(12),"c"(size));
    return val;
}
static inline void *UserAlloc(size_t size) __attribute__ ((alias ("user_alloc")));

static inline
int user_free(void *mem)
{
    int  val;
    __asm__ __volatile__(
    "int $0x40"
    :"=a"(val)
    :"a"(68),"b"(13),"c"(mem));
    return val;
}
static inline int UserFree(void *mem) __attribute__ ((alias ("user_free")));

static inline
int *user_unmap(void *base, size_t offset, size_t size)
{
    int  *val;
    __asm__ __volatile__(
    "int $0x40"
    :"=a"(val)
    :"a"(68),"b"(26),"c"(base),"d"(offset),"S"(size));
    return val;
};
static inline int *UserUnmap(void *base, size_t offset, size_t size) __attribute__ ((alias ("user_unmap")));

typedef union
{
    struct
    {
        void   *data;
        size_t  size;
    };
    unsigned long long raw;
}ufile_t;


static inline ufile_t load_file(const char *path)
{
    ufile_t uf;

    __asm__ __volatile__ (
    "int $0x40"
    :"=A"(uf.raw)
    :"a" (68), "b"(27),"c"(path));

    return uf;
};
static inline ufile_t LoadFile(const char *path) __attribute__ ((alias ("load_file")));

static inline int GetScreenSize()
{
    int retval;

    __asm__ __volatile__(
    "int $0x40"
    :"=a"(retval)
    :"a"(61), "b"(1));
    return retval;
}

static inline
uint32_t  load_cursor(void *path, uint32_t flags)
{
    uint32_t  val;
    __asm__ __volatile__(
    "int $0x40"
    :"=a"(val)
    :"a"(37), "b"(4), "c"(path), "d"(flags));
    return val;
}
static inline
uint32_t  LoadCursor(void *path, uint32_t flags) __attribute__ ((alias ("load_cursor")));

static inline
uint32_t  set_cursor(uint32_t  cursor)
{
    uint32_t  old;
    __asm__ __volatile__(
    "int $0x40"
    :"=a"(old)
    :"a"(37), "b"(5), "c"(cursor));
    return old;
};
static inline uint32_t SetCursor(uint32_t  cursor) __attribute__ ((alias ("set_cursor")));

static inline
int destroy_cursor(uint32_t cursor)
{
    int ret;
    __asm__ __volatile__(
    "int $0x40"
    :"=a"(ret)
    :"a"(37), "b"(6), "c"(cursor)
    :"memory");
    return ret;
};
static inline int DestroyCursor(uint32_t cursor) __attribute__ ((alias ("destroy_cursor")));

static inline void get_proc_info(char *info)
{
    __asm__ __volatile__(
    "int $0x40"
    :
    :"a"(9), "b"(info), "c"(-1));
};
static inline void GetProcInfo(char *info) __attribute__ ((alias ("get_proc_info")));

static inline
void* user_realloc(void *mem, size_t size)
{
    void *val;
    __asm__ __volatile__(
    "int $0x40"
    :"=a"(val)
    :"a"(68),"b"(20),"c"(size),"d"(mem)
    :"memory");

    return val;
};
static inline void* UserRealloc(void *mem, size_t size) __attribute__ ((alias ("user_realloc")));

/*--------------------------------------------------------------------------*/
/* Added by ashmew2 when experimenting with newlib and how the binary will be created finally using i586-kos32-* builders */

/* struct dll_proc_entry */
/* { */
/*   char *proc_name; */
/*   void *proc_address; */
/* }; */

/* typedef struct dll_proc_entry* dll_proc_table; */

/* static inline dll_proc_table dll_load(char *path) */
/* { */
/*     void *dll_table; */
/*     __asm__ __volatile__( */
/*     "int $0x40" */
/*     :"=a"(dll_table) */
/*     :"a"(68), "b"(19), "c"(path)); */

/*     return (dll_proc_table) dll_table; */
/* }; */
/* static inline dll_proc_table LoadDLL(char *path) __attribute__ ((alias ("dll_load"))); */

/* void *dll_find_proc(dll_proc_table table, char *proc_name) */
/* { */
/*   int i; */

/*   if(table == NULL) */
/*      return NULL; */
  
/*   for(i = 0; table[i].proc_name && strcmp(proc_name, table[i].proc_name); i++); */
	
/*   if(table[i].proc_name) */
/*     return table[i].proc_address; */
/*   else  */
/*     return NULL; */
/* } */

/* static inline void * DLLFindProc(dll_proc_table table, char *proc_name) __attribute__ ((alias ("dll_find_proc"))); */

/* static inline void board_write_byte(const char ch){ */
/*     __asm__ __volatile__( */
/*     "int $0x40" */
/*     : */
/*     :"a"(63), "b"(1), "c"(ch)); */
/* } */

/* void board_write_str(const char* str){ */
/*   while(*str) */
/*     board_write_byte(*str++); */
/* } */

/*--------------------------------------------------------------------------*/

void *get_resource(void *data, uint32_t id);

struct blit_call
{
    int dstx;
    int dsty;
    int w;
    int h;

    int srcx;
    int srcy;
    int srcw;
    int srch;

    void *bitmap;
    int   stride;
};

static inline void Blit(void *bitmap, int dst_x, int dst_y,
                        int src_x, int src_y, int w, int h,
                        int src_w, int src_h, int stride)
{
    volatile struct blit_call bc;

    bc.dstx = dst_x;
    bc.dsty = dst_y;
    bc.w    = w;
    bc.h    = h;
    bc.srcx = src_x;
    bc.srcy = src_y;
    bc.srcw = src_w;
    bc.srch = src_h;
    bc.stride = stride;
    bc.bitmap = bitmap;

    __asm__ __volatile__(
    "int $0x40"
    ::"a"(73),"b"(0),"c"(&bc.dstx));
};

void* load_library(const char *name);

void* get_proc_address(void *handle, const char *proc_name);

void enumerate_libraries(int (*callback)(void *handle, const char* name,
                                         uint32_t base, uint32_t size, void *user_data),
                         void *user_data);

#ifdef __cplusplus

}
#endif



#endif