Subversion Repositories Kolibri OS

Rev

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