Subversion Repositories Kolibri OS

Rev

Rev 437 | Rev 506 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 437 Rev 465
Line 1... Line 1...
1
$Revision: 437 $
1
$Revision: 465 $
2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3
;;                                                              ;;
3
;;                                                              ;;
4
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
4
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
5
;; Distributed under terms of the GNU General Public License    ;;
5
;; Distributed under terms of the GNU General Public License    ;;
6
;;                                                              ;;
6
;;                                                              ;;
Line 26... Line 26...
26
  .stack_top   dd ?    ;+24
26
  .stack_top   dd ?    ;+24
27
  .i_param     dd ?    ;+28
27
  .i_param     dd ?    ;+28
28
  .i_icon      dd ?    ;+32
28
  .i_icon      dd ?    ;+32
29
}
29
}
Line 30... Line -...
30
 
-
 
31
struc TSS
-
 
32
{
-
 
33
  ._back   rw 2
-
 
34
  ._esp0   rd 1
-
 
35
  ._ss0    rw 2
-
 
36
  ._esp1   rd 1
-
 
37
  ._ss1    rw 2
-
 
38
  ._esp2   rd 1
-
 
39
  ._ss2    rw 2
-
 
40
  ._cr3    rd 1
-
 
41
  ._eip    rd 1
-
 
42
  ._eflags rd 1
-
 
43
  ._eax    rd 1
-
 
44
  ._ecx    rd 1
-
 
45
  ._edx    rd 1
-
 
46
  ._ebx    rd 1
-
 
47
  ._esp    rd 1
-
 
48
  ._ebp    rd 1
-
 
49
  ._esi    rd 1
-
 
50
  ._edi    rd 1
-
 
51
  ._es     rw 2
-
 
52
  ._cs     rw 2
-
 
53
  ._ss     rw 2
-
 
54
  ._ds     rw 2
-
 
55
  ._fs     rw 2
-
 
56
  ._gs     rw 2
-
 
57
  ._ldt    rw 2
-
 
58
  ._trap   rw 1
-
 
59
  ._io     rw 1
-
 
60
}
-
 
61
 
-
 
62
virtual at 0
-
 
63
  TSS  TSS
-
 
Line 64... Line 30...
64
end virtual
30
 
65
 
31
 
66
struc APP_PARAMS
32
struc APP_PARAMS
67
{ .app_cmdline   ;0x00
33
{ .app_cmdline   ;0x00
Line 152... Line 118...
152
           mov eax, 1
118
           mov eax, 1
153
           xchg eax, [application_table_status]
119
           xchg eax, [application_table_status]
154
           cmp eax, 0
120
           cmp eax, 0
155
           jne .wait_lock
121
           jne .wait_lock
Line 156... Line -...
156
 
-
 
157
;           pushfd
-
 
158
;           cli
-
 
159
 
122
 
Line 160... Line 123...
160
           call set_application_table_status
123
           call set_application_table_status
161
 
124
 
162
           call get_new_process_place
125
           call get_new_process_place
Line 214... Line 177...
214
           and edi, not 4095
177
           and edi, not 4095
215
           sub ecx, edi
178
           sub ecx, edi
216
           jna @F
179
           jna @F
Line 217... Line 180...
217
 
180
 
218
           xor eax, eax
181
           xor eax, eax
219
           add edi, new_app_base
182
      ;     add edi, new_app_base
220
           cld
183
           cld
221
           rep stosb
184
           rep stosb
222
@@:
185
@@:
Line 393... Line 356...
393
           test eax, eax
356
           test eax, eax
394
           jz .fail
357
           jz .fail
395
           mov [dir_addr], eax
358
           mov [dir_addr], eax
396
           stdcall map_page,[tmp_task_pdir],eax,dword PG_SW
359
           stdcall map_page,[tmp_task_pdir],eax,dword PG_SW
Line 397... Line -...
397
 
-
 
398
           mov esi, sys_pgdir
360
 
399
           mov edi, [tmp_task_pdir]
361
           mov edi, [tmp_task_pdir]
-
 
362
           mov ecx, (OS_BASE shr 20)/4
400
           mov ecx, (page_tabs shr 20)/4
363
           xor eax, eax
-
 
364
           cld
-
 
365
           rep stosd
-
 
366
 
-
 
367
           mov ecx, (OS_BASE shr 20)/4
401
           cld
368
           mov esi, sys_pgdir+(OS_BASE shr 20)
Line 402... Line 369...
402
           rep movsd
369
           rep movsd
403
 
370
 
404
           mov eax, [dir_addr]
371
           mov eax, [dir_addr]
Line 405... Line -...
405
           or eax, PG_SW
-
 
406
           stosd                 ; [(page_tabs shr 20)]= eax
372
           or eax, PG_SW
407
 
-
 
408
           mov ecx, 0x800/4
-
 
409
           xor eax, eax
-
 
410
           rep stosd
373
           mov [edi-4096+(page_tabs shr 20)], eax
Line 411... Line 374...
411
 
374
 
412
           mov eax, [dir_addr]
375
           and eax, -4096
413
           call set_cr3
376
           call set_cr3
Line 492... Line 455...
492
           ret
455
           ret
493
endp
456
endp
Line 494... Line 457...
494
 
457
 
495
align 4
458
align 4
-
 
459
set_cr3:
496
set_cr3:
460
 
497
           mov esi, [CURRENT_TASK]
-
 
498
           mov ebx, esi
-
 
499
           shl esi,8
-
 
500
           mov [SLOT_BASE+esi+0xB8],eax
-
 
501
           imul   ebx,tss_step
-
 
502
           add    ebx,tss_data
461
           mov ebx, [current_slot]
503
           mov [ebx+28], eax
462
           mov [ebx+APPDATA.dir_table], eax
504
           mov cr3, eax
463
           mov cr3, eax
Line 505... Line 464...
505
           ret
464
           ret
506
 
465
 
Line 556... Line 515...
556
 
515
 
557
           mov eax, [pg_dir]
516
           mov eax, [pg_dir]
558
           and eax, not 0xFFF
517
           and eax, not 0xFFF
559
           stdcall map_page,[tmp_task_pdir],eax,dword PG_SW
518
           stdcall map_page,[tmp_task_pdir],eax,dword PG_SW
560
           mov esi, [tmp_task_pdir]
-
 
561
           add esi, 0x800
519
           mov esi, [tmp_task_pdir]
562
           mov edi, 0x800/4
520
           mov edi, (OS_BASE shr 20)/4
563
.destroy:
521
.destroy:
564
           mov eax, [esi]
522
           mov eax, [esi]
565
           test eax, 1
523
           test eax, 1
566
           jz .next
524
           jz .next
Line 742... Line 700...
742
           mov ecx, 0x8000
700
           mov ecx, 0x8000
743
@@:
701
@@:
744
           mov eax, [slot]
702
           mov eax, [slot]
745
           shl  eax,8
703
           shl  eax,8
746
           mov ebx, [offset]
704
           mov ebx, [offset]
747
           add ebx, new_app_base
705
     ;      add ebx, new_app_base
748
           push ecx
706
           push ecx
749
           stdcall map_memEx, [proc_mem_map],\
707
           stdcall map_memEx, [proc_mem_map],\
750
                              [SLOT_BASE+eax+0xB8],\
708
                              [SLOT_BASE+eax+0xB8],\
751
                              ebx, ecx
709
                              ebx, ecx
752
           pop ecx
710
           pop ecx
Line 808... Line 766...
808
           mov ecx, 0x8000
766
           mov ecx, 0x8000
809
@@:
767
@@:
810
           mov eax, [slot]
768
           mov eax, [slot]
811
           shl  eax,8
769
           shl  eax,8
812
           mov ebx, [offset]
770
           mov ebx, [offset]
813
           add ebx, new_app_base
771
      ;     add ebx, new_app_base
814
           push ecx
772
           push ecx
815
           stdcall map_memEx, [proc_mem_map],\
773
           stdcall map_memEx, [proc_mem_map],\
816
                              [SLOT_BASE+eax+0xB8],\
774
                              [SLOT_BASE+eax+0xB8],\
817
                              ebx, ecx
775
                              ebx, ecx
818
           pop ecx
776
           pop ecx
Line 873... Line 831...
873
           test eax, eax
831
           test eax, eax
874
           jz .failed
832
           jz .failed
Line 875... Line 833...
875
 
833
 
Line 876... Line 834...
876
           mov [slot], eax
834
           mov [slot], eax
877
 
-
 
878
           mov    esi,[CURRENT_TASK]
-
 
879
           shl    esi,8
835
 
Line 880... Line 836...
880
           add    esi,SLOT_BASE
836
           mov    esi,[current_slot]
881
           mov    ebx,esi             ;ebx=esi - pointer to extended information about current thread
837
           mov    ebx,esi             ;ebx=esi - pointer to extended information about current thread
882
 
838
 
Line 940... Line 896...
940
           jnz .do_wait
896
           jnz .do_wait
941
           pop ebx
897
           pop ebx
942
           pop eax
898
           pop eax
943
           ret
899
           ret
Line -... Line 900...
-
 
900
 
-
 
901
EFL_IF      equ 0x0200
-
 
902
EFL_IOPL1   equ 0x1000
-
 
903
EFL_IOPL2   equ 0x2000
-
 
904
EFL_IOPL3   equ 0x3000
-
 
905
 
944
 
906
 
945
align 4
907
align 4
946
proc set_app_params stdcall,slot:dword, params:dword,\
908
proc set_app_params stdcall,slot:dword, params:dword,\
Line 947... Line 909...
947
                        cmd_line:dword, app_path:dword, flags:dword
909
                        cmd_line:dword, app_path:dword, flags:dword
Line 961... Line 923...
961
           shl eax, 8
923
           shl eax, 8
962
           mov [eax+SLOT_BASE+APPDATA.fpu_state], edi
924
           mov [eax+SLOT_BASE+APPDATA.fpu_state], edi
963
           mov [eax+SLOT_BASE+APPDATA.fpu_handler], 0
925
           mov [eax+SLOT_BASE+APPDATA.fpu_handler], 0
964
           mov [eax+SLOT_BASE+APPDATA.sse_handler], 0
926
           mov [eax+SLOT_BASE+APPDATA.sse_handler], 0
Line -... Line 927...
-
 
927
 
-
 
928
;set default io permission map
-
 
929
           mov [eax+SLOT_BASE+APPDATA.io_map],\
-
 
930
                  (tss._io_map_0-OS_BASE+PG_MAP)
-
 
931
           mov [eax+SLOT_BASE+APPDATA.io_map+4],\
-
 
932
                  (tss._io_map_1-OS_BASE+PG_MAP)
965
 
933
 
966
           mov esi, fpu_data
934
           mov esi, fpu_data
967
           mov ecx, 512/4
-
 
968
           cld
935
           mov ecx, 512/4
Line 969... Line 936...
969
           rep movsd
936
           rep movsd
970
 
937
 
971
           cmp    ebx,[TASK_COUNT]
938
           cmp    ebx,[TASK_COUNT]
Line 1001... Line 968...
1001
           jc      @f
968
           jc      @f
Line 1002... Line 969...
1002
 
969
 
1003
           cmp     eax, [SLOT_BASE+APPDATA.mem_size+ebx*8]
970
           cmp     eax, [SLOT_BASE+APPDATA.mem_size+ebx*8]
Line 1004... Line -...
1004
           ja      @f
-
 
1005
 
971
           ja      @f
1006
           add edx, new_app_base
972
 
1007
           stdcall k_strncpy, edx, [cmd_line], 256
973
           stdcall k_strncpy, edx, [cmd_line], 256
1008
@@:
974
@@:
1009
           mov edx,[params]
975
           mov edx,[params]
Line 1013... Line 979...
1013
        mov     eax, edx
979
           mov     eax, edx
1014
        add     eax, 1024
980
           add     eax, 1024
1015
        jc      @f
981
           jc      @f
1016
        cmp     eax, [SLOT_BASE+APPDATA.mem_size+ebx*8]
982
           cmp     eax, [SLOT_BASE+APPDATA.mem_size+ebx*8]
1017
        ja      @f
983
           ja      @f
1018
           add edx, new_app_base
-
 
1019
           stdcall k_strncpy, edx, [app_path], 1024
984
           stdcall k_strncpy, edx, [app_path], 1024
1020
@@:
985
@@:
1021
           mov    ebx,[slot]
986
           mov    ebx,[slot]
1022
           mov    eax,ebx
987
           mov    eax,ebx
1023
           shl    ebx,5
988
           shl    ebx,5
-
 
989
           lea    ecx,[draw_data+ebx]  ;ecx - pointer to draw data
-
 
990
 
1024
; set window state to 'normal' (non-minimized/maximized/rolled-up) state
991
; set window state to 'normal' (non-minimized/maximized/rolled-up) state
1025
           mov     [ebx+window_data+WDATA.fl_wstate], WSTATE_NORMAL
992
           mov     [ebx+window_data+WDATA.fl_wstate], WSTATE_NORMAL
1026
           mov     [ebx+window_data+WDATA.fl_redraw], 1
993
           mov     [ebx+window_data+WDATA.fl_redraw], 1
1027
           add    ebx,CURRENT_TASK            ;ebx - pointer to information about process
994
           add    ebx,CURRENT_TASK            ;ebx - pointer to information about process
1028
           mov    [ebx+TASKDATA.wnd_number],al;set window number on screen = process slot
995
           mov    [ebx+TASKDATA.wnd_number],al;set window number on screen = process slot
Line 1031... Line 998...
1031
 
998
 
1032
           inc    dword [process_number]
999
           inc    dword [process_number]
1033
           mov    eax,[process_number]
1000
           mov    eax,[process_number]
Line 1034... Line -...
1034
           mov    [ebx+4],eax           ;set PID
-
 
1035
 
-
 
1036
           mov    ecx,ebx
1001
           mov    [ebx+4],eax           ;set PID
Line 1037... Line 1002...
1037
           add    ecx,(draw_data-CURRENT_TASK)  ;ecx - pointer to draw data
1002
 
1038
;set draw data to full screen
1003
;set draw data to full screen
1039
 
1004
 
1040
           mov    [ecx+0],dword 0
1005
           mov    [ecx+0],dword 0
1041
           mov    [ecx+4],dword 0
1006
           mov    [ecx+4],dword 0
1042
           mov    eax,[ScreenWidth]
1007
           mov    eax,[ScreenWidth]
Line 1043... Line 1008...
1043
           mov    [ecx+8],eax
1008
           mov    [ecx+8],eax
1044
           mov    eax,[ScreenHeight]
1009
           mov    eax,[ScreenHeight]
1045
           mov    [ecx+12],eax
-
 
1046
 
1010
           mov    [ecx+12],eax
1047
           mov edi,[slot]
1011
 
1048
           imul edi,tss_step
-
 
1049
           add edi,tss_data
-
 
1050
           mov ecx,128/4
-
 
1051
           xor eax, eax
-
 
1052
           cld
-
 
1053
           rep stosd
-
 
1054
;Add IO access table - bit array of permitted ports
-
 
1055
           not eax
-
 
1056
           mov ecx,2048
-
 
1057
           rep stosd                 ; access to 4096*8=65536 ports
-
 
1058
           sub edi, tss_step
-
 
1059
 
-
 
1060
;set cr3 register in TSS of application
-
 
Line -... Line 1012...
-
 
1012
           mov ebx, [pl0_stack]
-
 
1013
           mov esi,[params]
-
 
1014
           lea ecx, [ebx+REG_EIP]
1061
           mov ecx, [slot]
1015
           xor eax, eax
-
 
1016
 
-
 
1017
           mov [ebx+REG_RET], dword irq0.return
-
 
1018
           mov [ebx+REG_EDI], eax
-
 
1019
           mov [ebx+REG_ESI], eax
-
 
1020
           mov [ebx+REG_EBP], eax
-
 
1021
           mov [ebx+REG_ESP], ecx   ;ebx+REG_EIP
1062
           shl ecx, 8
1022
           mov [ebx+REG_EBX], eax
1063
           mov eax,[SLOT_BASE+ecx+APPDATA.dir_table]
1023
           mov [ebx+REG_EDX], eax
1064
           mov [edi+TSS._cr3],eax
1024
           mov [ebx+REG_ECX], eax
1065
 
-
 
1066
           mov esi,[params]
1025
           mov [ebx+REG_EAX], eax
Line 1067... Line -...
1067
           mov eax, [esi+0x08]       ;app_eip
-
 
1068
           mov [edi+TSS._eip],eax    ;set eip in TSS
1026
 
1069
           mov eax, [esi+0x0C]       ;app_esp
1027
           mov eax, [esi+0x08]       ;app_eip
1070
           mov [edi+TSS._esp],eax    ;set stack in TSS
1028
           mov [ebx+REG_EIP],  eax   ;app_entry
1071
           mov [edi+TSS._eflags],dword 0x1202
-
 
1072
 
-
 
1073
           mov [edi+TSS._cs],app_code  ;selector of code segment
-
 
1074
           mov [edi+TSS._ss],app_data
-
 
1075
           mov [edi+TSS._ds],app_data
-
 
1076
           mov [edi+TSS._es],app_data
-
 
1077
           mov [edi+TSS._fs],app_data
-
 
Line 1078... Line 1029...
1078
           mov [edi+TSS._gs],graph_data ;selector of graphic segment
1029
           mov [ebx+REG_CS], dword app_code
1079
           mov [edi+TSS._io],word 128
1030
           mov [ebx+REG_EFLAGS], dword EFL_IOPL1+EFL_IF
1080
           mov [edi+TSS._ss0], os_data
1031
 
1081
           mov ebx, [pl0_stack]
-
 
1082
           add ebx, RING0_STACK_SIZE
-
 
1083
           mov [edi+TSS._esp0],ebx
-
 
1084
 
-
 
1085
           mov ecx, edi    ;ecx - address of application TSS
-
 
1086
           mov ebx,[slot]
1032
           mov eax, [esi+0x0C]       ;app_esp
1087
           shl ebx,3
-
 
Line 1088... Line 1033...
1088
;set TSS descriptor
1033
           mov [ebx+REG_APP_ESP], eax    ;app_stack
1089
           mov [ebx+gdts+tss0+0],word tss_step ;limit (size)
1034
           mov [ebx+REG_SS], dword app_data
1090
           mov [ebx+gdts+tss0+2],cx  ;part of offset
1035
 
Line 1119... Line 1064...
1119
           mov    esi,new_process_running
1064
           mov    esi,new_process_running
1120
           call   sys_msg_board_str     ;output information about succefull startup
1065
           call   sys_msg_board_str     ;output information about succefull startup
1121
           ret
1066
           ret
1122
endp
1067
endp
Line 1123... Line -...
1123
 
-
 
1124
 
-
 
1125
 
1068
 
Line 1126... Line -...
1126
include "debug.inc"
-
 
1127
 
-
 
1128
iglobal
-
 
1129
    new_process_loading db 'K : New Process - loading',13,10,0
-
 
1130
    new_process_running db 'K : New Process - done',13,10,0
-
 
1131
    start_not_enough_memory db 'K : New Process - not enough memory',13,10,0
-