Subversion Repositories Kolibri OS

Rev

Rev 168 | Rev 183 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 ha 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                               ;;
3
;;  MenuetOS process management, protected ring3                 ;;
4
;;                                                               ;;
5
;;  Distributed under GPL. See file COPYING for details.         ;;
6
;;  Copyright 2003 Ville Turjanmaa                               ;;
7
;;                                                               ;;
8
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9
 
10
align 32
11
 
12
; GDT TABLE
13
 
14
gdts:
15
 
16
        dw     gdte-$-1
17
        dd     gdts
18
        dw     0
19
 
20
int_code_l:
21
os_code_l:
22
 
23
        dw     0xffff
24
        dw     0x0000
25
        db     0x00
26
        dw     11011111b *256 +10011010b
27
        db     0x00
28
 
29
int_data_l:
30
os_data_l:
31
 
32
        dw     0xffff
33
        dw     0x0000
34
        db     0x00
35
        dw     11011111b *256 +10010010b
36
        db     0x00
37
 
76 mario79 38
; --------------- APM ---------------------
39
apm_code_32:
40
        dw     0x10        ; limit 64kb
41
        db     0, 0, 0
42
        dw     11011111b *256 +10011010b
43
        db     0x00
44
apm_code_16:
45
        dw     0x10
46
        db     0, 0, 0
47
        dw     10011111b *256 +10011010b
48
        db     0x00
49
apm_data_16:
50
        dw     0x10
51
        db     0, 0, 0
52
        dw     10011111b *256 +10010010b
53
        db     0x00
54
; -----------------------------------------
55
 
1 ha 56
app_code_l:
164 serge 57
      dw 0xFFFF;((0x80000000-std_application_base_address) shr 12) and 0xffff
4 poddubny 58
      dw 0
164 serge 59
      db 0x40
60
      db cpl3
61
      dw G32+D32+0x6000+0x7;
1 ha 62
 
63
app_data_l:
164 serge 64
      dw 0xFFFF;(0x80000000-std_application_base_address) shr 12 and 0xffff
4 poddubny 65
      dw 0
164 serge 66
      db 0x40
67
      db drw3
68
      dw G32+D32+0x6000+0x7;
1 ha 69
 
8 poddubny 70
graph_data_l:
1 ha 71
 
8 poddubny 72
        dw     0x3ff
73
        dw     0x0000
74
        db     0x00
75
        dw     11010000b *256 +11110010b
76
        db     0x00
77
 
78
tss0_l:
79
      times (max_processes+10) dd 0,0
80
 
1 ha 81
gdte:
82
 
83
 
84
idtreg:
85
     dw   8*0x41-1
86
     dd   idts+8
164 serge 87
;label idts at 0xB100-8
1 ha 88
 
89
 
90
 
8 poddubny 91
uglobal
92
 tss_sceleton:
93
  l.back   dw 0,0
94
  l.esp0   dd 0
95
  l.ss0    dw 0,0
96
  l.esp1   dd 0
97
  l.ss1    dw 0,0
98
  l.esp2   dd 0
99
  l.ss2    dw 0,0
100
  l.cr3    dd 0
101
  l.eip    dd 0
102
  l.eflags dd 0
103
  l.eax    dd 0
104
  l.ecx    dd 0
105
  l.edx    dd 0
106
  l.ebx    dd 0
107
  l.esp    dd 0
108
  l.ebp    dd 0
109
  l.esi    dd 0
110
  l.edi    dd 0
111
  l.es     dw 0,0
112
  l.cs     dw 0,0
113
  l.ss     dw 0,0
114
  l.ds     dw 0,0
115
  l.fs     dw 0,0
116
  l.gs     dw 0,0
117
  l.ldt    dw 0,0
118
  l.trap   dw 0
119
  l.io     dw 0
120
endg
121
 
122
 
1 ha 123
build_process_gdt_tss_pointer:
124
 
125
        mov    ecx,tss_data
126
        mov    edi,0
127
      setgdtl2:
128
        mov    [edi+gdts+ tss0 +0], word tss_step
129
        mov    [edi+gdts+ tss0 +2], cx
130
        mov    eax,ecx
131
        shr    eax,16
132
        mov    [edi+gdts+ tss0 +4], al
133
        mov    [edi+gdts+ tss0 +7], ah
134
        mov    [edi+gdts+ tss0 +5], word 01010000b *256 +11101001b
135
        add    ecx,tss_step
136
        add    edi,8
137
        cmp    edi,8*(max_processes+5)
138
        jbe    setgdtl2
139
 
140
        ret
141
 
142
 
143
build_interrupt_table:
144
 
6 poddubny 145
        mov    edi, idts+8
146
        mov    esi, sys_int
8 poddubny 147
        mov    ecx, 0x40
6 poddubny 148
     @@:
149
        mov    eax, [esi]
150
        mov    [edi],   ax           ; lower part of offset
151
        mov    [edi+2], word os_code ; segment selector
152
        shr    eax, 16
153
        mov    [edi+4], word 10001110b shl 8 ; interrupt descriptor
154
        mov    [edi+6], ax
155
        add    esi, 4
156
        add    edi, 8
157
        dec    ecx
158
        jnz    @b
164 serge 159
 
8 poddubny 160
        ;mov    edi,8*0x40+idts+8
3 halyavin 161
        mov    [edi + 0], word (i40 and ((1 shl 16)-1))
162
        mov    [edi + 2], word os_code
163
        mov    [edi + 4], word 11101110b*256
9 halyavin 164
        mov    [edi + 6], word (i40 shr 16)
1 ha 165
 
166
        ret
167
 
168
iglobal
169
  sys_int:
164 serge 170
    dd e0,debug_exc,e2,e3
171
    dd e4,e5,e6,e7
172
    dd e8,e9,e10,e11
173
    dd e12,e13,page_fault_handler,e15
174
 
168 serge 175
    dd except_16, e17,e18, except_19
176
    times 12 dd unknown_interrupt
1 ha 177
 
164 serge 178
    dd   irq0  , irq_serv.irq_1, p_irq2 ,irq_serv.irq_3
179
    dd   p_irq4 ,irq_serv.irq_5,p_irq6,irq_serv.irq_7
180
    dd   irq_serv.irq_8, irq_serv.irq_9, irq_serv.irq_10
181
    dd   irq_serv.irq_11,p_irq12,irqD ,p_irq14,p_irq15
1 ha 182
 
183
    times 16 dd unknown_interrupt
184
 
185
    dd   i40
186
endg
187
 
40 halyavin 188
macro save_ring3_context
189
{
58 mario79 190
    push    ds es
191
    pushad
40 halyavin 192
}
193
macro restore_ring3_context
194
{
58 mario79 195
    popad
196
    pop    es ds
40 halyavin 197
}
198
 
8 poddubny 199
; simply return control to interrupted process
200
unknown_interrupt:
201
     iret
1 ha 202
 
22 poddubny 203
macro exc_wo_code [num]
8 poddubny 204
{
205
  forward
206
  e#num :
40 halyavin 207
      save_ring3_context
20 mario79 208
      mov bl, num
209
      jmp exc_c
8 poddubny 210
}
1 ha 211
 
22 poddubny 212
macro exc_w_code [num]
213
{
214
  forward
215
  e#num :
216
      add esp, 4
40 halyavin 217
      save_ring3_context
22 poddubny 218
      mov bl, num
219
      jmp exc_c
220
}
221
 
168 serge 222
exc_wo_code 0, 1, 2, 3, 4, 5, 6, 9, 15, 18
22 poddubny 223
exc_w_code 8, 10, 11, 12, 13, 14, 17
224
 
8 poddubny 225
exc_c:
6 poddubny 226
        mov   ax, os_data
227
        mov   ds, ax
228
        mov   es, ax
1 ha 229
 
40 halyavin 230
; test if debugging
231
        cli
232
        mov   eax, [0x3000]
233
        shl   eax, 8
115 poddubny 234
        mov   eax, [0x80000+eax+APPDATA.debugger_slot]
40 halyavin 235
        test  eax, eax
236
        jnz   .debug
237
        sti
238
; not debuggee => say error and terminate
239
        add   esp, 28h
164 serge 240
        movzx eax, bl
8 poddubny 241
        mov   [error_interrupt], eax
1 ha 242
        call  show_error_parameters
164 serge 243
 
8 poddubny 244
        mov   edx, [0x3010]
115 poddubny 245
        mov   [edx + TASKDATA.state], byte 4
164 serge 246
 
1 ha 247
        jmp   change_task
248
 
40 halyavin 249
.debug:
250
; we are debugged process, notify debugger and suspend ourself
251
; eax=debugger PID
113 diamond 252
        cld
40 halyavin 253
        movzx ecx, bl
254
        push  ecx
255
        mov   ecx, [0x3010]
115 poddubny 256
        push  dword [ecx+TASKDATA.pid]    ; PID of current process
40 halyavin 257
        push  12
258
        pop   ecx
58 mario79 259
        push  1        ; 1=exception
40 halyavin 260
        call  debugger_notify
261
        pop   ecx
262
        pop   ecx
263
        pop   ecx
264
        mov   edx, [0x3010]
115 poddubny 265
        mov   byte [edx+TASKDATA.state], 1        ; suspended
40 halyavin 266
        call  change_task
267
        restore_ring3_context
268
        iretd
1 ha 269
 
270
;;;;;;;;;;;;;;;;;;;;;;;
271
;; FPU ERROR HANDLER ;;
272
;;;;;;;;;;;;;;;;;;;;;;;
273
 
274
align 4
8 poddubny 275
e7:
40 halyavin 276
        save_ring3_context
6 poddubny 277
        clts
164 serge 278
        mov ax, os_data
279
        mov ds, ax
280
        mov es, ax
281
 
282
        mov ebx, [fpu_owner]
283
        cmp ebx, [CURRENT_TASK]
284
        je .exit
285
 
286
        shl ebx, 8
287
        mov eax, [ebx+PROC_BASE+APPDATA.fpu_state]
288
        bt [cpu_caps], CAPS_FXSR
289
        jnc .no_SSE
290
 
291
        fxsave [eax]
292
        mov ebx, [CURRENT_TASK]
293
        mov [fpu_owner], ebx
294
        shl ebx, 8
295
        cmp dword [ebx+PROC_BASE+APPDATA.fpu_init], 0
296
        je .init
297
        mov eax, [ebx+PROC_BASE+APPDATA.fpu_state]
298
        fxrstor [eax]
40 halyavin 299
        restore_ring3_context
6 poddubny 300
        iret
170 serge 301
 
164 serge 302
.no_SSE:
303
        fnsave [eax]
304
        mov ebx, [CURRENT_TASK]
305
        mov [fpu_owner], ebx
306
        shl ebx, 8
307
        cmp dword [ebx+PROC_BASE+APPDATA.fpu_init], 0
170 serge 308
        je .ready
164 serge 309
 
310
        mov eax, [ebx+PROC_BASE+APPDATA.fpu_state]
311
        frstor [eax]
312
        restore_ring3_context
313
        iret
314
 
170 serge 315
.init:
316
        fninit                      ;­ ¬ ­¥ ­ã¦­ë ­¥¬ áª¨à®¢ ­­ë¥ ¨áª«î祭¨ï
317
.ready:
318
        mov dword [ebx+PROC_BASE+APPDATA.fpu_init], 1
319
.exit:
320
        restore_ring3_context
321
        iret
322
 
6 poddubny 323
iglobal
164 serge 324
  fpu_owner dd 1
325
 endg
1 ha 326
 
327
 
328
writehex:
329
      pusha
164 serge 330
 
8 poddubny 331
      mov  edi, [write_error_to]
332
      mov  esi, 8
333
    @@:
334
      mov  ecx, eax
335
      and  ecx, 0xf
1 ha 336
 
8 poddubny 337
      mov  cl,[ecx+hexletters]
1 ha 338
      mov  [edi],cl
8 poddubny 339
      dec  edi
1 ha 340
 
8 poddubny 341
      shr  eax,4
1 ha 342
      dec  esi
8 poddubny 343
      jnz  @b
1 ha 344
 
345
      popa
346
      ret
347
 
348
iglobal
349
  hexletters  db '0123456789ABCDEF'
350
 
351
  error_interrupt         dd  -1
352
 
353
  process_error  db 'K : Process - forced terminate INT: 00000000',13,10,0
354
  process_pid    db 'K : Process - forced terminate PID: 00000000',13,10,0
355
  process_eip    db 'K : Process - forced terminate EIP: 00000000',13,10,0
356
  system_error   db 'K : Kernel error',13,10,0
357
endg
358
 
359
uglobal
360
  write_error_to  dd  0x0
361
endg
362
 
363
show_error_parameters:
164 serge 364
 
1 ha 365
        mov    [write_error_to],process_pid+43
366
        mov    eax,[0x3000]
367
        shl    eax, 5
115 poddubny 368
        mov    eax,[0x3000+TASKDATA.pid+eax]
1 ha 369
        call   writehex
164 serge 370
 
1 ha 371
        mov    [write_error_to],process_error+43
372
        mov    eax,[error_interrupt]
373
        call   writehex
16 poddubny 374
 
375
        cmp    dword [esp+4+4], os_code ; CS
376
        jnz    @f
10 poddubny 377
        mov    esi,system_error
378
        call   sys_msg_board_str
379
      @@:
16 poddubny 380
        mov    eax, [esp+4] ; EIP
10 poddubny 381
 
1 ha 382
        mov    [write_error_to],process_eip+43
383
        call   writehex
384
 
385
        mov    esi,process_error
386
        call   sys_msg_board_str
387
 
388
        mov    esi,process_pid
389
        call   sys_msg_board_str
390
 
391
        mov    esi,process_eip
392
        call   sys_msg_board_str
393
 
394
        ret
395
 
396
 
397
 
6 poddubny 398
; irq1  ->  hid/keyboard.inc
1 ha 399
 
400
 
10 poddubny 401
macro irqh [num]
8 poddubny 402
{
403
  forward
404
  p_irq#num :
40 halyavin 405
     save_ring3_context
8 poddubny 406
     mov   edi, num
407
     jmp   irq_c
408
}
1 ha 409
 
160 diamond 410
irqh 2,5,7,8,9,10,11
1 ha 411
 
8 poddubny 412
 irq_c:
413
     mov   ax, os_data
414
     mov   ds, ax
415
     mov   es, ax
1 ha 416
     call  irqhandler
40 halyavin 417
     restore_ring3_context
8 poddubny 418
     iret
11 poddubny 419
 
420
p_irq6:
40 halyavin 421
     save_ring3_context
11 poddubny 422
     mov   ax, os_data
423
     mov   ds, ax
424
     mov   es, ax
425
     call  fdc_irq
33 mario79 426
     call  ready_for_next_irq
40 halyavin 427
     restore_ring3_context
33 mario79 428
     iret
15 poddubny 429
 
33 mario79 430
p_irq3:
40 halyavin 431
     save_ring3_context
33 mario79 432
     mov   ax, os_data
433
     mov   ds, ax
434
     mov   es, ax
58 mario79 435
     cmp   [com2_mouse_detected],0
436
     je    old_irq3_handler
33 mario79 437
     call  check_mouse_data_com2
58 mario79 438
     jmp   p_irq3_1
439
 old_irq3_handler:
440
     mov   edi,3
441
     call  irqhandler
164 serge 442
  p_irq3_1:
40 halyavin 443
     restore_ring3_context
33 mario79 444
     iret
15 poddubny 445
 
33 mario79 446
p_irq4:
40 halyavin 447
     save_ring3_context
33 mario79 448
     mov   ax, os_data
449
     mov   ds, ax
450
     mov   es, ax
58 mario79 451
     cmp   [com1_mouse_detected],0
452
     je    old_irq4_handler
33 mario79 453
     call  check_mouse_data_com1
58 mario79 454
     jmp   p_irq4_1
455
 old_irq4_handler:
456
     mov   edi,4
457
     call  irqhandler
164 serge 458
  p_irq4_1:
40 halyavin 459
     restore_ring3_context
11 poddubny 460
     iret
461
 
33 mario79 462
p_irq12:
40 halyavin 463
     save_ring3_context
33 mario79 464
     mov   ax, os_data
465
     mov   ds, ax
466
     mov   es, ax
467
     call  check_mouse_data_ps2
40 halyavin 468
     restore_ring3_context
33 mario79 469
     iret
470
 
160 diamond 471
p_irq14:
472
        save_ring3_context
473
        mov     ax, os_data
474
        mov     ds, ax
475
        mov     es, ax
476
        call    [irq14_func]
477
        call    ready_for_next_irq_1
478
        restore_ring3_context
479
        iret
480
p_irq15:
481
        save_ring3_context
482
        mov     ax, os_data
483
        mov     ds, ax
484
        mov     es, ax
485
        call    [irq15_func]
486
        call    ready_for_next_irq_1
487
        restore_ring3_context
488
        iret
489
 
33 mario79 490
ready_for_next_irq:
491
     mov    [check_idle_semaphore],5
492
     mov   al, 0x20
493
     out   0x20, al
494
     ret
495
 
496
ready_for_next_irq_1:
497
     mov    [check_idle_semaphore],5
498
     mov   al, 0x20
499
     out    0xa0,al
500
     out   0x20, al
501
     ret
502
 
6 poddubny 503
irqD:
40 halyavin 504
     save_ring3_context
8 poddubny 505
     mov   ax, os_data
506
     mov   ds, ax
507
     mov   es, ax
164 serge 508
 
6 poddubny 509
     mov   dx,0xf0
510
     mov   al,0
511
     out   dx,al
1 ha 512
 
6 poddubny 513
     mov   dx,0xa0
514
     mov   al,0x20
515
     out   dx,al
516
     mov   dx,0x20
40 halyavin 517
     out   dx,al
518
 
519
     restore_ring3_context
164 serge 520
 
8 poddubny 521
     iret
1 ha 522
 
523
 
524
irqhandler:
525
 
526
     push   edi
527
 
528
     mov    esi,edi          ; 1
529
     shl    esi,6            ; 1
530
     add    esi,irq00read    ; 1
531
     shl    edi,12           ; 1
532
     add    edi,0x2E0000
75 diamond 533
     mov    ecx,16
1 ha 534
 
535
     mov    [check_idle_semaphore],5
536
 
537
   irqnewread:
75 diamond 538
     dec    ecx
539
     js     irqover
1 ha 540
 
541
     mov    dx,[esi]         ; 2+
542
 
543
     cmp    dx,0             ; 1
544
     jz     irqover
545
     cmp    [esi+3],byte 1   ; 2     ; byte read
546
     jne    noirqbyte        ; 4-11
547
 
548
     in     al,dx
549
 
550
     mov    edx,[edi]
551
     cmp    edx,4000
552
     je     irqfull
553
     mov    ebx,edi
554
     add    ebx,0x10
555
     add    ebx,edx
556
     mov    [ebx],al
557
     inc    edx
558
     mov    [edi],edx
559
 
560
     add    esi,4
561
     jmp    irqnewread
562
 
563
   noirqbyte:
564
 
565
 
566
     cmp    [esi+3],byte 2     ; word read
567
     jne    noirqword
568
 
569
     in     ax,dx
570
 
571
     mov    edx,[edi]
572
     cmp    edx,4000
573
     je     irqfull
574
     mov    ebx,edi
575
     add    ebx,0x10
576
     add    ebx,edx
577
     mov    [ebx],ax
578
     add    edx,2
579
     mov    [edi],edx
580
     add    esi,4
581
     jmp    irqnewread
582
 
583
   noirqword:
584
   irqfull:
585
   irqover:
586
 
587
     mov    al,0x20            ; ready for next irq
588
     out    0x20,al
589
 
590
     pop    ebx
591
     cmp    ebx,7
592
     jbe    noa0
593
     out    0xa0,al
594
   noa0:
595
 
596
     ret
597
 
598
 
599
 
600
set_application_table_status:
601
        push eax
602
 
603
        mov  eax,[0x3000]
604
        shl  eax, 5
115 poddubny 605
        add  eax,0x3000+TASKDATA.pid
1 ha 606
        mov  eax,[eax]
607
 
608
        mov  [application_table_status],eax
609
 
610
        pop  eax
611
 
612
        ret
613
 
614
 
615
clear_application_table_status:
616
        push eax
617
 
618
        mov  eax,[0x3000]
619
        shl  eax, 5
115 poddubny 620
        add  eax,0x3000+TASKDATA.pid
1 ha 621
        mov  eax,[eax]
622
 
623
        cmp  eax,[application_table_status]
624
        jne  apptsl1
625
        mov  [application_table_status],0
626
      apptsl1:
627
 
628
        pop  eax
629
 
630
        ret
631
 
632
 
633
 
634
sys_resize_app_memory:
635
        ; eax = 1 - resize
636
        ;     ebx = new amount of memory
637
 
638
        cmp    eax,1
4 poddubny 639
        jne    .no_application_mem_resize
1 ha 640
 
164 serge 641
        stdcall new_mem_resize, ebx
642
        mov [esp+36], eax
643
        ret
1 ha 644
 
164 serge 645
.no_application_mem_resize:
1 ha 646
        ret
647
 
648
 
649
 
650
get_app_params:
651
 
652
    push eax
653
 
654
    cmp  [0x90000+6],word '00'
655
    jne  no_00_header
656
 
657
    mov  eax,[0x90000+12]
658
    mov  [app_start],eax
659
    mov  eax,[0x90000+16]
660
    mov  [app_i_end],eax
661
    mov  eax,[0x90000+20]
662
    mov  [app_mem],eax
133 diamond 663
; \begin{diamond}[20.08.2006]
664
; sanity check (functions 19,58 load app_i_end bytes and that must
665
; fit in allocated memory to prevent kernel faults)
666
    cmp  eax,[app_i_end]
667
    jb   no_01_header
668
; \end{diamond}[20.08.2006]
1 ha 669
    shr  eax,1
670
    sub  eax,0x10
671
    mov  [app_esp],eax
672
    mov  eax,[0x90000+24]
673
    mov  [app_i_param],eax
674
    mov  [app_i_icon],dword 0
675
 
676
    pop  eax
133 diamond 677
    clc
1 ha 678
    ret
679
 
680
  no_00_header:
681
 
682
 
683
    cmp  [0x90000+6],word '01'
684
    jne  no_01_header
685
 
686
    mov  eax,[0x90000+12]
687
    mov  [app_start],eax
688
    mov  eax,[0x90000+16]
689
    mov  [app_i_end],eax
690
    mov  eax,[0x90000+20]
691
    mov  [app_mem],eax
133 diamond 692
; \begin{diamond}[20.08.2006]
693
    cmp  eax,[app_i_end]
694
    jb   no_01_header
695
; \end{diamond}[20.08.2006]
1 ha 696
    mov  eax,[0x90000+24]
697
    mov  [app_esp],eax
698
    mov  eax,[0x90000+28]
699
    mov  [app_i_param],eax
700
    mov  eax,[0x90000+32]
701
    mov  [app_i_icon],eax
702
 
703
    pop  eax
133 diamond 704
    clc
1 ha 705
    ret
706
 
707
   no_01_header:
708
 
709
    pop  eax
133 diamond 710
    stc
1 ha 711
    ret
712
 
713
 
714
uglobal
715
  new_process_place  dd  0x0
716
  app_start    dd  0x0
717
  app_i_end    dd  0x0
718
  app_mem      dd  0x0
719
  app_esp      dd  0x0
720
  app_i_param  dd  0x0
721
  app_i_icon   dd  0x0
164 serge 722
;  app_mem_pos  dd  0x0
5 halyavin 723
  appl_path        dd 0x0
164 serge 724
  appl_path_size   dd 0x0
1 ha 725
endg
726
 
727
 
728
sys_threads:
729
 
730
; eax=1 create thread
731
;
732
;   ebx=thread start
733
;   ecx=thread stack value
734
;
735
; on return : eax = pid
736
jmp new_sys_threads
737
 
738
iglobal
739
  process_terminating   db 'K : Process - terminating',13,10,0
740
  process_terminated    db 'K : Process - done',13,10,0
741
endg
742
 
743
 
744
terminate: ; terminate application
745
    push   esi
746
    mov    esi,process_terminating
747
    call   sys_msg_board_str
748
    pop    esi
749
 
40 halyavin 750
@@:
1 ha 751
    cli
752
    cmp   [application_table_status],0
753
    je    term9
754
    sti
755
    call  change_task
40 halyavin 756
    jmp   @b
1 ha 757
  term9:
758
 
759
    call  set_application_table_status
164 serge 760
 
1 ha 761
    mov    eax,esi
762
 
164 serge 763
    pushad
764
    shl   eax,8
765
    mov   eax,[PROC_BASE+eax+0xB8]
766
    stdcall destroy_app_space, eax
767
    popad
768
 
769
    cmp   [fpu_owner],esi   ; if user fpu last -> fpu user = 1
1 ha 770
    jne   fpu_ok_1
164 serge 771
    mov   [fpu_owner],1
1 ha 772
  fpu_ok_1:
773
 
774
    mov   [0xf400],byte 0           ; empty keyboard buffer
775
    mov   [0xf500],byte 0           ; empty button buffer
776
 
777
 
92 diamond 778
; remove defined hotkeys
779
        mov     eax, hotkey_list
780
.loop:
781
        cmp     [eax+8], esi
782
        jnz     .cont
783
        mov     ecx, [eax]
784
        jecxz   @f
785
        push    dword [eax+12]
786
        pop     dword [ecx+12]
787
@@:
788
        mov     ecx, [eax+12]
789
        push    dword [eax]
790
        pop     dword [ecx]
791
        xor     ecx, ecx
792
        mov     [eax], ecx
793
        mov     [eax+4], ecx
794
        mov     [eax+8], ecx
795
        mov     [eax+12], ecx
796
.cont:
797
        add     eax, 16
798
        cmp     eax, hotkey_list+256*16
799
        jb      .loop
800
; remove hotkeys in buffer
801
        mov     eax, hotkey_buffer
802
.loop2:
803
        cmp     [eax], esi
804
        jnz     .cont2
805
        and     dword [eax+4], 0
806
        and     dword [eax], 0
807
.cont2:
808
        add     eax, 8
809
        cmp     eax, hotkey_buffer+120*8
810
        jb      .loop2
811
 
1 ha 812
    mov   ecx,esi                 ; remove buttons
813
  bnewba2:
814
    mov   edi,[0xfe88]
815
    mov   eax,edi
816
    cld
817
    movzx ebx,word [edi]
818
    inc   bx
819
  bnewba:
820
    dec   bx
821
    jz    bnmba
822
    add   eax,0x10
823
    cmp   cx,[eax]
824
    jnz   bnewba
825
    pusha
826
    mov   ecx,ebx
827
    inc   ecx
828
    shl   ecx,4
829
    mov   ebx,eax
830
    add   eax,0x10
831
    call  memmove
832
    dec   dword [edi]
833
    popa
834
    jmp   bnewba2
835
  bnmba:
836
 
837
    pusha     ; save window coordinates for window restoring
838
    cld
839
    shl   esi,5
840
    add   esi,window_data
114 mikedld 841
    mov   eax,[esi+WDATA.box.left]
102 poddubny 842
    mov   [dlx],eax
114 mikedld 843
    add   eax,[esi+WDATA.box.width]
102 poddubny 844
    mov   [dlxe],eax
114 mikedld 845
    mov   eax,[esi+WDATA.box.top]
102 poddubny 846
    mov   [dly],eax
114 mikedld 847
    add   eax,[esi+WDATA.box.height]
102 poddubny 848
    mov   [dlye],eax
1 ha 849
 
142 diamond 850
    xor   eax, eax
851
    mov   [esi+WDATA.box.left],eax
852
    mov   [esi+WDATA.box.width],eax
114 mikedld 853
    mov   [esi+WDATA.box.top],eax
142 diamond 854
    mov   [esi+WDATA.box.height],eax
115 poddubny 855
    mov   [esi+WDATA.cl_workarea],eax
856
    mov   [esi+WDATA.cl_titlebar],eax
857
    mov   [esi+WDATA.cl_frames],eax
858
    mov   dword [esi+WDATA.reserved],eax ; clear all flags: wstate, redraw, wdrawn
102 poddubny 859
    lea   edi, [esi-window_data+draw_data]
1 ha 860
    mov   ecx,32/4
861
    rep   stosd
862
    popa
863
 
40 halyavin 864
; debuggee test
865
    pushad
866
    mov  edi, esi
867
    shl  edi, 5
115 poddubny 868
    mov  eax, [0x80000+edi*8+APPDATA.debugger_slot]
40 halyavin 869
    test eax, eax
870
    jz   .nodebug
871
    push 8
872
    pop  ecx
115 poddubny 873
    push dword [0x3000+edi+TASKDATA.pid]   ; PID
40 halyavin 874
    push 2
875
    call debugger_notify
876
    pop  ecx
877
    pop  ecx
878
.nodebug:
879
    popad
880
 
1 ha 881
    pusha         ; at 0x80000+
882
    mov   edi,esi
883
    shl   edi,8
884
    add   edi,0x80000
885
    mov   ecx,256/4
886
    xor   eax, eax
887
    rep   stosd
888
    popa
889
 
890
    pusha          ; name to spaces
891
    mov   edi,esi
892
    shl   edi,8
115 poddubny 893
    add   edi,0x80000+APPDATA.app_name
1 ha 894
    mov   ecx,11
895
    mov   eax,' '
896
    rep   stosb
897
    popa
898
 
899
 
102 poddubny 900
  ; activate window
901
        movzx  eax, word [0xC000 + esi*2]
902
        cmp    eax, [0x3004]
903
        jne    .dont_activate
904
        pushad
905
 .check_next_window:
906
        dec    eax
907
        cmp    eax, 1
908
        jbe    .nothing_to_activate
909
        lea    esi, [0xc400+eax*2]
910
        movzx  edi, word [esi]               ; edi = process
911
        shl    edi, 5
115 poddubny 912
        cmp    [0x3000 + edi + TASKDATA.state], byte 9  ; skip dead slots
102 poddubny 913
        je     .check_next_window
914
        add    edi, window_data
154 diamond 915
; \begin{diamond}[19.09.2006]
916
; skip minimized windows
164 serge 917
        test   [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
918
        jnz    .check_next_window
154 diamond 919
; \end{diamond}
102 poddubny 920
        call   waredraw
921
 .nothing_to_activate:
922
        popad
923
 .dont_activate:
924
 
92 diamond 925
        push    esi     ; remove hd1 & cd & flp reservation
926
        shl     esi, 5
118 diamond 927
        mov     esi, [esi+0x3000+TASKDATA.pid]
92 diamond 928
        cmp     [hd1_status], esi
929
        jnz     @f
930
        mov     [hd1_status], 0
931
@@:
932
        cmp     [cd_status], esi
933
        jnz     @f
934
        mov     [cd_status], 0
935
@@:
936
        cmp     [flp_status], esi
937
        jnz     @f
938
        mov     [flp_status], 0
939
@@:
940
        pop     esi
1 ha 941
 
942
    pusha ; remove all irq reservations
92 diamond 943
    mov   eax,esi
115 poddubny 944
    shl   eax, 5
118 diamond 945
    mov   eax,[eax+0x3000+TASKDATA.pid]
1 ha 946
    mov   edi,irq_owner
947
    mov   ecx,16
948
  newirqfree:
92 diamond 949
    scasd
1 ha 950
    jne   nofreeirq
92 diamond 951
    mov   [edi-4],dword 0
1 ha 952
  nofreeirq:
953
    loop   newirqfree
954
    popa
955
 
956
 
957
    pusha                     ; remove all port reservations
958
    mov   edx,esi
115 poddubny 959
    shl   edx, 5
1 ha 960
    add   edx,0x3000
115 poddubny 961
    mov   edx,[edx+TASKDATA.pid]
1 ha 962
 
963
  rmpr0:
964
 
965
    mov   esi,[0x2d0000]
966
 
967
    cmp   esi,0
968
    je    rmpr9
969
 
970
  rmpr3:
971
 
972
    mov   edi,esi
973
    shl   edi,4
974
    add   edi,0x2d0000
975
 
976
    cmp   edx,[edi]
977
    je    rmpr4
978
 
979
    dec   esi
980
    jnz   rmpr3
981
 
982
    jmp   rmpr9
983
 
984
  rmpr4:
985
 
986
    mov   ecx,256
987
    sub   ecx,esi
988
    shl   ecx,4
989
 
990
    mov   esi,edi
991
    add   esi,16
992
    cld
993
    rep   movsb
994
 
995
    dec   dword [0x2d0000]
996
 
997
    jmp   rmpr0
998
 
999
  rmpr9:
1000
 
1001
    popa
1002
    mov  edi,esi         ; do not run this process slot
6 poddubny 1003
    shl  edi, 5
115 poddubny 1004
    mov  [edi+0x3000 + TASKDATA.state],byte 9
40 halyavin 1005
; debugger test - terminate all debuggees
1006
    mov  eax, 2
115 poddubny 1007
    mov  ecx, 0x80000+2*0x100+APPDATA.debugger_slot
40 halyavin 1008
.xd0:
1009
    cmp  eax, [0x3004]
1010
    ja   .xd1
1011
    cmp  dword [ecx], esi
1012
    jnz  @f
1013
    and  dword [ecx], 0
1014
    pushad
1015
    xchg eax, ebx
1016
    mov  eax, 2
1017
    call sys_system
1018
    popad
1019
@@:
1020
    inc  eax
1021
    add  ecx, 0x100
1022
    jmp  .xd0
1023
.xd1:
1 ha 1024
;    call  systest
1025
    sti  ; .. and life goes on
1026
 
112 poddubny 1027
    mov   eax, [dlx]
1028
    mov   ebx, [dly]
1029
    mov   ecx, [dlxe]
1030
    mov   edx, [dlye]
1 ha 1031
    call  calculatescreen
1032
    xor   eax, eax
1033
    xor   esi, esi
1034
    call  redrawscreen
1035
 
1036
    mov   [0xfff4],byte 0  ; no mouse background
1037
    mov   [0xfff5],byte 0  ; draw mouse
1038
 
1039
    mov   [application_table_status],0
1040
    mov   esi,process_terminated
1041
    call  sys_msg_board_str
1042
 
1043
    ret
1044
 
1045
iglobal
1046
  boot_sched_1    db   'Building gdt tss pointer',0
8 poddubny 1047
  boot_sched_2    db   'Building IDT table',0
1 ha 1048
endg
1049
 
1050
 
1051
build_scheduler:
1052
 
1053
        mov    esi,boot_sched_1
1054
        call   boot_log
1055
        call   build_process_gdt_tss_pointer
1056
 
8 poddubny 1057
        mov    esi,boot_sched_2
1 ha 1058
        call   boot_log
1059
        call   build_interrupt_table
1060
 
1061
        ret
1062