Subversion Repositories Kolibri OS

Rev

Rev 8580 | Go to most recent revision | Blame | Last modification | View Log | RSS feed

  1. #ifndef __KOS_32_SYS_H__
  2. #define __KOS_32_SYS_H__
  3.  
  4. #include <newlib.h>
  5. #include <stdint.h>
  6. #include <stddef.h>
  7. #include <string.h>
  8.  
  9. #ifdef __cplusplus
  10. extern "C" {
  11. #endif
  12.  
  13. //#ifdef CONFIG_DEBUF
  14. //  #define DBG(format,...) printf(format,##__VA_ARGS__)
  15. //#else
  16. //  #define DBG(format,...)
  17. //#endif
  18.  
  19. #define TYPE_3_BORDER_WIDTH  5
  20. #define WIN_STATE_MINIMIZED  0x02
  21. #define WIN_STATE_ROLLED     0x04
  22.  
  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.  
  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.  
  90. static inline void begin_draw(void)
  91. {
  92.     __asm__ __volatile__(
  93.     "int $0x40" ::"a"(12),"b"(1));
  94. };
  95.  
  96. static inline
  97. void end_draw(void)
  98. {
  99.     __asm__ __volatile__(
  100.     "int $0x40" ::"a"(12),"b"(2));
  101. };
  102.  
  103. static inline void
  104. put_image(uint16_t x_coord, uint16_t y_coord,
  105.           uint16_t size_x, uint16_t size_y, void *img)
  106. {
  107.     __asm__ __volatile__("int $0x40"
  108.                          ::"a"(25),
  109.                           "b"(img),
  110.                           "c"(size_x<<16 | size_y),
  111.                           "d"(x_coord<<16 | y_coord));
  112. };
  113.  
  114.  
  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.  
  129. #define OLD -1
  130. static inline
  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
  140. void define_button(uint32_t x_w, uint32_t y_h, uint32_t id, uint32_t color)
  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
  152. void draw_line(int xs, int ys, int xe, int ye, color_t color)
  153. {
  154.     __asm__ __volatile__(
  155.     "int $0x40"
  156.     ::"a"(38), "d"(color),
  157.       "b"((xs << 16) | xe),
  158.       "c"((ys << 16) | ye));
  159. }
  160.  
  161. static inline
  162. void draw_bar(int x, int y, int w, int h, color_t color)
  163. {
  164.     __asm__ __volatile__(
  165.     "int $0x40"
  166.     ::"a"(13), "d"(color),
  167.       "b"((x << 16) | w),
  168.       "c"((y << 16) | h));
  169. }
  170.  
  171. static inline
  172. void draw_bitmap(void *bitmap, int x, int y, int w, int h)
  173. {
  174.     __asm__ __volatile__(
  175.     "int $0x40"
  176.     ::"a"(7), "b"(bitmap),
  177.       "c"((w << 16) | h),
  178.       "d"((x << 16) | y));
  179. }
  180.  
  181. static inline
  182. void draw_text_sys(const char *text, int x, int y, int len, color_t color)
  183. {
  184.     __asm__ __volatile__(
  185.     "int $0x40"
  186.     ::"a"(4),"d"(text),
  187.       "b"((x << 16) | y),
  188.       "S"(len),"c"(color)
  189.      :"memory");
  190. }
  191.  
  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.  
  204. static inline
  205. uint32_t get_skin_height(void)
  206. {
  207.     uint32_t height;
  208.  
  209.     __asm__ __volatile__(
  210.     "int $0x40 \n\t"
  211.     :"=a"(height)
  212.     :"a"(48),"b"(4));
  213.     return height;
  214. };
  215.  
  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.  
  231. #define POS_SCREEN 0
  232. #define POS_WINDOW 1
  233.  
  234. static inline
  235. pos_t get_mouse_pos(int origin)
  236. {
  237.     pos_t val;
  238.  
  239.     __asm__ __volatile__(
  240.     "int $0x40 \n\t"
  241.     "rol $16, %%eax"
  242.     :"=a"(val)
  243.     :"a"(37),"b"(origin));
  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. };
  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.  
  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.  
  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)
  311.     :"a"(40),"b"(event_mask));
  312.  
  313.     return old_event_mask;
  314. };
  315.  
  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")));
  329. static inline uint32_t GetMouseWheels(void) __attribute__ ((alias ("get_mouse_wheels")));
  330.  
  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.  
  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.  
  347. static inline uint32_t check_os_event(void)
  348. {
  349.     uint32_t val;
  350.     __asm__ __volatile__(
  351.     "int $0x40"
  352.     :"=a"(val)
  353.     :"a"(11));
  354.     return val;
  355. };
  356.  
  357. static inline uint32_t get_os_event(void)
  358. {
  359.     uint32_t val;
  360.     __asm__ __volatile__(
  361.     "int $0x40"
  362.     :"=a"(val)
  363.     :"a"(10));
  364.     return val;
  365. };
  366. static inline uint32_t GetOsEvent(void) __attribute__ ((alias ("get_os_event")));
  367.  
  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
  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
  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
  402. uint32_t get_os_button(void)
  403. {
  404.     uint32_t val;
  405.     __asm__ __volatile__(
  406.     "int $0x40"
  407.     :"=a"(val)
  408.     :"a"(17));
  409.     return val>>8;
  410. };
  411.  
  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.  
  426. static inline uint32_t get_service(char *name)
  427. {
  428.     uint32_t retval = 0;
  429.     __asm__ __volatile__(
  430.     "int $0x40"
  431.     :"=a"(retval)
  432.     :"a"(68),"b"(16),"c"(name)
  433.     :"memory");
  434.  
  435.     return retval;
  436. };
  437.  
  438. static inline int call_service(ioctl_t *io)
  439. {
  440.     int retval;
  441.  
  442.     __asm__ __volatile__(
  443.     "int $0x40"
  444.     :"=a"(retval)
  445.     :"a"(68),"b"(17),"c"(io)
  446.     :"memory","cc");
  447.  
  448.     return retval;
  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)
  485.     :"a"(68),"b"(13),"c"(mem));
  486.     return val;
  487. }
  488.  
  489. static inline
  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
  503. int *user_unmap(void *base, size_t offset, size_t size)
  504. {
  505.     int  *val;
  506.     __asm__ __volatile__(
  507.     "int $0x40"
  508.     :"=a"(val)
  509.     :"a"(68),"b"(26),"c"(base),"d"(offset),"S"(size));
  510.     return val;
  511. };
  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")));
  516. static inline int *UserUnmap(void *base, size_t offset, size_t size) __attribute__ ((alias ("user_unmap")));
  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. {
  530.     ufile_t uf;
  531.  
  532.     __asm__ __volatile__ (
  533.     "int $0x40"
  534.     :"=A"(uf.raw)
  535.     :"a" (68), "b"(27),"c"(path));
  536.  
  537.     return uf;
  538. };
  539. static inline ufile_t LoadFile(const char *path) __attribute__ ((alias ("load_file")));
  540.  
  541. static inline int GetScreenSize(void)
  542. {
  543.     int retval;
  544.  
  545.     __asm__ __volatile__(
  546.     "int $0x40"
  547.     :"=a"(retval)
  548.     :"a"(61), "b"(1));
  549.     return retval;
  550. }
  551.  
  552. static inline
  553. pos_t max_screen_size()
  554. {
  555.         pos_t size;
  556.     pos_t size_tmp;
  557.     __asm__ __volatile__(
  558.     "int $0x40"
  559.     :"=a"(size_tmp)
  560.     :"a"(14));
  561.     size.x = size_tmp.y;
  562.     size.y = size_tmp.x;
  563.     return size;
  564. };
  565.  
  566. static inline void get_system_colors(struct kolibri_system_colors *color_table)
  567. {
  568.   __asm__ volatile ("int $0x40"
  569.                     :
  570.                     :"a"(48),"b"(3),"c"(color_table),"d"(40)
  571.                     );
  572. }
  573.  
  574. static inline void get_proc_info(char *info)
  575. {
  576.     __asm__ __volatile__(
  577.     "int $0x40"
  578.     :
  579.     :"a"(9), "b"(info), "c"(-1)
  580.     :"memory");
  581. };
  582. static inline void GetProcInfo(char *info) __attribute__ ((alias ("get_proc_info")));
  583.  
  584.  
  585. struct blit_call
  586. {
  587.     int dstx;
  588.     int dsty;
  589.     int w;
  590.     int h;
  591.  
  592.     int srcx;
  593.     int srcy;
  594.     int srcw;
  595.     int srch;
  596.  
  597.     void *bitmap;
  598.     int   stride;
  599. };
  600.  
  601. static inline void Blit(void *bitmap, int dst_x, int dst_y,
  602.                         int src_x, int src_y, int w, int h,
  603.                         int src_w, int src_h, int stride)
  604. {
  605.     volatile struct blit_call bc;
  606.  
  607.     bc.dstx = dst_x;
  608.     bc.dsty = dst_y;
  609.     bc.w    = w;
  610.     bc.h    = h;
  611.     bc.srcx = src_x;
  612.     bc.srcy = src_y;
  613.     bc.srcw = src_w;
  614.     bc.srch = src_h;
  615.     bc.stride = stride;
  616.     bc.bitmap = bitmap;
  617.  
  618.     __asm__ __volatile__(
  619.     "int $0x40"
  620.     ::"a"(73),"b"(0),"c"(&bc.dstx));
  621. };
  622.  
  623. #define TLS_KEY_PID         0
  624. #define TLS_KEY_TID         4
  625. #define TLS_KEY_LOW_STACK   8
  626. #define TLS_KEY_HIGH_STACK 12
  627. #define TLS_KEY_LIBC       16
  628.  
  629. unsigned int tls_alloc(void);
  630. int tls_free(unsigned int key);
  631.  
  632. static inline int tls_set(unsigned int key, void *val)
  633. {
  634.     int ret = -1;
  635.     if(key < 4096)
  636.     {
  637.         __asm__ __volatile__(
  638.         "movl %0, %%fs:(%1)"
  639.         ::"r"(val),"r"(key));
  640.         ret = 0;
  641.     }
  642.     return ret;
  643. };
  644.  
  645. static inline void *tls_get(unsigned int key)
  646. {
  647.     void *val = (void*)-1;
  648.     if(key < 4096)
  649.     {
  650.         __asm__ __volatile__(
  651.         "movl %%fs:(%1), %0"
  652.         :"=r"(val)
  653.         :"r"(key));
  654.     };
  655.     return val;
  656. }
  657.  
  658.  
  659. int create_thread(int (*proc)(void *param), void *param, int stack_size);
  660.  
  661. void* load_library(const char *name);
  662.  
  663. void* get_proc_address(void *handle, const char *proc_name);
  664.  
  665. void enumerate_libraries(int (*callback)(void *handle, const char* name,
  666.                                          uint32_t base, uint32_t size, void *user_data),
  667.                          void *user_data);
  668.  
  669. #ifdef __cplusplus
  670. }
  671. #endif
  672.  
  673.  
  674. #endif
  675.  
  676.  
  677.  
  678.  
  679.  
  680.