Subversion Repositories Kolibri OS

Rev

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