Subversion Repositories Kolibri OS

Rev

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