Subversion Repositories Kolibri OS

Rev

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