Subversion Repositories Kolibri OS

Rev

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

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