Subversion Repositories Kolibri OS

Rev

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

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