-
Notifications
You must be signed in to change notification settings - Fork 3
/
umka.h
2467 lines (2195 loc) · 56 KB
/
umka.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
SPDX-License-Identifier: GPL-2.0-or-later
UMKa - User-Mode KolibriOS developer tools
Copyright (C) 2017-2023 Ivan Baravy <[email protected]>
Copyright (C) 2021 Magomed Kostoev <[email protected]>
*/
#ifndef UMKA_H_INCLUDED
#define UMKA_H_INCLUDED
#include <assert.h>
#include <inttypes.h>
#include <signal.h>
#include <stdatomic.h>
#include <stddef.h>
#include <string.h>
#include <sys/types.h>
#include <time.h>
#define UMKA_PATH_MAX 4096
#define UMKA_DEFAULT_THREAD_STACK_SIZE 0x10000
#define RAMDISK_MAX_LEN (2880*512)
// TODO: Cleanup
#ifndef _WIN32
#include <signal.h> // for irq0: siginfo_t
#else
typedef void siginfo_t;
#endif
#define STDCALL __attribute__((__stdcall__))
enum {
UMKA_RUNNING_NEVER,
UMKA_RUNNING_NOT_YET,
UMKA_RUNNING_YES,
};
struct umka_ctx {
int booted;
atomic_int running;
};
#define KEYBOARD_MODE_ASCII 0
#define KEYBOARD_MODE_SCANCODES 1
#define UMKA_IRQ_BASE 0x20 // skip CPU exceptions
#define UMKA_SIGNAL_IRQ SIGSYS
#define UMKA_IRQ_MOUSE 14
#define UMKA_IRQ_NETWORK 15
enum kos_lang {
KOS_LANG_EN = 1,
KOS_LANG_FIRST = KOS_LANG_EN,
KOS_LANG_FI,
KOS_LANG_GE,
KOS_LANG_RU,
KOS_LANG_FR,
KOS_LANG_ET,
KOS_LANG_UA,
KOS_LANG_IT,
KOS_LANG_BE,
KOS_LANG_SP,
KOS_LANG_CA,
KOS_LANG_LAST = KOS_LANG_CA
};
#define KOS_TSTATE_RUNNING 0
#define KOS_TSTATE_RUN_SUSPENDED 1
#define KOS_TSTATE_WAIT_SUSPENDED 2
#define KOS_TSTATE_ZOMBIE 3
#define KOS_TSTATE_TERMINATING 4
#define KOS_TSTATE_WAITING 5
#define KOS_TSTATE_FREE 9
#define KOS_LAYOUT_SIZE 128
#define BDFE_LEN_CP866 304
#define BDFE_LEN_UNICODE 560
#define EVENT_REDRAW 0x0001
#define EVENT_KEY 0x0002
#define EVENT_BUTTON 0x0004
#define EVENT_BACKGROUND 0x0010
#define EVENT_MOUSE 0x0020
#define EVENT_IPC 0x0040
#define EVENT_NETWORK 0x0080
#define EVENT_DEBUG 0x0100
#define EVENT_NETWORK2 0x0200
#define EVENT_EXTENDED 0x0400
#define KOS_APP_BASE 0
#define MENUET01_MAGIC "MENUET01"
struct app_hdr {
union {
struct {
char magic[8];
uint32_t version;
uint32_t start;
uint32_t i_end;
uint32_t mem_size;
uint32_t stack_top;
uint32_t i_param;
uint32_t i_icon;
} menuet;
};
};
struct point16s {
int16_t y, x;
};
struct mouse_state {
uint8_t bl_held:1;
uint8_t br_held:1;
uint8_t bm_held:1;
uint8_t b4_held:1;
uint8_t b5_held:1;
};
struct mouse_events {
uint8_t bl_pressed:1;
uint8_t br_pressed:1;
uint8_t bm_pressed:1;
uint8_t :5;
uint8_t vscroll_used:1;
uint8_t bl_released:1;
uint8_t br_released:1;
uint8_t bm_released:1;
uint8_t :4;
uint8_t hscroll_used:1;
uint8_t bl_dbclick:1;
uint8_t :6;
};
struct mouse_state_events {
struct mouse_state st;
struct mouse_events ev;
};
typedef struct {
uint32_t left, top, right, bottom;
} rect_t;
typedef struct {
uint32_t left, top, width, height;
} box_t;
typedef struct {
uint32_t dr0, dr1, dr2, dr3, dr7;
} dbg_regs_t;
typedef struct {
uint32_t cpu_usage;
uint16_t window_stack_position;
uint16_t window_stack_value;
uint16_t pad;
char process_name[12];
uint32_t memory_start;
uint32_t used_memory;
uint32_t pid;
box_t box;
uint16_t slot_state;
uint16_t pad2;
box_t client_box;
uint8_t wnd_state;
uint8_t pad3[1024-71];
} __attribute__((packed)) process_information_t;
static_assert(sizeof(process_information_t) == 0x400,
"must be 0x400 bytes long");
typedef struct wdata {
box_t box;
uint32_t cl_workarea;
uint32_t cl_titlebar;
uint32_t cl_frames;
uint8_t z_modif;
uint8_t fl_wstate;
uint8_t fl_wdrawn;
uint8_t fl_redraw;
box_t clientbox;
uint8_t *shape;
uint32_t shape_scale;
char *caption;
uint8_t caption_encoding;
uint8_t pad0[3];
box_t saved_box;
void *cursor;
void *temp_cursor;
uint32_t draw_bgr_x;
uint32_t draw_bgr_y;
rect_t draw_data;
struct appdata *thread;
uint8_t pad1[12];
} __attribute__((packed)) wdata_t;
static_assert(sizeof(struct wdata) == 0x80, "must be 0x80 bytes long");
typedef struct {
uint32_t frame;
uint32_t grab;
uint32_t work_3d_dark;
uint32_t work_3d_light;
uint32_t grab_text;
uint32_t work;
uint32_t work_button;
uint32_t work_button_text;
uint32_t work_text;
uint32_t work_graph;
} system_colors_t;
typedef enum {
DEFAULT_ENCODING,
CP866,
UTF16,
UTF8,
INVALID_ENCODING,
} fs_enc_t;
typedef enum {
F70 = 70,
F80 = 80,
} f70or80_t;
enum {
KOS_ERROR_SUCCESS,
KOS_ERROR_DISK_BASE,
KOS_ERROR_UNSUPPORTED_FS,
KOS_ERROR_UNKNOWN_FS,
KOS_ERROR_PARTITION,
KOS_ERROR_FILE_NOT_FOUND,
KOS_ERROR_END_OF_FILE,
KOS_ERROR_MEMORY_POINTER,
KOS_ERROR_DISK_FULL,
KOS_ERROR_FS_FAIL,
KOS_ERROR_ACCESS_DENIED,
KOS_ERROR_DEVICE,
KOS_ERROR_OUT_OF_MEMORY,
};
typedef struct lhead lhead_t;
struct lhead {
void *next;
void *prev;
};
typedef struct {
lhead_t wait_list;
uint32_t count;
} mutex_t;
struct board_get_ret {
uint32_t value;
uint32_t status;
};
typedef mutex_t rwsem_t;
typedef struct {
uint32_t flags;
uint32_t sector_size;
uint64_t capacity; // in sectors
} diskmediainfo_t;
typedef struct {
uintptr_t pointer;
uint32_t data_size;
uintptr_t data;
uint32_t sad_size;
uint32_t search_start;
uint32_t sector_size_log;
} disk_cache_t;
typedef struct {
uint64_t first_sector;
uint64_t length; // in sectors
void *disk;
void *fs_user_functions;
} partition_t;
typedef struct disk_t disk_t;
typedef struct {
uint32_t strucsize;
STDCALL void (*close)(void *userdata);
STDCALL void (*closemedia)(void *userdata);
STDCALL int (*querymedia)(void *userdata, diskmediainfo_t *info);
STDCALL int (*read)(void *userdata, void *buffer, off_t startsector,
size_t *numsectors);
STDCALL int (*write)(void *userdata, void *buffer, off_t startsector,
size_t *numsectors);
STDCALL int (*flush)(void *userdata);
STDCALL unsigned int (*adjust_cache_size)(void *userdata,
size_t suggested_size);
} diskfunc_t;
struct disk_t {
disk_t *next;
disk_t *prev;
diskfunc_t *functions;
const char *name;
void *userdata;
uint32_t driver_flags;
uint32_t ref_count;
mutex_t media_lock;
uint8_t media_inserted;
uint8_t media_used;
uint16_t padding;
uint32_t media_ref_count;
diskmediainfo_t media_info;
uint32_t num_partitions;
partition_t **partitions;
uint32_t cache_size;
mutex_t cache_lock;
disk_cache_t sys_cache;
disk_cache_t app_cache;
};
typedef struct {
uint32_t attr;
uint32_t enc;
uint32_t ctime;
uint32_t cdate;
uint32_t atime;
uint32_t adate;
uint32_t mtime;
uint32_t mdate;
uint64_t size;
char name[0x777]; // how to handle this properly? FIXME
} bdfe_t;
typedef struct {
int32_t status;
uint32_t count;
} f7080ret_t;
typedef struct {
uint32_t sf;
uint64_t offset;
uint32_t count;
void *buf;
union {
struct {
uint8_t zero;
const char *path;
} __attribute__((packed)) f70;
struct {
uint32_t path_encoding;
const char *path;
} f80;
} u;
} __attribute__((packed)) f7080s0arg_t;
typedef struct {
uint32_t sf;
uint32_t offset;
uint32_t encoding;
uint32_t size;
void *buf;
union {
struct {
uint8_t zero;
const char *path;
} __attribute__((packed)) f70;
struct {
uint32_t path_encoding;
const char *path;
} f80;
} u;
} __attribute__((packed)) f7080s1arg_t;
typedef struct {
uint32_t version;
uint32_t cnt;
uint32_t total_cnt;
uint32_t zeroed[5];
bdfe_t bdfes[];
} f7080s1info_t;
typedef struct {
uint32_t sf;
uint32_t reserved1;
uint32_t flags;
uint32_t reserved2;
void *buf;
union {
struct {
uint8_t zero;
const char *path;
} __attribute__((packed)) f70;
struct {
uint32_t path_encoding;
const char *path;
} f80;
} u;
} __attribute__((packed)) f7080s5arg_t;
typedef struct {
uint32_t sf;
uint32_t flags;
char *params;
uint32_t reserved1;
uint32_t reserved2;
union {
struct {
uint8_t zero;
const char *path;
} __attribute__((packed)) f70;
struct {
uint32_t path_encoding;
const char *path;
} f80;
} u;
} __attribute__((packed)) f7080s7arg_t;
#define KF_READONLY 0x01
#define KF_HIDDEN 0x02
#define KF_SYSTEM 0x04
#define KF_LABEL 0x08
#define KF_FOLDER 0x10
#define KF_ATTR_CNT 5
#define HASH_SIZE 32
typedef struct {
uint8_t hash[HASH_SIZE];
uint8_t opaque[1024-HASH_SIZE];
} hash_context;
typedef struct {
uint32_t edi;
uint32_t esi;
uint32_t ebp;
uint32_t esp;
uint32_t ebx;
uint32_t edx;
uint32_t ecx;
uint32_t eax;
} pushad_t;
#define NET_TYPE_ETH 1
#define NET_TYPE_SLIP 2
// Link state
#define ETH_LINK_DOWN 0x0 // Link is down
#define ETH_LINK_UNKNOWN 0x1 // There could be an active link
#define ETH_LINK_FD 0x2 // full duplex flag
#define ETH_LINK_10M 0x4 // 10 mbit
#define ETH_LINK_100M 0x8 // 100 mbit
#define ETH_LINK_1G 0xc // gigabit
// Ethernet protocol numbers
#define ETHER_PROTO_ARP 0x0608
#define ETHER_PROTO_IPv4 0x0008
#define ETHER_PROTO_IPv6 0xDD86
#define ETHER_PROTO_PPP_DISCOVERY 0x6388
#define ETHER_PROTO_PPP_SESSION 0x6488
// Internet protocol numbers
#define IP_PROTO_IP 0
#define IP_PROTO_ICMP 1
#define IP_PROTO_TCP 6
#define IP_PROTO_UDP 17
#define IP_PROTO_RAW 255
// IP options
#define IP_TOS 1
#define IP_TTL 2
#define IP_HDRINCL 3
// PPP protocol numbers
#define PPP_PROTO_IPv4 0x2100
#define PPP_PROTO_IPV6 0x5780
#define PPP_PROTO_ETHERNET 666
// Protocol family
#define AF_INET4 AF_INET
struct net_device;
#define NET_BUFFER_SIZE 0x800
typedef struct {
void *next; // pointer to next frame in list
void *prev; // pointer to previous frame in list
struct net_device *device; // ptr to NET_DEVICE structure
uint32_t type; // encapsulation type: e.g. Ethernet
size_t length; // size of encapsulated data
size_t offset; // offset to actual data (24 bytes for default frame)
uint8_t data[];
} net_buff_t;
struct net_device {
uint32_t device_type; // type field
uint32_t mtu; // Maximal Transmission Unit
char *name; // ptr to 0 terminated string
// ptrs to driver functions
STDCALL void (*unload) (void);
STDCALL void (*reset) (void);
STDCALL int (*transmit) (net_buff_t *);
uint32_t link_state; // link state (0 = no link)
uint32_t hwacc; // bitmask stating enabled HW accelerations (offload
// engines)
uint64_t bytes_tx; // statistics, updated by the driver
uint64_t bytes_rx;
uint32_t packets_tx;
uint32_t packets_tx_err;
uint32_t packets_tx_drop;
uint32_t packets_tx_ovr;
uint32_t packets_rx;
uint32_t packets_rx_err;
uint32_t packets_rx_drop;
uint32_t packets_rx_ovr;
}; // NET_DEVICE
struct eth_device {
struct net_device net;
uint8_t mac[6];
};
typedef struct {
uint32_t ip;
uint8_t mac[6];
uint16_t status;
uint16_t ttl;
} arp_entry_t;
typedef struct acpi_node acpi_node_t;
struct acpi_node {
uint32_t name;
int32_t refcount;
acpi_node_t *parent;
acpi_node_t *children;
acpi_node_t *next;
int32_t type;
};
typedef struct {
acpi_node_t node;
uint64_t value;
} kos_node_integer_t;
typedef struct {
acpi_node_t node;
acpi_node_t **list;
size_t el_cnt;
} kos_node_package_t;
static inline void
umka_osloop(void) {
__asm__ __inline__ __volatile__ (
"pusha;"
"call kos_osloop;"
"popa"
:
:
: "memory", "cc");
}
void
irq0(int signo, siginfo_t *info, void *context);
struct umka_ctx *
umka_init(int running);
void
umka_close(struct umka_ctx *ctx);
void
umka_boot(void);
void
i40(void);
time_t
kos_time_to_epoch(uint32_t *time);
STDCALL disk_t *
disk_add(diskfunc_t *disk, const char *name, void *userdata, uint32_t flags);
STDCALL void *
disk_media_changed(disk_t *disk, int inserted);
STDCALL void
disk_del(disk_t *disk);
void
hash_oneshot(void *ctx, void *data, size_t len);
extern atomic_int idle_scheduled;
extern atomic_int os_scheduled;
extern uint8_t xfs_user_functions[];
extern uint8_t ext_user_functions[];
extern uint8_t fat_user_functions[];
extern uint8_t exfat_user_functions[];
extern uint8_t ntfs_user_functions[];
extern char kos_ramdisk[RAMDISK_MAX_LEN];
disk_t *
kos_ramdisk_init(void);
STDCALL void
kos_set_mouse_data(uint32_t btn_state, int32_t xmoving, int32_t ymoving,
int32_t vscroll, int32_t hscroll);
STDCALL net_buff_t *
kos_net_buff_alloc(size_t size);
struct idt_entry {
uint16_t addr_lo;
uint16_t segment;
uint16_t flags;
uint16_t addr_hi;
};
typedef int (*hw_int_handler_t)(void*);
extern struct idt_entry kos_idts[];
STDCALL void
kos_attach_int_handler(int irq, hw_int_handler_t handler, void *userdata);
void
kos_irq_serv_irq10(void);
struct ret_create_event {
uint32_t event; // (=0 => fail)
uint32_t uid;
};
#define KOS_ACPI_NODE_Uninitialized 1
#define KOS_ACPI_NODE_Integer 2
#define KOS_ACPI_NODE_String 3
#define KOS_ACPI_NODE_Buffer 4
#define KOS_ACPI_NODE_Package 5
#define KOS_ACPI_NODE_OpRegionField 6
#define KOS_ACPI_NODE_IndexField 7
#define KOS_ACPI_NODE_BankField 8
#define KOS_ACPI_NODE_Device 9
extern acpi_node_t *kos_acpi_root;
typedef struct {
int pew[0x100];
} amlctx_t;
struct pci_dev {
struct pci_dev *next;
size_t bus;
size_t dev;
size_t fun;
void *acpi;
struct pci_dev *children;
struct pci_dev *parent;
void *prt;
size_t is_bridge;
size_t vendor_id;
size_t device_id;
size_t int_pin;
size_t gsi;
};
extern struct pci_dev *kos_pci_root;
void
kos_acpi_aml_init(void);
STDCALL void
kos_aml_attach(acpi_node_t *parent, acpi_node_t *node);
STDCALL void
kos_acpi_fill_pci_irqs(void *ctx);
STDCALL amlctx_t*
kos_acpi_aml_new_thread(void);
STDCALL acpi_node_t*
kos_aml_alloc_node(int32_t type);
STDCALL acpi_node_t*
kos_aml_constructor_integer(void);
STDCALL acpi_node_t*
kos_aml_constructor_package(size_t el_cnt);
STDCALL acpi_node_t*
kos_acpi_lookup_node(acpi_node_t *root, char *name);
STDCALL void
kos_acpi_print_tree(void *ctx);
#define MAX_PCI_DEVICES 256
extern void *kos_acpi_dev_data;
extern size_t kos_acpi_dev_size;
extern void *kos_acpi_dev_next;
void kos_eth_input(void *buf);
STDCALL void*
kos_kernel_alloc(size_t len);
STDCALL void
kos_pci_walk_tree(struct pci_dev *node,
STDCALL void* (*test)(struct pci_dev *node, void *arg),
STDCALL void* (*clbk)(struct pci_dev *node, void *arg),
void *arg);
typedef struct {
uint32_t value;
uint32_t errorcode;
} f75ret_t;
typedef struct {
uint32_t eax;
uint32_t ebx;
} f76ret_t;
static inline void
umka_stack_init(void) {
__asm__ __inline__ __volatile__ (
"pusha;"
"call kos_stack_init;"
"popa"
:
:
: "memory", "cc");
}
static inline int32_t
kos_net_add_device(struct net_device *dev) {
int32_t dev_num;
__asm__ __inline__ __volatile__ (
"call net_add_device"
: "=a"(dev_num)
: "b"(dev)
: "ecx", "edx", "esi", "edi", "memory", "cc");
return dev_num;
}
STDCALL void
kos_window_set_screen(ssize_t left, ssize_t top, ssize_t right, ssize_t bottom,
ssize_t proc);
typedef struct {
int32_t x;
int32_t y;
size_t width;
size_t height;
size_t bits_per_pixel;
size_t vrefresh;
void *current_lfb;
size_t lfb_pitch;
rwsem_t win_map_lock;
uint8_t *win_map;
size_t win_map_pitch;
size_t win_map_size;
void *modes;
void *ddev;
void *connector;
void *crtc;
void *cr_list_next;
void *cr_list_prev;
void *cursor;
void *init_cursor;
void *select_cursor;
void *show_cursor;
void *move_cursor;
void *restore_cursor;
void *disable_mouse;
size_t mask_seqno;
void *check_mouse;
void *check_m_pixel;
size_t bytes_per_pixel;
void *put_pixel;
void *put_rect;
void *put_image;
void *put_line;
void *get_pixel;
void *get_rect;
void *get_image;
void *get_line;
} __attribute__((packed)) display_t;
extern display_t kos_display;
typedef struct {
uint64_t addr;
uint64_t size;
uint32_t type;
} e820entry_t;
#define MAX_MEMMAP_BLOCKS 32
typedef struct {
uint8_t bpp; // bits per pixel
uint16_t pitch; // scanline length
uint8_t pad1[5];
uint16_t vesa_mode;
uint16_t x_res;
uint16_t y_res;
uint8_t pad2[6];
uint32_t bank_switch; // Vesa 1.2 pm bank switch
void *lfb; // Vesa 2.0 LFB address
uint8_t mtrr; // 0 or 1: enable MTRR graphics acceleration
uint8_t launcher_start; // 0 or 1: start the first app (right now it's
// LAUNCHER) after kernel is loaded
uint8_t debug_print; // if nonzero, duplicates debug output to the screen
uint8_t dma; // DMA write: 1=yes, 2=no
uint8_t pci_data[8];
uint8_t pad3[8];
uint8_t shutdown_type; // see sysfn 18.9
uint8_t pad4[15];
uint32_t apm_entry; // entry point of APM BIOS
uint16_t apm_version; // BCD
uint16_t apm_flags;
uint8_t pad5[8];
uint16_t apm_code_32;
uint16_t apm_code_16;
uint16_t apm_data_16;
uint8_t rd_load_from; // Device to load ramdisk from, RD_LOAD_FROM_*
uint8_t pad6[1];
uint16_t kernel_restart;
uint16_t sys_disk; // Device to mount on /sys/, see loader_doc.txt for details
void *acpi_rsdp;
char syspath[0x17];
void *devicesdat_data;
size_t devicesdat_size;
uint8_t bios_hd_cnt; // number of BIOS hard disks
uint8_t bios_hd[0x80]; // BIOS hard disks
size_t memmap_block_cnt; // available physical memory map: number of blocks
e820entry_t memmap_blocks[MAX_MEMMAP_BLOCKS];
uint8_t acpi_usage;
} __attribute__((packed)) boot_data_t;
extern uint8_t kos_msg_board_data[];
extern uint32_t kos_msg_board_count;
extern boot_data_t kos_boot;
void
umka_cli(void);
void
umka_sti(void);
void
set_eflags_tf(uint32_t tf);
#define COVERAGE_TABLE_SIZE (512*1024)
struct coverage_branch {
uint64_t to_cnt;
uint64_t from_cnt;
};
extern struct coverage_branch coverage_table[];
extern uint8_t coverage_begin[];
extern uint8_t coverage_end[];
typedef struct appobj_t appobj_t;
struct appobj_t {
uint32_t magic;
void *destroy; // internal destructor
appobj_t *fd; // next object in list
appobj_t *bk; // prev object in list
uint32_t pid; // owner id
};
typedef struct {
uint32_t magic;
void *destroy; // internal destructor
appobj_t *fd; // next object in list
appobj_t *bk; // prev object in list
uint32_t pid; // owner id
uint32_t id; // event uid
uint32_t state; // internal flags
uint32_t code;
uint32_t pad[5];
} event_t;
typedef struct {
lhead_t list;
lhead_t thr_list;
mutex_t heap_lock;
void *heap_base;
void *heap_top;
uint32_t mem_used;
void *dlls_list_ptr;
void *pdt_0_phys;
void *pdt_1_phys;
void *io_map_0;
void *io_map_1;
void *ht_lock;
void *ht_free;
void *ht_next;
void *htab[(1024-18*4)/4];
void *pdt_0[1024];
} proc_t;
static_assert(sizeof(proc_t) == 0x1400, "must be 0x1400 bytes long");
typedef struct appdata {
char app_name[11];
uint8_t pad1[5];
lhead_t list; // +16
proc_t *process; // +24
void *fpu_state; // +28
void *exc_handler; // +32
uint32_t except_mask; // +36
void *pl0_stack; // +40
uint32_t pad2; // +44
event_t *fd_ev; // +48
event_t *bk_ev; // +52
appobj_t *fd_obj; // +56
appobj_t *bk_obj; // +60
void *saved_esp; // +64
uint32_t io_map[2]; // +68
uint32_t dbg_state; // +76
char *cur_dir; // +80
uint32_t wait_timeout; // +84
void *saved_esp0; // +88
uint32_t wait_begin; // +92
int (*wait_test)(void); // +96
void *wait_param; // +100
void *tls_base; // +104
uint32_t event_mask; // +108
uint32_t tid; // +112
uint32_t pad3; // +116
uint32_t pad4; // +120
uint8_t state; // +124
uint8_t wnd_number; // +125
uint16_t pad5; // +126
struct wdata *window; // +128
uint32_t pad6; // +132
uint32_t pad7; // +136
uint32_t counter_sum; // +140
uint32_t pad8[4]; // +144
uint32_t *ipc_start; // +160
size_t ipc_size; // +164
uint32_t occurred_events; // +168
uint32_t debugger_slot; // +172
uint32_t terminate_protection; // +176
uint8_t keyboard_mode; // +180
uint8_t pad9[3]; // +181
char *exec_params; // +184
void *dbg_event_mem; // +188
dbg_regs_t dbg_regs; // +192
uint32_t pad10; // +212
uint32_t pad11[4]; // +216
uint32_t priority; // +232
lhead_t in_schedule; // +236
uint32_t counter_add; // +244
uint32_t cpu_usage; // +248
uint32_t pad12; // +252
} appdata_t;
static_assert(sizeof(struct appdata) == 256, "must be 0x100 bytes long");
extern uint8_t kos_redraw_background;
extern size_t kos_task_count;
extern wdata_t kos_window_data[];
extern appdata_t kos_slot_base[];
extern uint32_t kos_current_process;
extern appdata_t *kos_current_slot;
extern uint32_t kos_current_slot_idx;
extern void umka_do_change_task(appdata_t *new);
extern void scheduler_add_thread(void);
extern void find_next_task(void);
extern uint8_t kos_lfb_base[];
extern uint16_t kos_win_stack[];
extern uint16_t kos_win_pos[];
extern uint32_t kos_acpi_ssdt_cnt;
extern uint8_t *kos_acpi_ssdt_base[];
extern size_t kos_acpi_ssdt_size[];
extern void *acpi_ctx;
extern uint32_t kos_acpi_usage;
extern uint32_t kos_acpi_node_alloc_cnt;
extern uint32_t kos_acpi_node_free_cnt;