Subversion Repositories Kolibri OS

Rev

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

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