Subversion Repositories Kolibri OS

Rev

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