Subversion Repositories Kolibri OS

Rev

Rev 3487 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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