Subversion Repositories Kolibri OS

Rev

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

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