Subversion Repositories Kolibri OS

Rev

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