-
Notifications
You must be signed in to change notification settings - Fork 3
/
umka.asm
1278 lines (1118 loc) · 30.3 KB
/
umka.asm
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]>
if HOST eq windows
format MS COFF
else if HOST eq linux
format ELF
else
error "Your HOST is not supported"
end if
; win32:
; pubsym name -> public name as "_name"
; pubsym name, 20 -> public name as "_name@20"
; pubsym name, no_mangle -> public name
; pubsym name, "name" -> public name as "_name"
; pubsym name, "name", 20 -> public name as "_name@20"
; pubsym name, "name", no_mangle -> public name as "name"
; linux:
; pubsym name -> public name
; pubsym name, 20 -> public name
; pubsym name, no_mangle -> public name
; pubsym name, "name" -> public name as "name"
; pubsym name, "name", 20 -> public name as "name"
; pubsym name, "name", no_mangle -> public name as "name"
macro pubsym name, marg1, marg2 {
if HOST eq windows
if marg1 eq no_mangle
public name
else if marg1 eqtype 20
public name as '_' # `name # '@' # `marg1
else if marg1 eqtype 'string'
if marg2 eq no_mangle
public name as marg1
else if marg2 eqtype 20
public name as '_' # marg1 # '@' # `marg2
else
public name as '_' # marg1
end if
else
public name as '_' # `name
end if
else if HOST eq linux
if marg1 eqtype 'string'
public name as marg1
else
public name
end if
else
error "Your HOST is not supported"
end if
}
; win32:
; extrn name -> extrn _name
; extrn name, 20 -> extrn _name@20
; linux:
; extrn name -> extrn name
; extrn name, 20 -> extrn name
macro extrn name, argsize, asname {
if HOST eq windows
if argsize eqtype 0 & argsize > 0
if asname eqtype 'string'
extrn '_' # `name # '@' # `argsize as asname
else
extrn '_' # `name # '@' # `argsize as name
end if
else
if asname eqtype
extrn '_' # `name as name
else
extrn '_' # `name as asname
end if
end if
else if HOST eq linux
if asname eqtype
extrn name
else
extrn name as asname
end if
else
error "Your HOST is not supported"
end if
}
__DEBUG__ = 1
__DEBUG_LEVEL__ = 1
UMKA_SHELL = 1
UMKA_FUSE = 2
UMKA_OS = 3
UMKA_MEMORY_BYTES = 256 SHL 20
UMKA_BOOT_DEFAULT_DISPLAY_BPP = 32
UMKA_BOOT_DEFAULT_DISPLAY_WIDTH = 400
UMKA_BOOT_DEFAULT_DISPLAY_HEIGHT = 300
pubsym idle_scheduled, 'idle_scheduled'
pubsym os_scheduled, 'os_scheduled'
pubsym irq_serv.irq_10, 'kos_irq_serv_irq10'
pubsym idts, 'kos_idts'
pubsym attach_int_handler, 'kos_attach_int_handler', 12
pubsym fs_execute, 'kos_fs_execute', 4
pubsym set_keyboard_data, 'kos_set_keyboard_data', no_mangle
pubsym KEY_COUNT, 'kos_key_count'
pubsym KEY_BUFF, 'kos_key_buff'
pubsym keyboard_mode, 'kos_keyboard_mode'
pubsym sys_getkey, 'kos_get_key'
pubsym syslang, 'kos_syslang'
pubsym keyboard, 'kos_keyboard'
pubsym disk_add, 16
pubsym disk_del, 4
pubsym disk_list
pubsym disk_media_changed, 8
pubsym xfs._.user_functions, 'xfs_user_functions'
pubsym ext_user_functions
pubsym fat_user_functions
pubsym exFAT_user_functions, 'exfat_user_functions'
pubsym ntfs_user_functions
pubsym i40, no_mangle
pubsym coverage_begin
pubsym coverage_end
pubsym sha3_256_oneshot, 'hash_oneshot'
pubsym kos_time_to_epoch
pubsym umka_init, 'umka_init'
pubsym umka_close, 'umka_close'
pubsym umka_boot
pubsym current_process, 'kos_current_process'
pubsym current_slot, 'kos_current_slot'
pubsym current_slot_idx, 'kos_current_slot_idx'
pubsym thread_count, 'kos_thread_count'
pubsym SLOT_BASE, 'kos_slot_base'
pubsym window_data, 'kos_window_data'
pubsym WIN_STACK, 'kos_win_stack'
pubsym WIN_POS, 'kos_win_pos'
pubsym lfb_base, 'kos_lfb_base'
pubsym RAMDISK, 'kos_ramdisk'
pubsym ramdisk_init, 'kos_ramdisk_init'
pubsym enable_acpi, no_mangle
pubsym acpi.call_name, no_mangle
pubsym acpi_ssdt_cnt, 'kos_acpi_ssdt_cnt'
pubsym acpi_ssdt_base, 'kos_acpi_ssdt_base'
pubsym acpi_ssdt_size, 'kos_acpi_ssdt_size'
pubsym acpi_ctx
pubsym acpi_usage, 'kos_acpi_usage'
pubsym acpi_node_alloc_cnt, 'kos_acpi_node_alloc_cnt'
pubsym acpi_node_free_cnt, 'kos_acpi_node_free_cnt'
pubsym acpi.count_nodes, 'kos_acpi_count_nodes', 4
pubsym stack_init, 'kos_stack_init', no_mangle
pubsym net_add_device, no_mangle
pubsym img_background
pubsym mem_BACKGROUND
pubsym sys_background
pubsym REDRAW_BACKGROUND, 'kos_redraw_background'
pubsym new_sys_threads, '_kos_new_sys_threads', no_mangle
pubsym osloop, 'kos_osloop', no_mangle
pubsym set_mouse_data, 'kos_set_mouse_data', 20
pubsym scheduler_current, 'kos_scheduler_current'
pubsym kos_eth_input
pubsym net_buff_alloc, 'kos_net_buff_alloc', 4
pubsym mem_block_list
pubsym pci_root, "kos_pci_root"
pubsym acpi.aml.init, "kos_acpi_aml_init"
pubsym acpi_root, "kos_acpi_root"
pubsym aml._.attach, "kos_aml_attach"
pubsym acpi.fill_pci_irqs, "kos_acpi_fill_pci_irqs"
pubsym pci.walk_tree, "kos_pci_walk_tree", 16
pubsym acpi.aml.new_thread, "kos_acpi_aml_new_thread"
pubsym aml._.alloc_node, "kos_aml_alloc_node"
pubsym aml._.constructor.integer, "kos_aml_constructor_integer"
pubsym aml._.constructor.package, "kos_aml_constructor_package"
pubsym acpi._.lookup_node, "kos_acpi_lookup_node"
pubsym acpi._.print_tree, "kos_acpi_print_tree"
pubsym acpi_dev_data, "kos_acpi_dev_data"
pubsym acpi_dev_size, "kos_acpi_dev_size"
pubsym acpi_dev_next, "kos_acpi_dev_next"
pubsym kernel_alloc, "kos_kernel_alloc"
pubsym create_event, "_kos_create_event"
pubsym destroy_event, "_kos_destroy_event"
pubsym wait_event, "_kos_wait_event"
pubsym Wait_events, "_kos_wait_events"
pubsym window._.set_screen, 'kos_window_set_screen'
pubsym _display, 'kos_display'
pubsym msg_board_data, "kos_msg_board_data"
pubsym msg_board_count, "kos_msg_board_count"
pubsym BOOT, 'kos_boot'
EFLAGS.ID = 1 SHL 21
macro lidt x {
}
macro invlpg addr {
}
macro cli {
pushfd
bts dword[esp], BSF EFLAGS.ID
popfd
}
macro sti {
pushfd
btr dword[esp], BSF EFLAGS.ID
popfd
}
iretd equ retd
iret equ ret
lang fix en
macro int n {
if n eq 0x40
call i40
else
int n
end if
}
section '.app' executable writable align 64
rb 64*1024
section '.text' executable align 64
coverage_begin:
include 'macros.inc'
macro diff16 msg,blah2,blah3 {
if msg eq "end of .data segment"
; fasm doesn't align on 1MiB, but ld script does
section '.bss.1M' writeable align 0x1000
bss_base:
end if
}
include 'proc32.inc'
include 'struct.inc'
macro BOOT_LO a {}
macro BOOT a {}
window_data equ __pew_window_data
background_window equ __pew_background_window
idts equ __pew07
WIN_STACK equ __pew08
WIN_POS equ __pew09
FDD_BUFF equ __pew10
WIN_TEMP_XY equ __pew11
KEY_COUNT equ __pew12
KEY_BUFF equ __pew13
BTN_COUNT equ __pew14
BTN_BUFF equ __pew15
BTN_ADDR equ __pew16
MEM_AMOUNT equ __pew17
SYS_SHUTDOWN equ __pew18
SLOT_BASE equ __pew20
sys_proc equ __pew21
VGABasePtr equ __pew22
HEAP_BASE equ __pew23
page_tabs equ page_tabs_pew
;macro OS_BASE [x] {
; OS_BASE equ os_base
;}
struct idt_entry
addr_lo dw ?
seg dw ?
flags dw ?
addr_hi dw ?
ends
NUM_EXCEPTIONS = 32
macro tss pew {}
include 'const.inc'
purge tss
restore window_data
restore background_window
restore idts,WIN_STACK,WIN_POS
restore FDD_BUFF,WIN_TEMP_XY,KEY_COUNT,KEY_BUFF,BTN_COUNT,BTN_BUFF,BTN_ADDR
restore MEM_AMOUNT,SYS_SHUTDOWN,SLOT_BASE,sys_proc,VGABasePtr
restore HEAP_BASE
restore page_tabs
purge BOOT_LO,BOOT
LFB_BASE = lfb_base
macro save_ring3_context {
pushad
}
macro restore_ring3_context {
popad
}
macro stdcall target, [args] {
common
if target eq is_region_userspace
cmp esp, esp ; ZF
else if target eq is_string_userspace
cmp esp, esp ; ZF
else
stdcall target, args
end if
}
include 'system.inc'
include 'fdo.inc'
OS_BASE equ 0
;OS_BASE equ os_base
macro mov target, source {
if source eq (HEAP_BASE - OS_BASE + HEAP_MIN_SIZE)/PAGE_SIZE
push eax eax
mov eax, HEAP_BASE
add eax, HEAP_MIN_SIZE
shr eax, 12
mov [esp+4], eax
pop eax
pop target
else if target eq dword [sys_proc-OS_BASE+PROC.pdt_0+(page_tabs shr 20)]
push eax ecx
mov eax, page_tabs
shr eax, 20
add eax, PROC.pdt_0
add eax, sys_proc
mov ecx, sys_proc+PROC.pdt_0+PG_SWR
mov [eax], ecx
pop ecx eax
else if target eq [(pci_code_32 - OS_BASE)]
else if target eq [(pci_data_32 - OS_BASE)]
else if target eq [(pci_code_32 - OS_BASE)+2]
else if target eq [(pci_data_32 - OS_BASE)+2]
else if target eq [(pci_code_32 - OS_BASE)+4]
else if target eq [(pci_data_32 - OS_BASE)+4]
else if target eq [(pci_code_32 - OS_BASE)+6]
else if target eq [(pci_data_32 - OS_BASE)+6]
else if target eq [(pci_bios_entry - OS_BASE)]
else if source eq (OS_BASE/PAGE_SIZE)
push ecx
mov ecx, OS_BASE
shr ecx, 12
mov target, ecx
pop ecx
else if target eq dword [sys_proc-OS_BASE+PROC.pdt_0+(page_tabs shr 20)]
else if source eq (sys_proc - OS_BASE + PROC.pdt_0) + (OS_BASE shr 20)
push ecx
mov ecx, OS_BASE
shr ecx, 20
add ecx, sys_proc
add ecx, PROC.pdt_0
sub ecx, OS_BASE
mov target, ecx
pop ecx
else
mov target, source
end if
}
macro cmp target, source {
if source eq (HEAP_BASE - OS_BASE + HEAP_MIN_SIZE)/PAGE_SIZE
push eax eax
mov eax, HEAP_BASE
add eax, HEAP_MIN_SIZE
shr eax, 12
mov [esp], eax
mov eax, [esp+4]
cmp target, [esp]
pop eax eax
else if source eq (OS_BASE/PAGE_SIZE)
push ecx
mov ecx, OS_BASE
shr ecx, 12
cmp target, ecx
pop ecx
else
cmp target, source
end if
}
macro lea target, source {
if source eq [edi + (OS_BASE shr 20)]
push ecx
mov ecx, OS_BASE
shr ecx, 20
add ecx, edi
mov target, ecx
pop ecx
else
lea target, source
end if
}
include 'init.inc'
purge mov
purge cmp
purge lea
restore OS_BASE
include 'core/sync.inc'
macro call target {
if target eq do_change_task
call _do_change_task
else if target eq page_fault_handler
call _page_fault_handler
else
call target
end if
}
include 'core/sys32.inc'
do_change_task equ hjk
irq0 equ irq0_pew
tss._io_map_0 equ 0
tss._io_map_1 equ 0
include 'core/sched.inc'
restore tss._io_map_0
restore tss._io_map_1
;purge mov
restore irq0
include 'core/syscall.inc'
;include 'core/fpu.inc'
map_io_mem equ map_io_mem_pew
create_trampoline_pgmap equ create_trampoline_pgmap_pew
alloc_page equ alloc_page_pew
alloc_pages equ alloc_pages_pew
free_page equ free_page_pew
include 'core/memory.inc'
restore map_io_mem, free_page, create_trampoline_pgmap, alloc_page, alloc_pages
;include 'core/mtrr.inc'
;user_alloc_at equ user_alloc_at_pew
include 'core/heap.inc'
;restore user_alloc_at
include 'core/malloc.inc'
macro mov target, source {
if target eq [edi - PAGE_SIZE + (page_tabs shr 20)]
push eax ebx
mov ebx, eax
mov eax, page_tabs
shr eax, 20
sub eax, PAGE_SIZE
add eax, edi
mov [eax], ebx
pop ebx eax
else
mov target, source
end if
}
include 'core/taskman.inc'
purge mov
include 'core/dll.inc'
macro call target {
if target eq pci_read_reg
call _pci_read_reg
else
call target
end if
}
include 'bus/pci/pci32.inc'
purge call
;include 'core/peload.inc'
;include 'core/exports.inc'
include 'core/string.inc'
;include 'core/v86.inc'
macro mov dst, src {
if dst eq ds
else if dst eq es
else
mov dst, src
end if
}
include 'core/irq.inc'
purge mov
purge call
include 'core/apic.inc'
include 'core/hpet.inc'
include 'core/timers.inc'
include 'core/clipboard.inc'
include 'core/slab.inc'
include 'posix/posix.inc'
;include 'boot/shutdown.inc'
include 'video/vesa20.inc'
include 'video/blitter.inc'
include 'video/vga.inc'
include 'video/cursors.inc'
macro lea target, source {
if source eq [eax + PROC.pdt_0 + (LFB_BASE shr 20)]
push ecx
mov ecx, LFB_BASE
shr ecx, 20
add ecx, PROC.pdt_0
lea target, [eax + ecx]
pop ecx
else
lea target, source
end if
}
include 'video/framebuffer.inc'
purge lea
include 'gui/window.inc'
include 'gui/event.inc'
include 'gui/font.inc'
include 'gui/button.inc'
include 'gui/mouse.inc'
include 'gui/skincode.inc'
include 'gui/background.inc'
include 'hid/keyboard.inc'
include 'hid/mousedrv.inc'
include 'hid/set_dtc.inc' ; setting date,time,clock and alarm-clock
include 'sound/playnote.inc'
;include 'bus/pci/pci32.inc'
;include 'bus/usb/init.inc'
;include 'blkdev/flp_drv.inc' ; floppy driver
;include 'blkdev/fdc.inc'
;include 'blkdev/cd_drv.inc' ; CD driver
;include 'blkdev/ide_cache.inc' ; CD cache
;include 'blkdev/hd_drv.inc' ; HDD driver
;include 'blkdev/bd_drv.inc' ; BIOS disks driver
include 'blkdev/rd.inc' ; ramdisk driver
include 'blkdev/disk.inc'
include 'blkdev/disk_cache.inc'
include 'fs/fs_lfn.inc'
include 'network/stack.inc'
include 'crc.inc'
include 'unicode.inc'
include 'acpi/acpi.inc'
include 'unpacker.inc'
LIBCRASH_CTX_LEN = 0x500 ; FIXME
include 'sha3.asm'
; TODO: stdcall attribute in umka.h
proc sha3_256_oneshot c uses ebx esi edi ebp, _ctx, _data, _len
stdcall sha3_256.oneshot, [_ctx], [_data], [_len]
ret
endp
proc kos_time_to_epoch c uses ebx esi edi ebp, _time
mov esi, [_time]
call fsCalculateTime
xor edx, edx
add eax, UNIXTIME_TO_KOS_OFFSET
adc edx, 0
ret
endp
proc umka._.check_alignment
mov eax, HEAP_BASE
and eax, PAGE_SIZE - 1
jz @f
mov ecx, PAGE_SIZE
sub ecx, eax
DEBUGF 4, "HEAP_BASE must be aligned on PAGE_SIZE: 0x%x", HEAP_BASE
DEBUGF 4, ", add 0x%x or sub 0x%x\n", ecx, eax
mov eax, SLOT_BASE
and eax, 0x10000 - 1
jz @f
mov eax, os_base
and eax, 0x100000 - 1
jz @f
int3
@@:
ret
endp
pubsym i40_asm
;void i40_asm(uint32_t _eax,
; uint32_t _ebx,
; uint32_t _ecx,
; uint32_t _edx,
; uint32_t _esi,
; uint32_t _edi,
; uint32_t _ebp,
; uint32_t *_eax_out,
; uint32_t _ebx_out)
i40_asm:
; Return address: esp
; First argument: esp + 4
push eax ebx ecx edx esi edi ebp
; First argument: esp + 4 + 7 * sizeof(dword) = esp + 8 + 7 * 4 = esp + 4 + 28 = esp + 32
mov eax, [esp + 32]
mov ebx, [esp + 36]
mov ecx, [esp + 40]
mov edx, [esp + 44]
mov esi, [esp + 48]
mov edi, [esp + 52]
mov ebp, [esp + 56]
call i40
mov edi, [esp + 60]
mov [edi], eax
mov edi, [esp + 64]
mov [edi], ebx
pop ebp edi esi edx ecx ebx eax
ret
pubsym set_eflags_tf
proc set_eflags_tf c uses ebx esi edi ebp, tf
mov ecx, [tf]
pushfd
pop eax
ror eax, 8
mov edx, eax
and edx, 1
and eax, 0xfffffffe
or eax, ecx
rol eax, 8
push eax
popfd
ret
endp
proc kos_eth_input c uses ebx esi edi ebp, buffer_ptr
push .retaddr
push [buffer_ptr]
jmp eth_input
.retaddr:
ret
endp
struct umka_ctx
booted dd ?
running dd ?
ends
proc umka_init c uses ebx esi edi ebp, _running
call umka._.check_alignment
; init boot vars
mov eax, BOOT
mov [eax + boot_data.x_res], UMKA_BOOT_DEFAULT_DISPLAY_WIDTH
mov [eax + boot_data.y_res], UMKA_BOOT_DEFAULT_DISPLAY_HEIGHT
mov [eax + boot_data.bpp], UMKA_BOOT_DEFAULT_DISPLAY_BPP
mov [eax + boot_data.pitch], UMKA_BOOT_DEFAULT_DISPLAY_BPP * \
UMKA_BOOT_DEFAULT_DISPLAY_WIDTH / 8
mov [eax + boot_data.memmap_block_cnt], 1
lea ecx, [eax + boot_data.memmap_blocks]
mov [ecx + e820entry.addr.lo], mem_block
mov [ecx + e820entry.addr.hi], 0
mov [ecx + e820entry.size.lo], 256*0x10000
mov [ecx + e820entry.size.hi], 0
mov [ecx + e820entry.type], 1
; init umka context
mov eax, umka
mov [eax+umka_ctx.booted], 0
mov ecx, [_running]
mov [eax+umka_ctx.running], ecx
ret
endp
proc umka_close c, _ctx
xor eax, eax
ret
endp
proc umka_boot uses ebx esi edi ebp
mov [umka.booted], 1
mov edi, endofcode
mov ecx, uglobals_size
xor eax, eax
rep stosb
call mem_test
; call init_mem
; call init_page_map
mov [irq_mode], IRQ_APIC
mov [IOAPIC_base], ioapic_data
mov [LAPIC_BASE], lapic_data
mov [ioapic_cnt], 1
mov [xsave_area_size], 0x1000
mov ecx, pg_data.mutex
call mutex_init
mov ecx, disk_list_mutex
call mutex_init
mov ecx, keyboard_list_mutex
call mutex_init
mov ecx, unpack_mutex
call mutex_init
mov ecx, application_table_mutex
call mutex_init
mov ecx, ide_mutex
call mutex_init
mov ecx, ide_channel1_mutex
call mutex_init
mov ecx, ide_channel2_mutex
call mutex_init
mov ecx, ide_channel3_mutex
call mutex_init
mov ecx, ide_channel4_mutex
call mutex_init
mov ecx, ide_channel5_mutex
call mutex_init
mov ecx, ide_channel6_mutex
call mutex_init
mov [pg_data.mem_amount], UMKA_MEMORY_BYTES
mov [pg_data.pages_count], UMKA_MEMORY_BYTES / PAGE_SIZE
mov [pg_data.pages_free], UMKA_MEMORY_BYTES / PAGE_SIZE
mov eax, UMKA_MEMORY_BYTES SHR 12
mov [pg_data.kernel_pages], eax
shr eax, 10
mov [pg_data.kernel_tables], eax
call build_interrupt_table
call init_kernel_heap
call init_malloc
mov eax, sys_proc
list_init eax
add eax, PROC.thr_list
list_init eax
mov [BOOT.lfb], LFB_BASE
mov [BOOT.vesa_mode], 0x4000
call init_video
stdcall alloc_kernel_space, 0x50000 ; FIXME check size
mov [default_io_map], eax
add eax, 0x2000
mov [ipc_tmp], eax
mov ebx, 0x1000
add eax, 0x40000
mov [proc_mem_map], eax
add eax, 0x8000
mov [proc_mem_pdir], eax
add eax, ebx
mov [proc_mem_tab], eax
add eax, ebx
mov [tmp_task_ptab], eax
add eax, ebx
mov [ipc_pdir], eax
add eax, ebx
mov [ipc_ptab], eax
stdcall kernel_alloc, (unpack.LZMA_BASE_SIZE+(unpack.LZMA_LIT_SIZE shl \
(unpack.lc+unpack.lp)))*4
mov [unpack.p], eax
call init_events
mov eax, srv.fd-SRV.fd
mov [srv.fd], eax
mov [srv.bk], eax
stdcall kernel_alloc, [_display.win_map_size]
mov [_display.win_map], eax
; set background
movi eax, 1
mov [BgrDrawMode], eax
mov [BgrDataWidth], eax
mov [BgrDataHeight], eax
mov [mem_BACKGROUND], 4
mov [img_background], static_background_data
; set clipboard
xor eax, eax
mov [clipboard_slots], eax
mov [clipboard_write_lock], eax
stdcall kernel_alloc, 4096
test eax, eax
jnz @f
dec eax
@@:
mov [clipboard_main_list], eax
mov dword[sysdir_name], 'sys'
mov dword[sysdir_path], 'RD/1'
mov word[sysdir_path+4], 0
;call ramdisk_init
mov [X_UNDER], 500
mov [Y_UNDER], 500
mov eax, -1
mov edi, thr_slot_map+4
mov [edi-4], dword 0xFFFFFFF8
stosd
stosd
stosd
stosd
stosd
stosd
stosd
mov [current_process], sys_proc
mov [current_slot_idx], 0
mov [thread_count], 0
mov eax, [xsave_area_size]
add eax, RING0_STACK_SIZE
stdcall kernel_alloc, eax
mov ebx, eax
mov edx, SLOT_BASE+256*1
call setup_os_slot
mov dword[edx], 'IDLE'
sub [edx+APPDATA.saved_esp], 4
mov eax, [edx+APPDATA.saved_esp]
mov dword[eax], idle
mov ecx, IDLE_PRIORITY
call scheduler_add_thread
mov eax, [xsave_area_size]
add eax, RING0_STACK_SIZE
stdcall kernel_alloc, eax
mov ebx, eax
mov edx, SLOT_BASE+sizeof.APPDATA*2
call setup_os_slot
mov dword[edx], 'OS'
sub [edx+APPDATA.saved_esp], 4
mov eax, [edx+APPDATA.saved_esp]
mov dword[eax], 0
movi ecx, MAX_PRIORITY
call scheduler_add_thread
mov [current_slot_idx], 2
mov [thread_count], 2
mov [current_slot], SLOT_BASE+2*sizeof.APPDATA
mov [SLOT_BASE + 2*sizeof.APPDATA + APPDATA.tid], 2
call set_window_defaults
call init_background
call calculatebackground
call init_display
mov eax, [def_cursor]
mov [window_data + sizeof.WDATA + WDATA.cursor], eax
mov [window_data + sizeof.WDATA*2 + WDATA.cursor], eax
; from set_variables
mov ax, [BOOT.y_res]
shr ax, 1
shl eax, 16
mov ax, [BOOT.x_res]
shr ax, 1
mov [MOUSE_X], eax
call wakeup_osloop
xor eax, eax
mov [BTN_ADDR], dword BUTTON_INFO ; address of button list
mov byte [KEY_COUNT], al ; keyboard buffer
mov byte [BTN_COUNT], al ; button buffer
mov ebx, SLOT_BASE + 2*sizeof.APPDATA
mov word[cur_dir.path], '/'
mov [ebx+APPDATA.cur_dir], cur_dir
; end of set_variables
call init_irqs
ret
endp
pubsym skin_udata
proc idle uses ebx esi edi
sti
@@:
mov [idle_scheduled], 1
sfence
if ~ HOST eq windows
extrn "pause", 0, libc_pause
call libc_pause
end if
jmp @b
ret
endp
extrn pci_read, 20
proc _pci_read_reg uses ebx esi edi
mov ecx, eax
and ecx, 3
movi edx, 1
shl edx, cl
push edx ; len
movzx edx, bl
push edx ; offset
movzx edx, bh
and edx, 7
push edx ; fun
movzx edx, bh
shr edx, 3
push edx ; dev
movzx edx, ah
push edx ; bus
call pci_read
ret
endp
proc _page_fault_handler
ret
endp
proc delay_ms
ret
endp
pubsym umka_cli
proc umka_cli
cli ; macro
ret
endp
pubsym umka_sti
proc umka_sti
sti ; macro
ret
endp
extrn reset_procmask
extrn get_fake_if
pubsym irq0
proc irq0 c, _signo, _info, _context
DEBUGF 1, "### irq0\n"
pushfd
cli
pushad
inc [timer_ticks]
call updatecputimes
ccall reset_procmask ; kind of irq_eoi:ta
ccall get_fake_if, [_context]
test eax, eax
jnz @f
DEBUGF 1, "### cli\n"
jmp .done
@@:
mov bl, SCHEDULE_ANY_PRIORITY
call find_next_task
jz .done ; if there is only one running process
call _do_change_task
.done:
popad
popfd
ret
endp
proc _do_change_task
mov eax, [current_slot]
sub eax, SLOT_BASE
shr eax, 8
mov ecx, ebx
sub ecx, SLOT_BASE
shr ecx, 8
DEBUGF 1, "### switching task from %d to %d\n",eax,ecx
mov esi, ebx
xchg esi, [current_slot]
; set new stack after saving old
mov [esi+APPDATA.saved_esp], esp
mov esp, [ebx+APPDATA.saved_esp]
ret
endp