Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
431 serge 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
709 diamond 3
;; Copyright (C) KolibriOS team 2004-2008. All rights reserved. ;;
431 serge 4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;;                                                              ;;
7
;;  MenuetOS process management, protected ring3                ;;
8
;;                                                              ;;
9
;;  Distributed under GPL. See file COPYING for details.        ;;
10
;;  Copyright 2003 Ville Turjanmaa                              ;;
11
;;                                                              ;;
12
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1 ha 13
 
593 mikedld 14
$Revision: 1074 $
15
 
16
 
1056 Galkov 17
align 4 ;3A08
1 ha 18
build_interrupt_table:
1056 Galkov 19
        mov     edi, idts
20
        mov     esi, sys_int
21
        mov     ecx, 0x40
22
        mov     eax, (10001110b shl 24) + os_code
23
  @@:   movsw   ;low word of code-entry
24
        stosd   ;interrupt gate type : os_code selector
25
        movsw   ;high word of code-entry
26
        loop    @b
27
        movsd   ;copy low  dword of trap gate for int 0x40
28
        movsd   ;copy high dword of trap gate for int 0x40
29
        lidt    [esi]
30
        ret
1 ha 31
 
1056 Galkov 32
iglobal
33
  align 4
34
  sys_int:
35
    ;exception handlers addresses (for interrupt gate construction)
36
        dd      e0,e1,e2,e3,e4,e5,e6,except_7
37
        dd      e8,e9,e10,e11,e12,e13,page_fault_exc,e15
38
        dd      e16, e17,e18, e19
39
        times   12 dd unknown_interrupt ;int_20..int_31
164 serge 40
 
1056 Galkov 41
    ;interrupt handlers addresses (for interrupt gate construction)
42
        dd      irq0, irq_serv.irq_1, irq_serv.irq_2
43
    if  USE_COM_IRQ
44
        dd      irq_serv.irq_3, irq_serv.irq_4
45
    else
46
        dd      p_irq3, p_irq4 ;??? нестыковка
47
    end if
48
        dd      irq_serv.irq_5,  p_irq6,          irq_serv.irq_7
49
        dd      irq_serv.irq_8,  irq_serv.irq_9,  irq_serv.irq_10
50
        dd      irq_serv.irq_11, irq_serv.irq_12, irqD,p_irq14,p_irq15
51
        times   16 dd unknown_interrupt ;int_0x30..int_0x3F
1 ha 52
 
1056 Galkov 53
    ;int_0x40 gate trap (for directly copied)
54
        dw      i40 and 0xFFFF, os_code, 11101111b shl 8, i40 shr 16
656 mikedld 55
 
1056 Galkov 56
  idtreg: ; data for LIDT instruction (must be immediately below sys_int data)
57
        dw      2*($-sys_int-4)-1
58
        dd      idts ;0x8000B100
59
        dw      0    ;просто выравнивание
656 mikedld 60
 
1056 Galkov 61
  msg_fault_sel dd  msg_exc_8,msg_exc_u,msg_exc_a,msg_exc_b
62
                dd  msg_exc_c,msg_exc_d,msg_exc_e
164 serge 63
 
1056 Galkov 64
  msg_exc_8     db "Double fault", 0
65
  msg_exc_u     db "Undefined Exception", 0
66
  msg_exc_a     db "Invalid TSS", 0
67
  msg_exc_b     db "Segment not present", 0
68
  msg_exc_c     db "Stack fault", 0
69
  msg_exc_d     db "General protection fault", 0
70
  msg_exc_e     db "Page fault", 0
1 ha 71
 
1056 Galkov 72
  msg_sel_ker   db "kernel", 0
73
  msg_sel_app   db "application", 0
1 ha 74
 
75
endg
76
 
1056 Galkov 77
macro save_ring3_context {
78
        pushad
40 halyavin 79
}
1056 Galkov 80
macro restore_ring3_context {
81
        popad
40 halyavin 82
}
1056 Galkov 83
macro exc_wo_code [num] {
8 poddubny 84
  e#num :
1056 Galkov 85
        save_ring3_context
86
        mov     bl, num
87
        jmp     exc_c
88
} exc_wo_code   0,1,2,3,4,5,6,15,16,19
1 ha 89
 
1056 Galkov 90
macro exc_w_code [num] {
22 poddubny 91
  e#num :
1056 Galkov 92
        add     esp, 4
93
        save_ring3_context
94
        mov     bl, num
95
        jmp     exc_c
96
} exc_w_code    8,9,10,11,12,13,17,18
22 poddubny 97
 
98
 
1056 Galkov 99
uglobal
100
  pf_err_code   dd ?
101
endg
1 ha 102
 
1056 Galkov 103
page_fault_exc:
104
        pop     [pf_err_code]  ;действительно до следующего #PF
105
        save_ring3_context
106
        mov     bl,14
107
exc_c:                         ;исключение
108
; Фрэйм стека при исключении/прерывании из 3-го кольца + pushad (т.е., именно здесь)
109
  reg_ss        equ esp+0x30
110
  reg_esp3      equ esp+0x2C
111
  reg_eflags    equ esp+0x28
112
  reg_cs3       equ esp+0x24
113
  reg_eip       equ esp+0x20
114
 ; это фрэйм от pushad
115
  reg_eax       equ esp+0x1C
116
  reg_ecx       equ esp+0x18
117
  reg_edx       equ esp+0x14
118
  reg_ebx       equ esp+0x10
119
  reg_esp0      equ esp+0x0C
120
  reg_ebp       equ esp+0x08
121
  reg_esi       equ esp+0x04
122
  reg_edi       equ esp+0x00
123
 
124
        Mov     ds,ax,app_data  ; загрузим правильные значения
125
        mov     es,ax           ; в сегментные регистры
126
        cld                     ; и приводим DF к стандарту
1074 Galkov 127
        movzx   ebx,bl
709 diamond 128
; redirect to V86 manager? (EFLAGS & 0x20000) != 0?
1056 Galkov 129
        test    byte[reg_eflags+2],2
130
        jnz     v86_exc_c
131
        cmp     bl,14           ; #PF
1074 Galkov 132
        jne     @f
1056 Galkov 133
        call    page_fault_handler
1074 Galkov 134
  @@:   mov     esi, [current_slot]
135
        btr     [esi+APPDATA.except_mask], ebx
136
        jnc     @f
137
        mov     eax,[esi+APPDATA.exc_handler]
138
        test    eax, eax
1056 Galkov 139
        jnz     IRetToUserHook
1074 Galkov 140
  @@:   cli
1056 Galkov 141
        mov     eax, [esi+APPDATA.debugger_slot]
142
        test    eax, eax
143
        jnz     .debug
144
        sti
40 halyavin 145
; not debuggee => say error and terminate
1056 Galkov 146
        call    show_error_parameters ;; only ONE using, inline ???
147
       ;mov     edx, [TASK_BASE]
148
        mov     [edx + TASKDATA.state], byte 4 ; terminate
149
        jmp     change_task     ; stack - here it does not matter at all
40 halyavin 150
.debug:
151
; we are debugged process, notify debugger and suspend ourself
152
; eax=debugger PID
1056 Galkov 153
        cmp     bl,1            ; #DB
154
        je      debug_ex
1074 Galkov 155
        mov     edx, ebx        ; debug_message data=Number_Of_Exception
1056 Galkov 156
        mov     ecx,1           ; debug_message code=other_exception
157
        jmp     debug_ex.notify ; notify debugger and suspend ourself
1 ha 158
 
1056 Galkov 159
IRetToUserHook:
160
        xchg    eax, [reg_eip]
1074 Galkov 161
        sub     dword[reg_esp3], 8
1056 Galkov 162
        mov     edi, [reg_esp3]
163
        stosd
1074 Galkov 164
        mov     [edi], ebx
1056 Galkov 165
        restore_ring3_context
166
unknown_interrupt:
167
        iretd
1 ha 168
 
658 Ghost 169
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
1 ha 170
show_error_parameters:
1056 Galkov 171
        mov     edx,[TASK_BASE] ;not scratched below
172
        DEBUGF  1, "K : Process - forced terminate PID: %x\n", [edx+TASKDATA.pid]
173
        cmp     bl, 0x08
174
        jb      .l0
175
        cmp     bl, 0x0e
176
        jbe     .l1
177
  .l0:  mov     bl, 0x09
1074 Galkov 178
  .l1:  mov     eax,[msg_fault_sel+ebx*4 - 0x08*4]
1056 Galkov 179
        DEBUGF  1, "K : %s\n", eax
180
        mov     eax, [reg_cs3+4]
181
        mov     edi, msg_sel_app
182
        mov     ebx, [reg_esp3+4]
183
        cmp     eax, app_code
184
        je      @f
185
        mov     edi, msg_sel_ker
186
        mov     ebx, [reg_esp0+4]
187
    @@: DEBUGF  1, "K : EAX : %x EBX : %x ECX : %x\n", [reg_eax+4], [reg_ebx+4], [reg_ecx+4]
188
        DEBUGF  1, "K : EDX : %x ESI : %x EDI : %x\n", [reg_edx+4], [reg_esi+4], [reg_edi+4]
189
        DEBUGF  1, "K : EBP : %x EIP : %x ESP : %x\n", [reg_ebp+4], [reg_eip+4], ebx
190
        DEBUGF  1, "K : Flags : %x CS : %x (%s)\n", [reg_eflags+4], eax, edi
191
        ret
658 Ghost 192
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
164 serge 193
 
1056 Galkov 194
  restore  reg_ss
195
  restore  reg_esp3
196
  restore  reg_eflags
197
  restore  reg_cs
198
  restore  reg_eip
199
  restore  reg_eax
200
  restore  reg_ecx
201
  restore  reg_edx
202
  restore  reg_ebx
203
  restore  reg_esp0
204
  restore  reg_ebp
205
  restore  reg_esi
206
  restore  reg_edi
16 poddubny 207
 
6 poddubny 208
; irq1  ->  hid/keyboard.inc
1056 Galkov 209
macro irqh [num] {
8 poddubny 210
  p_irq#num :
1056 Galkov 211
        mov     edi, num
212
        jmp     irqhandler
8 poddubny 213
}
1 ha 214
 
215
 
11 poddubny 216
 
217
p_irq6:
980 diamond 218
        save_ring3_context
219
        mov     ax, app_data  ;os_data
220
        mov     ds, ax
221
        mov     es, ax
982 diamond 222
        mov     edi, 6
980 diamond 223
        cmp     [v86_irqhooks+edi*8], 0
224
        jnz     v86_irq2
225
        call    fdc_irq
226
        call    ready_for_next_irq
227
        restore_ring3_context
228
        iret
15 poddubny 229
 
230
 
160 diamond 231
p_irq14:
1056 Galkov 232
        save_ring3_context
233
        mov     ax, app_data  ;os_data
234
        mov     ds, ax
235
        mov     es, ax
236
        mov     edi, 14
237
        cmp     [v86_irqhooks+edi*8], 0
238
        jnz     v86_irq2
239
;       mov     byte [BOOT_VAR + 0x48E], 0xFF
240
        call    [irq14_func]
241
        call    ready_for_next_irq_1
242
        restore_ring3_context
243
        iret
160 diamond 244
p_irq15:
1056 Galkov 245
        save_ring3_context
246
        mov     ax, app_data  ;os_data
247
        mov     ds, ax
248
        mov     es, ax
249
        mov     edi, 15
250
        cmp     [v86_irqhooks+edi*8], 0
251
        jnz     v86_irq2
252
;       mov     byte [BOOT_VAR + 0x48E], 0xFF
253
        call    [irq15_func]
254
        call    ready_for_next_irq_1
255
        restore_ring3_context
256
        iret
160 diamond 257
 
33 mario79 258
ready_for_next_irq:
1056 Galkov 259
        mov     [check_idle_semaphore],5
260
        mov     al, 0x20
261
        out     0x20, al
262
        ret
33 mario79 263
 
264
ready_for_next_irq_1:
1056 Galkov 265
        mov     [check_idle_semaphore],5
266
        mov     al, 0x20
267
        out     0xa0,al
268
        out     0x20, al
269
        ret
33 mario79 270
 
6 poddubny 271
irqD:
1056 Galkov 272
        push  eax
273
        mov   al,0
274
        out   0xf0,al
275
        mov   al,0x20
276
        out   0xa0,al
277
        out   0x20,al
278
        pop   eax
279
        iret
164 serge 280
 
1 ha 281
 
1056 Galkov 282
irqh 2,3,4,5,7,8,9,10,11
40 halyavin 283
 
1 ha 284
irqhandler:
285
 
1056 Galkov 286
     mov    esi,edi          ; 1
287
     shl    esi,6            ; 1
1 ha 288
     add    esi,irq00read    ; 1
1056 Galkov 289
     shl    edi,12           ; 1
381 serge 290
     add    edi,IRQ_SAVE
75 diamond 291
     mov    ecx,16
1 ha 292
 
293
   irqnewread:
75 diamond 294
     dec    ecx
295
     js     irqover
1 ha 296
 
1056 Galkov 297
     movzx  edx, word [esi]        ; 2+
1 ha 298
 
1056 Galkov 299
     test   edx, edx               ; 1
1 ha 300
     jz     irqover
301
 
302
 
1056 Galkov 303
     mov    ebx, [edi]             ; address of begin of buffer in edi      ; + 0x0 dword - data size
304
     mov    eax, 4000                                                       ; + 0x4 dword - data begin offset
759 Rus 305
     cmp    ebx, eax
1 ha 306
     je     irqfull
1056 Galkov 307
     add    ebx, [edi + 0x4]       ; add data size to data begin offset
308
     cmp    ebx, eax               ; if end of buffer, begin cycle again
759 Rus 309
     jb     @f
1 ha 310
 
759 Rus 311
     xor    ebx, ebx
1 ha 312
 
759 Rus 313
  @@:
314
     add    ebx, edi
1056 Galkov 315
     movzx  eax, byte[esi + 3]     ; get type of data being received 1 - byte, 2 - word
759 Rus 316
     dec    eax
317
     jz     irqbyte
318
     dec    eax
319
     jnz    noirqword
1 ha 320
 
759 Rus 321
     in     ax,dx
1056 Galkov 322
     cmp    ebx, 3999              ; check for address odd in the end of buffer
759 Rus 323
     jne    .odd
324
     mov    [ebx + 0x10], ax
325
     jmp    .add_size
326
  .odd:
1056 Galkov 327
     mov    [ebx + 0x10], al       ; I could make mistake here :)
759 Rus 328
     mov    [edi + 0x10], ah
329
  .add_size:
330
     add    dword [edi], 2
331
     jmp    nextport
1 ha 332
 
333
 
759 Rus 334
  irqbyte:
335
     in     al,dx
336
     mov    [ebx + 0x10],al
337
     inc    dword [edi]
338
  nextport:
1 ha 339
     add    esi,4
340
     jmp    irqnewread
341
 
759 Rus 342
 
1 ha 343
   noirqword:
344
   irqfull:
345
   irqover:
346
 
347
     ret
348
 
349
 
350
 
351
set_application_table_status:
1056 Galkov 352
        push eax
1 ha 353
 
1056 Galkov 354
        mov  eax,[CURRENT_TASK]
355
        shl  eax, 5
356
        add  eax,CURRENT_TASK+TASKDATA.pid
357
        mov  eax,[eax]
1 ha 358
 
1056 Galkov 359
        mov  [application_table_status],eax
1 ha 360
 
1056 Galkov 361
        pop  eax
1 ha 362
 
1056 Galkov 363
        ret
1 ha 364
 
365
 
366
clear_application_table_status:
1056 Galkov 367
        push eax
1 ha 368
 
1056 Galkov 369
        mov  eax,[CURRENT_TASK]
370
        shl  eax, 5
371
        add  eax,CURRENT_TASK+TASKDATA.pid
372
        mov  eax,[eax]
1 ha 373
 
1056 Galkov 374
        cmp  eax,[application_table_status]
375
        jne  apptsl1
376
        mov  [application_table_status],0
1 ha 377
      apptsl1:
378
 
1056 Galkov 379
        pop  eax
1 ha 380
 
1056 Galkov 381
        ret
1 ha 382
 
383
sys_resize_app_memory:
1056 Galkov 384
        ; eax = 1 - resize
385
        ;     ebx = new amount of memory
1 ha 386
 
1056 Galkov 387
        cmp    eax,1
388
        jne    .no_application_mem_resize
1 ha 389
 
1056 Galkov 390
        stdcall new_mem_resize, ebx
391
        mov [esp+36], eax
392
        ret
1 ha 393
 
164 serge 394
.no_application_mem_resize:
1056 Galkov 395
        ret
1 ha 396
 
397
sys_threads:
398
 
399
; eax=1 create thread
400
;
401
;   ebx=thread start
402
;   ecx=thread stack value
403
;
404
; on return : eax = pid
405
jmp new_sys_threads
406
 
407
iglobal
1056 Galkov 408
;  process_terminating  db 'K : Process - terminating',13,10,0
409
;  process_terminated   db 'K : Process - done',13,10,0
410
  msg_obj_destroy       db 'K : destroy app object',13,10,0
1 ha 411
endg
412
 
329 serge 413
; param
414
;  esi= slot
1 ha 415
 
416
terminate: ; terminate application
417
 
1056 Galkov 418
           .slot equ esp   ;locals
329 serge 419
 
1056 Galkov 420
           push   esi      ;save .slot
334 serge 421
 
1056 Galkov 422
           shl esi, 8
423
           cmp [SLOT_BASE+esi+APPDATA.dir_table], 0
424
           jne @F
425
           pop    esi
426
           shl    esi, 5
427
           mov    [CURRENT_TASK+esi+TASKDATA.state], 9
428
           ret
334 serge 429
@@:
1056 Galkov 430
           ;mov    esi,process_terminating
431
           ;call   sys_msg_board_str
40 halyavin 432
@@:
1056 Galkov 433
           cli
434
           cmp   [application_table_status],0
435
           je    term9
436
           sti
437
           call  change_task
438
           jmp   @b
329 serge 439
term9:
1056 Galkov 440
           call  set_application_table_status
1 ha 441
 
709 diamond 442
; if the process is in V86 mode...
1056 Galkov 443
        mov     eax, [.slot]
444
        shl     eax, 8
445
        mov     esi, [eax+SLOT_BASE+APPDATA.pl0_stack]
446
        add     esi, RING0_STACK_SIZE
447
        cmp     [eax+SLOT_BASE+APPDATA.saved_esp0], esi
448
        jz      .nov86
709 diamond 449
; ...it has page directory for V86 mode
1056 Galkov 450
        mov     esi, [eax+SLOT_BASE+APPDATA.saved_esp0]
451
        mov     ecx, [esi+4]
452
        mov     [eax+SLOT_BASE+APPDATA.dir_table], ecx
709 diamond 453
; ...and I/O permission map for V86 mode
1056 Galkov 454
        mov     ecx, [esi+12]
455
        mov     [eax+SLOT_BASE+APPDATA.io_map], ecx
456
        mov     ecx, [esi+8]
457
        mov     [eax+SLOT_BASE+APPDATA.io_map+4], ecx
709 diamond 458
.nov86:
459
 
1056 Galkov 460
           mov esi, [.slot]
461
           shl esi,8
462
           add esi, SLOT_BASE+APP_OBJ_OFFSET
329 serge 463
@@:
1056 Galkov 464
           mov eax, [esi+APPOBJ.fd]
465
           test eax, eax
466
           jz @F
334 serge 467
 
1056 Galkov 468
           cmp eax, esi
469
           je @F
164 serge 470
 
1056 Galkov 471
           push esi
472
           call [eax+APPOBJ.destroy]
473
           DEBUGF 1,"%s",msg_obj_destroy
474
           pop esi
475
           jmp @B
329 serge 476
@@:
1056 Galkov 477
           mov eax, [.slot]
478
           shl eax, 8
479
           mov eax,[SLOT_BASE+eax+APPDATA.dir_table]
480
           stdcall destroy_app_space, eax
1 ha 481
 
1056 Galkov 482
           mov esi, [.slot]
483
           cmp [fpu_owner],esi   ; if user fpu last -> fpu user = 1
484
           jne @F
164 serge 485
 
1056 Galkov 486
           mov [fpu_owner],1
487
           mov eax, [256+SLOT_BASE+APPDATA.fpu_state]
488
           clts
489
           bt [cpu_caps], CAPS_SSE
490
           jnc .no_SSE
491
           fxrstor [eax]
492
           jmp @F
203 serge 493
.no_SSE:
1056 Galkov 494
           fnclex
495
           frstor [eax]
357 serge 496
@@:
203 serge 497
 
1056 Galkov 498
    mov   [KEY_COUNT],byte 0           ; empty keyboard buffer
499
    mov   [BTN_COUNT],byte 0           ; empty button buffer
1 ha 500
 
501
 
92 diamond 502
; remove defined hotkeys
1056 Galkov 503
        mov     eax, hotkey_list
92 diamond 504
.loop:
1056 Galkov 505
        cmp     [eax+8], esi
506
        jnz     .cont
507
        mov     ecx, [eax]
508
        jecxz   @f
509
        push    dword [eax+12]
510
        pop     dword [ecx+12]
92 diamond 511
@@:
1056 Galkov 512
        mov     ecx, [eax+12]
513
        push    dword [eax]
514
        pop     dword [ecx]
515
        xor     ecx, ecx
516
        mov     [eax], ecx
517
        mov     [eax+4], ecx
518
        mov     [eax+8], ecx
519
        mov     [eax+12], ecx
92 diamond 520
.cont:
1056 Galkov 521
        add     eax, 16
522
        cmp     eax, hotkey_list+256*16
523
        jb      .loop
92 diamond 524
; remove hotkeys in buffer
1056 Galkov 525
        mov     eax, hotkey_buffer
92 diamond 526
.loop2:
1056 Galkov 527
        cmp     [eax], esi
528
        jnz     .cont2
529
        and     dword [eax+4], 0
530
        and     dword [eax], 0
92 diamond 531
.cont2:
1056 Galkov 532
        add     eax, 8
533
        cmp     eax, hotkey_buffer+120*8
534
        jb      .loop2
92 diamond 535
 
1056 Galkov 536
    mov   ecx,esi                 ; remove buttons
1 ha 537
  bnewba2:
381 serge 538
    mov   edi,[BTN_ADDR]
1 ha 539
    mov   eax,edi
540
    cld
541
    movzx ebx,word [edi]
542
    inc   bx
543
  bnewba:
544
    dec   bx
1056 Galkov 545
    jz    bnmba
1 ha 546
    add   eax,0x10
547
    cmp   cx,[eax]
548
    jnz   bnewba
549
    pusha
550
    mov   ecx,ebx
551
    inc   ecx
552
    shl   ecx,4
553
    mov   ebx,eax
554
    add   eax,0x10
555
    call  memmove
556
    dec   dword [edi]
557
    popa
558
    jmp   bnewba2
559
  bnmba:
560
 
561
    pusha     ; save window coordinates for window restoring
562
    cld
563
    shl   esi,5
564
    add   esi,window_data
114 mikedld 565
    mov   eax,[esi+WDATA.box.left]
102 poddubny 566
    mov   [dlx],eax
114 mikedld 567
    add   eax,[esi+WDATA.box.width]
102 poddubny 568
    mov   [dlxe],eax
114 mikedld 569
    mov   eax,[esi+WDATA.box.top]
102 poddubny 570
    mov   [dly],eax
114 mikedld 571
    add   eax,[esi+WDATA.box.height]
102 poddubny 572
    mov   [dlye],eax
1 ha 573
 
142 diamond 574
    xor   eax, eax
575
    mov   [esi+WDATA.box.left],eax
576
    mov   [esi+WDATA.box.width],eax
114 mikedld 577
    mov   [esi+WDATA.box.top],eax
142 diamond 578
    mov   [esi+WDATA.box.height],eax
115 poddubny 579
    mov   [esi+WDATA.cl_workarea],eax
580
    mov   [esi+WDATA.cl_titlebar],eax
581
    mov   [esi+WDATA.cl_frames],eax
582
    mov   dword [esi+WDATA.reserved],eax ; clear all flags: wstate, redraw, wdrawn
102 poddubny 583
    lea   edi, [esi-window_data+draw_data]
1 ha 584
    mov   ecx,32/4
585
    rep   stosd
586
    popa
587
 
40 halyavin 588
; debuggee test
589
    pushad
590
    mov  edi, esi
591
    shl  edi, 5
380 serge 592
    mov  eax, [SLOT_BASE+edi*8+APPDATA.debugger_slot]
40 halyavin 593
    test eax, eax
1056 Galkov 594
    jz   .nodebug
40 halyavin 595
    push 8
596
    pop  ecx
1056 Galkov 597
    push dword [CURRENT_TASK+edi+TASKDATA.pid]   ; PID
40 halyavin 598
    push 2
599
    call debugger_notify
600
    pop  ecx
601
    pop  ecx
602
.nodebug:
603
    popad
604
 
1056 Galkov 605
           mov ebx, [.slot]
606
           shl ebx, 8
607
           push ebx
608
           mov ebx,[SLOT_BASE+ebx+APPDATA.pl0_stack]
1 ha 609
 
1056 Galkov 610
           stdcall kernel_free, ebx
1 ha 611
 
1056 Galkov 612
           pop ebx
613
           mov ebx,[SLOT_BASE+ebx+APPDATA.cur_dir]
614
           stdcall kernel_free, ebx
521 diamond 615
 
1056 Galkov 616
           mov edi, [.slot]
617
           shl edi,8
618
           add edi,SLOT_BASE
465 serge 619
 
1056 Galkov 620
           mov eax, [edi+APPDATA.io_map]
621
           cmp eax, (tss._io_map_0-OS_BASE+PG_MAP)
622
           je @F
623
           call free_page
465 serge 624
@@:
1056 Galkov 625
           mov eax, [edi+APPDATA.io_map+4]
626
           cmp eax, (tss._io_map_1-OS_BASE+PG_MAP)
627
           je @F
628
           call free_page
465 serge 629
@@:
1056 Galkov 630
           mov eax, 0x20202020
631
           stosd
632
           stosd
633
           stosd
634
           mov ecx,244/4
635
           xor eax, eax
636
           rep stosd
1 ha 637
 
102 poddubny 638
  ; activate window
1056 Galkov 639
        movzx  eax, word [WIN_STACK + esi*2]
640
        cmp    eax, [TASK_COUNT]
641
        jne    .dont_activate
642
        pushad
102 poddubny 643
 .check_next_window:
1056 Galkov 644
        dec    eax
645
        cmp    eax, 1
646
        jbe    .nothing_to_activate
647
        lea    esi, [WIN_POS+eax*2]
648
        movzx  edi, word [esi]               ; edi = process
649
        shl    edi, 5
650
        cmp    [CURRENT_TASK + edi + TASKDATA.state], byte 9  ; skip dead slots
651
        je     .check_next_window
652
        add    edi, window_data
154 diamond 653
; \begin{diamond}[19.09.2006]
654
; skip minimized windows
1056 Galkov 655
        test   [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
656
        jnz    .check_next_window
154 diamond 657
; \end{diamond}
1056 Galkov 658
        call   waredraw
102 poddubny 659
 .nothing_to_activate:
1056 Galkov 660
        popad
102 poddubny 661
 .dont_activate:
662
 
1056 Galkov 663
        push    esi     ; remove hd1 & cd & flp reservation
664
        shl     esi, 5
665
        mov     esi, [esi+CURRENT_TASK+TASKDATA.pid]
666
        cmp     [hd1_status], esi
667
        jnz     @f
668
        call    free_hd_channel
669
        mov     [hd1_status], 0
92 diamond 670
@@:
1056 Galkov 671
        cmp     [cd_status], esi
672
        jnz     @f
673
        call    free_cd_channel
674
        mov     [cd_status], 0
92 diamond 675
@@:
1056 Galkov 676
        cmp     [flp_status], esi
677
        jnz     @f
678
        mov     [flp_status], 0
92 diamond 679
@@:
1056 Galkov 680
        pop     esi
681
        cmp     [bgrlockpid], esi
682
        jnz     @f
683
        and     [bgrlockpid], 0
684
        mov     [bgrlock], 0
546 diamond 685
@@:
1 ha 686
 
687
    pusha ; remove all irq reservations
92 diamond 688
    mov   eax,esi
115 poddubny 689
    shl   eax, 5
379 serge 690
    mov   eax,[eax+CURRENT_TASK+TASKDATA.pid]
1 ha 691
    mov   edi,irq_owner
774 Rus 692
    xor   ebx, ebx
693
    xor   edx, edx
1 ha 694
  newirqfree:
774 Rus 695
    cmp   [edi + 4 * ebx], eax
1 ha 696
    jne   nofreeirq
1056 Galkov 697
    mov   [edi + 4 * ebx], edx                          ; remove irq reservation
698
    mov   [irq_tab + 4 * ebx], edx                      ; remove irq handler
699
    mov   [irq_rights + 4 * ebx], edx                   ; set access rights to full access
1 ha 700
  nofreeirq:
774 Rus 701
    inc   ebx
702
    cmp   ebx, 16
1056 Galkov 703
    jb    newirqfree
1 ha 704
    popa
705
 
1056 Galkov 706
    pusha                     ; remove all port reservations
1 ha 707
    mov   edx,esi
115 poddubny 708
    shl   edx, 5
379 serge 709
    add   edx,CURRENT_TASK
115 poddubny 710
    mov   edx,[edx+TASKDATA.pid]
1 ha 711
 
712
  rmpr0:
713
 
381 serge 714
    mov   esi,[RESERVED_PORTS]
1 ha 715
 
716
    cmp   esi,0
1056 Galkov 717
    je    rmpr9
1 ha 718
 
719
  rmpr3:
720
 
721
    mov   edi,esi
722
    shl   edi,4
381 serge 723
    add   edi,RESERVED_PORTS
1 ha 724
 
725
    cmp   edx,[edi]
1056 Galkov 726
    je    rmpr4
1 ha 727
 
728
    dec   esi
729
    jnz   rmpr3
730
 
731
    jmp   rmpr9
732
 
733
  rmpr4:
734
 
735
    mov   ecx,256
736
    sub   ecx,esi
737
    shl   ecx,4
738
 
739
    mov   esi,edi
740
    add   esi,16
741
    cld
742
    rep   movsb
743
 
381 serge 744
    dec   dword [RESERVED_PORTS]
1 ha 745
 
746
    jmp   rmpr0
747
 
748
  rmpr9:
749
 
750
    popa
1056 Galkov 751
    mov  edi,esi         ; do not run this process slot
6 poddubny 752
    shl  edi, 5
379 serge 753
    mov  [edi+CURRENT_TASK + TASKDATA.state],byte 9
40 halyavin 754
; debugger test - terminate all debuggees
755
    mov  eax, 2
380 serge 756
    mov  ecx, SLOT_BASE+2*0x100+APPDATA.debugger_slot
40 halyavin 757
.xd0:
379 serge 758
    cmp  eax, [TASK_COUNT]
1056 Galkov 759
    ja   .xd1
40 halyavin 760
    cmp  dword [ecx], esi
761
    jnz  @f
762
    and  dword [ecx], 0
763
    pushad
684 diamond 764
    xchg eax, ecx
765
    mov  ebx, 2
40 halyavin 766
    call sys_system
767
    popad
768
@@:
769
    inc  eax
770
    add  ecx, 0x100
771
    jmp  .xd0
772
.xd1:
1 ha 773
;    call  systest
774
    sti  ; .. and life goes on
775
 
112 poddubny 776
    mov   eax, [dlx]
777
    mov   ebx, [dly]
778
    mov   ecx, [dlxe]
779
    mov   edx, [dlye]
1 ha 780
    call  calculatescreen
781
    xor   eax, eax
782
    xor   esi, esi
783
    call  redrawscreen
784
 
381 serge 785
    mov   [MOUSE_BACKGROUND],byte 0  ; no mouse background
786
    mov   [DONT_DRAW_MOUSE],byte 0  ; draw mouse
1 ha 787
 
788
    mov   [application_table_status],0
506 mikedld 789
    ;mov   esi,process_terminated
790
    ;call  sys_msg_board_str
357 serge 791
    add esp, 4
1 ha 792
    ret
345 serge 793
restore .slot
1 ha 794
 
795
iglobal
1056 Galkov 796
  boot_sched_1    db   'Building gdt tss pointer',0
797
  boot_sched_2    db   'Building IDT table',0
1 ha 798
endg
799
 
800
 
801
build_scheduler:
802
 
1056 Galkov 803
        mov    esi,boot_sched_1
804
        call   boot_log
465 serge 805
  ;      call   build_process_gdt_tss_pointer
1 ha 806
 
465 serge 807
  ;      mov    esi,boot_sched_2
808
  ;      call   boot_log
1 ha 809
 
1056 Galkov 810
        ret