Subversion Repositories Kolibri OS

Rev

Rev 160 | Rev 168 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 160 Rev 164
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                               ;;
2
;;                                                               ;;
3
;;  MenuetOS process management, protected ring3                 ;;
3
;;  MenuetOS process management, protected ring3                 ;;
4
;;                                                               ;;
4
;;                                                               ;;
5
;;  Distributed under GPL. See file COPYING for details.         ;;
5
;;  Distributed under GPL. See file COPYING for details.         ;;
6
;;  Copyright 2003 Ville Turjanmaa                               ;;
6
;;  Copyright 2003 Ville Turjanmaa                               ;;
7
;;                                                               ;;
7
;;                                                               ;;
8
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
8
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9
 
9
 
10
align 32
10
align 32
11
 
11
 
12
; GDT TABLE
12
; GDT TABLE
13
 
13
 
14
gdts:
14
gdts:
15
 
15
 
16
        dw     gdte-$-1
16
        dw     gdte-$-1
17
        dd     gdts
17
        dd     gdts
18
        dw     0
18
        dw     0
19
 
19
 
20
int_code_l:
20
int_code_l:
21
os_code_l:
21
os_code_l:
22
 
22
 
23
        dw     0xffff
23
        dw     0xffff
24
        dw     0x0000
24
        dw     0x0000
25
        db     0x00
25
        db     0x00
26
        dw     11011111b *256 +10011010b
26
        dw     11011111b *256 +10011010b
27
        db     0x00
27
        db     0x00
28
 
28
 
29
int_data_l:
29
int_data_l:
30
os_data_l:
30
os_data_l:
31
 
31
 
32
        dw     0xffff
32
        dw     0xffff
33
        dw     0x0000
33
        dw     0x0000
34
        db     0x00
34
        db     0x00
35
        dw     11011111b *256 +10010010b
35
        dw     11011111b *256 +10010010b
36
        db     0x00
36
        db     0x00
37
 
37
 
38
; --------------- APM ---------------------
38
; --------------- APM ---------------------
39
apm_code_32:
39
apm_code_32:
40
        dw     0x10        ; limit 64kb
40
        dw     0x10        ; limit 64kb
41
        db     0, 0, 0
41
        db     0, 0, 0
42
        dw     11011111b *256 +10011010b
42
        dw     11011111b *256 +10011010b
43
        db     0x00
43
        db     0x00
44
apm_code_16:
44
apm_code_16:
45
        dw     0x10
45
        dw     0x10
46
        db     0, 0, 0
46
        db     0, 0, 0
47
        dw     10011111b *256 +10011010b
47
        dw     10011111b *256 +10011010b
48
        db     0x00
48
        db     0x00
49
apm_data_16:
49
apm_data_16:
50
        dw     0x10
50
        dw     0x10
51
        db     0, 0, 0
51
        db     0, 0, 0
52
        dw     10011111b *256 +10010010b
52
        dw     10011111b *256 +10010010b
53
        db     0x00
53
        db     0x00
54
; -----------------------------------------
54
; -----------------------------------------
55
 
55
 
56
app_code_l:
56
app_code_l:
57
      dw ((0x80000000-std_application_base_address) shr 12) and 0xffff
57
      dw 0xFFFF;((0x80000000-std_application_base_address) shr 12) and 0xffff
58
      dw 0
58
      dw 0
59
      db 0
59
      db 0x40
60
      dw 11010000b*256+11111010b+256*((0x80000000-std_application_base_address) shr 28)
60
      db cpl3
61
      db std_application_base_address shr 24
61
      dw G32+D32+0x6000+0x7;
62
 
62
 
63
app_data_l:
63
app_data_l:
64
      dw (0x80000000-std_application_base_address) shr 12 and 0xffff
64
      dw 0xFFFF;(0x80000000-std_application_base_address) shr 12 and 0xffff
65
      dw 0
65
      dw 0
66
      db 0
66
      db 0x40
67
      dw 11010000b*256+11110010b+256*((0x80000000-std_application_base_address) shr 28)
67
      db drw3
68
      db std_application_base_address shr 24
68
      dw G32+D32+0x6000+0x7;
69
 
69
 
70
graph_data_l:
70
graph_data_l:
71
 
71
 
72
        dw     0x3ff
72
        dw     0x3ff
73
        dw     0x0000
73
        dw     0x0000
74
        db     0x00
74
        db     0x00
75
        dw     11010000b *256 +11110010b
75
        dw     11010000b *256 +11110010b
76
        db     0x00
76
        db     0x00
77
 
77
 
78
tss0_l:
78
tss0_l:
79
      times (max_processes+10) dd 0,0
79
      times (max_processes+10) dd 0,0
80
 
80
 
81
gdte:
81
gdte:
82
 
82
 
83
 
-
 
84
 
83
 
85
idtreg:
84
idtreg:
86
     dw   8*0x41-1
85
     dw   8*0x41-1
87
     dd   idts+8
86
     dd   idts+8
88
label idts at 0xB100-8
87
;label idts at 0xB100-8
89
 
88
 
90
 
89
 
91
 
90
 
92
uglobal
91
uglobal
93
 tss_sceleton:
92
 tss_sceleton:
94
  l.back   dw 0,0
93
  l.back   dw 0,0
95
  l.esp0   dd 0
94
  l.esp0   dd 0
96
  l.ss0    dw 0,0
95
  l.ss0    dw 0,0
97
  l.esp1   dd 0
96
  l.esp1   dd 0
98
  l.ss1    dw 0,0
97
  l.ss1    dw 0,0
99
  l.esp2   dd 0
98
  l.esp2   dd 0
100
  l.ss2    dw 0,0
99
  l.ss2    dw 0,0
101
  l.cr3    dd 0
100
  l.cr3    dd 0
102
  l.eip    dd 0
101
  l.eip    dd 0
103
  l.eflags dd 0
102
  l.eflags dd 0
104
  l.eax    dd 0
103
  l.eax    dd 0
105
  l.ecx    dd 0
104
  l.ecx    dd 0
106
  l.edx    dd 0
105
  l.edx    dd 0
107
  l.ebx    dd 0
106
  l.ebx    dd 0
108
  l.esp    dd 0
107
  l.esp    dd 0
109
  l.ebp    dd 0
108
  l.ebp    dd 0
110
  l.esi    dd 0
109
  l.esi    dd 0
111
  l.edi    dd 0
110
  l.edi    dd 0
112
  l.es     dw 0,0
111
  l.es     dw 0,0
113
  l.cs     dw 0,0
112
  l.cs     dw 0,0
114
  l.ss     dw 0,0
113
  l.ss     dw 0,0
115
  l.ds     dw 0,0
114
  l.ds     dw 0,0
116
  l.fs     dw 0,0
115
  l.fs     dw 0,0
117
  l.gs     dw 0,0
116
  l.gs     dw 0,0
118
  l.ldt    dw 0,0
117
  l.ldt    dw 0,0
119
  l.trap   dw 0
118
  l.trap   dw 0
120
  l.io     dw 0
119
  l.io     dw 0
121
endg
120
endg
122
 
121
 
123
 
122
 
124
build_process_gdt_tss_pointer:
123
build_process_gdt_tss_pointer:
125
 
124
 
126
        mov    ecx,tss_data
125
        mov    ecx,tss_data
127
        mov    edi,0
126
        mov    edi,0
128
      setgdtl2:
127
      setgdtl2:
129
        mov    [edi+gdts+ tss0 +0], word tss_step
128
        mov    [edi+gdts+ tss0 +0], word tss_step
130
        mov    [edi+gdts+ tss0 +2], cx
129
        mov    [edi+gdts+ tss0 +2], cx
131
        mov    eax,ecx
130
        mov    eax,ecx
132
        shr    eax,16
131
        shr    eax,16
133
        mov    [edi+gdts+ tss0 +4], al
132
        mov    [edi+gdts+ tss0 +4], al
134
        mov    [edi+gdts+ tss0 +7], ah
133
        mov    [edi+gdts+ tss0 +7], ah
135
        mov    [edi+gdts+ tss0 +5], word 01010000b *256 +11101001b
134
        mov    [edi+gdts+ tss0 +5], word 01010000b *256 +11101001b
136
        add    ecx,tss_step
135
        add    ecx,tss_step
137
        add    edi,8
136
        add    edi,8
138
        cmp    edi,8*(max_processes+5)
137
        cmp    edi,8*(max_processes+5)
139
        jbe    setgdtl2
138
        jbe    setgdtl2
140
 
139
 
141
        ret
140
        ret
142
 
141
 
143
 
142
 
144
build_interrupt_table:
143
build_interrupt_table:
145
 
144
 
146
        mov    edi, idts+8
145
        mov    edi, idts+8
147
        mov    esi, sys_int
146
        mov    esi, sys_int
148
        mov    ecx, 0x40
147
        mov    ecx, 0x40
149
     @@:
148
     @@:
150
        mov    eax, [esi]
149
        mov    eax, [esi]
151
        mov    [edi],   ax           ; lower part of offset
150
        mov    [edi],   ax           ; lower part of offset
152
        mov    [edi+2], word os_code ; segment selector
151
        mov    [edi+2], word os_code ; segment selector
153
        shr    eax, 16
152
        shr    eax, 16
154
        mov    [edi+4], word 10001110b shl 8 ; interrupt descriptor
153
        mov    [edi+4], word 10001110b shl 8 ; interrupt descriptor
155
        mov    [edi+6], ax
154
        mov    [edi+6], ax
156
        add    esi, 4
155
        add    esi, 4
157
        add    edi, 8
156
        add    edi, 8
158
        dec    ecx
157
        dec    ecx
159
        jnz    @b
158
        jnz    @b
160
        
159
 
161
        ;mov    edi,8*0x40+idts+8
160
        ;mov    edi,8*0x40+idts+8
162
        mov    [edi + 0], word (i40 and ((1 shl 16)-1))
161
        mov    [edi + 0], word (i40 and ((1 shl 16)-1))
163
        mov    [edi + 2], word os_code
162
        mov    [edi + 2], word os_code
164
        mov    [edi + 4], word 11101110b*256
163
        mov    [edi + 4], word 11101110b*256
165
        mov    [edi + 6], word (i40 shr 16)
164
        mov    [edi + 6], word (i40 shr 16)
166
 
165
 
167
        ret
166
        ret
168
 
-
 
169
 
-
 
170
 
167
 
171
iglobal
168
iglobal
172
  sys_int:
169
  sys_int:
-
 
170
    dd e0,debug_exc,e2,e3
-
 
171
    dd e4,e5,e6,e7
-
 
172
    dd e8,e9,e10,e11
-
 
173
    dd e12,e13,page_fault_handler,e15
173
    dd   e0,debug_exc,e2,e3,e4,e5,e6,e7,e8,e9,e10,e11,e12,e13,e14,e15
174
 
174
    dd   e16,e17
175
    dd except_16, e17
175
    times 14 dd unknown_interrupt
176
    times 14 dd unknown_interrupt
-
 
177
 
-
 
178
    dd   irq0  , irq_serv.irq_1, p_irq2 ,irq_serv.irq_3
176
 
179
    dd   p_irq4 ,irq_serv.irq_5,p_irq6,irq_serv.irq_7
177
    dd   irq0  ,irq1  ,p_irq2 ,p_irq3 ,p_irq4 ,p_irq5,p_irq6 ,p_irq7
180
    dd   irq_serv.irq_8, irq_serv.irq_9, irq_serv.irq_10
178
    dd   p_irq8,p_irq9,p_irq10,p_irq11,p_irq12,irqD  ,p_irq14,p_irq15
181
    dd   irq_serv.irq_11,p_irq12,irqD ,p_irq14,p_irq15
179
 
182
 
180
    times 16 dd unknown_interrupt
183
    times 16 dd unknown_interrupt
181
 
184
 
182
    dd   i40
185
    dd   i40
183
endg
186
endg
184
 
187
 
185
macro save_ring3_context
188
macro save_ring3_context
186
{
189
{
187
    push    ds es
190
    push    ds es
188
    pushad
191
    pushad
189
}
192
}
190
macro restore_ring3_context
193
macro restore_ring3_context
191
{
194
{
192
    popad
195
    popad
193
    pop    es ds
196
    pop    es ds
194
}
197
}
195
 
198
 
196
; simply return control to interrupted process
199
; simply return control to interrupted process
197
unknown_interrupt:
200
unknown_interrupt:
198
     iret
201
     iret
199
 
202
 
200
macro exc_wo_code [num]
203
macro exc_wo_code [num]
201
{
204
{
202
  forward
205
  forward
203
  e#num :
206
  e#num :
204
      save_ring3_context
207
      save_ring3_context
205
      mov bl, num
208
      mov bl, num
206
      jmp exc_c
209
      jmp exc_c
207
}
210
}
208
 
211
 
209
macro exc_w_code [num]
212
macro exc_w_code [num]
210
{
213
{
211
  forward
214
  forward
212
  e#num :
215
  e#num :
213
      add esp, 4
216
      add esp, 4
214
      save_ring3_context
217
      save_ring3_context
215
      mov bl, num
218
      mov bl, num
216
      jmp exc_c
219
      jmp exc_c
217
}
220
}
218
 
221
 
219
exc_wo_code 0, 1, 2, 3, 4, 5, 6, 9, 15, 16 ; 18, 19
222
exc_wo_code 0, 1, 2, 3, 4, 5, 6, 9, 15 ; 18, 19
220
exc_w_code 8, 10, 11, 12, 13, 14, 17
223
exc_w_code 8, 10, 11, 12, 13, 14, 17
221
 
224
 
222
exc_c:
225
exc_c:
223
        mov   ax, os_data
226
        mov   ax, os_data
224
        mov   ds, ax
227
        mov   ds, ax
225
        mov   es, ax
228
        mov   es, ax
226
 
229
 
227
; test if debugging
230
; test if debugging
228
        cli
231
        cli
229
        mov   eax, [0x3000]
232
        mov   eax, [0x3000]
230
        shl   eax, 8
233
        shl   eax, 8
231
        mov   eax, [0x80000+eax+APPDATA.debugger_slot]
234
        mov   eax, [0x80000+eax+APPDATA.debugger_slot]
232
        test  eax, eax
235
        test  eax, eax
233
        jnz   .debug
236
        jnz   .debug
234
        sti
237
        sti
235
; not debuggee => say error and terminate
238
; not debuggee => say error and terminate
236
        add   esp, 28h
239
        add   esp, 28h
237
        movzx eax, bl        
240
        movzx eax, bl
238
        mov   [error_interrupt], eax
241
        mov   [error_interrupt], eax
239
        call  show_error_parameters
242
        call  show_error_parameters
240
        
243
 
241
        mov   edx, [0x3010]
244
        mov   edx, [0x3010]
242
        mov   [edx + TASKDATA.state], byte 4
245
        mov   [edx + TASKDATA.state], byte 4
243
        
246
 
244
        jmp   change_task
247
        jmp   change_task
245
 
248
 
246
.debug:
249
.debug:
247
; we are debugged process, notify debugger and suspend ourself
250
; we are debugged process, notify debugger and suspend ourself
248
; eax=debugger PID
251
; eax=debugger PID
249
        cld
252
        cld
250
        movzx ecx, bl
253
        movzx ecx, bl
251
        push  ecx
254
        push  ecx
252
        mov   ecx, [0x3010]
255
        mov   ecx, [0x3010]
253
        push  dword [ecx+TASKDATA.pid]    ; PID of current process
256
        push  dword [ecx+TASKDATA.pid]    ; PID of current process
254
        push  12
257
        push  12
255
        pop   ecx
258
        pop   ecx
256
        push  1        ; 1=exception
259
        push  1        ; 1=exception
257
        call  debugger_notify
260
        call  debugger_notify
258
        pop   ecx
261
        pop   ecx
259
        pop   ecx
262
        pop   ecx
260
        pop   ecx
263
        pop   ecx
261
        mov   edx, [0x3010]
264
        mov   edx, [0x3010]
262
        mov   byte [edx+TASKDATA.state], 1        ; suspended
265
        mov   byte [edx+TASKDATA.state], 1        ; suspended
263
        call  change_task
266
        call  change_task
264
        restore_ring3_context
267
        restore_ring3_context
265
        iretd
268
        iretd
266
 
269
 
267
;;;;;;;;;;;;;;;;;;;;;;;
270
;;;;;;;;;;;;;;;;;;;;;;;
268
;; FPU ERROR HANDLER ;;
271
;; FPU ERROR HANDLER ;;
269
;;;;;;;;;;;;;;;;;;;;;;;
272
;;;;;;;;;;;;;;;;;;;;;;;
270
 
273
 
271
align 4
274
align 4
272
e7:
275
e7:
273
        save_ring3_context
276
        save_ring3_context
274
        clts
277
        clts
275
        mov   ax, os_data
278
        mov ax, os_data
276
        mov   ds, ax
279
        mov ds, ax
277
        mov   es, ax
280
        mov es, ax
278
        
281
 
-
 
282
        mov ebx, [fpu_owner]
-
 
283
        cmp ebx, [CURRENT_TASK]
-
 
284
        je .exit
-
 
285
 
-
 
286
        shl ebx, 8
-
 
287
        mov eax, [ebx+PROC_BASE+APPDATA.fpu_state]
-
 
288
        bt [cpu_caps], CAPS_FXSR
-
 
289
        jnc .no_SSE
-
 
290
 
-
 
291
        fxsave [eax]
-
 
292
        mov ebx, [CURRENT_TASK]
279
        mov   eax, [prev_user_of_fpu]
293
        mov [fpu_owner], ebx
-
 
294
        shl ebx, 8
-
 
295
        cmp dword [ebx+PROC_BASE+APPDATA.fpu_init], 0
280
        shl   eax, 8
296
        je .init
-
 
297
        mov eax, [ebx+PROC_BASE+APPDATA.fpu_state]
-
 
298
        fxrstor [eax]
-
 
299
        restore_ring3_context
-
 
300
        iret
-
 
301
.init:
-
 
302
        fninit                      ;­ ¬ ­¥ ­ã¦­ë ­¥¬ áª¨à®¢ ­­ë¥ ¨áª«î祭¨ï
-
 
303
        mov dword [ebx+PROC_BASE+APPDATA.fpu_init], 1
-
 
304
.exit:
-
 
305
        restore_ring3_context
-
 
306
        iret
281
        add   eax, 0x80000 + APPDATA.fpu_save_area
307
.no_SSE:
-
 
308
        fnsave [eax]
-
 
309
        mov ebx, [CURRENT_TASK]
-
 
310
        mov [fpu_owner], ebx
-
 
311
        shl ebx, 8
-
 
312
        cmp dword [ebx+PROC_BASE+APPDATA.fpu_init], 0
282
        fsave [eax]
-
 
283
        
313
        je .init
284
        mov   eax, [0x3000]
314
 
285
        mov   [prev_user_of_fpu], eax
-
 
286
        shl   eax, 8
-
 
287
        add   eax, 0x80000
-
 
288
        cmp   [eax + APPDATA.is_fpu_saved], 0
-
 
289
        je    @f
-
 
290
        frstor [eax+APPDATA.fpu_save_area]
-
 
291
     @@:
315
        mov eax, [ebx+PROC_BASE+APPDATA.fpu_state]
292
        mov   [eax + APPDATA.is_fpu_saved], 1
316
        frstor [eax]
293
        restore_ring3_context
317
        restore_ring3_context
294
        iret
318
        iret
295
        
319
 
296
iglobal
320
iglobal
297
  prev_user_of_fpu dd 1
321
  fpu_owner dd 1
298
endg
322
 endg
299
 
323
 
300
 
324
 
301
writehex:
325
writehex:
302
      pusha
326
      pusha
303
      
327
 
304
      mov  edi, [write_error_to]
328
      mov  edi, [write_error_to]
305
      mov  esi, 8
329
      mov  esi, 8
306
    @@:
330
    @@:
307
      mov  ecx, eax
331
      mov  ecx, eax
308
      and  ecx, 0xf
332
      and  ecx, 0xf
309
 
333
 
310
      mov  cl,[ecx+hexletters]
334
      mov  cl,[ecx+hexletters]
311
      mov  [edi],cl
335
      mov  [edi],cl
312
      dec  edi
336
      dec  edi
313
 
337
 
314
      shr  eax,4
338
      shr  eax,4
315
      dec  esi
339
      dec  esi
316
      jnz  @b
340
      jnz  @b
317
 
341
 
318
      popa
342
      popa
319
      ret
343
      ret
320
 
344
 
321
iglobal
345
iglobal
322
  hexletters  db '0123456789ABCDEF'
346
  hexletters  db '0123456789ABCDEF'
323
 
347
 
324
  error_interrupt         dd  -1
348
  error_interrupt         dd  -1
325
 
349
 
326
  process_error  db 'K : Process - forced terminate INT: 00000000',13,10,0
350
  process_error  db 'K : Process - forced terminate INT: 00000000',13,10,0
327
  process_pid    db 'K : Process - forced terminate PID: 00000000',13,10,0
351
  process_pid    db 'K : Process - forced terminate PID: 00000000',13,10,0
328
  process_eip    db 'K : Process - forced terminate EIP: 00000000',13,10,0
352
  process_eip    db 'K : Process - forced terminate EIP: 00000000',13,10,0
329
  system_error   db 'K : Kernel error',13,10,0
353
  system_error   db 'K : Kernel error',13,10,0
330
endg
354
endg
331
 
355
 
332
uglobal
356
uglobal
333
  write_error_to  dd  0x0
357
  write_error_to  dd  0x0
334
endg
358
endg
335
 
359
 
336
show_error_parameters:
360
show_error_parameters:
337
        
361
 
338
        mov    [write_error_to],process_pid+43
362
        mov    [write_error_to],process_pid+43
339
        mov    eax,[0x3000]
363
        mov    eax,[0x3000]
340
        shl    eax, 5
364
        shl    eax, 5
341
        mov    eax,[0x3000+TASKDATA.pid+eax]
365
        mov    eax,[0x3000+TASKDATA.pid+eax]
342
        call   writehex
366
        call   writehex
343
        
367
 
344
        mov    [write_error_to],process_error+43
368
        mov    [write_error_to],process_error+43
345
        mov    eax,[error_interrupt]
369
        mov    eax,[error_interrupt]
346
        call   writehex
370
        call   writehex
347
 
371
 
348
        cmp    dword [esp+4+4], os_code ; CS
372
        cmp    dword [esp+4+4], os_code ; CS
349
        jnz    @f
373
        jnz    @f
350
        mov    esi,system_error
374
        mov    esi,system_error
351
        call   sys_msg_board_str
375
        call   sys_msg_board_str
352
      @@:
376
      @@:
353
        mov    eax, [esp+4] ; EIP
377
        mov    eax, [esp+4] ; EIP
354
 
378
 
355
        mov    [write_error_to],process_eip+43
379
        mov    [write_error_to],process_eip+43
356
        call   writehex
380
        call   writehex
357
 
381
 
358
        mov    esi,process_error
382
        mov    esi,process_error
359
        call   sys_msg_board_str
383
        call   sys_msg_board_str
360
 
384
 
361
        mov    esi,process_pid
385
        mov    esi,process_pid
362
        call   sys_msg_board_str
386
        call   sys_msg_board_str
363
 
387
 
364
        mov    esi,process_eip
388
        mov    esi,process_eip
365
        call   sys_msg_board_str
389
        call   sys_msg_board_str
366
 
390
 
367
        ret
391
        ret
368
 
392
 
369
 
393
 
370
 
394
 
371
; irq1  ->  hid/keyboard.inc
395
; irq1  ->  hid/keyboard.inc
372
 
396
 
373
 
397
 
374
macro irqh [num]
398
macro irqh [num]
375
{
399
{
376
  forward
400
  forward
377
  p_irq#num :
401
  p_irq#num :
378
     save_ring3_context
402
     save_ring3_context
379
     mov   edi, num
403
     mov   edi, num
380
     jmp   irq_c
404
     jmp   irq_c
381
}
405
}
382
 
406
 
383
irqh 2,5,7,8,9,10,11
407
irqh 2,5,7,8,9,10,11
384
 
408
 
385
 irq_c:
409
 irq_c:
386
     mov   ax, os_data
410
     mov   ax, os_data
387
     mov   ds, ax
411
     mov   ds, ax
388
     mov   es, ax
412
     mov   es, ax
389
     call  irqhandler
413
     call  irqhandler
390
     restore_ring3_context
414
     restore_ring3_context
391
     iret
415
     iret
392
 
416
 
393
p_irq6:
417
p_irq6:
394
     save_ring3_context
418
     save_ring3_context
395
     mov   ax, os_data
419
     mov   ax, os_data
396
     mov   ds, ax
420
     mov   ds, ax
397
     mov   es, ax
421
     mov   es, ax
398
     call  fdc_irq
422
     call  fdc_irq
399
     call  ready_for_next_irq
423
     call  ready_for_next_irq
400
     restore_ring3_context
424
     restore_ring3_context
401
     iret
425
     iret
402
 
426
 
403
p_irq3:
427
p_irq3:
404
     save_ring3_context
428
     save_ring3_context
405
     mov   ax, os_data
429
     mov   ax, os_data
406
     mov   ds, ax
430
     mov   ds, ax
407
     mov   es, ax
431
     mov   es, ax
408
     cmp   [com2_mouse_detected],0
432
     cmp   [com2_mouse_detected],0
409
     je    old_irq3_handler
433
     je    old_irq3_handler
410
     call  check_mouse_data_com2
434
     call  check_mouse_data_com2
411
     jmp   p_irq3_1
435
     jmp   p_irq3_1
412
 old_irq3_handler:
436
 old_irq3_handler:
413
     mov   edi,3
437
     mov   edi,3
414
     call  irqhandler
438
     call  irqhandler
415
  p_irq3_1: 
439
  p_irq3_1:
416
     restore_ring3_context
440
     restore_ring3_context
417
     iret
441
     iret
418
 
442
 
419
p_irq4:
443
p_irq4:
420
     save_ring3_context
444
     save_ring3_context
421
     mov   ax, os_data
445
     mov   ax, os_data
422
     mov   ds, ax
446
     mov   ds, ax
423
     mov   es, ax
447
     mov   es, ax
424
     cmp   [com1_mouse_detected],0
448
     cmp   [com1_mouse_detected],0
425
     je    old_irq4_handler
449
     je    old_irq4_handler
426
     call  check_mouse_data_com1
450
     call  check_mouse_data_com1
427
     jmp   p_irq4_1
451
     jmp   p_irq4_1
428
 old_irq4_handler:
452
 old_irq4_handler:
429
     mov   edi,4
453
     mov   edi,4
430
     call  irqhandler
454
     call  irqhandler
431
  p_irq4_1:   
455
  p_irq4_1:
432
     restore_ring3_context
456
     restore_ring3_context
433
     iret
457
     iret
434
 
458
 
435
p_irq12:
459
p_irq12:
436
     save_ring3_context
460
     save_ring3_context
437
     mov   ax, os_data
461
     mov   ax, os_data
438
     mov   ds, ax
462
     mov   ds, ax
439
     mov   es, ax
463
     mov   es, ax
440
     call  check_mouse_data_ps2
464
     call  check_mouse_data_ps2
441
     restore_ring3_context
465
     restore_ring3_context
442
     iret
466
     iret
443
 
467
 
444
p_irq14:
468
p_irq14:
445
        save_ring3_context
469
        save_ring3_context
446
        mov     ax, os_data
470
        mov     ax, os_data
447
        mov     ds, ax
471
        mov     ds, ax
448
        mov     es, ax
472
        mov     es, ax
449
        call    [irq14_func]
473
        call    [irq14_func]
450
        call    ready_for_next_irq_1
474
        call    ready_for_next_irq_1
451
        restore_ring3_context
475
        restore_ring3_context
452
        iret
476
        iret
453
p_irq15:
477
p_irq15:
454
        save_ring3_context
478
        save_ring3_context
455
        mov     ax, os_data
479
        mov     ax, os_data
456
        mov     ds, ax
480
        mov     ds, ax
457
        mov     es, ax
481
        mov     es, ax
458
        call    [irq15_func]
482
        call    [irq15_func]
459
        call    ready_for_next_irq_1
483
        call    ready_for_next_irq_1
460
        restore_ring3_context
484
        restore_ring3_context
461
        iret
485
        iret
462
 
486
 
463
ready_for_next_irq:
487
ready_for_next_irq:
464
     mov    [check_idle_semaphore],5
488
     mov    [check_idle_semaphore],5
465
     mov   al, 0x20
489
     mov   al, 0x20
466
     out   0x20, al
490
     out   0x20, al
467
     ret
491
     ret
468
 
492
 
469
ready_for_next_irq_1:
493
ready_for_next_irq_1:
470
     mov    [check_idle_semaphore],5
494
     mov    [check_idle_semaphore],5
471
     mov   al, 0x20
495
     mov   al, 0x20
472
     out    0xa0,al
496
     out    0xa0,al
473
     out   0x20, al
497
     out   0x20, al
474
     ret
498
     ret
475
 
499
 
476
irqD:
500
irqD:
477
     save_ring3_context
501
     save_ring3_context
478
     mov   ax, os_data
502
     mov   ax, os_data
479
     mov   ds, ax
503
     mov   ds, ax
480
     mov   es, ax
504
     mov   es, ax
481
     
505
 
482
     mov   dx,0xf0
506
     mov   dx,0xf0
483
     mov   al,0
507
     mov   al,0
484
     out   dx,al
508
     out   dx,al
485
 
509
 
486
     mov   dx,0xa0
510
     mov   dx,0xa0
487
     mov   al,0x20
511
     mov   al,0x20
488
     out   dx,al
512
     out   dx,al
489
     mov   dx,0x20
513
     mov   dx,0x20
490
     out   dx,al
514
     out   dx,al
491
 
515
 
492
     restore_ring3_context
516
     restore_ring3_context
493
     
517
 
494
     iret
518
     iret
495
 
519
 
496
 
520
 
497
irqhandler:
521
irqhandler:
498
 
522
 
499
     push   edi
523
     push   edi
500
 
524
 
501
     mov    esi,edi          ; 1
525
     mov    esi,edi          ; 1
502
     shl    esi,6            ; 1
526
     shl    esi,6            ; 1
503
     add    esi,irq00read    ; 1
527
     add    esi,irq00read    ; 1
504
     shl    edi,12           ; 1
528
     shl    edi,12           ; 1
505
     add    edi,0x2E0000
529
     add    edi,0x2E0000
506
     mov    ecx,16
530
     mov    ecx,16
507
 
531
 
508
     mov    [check_idle_semaphore],5
532
     mov    [check_idle_semaphore],5
509
 
533
 
510
   irqnewread:
534
   irqnewread:
511
     dec    ecx
535
     dec    ecx
512
     js     irqover
536
     js     irqover
513
 
537
 
514
     mov    dx,[esi]         ; 2+
538
     mov    dx,[esi]         ; 2+
515
 
539
 
516
     cmp    dx,0             ; 1
540
     cmp    dx,0             ; 1
517
     jz     irqover
541
     jz     irqover
518
     cmp    [esi+3],byte 1   ; 2     ; byte read
542
     cmp    [esi+3],byte 1   ; 2     ; byte read
519
     jne    noirqbyte        ; 4-11
543
     jne    noirqbyte        ; 4-11
520
 
544
 
521
     in     al,dx
545
     in     al,dx
522
 
546
 
523
     mov    edx,[edi]
547
     mov    edx,[edi]
524
     cmp    edx,4000
548
     cmp    edx,4000
525
     je     irqfull
549
     je     irqfull
526
     mov    ebx,edi
550
     mov    ebx,edi
527
     add    ebx,0x10
551
     add    ebx,0x10
528
     add    ebx,edx
552
     add    ebx,edx
529
     mov    [ebx],al
553
     mov    [ebx],al
530
     inc    edx
554
     inc    edx
531
     mov    [edi],edx
555
     mov    [edi],edx
532
 
556
 
533
     add    esi,4
557
     add    esi,4
534
     jmp    irqnewread
558
     jmp    irqnewread
535
 
559
 
536
   noirqbyte:
560
   noirqbyte:
537
 
561
 
538
 
562
 
539
     cmp    [esi+3],byte 2     ; word read
563
     cmp    [esi+3],byte 2     ; word read
540
     jne    noirqword
564
     jne    noirqword
541
 
565
 
542
     in     ax,dx
566
     in     ax,dx
543
 
567
 
544
     mov    edx,[edi]
568
     mov    edx,[edi]
545
     cmp    edx,4000
569
     cmp    edx,4000
546
     je     irqfull
570
     je     irqfull
547
     mov    ebx,edi
571
     mov    ebx,edi
548
     add    ebx,0x10
572
     add    ebx,0x10
549
     add    ebx,edx
573
     add    ebx,edx
550
     mov    [ebx],ax
574
     mov    [ebx],ax
551
     add    edx,2
575
     add    edx,2
552
     mov    [edi],edx
576
     mov    [edi],edx
553
     add    esi,4
577
     add    esi,4
554
     jmp    irqnewread
578
     jmp    irqnewread
555
 
579
 
556
   noirqword:
580
   noirqword:
557
   irqfull:
581
   irqfull:
558
   irqover:
582
   irqover:
559
 
583
 
560
     mov    al,0x20            ; ready for next irq
584
     mov    al,0x20            ; ready for next irq
561
     out    0x20,al
585
     out    0x20,al
562
 
586
 
563
     pop    ebx
587
     pop    ebx
564
     cmp    ebx,7
588
     cmp    ebx,7
565
     jbe    noa0
589
     jbe    noa0
566
     out    0xa0,al
590
     out    0xa0,al
567
   noa0:
591
   noa0:
568
 
592
 
569
     ret
593
     ret
570
 
594
 
571
 
595
 
572
 
596
 
573
set_application_table_status:
597
set_application_table_status:
574
        push eax
598
        push eax
575
 
599
 
576
        mov  eax,[0x3000]
600
        mov  eax,[0x3000]
577
        shl  eax, 5
601
        shl  eax, 5
578
        add  eax,0x3000+TASKDATA.pid
602
        add  eax,0x3000+TASKDATA.pid
579
        mov  eax,[eax]
603
        mov  eax,[eax]
580
 
604
 
581
        mov  [application_table_status],eax
605
        mov  [application_table_status],eax
582
 
606
 
583
        pop  eax
607
        pop  eax
584
 
608
 
585
        ret
609
        ret
586
 
610
 
587
 
611
 
588
clear_application_table_status:
612
clear_application_table_status:
589
        push eax
613
        push eax
590
 
614
 
591
        mov  eax,[0x3000]
615
        mov  eax,[0x3000]
592
        shl  eax, 5
616
        shl  eax, 5
593
        add  eax,0x3000+TASKDATA.pid
617
        add  eax,0x3000+TASKDATA.pid
594
        mov  eax,[eax]
618
        mov  eax,[eax]
595
 
619
 
596
        cmp  eax,[application_table_status]
620
        cmp  eax,[application_table_status]
597
        jne  apptsl1
621
        jne  apptsl1
598
        mov  [application_table_status],0
622
        mov  [application_table_status],0
599
      apptsl1:
623
      apptsl1:
600
 
624
 
601
        pop  eax
625
        pop  eax
602
 
626
 
603
        ret
627
        ret
604
 
628
 
605
 
629
 
606
 
630
 
607
sys_resize_app_memory:
631
sys_resize_app_memory:
608
        ; eax = 1 - resize
632
        ; eax = 1 - resize
609
        ;     ebx = new amount of memory
633
        ;     ebx = new amount of memory
610
 
634
 
611
        cmp    eax,1
635
        cmp    eax,1
612
        jne    .no_application_mem_resize
636
        jne    .no_application_mem_resize
613
        
637
 
-
 
638
        stdcall new_mem_resize, ebx
614
        jmp    new_mem_resize ;resize for new type of processes
639
        mov [esp+36], eax
615
 
640
        ret
616
 
-
 
617
     .no_application_mem_resize:
641
 
618
 
642
.no_application_mem_resize:
619
        ret
643
        ret
620
 
644
 
621
 
645
 
622
 
646
 
623
get_app_params:
647
get_app_params:
624
 
648
 
625
    push eax
649
    push eax
626
 
650
 
627
    cmp  [0x90000+6],word '00'
651
    cmp  [0x90000+6],word '00'
628
    jne  no_00_header
652
    jne  no_00_header
629
 
653
 
630
    mov  eax,[0x90000+12]
654
    mov  eax,[0x90000+12]
631
    mov  [app_start],eax
655
    mov  [app_start],eax
632
    mov  eax,[0x90000+16]
656
    mov  eax,[0x90000+16]
633
    mov  [app_i_end],eax
657
    mov  [app_i_end],eax
634
    mov  eax,[0x90000+20]
658
    mov  eax,[0x90000+20]
635
    mov  [app_mem],eax
659
    mov  [app_mem],eax
636
; \begin{diamond}[20.08.2006]
660
; \begin{diamond}[20.08.2006]
637
; sanity check (functions 19,58 load app_i_end bytes and that must
661
; sanity check (functions 19,58 load app_i_end bytes and that must
638
; fit in allocated memory to prevent kernel faults)
662
; fit in allocated memory to prevent kernel faults)
639
    cmp  eax,[app_i_end]
663
    cmp  eax,[app_i_end]
640
    jb   no_01_header
664
    jb   no_01_header
641
; \end{diamond}[20.08.2006]
665
; \end{diamond}[20.08.2006]
642
    shr  eax,1
666
    shr  eax,1
643
    sub  eax,0x10
667
    sub  eax,0x10
644
    mov  [app_esp],eax
668
    mov  [app_esp],eax
645
    mov  eax,[0x90000+24]
669
    mov  eax,[0x90000+24]
646
    mov  [app_i_param],eax
670
    mov  [app_i_param],eax
647
    mov  [app_i_icon],dword 0
671
    mov  [app_i_icon],dword 0
648
 
672
 
649
    pop  eax
673
    pop  eax
650
    clc
674
    clc
651
    ret
675
    ret
652
 
676
 
653
  no_00_header:
677
  no_00_header:
654
 
678
 
655
 
679
 
656
    cmp  [0x90000+6],word '01'
680
    cmp  [0x90000+6],word '01'
657
    jne  no_01_header
681
    jne  no_01_header
658
 
682
 
659
    mov  eax,[0x90000+12]
683
    mov  eax,[0x90000+12]
660
    mov  [app_start],eax
684
    mov  [app_start],eax
661
    mov  eax,[0x90000+16]
685
    mov  eax,[0x90000+16]
662
    mov  [app_i_end],eax
686
    mov  [app_i_end],eax
663
    mov  eax,[0x90000+20]
687
    mov  eax,[0x90000+20]
664
    mov  [app_mem],eax
688
    mov  [app_mem],eax
665
; \begin{diamond}[20.08.2006]
689
; \begin{diamond}[20.08.2006]
666
    cmp  eax,[app_i_end]
690
    cmp  eax,[app_i_end]
667
    jb   no_01_header
691
    jb   no_01_header
668
; \end{diamond}[20.08.2006]
692
; \end{diamond}[20.08.2006]
669
    mov  eax,[0x90000+24]
693
    mov  eax,[0x90000+24]
670
    mov  [app_esp],eax
694
    mov  [app_esp],eax
671
    mov  eax,[0x90000+28]
695
    mov  eax,[0x90000+28]
672
    mov  [app_i_param],eax
696
    mov  [app_i_param],eax
673
    mov  eax,[0x90000+32]
697
    mov  eax,[0x90000+32]
674
    mov  [app_i_icon],eax
698
    mov  [app_i_icon],eax
675
 
699
 
676
    pop  eax
700
    pop  eax
677
    clc
701
    clc
678
    ret
702
    ret
679
 
703
 
680
   no_01_header:
704
   no_01_header:
681
 
705
 
682
    pop  eax
706
    pop  eax
683
    stc
707
    stc
684
    ret
708
    ret
685
 
709
 
686
 
710
 
687
uglobal
711
uglobal
688
  new_process_place  dd  0x0
712
  new_process_place  dd  0x0
689
  app_start    dd  0x0
713
  app_start    dd  0x0
690
  app_i_end    dd  0x0
714
  app_i_end    dd  0x0
691
  app_mem      dd  0x0
715
  app_mem      dd  0x0
692
  app_esp      dd  0x0
716
  app_esp      dd  0x0
693
  app_i_param  dd  0x0
717
  app_i_param  dd  0x0
694
  app_i_icon   dd  0x0
718
  app_i_icon   dd  0x0
695
  ;app_mem_pos  dd  0x0
719
;  app_mem_pos  dd  0x0
696
  appl_path        dd 0x0
720
  appl_path        dd 0x0
697
  appl_path_size   dd 0x0         
721
  appl_path_size   dd 0x0
698
endg
722
endg
699
 
723
 
700
 
724
 
701
sys_threads:
725
sys_threads:
702
 
726
 
703
; eax=1 create thread
727
; eax=1 create thread
704
;
728
;
705
;   ebx=thread start
729
;   ebx=thread start
706
;   ecx=thread stack value
730
;   ecx=thread stack value
707
;
731
;
708
; on return : eax = pid
732
; on return : eax = pid
709
jmp new_sys_threads
733
jmp new_sys_threads
710
 
734
 
711
iglobal
735
iglobal
712
  process_terminating   db 'K : Process - terminating',13,10,0
736
  process_terminating   db 'K : Process - terminating',13,10,0
713
  process_terminated    db 'K : Process - done',13,10,0
737
  process_terminated    db 'K : Process - done',13,10,0
714
endg
738
endg
715
 
739
 
716
 
740
 
717
terminate: ; terminate application
741
terminate: ; terminate application
718
    push   esi
742
    push   esi
719
    mov    esi,process_terminating
743
    mov    esi,process_terminating
720
    call   sys_msg_board_str
744
    call   sys_msg_board_str
721
    pop    esi
745
    pop    esi
722
 
746
 
723
@@:
747
@@:
724
    cli
748
    cli
725
    cmp   [application_table_status],0
749
    cmp   [application_table_status],0
726
    je    term9
750
    je    term9
727
    sti
751
    sti
728
    call  change_task
752
    call  change_task
729
    jmp   @b
753
    jmp   @b
730
  term9:
754
  term9:
731
 
755
 
732
    call  set_application_table_status
756
    call  set_application_table_status
733
    
757
 
734
    mov    eax,esi
758
    mov    eax,esi
735
    call   dispose_app_cr3_table
-
 
-
 
759
 
-
 
760
    pushad
-
 
761
    shl   eax,8
-
 
762
    mov   eax,[PROC_BASE+eax+0xB8]
-
 
763
    stdcall destroy_app_space, eax
-
 
764
    popad
736
 
765
 
737
    cmp   [prev_user_of_fpu],esi   ; if user fpu last -> fpu user = 1
766
    cmp   [fpu_owner],esi   ; if user fpu last -> fpu user = 1
738
    jne   fpu_ok_1
767
    jne   fpu_ok_1
739
    mov   [prev_user_of_fpu],1
768
    mov   [fpu_owner],1
740
  fpu_ok_1:
769
  fpu_ok_1:
741
 
770
 
742
    mov   [0xf400],byte 0           ; empty keyboard buffer
771
    mov   [0xf400],byte 0           ; empty keyboard buffer
743
    mov   [0xf500],byte 0           ; empty button buffer
772
    mov   [0xf500],byte 0           ; empty button buffer
744
 
773
 
745
 
774
 
746
; remove defined hotkeys
775
; remove defined hotkeys
747
        mov     eax, hotkey_list
776
        mov     eax, hotkey_list
748
.loop:
777
.loop:
749
        cmp     [eax+8], esi
778
        cmp     [eax+8], esi
750
        jnz     .cont
779
        jnz     .cont
751
        mov     ecx, [eax]
780
        mov     ecx, [eax]
752
        jecxz   @f
781
        jecxz   @f
753
        push    dword [eax+12]
782
        push    dword [eax+12]
754
        pop     dword [ecx+12]
783
        pop     dword [ecx+12]
755
@@:
784
@@:
756
        mov     ecx, [eax+12]
785
        mov     ecx, [eax+12]
757
        push    dword [eax]
786
        push    dword [eax]
758
        pop     dword [ecx]
787
        pop     dword [ecx]
759
        xor     ecx, ecx
788
        xor     ecx, ecx
760
        mov     [eax], ecx
789
        mov     [eax], ecx
761
        mov     [eax+4], ecx
790
        mov     [eax+4], ecx
762
        mov     [eax+8], ecx
791
        mov     [eax+8], ecx
763
        mov     [eax+12], ecx
792
        mov     [eax+12], ecx
764
.cont:
793
.cont:
765
        add     eax, 16
794
        add     eax, 16
766
        cmp     eax, hotkey_list+256*16
795
        cmp     eax, hotkey_list+256*16
767
        jb      .loop
796
        jb      .loop
768
; remove hotkeys in buffer
797
; remove hotkeys in buffer
769
        mov     eax, hotkey_buffer
798
        mov     eax, hotkey_buffer
770
.loop2:
799
.loop2:
771
        cmp     [eax], esi
800
        cmp     [eax], esi
772
        jnz     .cont2
801
        jnz     .cont2
773
        and     dword [eax+4], 0
802
        and     dword [eax+4], 0
774
        and     dword [eax], 0
803
        and     dword [eax], 0
775
.cont2:
804
.cont2:
776
        add     eax, 8
805
        add     eax, 8
777
        cmp     eax, hotkey_buffer+120*8
806
        cmp     eax, hotkey_buffer+120*8
778
        jb      .loop2
807
        jb      .loop2
779
 
808
 
780
    mov   ecx,esi                 ; remove buttons
809
    mov   ecx,esi                 ; remove buttons
781
  bnewba2:
810
  bnewba2:
782
    mov   edi,[0xfe88]
811
    mov   edi,[0xfe88]
783
    mov   eax,edi
812
    mov   eax,edi
784
    cld
813
    cld
785
    movzx ebx,word [edi]
814
    movzx ebx,word [edi]
786
    inc   bx
815
    inc   bx
787
  bnewba:
816
  bnewba:
788
    dec   bx
817
    dec   bx
789
    jz    bnmba
818
    jz    bnmba
790
    add   eax,0x10
819
    add   eax,0x10
791
    cmp   cx,[eax]
820
    cmp   cx,[eax]
792
    jnz   bnewba
821
    jnz   bnewba
793
    pusha
822
    pusha
794
    mov   ecx,ebx
823
    mov   ecx,ebx
795
    inc   ecx
824
    inc   ecx
796
    shl   ecx,4
825
    shl   ecx,4
797
    mov   ebx,eax
826
    mov   ebx,eax
798
    add   eax,0x10
827
    add   eax,0x10
799
    call  memmove
828
    call  memmove
800
    dec   dword [edi]
829
    dec   dword [edi]
801
    popa
830
    popa
802
    jmp   bnewba2
831
    jmp   bnewba2
803
  bnmba:
832
  bnmba:
804
 
833
 
805
    pusha     ; save window coordinates for window restoring
834
    pusha     ; save window coordinates for window restoring
806
    cld
835
    cld
807
    shl   esi,5
836
    shl   esi,5
808
    add   esi,window_data
837
    add   esi,window_data
809
    mov   eax,[esi+WDATA.box.left]
838
    mov   eax,[esi+WDATA.box.left]
810
    mov   [dlx],eax
839
    mov   [dlx],eax
811
    add   eax,[esi+WDATA.box.width]
840
    add   eax,[esi+WDATA.box.width]
812
    mov   [dlxe],eax
841
    mov   [dlxe],eax
813
    mov   eax,[esi+WDATA.box.top]
842
    mov   eax,[esi+WDATA.box.top]
814
    mov   [dly],eax
843
    mov   [dly],eax
815
    add   eax,[esi+WDATA.box.height]
844
    add   eax,[esi+WDATA.box.height]
816
    mov   [dlye],eax
845
    mov   [dlye],eax
817
 
846
 
818
    xor   eax, eax
847
    xor   eax, eax
819
    mov   [esi+WDATA.box.left],eax
848
    mov   [esi+WDATA.box.left],eax
820
    mov   [esi+WDATA.box.width],eax
849
    mov   [esi+WDATA.box.width],eax
821
    mov   [esi+WDATA.box.top],eax
850
    mov   [esi+WDATA.box.top],eax
822
    mov   [esi+WDATA.box.height],eax
851
    mov   [esi+WDATA.box.height],eax
823
    mov   [esi+WDATA.cl_workarea],eax
852
    mov   [esi+WDATA.cl_workarea],eax
824
    mov   [esi+WDATA.cl_titlebar],eax
853
    mov   [esi+WDATA.cl_titlebar],eax
825
    mov   [esi+WDATA.cl_frames],eax
854
    mov   [esi+WDATA.cl_frames],eax
826
    mov   dword [esi+WDATA.reserved],eax ; clear all flags: wstate, redraw, wdrawn
855
    mov   dword [esi+WDATA.reserved],eax ; clear all flags: wstate, redraw, wdrawn
827
    lea   edi, [esi-window_data+draw_data]
856
    lea   edi, [esi-window_data+draw_data]
828
    mov   ecx,32/4
857
    mov   ecx,32/4
829
    rep   stosd
858
    rep   stosd
830
    popa
859
    popa
831
 
860
 
832
; debuggee test
861
; debuggee test
833
    pushad
862
    pushad
834
    mov  edi, esi
863
    mov  edi, esi
835
    shl  edi, 5
864
    shl  edi, 5
836
    mov  eax, [0x80000+edi*8+APPDATA.debugger_slot]
865
    mov  eax, [0x80000+edi*8+APPDATA.debugger_slot]
837
    test eax, eax
866
    test eax, eax
838
    jz   .nodebug
867
    jz   .nodebug
839
    push 8
868
    push 8
840
    pop  ecx
869
    pop  ecx
841
    push dword [0x3000+edi+TASKDATA.pid]   ; PID
870
    push dword [0x3000+edi+TASKDATA.pid]   ; PID
842
    push 2
871
    push 2
843
    call debugger_notify
872
    call debugger_notify
844
    pop  ecx
873
    pop  ecx
845
    pop  ecx
874
    pop  ecx
846
.nodebug:
875
.nodebug:
847
    popad
876
    popad
848
 
877
 
849
    pusha         ; at 0x80000+
878
    pusha         ; at 0x80000+
850
    mov   edi,esi
879
    mov   edi,esi
851
    shl   edi,8
880
    shl   edi,8
852
    add   edi,0x80000
881
    add   edi,0x80000
853
    mov   ecx,256/4
882
    mov   ecx,256/4
854
    xor   eax, eax
883
    xor   eax, eax
855
    rep   stosd
884
    rep   stosd
856
    popa
885
    popa
857
 
886
 
858
    pusha          ; name to spaces
887
    pusha          ; name to spaces
859
    mov   edi,esi
888
    mov   edi,esi
860
    shl   edi,8
889
    shl   edi,8
861
    add   edi,0x80000+APPDATA.app_name
890
    add   edi,0x80000+APPDATA.app_name
862
    mov   ecx,11
891
    mov   ecx,11
863
    mov   eax,' '
892
    mov   eax,' '
864
    rep   stosb
893
    rep   stosb
865
    popa
894
    popa
866
 
895
 
867
 
896
 
868
  ; activate window
897
  ; activate window
869
        movzx  eax, word [0xC000 + esi*2]
898
        movzx  eax, word [0xC000 + esi*2]
870
        cmp    eax, [0x3004]
899
        cmp    eax, [0x3004]
871
        jne    .dont_activate
900
        jne    .dont_activate
872
        pushad
901
        pushad
873
 .check_next_window:
902
 .check_next_window:
874
        dec    eax
903
        dec    eax
875
        cmp    eax, 1
904
        cmp    eax, 1
876
        jbe    .nothing_to_activate
905
        jbe    .nothing_to_activate
877
        lea    esi, [0xc400+eax*2]
906
        lea    esi, [0xc400+eax*2]
878
        movzx  edi, word [esi]               ; edi = process
907
        movzx  edi, word [esi]               ; edi = process
879
        shl    edi, 5
908
        shl    edi, 5
880
        cmp    [0x3000 + edi + TASKDATA.state], byte 9  ; skip dead slots
909
        cmp    [0x3000 + edi + TASKDATA.state], byte 9  ; skip dead slots
881
        je     .check_next_window
910
        je     .check_next_window
882
        add    edi, window_data
911
        add    edi, window_data
883
; \begin{diamond}[19.09.2006]
912
; \begin{diamond}[19.09.2006]
884
; skip minimized windows
913
; skip minimized windows
885
        test    [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
914
        test   [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
886
        jnz     .check_next_window
915
        jnz    .check_next_window
887
; \end{diamond}
916
; \end{diamond}
888
        call   waredraw
917
        call   waredraw
889
 .nothing_to_activate:
918
 .nothing_to_activate:
890
        popad
919
        popad
891
 .dont_activate:
920
 .dont_activate:
892
 
921
 
893
        push    esi     ; remove hd1 & cd & flp reservation
922
        push    esi     ; remove hd1 & cd & flp reservation
894
        shl     esi, 5
923
        shl     esi, 5
895
        mov     esi, [esi+0x3000+TASKDATA.pid]
924
        mov     esi, [esi+0x3000+TASKDATA.pid]
896
        cmp     [hd1_status], esi
925
        cmp     [hd1_status], esi
897
        jnz     @f
926
        jnz     @f
898
        mov     [hd1_status], 0
927
        mov     [hd1_status], 0
899
@@:
928
@@:
900
        cmp     [cd_status], esi
929
        cmp     [cd_status], esi
901
        jnz     @f
930
        jnz     @f
902
        mov     [cd_status], 0
931
        mov     [cd_status], 0
903
@@:
932
@@:
904
        cmp     [flp_status], esi
933
        cmp     [flp_status], esi
905
        jnz     @f
934
        jnz     @f
906
        mov     [flp_status], 0
935
        mov     [flp_status], 0
907
@@:
936
@@:
908
        pop     esi
937
        pop     esi
909
 
938
 
910
    pusha ; remove all irq reservations
939
    pusha ; remove all irq reservations
911
    mov   eax,esi
940
    mov   eax,esi
912
    shl   eax, 5
941
    shl   eax, 5
913
    mov   eax,[eax+0x3000+TASKDATA.pid]
942
    mov   eax,[eax+0x3000+TASKDATA.pid]
914
    mov   edi,irq_owner
943
    mov   edi,irq_owner
915
    mov   ecx,16
944
    mov   ecx,16
916
  newirqfree:
945
  newirqfree:
917
    scasd
946
    scasd
918
    jne   nofreeirq
947
    jne   nofreeirq
919
    mov   [edi-4],dword 0
948
    mov   [edi-4],dword 0
920
  nofreeirq:
949
  nofreeirq:
921
    loop   newirqfree
950
    loop   newirqfree
922
    popa
951
    popa
923
 
952
 
924
 
953
 
925
    pusha                     ; remove all port reservations
954
    pusha                     ; remove all port reservations
926
    mov   edx,esi
955
    mov   edx,esi
927
    shl   edx, 5
956
    shl   edx, 5
928
    add   edx,0x3000
957
    add   edx,0x3000
929
    mov   edx,[edx+TASKDATA.pid]
958
    mov   edx,[edx+TASKDATA.pid]
930
 
959
 
931
  rmpr0:
960
  rmpr0:
932
 
961
 
933
    mov   esi,[0x2d0000]
962
    mov   esi,[0x2d0000]
934
 
963
 
935
    cmp   esi,0
964
    cmp   esi,0
936
    je    rmpr9
965
    je    rmpr9
937
 
966
 
938
  rmpr3:
967
  rmpr3:
939
 
968
 
940
    mov   edi,esi
969
    mov   edi,esi
941
    shl   edi,4
970
    shl   edi,4
942
    add   edi,0x2d0000
971
    add   edi,0x2d0000
943
 
972
 
944
    cmp   edx,[edi]
973
    cmp   edx,[edi]
945
    je    rmpr4
974
    je    rmpr4
946
 
975
 
947
    dec   esi
976
    dec   esi
948
    jnz   rmpr3
977
    jnz   rmpr3
949
 
978
 
950
    jmp   rmpr9
979
    jmp   rmpr9
951
 
980
 
952
  rmpr4:
981
  rmpr4:
953
 
982
 
954
    mov   ecx,256
983
    mov   ecx,256
955
    sub   ecx,esi
984
    sub   ecx,esi
956
    shl   ecx,4
985
    shl   ecx,4
957
 
986
 
958
    mov   esi,edi
987
    mov   esi,edi
959
    add   esi,16
988
    add   esi,16
960
    cld
989
    cld
961
    rep   movsb
990
    rep   movsb
962
 
991
 
963
    dec   dword [0x2d0000]
992
    dec   dword [0x2d0000]
964
 
993
 
965
    jmp   rmpr0
994
    jmp   rmpr0
966
 
995
 
967
  rmpr9:
996
  rmpr9:
968
 
997
 
969
    popa
998
    popa
970
    mov  edi,esi         ; do not run this process slot
999
    mov  edi,esi         ; do not run this process slot
971
    shl  edi, 5
1000
    shl  edi, 5
972
    mov  [edi+0x3000 + TASKDATA.state],byte 9
1001
    mov  [edi+0x3000 + TASKDATA.state],byte 9
973
; debugger test - terminate all debuggees
1002
; debugger test - terminate all debuggees
974
    mov  eax, 2
1003
    mov  eax, 2
975
    mov  ecx, 0x80000+2*0x100+APPDATA.debugger_slot
1004
    mov  ecx, 0x80000+2*0x100+APPDATA.debugger_slot
976
.xd0:
1005
.xd0:
977
    cmp  eax, [0x3004]
1006
    cmp  eax, [0x3004]
978
    ja   .xd1
1007
    ja   .xd1
979
    cmp  dword [ecx], esi
1008
    cmp  dword [ecx], esi
980
    jnz  @f
1009
    jnz  @f
981
    and  dword [ecx], 0
1010
    and  dword [ecx], 0
982
    pushad
1011
    pushad
983
    xchg eax, ebx
1012
    xchg eax, ebx
984
    mov  eax, 2
1013
    mov  eax, 2
985
    call sys_system
1014
    call sys_system
986
    popad
1015
    popad
987
@@:
1016
@@:
988
    inc  eax
1017
    inc  eax
989
    add  ecx, 0x100
1018
    add  ecx, 0x100
990
    jmp  .xd0
1019
    jmp  .xd0
991
.xd1:
1020
.xd1:
992
;    call  systest
1021
;    call  systest
993
    sti  ; .. and life goes on
1022
    sti  ; .. and life goes on
994
 
1023
 
995
    mov   eax, [dlx]
1024
    mov   eax, [dlx]
996
    mov   ebx, [dly]
1025
    mov   ebx, [dly]
997
    mov   ecx, [dlxe]
1026
    mov   ecx, [dlxe]
998
    mov   edx, [dlye]
1027
    mov   edx, [dlye]
999
    call  calculatescreen
1028
    call  calculatescreen
1000
    xor   eax, eax
1029
    xor   eax, eax
1001
    xor   esi, esi
1030
    xor   esi, esi
1002
    call  redrawscreen
1031
    call  redrawscreen
1003
 
1032
 
1004
    mov   [0xfff4],byte 0  ; no mouse background
1033
    mov   [0xfff4],byte 0  ; no mouse background
1005
    mov   [0xfff5],byte 0  ; draw mouse
1034
    mov   [0xfff5],byte 0  ; draw mouse
1006
 
1035
 
1007
    mov   [application_table_status],0
1036
    mov   [application_table_status],0
1008
    mov   esi,process_terminated
1037
    mov   esi,process_terminated
1009
    call  sys_msg_board_str
1038
    call  sys_msg_board_str
1010
 
1039
 
1011
    ret
1040
    ret
1012
 
1041
 
1013
iglobal
1042
iglobal
1014
  boot_sched_1    db   'Building gdt tss pointer',0
1043
  boot_sched_1    db   'Building gdt tss pointer',0
1015
  boot_sched_2    db   'Building IDT table',0
1044
  boot_sched_2    db   'Building IDT table',0
1016
endg
1045
endg
1017
 
1046
 
1018
 
1047
 
1019
build_scheduler:
1048
build_scheduler:
1020
 
1049
 
1021
        mov    esi,boot_sched_1
1050
        mov    esi,boot_sched_1
1022
        call   boot_log
1051
        call   boot_log
1023
        call   build_process_gdt_tss_pointer
1052
        call   build_process_gdt_tss_pointer
1024
 
1053
 
1025
        mov    esi,boot_sched_2
1054
        mov    esi,boot_sched_2
1026
        call   boot_log
1055
        call   boot_log
1027
        call   build_interrupt_table
1056
        call   build_interrupt_table
1028
 
1057
 
1029
        ret
1058
        ret