Subversion Repositories Kolibri OS

Rev

Rev 1989 | Rev 2089 | 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: 1992 $
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
1992 clevermous 48
        dd      irq_serv.irq_5,  irq_serv.irq_6,  irq_serv.irq_7
1056 Galkov 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
 
33 mario79 248
ready_for_next_irq:
1306 Lrz 249
	mov	eax,5
250
        mov     [check_idle_semaphore],eax
251
;        mov     al, 0x20
252
	add 	eax,(0x20-0x5)
253
 
1056 Galkov 254
        out     0x20, al
255
        ret
1306 Lrz 256
;destroy eax
33 mario79 257
ready_for_next_irq_1:
1306 Lrz 258
	mov	eax,5
259
        mov     [check_idle_semaphore],eax
260
;        mov     al, 0x20
261
	add 	eax,(0x20-0x5)
1056 Galkov 262
        out     0xa0,al
263
        out     0x20, al
264
        ret
33 mario79 265
 
6 poddubny 266
irqD:
1056 Galkov 267
        push  eax
1306 Lrz 268
	xor   eax,eax
1056 Galkov 269
        out   0xf0,al
270
        mov   al,0x20
271
        out   0xa0,al
272
        out   0x20,al
273
        pop   eax
274
        iret
164 serge 275
 
1 ha 276
 
1992 clevermous 277
irqh 2,3,4,5,6,7,8,9,10,11
40 halyavin 278
 
1 ha 279
irqhandler:
280
 
1056 Galkov 281
     mov    esi,edi          ; 1
282
     shl    esi,6            ; 1
1 ha 283
     add    esi,irq00read    ; 1
1056 Galkov 284
     shl    edi,12           ; 1
381 serge 285
     add    edi,IRQ_SAVE
75 diamond 286
     mov    ecx,16
1 ha 287
 
288
   irqnewread:
75 diamond 289
     dec    ecx
290
     js     irqover
1 ha 291
 
1056 Galkov 292
     movzx  edx, word [esi]        ; 2+
1 ha 293
 
1056 Galkov 294
     test   edx, edx               ; 1
1 ha 295
     jz     irqover
296
 
297
 
1056 Galkov 298
     mov    ebx, [edi]             ; address of begin of buffer in edi      ; + 0x0 dword - data size
299
     mov    eax, 4000                                                       ; + 0x4 dword - data begin offset
759 Rus 300
     cmp    ebx, eax
1 ha 301
     je     irqfull
1056 Galkov 302
     add    ebx, [edi + 0x4]       ; add data size to data begin offset
303
     cmp    ebx, eax               ; if end of buffer, begin cycle again
759 Rus 304
     jb     @f
1 ha 305
 
759 Rus 306
     xor    ebx, ebx
1 ha 307
 
759 Rus 308
  @@:
309
     add    ebx, edi
1056 Galkov 310
     movzx  eax, byte[esi + 3]     ; get type of data being received 1 - byte, 2 - word
759 Rus 311
     dec    eax
312
     jz     irqbyte
313
     dec    eax
314
     jnz    noirqword
1 ha 315
 
759 Rus 316
     in     ax,dx
1056 Galkov 317
     cmp    ebx, 3999              ; check for address odd in the end of buffer
759 Rus 318
     jne    .odd
319
     mov    [ebx + 0x10], ax
320
     jmp    .add_size
321
  .odd:
1056 Galkov 322
     mov    [ebx + 0x10], al       ; I could make mistake here :)
759 Rus 323
     mov    [edi + 0x10], ah
324
  .add_size:
325
     add    dword [edi], 2
326
     jmp    nextport
1 ha 327
 
328
 
759 Rus 329
  irqbyte:
330
     in     al,dx
331
     mov    [ebx + 0x10],al
332
     inc    dword [edi]
333
  nextport:
1 ha 334
     add    esi,4
335
     jmp    irqnewread
336
 
759 Rus 337
 
1 ha 338
   noirqword:
339
   irqfull:
340
   irqover:
341
 
342
     ret
343
 
344
 
345
 
346
set_application_table_status:
1056 Galkov 347
        push eax
1 ha 348
 
1056 Galkov 349
        mov  eax,[CURRENT_TASK]
350
        shl  eax, 5
351
        add  eax,CURRENT_TASK+TASKDATA.pid
352
        mov  eax,[eax]
1 ha 353
 
1056 Galkov 354
        mov  [application_table_status],eax
1 ha 355
 
1056 Galkov 356
        pop  eax
1 ha 357
 
1056 Galkov 358
        ret
1 ha 359
 
360
 
361
clear_application_table_status:
1056 Galkov 362
        push eax
1 ha 363
 
1056 Galkov 364
        mov  eax,[CURRENT_TASK]
365
        shl  eax, 5
366
        add  eax,CURRENT_TASK+TASKDATA.pid
367
        mov  eax,[eax]
1 ha 368
 
1056 Galkov 369
        cmp  eax,[application_table_status]
370
        jne  apptsl1
1306 Lrz 371
	xor  eax,eax
372
        mov  [application_table_status],eax
1 ha 373
      apptsl1:
374
 
1056 Galkov 375
        pop  eax
1 ha 376
 
1056 Galkov 377
        ret
1 ha 378
 
1306 Lrz 379
;  * eax = 64 - номер функции
380
;  * ebx = 1 - единственная подфункция
381
;  * ecx = новый размер памяти
382
;Возвращаемое значение:
383
;  * eax = 0 - успешно
384
;  * eax = 1 - недостаточно памяти
385
 
1 ha 386
sys_resize_app_memory:
1306 Lrz 387
        ; ebx = 1 - resize
388
        ; ecx = new amount of memory
1 ha 389
 
1306 Lrz 390
;        cmp    eax,1
391
	dec	ebx
392
        jnz    .no_application_mem_resize
1307 Lrz 393
        stdcall new_mem_resize, ecx
1306 Lrz 394
        mov [esp+32], eax
164 serge 395
.no_application_mem_resize:
1056 Galkov 396
        ret
1 ha 397
 
398
iglobal
1056 Galkov 399
;  process_terminating  db 'K : Process - terminating',13,10,0
400
;  process_terminated   db 'K : Process - done',13,10,0
401
  msg_obj_destroy       db 'K : destroy app object',13,10,0
1 ha 402
endg
403
 
329 serge 404
; param
405
;  esi= slot
1 ha 406
 
407
terminate: ; terminate application
408
 
1056 Galkov 409
           .slot equ esp   ;locals
329 serge 410
 
1056 Galkov 411
           push   esi      ;save .slot
334 serge 412
 
1056 Galkov 413
           shl esi, 8
414
           cmp [SLOT_BASE+esi+APPDATA.dir_table], 0
415
           jne @F
416
           pop    esi
417
           shl    esi, 5
418
           mov    [CURRENT_TASK+esi+TASKDATA.state], 9
419
           ret
334 serge 420
@@:
1056 Galkov 421
           ;mov    esi,process_terminating
422
           ;call   sys_msg_board_str
40 halyavin 423
@@:
1056 Galkov 424
           cli
425
           cmp   [application_table_status],0
426
           je    term9
427
           sti
428
           call  change_task
429
           jmp   @b
329 serge 430
term9:
1056 Galkov 431
           call  set_application_table_status
1 ha 432
 
709 diamond 433
; if the process is in V86 mode...
1056 Galkov 434
        mov     eax, [.slot]
435
        shl     eax, 8
436
        mov     esi, [eax+SLOT_BASE+APPDATA.pl0_stack]
437
        add     esi, RING0_STACK_SIZE
438
        cmp     [eax+SLOT_BASE+APPDATA.saved_esp0], esi
439
        jz      .nov86
709 diamond 440
; ...it has page directory for V86 mode
1056 Galkov 441
        mov     esi, [eax+SLOT_BASE+APPDATA.saved_esp0]
442
        mov     ecx, [esi+4]
443
        mov     [eax+SLOT_BASE+APPDATA.dir_table], ecx
709 diamond 444
; ...and I/O permission map for V86 mode
1056 Galkov 445
        mov     ecx, [esi+12]
446
        mov     [eax+SLOT_BASE+APPDATA.io_map], ecx
447
        mov     ecx, [esi+8]
448
        mov     [eax+SLOT_BASE+APPDATA.io_map+4], ecx
709 diamond 449
.nov86:
450
 
1056 Galkov 451
           mov esi, [.slot]
452
           shl esi,8
453
           add esi, SLOT_BASE+APP_OBJ_OFFSET
329 serge 454
@@:
1056 Galkov 455
           mov eax, [esi+APPOBJ.fd]
456
           test eax, eax
457
           jz @F
334 serge 458
 
1056 Galkov 459
           cmp eax, esi
460
           je @F
164 serge 461
 
1056 Galkov 462
           push esi
463
           call [eax+APPOBJ.destroy]
464
           DEBUGF 1,"%s",msg_obj_destroy
465
           pop esi
466
           jmp @B
329 serge 467
@@:
1311 diamond 468
 
1056 Galkov 469
           mov eax, [.slot]
470
           shl eax, 8
1311 diamond 471
           stdcall destroy_app_space, [SLOT_BASE+eax+APPDATA.dir_table], [SLOT_BASE+eax+APPDATA.dlls_list_ptr]
1 ha 472
 
1056 Galkov 473
           mov esi, [.slot]
474
           cmp [fpu_owner],esi   ; if user fpu last -> fpu user = 1
475
           jne @F
164 serge 476
 
1056 Galkov 477
           mov [fpu_owner],1
478
           mov eax, [256+SLOT_BASE+APPDATA.fpu_state]
479
           clts
480
           bt [cpu_caps], CAPS_SSE
481
           jnc .no_SSE
482
           fxrstor [eax]
483
           jmp @F
203 serge 484
.no_SSE:
1056 Galkov 485
           fnclex
486
           frstor [eax]
357 serge 487
@@:
203 serge 488
 
1056 Galkov 489
    mov   [KEY_COUNT],byte 0           ; empty keyboard buffer
490
    mov   [BTN_COUNT],byte 0           ; empty button buffer
1 ha 491
 
492
 
92 diamond 493
; remove defined hotkeys
1056 Galkov 494
        mov     eax, hotkey_list
92 diamond 495
.loop:
1056 Galkov 496
        cmp     [eax+8], esi
497
        jnz     .cont
498
        mov     ecx, [eax]
499
        jecxz   @f
500
        push    dword [eax+12]
501
        pop     dword [ecx+12]
92 diamond 502
@@:
1056 Galkov 503
        mov     ecx, [eax+12]
504
        push    dword [eax]
505
        pop     dword [ecx]
506
        xor     ecx, ecx
507
        mov     [eax], ecx
508
        mov     [eax+4], ecx
509
        mov     [eax+8], ecx
510
        mov     [eax+12], ecx
92 diamond 511
.cont:
1056 Galkov 512
        add     eax, 16
513
        cmp     eax, hotkey_list+256*16
514
        jb      .loop
92 diamond 515
; remove hotkeys in buffer
1056 Galkov 516
        mov     eax, hotkey_buffer
92 diamond 517
.loop2:
1056 Galkov 518
        cmp     [eax], esi
519
        jnz     .cont2
520
        and     dword [eax+4], 0
521
        and     dword [eax], 0
92 diamond 522
.cont2:
1056 Galkov 523
        add     eax, 8
524
        cmp     eax, hotkey_buffer+120*8
525
        jb      .loop2
92 diamond 526
 
1056 Galkov 527
    mov   ecx,esi                 ; remove buttons
1 ha 528
  bnewba2:
381 serge 529
    mov   edi,[BTN_ADDR]
1 ha 530
    mov   eax,edi
531
    cld
532
    movzx ebx,word [edi]
533
    inc   bx
534
  bnewba:
535
    dec   bx
1056 Galkov 536
    jz    bnmba
1 ha 537
    add   eax,0x10
538
    cmp   cx,[eax]
539
    jnz   bnewba
540
    pusha
541
    mov   ecx,ebx
542
    inc   ecx
543
    shl   ecx,4
544
    mov   ebx,eax
545
    add   eax,0x10
546
    call  memmove
547
    dec   dword [edi]
548
    popa
549
    jmp   bnewba2
550
  bnmba:
551
 
552
    pusha     ; save window coordinates for window restoring
553
    cld
554
    shl   esi,5
555
    add   esi,window_data
114 mikedld 556
    mov   eax,[esi+WDATA.box.left]
1362 mikedld 557
    mov   [draw_limits.left],eax
114 mikedld 558
    add   eax,[esi+WDATA.box.width]
1362 mikedld 559
    mov   [draw_limits.right],eax
114 mikedld 560
    mov   eax,[esi+WDATA.box.top]
1362 mikedld 561
    mov   [draw_limits.top],eax
114 mikedld 562
    add   eax,[esi+WDATA.box.height]
1362 mikedld 563
    mov   [draw_limits.bottom],eax
1 ha 564
 
142 diamond 565
    xor   eax, eax
566
    mov   [esi+WDATA.box.left],eax
567
    mov   [esi+WDATA.box.width],eax
114 mikedld 568
    mov   [esi+WDATA.box.top],eax
142 diamond 569
    mov   [esi+WDATA.box.height],eax
115 poddubny 570
    mov   [esi+WDATA.cl_workarea],eax
571
    mov   [esi+WDATA.cl_titlebar],eax
572
    mov   [esi+WDATA.cl_frames],eax
573
    mov   dword [esi+WDATA.reserved],eax ; clear all flags: wstate, redraw, wdrawn
102 poddubny 574
    lea   edi, [esi-window_data+draw_data]
1 ha 575
    mov   ecx,32/4
576
    rep   stosd
577
    popa
578
 
40 halyavin 579
; debuggee test
580
    pushad
581
    mov  edi, esi
582
    shl  edi, 5
380 serge 583
    mov  eax, [SLOT_BASE+edi*8+APPDATA.debugger_slot]
40 halyavin 584
    test eax, eax
1056 Galkov 585
    jz   .nodebug
40 halyavin 586
    push 8
587
    pop  ecx
1056 Galkov 588
    push dword [CURRENT_TASK+edi+TASKDATA.pid]   ; PID
40 halyavin 589
    push 2
590
    call debugger_notify
591
    pop  ecx
592
    pop  ecx
593
.nodebug:
594
    popad
595
 
1056 Galkov 596
           mov ebx, [.slot]
597
           shl ebx, 8
598
           push ebx
599
           mov ebx,[SLOT_BASE+ebx+APPDATA.pl0_stack]
1 ha 600
 
1056 Galkov 601
           stdcall kernel_free, ebx
1 ha 602
 
1056 Galkov 603
           pop ebx
604
           mov ebx,[SLOT_BASE+ebx+APPDATA.cur_dir]
605
           stdcall kernel_free, ebx
521 diamond 606
 
1056 Galkov 607
           mov edi, [.slot]
608
           shl edi,8
609
           add edi,SLOT_BASE
465 serge 610
 
1056 Galkov 611
           mov eax, [edi+APPDATA.io_map]
1310 diamond 612
           cmp eax, [SLOT_BASE+256+APPDATA.io_map]
1056 Galkov 613
           je @F
614
           call free_page
465 serge 615
@@:
1056 Galkov 616
           mov eax, [edi+APPDATA.io_map+4]
1310 diamond 617
           cmp eax, [SLOT_BASE+256+APPDATA.io_map+4]
1056 Galkov 618
           je @F
619
           call free_page
465 serge 620
@@:
1056 Galkov 621
           mov eax, 0x20202020
622
           stosd
623
           stosd
624
           stosd
625
           mov ecx,244/4
626
           xor eax, eax
627
           rep stosd
1 ha 628
 
102 poddubny 629
  ; activate window
1056 Galkov 630
        movzx  eax, word [WIN_STACK + esi*2]
631
        cmp    eax, [TASK_COUNT]
632
        jne    .dont_activate
633
        pushad
102 poddubny 634
 .check_next_window:
1056 Galkov 635
        dec    eax
636
        cmp    eax, 1
637
        jbe    .nothing_to_activate
638
        lea    esi, [WIN_POS+eax*2]
639
        movzx  edi, word [esi]               ; edi = process
640
        shl    edi, 5
641
        cmp    [CURRENT_TASK + edi + TASKDATA.state], byte 9  ; skip dead slots
642
        je     .check_next_window
643
        add    edi, window_data
154 diamond 644
; \begin{diamond}[19.09.2006]
645
; skip minimized windows
1056 Galkov 646
        test   [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
647
        jnz    .check_next_window
154 diamond 648
; \end{diamond}
1056 Galkov 649
        call   waredraw
102 poddubny 650
 .nothing_to_activate:
1056 Galkov 651
        popad
102 poddubny 652
 .dont_activate:
653
 
1056 Galkov 654
        push    esi     ; remove hd1 & cd & flp reservation
655
        shl     esi, 5
656
        mov     esi, [esi+CURRENT_TASK+TASKDATA.pid]
657
        cmp     [hd1_status], esi
658
        jnz     @f
659
        call    free_hd_channel
1306 Lrz 660
        and     [hd1_status], 0
92 diamond 661
@@:
1056 Galkov 662
        cmp     [cd_status], esi
663
        jnz     @f
664
        call    free_cd_channel
1306 Lrz 665
        and     [cd_status], 0
92 diamond 666
@@:
1056 Galkov 667
        cmp     [flp_status], esi
668
        jnz     @f
1306 Lrz 669
        and     [flp_status], 0
92 diamond 670
@@:
1056 Galkov 671
        pop     esi
672
        cmp     [bgrlockpid], esi
673
        jnz     @f
674
        and     [bgrlockpid], 0
1306 Lrz 675
        and     [bgrlock], 0
546 diamond 676
@@:
1 ha 677
 
678
    pusha ; remove all irq reservations
92 diamond 679
    mov   eax,esi
115 poddubny 680
    shl   eax, 5
379 serge 681
    mov   eax,[eax+CURRENT_TASK+TASKDATA.pid]
1 ha 682
    mov   edi,irq_owner
774 Rus 683
    xor   ebx, ebx
684
    xor   edx, edx
1 ha 685
  newirqfree:
774 Rus 686
    cmp   [edi + 4 * ebx], eax
1 ha 687
    jne   nofreeirq
1056 Galkov 688
    mov   [edi + 4 * ebx], edx                          ; remove irq reservation
689
    mov   [irq_tab + 4 * ebx], edx                      ; remove irq handler
690
    mov   [irq_rights + 4 * ebx], edx                   ; set access rights to full access
1 ha 691
  nofreeirq:
774 Rus 692
    inc   ebx
693
    cmp   ebx, 16
1056 Galkov 694
    jb    newirqfree
1 ha 695
    popa
696
 
1056 Galkov 697
    pusha                     ; remove all port reservations
1 ha 698
    mov   edx,esi
115 poddubny 699
    shl   edx, 5
379 serge 700
    add   edx,CURRENT_TASK
115 poddubny 701
    mov   edx,[edx+TASKDATA.pid]
1 ha 702
 
703
  rmpr0:
704
 
381 serge 705
    mov   esi,[RESERVED_PORTS]
1 ha 706
 
1306 Lrz 707
    test  esi,esi
708
    jz    rmpr9
1 ha 709
 
710
  rmpr3:
711
 
712
    mov   edi,esi
713
    shl   edi,4
381 serge 714
    add   edi,RESERVED_PORTS
1 ha 715
 
716
    cmp   edx,[edi]
1056 Galkov 717
    je    rmpr4
1 ha 718
 
719
    dec   esi
720
    jnz   rmpr3
721
 
722
    jmp   rmpr9
723
 
724
  rmpr4:
725
 
726
    mov   ecx,256
727
    sub   ecx,esi
728
    shl   ecx,4
729
 
730
    mov   esi,edi
731
    add   esi,16
732
    cld
733
    rep   movsb
734
 
381 serge 735
    dec   dword [RESERVED_PORTS]
1 ha 736
 
737
    jmp   rmpr0
738
 
739
  rmpr9:
740
 
741
    popa
1056 Galkov 742
    mov  edi,esi         ; do not run this process slot
6 poddubny 743
    shl  edi, 5
379 serge 744
    mov  [edi+CURRENT_TASK + TASKDATA.state],byte 9
40 halyavin 745
; debugger test - terminate all debuggees
746
    mov  eax, 2
380 serge 747
    mov  ecx, SLOT_BASE+2*0x100+APPDATA.debugger_slot
40 halyavin 748
.xd0:
379 serge 749
    cmp  eax, [TASK_COUNT]
1056 Galkov 750
    ja   .xd1
40 halyavin 751
    cmp  dword [ecx], esi
752
    jnz  @f
753
    and  dword [ecx], 0
754
    pushad
684 diamond 755
    xchg eax, ecx
756
    mov  ebx, 2
40 halyavin 757
    call sys_system
758
    popad
759
@@:
760
    inc  eax
761
    add  ecx, 0x100
762
    jmp  .xd0
763
.xd1:
1 ha 764
;    call  systest
765
    sti  ; .. and life goes on
766
 
1362 mikedld 767
    mov   eax, [draw_limits.left]
768
    mov   ebx, [draw_limits.top]
769
    mov   ecx, [draw_limits.right]
770
    mov   edx, [draw_limits.bottom]
1 ha 771
    call  calculatescreen
772
    xor   eax, eax
773
    xor   esi, esi
774
    call  redrawscreen
775
 
381 serge 776
    mov   [MOUSE_BACKGROUND],byte 0  ; no mouse background
777
    mov   [DONT_DRAW_MOUSE],byte 0  ; draw mouse
1 ha 778
 
1306 Lrz 779
    and   [application_table_status],0
506 mikedld 780
    ;mov   esi,process_terminated
781
    ;call  sys_msg_board_str
357 serge 782
    add esp, 4
1 ha 783
    ret
345 serge 784
restore .slot
1 ha 785
 
786
iglobal
1056 Galkov 787
  boot_sched_1    db   'Building gdt tss pointer',0
788
  boot_sched_2    db   'Building IDT table',0
1 ha 789
endg
790
 
791
 
792
build_scheduler:
793
 
1056 Galkov 794
        mov    esi,boot_sched_1
795
        call   boot_log
465 serge 796
  ;      call   build_process_gdt_tss_pointer
1 ha 797
 
465 serge 798
  ;      mov    esi,boot_sched_2
799
  ;      call   boot_log
1 ha 800
 
1056 Galkov 801
        ret