Rev 6441 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6441 | Rev 7172 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | #ifndef __KOS_32_SYS_H__ |
1 | #ifndef __KOS_32_SYS_H__ |
2 | #define __KOS_32_SYS_H__ |
2 | #define __KOS_32_SYS_H__ |
Line 3... | Line 3... | ||
3 | 3 | ||
4 | // file header taken from newlib |
4 | // file header taken from newlib |
- | 5 | // added many sys functions, compatible with tcc |
|
- | 6 | // with gcc USE gcc -mno-ms-bitfields!!! |
|
Line 5... | Line 7... | ||
5 | // added many sys functions, compatible with tcc |
7 | |
6 | 8 | ||
7 | //#include |
9 | //#include |
8 | //#include |
10 | //#include |
Line 40... | Line 42... | ||
40 | #define SHM_CREATE 0x08 |
42 | #define SHM_CREATE 0x08 |
41 | #define SHM_READ 0x00 |
43 | #define SHM_READ 0x00 |
42 | #define SHM_WRITE 0x01 |
44 | #define SHM_WRITE 0x01 |
Line 43... | Line -... | ||
43 | - | ||
44 | 45 | ||
Line 45... | Line 46... | ||
45 | 46 | ||
46 | typedef unsigned int color_t; |
47 | typedef unsigned int color_t; |
Line 130... | Line 131... | ||
130 | uint32_t lock; // nonzero is locked |
131 | uint32_t lock; // nonzero is locked |
131 | uint32_t used; // used bytes in buffer |
132 | uint32_t used; // used bytes in buffer |
132 | struct ipc_message data[0]; // data begin |
133 | struct ipc_message data[0]; // data begin |
133 | }; |
134 | }; |
Line -... | Line 135... | ||
- | 135 | ||
- | 136 | ||
- | 137 | typedef struct __attribute__((packed)) file_op_t |
|
- | 138 | { |
|
- | 139 | uint32_t fn; |
|
- | 140 | uint32_t flags; |
|
- | 141 | char* args; |
|
- | 142 | uint32_t res1, res2; |
|
- | 143 | char zero; |
|
- | 144 | char* app_name |
|
- | 145 | #ifdef __TINYC__ |
|
- | 146 | __attribute__((packed)) |
|
- | 147 | #endif |
|
- | 148 | ; |
|
- | 149 | } file_op_t; |
|
- | 150 | ||
134 | 151 | ||
135 | static inline void begin_draw(void) |
152 | static inline void begin_draw(void) |
136 | { |
153 | { |
137 | __asm__ __volatile__( |
154 | __asm__ __volatile__( |
138 | "int $0x40" ::"a"(12),"b"(1)); |
155 | "int $0x40" ::"a"(12),"b"(1)); |
Line 522... | Line 539... | ||
522 | void enumerate_libraries(int (*callback)(void *handle, const char* name, |
539 | void enumerate_libraries(int (*callback)(void *handle, const char* name, |
523 | uint32_t base, uint32_t size, void *user_data), |
540 | uint32_t base, uint32_t size, void *user_data), |
524 | void *user_data); |
541 | void *user_data); |
525 | #endif |
542 | #endif |
Line -... | Line 543... | ||
- | 543 | ||
526 | 544 | /////////////////////////////////////////////////////////////////////////////// |
|
- | 545 | /// May be next section need to be added in newlibc |
|
- | 546 | // Siemargl addenium |
|
- | 547 | ||
Line 527... | Line 548... | ||
527 | // May be next section need to be added in newlibc |
548 | #define X_Y(x,y) (((x)<<16)|(y)) |
528 | 549 | ||
529 | enum KOLIBRI_GUI_EVENTS { |
550 | enum KOLIBRI_GUI_EVENTS { |
530 | KOLIBRI_EVENT_NONE = 0, /* Event queue is empty */ |
551 | KOLIBRI_EVENT_NONE = 0, /* Event queue is empty */ |
Line 537... | Line 558... | ||
537 | KOLIBRI_EVENT_NETWORK = 8, /* Network event */ |
558 | KOLIBRI_EVENT_NETWORK = 8, /* Network event */ |
538 | KOLIBRI_EVENT_DEBUG = 9, /* Debug subsystem event */ |
559 | KOLIBRI_EVENT_DEBUG = 9, /* Debug subsystem event */ |
539 | KOLIBRI_EVENT_IRQBEGIN = 16 /* 16..31 IRQ0..IRQ15 interrupt =IRQBEGIN+IRQn */ |
560 | KOLIBRI_EVENT_IRQBEGIN = 16 /* 16..31 IRQ0..IRQ15 interrupt =IRQBEGIN+IRQn */ |
540 | }; |
561 | }; |
Line -... | Line 562... | ||
- | 562 | ||
- | 563 | enum control_keys { |
|
- | 564 | KM_SHIFT = 0x00010000, |
|
- | 565 | KM_CTRL = 0x00020000, |
|
- | 566 | KM_ALT = 0x00040000, |
|
- | 567 | KM_NUMLOCK = 0x00080000 |
|
- | 568 | }; |
|
- | 569 | ||
- | 570 | ||
- | 571 | struct __attribute__ ((__packed__)) fs_dirinfo { |
|
- | 572 | uint32_t subfn; // 1 read dir |
|
- | 573 | uint32_t start; |
|
- | 574 | uint32_t flags; |
|
- | 575 | uint32_t size; |
|
- | 576 | uint32_t retval; |
|
- | 577 | union { |
|
- | 578 | struct __attribute__ ((__packed__)) { |
|
- | 579 | uint8_t zero; // 0 |
|
- | 580 | char* ppath; |
|
- | 581 | }; |
|
- | 582 | char path[5]; // up to 4096 |
|
- | 583 | } ; |
|
- | 584 | }; |
|
- | 585 | ||
- | 586 | static inline |
|
- | 587 | uint32_t sf_file(int subfn, struct fs_dirinfo* dinfo) |
|
- | 588 | /// SysFn70 call with subfunction |
|
- | 589 | /// retval 0 if ok |
|
- | 590 | { |
|
- | 591 | uint32_t retval; |
|
- | 592 | dinfo->subfn = subfn; |
|
- | 593 | ||
- | 594 | __asm__ __volatile__( |
|
- | 595 | "int $0x40 " |
|
- | 596 | :"=a"(retval) |
|
- | 597 | :"a"(70),"b"(dinfo) |
|
- | 598 | :); |
|
- | 599 | ||
- | 600 | return retval; |
|
- | 601 | }; |
|
- | 602 | ||
- | 603 | ||
- | 604 | struct fs_dirheader { |
|
- | 605 | uint32_t version; // 1 |
|
- | 606 | uint32_t curn_blocks; // number of read dir items (BDFE) |
|
- | 607 | uint32_t totl_blocks; // directory full size |
|
- | 608 | char other[20]; // reserved 0 |
|
- | 609 | }; |
|
- | 610 | ||
- | 611 | enum filetype |
|
- | 612 | { |
|
- | 613 | FS_RONLY = 1, |
|
- | 614 | FS_HIDDEN = 2, |
|
- | 615 | FS_SYSTEM = 4, |
|
- | 616 | FS_VOLID = 8, |
|
- | 617 | FS_SUBDIR = 16, |
|
- | 618 | FS_FOLDER = 16, |
|
- | 619 | FS_ARCHIV = 32 |
|
- | 620 | }; |
|
- | 621 | ||
- | 622 | struct __attribute__ ((__packed__)) fs_filetime { |
|
- | 623 | uint8_t sec; |
|
- | 624 | uint8_t mm; |
|
- | 625 | uint8_t hour; |
|
- | 626 | uint8_t zero; |
|
- | 627 | }; |
|
- | 628 | ||
- | 629 | struct __attribute__ ((__packed__)) fs_filedate { |
|
- | 630 | uint8_t day; |
|
- | 631 | uint8_t month; |
|
- | 632 | uint16_t year; |
|
- | 633 | }; |
|
- | 634 | ||
- | 635 | /// directory entry cp866 |
|
- | 636 | struct fsBDFE { |
|
- | 637 | uint32_t filetype; |
|
- | 638 | uint32_t encoding; // 0 - cp866, 1 - utf16le |
|
- | 639 | struct fs_filetime tm_created; |
|
- | 640 | struct fs_filedate dt_created; |
|
- | 641 | struct fs_filetime tm_accessed; |
|
- | 642 | struct fs_filedate dt_accessed; |
|
- | 643 | struct fs_filetime tm_modified; |
|
- | 644 | struct fs_filedate dt_modified; |
|
- | 645 | uint64_t size; |
|
- | 646 | char fname[264]; |
|
- | 647 | }; // must be sized 304 |
|
- | 648 | ||
- | 649 | /// directory entry UTF16LE |
|
- | 650 | struct fsBDFE_16 { |
|
- | 651 | uint32_t filetype; |
|
- | 652 | uint32_t encoding; // 0 - cp866, 1 - utf16le |
|
- | 653 | struct fs_filetime tm_created; |
|
- | 654 | struct fs_filedate dt_created; |
|
- | 655 | struct fs_filetime tm_accessed; |
|
- | 656 | struct fs_filedate dt_accessed; |
|
- | 657 | struct fs_filetime tm_modified; |
|
- | 658 | struct fs_filedate dt_modified; |
|
- | 659 | uint64_t size; |
|
- | 660 | wchar_t fname[260]; |
|
- | 661 | }; // must be sized 560 |
|
- | 662 | ||
Line 541... | Line 663... | ||
541 | 663 | ||
542 | 664 | ||
543 | // copied from /programs/system/shell/system/kolibri.c |
665 | // copied from /programs/system/shell/system/kolibri.c |
544 | // fn's returned -1 as syserror, 1 as error, 0 as OK |
666 | // fn's returned -1 as syserror, 1 as error, 0 as OK |
Line 693... | Line 815... | ||
693 | asm volatile ("int $0x40"::"a"(68), "b"(23), "c"(shm_name)); |
815 | asm volatile ("int $0x40"::"a"(68), "b"(23), "c"(shm_name)); |
694 | } |
816 | } |
Line 695... | Line 817... | ||
695 | 817 | ||
696 | static inline |
818 | static inline |
697 | int start_app(char *app_name, char *args){ |
819 | int start_app(char *app_name, char *args){ |
698 | struct file_op_t |
- | |
699 | { |
- | |
700 | uint32_t fn; |
- | |
701 | uint32_t flags; |
- | |
702 | char* args; |
- | |
703 | uint32_t res1, res2; |
- | |
704 | char zero; |
- | |
705 | char* app_name __attribute__((packed)); |
- | |
706 | } file_op; |
820 | file_op_t file_op; |
707 | memset(&file_op, 0, sizeof(file_op)); |
821 | memset(&file_op, 0, sizeof(file_op)); |
708 | file_op.fn = 7; |
822 | file_op.fn = 7; |
709 | file_op.args = args; |
823 | file_op.args = args; |
Line 713... | Line 827... | ||
713 | asm volatile ("int $0x40":"=a"(val):"a"(70), "b"(&file_op)); |
827 | asm volatile ("int $0x40":"=a"(val):"a"(70), "b"(&file_op)); |
Line 714... | Line 828... | ||
714 | 828 | ||
715 | return val; |
829 | return val; |
Line -... | Line 830... | ||
- | 830 | } |
|
- | 831 | ||
- | 832 | static inline |
|
- | 833 | uint32_t get_control_keys(void) |
|
- | 834 | { |
|
- | 835 | uint32_t ctrl; |
|
- | 836 | ||
- | 837 | __asm__ __volatile__( |
|
- | 838 | "int $0x40 \n\t" |
|
- | 839 | :"=a"(ctrl) |
|
- | 840 | :"a"(66),"b"(3)); |
|
- | 841 | ||
- | 842 | return ctrl; |
|
- | 843 | }; |
|
- | 844 | ||
- | 845 | static inline |
|
- | 846 | int get_keyboard_layout(int opt, char* buf) |
|
- | 847 | /// 128 byte buffer |
|
- | 848 | /// opt: 1 - normal, 2 - shifted, 3 - alted, or 9 - return language |
|
- | 849 | { |
|
- | 850 | uint32_t lang; |
|
- | 851 | ||
- | 852 | __asm__ __volatile__( |
|
- | 853 | "int $0x40 \n\t" |
|
- | 854 | :"=a"(lang) |
|
- | 855 | :"a"(26),"b"(2), "c"(opt), "d"(buf)); |
|
- | 856 | ||
- | 857 | return lang; |
|
- | 858 | }; |
|
- | 859 | ||
- | 860 | ||
- | 861 | static inline |
|
- | 862 | int font_size(int color) |
|
- | 863 | /// decode font size in pixels from color as SysFn4 |
|
- | 864 | /// returns (width, hight) |
|
- | 865 | { |
|
- | 866 | int font = color >> 24; |
|
- | 867 | int font_multipl = (font & 7) + 1; |
|
- | 868 | int width_sym, hight_sym; |
|
- | 869 | ||
- | 870 | if (font & 0x10) // 8x16 |
|
- | 871 | { |
|
- | 872 | width_sym = 8 * font_multipl; |
|
- | 873 | hight_sym = 16 * font_multipl; |
|
- | 874 | } else // 6x9 |
|
- | 875 | { |
|
- | 876 | width_sym = 6 * font_multipl; |
|
- | 877 | hight_sym = 9 * font_multipl; |
|
- | 878 | } |
|
Line 716... | Line 879... | ||
716 | } |
879 | return hight_sym + (width_sym << 16); |
717 | 880 | } |
|
718 | 881 | ||
719 | /* |
882 | /* |
Line 727... | Line 890... | ||
727 | } |
890 | } |
728 | else |
891 | else |
729 | return buf; |
892 | return buf; |
730 | } |
893 | } |
731 | */ |
894 | */ |
- | 895 | /* not finished |
|
- | 896 | void staticnum_draw(staticnum *st) |
|
- | 897 | { |
|
- | 898 | register uint32_t fmt; |
|
- | 899 | if (st->width < 0) |
|
- | 900 | fmt = (-st->width << 16); // leading zeros, decimal |
|
- | 901 | else |
|
- | 902 | fmt = (st->width << 16) | 0x80000000; // no leading zeros, decimal |
|
- | 903 | ||
- | 904 | __asm__ __volatile__( |
|
- | 905 | "int $0x40" |
|
- | 906 | ::"a"(47), |
|
- | 907 | "b"(fmt), |
|
- | 908 | "c"(st->number), |
|
- | 909 | "d"(st->start_xy), |
|
- | 910 | "S"(st->color_flags), |
|
- | 911 | "D"(st->bg_color) |
|
- | 912 | :); |
|
- | 913 | } |
|
- | 914 | ||
- | 915 | */ |
|
732 | // end section |
916 | //////////// end section |
Line 733... | Line 917... | ||
733 | 917 | ||
734 | 918 | ||
Line 751... | Line 935... | ||
751 | va_start (ap, format); |
935 | va_start (ap, format); |
752 | vsnprintf(log_board, sizeof log_board, format, ap); |
936 | vsnprintf(log_board, sizeof log_board, format, ap); |
753 | va_end(ap); |
937 | va_end(ap); |
754 | debug_board_write_str(log_board); |
938 | debug_board_write_str(log_board); |
755 | } |
939 | } |
- | 940 | ||
- | 941 | __attribute__ ((noinline)) void trap(int n) |
|
- | 942 | { |
|
- | 943 | // nothing todo, just see n in debugger. use "bp trap" command |
|
- | 944 | __asm__ __volatile__( |
|
- | 945 | "nop" |
|
- | 946 | : |
|
- | 947 | :"a"(n)); |
|
- | 948 | } |
|
- | 949 | ||
756 | */ |
950 | */ |
Line 757... | Line 951... | ||
757 | 951 |