Subversion Repositories Kolibri OS

Rev

Rev 66 | Rev 76 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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