Subversion Repositories Kolibri OS

Rev

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