Subversion Repositories Kolibri OS

Rev

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

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