Subversion Repositories Kolibri OS

Rev

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