Subversion Repositories Kolibri OS

Rev

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

Rev 112 Rev 113
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+0xAC]
231
        mov   eax, [0x80000+eax+0xAC]
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 + 0xA], byte 4
242
        mov   [edx + 0xA], 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
        movzx ecx, bl
250
        movzx ecx, bl
250
        push  ecx
251
        push  ecx
251
        mov   ecx, [0x3010]
252
        mov   ecx, [0x3010]
252
        push  dword [ecx+4]    ; PID of current process
253
        push  dword [ecx+4]    ; PID of current process
253
        push  12
254
        push  12
254
        pop   ecx
255
        pop   ecx
255
        push  1        ; 1=exception
256
        push  1        ; 1=exception
256
        call  debugger_notify
257
        call  debugger_notify
257
        pop   ecx
258
        pop   ecx
258
        pop   ecx
259
        pop   ecx
259
        pop   ecx
260
        pop   ecx
260
        mov   edx, [0x3010]
261
        mov   edx, [0x3010]
261
        mov   byte [edx+0xA], 1        ; suspended
262
        mov   byte [edx+0xA], 1        ; suspended
262
        call  change_task
263
        call  change_task
263
        restore_ring3_context
264
        restore_ring3_context
264
        iretd
265
        iretd
265
 
266
 
266
;;;;;;;;;;;;;;;;;;;;;;;
267
;;;;;;;;;;;;;;;;;;;;;;;
267
;; FPU ERROR HANDLER ;;
268
;; FPU ERROR HANDLER ;;
268
;;;;;;;;;;;;;;;;;;;;;;;
269
;;;;;;;;;;;;;;;;;;;;;;;
269
 
270
 
270
align 4
271
align 4
271
e7:
272
e7:
272
        save_ring3_context
273
        save_ring3_context
273
        clts
274
        clts
274
        mov   ax, os_data
275
        mov   ax, os_data
275
        mov   ds, ax
276
        mov   ds, ax
276
        mov   es, ax
277
        mov   es, ax
277
        
278
        
278
        mov   eax, [prev_user_of_fpu]
279
        mov   eax, [prev_user_of_fpu]
279
        shl   eax, 8
280
        shl   eax, 8
280
        add   eax, 0x80000 + 0x10
281
        add   eax, 0x80000 + 0x10
281
        fsave [eax]
282
        fsave [eax]
282
        
283
        
283
        mov   eax, [0x3000]
284
        mov   eax, [0x3000]
284
        mov   [prev_user_of_fpu], eax
285
        mov   [prev_user_of_fpu], eax
285
        shl   eax, 8
286
        shl   eax, 8
286
        add   eax, 0x80000
287
        add   eax, 0x80000
287
        cmp   [eax + 0x7f], byte 0
288
        cmp   [eax + 0x7f], byte 0
288
        je    @f
289
        je    @f
289
        frstor [eax+0x10]
290
        frstor [eax+0x10]
290
     @@:
291
     @@:
291
        mov   [eax + 0x7f], byte 1
292
        mov   [eax + 0x7f], byte 1
292
        restore_ring3_context
293
        restore_ring3_context
293
        iret
294
        iret
294
        
295
        
295
iglobal
296
iglobal
296
  prev_user_of_fpu dd 1
297
  prev_user_of_fpu dd 1
297
endg
298
endg
298
 
299
 
299
 
300
 
300
writehex:
301
writehex:
301
      pusha
302
      pusha
302
      
303
      
303
      mov  edi, [write_error_to]
304
      mov  edi, [write_error_to]
304
      mov  esi, 8
305
      mov  esi, 8
305
    @@:
306
    @@:
306
      mov  ecx, eax
307
      mov  ecx, eax
307
      and  ecx, 0xf
308
      and  ecx, 0xf
308
 
309
 
309
      mov  cl,[ecx+hexletters]
310
      mov  cl,[ecx+hexletters]
310
      mov  [edi],cl
311
      mov  [edi],cl
311
      dec  edi
312
      dec  edi
312
 
313
 
313
      shr  eax,4
314
      shr  eax,4
314
      dec  esi
315
      dec  esi
315
      jnz  @b
316
      jnz  @b
316
 
317
 
317
      popa
318
      popa
318
      ret
319
      ret
319
 
320
 
320
iglobal
321
iglobal
321
  hexletters  db '0123456789ABCDEF'
322
  hexletters  db '0123456789ABCDEF'
322
 
323
 
323
  error_interrupt         dd  -1
324
  error_interrupt         dd  -1
324
 
325
 
325
  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
326
  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
327
  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
328
  system_error   db 'K : Kernel error',13,10,0
329
  system_error   db 'K : Kernel error',13,10,0
329
endg
330
endg
330
 
331
 
331
uglobal
332
uglobal
332
  write_error_to  dd  0x0
333
  write_error_to  dd  0x0
333
endg
334
endg
334
 
335
 
335
show_error_parameters:
336
show_error_parameters:
336
        
337
        
337
        mov    [write_error_to],process_pid+43
338
        mov    [write_error_to],process_pid+43
338
        mov    eax,[0x3000]
339
        mov    eax,[0x3000]
339
        shl    eax, 5
340
        shl    eax, 5
340
        mov    eax,[0x3000+4+eax]
341
        mov    eax,[0x3000+4+eax]
341
        call   writehex
342
        call   writehex
342
        
343
        
343
        mov    [write_error_to],process_error+43
344
        mov    [write_error_to],process_error+43
344
        mov    eax,[error_interrupt]
345
        mov    eax,[error_interrupt]
345
        call   writehex
346
        call   writehex
346
 
347
 
347
        cmp    dword [esp+4+4], os_code ; CS
348
        cmp    dword [esp+4+4], os_code ; CS
348
        jnz    @f
349
        jnz    @f
349
        mov    esi,system_error
350
        mov    esi,system_error
350
        call   sys_msg_board_str
351
        call   sys_msg_board_str
351
      @@:
352
      @@:
352
        mov    eax, [esp+4] ; EIP
353
        mov    eax, [esp+4] ; EIP
353
 
354
 
354
        mov    [write_error_to],process_eip+43
355
        mov    [write_error_to],process_eip+43
355
        call   writehex
356
        call   writehex
356
 
357
 
357
        mov    esi,process_error
358
        mov    esi,process_error
358
        call   sys_msg_board_str
359
        call   sys_msg_board_str
359
 
360
 
360
        mov    esi,process_pid
361
        mov    esi,process_pid
361
        call   sys_msg_board_str
362
        call   sys_msg_board_str
362
 
363
 
363
        mov    esi,process_eip
364
        mov    esi,process_eip
364
        call   sys_msg_board_str
365
        call   sys_msg_board_str
365
 
366
 
366
        ret
367
        ret
367
 
368
 
368
 
369
 
369
 
370
 
370
; irq1  ->  hid/keyboard.inc
371
; irq1  ->  hid/keyboard.inc
371
 
372
 
372
 
373
 
373
macro irqh [num]
374
macro irqh [num]
374
{
375
{
375
  forward
376
  forward
376
  p_irq#num :
377
  p_irq#num :
377
     save_ring3_context
378
     save_ring3_context
378
     mov   edi, num
379
     mov   edi, num
379
     jmp   irq_c
380
     jmp   irq_c
380
}
381
}
381
 
382
 
382
irqh 2,5,7,8,9,10,11,14,15
383
irqh 2,5,7,8,9,10,11,14,15
383
 
384
 
384
 irq_c:
385
 irq_c:
385
     mov   ax, os_data
386
     mov   ax, os_data
386
     mov   ds, ax
387
     mov   ds, ax
387
     mov   es, ax
388
     mov   es, ax
388
     call  irqhandler
389
     call  irqhandler
389
     restore_ring3_context
390
     restore_ring3_context
390
     iret
391
     iret
391
 
392
 
392
p_irq6:
393
p_irq6:
393
     save_ring3_context
394
     save_ring3_context
394
     mov   ax, os_data
395
     mov   ax, os_data
395
     mov   ds, ax
396
     mov   ds, ax
396
     mov   es, ax
397
     mov   es, ax
397
     call  fdc_irq
398
     call  fdc_irq
398
     call  ready_for_next_irq
399
     call  ready_for_next_irq
399
     restore_ring3_context
400
     restore_ring3_context
400
     iret
401
     iret
401
 
402
 
402
p_irq3:
403
p_irq3:
403
     save_ring3_context
404
     save_ring3_context
404
     mov   ax, os_data
405
     mov   ax, os_data
405
     mov   ds, ax
406
     mov   ds, ax
406
     mov   es, ax
407
     mov   es, ax
407
     cmp   [com2_mouse_detected],0
408
     cmp   [com2_mouse_detected],0
408
     je    old_irq3_handler
409
     je    old_irq3_handler
409
     call  check_mouse_data_com2
410
     call  check_mouse_data_com2
410
     jmp   p_irq3_1
411
     jmp   p_irq3_1
411
 old_irq3_handler:
412
 old_irq3_handler:
412
     mov   edi,3
413
     mov   edi,3
413
     call  irqhandler
414
     call  irqhandler
414
  p_irq3_1: 
415
  p_irq3_1: 
415
     restore_ring3_context
416
     restore_ring3_context
416
     iret
417
     iret
417
 
418
 
418
p_irq4:
419
p_irq4:
419
     save_ring3_context
420
     save_ring3_context
420
     mov   ax, os_data
421
     mov   ax, os_data
421
     mov   ds, ax
422
     mov   ds, ax
422
     mov   es, ax
423
     mov   es, ax
423
     cmp   [com1_mouse_detected],0
424
     cmp   [com1_mouse_detected],0
424
     je    old_irq4_handler
425
     je    old_irq4_handler
425
     call  check_mouse_data_com1
426
     call  check_mouse_data_com1
426
     jmp   p_irq4_1
427
     jmp   p_irq4_1
427
 old_irq4_handler:
428
 old_irq4_handler:
428
     mov   edi,4
429
     mov   edi,4
429
     call  irqhandler
430
     call  irqhandler
430
  p_irq4_1:   
431
  p_irq4_1:   
431
     restore_ring3_context
432
     restore_ring3_context
432
     iret
433
     iret
433
 
434
 
434
p_irq12:
435
p_irq12:
435
     save_ring3_context
436
     save_ring3_context
436
     mov   ax, os_data
437
     mov   ax, os_data
437
     mov   ds, ax
438
     mov   ds, ax
438
     mov   es, ax
439
     mov   es, ax
439
     call  check_mouse_data_ps2
440
     call  check_mouse_data_ps2
440
     restore_ring3_context
441
     restore_ring3_context
441
     iret
442
     iret
442
 
443
 
443
ready_for_next_irq:
444
ready_for_next_irq:
444
     mov    [check_idle_semaphore],5
445
     mov    [check_idle_semaphore],5
445
     mov   al, 0x20
446
     mov   al, 0x20
446
     out   0x20, al
447
     out   0x20, al
447
     ret
448
     ret
448
 
449
 
449
ready_for_next_irq_1:
450
ready_for_next_irq_1:
450
     mov    [check_idle_semaphore],5
451
     mov    [check_idle_semaphore],5
451
     mov   al, 0x20
452
     mov   al, 0x20
452
     out    0xa0,al
453
     out    0xa0,al
453
     out   0x20, al
454
     out   0x20, al
454
     ret
455
     ret
455
 
456
 
456
irqD:
457
irqD:
457
     save_ring3_context
458
     save_ring3_context
458
     mov   ax, os_data
459
     mov   ax, os_data
459
     mov   ds, ax
460
     mov   ds, ax
460
     mov   es, ax
461
     mov   es, ax
461
     
462
     
462
     mov   dx,0xf0
463
     mov   dx,0xf0
463
     mov   al,0
464
     mov   al,0
464
     out   dx,al
465
     out   dx,al
465
 
466
 
466
     mov   dx,0xa0
467
     mov   dx,0xa0
467
     mov   al,0x20
468
     mov   al,0x20
468
     out   dx,al
469
     out   dx,al
469
     mov   dx,0x20
470
     mov   dx,0x20
470
     out   dx,al
471
     out   dx,al
471
 
472
 
472
     restore_ring3_context
473
     restore_ring3_context
473
     
474
     
474
     iret
475
     iret
475
 
476
 
476
 
477
 
477
irqhandler:
478
irqhandler:
478
 
479
 
479
     push   edi
480
     push   edi
480
 
481
 
481
     mov    esi,edi          ; 1
482
     mov    esi,edi          ; 1
482
     shl    esi,6            ; 1
483
     shl    esi,6            ; 1
483
     add    esi,irq00read    ; 1
484
     add    esi,irq00read    ; 1
484
     shl    edi,12           ; 1
485
     shl    edi,12           ; 1
485
     add    edi,0x2E0000
486
     add    edi,0x2E0000
486
     mov    ecx,16
487
     mov    ecx,16
487
 
488
 
488
     mov    [check_idle_semaphore],5
489
     mov    [check_idle_semaphore],5
489
 
490
 
490
   irqnewread:
491
   irqnewread:
491
     dec    ecx
492
     dec    ecx
492
     js     irqover
493
     js     irqover
493
 
494
 
494
     mov    dx,[esi]         ; 2+
495
     mov    dx,[esi]         ; 2+
495
 
496
 
496
     cmp    dx,0             ; 1
497
     cmp    dx,0             ; 1
497
     jz     irqover
498
     jz     irqover
498
     cmp    [esi+3],byte 1   ; 2     ; byte read
499
     cmp    [esi+3],byte 1   ; 2     ; byte read
499
     jne    noirqbyte        ; 4-11
500
     jne    noirqbyte        ; 4-11
500
 
501
 
501
     in     al,dx
502
     in     al,dx
502
 
503
 
503
     mov    edx,[edi]
504
     mov    edx,[edi]
504
     cmp    edx,4000
505
     cmp    edx,4000
505
     je     irqfull
506
     je     irqfull
506
     mov    ebx,edi
507
     mov    ebx,edi
507
     add    ebx,0x10
508
     add    ebx,0x10
508
     add    ebx,edx
509
     add    ebx,edx
509
     mov    [ebx],al
510
     mov    [ebx],al
510
     inc    edx
511
     inc    edx
511
     mov    [edi],edx
512
     mov    [edi],edx
512
 
513
 
513
     add    esi,4
514
     add    esi,4
514
     jmp    irqnewread
515
     jmp    irqnewread
515
 
516
 
516
   noirqbyte:
517
   noirqbyte:
517
 
518
 
518
 
519
 
519
     cmp    [esi+3],byte 2     ; word read
520
     cmp    [esi+3],byte 2     ; word read
520
     jne    noirqword
521
     jne    noirqword
521
 
522
 
522
     in     ax,dx
523
     in     ax,dx
523
 
524
 
524
     mov    edx,[edi]
525
     mov    edx,[edi]
525
     cmp    edx,4000
526
     cmp    edx,4000
526
     je     irqfull
527
     je     irqfull
527
     mov    ebx,edi
528
     mov    ebx,edi
528
     add    ebx,0x10
529
     add    ebx,0x10
529
     add    ebx,edx
530
     add    ebx,edx
530
     mov    [ebx],ax
531
     mov    [ebx],ax
531
     add    edx,2
532
     add    edx,2
532
     mov    [edi],edx
533
     mov    [edi],edx
533
     add    esi,4
534
     add    esi,4
534
     jmp    irqnewread
535
     jmp    irqnewread
535
 
536
 
536
   noirqword:
537
   noirqword:
537
   irqfull:
538
   irqfull:
538
   irqover:
539
   irqover:
539
 
540
 
540
     mov    al,0x20            ; ready for next irq
541
     mov    al,0x20            ; ready for next irq
541
     out    0x20,al
542
     out    0x20,al
542
 
543
 
543
     pop    ebx
544
     pop    ebx
544
     cmp    ebx,7
545
     cmp    ebx,7
545
     jbe    noa0
546
     jbe    noa0
546
     out    0xa0,al
547
     out    0xa0,al
547
   noa0:
548
   noa0:
548
 
549
 
549
     ret
550
     ret
550
 
551
 
551
 
552
 
552
 
553
 
553
set_application_table_status:
554
set_application_table_status:
554
        push eax
555
        push eax
555
 
556
 
556
        mov  eax,[0x3000]
557
        mov  eax,[0x3000]
557
        shl  eax, 5
558
        shl  eax, 5
558
        add  eax,0x3000+4
559
        add  eax,0x3000+4
559
        mov  eax,[eax]
560
        mov  eax,[eax]
560
 
561
 
561
        mov  [application_table_status],eax
562
        mov  [application_table_status],eax
562
 
563
 
563
        pop  eax
564
        pop  eax
564
 
565
 
565
        ret
566
        ret
566
 
567
 
567
 
568
 
568
clear_application_table_status:
569
clear_application_table_status:
569
        push eax
570
        push eax
570
 
571
 
571
        mov  eax,[0x3000]
572
        mov  eax,[0x3000]
572
        shl  eax, 5
573
        shl  eax, 5
573
        add  eax,0x3000+4
574
        add  eax,0x3000+4
574
        mov  eax,[eax]
575
        mov  eax,[eax]
575
 
576
 
576
        cmp  eax,[application_table_status]
577
        cmp  eax,[application_table_status]
577
        jne  apptsl1
578
        jne  apptsl1
578
        mov  [application_table_status],0
579
        mov  [application_table_status],0
579
      apptsl1:
580
      apptsl1:
580
 
581
 
581
        pop  eax
582
        pop  eax
582
 
583
 
583
        ret
584
        ret
584
 
585
 
585
 
586
 
586
 
587
 
587
sys_resize_app_memory:
588
sys_resize_app_memory:
588
        ; eax = 1 - resize
589
        ; eax = 1 - resize
589
        ;     ebx = new amount of memory
590
        ;     ebx = new amount of memory
590
 
591
 
591
        cmp    eax,1
592
        cmp    eax,1
592
        jne    .no_application_mem_resize
593
        jne    .no_application_mem_resize
593
        
594
        
594
        jmp    new_mem_resize ;resize for new type of processes
595
        jmp    new_mem_resize ;resize for new type of processes
595
 
596
 
596
 
597
 
597
     .no_application_mem_resize:
598
     .no_application_mem_resize:
598
 
599
 
599
        ret
600
        ret
600
 
601
 
601
 
602
 
602
 
603
 
603
get_app_params:
604
get_app_params:
604
 
605
 
605
    push eax
606
    push eax
606
 
607
 
607
    cmp  [0x90000+6],word '00'
608
    cmp  [0x90000+6],word '00'
608
    jne  no_00_header
609
    jne  no_00_header
609
 
610
 
610
    mov  eax,[0x90000+12]
611
    mov  eax,[0x90000+12]
611
    mov  [app_start],eax
612
    mov  [app_start],eax
612
    mov  eax,[0x90000+16]
613
    mov  eax,[0x90000+16]
613
    mov  [app_i_end],eax
614
    mov  [app_i_end],eax
614
    mov  eax,[0x90000+20]
615
    mov  eax,[0x90000+20]
615
    mov  [app_mem],eax
616
    mov  [app_mem],eax
616
    shr  eax,1
617
    shr  eax,1
617
    sub  eax,0x10
618
    sub  eax,0x10
618
    mov  [app_esp],eax
619
    mov  [app_esp],eax
619
    mov  eax,[0x90000+24]
620
    mov  eax,[0x90000+24]
620
    mov  [app_i_param],eax
621
    mov  [app_i_param],eax
621
    mov  [app_i_icon],dword 0
622
    mov  [app_i_icon],dword 0
622
 
623
 
623
    pop  eax
624
    pop  eax
624
    mov  esi,1
625
    mov  esi,1
625
    ret
626
    ret
626
 
627
 
627
  no_00_header:
628
  no_00_header:
628
 
629
 
629
 
630
 
630
    cmp  [0x90000+6],word '01'
631
    cmp  [0x90000+6],word '01'
631
    jne  no_01_header
632
    jne  no_01_header
632
 
633
 
633
    mov  eax,[0x90000+12]
634
    mov  eax,[0x90000+12]
634
    mov  [app_start],eax
635
    mov  [app_start],eax
635
    mov  eax,[0x90000+16]
636
    mov  eax,[0x90000+16]
636
    mov  [app_i_end],eax
637
    mov  [app_i_end],eax
637
    mov  eax,[0x90000+20]
638
    mov  eax,[0x90000+20]
638
    mov  [app_mem],eax
639
    mov  [app_mem],eax
639
    mov  eax,[0x90000+24]
640
    mov  eax,[0x90000+24]
640
    mov  [app_esp],eax
641
    mov  [app_esp],eax
641
    mov  eax,[0x90000+28]
642
    mov  eax,[0x90000+28]
642
    mov  [app_i_param],eax
643
    mov  [app_i_param],eax
643
    mov  eax,[0x90000+32]
644
    mov  eax,[0x90000+32]
644
    mov  [app_i_icon],eax
645
    mov  [app_i_icon],eax
645
 
646
 
646
    pop  eax
647
    pop  eax
647
    mov  esi,1
648
    mov  esi,1
648
    ret
649
    ret
649
 
650
 
650
   no_01_header:
651
   no_01_header:
651
 
652
 
652
    pop  eax
653
    pop  eax
653
    mov  esi,0
654
    mov  esi,0
654
    ret
655
    ret
655
 
656
 
656
 
657
 
657
start_application_fl:
658
start_application_fl:
658
    jmp new_start_application_fl
659
    jmp new_start_application_fl
659
 
660
 
660
;************************************************************************
661
;************************************************************************
661
 
662
 
662
start_application_floppy:
663
start_application_floppy:
663
    jmp  new_start_application_floppy
664
    jmp  new_start_application_floppy
664
 
665
 
665
;********************************************************************
666
;********************************************************************
666
 
667
 
667
start_application_hd:
668
start_application_hd:
668
    jmp   new_start_application_hd
669
    jmp   new_start_application_hd
669
 
670
 
670
uglobal
671
uglobal
671
  new_process_place  dd  0x0
672
  new_process_place  dd  0x0
672
  app_start    dd  0x0
673
  app_start    dd  0x0
673
  app_i_end    dd  0x0
674
  app_i_end    dd  0x0
674
  app_mem      dd  0x0
675
  app_mem      dd  0x0
675
  app_esp      dd  0x0
676
  app_esp      dd  0x0
676
  app_i_param  dd  0x0
677
  app_i_param  dd  0x0
677
  app_i_icon   dd  0x0
678
  app_i_icon   dd  0x0
678
  app_mem_pos  dd  0x0
679
  app_mem_pos  dd  0x0
679
  appl_path        dd 0x0
680
  appl_path        dd 0x0
680
  appl_path_size   dd 0x0         
681
  appl_path_size   dd 0x0         
681
endg
682
endg
682
 
683
 
683
iglobal
684
iglobal
684
  hd_app_string      db  'HDAPP       '
685
  hd_app_string      db  'HDAPP       '
685
  process_loading    db 'K : Process - loading ',13,10,0
686
  process_loading    db 'K : Process - loading ',13,10,0
686
  process_running    db 'K : Process - done',13,10,0
687
  process_running    db 'K : Process - done',13,10,0
687
  first_gdt_search   dd 0x2
688
  first_gdt_search   dd 0x2
688
endg
689
endg
689
 
690
 
690
 
691
 
691
sys_threads:
692
sys_threads:
692
 
693
 
693
; eax=1 create thread
694
; eax=1 create thread
694
;
695
;
695
;   ebx=thread start
696
;   ebx=thread start
696
;   ecx=thread stack value
697
;   ecx=thread stack value
697
;
698
;
698
; on return : eax = pid
699
; on return : eax = pid
699
jmp new_sys_threads
700
jmp new_sys_threads
700
 
701
 
701
iglobal
702
iglobal
702
  process_terminating   db 'K : Process - terminating',13,10,0
703
  process_terminating   db 'K : Process - terminating',13,10,0
703
  process_terminated    db 'K : Process - done',13,10,0
704
  process_terminated    db 'K : Process - done',13,10,0
704
endg
705
endg
705
 
706
 
706
 
707
 
707
terminate: ; terminate application
708
terminate: ; terminate application
708
    push   esi
709
    push   esi
709
    mov    esi,process_terminating
710
    mov    esi,process_terminating
710
    call   sys_msg_board_str
711
    call   sys_msg_board_str
711
    pop    esi
712
    pop    esi
712
 
713
 
713
@@:
714
@@:
714
    cli
715
    cli
715
    cmp   [application_table_status],0
716
    cmp   [application_table_status],0
716
    je    term9
717
    je    term9
717
    sti
718
    sti
718
    call  change_task
719
    call  change_task
719
    jmp   @b
720
    jmp   @b
720
  term9:
721
  term9:
721
 
722
 
722
    call  set_application_table_status
723
    call  set_application_table_status
723
    
724
    
724
    mov    eax,esi
725
    mov    eax,esi
725
    call   dispose_app_cr3_table
726
    call   dispose_app_cr3_table
726
 
727
 
727
    cmp   [prev_user_of_fpu],esi   ; if user fpu last -> fpu user = 1
728
    cmp   [prev_user_of_fpu],esi   ; if user fpu last -> fpu user = 1
728
    jne   fpu_ok_1
729
    jne   fpu_ok_1
729
    mov   [prev_user_of_fpu],1
730
    mov   [prev_user_of_fpu],1
730
  fpu_ok_1:
731
  fpu_ok_1:
731
 
732
 
732
    mov   [0xf400],byte 0           ; empty keyboard buffer
733
    mov   [0xf400],byte 0           ; empty keyboard buffer
733
    mov   [0xf500],byte 0           ; empty button buffer
734
    mov   [0xf500],byte 0           ; empty button buffer
734
 
735
 
735
 
736
 
736
; remove defined hotkeys
737
; remove defined hotkeys
737
        mov     eax, hotkey_list
738
        mov     eax, hotkey_list
738
.loop:
739
.loop:
739
        cmp     [eax+8], esi
740
        cmp     [eax+8], esi
740
        jnz     .cont
741
        jnz     .cont
741
        mov     ecx, [eax]
742
        mov     ecx, [eax]
742
        jecxz   @f
743
        jecxz   @f
743
        push    dword [eax+12]
744
        push    dword [eax+12]
744
        pop     dword [ecx+12]
745
        pop     dword [ecx+12]
745
@@:
746
@@:
746
        mov     ecx, [eax+12]
747
        mov     ecx, [eax+12]
747
        push    dword [eax]
748
        push    dword [eax]
748
        pop     dword [ecx]
749
        pop     dword [ecx]
749
        xor     ecx, ecx
750
        xor     ecx, ecx
750
        mov     [eax], ecx
751
        mov     [eax], ecx
751
        mov     [eax+4], ecx
752
        mov     [eax+4], ecx
752
        mov     [eax+8], ecx
753
        mov     [eax+8], ecx
753
        mov     [eax+12], ecx
754
        mov     [eax+12], ecx
754
.cont:
755
.cont:
755
        add     eax, 16
756
        add     eax, 16
756
        cmp     eax, hotkey_list+256*16
757
        cmp     eax, hotkey_list+256*16
757
        jb      .loop
758
        jb      .loop
758
; remove hotkeys in buffer
759
; remove hotkeys in buffer
759
        mov     eax, hotkey_buffer
760
        mov     eax, hotkey_buffer
760
.loop2:
761
.loop2:
761
        cmp     [eax], esi
762
        cmp     [eax], esi
762
        jnz     .cont2
763
        jnz     .cont2
763
        and     dword [eax+4], 0
764
        and     dword [eax+4], 0
764
        and     dword [eax], 0
765
        and     dword [eax], 0
765
.cont2:
766
.cont2:
766
        add     eax, 8
767
        add     eax, 8
767
        cmp     eax, hotkey_buffer+120*8
768
        cmp     eax, hotkey_buffer+120*8
768
        jb      .loop2
769
        jb      .loop2
769
 
770
 
770
    mov   ecx,esi                 ; remove buttons
771
    mov   ecx,esi                 ; remove buttons
771
  bnewba2:
772
  bnewba2:
772
    mov   edi,[0xfe88]
773
    mov   edi,[0xfe88]
773
    mov   eax,edi
774
    mov   eax,edi
774
    cld
775
    cld
775
    movzx ebx,word [edi]
776
    movzx ebx,word [edi]
776
    inc   bx
777
    inc   bx
777
  bnewba:
778
  bnewba:
778
    dec   bx
779
    dec   bx
779
    jz    bnmba
780
    jz    bnmba
780
    add   eax,0x10
781
    add   eax,0x10
781
    cmp   cx,[eax]
782
    cmp   cx,[eax]
782
    jnz   bnewba
783
    jnz   bnewba
783
    pusha
784
    pusha
784
    mov   ecx,ebx
785
    mov   ecx,ebx
785
    inc   ecx
786
    inc   ecx
786
    shl   ecx,4
787
    shl   ecx,4
787
    mov   ebx,eax
788
    mov   ebx,eax
788
    add   eax,0x10
789
    add   eax,0x10
789
    call  memmove
790
    call  memmove
790
    dec   dword [edi]
791
    dec   dword [edi]
791
    popa
792
    popa
792
    jmp   bnewba2
793
    jmp   bnewba2
793
  bnmba:
794
  bnmba:
794
 
795
 
795
    pusha     ; save window coordinates for window restoring
796
    pusha     ; save window coordinates for window restoring
796
    cld
797
    cld
797
    shl   esi,5
798
    shl   esi,5
798
    add   esi,window_data
799
    add   esi,window_data
799
    mov   eax,[esi+WDATA.left]
800
    mov   eax,[esi+WDATA.left]
800
    mov   [dlx],eax
801
    mov   [dlx],eax
801
    add   eax,[esi+WDATA.width]
802
    add   eax,[esi+WDATA.width]
802
    mov   [dlxe],eax
803
    mov   [dlxe],eax
803
    mov   eax,[esi+WDATA.top]
804
    mov   eax,[esi+WDATA.top]
804
    mov   [dly],eax
805
    mov   [dly],eax
805
    add   eax,[esi+WDATA.height]
806
    add   eax,[esi+WDATA.height]
806
    mov   [dlye],eax
807
    mov   [dlye],eax
807
 
808
 
808
    mov   [esi+WDATA.left], 0
809
    mov   [esi+WDATA.left], 0
809
    mov   [esi+WDATA.width], 5
810
    mov   [esi+WDATA.width], 5
810
    mov   eax,[0xFE04]
811
    mov   eax,[0xFE04]
811
    mov   [esi+WDATA.top],eax
812
    mov   [esi+WDATA.top],eax
812
    mov   [esi+WDATA.height], 5
813
    mov   [esi+WDATA.height], 5
813
    xor   eax, eax
814
    xor   eax, eax
814
    mov   [esi+16],eax
815
    mov   [esi+16],eax
815
    mov   [esi+20],eax
816
    mov   [esi+20],eax
816
    mov   [esi+24],eax
817
    mov   [esi+24],eax
817
    mov   [esi+28],eax
818
    mov   [esi+28],eax
818
    lea   edi, [esi-window_data+draw_data]
819
    lea   edi, [esi-window_data+draw_data]
819
    mov   ecx,32/4
820
    mov   ecx,32/4
820
    rep   stosd
821
    rep   stosd
821
    popa
822
    popa
822
 
823
 
823
; debuggee test
824
; debuggee test
824
    pushad
825
    pushad
825
    mov  edi, esi
826
    mov  edi, esi
826
    shl  edi, 5
827
    shl  edi, 5
827
    mov  eax, [0x80000+edi*8+0xAC]
828
    mov  eax, [0x80000+edi*8+0xAC]
828
    test eax, eax
829
    test eax, eax
829
    jz   .nodebug
830
    jz   .nodebug
830
    push 8
831
    push 8
831
    pop  ecx
832
    pop  ecx
832
    push dword [0x3000+edi+0x4]   ; PID
833
    push dword [0x3000+edi+0x4]   ; PID
833
    push 2
834
    push 2
834
    call debugger_notify
835
    call debugger_notify
835
    pop  ecx
836
    pop  ecx
836
    pop  ecx
837
    pop  ecx
837
.nodebug:
838
.nodebug:
838
    popad
839
    popad
839
 
840
 
840
    pusha         ; at 0x80000+
841
    pusha         ; at 0x80000+
841
    mov   edi,esi
842
    mov   edi,esi
842
    shl   edi,8
843
    shl   edi,8
843
    add   edi,0x80000
844
    add   edi,0x80000
844
    mov   ecx,256/4
845
    mov   ecx,256/4
845
    xor   eax, eax
846
    xor   eax, eax
846
    rep   stosd
847
    rep   stosd
847
    popa
848
    popa
848
 
849
 
849
    pusha          ; name to spaces
850
    pusha          ; name to spaces
850
    mov   edi,esi
851
    mov   edi,esi
851
    shl   edi,8
852
    shl   edi,8
852
    add   edi,0x80000
853
    add   edi,0x80000
853
    mov   ecx,11
854
    mov   ecx,11
854
    mov   eax,' '
855
    mov   eax,' '
855
    rep   stosb
856
    rep   stosb
856
    popa
857
    popa
857
 
858
 
858
 
859
 
859
  ; activate window
860
  ; activate window
860
        movzx  eax, word [0xC000 + esi*2]
861
        movzx  eax, word [0xC000 + esi*2]
861
        cmp    eax, [0x3004]
862
        cmp    eax, [0x3004]
862
        jne    .dont_activate
863
        jne    .dont_activate
863
        pushad
864
        pushad
864
 .check_next_window:
865
 .check_next_window:
865
        dec    eax
866
        dec    eax
866
        cmp    eax, 1
867
        cmp    eax, 1
867
        jbe    .nothing_to_activate
868
        jbe    .nothing_to_activate
868
        lea    esi, [0xc400+eax*2]
869
        lea    esi, [0xc400+eax*2]
869
        movzx  edi, word [esi]               ; edi = process
870
        movzx  edi, word [esi]               ; edi = process
870
        shl    edi, 5
871
        shl    edi, 5
871
        cmp    [0x3000 + edi + 0xa], byte 9  ; skip dead slots
872
        cmp    [0x3000 + edi + 0xa], byte 9  ; skip dead slots
872
        je     .check_next_window
873
        je     .check_next_window
873
        add    edi, window_data
874
        add    edi, window_data
874
        call   waredraw
875
        call   waredraw
875
 .nothing_to_activate:
876
 .nothing_to_activate:
876
        popad
877
        popad
877
 .dont_activate:
878
 .dont_activate:
878
 
879
 
879
        push    esi     ; remove hd1 & cd & flp reservation
880
        push    esi     ; remove hd1 & cd & flp reservation
880
        shl     esi, 5
881
        shl     esi, 5
881
        mov     esi, [esi+0x3004]
882
        mov     esi, [esi+0x3004]
882
        cmp     [hd1_status], esi
883
        cmp     [hd1_status], esi
883
        jnz     @f
884
        jnz     @f
884
        mov     [hd1_status], 0
885
        mov     [hd1_status], 0
885
@@:
886
@@:
886
        cmp     [cd_status], esi
887
        cmp     [cd_status], esi
887
        jnz     @f
888
        jnz     @f
888
        mov     [cd_status], 0
889
        mov     [cd_status], 0
889
@@:
890
@@:
890
        cmp     [flp_status], esi
891
        cmp     [flp_status], esi
891
        jnz     @f
892
        jnz     @f
892
        mov     [flp_status], 0
893
        mov     [flp_status], 0
893
@@:
894
@@:
894
        pop     esi
895
        pop     esi
895
 
896
 
896
    pusha ; remove all irq reservations
897
    pusha ; remove all irq reservations
897
    mov   eax,esi
898
    mov   eax,esi
898
    shl   eax, 5 ;imul  edx,0x20
899
    shl   eax, 5 ;imul  edx,0x20
899
    mov   eax,[edx+0x3000+4]
900
    mov   eax,[edx+0x3000+4]
900
    mov   edi,irq_owner
901
    mov   edi,irq_owner
901
    mov   ecx,16
902
    mov   ecx,16
902
  newirqfree:
903
  newirqfree:
903
    scasd
904
    scasd
904
    jne   nofreeirq
905
    jne   nofreeirq
905
    mov   [edi-4],dword 0
906
    mov   [edi-4],dword 0
906
  nofreeirq:
907
  nofreeirq:
907
    loop   newirqfree
908
    loop   newirqfree
908
    popa
909
    popa
909
 
910
 
910
 
911
 
911
    pusha                     ; remove all port reservations
912
    pusha                     ; remove all port reservations
912
    mov   edx,esi
913
    mov   edx,esi
913
    shl   edx, 5 ;imul  edx,0x20
914
    shl   edx, 5 ;imul  edx,0x20
914
    add   edx,0x3000
915
    add   edx,0x3000
915
    mov   edx,[edx+4]
916
    mov   edx,[edx+4]
916
 
917
 
917
  rmpr0:
918
  rmpr0:
918
 
919
 
919
    mov   esi,[0x2d0000]
920
    mov   esi,[0x2d0000]
920
 
921
 
921
    cmp   esi,0
922
    cmp   esi,0
922
    je    rmpr9
923
    je    rmpr9
923
 
924
 
924
  rmpr3:
925
  rmpr3:
925
 
926
 
926
    mov   edi,esi
927
    mov   edi,esi
927
    shl   edi,4
928
    shl   edi,4
928
    add   edi,0x2d0000
929
    add   edi,0x2d0000
929
 
930
 
930
    cmp   edx,[edi]
931
    cmp   edx,[edi]
931
    je    rmpr4
932
    je    rmpr4
932
 
933
 
933
    dec   esi
934
    dec   esi
934
    jnz   rmpr3
935
    jnz   rmpr3
935
 
936
 
936
    jmp   rmpr9
937
    jmp   rmpr9
937
 
938
 
938
  rmpr4:
939
  rmpr4:
939
 
940
 
940
    mov   ecx,256
941
    mov   ecx,256
941
    sub   ecx,esi
942
    sub   ecx,esi
942
    shl   ecx,4
943
    shl   ecx,4
943
 
944
 
944
    mov   esi,edi
945
    mov   esi,edi
945
    add   esi,16
946
    add   esi,16
946
    cld
947
    cld
947
    rep   movsb
948
    rep   movsb
948
 
949
 
949
    dec   dword [0x2d0000]
950
    dec   dword [0x2d0000]
950
 
951
 
951
    jmp   rmpr0
952
    jmp   rmpr0
952
 
953
 
953
  rmpr9:
954
  rmpr9:
954
 
955
 
955
    popa
956
    popa
956
    mov  edi,esi         ; do not run this process slot
957
    mov  edi,esi         ; do not run this process slot
957
    shl  edi, 5
958
    shl  edi, 5
958
    mov  [edi+0x300A],byte 9
959
    mov  [edi+0x300A],byte 9
959
; debugger test - terminate all debuggees
960
; debugger test - terminate all debuggees
960
    mov  eax, 2
961
    mov  eax, 2
961
    mov  ecx, 0x80000+2*0x100+0xAC
962
    mov  ecx, 0x80000+2*0x100+0xAC
962
.xd0:
963
.xd0:
963
    cmp  eax, [0x3004]
964
    cmp  eax, [0x3004]
964
    ja   .xd1
965
    ja   .xd1
965
    cmp  dword [ecx], esi
966
    cmp  dword [ecx], esi
966
    jnz  @f
967
    jnz  @f
967
    and  dword [ecx], 0
968
    and  dword [ecx], 0
968
    pushad
969
    pushad
969
    xchg eax, ebx
970
    xchg eax, ebx
970
    mov  eax, 2
971
    mov  eax, 2
971
    call sys_system
972
    call sys_system
972
    popad
973
    popad
973
@@:
974
@@:
974
    inc  eax
975
    inc  eax
975
    add  ecx, 0x100
976
    add  ecx, 0x100
976
    jmp  .xd0
977
    jmp  .xd0
977
.xd1:
978
.xd1:
978
;    call  systest
979
;    call  systest
979
    sti  ; .. and life goes on
980
    sti  ; .. and life goes on
980
 
981
 
981
    mov   eax, [dlx]
982
    mov   eax, [dlx]
982
    mov   ebx, [dly]
983
    mov   ebx, [dly]
983
    mov   ecx, [dlxe]
984
    mov   ecx, [dlxe]
984
    mov   edx, [dlye]
985
    mov   edx, [dlye]
985
    call  calculatescreen
986
    call  calculatescreen
986
    xor   eax, eax
987
    xor   eax, eax
987
    xor   esi, esi
988
    xor   esi, esi
988
    call  redrawscreen
989
    call  redrawscreen
989
 
990
 
990
    mov   [0xfff4],byte 0  ; no mouse background
991
    mov   [0xfff4],byte 0  ; no mouse background
991
    mov   [0xfff5],byte 0  ; draw mouse
992
    mov   [0xfff5],byte 0  ; draw mouse
992
 
993
 
993
    mov   [application_table_status],0
994
    mov   [application_table_status],0
994
    mov   esi,process_terminated
995
    mov   esi,process_terminated
995
    call  sys_msg_board_str
996
    call  sys_msg_board_str
996
 
997
 
997
    ret
998
    ret
998
 
999
 
999
iglobal
1000
iglobal
1000
  boot_sched_1    db   'Building gdt tss pointer',0
1001
  boot_sched_1    db   'Building gdt tss pointer',0
1001
  boot_sched_2    db   'Building IDT table',0
1002
  boot_sched_2    db   'Building IDT table',0
1002
endg
1003
endg
1003
 
1004
 
1004
 
1005
 
1005
build_scheduler:
1006
build_scheduler:
1006
 
1007
 
1007
        mov    esi,boot_sched_1
1008
        mov    esi,boot_sched_1
1008
        call   boot_log
1009
        call   boot_log
1009
        call   build_process_gdt_tss_pointer
1010
        call   build_process_gdt_tss_pointer
1010
 
1011
 
1011
        mov    esi,boot_sched_2
1012
        mov    esi,boot_sched_2
1012
        call   boot_log
1013
        call   boot_log
1013
        call   build_interrupt_table
1014
        call   build_interrupt_table
1014
 
1015
 
1015
        ret
1016
        ret