Subversion Repositories Kolibri OS

Rev

Rev 1161 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1161 Rev 1198
Line 12... Line 12...
12
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Line 13... Line 13...
13
 
13
 
Line 14... Line 14...
14
$Revision: 982 $
14
$Revision: 982 $
15
 
-
 
16
 
-
 
17
align 4
-
 
18
idtreg:
-
 
19
     dw   8*0x41-1
15
 
20
     dd   idts+8
-
 
21
 
16
 
22
build_interrupt_table:
17
align 4 ;3A08
23
 
18
build_interrupt_table:
24
	mov    edi, idts+8
-
 
25
	mov    esi, sys_int
-
 
26
	mov    ecx, 0x40
19
        mov     edi, idts
27
     @@:
20
        mov     esi, sys_int
28
	lodsd
21
        mov     ecx, 0x40
29
	mov    [edi],	ax	     ; lower part of offset
22
        mov     eax, (10001110b shl 24) + os_code
30
	mov    [edi+2], word os_code ; segment selector
23
  @@:   movsw   ;low word of code-entry
31
	mov	ax, word 10001110b shl 8	; type: interrupt gate
-
 
32
	mov	[edi+4], eax
-
 
33
	add    edi, 8
-
 
34
	loop	@b
24
        stosd   ;interrupt gate type : os_code selector
35
 
25
        movsw   ;high word of code-entry
36
	;mov    edi,8*0x40+idts+8
26
        loop    @b
37
	mov	dword [edi], (i40 and 0xFFFF) or (os_code shl 16)
27
        movsd   ;copy low  dword of trap gate for int 0x40
Line 38... Line 28...
38
	mov	dword [edi+4], (11101111b shl 8) or (i40 and 0xFFFF0000)
28
        movsd   ;copy high dword of trap gate for int 0x40
39
						; type: trap gate
-
 
40
	ret
29
        lidt    [esi]
41
 
-
 
42
iglobal
-
 
43
 
30
        ret
44
  msg_sel_ker	db "kernel", 0
31
 
45
  msg_sel_app	db "application", 0
32
iglobal
46
 
-
 
47
  sys_int:
33
  align 4
48
    dd e0,debug_exc,e2,e3
-
 
49
    dd e4,e5,e6,e7
34
  sys_int:
50
    dd e8,e9,e10,e11
35
    ;exception handlers addresses (for interrupt gate construction)
51
    dd e12,e13,page_fault_handler,e15
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
52
 
38
        dd      e16, e17,e18, e19
53
    dd except_16, e17,e18, except_19
39
        times   12 dd unknown_interrupt ;int_20..int_31
54
    times 12 dd unknown_interrupt
40
 
55
 
41
    ;interrupt handlers addresses (for interrupt gate construction)
56
    dd	 irq0, irq_serv.irq_1, irq_serv.irq_2
42
        dd      irq0, irq_serv.irq_1, irq_serv.irq_2
57
if USE_COM_IRQ
43
    if  USE_COM_IRQ
58
    dd	 irq_serv.irq_3, irq_serv.irq_4
44
        dd      irq_serv.irq_3, irq_serv.irq_4
59
else
45
    else
60
    dd	 p_irq3, p_irq4
46
        dd      p_irq3, p_irq4 ;??? íåñòûêîâêà
-
 
47
    end if
-
 
48
        dd      irq_serv.irq_5,  p_irq6,          irq_serv.irq_7
-
 
49
        dd      irq_serv.irq_8,  irq_serv.irq_9,  irq_serv.irq_10
-
 
50
        dd      irq_serv.irq_11, irq_serv.irq_12, irqD,p_irq14,p_irq15
-
 
51
        times   16 dd unknown_interrupt ;int_0x30..int_0x3F
-
 
52
 
-
 
53
    ;int_0x40 gate trap (for directly copied)
-
 
54
        dw      i40 and 0xFFFF, os_code, 11101111b shl 8, i40 shr 16
-
 
55
 
-
 
56
  idtreg: ; data for LIDT instruction (!!! must be immediately below sys_int data)
-
 
57
        dw      2*($-sys_int-4)-1
-
 
58
        dd      idts ;0x8000B100
-
 
59
        dw      0    ;ïðîñòî âûðàâíèâàíèå
-
 
60
 
-
 
61
  msg_fault_sel dd  msg_exc_8,msg_exc_u,msg_exc_a,msg_exc_b
-
 
62
                dd  msg_exc_c,msg_exc_d,msg_exc_e
-
 
63
 
-
 
64
  msg_exc_8     db "Double fault", 0
-
 
65
  msg_exc_u     db "Undefined Exception", 0
-
 
66
  msg_exc_a     db "Invalid TSS", 0
Line -... Line 67...
-
 
67
  msg_exc_b     db "Segment not present", 0
61
end if
68
  msg_exc_c     db "Stack fault", 0
Line 62... Line -...
62
    dd	 irq_serv.irq_5,  p_irq6,	  irq_serv.irq_7
-
 
63
    dd	 irq_serv.irq_8,  irq_serv.irq_9, irq_serv.irq_10
69
  msg_exc_d     db "General protection fault", 0
Line 64... Line 70...
64
    dd	 irq_serv.irq_11, irq_serv.irq_12,irqD ,p_irq14,p_irq15
70
  msg_exc_e     db "Page fault", 0
65
 
-
 
66
    times 16 dd unknown_interrupt
71
 
67
 
72
  msg_sel_ker   db "kernel", 0
68
    dd	 i40
73
  msg_sel_app   db "application", 0
69
endg
-
 
70
 
74
 
71
macro save_ring3_context
75
endg
72
{
-
 
73
    pushad
-
 
74
}
-
 
75
macro restore_ring3_context
-
 
76
{
-
 
77
    popad
76
 
78
}
-
 
79
 
-
 
80
; simply return control to interrupted process
77
macro save_ring3_context {
81
unknown_interrupt:
78
        pushad
82
     iret
79
}
83
 
80
macro restore_ring3_context {
84
macro exc_wo_code [num]
-
 
-
 
81
        popad
Line 85... Line 82...
85
{
82
}
86
  forward
-
 
87
  e#num :
-
 
88
      save_ring3_context
83
macro exc_wo_code [num] {
89
      mov bl, num
84
  e#num :
90
      jmp exc_c
85
        save_ring3_context
91
}
86
        mov     bl, num
92
 
87
        jmp     exc_c
93
macro exc_w_code [num]
-
 
-
 
88
} exc_wo_code   0,1,2,3,4,5,6,15,16,19
Line 94... Line -...
94
{
-
 
95
  forward
-
 
Line 96... Line 89...
96
  e#num :
89
 
97
      add esp, 4
-
 
98
      save_ring3_context
-
 
99
      mov bl, num
90
macro exc_w_code [num] {
-
 
91
  e#num :
Line -... Line 92...
-
 
92
        add     esp, 4
100
      jmp exc_c
93
        save_ring3_context
101
}
94
        mov     bl, num
102
 
95
        jmp     exc_c
Line -... Line 96...
-
 
96
} exc_w_code    8,9,10,11,12,13,17,18
-
 
97
 
-
 
98
 
-
 
99
uglobal
-
 
100
  pf_err_code   dd ?
103
exc_wo_code 0, 2, 3, 4, 5, 6, 9, 15, 18
101
endg
-
 
102
 
-
 
103
page_fault_exc:                 ; äóðàêîóñòî÷èâîñòü: ñåëåêòîðû èñïîð÷åíû...
-
 
104
        pop     [ss:pf_err_code]; äåéñòâèòåëüíî äî ñëåäóþùåãî #PF
-
 
105
        save_ring3_context
-
 
106
        mov     bl,14
-
 
107
 
-
 
108
exc_c:                          ; èñêëþ÷åíèÿ (âñå, êðîìå 7-ãî - #NM)
-
 
109
; Ôðýéì ñòåêà ïðè èñêëþ÷åíèè/ïðåðûâàíèè èç 3-ãî êîëüöà + pushad (ò.å., èìåííî çäåñü)
-
 
110
  reg_ss        equ esp+0x30
-
 
111
  reg_esp3      equ esp+0x2C
104
exc_w_code 8, 10, 11, 12, 13, 14, 17
112
  reg_eflags    equ esp+0x28
-
 
113
  reg_cs3       equ esp+0x24
-
 
114
  reg_eip       equ esp+0x20
-
 
115
 ; ýòî ôðýéì îò pushad
-
 
116
  reg_eax       equ esp+0x1C
-
 
117
  reg_ecx       equ esp+0x18
-
 
118
  reg_edx       equ esp+0x14
-
 
119
  reg_ebx       equ esp+0x10
-
 
120
  reg_esp0      equ esp+0x0C
-
 
121
  reg_ebp       equ esp+0x08
-
 
122
  reg_esi       equ esp+0x04
105
 
123
  reg_edi       equ esp+0x00
-
 
124
 
-
 
125
        Mov     ds,ax,app_data  ; çàãðóçèì ïðàâèëüíûå çíà÷åíèÿ
-
 
126
        mov     es,ax           ; â ñåãìåíòíûå ðåãèñòðû
-
 
127
        cld                     ; è ïðèâîäèì DF ê ñòàíäàðòó
-
 
128
        movzx   ebx,bl
-
 
129
; redirect to V86 manager? (EFLAGS & 0x20000) != 0?
106
exc_c:
130
        test    byte[reg_eflags+2],2
107
	mov   ax, app_data  ;èñêëþ÷åíèå
131
        jnz     v86_exc_c
108
	mov   ds, ax	    ;çàãðóçèì ïðàâèëüíûå çíà÷åíè
132
        cmp     bl,14           ; #PF
109
	mov   es, ax	    ;â ðåãèñòðû
133
        jne     @f
110
 
134
        call    page_fault_handler ; SEE: core/memory.inc
111
; redirect to V86 manager? (EFLAGS & 0x20000) != 0?
-
 
112
	test	byte [esp+20h+8+2], 2
-
 
113
	jnz	v86_exc_c
135
  @@:   mov     esi, [current_slot]
114
 
-
 
115
; test if debugging
136
        btr     [esi+APPDATA.except_mask], ebx
116
	cli
137
        jnc     @f
117
	mov   eax, [current_slot]
-
 
118
	mov   eax, [eax+APPDATA.debugger_slot]
138
        mov     eax,[esi+APPDATA.exc_handler]
119
	test  eax, eax
-
 
120
	jnz   .debug
139
        test    eax, eax
121
	sti
140
        jnz     IRetToUserHook
122
; not debuggee => say error and terminate
141
  @@:   cli
-
 
142
        mov     eax, [esi+APPDATA.debugger_slot]
123
	movzx eax, bl
143
        test    eax, eax
-
 
144
        jnz     .debug
-
 
145
        sti
124
	mov   [error_interrupt], eax
146
; not debuggee => say error and terminate
125
	call  show_error_parameters
147
        call    show_error_parameters ;; only ONE using, inline ???
126
	add   esp, 0x20
148
       ;mov     edx, [TASK_BASE]
127
	mov   edx, [TASK_BASE]
149
        mov     [edx + TASKDATA.state], byte 4 ; terminate
128
	mov   [edx + TASKDATA.state], byte 4
150
        jmp     change_task     ; stack - here it does not matter at all, SEE: core/shed.inc
129
 
151
.debug:
130
	jmp   change_task
152
; we are debugged process, notify debugger and suspend ourself
131
 
153
; eax=debugger PID
132
.debug:
154
        mov     ecx,1           ; debug_message code=other_exception
-
 
155
        cmp     bl,1            ; #DB
133
; we are debugged process, notify debugger and suspend ourself
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
134
; eax=debugger PID
163
        jc      @f
135
	cld
164
        and     bl, cl
136
	movzx ecx, bl
165
  @@:   sar     cl,1
137
	push  ecx
166
        jc      .l1
138
	mov   ecx, [TASK_BASE]
167
        mov     cl, 3           ; debug_message code=debug_exception
139
	push  dword [ecx+TASKDATA.pid]	  ; PID of current process
168
.notify:
Line 140... Line 169...
140
	push  12
169
        push    ebx             ; debug_message data
-
 
170
        mov     ebx, [TASK_BASE]
141
	pop   ecx
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
142
	push  1        ; 1=exception
176
        mov     edx, [TASK_BASE]
143
	call  debugger_notify
177
        mov     byte [edx+TASKDATA.state], 1 ; suspended
Line 144... Line 178...
144
	pop   ecx
178
        call    change_task     ; SEE: core/shed.inc
145
	pop   ecx
179
        restore_ring3_context
146
	pop   ecx
180
        iretd
147
	mov   edx, [TASK_BASE]
-
 
148
	mov   byte [edx+TASKDATA.state], 1	  ; suspended
181
 
149
	call  change_task
-
 
150
	restore_ring3_context
182
IRetToUserHook:
151
	iretd
-
 
152
 
-
 
153
iglobal
183
        xchg    eax, [reg_eip]
154
	hexletters	db '0123456789ABCDEF'
-
 
155
	error_interrupt dd  -1
184
        sub     dword[reg_esp3], 8
156
endg
-
 
157
 
-
 
158
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
185
        mov     edi, [reg_esp3]
159
show_error_parameters:
-
 
160
    mov eax,[CURRENT_TASK]
186
        stosd
161
    shl eax, 5
-
 
162
    DEBUGF  1, "K : Process - forced terminate PID: %x\n", [CURRENT_TASK + TASKDATA.pid + eax]
187
        mov     [edi], ebx
163
    mov eax, [error_interrupt]
-
 
164
    cmp al, 0x08
-
 
165
    jne @f
-
 
166
    DEBUGF  1, "K : Double fault\n"
-
 
167
    jmp defined_error
188
        restore_ring3_context
168
@@:
189
unknown_interrupt:
169
    cmp al, 0x0a
-
 
170
    jne @f
-
 
171
    DEBUGF  1, "K : Invalid TSS\n"
-
 
172
    jmp defined_error
190
        iretd
173
@@:
191
 
174
    cmp al, 0x0b
-
 
175
    jne @f
192
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
176
    DEBUGF  1, "K : Segment not present\n"
193
show_error_parameters:
177
    jmp defined_error
194
        mov     edx,[TASK_BASE] ;not scratched below
178
@@:
195
        DEBUGF  1, "K : Process - forced terminate PID: %x\n", [edx+TASKDATA.pid]
179
    cmp al, 0x0c
-
 
180
    jne @f
-
 
181
    DEBUGF  1, "K : Stack fault\n"
-
 
182
    jmp defined_error
196
        cmp     bl, 0x08
183
@@:
197
        jb      .l0
184
    cmp al, 0x0d
198
        cmp     bl, 0x0e
185
    jne @f
-
 
186
    DEBUGF  1, "K : General protection fault\n"
-
 
187
    jmp defined_error
-
 
188
@@:
-
 
189
    cmp al, 0x0e
-
 
190
    jne @f
-
 
191
    DEBUGF  1, "K : Page fault\n"
-
 
192
    jmp defined_error
-
 
193
@@:
-
 
194
    DEBUGF  1, "K : Undefined Exception\n"
199
        jbe     .l1
195
defined_error:
200
  .l0:  mov     bl, 0x09
196
    DEBUGF  1, "K : EAX : %x EBX : %x ECX : %x\n", [esp + 0x20], [esp - 12 + 0x20], [esp - 4 + 0x20]
201
  .l1:  mov     eax,[msg_fault_sel+ebx*4 - 0x08*4]
Line -... Line 202...
-
 
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
Line 197... Line 215...
197
    DEBUGF  1, "K : EDX : %x ESI : %x EDI : %x\n", [esp - 8 + 0x20], [esp - 24 + 0x20], [esp - 28 + 0x20]
215
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
198
    DEBUGF  1, "K : EBP : %x EIP : %x ", [esp - 20 + 0x20], [esp + 4 + 0x20]
216
 
199
 
-
 
200
    mov eax, [esp + 8 + 0x20]
-
 
201
    mov edi, msg_sel_app
217
  restore  reg_ss
202
    mov ebx, [esp + 16 + 0x20]
218
  restore  reg_esp3
203
    cmp eax, app_code
219
  restore  reg_eflags
204
    je	@f
220
  restore  reg_cs
Line 205... Line -...
205
    mov edi, msg_sel_ker
-
 
Line 206... Line 221...
206
    mov ebx, [esp - 16 + 0x20]
221
  restore  reg_eip
207
@@:
222
  restore  reg_eax
208
    DEBUGF  1, "ESP : %x\nK : Flags : %x CS : %x (%s)\n", ebx, [esp + 12 + 0x20], eax, edi
223
  restore  reg_ecx
Line 235... Line 250...
235
        restore_ring3_context
250
        restore_ring3_context
236
        iret
251
        iret
Line 237... Line 252...
237
 
252
 
238
 
253
 
239
p_irq14:
254
p_irq14:
240
	save_ring3_context
255
        save_ring3_context
241
	mov	ax, app_data  ;os_data
256
        mov     ax, app_data  ;os_data
242
	mov	ds, ax
257
        mov     ds, ax
243
	mov	es, ax
258
        mov     es, ax
244
	mov	edi, 14
259
        mov     edi, 14
245
	cmp	[v86_irqhooks+edi*8], 0
260
        cmp     [v86_irqhooks+edi*8], 0
246
	jnz	v86_irq2
261
        jnz     v86_irq2
247
;	mov	byte [BOOT_VAR + 0x48E], 0xFF
262
;       mov     byte [BOOT_VAR + 0x48E], 0xFF
248
	call	[irq14_func]
263
        call    [irq14_func]
249
	call	ready_for_next_irq_1
264
        call    ready_for_next_irq_1
250
	restore_ring3_context
265
        restore_ring3_context
251
	iret
266
        iret
252
p_irq15:
267
p_irq15:
253
	save_ring3_context
268
        save_ring3_context
254
	mov	ax, app_data  ;os_data
269
        mov     ax, app_data  ;os_data
255
	mov	ds, ax
270
        mov     ds, ax
256
	mov	es, ax
271
        mov     es, ax
257
	mov	edi, 15
272
        mov     edi, 15
258
	cmp	[v86_irqhooks+edi*8], 0
273
        cmp     [v86_irqhooks+edi*8], 0
259
	jnz	v86_irq2
274
        jnz     v86_irq2
260
;	mov	byte [BOOT_VAR + 0x48E], 0xFF
275
;       mov     byte [BOOT_VAR + 0x48E], 0xFF
261
	call	[irq15_func]
276
        call    [irq15_func]
262
	call	ready_for_next_irq_1
277
        call    ready_for_next_irq_1
Line 263... Line 278...
263
	restore_ring3_context
278
        restore_ring3_context
264
	iret
279
        iret
265
 
280
 
266
ready_for_next_irq:
281
ready_for_next_irq:
267
     mov    [check_idle_semaphore],5
282
        mov     [check_idle_semaphore],5
Line 268... Line 283...
268
     mov   al, 0x20
283
        mov     al, 0x20
269
     out   0x20, al
284
        out     0x20, al
270
     ret
285
        ret
271
 
286
 
272
ready_for_next_irq_1:
287
ready_for_next_irq_1:
273
     mov    [check_idle_semaphore],5
288
        mov     [check_idle_semaphore],5
Line 274... Line 289...
274
     mov   al, 0x20
289
        mov     al, 0x20
275
     out    0xa0,al
-
 
276
     out   0x20, al
-
 
277
     ret
-
 
278
 
290
        out     0xa0,al
279
irqD:
-
 
280
     save_ring3_context
-
 
281
     mov   ax, app_data  ;os_data
291
        out     0x20, al
282
     mov   ds, ax
292
        ret
283
     mov   es, ax
-
 
284
 
293
 
285
     mov   dx,0xf0
294
irqD:
286
     mov   al,0
295
        push  eax
287
     out   dx,al
296
        mov   al,0
288
 
297
        out   0xf0,al
289
     mov   dx,0xa0
-
 
290
     mov   al,0x20
-
 
Line 291... Line -...
291
     out   dx,al
-
 
Line -... Line 298...
-
 
298
        mov   al,0x20
Line 292... Line 299...
292
     mov   dx,0x20
299
        out   0xa0,al
Line 293... Line 300...
293
     out   dx,al
300
        out   0x20,al
294
 
301
        pop   eax
295
     restore_ring3_context
302
        iret
296
 
303
 
297
     iret
304
 
298
 
305
irqh 2,3,4,5,7,8,9,10,11
Line 299... Line 306...
299
 
306
 
300
irqhandler:
307
irqhandler:
301
 
308
 
Line 302... Line 309...
302
     mov    esi,edi	     ; 1
309
     mov    esi,edi          ; 1
Line 303... Line 310...
303
     shl    esi,6	     ; 1
310
     shl    esi,6            ; 1
304
     add    esi,irq00read    ; 1
311
     add    esi,irq00read    ; 1
Line 305... Line 312...
305
     shl    edi,12	     ; 1
312
     shl    edi,12           ; 1
306
     add    edi,IRQ_SAVE
313
     add    edi,IRQ_SAVE
307
     mov    ecx,16
314
     mov    ecx,16
308
 
315
 
309
   irqnewread:
316
   irqnewread:
310
     dec    ecx
317
     dec    ecx
311
     js     irqover
318
     js     irqover
Line 312... Line 319...
312
 
319
 
Line 313... Line 320...
313
     movzx  edx, word [esi]	   ; 2+
320
     movzx  edx, word [esi]        ; 2+
314
 
321
 
315
     test   edx, edx		   ; 1
322
     test   edx, edx               ; 1
316
     jz     irqover
323
     jz     irqover
317
 
324
 
318
 
325
 
319
     mov    ebx, [edi]		   ; address of begin of buffer in edi      ; + 0x0 dword - data size
326
     mov    ebx, [edi]             ; address of begin of buffer in edi      ; + 0x0 dword - data size
Line 320... Line 327...
320
     mov    eax, 4000							    ; + 0x4 dword - data begin offset
327
     mov    eax, 4000                                                       ; + 0x4 dword - data begin offset
321
     cmp    ebx, eax
328
     cmp    ebx, eax
322
     je     irqfull
329
     je     irqfull
323
     add    ebx, [edi + 0x4]	   ; add data size to data begin offset
330
     add    ebx, [edi + 0x4]       ; add data size to data begin offset
324
     cmp    ebx, eax		   ; if end of buffer, begin cycle again
331
     cmp    ebx, eax               ; if end of buffer, begin cycle again
325
     jb     @f
332
     jb     @f
326
 
333
 
327
     xor    ebx, ebx
334
     xor    ebx, ebx
328
 
335
 
329
  @@:
336
  @@:
330
     add    ebx, edi
337
     add    ebx, edi
Line 363... Line 370...
363
     ret
370
     ret
Line 364... Line 371...
364
 
371
 
365
 
372
 
Line 366... Line 373...
366
 
373
 
367
set_application_table_status:
374
set_application_table_status:
368
	push eax
375
        push eax
369
 
376
 
Line 370... Line 377...
370
	mov  eax,[CURRENT_TASK]
377
        mov  eax,[CURRENT_TASK]
Line 371... Line 378...
371
	shl  eax, 5
378
        shl  eax, 5
Line 372... Line 379...
372
	add  eax,CURRENT_TASK+TASKDATA.pid
379
        add  eax,CURRENT_TASK+TASKDATA.pid
Line 373... Line 380...
373
	mov  eax,[eax]
380
        mov  eax,[eax]
374
 
381
 
Line 375... Line 382...
375
	mov  [application_table_status],eax
382
        mov  [application_table_status],eax
376
 
383
 
377
	pop  eax
384
        pop  eax
378
 
385
 
379
	ret
386
        ret
380
 
387
 
381
 
388
 
382
clear_application_table_status:
389
clear_application_table_status:
383
	push eax
390
        push eax
Line 384... Line 391...
384
 
391
 
Line 385... Line 392...
385
	mov  eax,[CURRENT_TASK]
392
        mov  eax,[CURRENT_TASK]
Line 386... Line 393...
386
	shl  eax, 5
393
        shl  eax, 5
387
	add  eax,CURRENT_TASK+TASKDATA.pid
394
        add  eax,CURRENT_TASK+TASKDATA.pid
388
	mov  eax,[eax]
395
        mov  eax,[eax]
Line 389... Line 396...
389
 
396
 
390
	cmp  eax,[application_table_status]
397
        cmp  eax,[application_table_status]
Line 391... Line 398...
391
	jne  apptsl1
398
        jne  apptsl1
392
	mov  [application_table_status],0
399
        mov  [application_table_status],0
393
      apptsl1:
400
      apptsl1:
Line 394... Line 401...
394
 
401
 
395
	pop  eax
402
        pop  eax
Line 396... Line 403...
396
 
403
 
Line 397... Line 404...
397
	ret
404
        ret
398
 
405
 
Line 419... Line 426...
419
;
426
;
420
; on return : eax = pid
427
; on return : eax = pid
421
jmp new_sys_threads
428
jmp new_sys_threads
Line 422... Line 429...
422
 
429
 
423
iglobal
430
iglobal
424
  process_terminating	db 'K : Process - terminating',13,10,0
431
;  process_terminating  db 'K : Process - terminating',13,10,0
425
  process_terminated	db 'K : Process - done',13,10,0
432
;  process_terminated   db 'K : Process - done',13,10,0
426
  msg_obj_destroy	db 'K : destroy app object',13,10,0
433
  msg_obj_destroy       db 'K : destroy app object',13,10,0
Line 427... Line 434...
427
endg
434
endg
428
 
435
 
Line 429... Line 436...
429
; param
436
; param
Line 430... Line 437...
430
;  esi= slot
437
;  esi= slot
Line 431... Line 438...
431
 
438
 
Line 432... Line 439...
432
terminate: ; terminate application
439
terminate: ; terminate application
433
 
440
 
434
	   .slot equ esp   ;locals
441
           .slot equ esp   ;locals
435
 
442
 
436
	   push   esi	   ;save .slot
443
           push   esi      ;save .slot
437
 
444
 
438
	   shl esi, 8
445
           shl esi, 8
439
	   cmp [SLOT_BASE+esi+APPDATA.dir_table], 0
446
           cmp [SLOT_BASE+esi+APPDATA.dir_table], 0
440
	   jne @F
447
           jne @F
441
	   pop	  esi
448
           pop    esi
442
	   shl	  esi, 5
-
 
443
	   mov	  [CURRENT_TASK+esi+TASKDATA.state], 9
449
           shl    esi, 5
444
	   ret
450
           mov    [CURRENT_TASK+esi+TASKDATA.state], 9
445
@@:
451
           ret
446
	   ;mov    esi,process_terminating
452
@@:
447
	   ;call   sys_msg_board_str
453
           ;mov    esi,process_terminating
448
	   DEBUGF 1,"%s",process_terminating
454
           ;call   sys_msg_board_str
449
@@:
455
@@:
450
	   cli
456
           cli
451
	   cmp	 [application_table_status],0
457
           cmp   [application_table_status],0
Line 452... Line 458...
452
	   je	 term9
458
           je    term9
453
	   sti
459
           sti
454
	   call  change_task
460
           call  change_task
455
	   jmp	 @b
461
           jmp   @b
456
term9:
462
term9:
457
	   call  set_application_table_status
463
           call  set_application_table_status
458
 
464
 
459
; if the process is in V86 mode...
465
; if the process is in V86 mode...
460
	mov	eax, [.slot]
466
        mov     eax, [.slot]
461
	shl	eax, 8
467
        shl     eax, 8
462
	mov	esi, [eax+SLOT_BASE+APPDATA.pl0_stack]
468
        mov     esi, [eax+SLOT_BASE+APPDATA.pl0_stack]
463
	add	esi, RING0_STACK_SIZE
469
        add     esi, RING0_STACK_SIZE
464
	cmp	[eax+SLOT_BASE+APPDATA.saved_esp0], esi
470
        cmp     [eax+SLOT_BASE+APPDATA.saved_esp0], esi
465
	jz	.nov86
471
        jz      .nov86
466
; ...it has page directory for V86 mode
472
; ...it has page directory for V86 mode
467
	mov	esi, [eax+SLOT_BASE+APPDATA.saved_esp0]
473
        mov     esi, [eax+SLOT_BASE+APPDATA.saved_esp0]
468
	mov	ecx, [esi+4]
474
        mov     ecx, [esi+4]
Line 469... Line 475...
469
	mov	[eax+SLOT_BASE+APPDATA.dir_table], ecx
475
        mov     [eax+SLOT_BASE+APPDATA.dir_table], ecx
470
; ...and I/O permission map for V86 mode
476
; ...and I/O permission map for V86 mode
471
	mov	ecx, [esi+12]
477
        mov     ecx, [esi+12]
472
	mov	[eax+SLOT_BASE+APPDATA.io_map], ecx
478
        mov     [eax+SLOT_BASE+APPDATA.io_map], ecx
473
	mov	ecx, [esi+8]
479
        mov     ecx, [esi+8]
474
	mov	[eax+SLOT_BASE+APPDATA.io_map+4], ecx
480
        mov     [eax+SLOT_BASE+APPDATA.io_map+4], ecx
475
.nov86:
481
.nov86:
476
 
482
 
477
	   mov esi, [.slot]
483
           mov esi, [.slot]
478
	   shl esi,8
484
           shl esi,8
479
	   add esi, SLOT_BASE+APP_OBJ_OFFSET
485
           add esi, SLOT_BASE+APP_OBJ_OFFSET
480
@@:
486
@@:
481
	   mov eax, [esi+APPOBJ.fd]
487
           mov eax, [esi+APPOBJ.fd]
482
	   test eax, eax
488
           test eax, eax
483
	   jz @F
489
           jz @F
484
 
490
 
485
	   cmp eax, esi
491
           cmp eax, esi
486
	   je @F
492
           je @F
487
 
493
 
488
	   push esi
494
           push esi
489
	   call [eax+APPOBJ.destroy]
495
           call [eax+APPOBJ.destroy]
490
	   DEBUGF 1,"%s",msg_obj_destroy
496
           DEBUGF 1,"%s",msg_obj_destroy
491
	   pop esi
497
           pop esi
492
	   jmp @B
498
           jmp @B
493
@@:
499
@@:
494
	   mov eax, [.slot]
500
           mov eax, [.slot]
495
	   shl eax, 8
501
           shl eax, 8
496
	   mov eax,[SLOT_BASE+eax+APPDATA.dir_table]
502
           mov eax,[SLOT_BASE+eax+APPDATA.dir_table]
497
	   stdcall destroy_app_space, eax
503
           stdcall destroy_app_space, eax
498
 
504
 
499
	   mov esi, [.slot]
505
           mov esi, [.slot]
500
	   cmp [fpu_owner],esi	 ; if user fpu last -> fpu user = 1
506
           cmp [fpu_owner],esi   ; if user fpu last -> fpu user = 1
501
	   jne @F
507
           jne @F
502
 
508
 
503
	   mov [fpu_owner],1
509
           mov [fpu_owner],1
504
	   mov eax, [256+SLOT_BASE+APPDATA.fpu_state]
510
           mov eax, [256+SLOT_BASE+APPDATA.fpu_state]
505
	   clts
511
           clts
Line 506... Line 512...
506
	   bt [cpu_caps], CAPS_SSE
512
           bt [cpu_caps], CAPS_SSE
507
	   jnc .no_SSE
513
           jnc .no_SSE
Line 508... Line 514...
508
	   fxrstor [eax]
514
           fxrstor [eax]
509
	   jmp @F
515
           jmp @F
510
.no_SSE:
516
.no_SSE:
511
	   fnclex
517
           fnclex
512
	   frstor [eax]
518
           frstor [eax]
513
@@:
519
@@:
514
 
520
 
515
    mov   [KEY_COUNT],byte 0	       ; empty keyboard buffer
521
    mov   [KEY_COUNT],byte 0           ; empty keyboard buffer
516
    mov   [BTN_COUNT],byte 0	       ; empty button buffer
522
    mov   [BTN_COUNT],byte 0           ; empty button buffer
517
 
523
 
518
 
524
 
519
; remove defined hotkeys
525
; remove defined hotkeys
520
	mov	eax, hotkey_list
526
        mov     eax, hotkey_list
521
.loop:
527
.loop:
522
	cmp	[eax+8], esi
528
        cmp     [eax+8], esi
523
	jnz	.cont
529
        jnz     .cont
524
	mov	ecx, [eax]
530
        mov     ecx, [eax]
525
	jecxz	@f
531
        jecxz   @f
526
	push	dword [eax+12]
532
        push    dword [eax+12]
527
	pop	dword [ecx+12]
533
        pop     dword [ecx+12]
528
@@:
534
@@:
529
	mov	ecx, [eax+12]
535
        mov     ecx, [eax+12]
530
	push	dword [eax]
536
        push    dword [eax]
531
	pop	dword [ecx]
537
        pop     dword [ecx]
532
	xor	ecx, ecx
538
        xor     ecx, ecx
533
	mov	[eax], ecx
539
        mov     [eax], ecx
534
	mov	[eax+4], ecx
540
        mov     [eax+4], ecx
535
	mov	[eax+8], ecx
541
        mov     [eax+8], ecx
536
	mov	[eax+12], ecx
542
        mov     [eax+12], ecx
537
.cont:
543
.cont:
538
	add	eax, 16
544
        add     eax, 16
539
	cmp	eax, hotkey_list+256*16
545
        cmp     eax, hotkey_list+256*16
540
	jb	.loop
546
        jb      .loop
Line 541... Line 547...
541
; remove hotkeys in buffer
547
; remove hotkeys in buffer
542
	mov	eax, hotkey_buffer
548
        mov     eax, hotkey_buffer
543
.loop2:
549
.loop2:
544
	cmp	[eax], esi
550
        cmp     [eax], esi
545
	jnz	.cont2
551
        jnz     .cont2
546
	and	dword [eax+4], 0
552
        and     dword [eax+4], 0
547
	and	dword [eax], 0
553
        and     dword [eax], 0
548
.cont2:
554
.cont2:
549
	add	eax, 8
555
        add     eax, 8
550
	cmp	eax, hotkey_buffer+120*8
556
        cmp     eax, hotkey_buffer+120*8
551
	jb	.loop2
557
        jb      .loop2
552
 
558
 
553
    mov   ecx,esi		  ; remove buttons
559
    mov   ecx,esi                 ; remove buttons
554
  bnewba2:
560
  bnewba2:
555
    mov   edi,[BTN_ADDR]
561
    mov   edi,[BTN_ADDR]
Line 606... Line 612...
606
    pushad
612
    pushad
607
    mov  edi, esi
613
    mov  edi, esi
608
    shl  edi, 5
614
    shl  edi, 5
609
    mov  eax, [SLOT_BASE+edi*8+APPDATA.debugger_slot]
615
    mov  eax, [SLOT_BASE+edi*8+APPDATA.debugger_slot]
610
    test eax, eax
616
    test eax, eax
611
    jz	 .nodebug
617
    jz   .nodebug
612
    push 8
618
    push 8
613
    pop  ecx
619
    pop  ecx
614
    push dword [CURRENT_TASK+edi+TASKDATA.pid]	 ; PID
620
    push dword [CURRENT_TASK+edi+TASKDATA.pid]   ; PID
615
    push 2
621
    push 2
616
    call debugger_notify
622
    call debugger_notify
617
    pop  ecx
623
    pop  ecx
618
    pop  ecx
624
    pop  ecx
619
.nodebug:
625
.nodebug:
620
    popad
626
    popad
Line 621... Line 627...
621
 
627
 
622
	   mov ebx, [.slot]
628
           mov ebx, [.slot]
623
	   shl ebx, 8
629
           shl ebx, 8
624
	   push ebx
630
           push ebx
625
	   mov ebx,[SLOT_BASE+ebx+APPDATA.pl0_stack]
631
           mov ebx,[SLOT_BASE+ebx+APPDATA.pl0_stack]
626
 
632
 
627
	   stdcall kernel_free, ebx
633
           stdcall kernel_free, ebx
628
 
634
 
629
	   pop ebx
635
           pop ebx
630
	   mov ebx,[SLOT_BASE+ebx+APPDATA.cur_dir]
636
           mov ebx,[SLOT_BASE+ebx+APPDATA.cur_dir]
631
	   stdcall kernel_free, ebx
637
           stdcall kernel_free, ebx
632
 
638
 
633
	   mov edi, [.slot]
639
           mov edi, [.slot]
634
	   shl edi,8
640
           shl edi,8
635
	   add edi,SLOT_BASE
641
           add edi,SLOT_BASE
636
 
642
 
637
	   mov eax, [edi+APPDATA.io_map]
643
           mov eax, [edi+APPDATA.io_map]
638
	   cmp eax, (tss._io_map_0-OS_BASE+PG_MAP)
644
           cmp eax, (tss._io_map_0-OS_BASE+PG_MAP)
639
	   je @F
645
           je @F
640
	   call free_page
646
           call free_page
641
@@:
647
@@:
642
	   mov eax, [edi+APPDATA.io_map+4]
648
           mov eax, [edi+APPDATA.io_map+4]
643
	   cmp eax, (tss._io_map_1-OS_BASE+PG_MAP)
649
           cmp eax, (tss._io_map_1-OS_BASE+PG_MAP)
644
	   je @F
650
           je @F
645
	   call free_page
651
           call free_page
646
@@:
652
@@:
647
	   mov eax, 0x20202020
653
           mov eax, 0x20202020
648
	   stosd
654
           stosd
649
	   stosd
655
           stosd
650
	   stosd
656
           stosd
651
	   mov ecx,244/4
657
           mov ecx,244/4
652
	   xor eax, eax
658
           xor eax, eax
Line 653... Line 659...
653
	   rep stosd
659
           rep stosd
654
 
660
 
655
  ; activate window
661
  ; activate window
656
	movzx  eax, word [WIN_STACK + esi*2]
662
        movzx  eax, word [WIN_STACK + esi*2]
657
	cmp    eax, [TASK_COUNT]
663
        cmp    eax, [TASK_COUNT]
658
	jne    .dont_activate
664
        jne    .dont_activate
659
	pushad
665
        pushad
660
 .check_next_window:
666
 .check_next_window:
661
	dec    eax
667
        dec    eax
662
	cmp    eax, 1
668
        cmp    eax, 1
663
	jbe    .nothing_to_activate
669
        jbe    .nothing_to_activate
664
	lea    esi, [WIN_POS+eax*2]
670
        lea    esi, [WIN_POS+eax*2]
665
	movzx  edi, word [esi]		     ; edi = process
671
        movzx  edi, word [esi]               ; edi = process
666
	shl    edi, 5
672
        shl    edi, 5
667
	cmp    [CURRENT_TASK + edi + TASKDATA.state], byte 9  ; skip dead slots
673
        cmp    [CURRENT_TASK + edi + TASKDATA.state], byte 9  ; skip dead slots
668
	je     .check_next_window
674
        je     .check_next_window
669
	add    edi, window_data
675
        add    edi, window_data
670
; \begin{diamond}[19.09.2006]
676
; \begin{diamond}[19.09.2006]
671
; skip minimized windows
677
; skip minimized windows
672
	test   [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
678
        test   [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
673
	jnz    .check_next_window
679
        jnz    .check_next_window
674
; \end{diamond}
680
; \end{diamond}
675
	call   waredraw
681
        call   waredraw
676
 .nothing_to_activate:
682
 .nothing_to_activate:
Line 677... Line 683...
677
	popad
683
        popad
678
 .dont_activate:
684
 .dont_activate:
679
 
685
 
680
	push	esi	; remove hd1 & cd & flp reservation
686
        push    esi     ; remove hd1 & cd & flp reservation
681
	shl	esi, 5
687
        shl     esi, 5
682
	mov	esi, [esi+CURRENT_TASK+TASKDATA.pid]
688
        mov     esi, [esi+CURRENT_TASK+TASKDATA.pid]
683
	cmp	[hd1_status], esi
689
        cmp     [hd1_status], esi
684
	jnz	@f
690
        jnz     @f
685
	call	free_hd_channel
691
        call    free_hd_channel
686
	mov	[hd1_status], 0
692
        mov     [hd1_status], 0
687
@@:
693
@@:
688
	cmp	[cd_status], esi
694
        cmp     [cd_status], esi
689
	jnz	@f
695
        jnz     @f
690
	call	free_cd_channel
696
        call    free_cd_channel
691
	mov	[cd_status], 0
697
        mov     [cd_status], 0
692
@@:
698
@@:
693
	cmp	[flp_status], esi
699
        cmp     [flp_status], esi
694
	jnz	@f
700
        jnz     @f
695
	mov	[flp_status], 0
701
        mov     [flp_status], 0
696
@@:
702
@@:
697
	pop	esi
703
        pop     esi
698
	cmp	[bgrlockpid], esi
704
        cmp     [bgrlockpid], esi
699
	jnz	@f
705
        jnz     @f
Line 700... Line 706...
700
	and	[bgrlockpid], 0
706
        and     [bgrlockpid], 0
701
	mov	[bgrlock], 0
707
        mov     [bgrlock], 0
702
@@:
708
@@:
Line 709... Line 715...
709
    xor   ebx, ebx
715
    xor   ebx, ebx
710
    xor   edx, edx
716
    xor   edx, edx
711
  newirqfree:
717
  newirqfree:
712
    cmp   [edi + 4 * ebx], eax
718
    cmp   [edi + 4 * ebx], eax
713
    jne   nofreeirq
719
    jne   nofreeirq
714
    mov   [edi + 4 * ebx], edx				; remove irq reservation
720
    mov   [edi + 4 * ebx], edx                          ; remove irq reservation
715
    mov   [irq_tab + 4 * ebx], edx			; remove irq handler
721
    mov   [irq_tab + 4 * ebx], edx                      ; remove irq handler
716
    mov   [irq_rights + 4 * ebx], edx			; set access rights to full access
722
    mov   [irq_rights + 4 * ebx], edx                   ; set access rights to full access
717
  nofreeirq:
723
  nofreeirq:
718
    inc   ebx
724
    inc   ebx
719
    cmp   ebx, 16
725
    cmp   ebx, 16
720
    jb	  newirqfree
726
    jb    newirqfree
721
    popa
727
    popa
Line 722... Line 728...
722
 
728
 
723
    pusha		      ; remove all port reservations
729
    pusha                     ; remove all port reservations
724
    mov   edx,esi
730
    mov   edx,esi
725
    shl   edx, 5
731
    shl   edx, 5
726
    add   edx,CURRENT_TASK
732
    add   edx,CURRENT_TASK
Line 727... Line 733...
727
    mov   edx,[edx+TASKDATA.pid]
733
    mov   edx,[edx+TASKDATA.pid]
Line 728... Line 734...
728
 
734
 
Line 729... Line 735...
729
  rmpr0:
735
  rmpr0:
730
 
736
 
Line 731... Line 737...
731
    mov   esi,[RESERVED_PORTS]
737
    mov   esi,[RESERVED_PORTS]
Line 732... Line 738...
732
 
738
 
733
    cmp   esi,0
739
    cmp   esi,0
734
    je	  rmpr9
740
    je    rmpr9
Line 735... Line 741...
735
 
741
 
736
  rmpr3:
742
  rmpr3:
Line 737... Line 743...
737
 
743
 
738
    mov   edi,esi
744
    mov   edi,esi
Line 739... Line 745...
739
    shl   edi,4
745
    shl   edi,4
Line 763... Line 769...
763
    jmp   rmpr0
769
    jmp   rmpr0
Line 764... Line 770...
764
 
770
 
Line 765... Line 771...
765
  rmpr9:
771
  rmpr9:
766
 
772
 
767
    popa
773
    popa
768
    mov  edi,esi	 ; do not run this process slot
774
    mov  edi,esi         ; do not run this process slot
769
    shl  edi, 5
775
    shl  edi, 5
770
    mov  [edi+CURRENT_TASK + TASKDATA.state],byte 9
776
    mov  [edi+CURRENT_TASK + TASKDATA.state],byte 9
771
; debugger test - terminate all debuggees
777
; debugger test - terminate all debuggees
772
    mov  eax, 2
778
    mov  eax, 2
773
    mov  ecx, SLOT_BASE+2*0x100+APPDATA.debugger_slot
779
    mov  ecx, SLOT_BASE+2*0x100+APPDATA.debugger_slot
774
.xd0:
780
.xd0:
775
    cmp  eax, [TASK_COUNT]
781
    cmp  eax, [TASK_COUNT]
776
    ja	 .xd1
782
    ja   .xd1
777
    cmp  dword [ecx], esi
783
    cmp  dword [ecx], esi
778
    jnz  @f
784
    jnz  @f
779
    and  dword [ecx], 0
785
    and  dword [ecx], 0
Line 803... Line 809...
803
    mov   [DONT_DRAW_MOUSE],byte 0  ; draw mouse
809
    mov   [DONT_DRAW_MOUSE],byte 0  ; draw mouse
Line 804... Line 810...
804
 
810
 
805
    mov   [application_table_status],0
811
    mov   [application_table_status],0
806
    ;mov   esi,process_terminated
812
    ;mov   esi,process_terminated
807
    ;call  sys_msg_board_str
-
 
808
    DEBUGF 1,"%s",process_terminated
813
    ;call  sys_msg_board_str
809
    add esp, 4
814
    add esp, 4
810
    ret
815
    ret
Line 811... Line 816...
811
restore .slot
816
restore .slot
812
 
817
 
813
iglobal
818
iglobal
814
  boot_sched_1	  db   'Building gdt tss pointer',0
819
  boot_sched_1    db   'Building gdt tss pointer',0
Line 815... Line 820...
815
  boot_sched_2	  db   'Building IDT table',0
820
  boot_sched_2    db   'Building IDT table',0
Line 816... Line 821...
816
endg
821
endg
817
 
822
 
818
 
823
 
Line 819... Line 824...
819
build_scheduler:
824
build_scheduler:
820
 
825
 
Line 821... Line 826...
821
	mov    esi,boot_sched_1
826
        mov    esi,boot_sched_1