Subversion Repositories Kolibri OS

Rev

Rev 8453 | 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. 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. };
  347.  
  348. static inline
  349. uint32_t wait_for_event(uint32_t time)
  350. {
  351.     uint32_t val;
  352.     __asm__ __volatile__(
  353.     "int $0x40"
  354.     :"=a"(val)
  355.     :"a"(23), "b"(time));
  356.     return val;
  357. };
  358.  
  359. static inline uint32_t check_os_event(void)
  360. {
  361.     uint32_t val;
  362.     __asm__ __volatile__(
  363.     "int $0x40"
  364.     :"=a"(val)
  365.     :"a"(11));
  366.     return val;
  367. };
  368.  
  369. static inline uint32_t get_os_event(void)
  370. {
  371.     uint32_t val;
  372.     __asm__ __volatile__(
  373.     "int $0x40"
  374.     :"=a"(val)
  375.     :"a"(10));
  376.     return val;
  377. };
  378. static inline uint32_t GetOsEvent(void) __attribute__ ((alias ("get_os_event")));
  379.  
  380. static inline
  381. uint32_t get_tick_count(void)
  382. {
  383.     uint32_t val;
  384.     __asm__ __volatile__(
  385.     "int $0x40"
  386.     :"=a"(val)
  387.     :"a"(26),"b"(9));
  388.     return val;
  389. };
  390.  
  391. static inline
  392. uint64_t get_ns_count(void)
  393. {
  394.     uint64_t val;
  395.     __asm__ __volatile__(
  396.     "int $0x40"
  397.     :"=A"(val)
  398.     :"a"(26), "b"(10));
  399.     return val;
  400. };
  401.  
  402. static inline
  403. oskey_t get_key(void)
  404. {
  405.     oskey_t val;
  406.     __asm__ __volatile__(
  407.     "int $0x40"
  408.     :"=a"(val)
  409.     :"a"(2));
  410.     return val;
  411. }
  412.  
  413. static inline
  414. uint32_t get_os_button(void)
  415. {
  416.     uint32_t val;
  417.     __asm__ __volatile__(
  418.     "int $0x40"
  419.     :"=a"(val)
  420.     :"a"(17));
  421.     return val>>8;
  422. };
  423.  
  424. static inline uint32_t
  425. heap_init(void)
  426. {
  427.     uint32_t heapsize;
  428.  
  429.     __asm__ __volatile__(
  430.                          "int $0x40"
  431.                          :"=a"(heapsize)
  432.                          :"a"(68),"b"(11)
  433.                          );
  434.  
  435.     return heapsize;
  436. }
  437.  
  438. static inline uint32_t get_service(char *name)
  439. {
  440.     uint32_t retval = 0;
  441.     __asm__ __volatile__(
  442.     "int $0x40"
  443.     :"=a"(retval)
  444.     :"a"(68),"b"(16),"c"(name)
  445.     :"memory");
  446.  
  447.     return retval;
  448. };
  449.  
  450. static inline int call_service(ioctl_t *io)
  451. {
  452.     int retval;
  453.  
  454.     __asm__ __volatile__(
  455.     "int $0x40"
  456.     :"=a"(retval)
  457.     :"a"(68),"b"(17),"c"(io)
  458.     :"memory","cc");
  459.  
  460.     return retval;
  461. };
  462.  
  463.  
  464. static inline void yield(void)
  465. {
  466.     __asm__ __volatile__(
  467.     "int $0x40"
  468.     ::"a"(68), "b"(1));
  469. };
  470.  
  471. static inline void delay(uint32_t time)
  472. {
  473.     __asm__ __volatile__(
  474.     "int $0x40"
  475.     ::"a"(5), "b"(time)
  476.     :"memory");
  477. };
  478.  
  479. static inline
  480. void *user_alloc(size_t size)
  481. {
  482.     void  *val;
  483.     __asm__ __volatile__(
  484.     "int $0x40"
  485.     :"=a"(val)
  486.     :"a"(68),"b"(12),"c"(size));
  487.     return val;
  488. }
  489.  
  490. static inline
  491. int user_free(void *mem)
  492. {
  493.     int  val;
  494.     __asm__ __volatile__(
  495.     "int $0x40"
  496.     :"=a"(val)
  497.     :"a"(68),"b"(13),"c"(mem));
  498.     return val;
  499. }
  500.  
  501. static inline
  502. void* user_realloc(void *mem, size_t size)
  503. {
  504.     void *val;
  505.     __asm__ __volatile__(
  506.     "int $0x40"
  507.     :"=a"(val)
  508.     :"a"(68),"b"(20),"c"(size),"d"(mem)
  509.     :"memory");
  510.  
  511.     return val;
  512. };
  513.  
  514. static inline
  515. int *user_unmap(void *base, size_t offset, size_t size)
  516. {
  517.     int  *val;
  518.     __asm__ __volatile__(
  519.     "int $0x40"
  520.     :"=a"(val)
  521.     :"a"(68),"b"(26),"c"(base),"d"(offset),"S"(size));
  522.     return val;
  523. };
  524.  
  525. static inline void *UserAlloc(size_t size) __attribute__ ((alias ("user_alloc")));
  526. static inline int UserFree(void *mem) __attribute__ ((alias ("user_free")));
  527. 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")));
  529.  
  530. typedef union
  531. {
  532.     struct
  533.     {
  534.         void   *data;
  535.         size_t  size;
  536.     };
  537.     unsigned long long raw;
  538. }ufile_t;
  539.  
  540. static inline ufile_t load_file(const char *path)
  541. {
  542.     ufile_t uf;
  543.  
  544.     __asm__ __volatile__ (
  545.     "int $0x40"
  546.     :"=A"(uf.raw)
  547.     :"a" (68), "b"(27),"c"(path));
  548.  
  549.     return uf;
  550. };
  551. static inline ufile_t LoadFile(const char *path) __attribute__ ((alias ("load_file")));
  552.  
  553. static inline int GetScreenSize(void)
  554. {
  555.     int retval;
  556.  
  557.     __asm__ __volatile__(
  558.     "int $0x40"
  559.     :"=a"(retval)
  560.     :"a"(61), "b"(1));
  561.     return retval;
  562. }
  563.  
  564. static inline
  565. pos_t max_screen_size()
  566. {
  567.         pos_t size;
  568.     __asm__ __volatile__(
  569.     "int $0x40"
  570.     :"=a"(size)
  571.     :"a"(14));
  572.    
  573.      
  574.      return size;
  575. };
  576.  
  577. static inline void get_system_colors(struct kolibri_system_colors *color_table)
  578. {
  579.   __asm__ volatile ("int $0x40"
  580.                     :
  581.                     :"a"(48),"b"(3),"c"(color_table),"d"(40)
  582.                     );
  583. }
  584.  
  585. static inline void get_proc_info(char *info)
  586. {
  587.     __asm__ __volatile__(
  588.     "int $0x40"
  589.     :
  590.     :"a"(9), "b"(info), "c"(-1)
  591.     :"memory");
  592. };
  593. static inline void GetProcInfo(char *info) __attribute__ ((alias ("get_proc_info")));
  594.  
  595.  
  596. struct blit_call
  597. {
  598.     int dstx;
  599.     int dsty;
  600.     int w;
  601.     int h;
  602.  
  603.     int srcx;
  604.     int srcy;
  605.     int srcw;
  606.     int srch;
  607.  
  608.     void *bitmap;
  609.     int   stride;
  610. };
  611.  
  612. static inline void Blit(void *bitmap, int dst_x, int dst_y,
  613.                         int src_x, int src_y, int w, int h,
  614.                         int src_w, int src_h, int stride)
  615. {
  616.     volatile struct blit_call bc;
  617.  
  618.     bc.dstx = dst_x;
  619.     bc.dsty = dst_y;
  620.     bc.w    = w;
  621.     bc.h    = h;
  622.     bc.srcx = src_x;
  623.     bc.srcy = src_y;
  624.     bc.srcw = src_w;
  625.     bc.srch = src_h;
  626.     bc.stride = stride;
  627.     bc.bitmap = bitmap;
  628.  
  629.     __asm__ __volatile__(
  630.     "int $0x40"
  631.     ::"a"(73),"b"(0),"c"(&bc.dstx));
  632. };
  633.  
  634. #define TLS_KEY_PID         0
  635. #define TLS_KEY_TID         4
  636. #define TLS_KEY_LOW_STACK   8
  637. #define TLS_KEY_HIGH_STACK 12
  638. #define TLS_KEY_LIBC       16
  639.  
  640. unsigned int tls_alloc(void);
  641. int tls_free(unsigned int key);
  642.  
  643. static inline int tls_set(unsigned int key, void *val)
  644. {
  645.     int ret = -1;
  646.     if(key < 4096)
  647.     {
  648.         __asm__ __volatile__(
  649.         "movl %0, %%fs:(%1)"
  650.         ::"r"(val),"r"(key));
  651.         ret = 0;
  652.     }
  653.     return ret;
  654. };
  655.  
  656. static inline void *tls_get(unsigned int key)
  657. {
  658.     void *val = (void*)-1;
  659.     if(key < 4096)
  660.     {
  661.         __asm__ __volatile__(
  662.         "movl %%fs:(%1), %0"
  663.         :"=r"(val)
  664.         :"r"(key));
  665.     };
  666.     return val;
  667. }
  668.  
  669.  
  670. int create_thread(int (*proc)(void *param), void *param, int stack_size);
  671.  
  672. void* load_library(const char *name);
  673.  
  674. void* get_proc_address(void *handle, const char *proc_name);
  675.  
  676. void enumerate_libraries(int (*callback)(void *handle, const char* name,
  677.                                          uint32_t base, uint32_t size, void *user_data),
  678.                          void *user_data);
  679.  
  680. #ifdef __cplusplus
  681. }
  682. #endif
  683.  
  684.  
  685. #endif
  686.  
  687.  
  688.  
  689.  
  690.  
  691.