Subversion Repositories Kolibri OS

Rev

Rev 2 | Rev 4 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  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. graph_data_l:
  39.  
  40.         dw     0x3ff
  41.         dw     0x0000
  42.         db     0x00
  43.         dw     11010000b *256 +11110010b
  44.         db     0x00
  45.  
  46. tss0_l:
  47.       times (max_processes+10) dd 0,0
  48.  
  49. tss0i_l:
  50.       times 0x41 dq 0 ;(256+10) dd 0,0
  51.  
  52. app_code_l:
  53.       times (max_processes+10) dd 0,0
  54.  
  55. app_data_l:
  56.       times (max_processes+10) dd 0,0
  57.  
  58. tss0sys_l:
  59.       times (max_processes+10) dd 0,0
  60.  
  61. gdte:
  62.  
  63.  
  64.  
  65. ; <IP 05.02.2005>
  66. idtreg:
  67.      dw   8*0x41-1
  68.      dd   idts+8
  69.  
  70. label idts at 0xB100-8
  71. ;idte = idts + 8 + 0x60
  72.  
  73. ; </IP> ; old code below:
  74.  
  75.  
  76. ;align 32
  77.  
  78. ;idts:
  79. ;      dw  idte-$-1
  80. ;      dd  idts+8
  81. ;      dw  0
  82.  
  83. ;      times 0x62 dd 0,0
  84.  
  85. ;idte:
  86.  
  87. build_process_gdt_tss_pointer:
  88.  
  89.         mov    ecx,tss_data
  90.         mov    edi,0
  91.       setgdtl2:
  92.         mov    [edi+gdts+ tss0 +0], word tss_step
  93.         mov    [edi+gdts+ tss0 +2], cx
  94.         mov    eax,ecx
  95.         shr    eax,16
  96.         mov    [edi+gdts+ tss0 +4], al
  97.         mov    [edi+gdts+ tss0 +7], ah
  98.         mov    [edi+gdts+ tss0 +5], word 01010000b *256 +11101001b
  99.         add    ecx,tss_step
  100.         add    edi,8
  101.         cmp    edi,8*(max_processes+5)
  102.         jbe    setgdtl2
  103.  
  104.         ret
  105.  
  106. ;build_process_gdt_gate_pointer:
  107.  
  108. ;        mov    edi,0
  109. ;        mov    dx,tss0
  110. ;      setidtl1:
  111. ;        mov    ecx,[esi]
  112. ;        mov    [edi+gdts+ tss0t +0], word 0
  113. ;        mov    [edi+gdts+ tss0t +2], dx
  114. ;        mov    [edi+gdts+ tss0t +4], word 11100101b*256
  115. ;        mov    [edi+gdts+ tss0t +6], word 0
  116. ;        add    dx,8
  117. ;        add    edi,8
  118. ;        cmp    edi,8*(max_processes+5)
  119. ;        jb     setidtl1
  120.  
  121. ;        ret
  122.  
  123. build_interrupt_table:
  124.  
  125.         mov  [l.eflags],dword 0x11002
  126.         mov  [l.ss0], int_data
  127.         ;mov  [l.ss1], ring1_data
  128.         ;mov  [l.ss2], ring2_data
  129.         mov  [l.esp0], 0x52000
  130.         mov  [l.esp1], 0x53000
  131.         mov  [l.esp2], 0x54000
  132.  
  133.         mov  eax,cr3
  134.         mov  [l.cr3],eax
  135.         mov  [l.cs],int_code
  136.         mov  [l.ss],int_data
  137.         mov  [l.ds],int_data
  138.         mov  [l.es],int_data
  139.         mov  [l.fs],int_data
  140.         mov  [l.gs],int_data
  141.  
  142.         mov  eax,sys_int
  143.         mov  [l.esp],0x720000
  144.         mov  edi,0x290000
  145.  
  146.      newint:
  147.         push edi
  148.         mov  ebx,[eax]
  149.         mov  [l.eip],ebx
  150.         mov  esi,tss_sceleton
  151.         mov  ecx,120/4
  152.         cld
  153.         rep  movsd
  154.         pop  edi
  155.  
  156.         add  edi,128
  157.         add  [l.esp],1024
  158.         add  eax,4
  159.  
  160.         cmp  eax,sys_int+4*0x40 ;0x60
  161.         jbe  newint  ;jb
  162.  
  163. ;;
  164.  
  165.         mov    esi,boot_sched_3_2
  166.         call   boot_log
  167.  
  168.         mov    ecx,0x290000
  169.         mov    edi,0
  170.       setgdtl2i:
  171.         mov    [edi+gdts+ tss0i +0], word 128
  172.         mov    [edi+gdts+ tss0i +2], cx
  173.         mov    eax,ecx
  174.         shr    eax,16
  175.         mov    [edi+gdts+ tss0i +4], al
  176.         mov    [edi+gdts+ tss0i +7], ah
  177.         mov    [edi+gdts+ tss0i +5], word 01010000b *256 +11101001b
  178.         add    ecx,128
  179.         add    edi,8
  180.         cmp    edi,8*0x40 ;0x60
  181.         jbe    setgdtl2i
  182.  
  183. ;;
  184.  
  185.         mov    esi,boot_sched_3_3
  186.         call   boot_log
  187.  
  188.         mov    edi,0
  189.         mov    edx,tss0i
  190.       setidtl2:
  191.         mov    [edi+idts+ 8 +0], word 0
  192.         mov    [edi+idts+ 8 +2], dx
  193.         mov    [edi+idts+ 8 +4], word 10000101b*256 ; task gate DPL=0
  194. ;        cmp    edi,0x40*8
  195. ;        jne    no_sw_int
  196. ;        mov    [edi+idts+ 8 +4], word 11100101b*256 ; task gate DPL=3
  197. ;      no_sw_int:
  198.         mov    [edi+idts+ 8 +6], word 0
  199.         add    edx,8
  200.         add    edi,8
  201.  
  202.         cmp    edi,8*0x40 ;0x60
  203.         jbe    setidtl2 ;jb
  204.  
  205. ; <Ivan Poddubny 06.02.2005>
  206. ; THIS CODE WON'T WORK ;-(
  207. ; because each process's 0-level stack points to the same area
  208. ; and if task switch occurs and another process is being interrupted
  209. ; a stack overflow happens
  210. ; The only way to solve that problem is to disable interrupts
  211. ; while 0x40-handler is working
  212. ; Then we have to make all entries in the IDT INTERRUPT gates, not TASK
  213. ;        mov    edi, idts+8
  214. ;        mov    esi, sys_int
  215. ;        mov    ecx, 32
  216. ;     @@:
  217. ;        mov    eax, [esi]
  218. ;        mov    [edi],   ax           ; lower part of offset
  219. ;        mov    [edi+2], word os_code ; segment selector
  220. ;        shr    eax, 16
  221. ;        mov    [edi+4], word 10001110b shl 8 ; interrupt descriptor
  222. ;        mov    [edi+6], ax
  223. ;        add    esi, 4
  224. ;        add    edi, 8
  225. ;        dec    ecx
  226. ;        jnz    @b
  227. ; </Ivan Poddubny>
  228.  
  229.         ret
  230.  
  231. build_syscall_interrupt_table:
  232.  
  233.         mov  [l.eflags],dword 0x11002
  234.         mov  [l.ss0], int_data   ;code
  235.         ;mov  [l.ss1], ring1_data ;code
  236.         ;mov  [l.ss2], ring2_data ;code
  237.         mov  [l.esp0], 0x52000
  238.         mov  [l.esp1], 0x53000
  239.         mov  [l.esp2], 0x54000
  240.  
  241.         mov  eax,cr3
  242.         mov  [l.cr3],eax
  243.         mov  [l.cs],int_code
  244.         mov  [l.ss],int_data
  245.         mov  [l.ds],int_data
  246.         mov  [l.es],int_data
  247.         mov  [l.fs],int_data
  248.         mov  [l.gs],int_data
  249.  
  250.         mov  [l.esp],sysint_stack_data
  251.         mov  edi,0x298000
  252.  
  253.      newint2:
  254.         push edi
  255.         mov  ebx,i40
  256.         mov  [l.eip],ebx
  257.         mov  esi,tss_sceleton
  258.         mov  ecx,120/4
  259.         cld
  260.         rep  movsd
  261.         pop  edi
  262.  
  263.         add  [l.esp],4096
  264.         add  edi,128
  265.         ;add  eax,4
  266.  
  267.         cmp  edi,0x298000+128*(max_processes+5)
  268.         jb   newint2
  269.  
  270. ;;
  271.  
  272.         mov    ecx,0x298000
  273.         mov    edi,0
  274.       setgdtl2i2:
  275.         mov    [edi+gdts+ tss0sys +0], word 128
  276.         mov    [edi+gdts+ tss0sys +2], cx
  277.         mov    eax,ecx
  278.         shr    eax,16
  279.         mov    [edi+gdts+ tss0sys +4], al
  280.         mov    [edi+gdts+ tss0sys +7], ah
  281.         mov    [edi+gdts+ tss0sys +5], word 01010000b *256 +11101001b
  282.         add    ecx,128
  283.         add    edi,8
  284.         cmp    edi,8*(max_processes+5)
  285.         jbe    setgdtl2i2
  286.  
  287. ;;
  288.  
  289.         ;mov    dx,tss0sys
  290.         mov    edi,8*0x40+idts+8
  291.         mov    [edi + 0], word (i40 and ((1 shl 16)-1))
  292.         mov    [edi + 2], word os_code
  293.         mov    [edi + 4], word 11101110b*256
  294.         mov    [edi + 6], word (i40 shr 16)
  295.  
  296.         mov    edi,8*0x38+idts+8
  297.         mov    eax, i38
  298.         mov    [edi],   ax           ; lower part of offset
  299.         mov    [edi+2], word os_code ; segment selector
  300.         shr    eax, 16
  301.         mov    [edi+4], word 11101110b shl 8 ; 32-bit interrupt gate, DPL 3
  302.         mov    [edi+6], ax
  303.  
  304.         ret
  305.  
  306.  
  307. align 4
  308. i38:
  309.         ; load data selectors
  310.         pushfd
  311.         push    ds es
  312.         push    eax
  313.         mov     ax, os_data
  314.         mov     ds, ax
  315.         mov     es, ax
  316.         pop     eax
  317.  
  318.         pushad
  319.         push    edi
  320.         mov     edi, eax
  321.         mov     eax, ebx
  322.         mov     ebx, ecx
  323.         mov     ecx, edx
  324.         mov     esi, [esp]
  325.         and     edi, 0xFF
  326.         call    dword [servetable+edi*4]
  327.         add     esp, 4
  328.         popad
  329.         pop     es ds
  330.         popfd
  331. iret
  332.  
  333.  
  334. iglobal
  335.   sys_int:
  336.     dd   s0,s1,s2,s3,s4,s5,s6,s7,s8,s9,sa,sb,sc,sd,se,sf
  337.  
  338.     dd   s10        ,s11      ;  ,i_unknown12,i_unknown13
  339. ;    dd   i_unknown14,i_unknown15,i_unknown16,i_unknown17
  340. ;    dd   i_unknown18,i_unknown19,i_unknown1a,i_unknown1b
  341. ;    dd   i_unknown1c,i_unknown1d,i_unknown1e,i_unknown1f
  342.     times 14 dd unknown_interrupt
  343.  
  344.     dd   irq0  ,irq1  ,p_irq2 ,p_irq3 ,p_irq4 ,p_irq5,p_irq6 ,p_irq7
  345.     dd   p_irq8,p_irq9,p_irq10,p_irq11,p_irq12,irqD  ,p_irq14,p_irq15
  346.  
  347.     ;dd   i_unknown30,i_unknown31,i_unknown32,i_unknown33
  348.     ;dd   i_unknown34,i_unknown35,i_unknown36,i_unknown37
  349.     ;dd   i_unknown38,i_unknown39,i_unknown3a,i_unknown3b
  350.     ;dd   i_unknown3c,i_unknown3d,i_unknown3e,i_unknown3f
  351.     times 16 dd unknown_interrupt
  352.  
  353.     dd   i40
  354. endg
  355.  
  356. uglobal
  357.  tss_sceleton:
  358.   l.back   dw 0,0
  359.   l.esp0   dd 0
  360.   l.ss0    dw 0,0
  361.   l.esp1   dd 0
  362.   l.ss1    dw 0,0
  363.   l.esp2   dd 0
  364.   l.ss2    dw 0,0
  365.   l.cr3    dd 0
  366.   l.eip    dd 0
  367.   l.eflags dd 0
  368.   l.eax    dd 0
  369.   l.ecx    dd 0
  370.   l.edx    dd 0
  371.   l.ebx    dd 0
  372.   l.esp    dd 0
  373.   l.ebp    dd 0
  374.   l.esi    dd 0
  375.   l.edi    dd 0
  376.   l.es     dw 0,0
  377.   l.cs     dw 0,0
  378.   l.ss     dw 0,0
  379.   l.ds     dw 0,0
  380.   l.fs     dw 0,0
  381.   l.gs     dw 0,0
  382.   l.ldt    dw 0,0
  383.   l.trap   dw 0
  384.   l.io     dw 0
  385. endg
  386.  
  387. s0:
  388.         cli
  389.  
  390.         mov   [error_interrupt],0x0
  391.         mov   [error_interrupt_entry],dword s0
  392.  
  393.         call  show_error_parameters
  394.  
  395.         mov   edx,[0x3010]
  396.         mov   [edx+0xa],byte 4
  397.  
  398.         jmp   change_task
  399.  
  400.  
  401. s1:
  402.         cli
  403.  
  404.         mov   [error_interrupt],0x1
  405.         mov   [error_interrupt_entry],dword s1
  406.  
  407.         call  show_error_parameters
  408.  
  409.         mov   edx,[0x3010]
  410.         mov   [edx+0xa],byte 4
  411.  
  412.         jmp   change_task
  413.  
  414. s2:
  415.         cli
  416.  
  417.         mov   [error_interrupt],0x2
  418.         mov   [error_interrupt_entry],dword s2
  419.  
  420.         call  show_error_parameters
  421.  
  422.         mov   edx,[0x3010]
  423.         mov   [edx+0xa],byte 4
  424.  
  425.         jmp   change_task
  426.  
  427. s3:
  428.         cli
  429.  
  430.         mov   [error_interrupt],0x3
  431.         mov   [error_interrupt_entry],dword s3
  432.  
  433.         call  show_error_parameters
  434.  
  435.         mov   edx,[0x3010]
  436.         mov   [edx+0xa],byte 4
  437.  
  438.         jmp   change_task
  439.  
  440. s4:
  441.         cli
  442.  
  443.         mov   [error_interrupt],0x4
  444.         mov   [error_interrupt_entry],dword s4
  445.  
  446.         call  show_error_parameters
  447.  
  448.         mov   edx,[0x3010]
  449.         mov   [edx+0xa],byte 4
  450.  
  451.         jmp   change_task
  452.  
  453. s5:
  454.         cli
  455.  
  456.         mov   [error_interrupt],0x5
  457.         mov   [error_interrupt_entry],dword s5
  458.  
  459.         call  show_error_parameters
  460.  
  461.         mov   edx,[0x3010]
  462.         mov   [edx+0xa],byte 4
  463.  
  464.         jmp   change_task
  465.  
  466. s6:
  467.         cli
  468.  
  469.         mov   [error_interrupt],0x6
  470.         mov   [error_interrupt_entry],dword s6
  471.  
  472.         call  show_error_parameters
  473.  
  474.         mov   edx,[0x3010]
  475.         mov   [edx+0xa],byte 4
  476.  
  477.         jmp   change_task
  478.  
  479.  
  480. ;;;;;;;;;;;;;;;;;;;;;;;
  481. ;; FPU ERROR HANDLER ;;
  482. ;;;;;;;;;;;;;;;;;;;;;;;
  483.  
  484. align 4
  485. s7:
  486.         ; <IP 05.02.2004>
  487.         cli
  488.         ; </IP>
  489.         mov    edi, 7*8
  490.         mov    [edi+gdts+ tss0i +5], word 01010000b *256 +11101001b
  491.  
  492.         mov    edi,[0x3000]
  493.         shl    edi, 3
  494.         mov    [edi+gdts+ tss0 +5], word 01010000b *256 +11101001b
  495.  
  496.  
  497.         ; save a copy of current task's TSS to fpu_tss
  498.         mov    esi,[0x3000]
  499.         imul   esi,tss_step
  500.         add    esi,tss_data
  501.         mov    edi,fpu_tss
  502.         mov    ecx,120/4
  503.         cld
  504.         rep    movsd
  505.  
  506.         ; get base address of our TSS and...
  507.         mov    esi,[0x3000]
  508.         imul   esi,tss_step
  509.         add    esi,tss_data
  510.  
  511.         ; ...init segments, stack, eip, flags
  512.         mov    word [esi+l.cs-tss_sceleton],int_code
  513.         mov    word [esi+l.ss-tss_sceleton],int_data
  514.         mov    word [esi+l.ds-tss_sceleton],int_data
  515.         mov    word [esi+l.es-tss_sceleton],int_data
  516.         mov    word [esi+l.fs-tss_sceleton],int_data
  517.         mov    word [esi+l.gs-tss_sceleton],int_data
  518.         mov    dword [esi+l.esp-tss_sceleton],fpu_stack+4*8
  519.         mov    dword [esi+l.eip-tss_sceleton],fpu_handler
  520.         mov    dword [esi+l.eflags-tss_sceleton],0x11002
  521.  
  522.         ; then execute this task
  523.         mov    ebx, [0x3000]
  524.         shl    ebx,3
  525.         add    ebx, tss0 ;t
  526.         mov    [0xB004], bx
  527.  
  528.         jmp    pword [0xB000]
  529.  
  530.         jmp    s7
  531.  
  532. s8:
  533.         cli
  534.  
  535.         mov   [error_interrupt],0x8
  536.         mov   [error_interrupt_entry],dword s8
  537.  
  538.         call  show_error_parameters
  539.  
  540.         mov   edx,[0x3010]
  541.         mov   [edx+0xa],byte 4
  542.  
  543.         jmp   change_task
  544.  
  545. s9:
  546.         cli
  547.  
  548.         mov   [error_interrupt],0x9
  549.         mov   [error_interrupt_entry],dword s9
  550.  
  551.         call  show_error_parameters
  552.  
  553.         mov   edx,[0x3010]
  554.         mov   [edx+0xa],byte 4
  555.  
  556.         jmp   change_task
  557.  
  558. sa:
  559.         cli
  560.  
  561.         mov   [error_interrupt],0xa
  562.         mov   [error_interrupt_entry],dword sa
  563.  
  564.         call  show_error_parameters
  565.  
  566.         mov   edx,[0x3010]
  567.         mov   [edx+0xa],byte 4
  568.  
  569.         jmp   change_task
  570.  
  571. sb:
  572.         cli
  573.  
  574.         mov   [error_interrupt],0xb
  575.         mov   [error_interrupt_entry],dword sb
  576.  
  577.         call  show_error_parameters
  578.  
  579.         mov   edx,[0x3010]
  580.         mov   [edx+0xa],byte 4
  581.  
  582.         jmp   change_task
  583.  
  584. sc:
  585.         cli
  586.  
  587.         mov   [error_interrupt],0xc
  588.         mov   [error_interrupt_entry],dword sc
  589.  
  590.         call  show_error_parameters
  591.  
  592.         mov   edx,[0x3010]
  593.         mov   [edx+0xa],byte 4
  594.  
  595.         jmp   change_task
  596.  
  597. sd:
  598.         cli
  599.  
  600.         mov   [error_interrupt],0xd
  601.         mov   [error_interrupt_entry],dword sd
  602.  
  603.         call  show_error_parameters
  604.  
  605.         mov   edx,[0x3010]
  606.         mov   [edx+0xa],byte 4
  607.  
  608.         jmp   change_task
  609.  
  610. se:
  611.         cli
  612.  
  613.         mov   [error_interrupt],0xe
  614.         mov   [error_interrupt_entry],dword se
  615.  
  616.         call  show_error_parameters
  617.  
  618.         mov   edx,[0x3010]
  619.         mov   [edx+0xa],byte 4
  620.  
  621.         jmp   change_task
  622.  
  623. sf:
  624.         cli
  625.  
  626.         mov   [error_interrupt],0xf
  627.         mov   [error_interrupt_entry],dword sf
  628.  
  629.         call  show_error_parameters
  630.  
  631.         mov   edx,[0x3010]
  632.         mov   [edx+0xa],byte 4
  633.  
  634.         jmp   change_task
  635.  
  636. s10:
  637.         cli
  638.  
  639.         mov   [error_interrupt],0x10
  640.         mov   [error_interrupt_entry],dword s10
  641.  
  642.         call  show_error_parameters
  643.  
  644.         mov   edx,[0x3010]
  645.         mov   [edx+0xa],byte 4
  646.  
  647.         jmp   change_task
  648.  
  649. s11:
  650.         cli
  651.  
  652.         mov   [error_interrupt],0x11
  653.         mov   [error_interrupt_entry],dword s11
  654.  
  655.         call  show_error_parameters
  656.  
  657.         mov   edx,[0x3010]
  658.         mov   [edx+0xa],byte 4
  659.  
  660.         jmp   change_task
  661.  
  662. writehex:
  663.  
  664.       pusha
  665.  
  666.       mov  ecx,eax
  667.       mov  ax,word [printerrorat]
  668.       shl  eax,16
  669.       mov  ax,[esp+32+4]
  670.       sub  ax,60
  671.       mov  edx,1
  672.       mov  esi,8
  673.       mov  ebx,0xffffff
  674.     whl1:
  675.       push ecx
  676.       and  ecx,0xf
  677.       add  ecx,hexletters
  678.       mov  edi,1
  679.  
  680.       mov  cl,[ecx]
  681.       mov  edi,[write_error_to]
  682.       mov  [edi],cl
  683.       dec  [write_error_to]
  684.  
  685.       pop  ecx
  686.       shr  ecx,4
  687.       sub  eax,6*65536
  688.       dec  esi
  689.       jnz  whl1
  690.  
  691.       popa
  692.       ret
  693.  
  694. iglobal
  695.   hexletters  db '0123456789ABCDEF'
  696.  
  697.   error_interrupt         dd  -1
  698.   error_interrupt_entry   dd  -1
  699.  
  700.   printerrorat            dd 300
  701.  
  702.   process_error  db 'K : Process - forced terminate INT: 00000000',13,10,0
  703.   process_pid    db 'K : Process - forced terminate PID: 00000000',13,10,0
  704.   process_eip    db 'K : Process - forced terminate EIP: 00000000',13,10,0
  705.   system_error   db 'K : Kernel error',13,10,0
  706. endg
  707.  
  708. uglobal
  709.   write_error_to  dd  0x0
  710. endg
  711.  
  712. show_error_parameters:
  713.        
  714.         mov    [write_error_to],process_pid+43
  715.         mov    eax,[0x3000]
  716.         shl    eax, 5
  717.         mov    eax,[0x3000+4+eax]
  718.         call   writehex
  719.        
  720.         mov    [write_error_to],process_error+43
  721.         mov    eax,[error_interrupt]
  722.         call   writehex
  723.        
  724.         mov    eax,[0x3000]
  725.         shl    eax,8
  726.         cmp    [0x80000+eax+0xB0],dword 0
  727.         jnz    .system_error
  728.  
  729.         mov    eax,[0x3000]
  730.         imul   eax,tss_step
  731.         mov    eax,[eax+tss_data+l.eip-tss_sceleton]
  732. .out_eip:        
  733.         mov    [write_error_to],process_eip+43
  734.         call   writehex
  735.  
  736.         mov    esi,process_error
  737.         call   sys_msg_board_str
  738.  
  739.         mov    esi,process_pid
  740.         call   sys_msg_board_str
  741.  
  742.         mov    esi,process_eip
  743.         call   sys_msg_board_str
  744.  
  745.         ret
  746.        
  747. .system_error:
  748.         mov    esi,system_error
  749.         call   sys_msg_board_str
  750.         mov    eax,[0x3000]
  751.         shl    eax,7
  752.         mov    eax,[eax+0x298000+l.eip-tss_sceleton]
  753.         jmp    .out_eip        
  754.  
  755.  
  756. irq5:
  757.  
  758.      call   restore_caller
  759.  
  760.      mov    dx,word [sb16]
  761.      add    dx,0xe
  762.      in     al,dx
  763.  
  764. ;     mov    byte [SB16_Status],0
  765.  
  766.      mov    [check_idle_semaphore],5
  767.  
  768.      mov    al,0x20
  769.      out    0x20,al
  770.  
  771.      call  return_to_caller
  772.  
  773.      jmp   irq5
  774.  
  775. irqD:
  776.  
  777.      call   restore_caller
  778.  
  779.      mov   dx,0xf0
  780.      mov   al,0
  781.      out   dx,al
  782.  
  783.      mov   dx,0xa0
  784.      mov   al,0x20
  785.      out   dx,al
  786.      mov   dx,0x20
  787.      out   dx,al
  788.  
  789.      mov   ds,cx
  790.      mov   es,cx
  791.      mov   fs,cx
  792.  
  793.      call  return_to_caller
  794.  
  795.      jmp   irqD
  796.  
  797. p_irq2:
  798.  
  799.      call  restore_caller
  800.  
  801.      mov   edi,2               ; 1
  802.      call  irqhandler          ; 2/5
  803.  
  804.      call  return_to_caller
  805.  
  806.      jmp   p_irq2
  807.  
  808. p_irq3:
  809.  
  810.      call  restore_caller
  811.  
  812.      mov   edi,3
  813.      call  irqhandler
  814.  
  815.      call  return_to_caller
  816.  
  817.      jmp   p_irq3
  818.  
  819. p_irq4:
  820.  
  821.      call  restore_caller
  822.  
  823.      mov   edi,4
  824.      call  irqhandler
  825.  
  826.      call  return_to_caller
  827.  
  828.      jmp   p_irq4
  829.  
  830. p_irq5:
  831.  
  832.      call  restore_caller
  833.  
  834.      mov   edi,5
  835.      call  irqhandler
  836.  
  837.      call  return_to_caller
  838.  
  839.      jmp   p_irq5
  840.  
  841. p_irq6:
  842.  
  843.      call  restore_caller
  844.  
  845.      call  fdc_irq
  846.  
  847.      mov   edi,6
  848.      call  irqhandler
  849.  
  850.      call  return_to_caller
  851.  
  852.      jmp   p_irq6
  853.  
  854. p_irq7:
  855.  
  856.      call  restore_caller
  857.  
  858.      mov   edi,7
  859.      call  irqhandler
  860.  
  861.      call  return_to_caller
  862.  
  863.      jmp   p_irq7
  864.  
  865. p_irq8:
  866.  
  867.      call  restore_caller
  868.  
  869.      mov   edi,8
  870.      call  irqhandler
  871.  
  872.      call  return_to_caller
  873.  
  874.      jmp   p_irq8
  875.  
  876. p_irq9:
  877.  
  878.      call  restore_caller
  879.  
  880.      mov   edi,9
  881.      call  irqhandler
  882.  
  883.      call  return_to_caller
  884.  
  885.      jmp   p_irq9
  886.  
  887. p_irq10:
  888.  
  889.      call  restore_caller
  890.  
  891.      mov   edi,10
  892.      call  irqhandler
  893.  
  894.      call  return_to_caller
  895.  
  896.      jmp   p_irq10
  897.  
  898. p_irq11:
  899.  
  900.      call  restore_caller
  901.  
  902.      mov   edi,11
  903.      call  irqhandler
  904.  
  905.      call  return_to_caller
  906.  
  907.      jmp   p_irq11
  908.  
  909. p_irq12:
  910.  
  911.       call  restore_caller
  912.  
  913.       mov   edi,12
  914.       call  irqhandler
  915.  
  916.       call  return_to_caller
  917.  
  918.       jmp   p_irq12
  919.  
  920. p_irq13:
  921.  
  922.      call  restore_caller
  923.  
  924.      mov   edi,13
  925.      call  irqhandler
  926.  
  927.      call  return_to_caller
  928.  
  929.      jmp   p_irq13
  930.  
  931. p_irq14:
  932.  
  933.      call  restore_caller
  934.      
  935.      mov   edi,14
  936.      call  irqhandler
  937.  
  938.      call  return_to_caller
  939.  
  940.      jmp   p_irq14
  941.  
  942. p_irq15:
  943.  
  944.      call  restore_caller
  945.  
  946.      mov   edi,15
  947.      call  irqhandler
  948.  
  949.      call  return_to_caller
  950.  
  951.      jmp   p_irq15
  952.  
  953.  
  954.  
  955. align 4
  956. restore_caller:
  957.  
  958.       mov    edi,[0x3000]
  959.       shl    edi, 3
  960.       mov    [edi+gdts+ tss0 +5], word 01010000b *256 +11101001b
  961.  
  962.       ret
  963.  
  964. align 4
  965. return_to_caller:
  966.  
  967.       mov   ebx,[0x3000]
  968.       shl   bx,3
  969.       add   bx,tss0;t
  970.       mov   [tss_irq12],bx
  971.  
  972.            db    0xea
  973.            dd    0
  974. tss_irq12  dw    tss0;t
  975.  
  976.            ret
  977.  
  978. uglobal
  979.   irqh dd 0x0
  980. endg
  981.  
  982. irqhandler:
  983.  
  984.      push   edi
  985.  
  986.      mov    esi,edi          ; 1
  987.      shl    esi,6            ; 1
  988.      add    esi,irq00read    ; 1
  989.      shl    edi,12           ; 1
  990.      add    edi,0x2E0000
  991.  
  992.      mov    [check_idle_semaphore],5
  993.  
  994.    irqnewread:
  995.  
  996.      mov    dx,[esi]         ; 2+
  997.  
  998.      cmp    dx,0             ; 1
  999.      jz     irqover
  1000.      cmp    [esi+3],byte 1   ; 2     ; byte read
  1001.      jne    noirqbyte        ; 4-11
  1002.  
  1003.      in     al,dx
  1004.  
  1005.      mov    edx,[edi]
  1006.      cmp    edx,4000
  1007.      je     irqfull
  1008.      mov    ebx,edi
  1009.      add    ebx,0x10
  1010.      add    ebx,edx
  1011.      mov    [ebx],al
  1012.      inc    edx
  1013.      mov    [edi],edx
  1014.  
  1015.      add    esi,4
  1016.      jmp    irqnewread
  1017.  
  1018.    noirqbyte:
  1019.  
  1020.  
  1021.      cmp    [esi+3],byte 2     ; word read
  1022.      jne    noirqword
  1023.  
  1024.      in     ax,dx
  1025.  
  1026.      mov    edx,[edi]
  1027.      cmp    edx,4000
  1028.      je     irqfull
  1029.      mov    ebx,edi
  1030.      add    ebx,0x10
  1031.      add    ebx,edx
  1032.      mov    [ebx],ax
  1033.      add    edx,2
  1034.      mov    [edi],edx
  1035.      add    esi,4
  1036.      jmp    irqnewread
  1037.  
  1038.    noirqword:
  1039.    irqfull:
  1040.    irqover:
  1041.  
  1042.      mov    al,0x20            ; ready for next irq
  1043.      out    0x20,al
  1044.  
  1045.      pop    ebx
  1046.      cmp    ebx,7
  1047.      jbe    noa0
  1048.      out    0xa0,al
  1049.    noa0:
  1050.  
  1051.      ret
  1052.  
  1053.  
  1054. ; this code should never get control!
  1055. ; applications can use only 0x40 interrupt
  1056. unknown_interrupt:
  1057.  @@: call   change_task
  1058.      jmp    @b
  1059.  
  1060.  
  1061.  
  1062. compare_to_thread:
  1063.  
  1064.          push ebx
  1065.  
  1066.          mov  eax,edx
  1067.          shl  eax, 3
  1068.          add  eax,gdts+ app_code-3
  1069.          mov  ebx,[eax]
  1070.          cmp  ebx,[old_code_0]
  1071.          jne  ctt0
  1072.          mov  ebx,[eax+4]
  1073.          cmp  ebx,[old_code_1]
  1074.          jne  ctt0
  1075.  
  1076.          pop  ebx
  1077.          mov  eax,1
  1078.          ret
  1079.  
  1080.        ctt0:
  1081.  
  1082.          pop  ebx
  1083.          mov  eax,0
  1084.          ret
  1085.  
  1086.  
  1087.  
  1088. check_for_thread_mem:
  1089.  
  1090.          pusha
  1091.  
  1092.          mov  ecx,[0x3004]
  1093.        cftm0:
  1094.          mov  eax,ecx
  1095.          shl  eax, 8
  1096.          add  eax,gdts+ app_code-3
  1097.          mov  ebx,[eax]
  1098.          cmp  ebx,[old_code_0]
  1099.          jne  cftm1
  1100.          mov  ebx,[eax+4]
  1101.          cmp  ebx,[old_code_1]
  1102.          jne  cftm1
  1103.  
  1104.          mov  eax,ecx  ; new code segments
  1105.          shl  eax, 3 ;imul eax,8
  1106.          add  eax,gdts+ app_code-3
  1107.  
  1108.          mov  ebx,[new_code_0]
  1109.          mov  [eax],ebx
  1110.          mov  ebx,[new_code_1]
  1111.          mov  [eax+4],ebx
  1112.  
  1113.          mov  eax,ecx  ; new data segments
  1114.          shl  eax, 3
  1115.  
  1116.          add  eax,gdts+ app_data-3
  1117.  
  1118.          mov  ebx,[new_data_0]
  1119.          mov  [eax],ebx
  1120.          mov  ebx,[new_data_1]
  1121.          mov  [eax+4],ebx
  1122.  
  1123.          cmp  [new_pos],0   ; new memory position segments
  1124.          je   no_new_postition_for_thread
  1125.          mov  eax,ecx
  1126.          shl  eax, 5
  1127.          add  eax,0x3000
  1128.          mov  ebx,[new_pos]
  1129.          mov  [eax+0x10],ebx
  1130.        no_new_postition_for_thread:
  1131.  
  1132.          mov  eax,ecx       ; new amount of memory
  1133.          shl  eax, 8
  1134.          add  eax,0x80000
  1135.          mov  ebx,[new_amount]
  1136.          mov  [eax+0x8C],ebx
  1137.  
  1138.        cftm1:
  1139.  
  1140.          dec  ecx
  1141.          jnz  cftm0
  1142.  
  1143.          popa
  1144.  
  1145.          ret
  1146.  
  1147.  
  1148. save_for_thread_check:
  1149.  
  1150.         ; save for thread check
  1151.  
  1152.         pusha
  1153.         mov    esi,[0x3000]
  1154.         ;imul   esi,8
  1155.         shl    esi, 3
  1156.         add    esi,gdts+ app_code-3 +0
  1157.         mov    edi,old_code_0
  1158.         mov    ecx,8
  1159.         cld
  1160.         rep    movsb
  1161.         popa
  1162.  
  1163.         ret
  1164.  
  1165.  
  1166. save_new_position_for_threads:
  1167.  
  1168.         ; new code segment for thread check
  1169.         pusha
  1170.         mov    esi,[0x3000]
  1171.         ;imul   esi,8
  1172.         shl    esi, 3
  1173.         add    esi,gdts+ app_code-3 +0
  1174.         mov    edi,new_code_0
  1175.         mov    ecx,8
  1176.         cld
  1177.         rep    movsb
  1178.         popa
  1179.  
  1180.         ; new data segment for thread check
  1181.         pusha
  1182.         mov    esi,[0x3000]
  1183.         ;imul   esi,8
  1184.         shl    esi, 3
  1185.         add    esi,gdts+ app_data-3 +0
  1186.         mov    edi,new_data_0
  1187.         mov    ecx,8
  1188.         cld
  1189.         rep    movsb
  1190.         popa
  1191.  
  1192.         ret
  1193.  
  1194. set_application_table_status:
  1195.         push eax
  1196.  
  1197.         mov  eax,[0x3000]
  1198.         ;imul eax,32
  1199.         shl  eax, 5
  1200.         add  eax,0x3000+4
  1201.         mov  eax,[eax]
  1202.  
  1203.         mov  [application_table_status],eax
  1204.  
  1205.         pop  eax
  1206.  
  1207.         ret
  1208.  
  1209.  
  1210. clear_application_table_status:
  1211.         push eax
  1212.  
  1213.         mov  eax,[0x3000]
  1214.         ;imul eax,32
  1215.         shl  eax, 5
  1216.         add  eax,0x3000+4
  1217.         mov  eax,[eax]
  1218.  
  1219.         cmp  eax,[application_table_status]
  1220.         jne  apptsl1
  1221.         mov  [application_table_status],0
  1222.       apptsl1:
  1223.  
  1224.         pop  eax
  1225.  
  1226.         ret
  1227.  
  1228. uglobal
  1229.   old_code_0 dd 0x0
  1230.   old_code_1 dd 0x0
  1231.  
  1232.   ;
  1233.  
  1234.   new_code_0 dd 0x0
  1235.   new_code_1 dd 0x0
  1236.  
  1237.   new_data_0 dd 0x0
  1238.   new_data_1 dd 0x0
  1239.  
  1240.   new_pos    dd 0x0
  1241.   new_amount dd 0x0
  1242. endg
  1243.  
  1244.  
  1245. sys_resize_app_memory:
  1246.         ; eax = 1 - resize
  1247.         ;     ebx = new amount of memory
  1248.  
  1249.         cmp    eax,1
  1250.         jne    no_application_mem_resize
  1251.        
  1252.         mov    eax,[0x3010]
  1253.         cmp    dword [eax+0x10],std_application_base_address
  1254.         jz     new_mem_resize ;resize for new type of processes
  1255.  
  1256.         add    ebx,4095
  1257.         shr    ebx,12
  1258.         shl    ebx,12
  1259.         mov    ebp,ebx
  1260.  
  1261.         ; wait for process table to be free
  1262.  
  1263.       rsm0:
  1264.  
  1265.         cli
  1266.         cmp   [application_table_status],0
  1267.         je    rsm1
  1268.         sti
  1269.         call  change_task
  1270.         jmp   rsm0
  1271.  
  1272.       rsm1:
  1273.  
  1274.         call  set_application_table_status
  1275.         sti
  1276.  
  1277.         cmp    ebx,0 ; other than zero
  1278.         je     mem_resize_unsuccess
  1279.  
  1280.         call   save_for_thread_check
  1281.  
  1282.         ; find a free place
  1283.  
  1284.         mov    esi,[0xfe84]  ; application memory start
  1285.         mov    edi,ebp
  1286.         add    edi,esi
  1287.         dec    edi
  1288.  
  1289.       rfgdt:
  1290.  
  1291.         mov    edx,2
  1292.  
  1293.       rfindgdtl1:
  1294.  
  1295.         call   compare_to_thread
  1296.         cmp    eax,1
  1297.         je     rfindfl3
  1298.  
  1299.         mov    ecx,edx
  1300.         shl    ecx,3
  1301.  
  1302.         ; eax run base -> ebx limit
  1303.  
  1304.         mov    al,[ecx+gdts+ app_code-3 +4]
  1305.         mov    ah,[ecx+gdts+ app_code-3 +7]
  1306.         shl    eax,16
  1307.         mov    ax,[ecx+gdts+ app_code-3 +2]
  1308.        
  1309. ;!!mem
  1310.         cmp    eax,std_application_base_address
  1311.         jz     rfindfl3
  1312. ;!!mem
  1313.  
  1314.         movzx  ebx,word [ecx+gdts+ app_code-3 +0]
  1315.         shl    ebx,12
  1316.         add    ebx,eax
  1317.  
  1318.         cmp    eax,edi
  1319.         jg     rfindfl3
  1320.         cmp    ebx,esi
  1321.         jb     rfindfl3
  1322.  
  1323.         add    esi,4096
  1324.         add    edi,4096
  1325.  
  1326.         cmp    edi,[0xfe8c]        ; < c_memory
  1327.         jbe    rfgdt
  1328.  
  1329.         jmp    rfind_free_ret_2   ;; not enough memory
  1330.  
  1331.       rfindfl3:
  1332.  
  1333.         inc    edx
  1334.         cmp    edx,[0x3004]
  1335.         jbe    rfindgdtl1
  1336.  
  1337.      rfindfl1:
  1338.      rthread_c:
  1339.  
  1340.         mov    ecx,[0x3000]
  1341.         shl    ecx,3
  1342.  
  1343.         inc    edi
  1344.         sub    edi,esi
  1345.         add    edi,4095
  1346.         shr    edi,12
  1347.         dec    edi
  1348.  
  1349.         ; code
  1350.  
  1351.         mov    eax,esi
  1352.         mov    ebx,edi
  1353.  
  1354.         mov    [ecx+gdts+ app_code-3 +2], ax              ;  base  0:15
  1355.         shr    eax,16
  1356.         mov    [ecx+gdts+ app_code-3 +4], al              ;  base  23:16
  1357.         mov    [ecx+gdts+ app_code-3 +7], ah              ;  base  31:24
  1358.         mov    [ecx+gdts+ app_code-3 +0], bx              ;  limit
  1359.  
  1360.         ; data
  1361.  
  1362.         mov    eax,esi
  1363.         mov    [ecx+gdts+ app_data-3 +2], ax              ;  base  0:15
  1364.         shr    eax,16
  1365.         mov    [ecx+gdts+ app_data-3 +4], al              ;  base  23:16
  1366.         mov    [ecx+gdts+ app_data-3 +7], ah              ;  base  31:24
  1367.  
  1368.         movzx  edx,word [ecx+gdts+ app_code-3 +0]         ;  save limit
  1369.  
  1370.         mov    [ecx+gdts+ app_data-3 +0], bx              ;  limit
  1371.  
  1372.         and    ebx,0xffff
  1373.  
  1374.         cmp    ebx,edx  ; copy smaller from memory sizes
  1375.         jge    noedxebxxchg
  1376.         mov    edx,ebx
  1377.       noedxebxxchg:
  1378.  
  1379.         movzx  ecx,dx
  1380.         shl    ecx,12
  1381.         add    ecx,4096
  1382.  
  1383.         mov    edi,esi
  1384.  
  1385.         mov    eax,[0x3010]
  1386.         mov    esi,[eax+0x10]
  1387.  
  1388.         mov    [eax+0x10],edi  ; new memory position
  1389.  
  1390.         mov    eax,[0x3000]    ; new memory size
  1391.         shl    eax,8
  1392.         add    eax,0x80000
  1393.         mov    [eax+0x8c],ebp
  1394.  
  1395.         mov    [new_pos],edi    ; new position for threads
  1396.         mov    [new_amount],ebp ; new amount of mem for threads
  1397.  
  1398.         cmp    esi,edi
  1399.         je     no_app_move
  1400.  
  1401.         cld
  1402.         rep    movsb           ; move the app image to the new position
  1403.  
  1404.       no_app_move:
  1405.  
  1406.         call   save_new_position_for_threads
  1407.         call   check_for_thread_mem
  1408.  
  1409.         mov    [application_table_status],0
  1410.  
  1411.         mov    [esp+36],dword 0 ; eax <- 0 ; successfull
  1412.  
  1413.         ret
  1414.  
  1415.      rfind_free_ret_2:
  1416.  
  1417.      mem_resize_unsuccess:
  1418.  
  1419.         mov    [application_table_status],0
  1420.  
  1421.         mov    [esp+36],dword 1 ; eax <- 1 ; unsuccessfull
  1422.  
  1423.         ret
  1424.  
  1425.      no_application_mem_resize:
  1426.  
  1427.  
  1428.         ret
  1429.  
  1430.  
  1431. align 4
  1432. find_free_mem:
  1433.  
  1434.         push   eax
  1435.         push   ebx
  1436.         push   ecx
  1437.         push   edx
  1438.         push   edi
  1439.  
  1440.         call   find_free_process_slot
  1441.         mov    eax,[new_process_place]
  1442.  
  1443.         cmp    eax,max_processes
  1444.         jg     find_free_ret_2
  1445.  
  1446.         cmp    [thread_create],1
  1447.         je     thread_c
  1448.  
  1449.         mov    esi,[0xfe84]
  1450.         add    edi,esi
  1451.         dec    edi
  1452.  
  1453.         mov    eax,2
  1454.         cmp    dword [0x3004],1
  1455.         je     findf4
  1456.  
  1457.      fgdt:
  1458.  
  1459.         mov    edx,2
  1460.  
  1461.       findgdtl1:
  1462.  
  1463.         mov    ecx,edx
  1464.         shl    ecx,3
  1465.  
  1466.         ; eax run base -> ebx limit
  1467.  
  1468.         mov    al,[ecx+gdts+ app_code-3 +4]
  1469.         mov    ah,[ecx+gdts+ app_code-3 +7]
  1470.         shl    eax,16
  1471.         mov    ax,[ecx+gdts+ app_code-3 +2]
  1472. ;!!mem
  1473.         cmp    eax,std_application_base_address
  1474.         jz     findfl3
  1475. ;!!mem
  1476.  
  1477.         movzx  ebx,word [ecx+gdts+ app_code-3 +0]
  1478.         shl    ebx,12
  1479.         add    ebx,eax
  1480.  
  1481.         cmp    eax,edi
  1482.         jg     findfl3
  1483.         cmp    ebx,esi
  1484.         jb     findfl3
  1485.  
  1486.         add    esi,4096
  1487.         add    edi,4096
  1488.  
  1489.         cmp    edi,[0xfe8c]        ; < c_memory
  1490.         jbe    fgdt
  1491.  
  1492.         jmp    find_free_ret_2
  1493.  
  1494.       findfl3:
  1495.  
  1496.         inc    edx
  1497.         cmp    edx,[check_processes]
  1498.         jbe    findgdtl1
  1499.  
  1500.      findfl1:
  1501.      thread_c:
  1502.  
  1503.          mov    eax,[new_process_place]
  1504.  
  1505.      findf4:
  1506.  
  1507.         mov    [first_gdt_search],eax
  1508.         mov    [gdt_place],eax
  1509.  
  1510.         mov    ecx,eax
  1511.         shl    ecx,3
  1512.  
  1513.         inc    edi
  1514.         sub    edi,esi
  1515.         add    edi,4095
  1516.         shr    edi,12
  1517.         dec    edi
  1518.  
  1519.         ; code
  1520.  
  1521.         mov    eax,esi
  1522.         mov    ebx,edi
  1523.  
  1524.         mov    [ecx+gdts+ app_code-3 +2], ax                   ;  base  0:15
  1525.         shr    eax,16
  1526.         mov    [ecx+gdts+ app_code-3 +4], al                   ;  base  23:16
  1527.         mov    [ecx+gdts+ app_code-3 +7], ah                   ;  base  31:24
  1528.         mov    [ecx+gdts+ app_code-3 +0], bx                   ;  limit
  1529.         mov    [ecx+gdts+ app_code-3 +5], word 11010000b *256 +11111010b
  1530.  
  1531.         ; data
  1532.  
  1533.         mov    eax,esi
  1534.         mov    [ecx+gdts+ app_data-3 +2], ax                   ;  base  0:15
  1535.         shr    eax,16
  1536.         mov    [ecx+gdts+ app_data-3 +4], al                   ;  base  23:16
  1537.         mov    [ecx+gdts+ app_data-3 +7], ah                   ;  base  31:24
  1538.         mov    [ecx+gdts+ app_data-3 +0], bx                   ;  limit
  1539.         mov    [ecx+gdts+ app_data-3 +5], word 11010000b *256 +11110010b
  1540.  
  1541.         push   esi
  1542.         mov    esi,process_loading
  1543.         call   sys_msg_board_str
  1544.         pop    esi
  1545.  
  1546.       find_free_ret:
  1547.  
  1548.         pop    edi
  1549.         pop    edx
  1550.         pop    ecx
  1551.         pop    ebx
  1552.         pop    eax
  1553.         ret
  1554.  
  1555.       find_free_ret_2:
  1556.  
  1557.         cmp    [dec3004],0
  1558.         je     no3004inc
  1559.         dec    dword [0x3004]
  1560.       no3004inc:
  1561.  
  1562.         pop    edi
  1563.         pop    edx
  1564.         pop    ecx
  1565.         pop    ebx
  1566.         pop    eax
  1567.         mov    esi,0
  1568.         ret
  1569.  
  1570.  
  1571. get_app_params:
  1572.  
  1573.     push eax
  1574.  
  1575.     cmp  [0x90000+6],word '00'
  1576.     jne  no_00_header
  1577.  
  1578.     mov  eax,[0x90000+12]
  1579.     mov  [app_start],eax
  1580.     mov  eax,[0x90000+16]
  1581.     mov  [app_i_end],eax
  1582.     mov  eax,[0x90000+20]
  1583.     mov  [app_mem],eax
  1584.     shr  eax,1
  1585.     sub  eax,0x10
  1586.     mov  [app_esp],eax
  1587.     mov  eax,[0x90000+24]
  1588.     mov  [app_i_param],eax
  1589.     mov  [app_i_icon],dword 0
  1590.  
  1591.     pop  eax
  1592.     mov  esi,1
  1593.     ret
  1594.  
  1595.   no_00_header:
  1596.  
  1597.  
  1598.     cmp  [0x90000+6],word '01'
  1599.     jne  no_01_header
  1600.  
  1601.     mov  eax,[0x90000+12]
  1602.     mov  [app_start],eax
  1603.     mov  eax,[0x90000+16]
  1604.     mov  [app_i_end],eax
  1605.     mov  eax,[0x90000+20]
  1606.     mov  [app_mem],eax
  1607.     mov  eax,[0x90000+24]
  1608.     mov  [app_esp],eax
  1609.     mov  eax,[0x90000+28]
  1610.     mov  [app_i_param],eax
  1611.     mov  eax,[0x90000+32]
  1612.     mov  [app_i_icon],eax
  1613.  
  1614.     pop  eax
  1615.     mov  esi,1
  1616.     ret
  1617.  
  1618.    no_01_header:
  1619.  
  1620.     pop  eax
  1621.     mov  esi,0
  1622.     ret
  1623.  
  1624.  
  1625. start_application_fl:
  1626.     jmp new_start_application_fl
  1627.  
  1628. ;************************************************************************
  1629.  
  1630. start_application_floppy:
  1631.     jmp  new_start_application_floppy
  1632.  
  1633. ;********************************************************************
  1634.  
  1635. start_application_hd:
  1636.     jmp   new_start_application_hd
  1637.  
  1638. uglobal
  1639.   threadstring       dd  0x0
  1640.   new_process_place  dd  0x0
  1641.   check_processes    dd  0x0
  1642.   dec3004            db  0x0
  1643.   app_start    dd  0x0
  1644.   app_i_end    dd  0x0
  1645.   app_mem      dd  0x0
  1646.   app_esp      dd  0x0
  1647.   app_i_param  dd  0x0
  1648.   app_i_icon   dd  0x0
  1649.   app_mem_pos  dd  0x0
  1650.   thread_create    dd 0x0
  1651.   gdt_place        dd 0x0
  1652. endg
  1653.  
  1654. iglobal
  1655.   hd_app_string      db  'HDAPP       '
  1656.   process_loading    db 'K : Process - loading ',13,10,0
  1657.   process_running    db 'K : Process - done',13,10,0
  1658.   first_gdt_search   dd 0x2
  1659. endg
  1660.  
  1661.  
  1662. sys_threads:
  1663.  
  1664. ; eax=1 create thread
  1665. ;
  1666. ;   ebx=thread start
  1667. ;   ecx=thread stack value
  1668. ;
  1669. ; on return : eax = pid
  1670. jmp new_sys_threads
  1671.     cli
  1672.     cmp   [application_table_status],0
  1673.     je    stth9
  1674.     sti
  1675.     call  change_task
  1676.     jmp   sys_threads
  1677.   stth9:
  1678.  
  1679.     call  set_application_table_status
  1680.  
  1681.     sti
  1682.  
  1683.     cmp  eax,1
  1684.     jne  no_sys_thread_create
  1685.     cli
  1686.  
  1687.     mov  eax,[0x3010]
  1688.     mov  eax,[eax+0x10]
  1689.     mov  [app_mem_pos],eax
  1690.  
  1691.     mov  [app_i_param],0
  1692.     mov  [app_i_icon],0
  1693.  
  1694.     mov  [app_start],ebx
  1695.     mov  [app_esp],ecx
  1696.  
  1697.     mov  ebx,[0x3000]
  1698.     shl  ebx,8
  1699.     add  ebx,0x80000
  1700.     mov  [threadstring],ebx
  1701.     mov  ebx,[ebx+0x8c]
  1702.     mov  [app_mem],ebx
  1703.  
  1704.     mov  esi,[app_mem_pos]
  1705.     mov  edi,[app_mem]
  1706.     add  edi,esi
  1707.     dec  edi
  1708.     mov  [thread_create],1
  1709.     call find_free_mem
  1710.     cmp  esi,0
  1711.     jne  th_cr1
  1712.     mov  [application_table_status],0
  1713.     mov  eax,1   ; no free memory
  1714.     sti
  1715.     ret
  1716.   th_cr1:
  1717.     push dword 0
  1718.     push dword [threadstring]
  1719.     jmp  add_app_parameters
  1720.   no_sys_thread_create:
  1721.  
  1722.     mov  eax,-1
  1723.     mov  [application_table_status],0
  1724.     ret
  1725.  
  1726.  
  1727. find_free_process_slot:
  1728.  
  1729.     pusha
  1730.  
  1731.     mov   ebx,[0x3004]
  1732.     mov   [check_processes],ebx
  1733.     inc   ebx
  1734.     mov   [new_process_place],ebx
  1735.  
  1736.     mov   ebx,2
  1737.  
  1738.   newfps:
  1739.  
  1740.     mov   eax,ebx
  1741.     ;imul  eax,0x20
  1742.     shl   eax, 5
  1743.     add   eax,0x3000+0xa
  1744.     cmp   [eax],byte 9
  1745.     je    ffpl
  1746.  
  1747.     inc   ebx
  1748.     cmp   ebx,[0x3004]
  1749.     jbe   newfps
  1750.  
  1751.     ;mov   [dec3004],0
  1752.     mov   [dec3004],1
  1753.     shl   ebx,5
  1754.     mov   [0x3000+0xa+ebx],byte 9
  1755.     inc   dword [0x3004]
  1756.  
  1757.     popa
  1758.     ret
  1759.  
  1760.   ffpl:
  1761.  
  1762.     ;mov   [dec3004],1
  1763.     ;dec   dword [0x3004]
  1764.     mov   [dec3004],0
  1765.     mov   [new_process_place],ebx
  1766.  
  1767.     popa
  1768.     ret
  1769.  
  1770.  
  1771. add_app_parameters:
  1772. ; returns:  eax = pid or -1 if unsuccesfull
  1773.     cmp   [app_i_param],dword 0     ; parameter
  1774.     jz    no_app_params
  1775.     xor   eax, eax
  1776.     mov   edi,[app_i_param]
  1777.     add   edi,[app_mem_pos]
  1778.     mov   ecx,256/4
  1779.     cld
  1780.     rep   stosd
  1781.     mov   esi,[esp+4]
  1782.     test  esi, esi
  1783.     jz    no_app_params
  1784.     mov   eax,[app_i_param]
  1785.     add   eax,[app_mem_pos]
  1786.     mov   edi,eax
  1787.     mov   ecx,256
  1788.     cld
  1789.   app_new_param:
  1790.     cmp   [esi],byte 0
  1791.     jz    no_app_params
  1792.     movsb
  1793.     loop  app_new_param
  1794.   no_app_params:
  1795.  
  1796.     ;inc   dword [0x3004]            ; increase number of processes
  1797.     mov   ebx,[new_process_place]
  1798.  
  1799.     mov   edi,ebx                   ; clear 0x80000 (256 bytes)
  1800.     shl   edi,8
  1801.     add   edi,0x80000
  1802.     mov   ecx,256 / 4
  1803.     mov   eax,0
  1804.     cld
  1805.     rep   stosd
  1806.  
  1807.     shl   ebx,5                     ; * 32 +0x3000
  1808.     add   ebx,0x3000
  1809.  
  1810.     mov   al,byte [new_process_place] ; screen id ?
  1811.     mov   [ebx+0xe],al
  1812.  
  1813.     mov   [ebx],dword 1+2+4         ; report events: windowdraw, key, button
  1814.  
  1815.     inc   dword [process_number]    ; process id number
  1816.     mov   eax,[process_number]
  1817.     mov   [ebx+4],eax
  1818.  
  1819.     mov   ecx,ebx                   ; set draw limits
  1820.     add   ecx,draw_data-0x3000
  1821.     mov   [ecx+0],dword 0
  1822.     mov   [ecx+4],dword 0
  1823.     mov   eax,[0xfe00]
  1824.     mov   [ecx+8],eax
  1825.     mov   eax,[0xfe04]
  1826.     mov   [ecx+12],eax
  1827.  
  1828.     mov   eax,[app_mem_pos]        ; position in memory
  1829.     mov   [ebx+0x10],eax
  1830.  
  1831.     ; TSS
  1832.     xor   ebx,ebx
  1833.     cmp   [thread_create],ebx
  1834.     jnz   clone_cr3_table
  1835.     mov   eax,[new_process_place]
  1836.     call  create_app_cr3_table
  1837.     jmp   set_cr3
  1838. clone_cr3_table:
  1839. ;    mov   eax,[new_process_place]
  1840. ;    mov   ebx,[0x3000]
  1841. ;    call  addreference_app_cr3_table
  1842.     mov   eax,[0x3000]
  1843.     call  get_cr3_table
  1844. set_cr3:
  1845.     add   eax,8+16
  1846.     mov   [l.cr3],eax
  1847.    
  1848.     mov   eax,[app_start]
  1849.     mov   [l.eip],eax
  1850.     mov   eax,[app_esp]
  1851.     mov   [l.esp],eax
  1852.  
  1853.     mov   ebx,[new_process_place]              ; gdt's
  1854.     shl   ebx,3
  1855.  
  1856.     mov   ax,app_code
  1857.     add   ax,bx
  1858.     mov   [l.cs],ax
  1859.     mov   ax,app_data
  1860.     add   ax,bx
  1861.     mov   [l.ss],ax
  1862.     mov   [l.ds],ax
  1863.     mov   [l.es],ax
  1864.     mov   [l.fs],ax
  1865.     mov   ax,graph_data
  1866.     mov   [l.gs],ax
  1867.     mov   [l.io],word 128
  1868.     mov   [l.eflags],dword 0x11202
  1869.     mov   [l.ss0], os_data
  1870.     ;mov   [l.ss1], ring1_data
  1871.     ;mov   [l.ss2], ring2_data
  1872.     ; [Ivan 07.03.2005]
  1873.     mov   [l.esp0], 0x8000 ;0x55000 ; used by i38 handler
  1874.     ; [/Ivan 07.03.2005]
  1875.     mov   [l.esp1], 0x56000
  1876.     mov   [l.esp2], 0x57000
  1877.  
  1878.     mov   eax,tss_sceleton          ; move tss to tss_data+
  1879.     mov   ebx,[new_process_place]
  1880.     imul  ebx,tss_step
  1881.     add   ebx,tss_data
  1882.     mov   ecx,120
  1883.     call  memmove
  1884.  
  1885.  
  1886.     ; Add IO access table
  1887.  
  1888.     or   eax, -1
  1889.     mov  edi, [new_process_place]
  1890.     imul edi, tss_step
  1891.     add  edi, tss_data + 128
  1892.     mov  ecx, 2048 ; for 2048 * 4 * 8 bits = 65536 ports
  1893.     cld
  1894.     rep  stosd
  1895.  
  1896.     ; make sure gdt is pointing to the process
  1897.     ; and not to i40 handler
  1898.  
  1899.     mov   ecx,ebx
  1900.     mov   edi,[new_process_place]
  1901. ;    imul  edi,8
  1902.     shl   edi, 3
  1903.  
  1904.     mov   [edi+gdts+ tss0 +0], word tss_step     ; limit 0:15
  1905.     mov   [edi+gdts+ tss0 +2], cx                ; base  0:15
  1906.     mov   eax,ecx
  1907.     shr   eax,16
  1908.     mov   [edi+gdts+ tss0 +4], al                ; base  23:16
  1909.     mov   [edi+gdts+ tss0 +7], ah                ; base  31:24
  1910.     mov   [edi+gdts+ tss0 +5], word 01010000b *256 +11101001b
  1911.  
  1912.     pop   eax
  1913.     pop   ebx
  1914.  
  1915.     mov   ebx,[new_process_place]              ; save name of the process
  1916.     shl   ebx,8
  1917.     add   ebx,0x80000
  1918.     mov   ecx,11
  1919.     call  memmove
  1920.  
  1921.     mov   ebx,[new_process_place]              ; save image size
  1922.     shl   ebx,8
  1923.     add   ebx,0x80000+0x8C
  1924.     mov   eax,[app_mem]
  1925.     mov   [ebx],eax
  1926.  
  1927.     mov   [0xf400],byte 0           ; empty keyboard buffer
  1928.     mov   [0xf500],byte 0           ; empty button buffer
  1929.  
  1930.     mov   [application_table_status],0
  1931.     mov   eax,[process_number]
  1932.  
  1933.     mov   ebx,[new_process_place]
  1934.     shl   ebx, 5 ;imul  ebx,0x20
  1935.     mov   [0x3000+ebx+0xa],byte 0
  1936.  
  1937.     mov   edi,[new_process_place]
  1938.     shl   edi,5
  1939.     add   edi,window_data
  1940.  
  1941.     mov   ebx,[new_process_place]
  1942.     movzx  esi, word [0xC000 + ebx*2]
  1943.     lea    esi, [0xC400 + esi*2]
  1944.     call   windowactivate
  1945.  
  1946.     sti
  1947.  
  1948.     push   esi
  1949.     mov    esi,process_running
  1950.     call   sys_msg_board_str
  1951.     pop    esi
  1952.  
  1953.     ret
  1954.  
  1955. iglobal
  1956.   process_terminating   db 'K : Process - terminating',13,10,0
  1957.   process_terminated    db 'K : Process - done',13,10,0
  1958. endg
  1959.  
  1960.  
  1961. terminate: ; terminate application
  1962.     push   esi
  1963.     mov    esi,process_terminating
  1964.     call   sys_msg_board_str
  1965.     pop    esi
  1966. ;start memory manager code    
  1967. ;    mov    eax,esi
  1968. ;    call   MEM_Heap_Clean
  1969. ;end memory manager code
  1970.    
  1971.  
  1972.     cli
  1973.     cmp   [application_table_status],0
  1974.     je    term9
  1975.     sti
  1976.     call  change_task
  1977.     jmp   terminate
  1978.   term9:
  1979.  
  1980.     call  set_application_table_status
  1981.    
  1982.     mov    eax,esi
  1983.     call   dispose_app_cr3_table
  1984.  
  1985.     mov   [first_gdt_search],0x2   ; start gdt search from beginning
  1986.  
  1987.     cmp   [prev_user_of_fpu],esi   ; if user fpu last -> fpu user = 1
  1988.     jne   fpu_ok_1
  1989.     mov   [prev_user_of_fpu],1
  1990.   fpu_ok_1:
  1991.  
  1992.     mov   [0xf400],byte 0           ; empty keyboard buffer
  1993.     mov   [0xf500],byte 0           ; empty button buffer
  1994.  
  1995.     mov   ecx,esi                               ; clear memory reserv.
  1996.     shl   ecx,3
  1997.     mov   [ecx+gdts+ app_code-3 +0],dword 0
  1998.     mov   [ecx+gdts+ app_code-3 +4],dword 0
  1999.     mov   [ecx+gdts+ app_data-3 +0],dword 0
  2000.     mov   [ecx+gdts+ app_data-3 +4],dword 0
  2001.  
  2002.     mov   edi, esi
  2003. ;    shl   edi, 5
  2004. ;    add   edi, 0x3000
  2005. ;    cmp   [edi+0xa],byte 3  ; if normal terminate then clear int40 handler
  2006. ;    jne   nocl40
  2007.  
  2008. ;    mov   edi,esi   ; free the used interrupt 0x40 handler
  2009. ;    shl   edi, 8 ;imul  edi,256
  2010. ;    mov   eax,[edi+0x80000+0xb0]
  2011.  
  2012. ;    cmp   eax,0     ; is application using a systemcall interrupt  ?
  2013. ;    je    nocl40
  2014.  
  2015.     mov   [usedi40+eax],byte 0
  2016.  
  2017. ;    mov   edi,8
  2018. ;    imul  edi,eax
  2019.     mov   edi, eax
  2020.     shl   edi, 3
  2021.     mov   [edi+tss0sys_l +5], word 01010000b *256 +11101001b
  2022.  
  2023. ;    mov   edi,128
  2024. ;    imul  edi,eax
  2025.     mov   edi, eax
  2026.     shl   edi, 7
  2027.     mov   [edi+0x298000+l.eip-tss_sceleton],dword i40
  2028.     mov   [edi+0x298000+l.eflags-tss_sceleton],dword 0x11002
  2029.  
  2030.     mov   ebx,eax
  2031.     shl   ebx, 12 ;imul  ebx,4096
  2032.     add   ebx,sysint_stack_data
  2033.     mov   [edi+0x298000+l.esp-tss_sceleton],ebx
  2034.  
  2035.   nocl40:
  2036.  
  2037.     mov   ecx,esi                 ; remove buttons
  2038.   bnewba2:
  2039.     mov   edi,[0xfe88]
  2040.     mov   eax,edi
  2041.     cld
  2042.     movzx ebx,word [edi]
  2043.     inc   bx
  2044.   bnewba:
  2045.     dec   bx
  2046.     jz    bnmba
  2047.     add   eax,0x10
  2048.     cmp   cx,[eax]
  2049.     jnz   bnewba
  2050.     pusha
  2051.     mov   ecx,ebx
  2052.     inc   ecx
  2053.     shl   ecx,4
  2054.     mov   ebx,eax
  2055.     add   eax,0x10
  2056.     call  memmove
  2057.     dec   dword [edi]
  2058.     popa
  2059.     jmp   bnewba2
  2060.   bnmba:
  2061.  
  2062.     pusha     ; save window coordinates for window restoring
  2063.     cld
  2064.     shl   esi,5
  2065.     add   esi,window_data
  2066.     mov   ax,[esi+0]
  2067.     mov   word [dlx],ax
  2068.     mov   bx,[esi+8]
  2069.     add   ax,bx
  2070.     mov   word [dlxe],ax
  2071.     mov   ax,[esi+4]
  2072.     mov   word [dly],ax
  2073.     mov   bx,[esi+12]
  2074.     add   ax,bx
  2075.     mov   word [dlye],ax
  2076.     mov   [esi+0],word 0
  2077.     mov   [esi+8],word 5
  2078.     mov   ax,[0xFE04]
  2079.     mov   [esi+4],ax
  2080.     mov   [esi+12],word 5
  2081.     xor   eax, eax
  2082.     mov   [esi+16],eax;dword 0
  2083.     mov   [esi+20],eax;dword 0
  2084.     mov   [esi+24],eax;dword 0
  2085.     mov   [esi+28],eax;dword 0
  2086.     popa
  2087.  
  2088.     pusha
  2089.     mov   edi,esi
  2090.     shl   edi,5
  2091.     add   edi,window_data
  2092.     mov   ecx,32/4
  2093.     xor   eax, eax
  2094.   ;  cld
  2095.     rep   stosd
  2096.  
  2097.     mov   eax,[0xFE04]      ; set window to start from maxy+1
  2098.     add   eax,2
  2099.  
  2100.     mov   edi,esi
  2101.     shl   edi,5
  2102.     add   edi,window_data
  2103.     mov   [edi+4],eax
  2104.  
  2105.     popa
  2106.  
  2107.     pusha
  2108.     mov   edi,esi
  2109.     shl   edi,5
  2110.     add   edi,draw_data
  2111.     mov   ecx,32/4
  2112.     xor   eax, eax
  2113.   ;  cld
  2114.     rep   stosd
  2115.     popa
  2116.  
  2117.     pusha         ; at 0x80000+
  2118.     mov   edi,esi
  2119.     shl   edi,8
  2120.     add   edi,0x80000
  2121.     mov   ecx,256/4
  2122.     xor   eax, eax
  2123.   ;  cld
  2124.     rep   stosd
  2125.     popa
  2126.  
  2127.     pusha          ; name to spaces
  2128.     mov   edi,esi
  2129.     shl   edi,8
  2130.     add   edi,0x80000
  2131.     mov   ecx,11
  2132.     mov   eax,' '
  2133.   ;  cld
  2134.     rep   stosb
  2135.     popa
  2136.  
  2137.     pusha                ; C000 --> C400
  2138.     mov   eax, 0xc000
  2139.     mov   esi, 0
  2140.   nlc40:
  2141.     add   eax, 2
  2142.     inc   esi
  2143.     cmp   esi, [0x3004]
  2144.     jae   nlc41
  2145.     movzx ecx, word [eax]
  2146.     mov   [0xC400 + ecx*2], si
  2147.     jmp   nlc40
  2148.   nlc41:
  2149.  ; ivan 08.12.2004 begin
  2150.     ;mov   ebx, [0x3004]
  2151.     ;dec   ebx
  2152.     ;lea   esi, [0xC400 + ebx*2]
  2153.     ;call  windowactivate
  2154.  ; ivan 08.12.2004 end
  2155.     popa
  2156.  
  2157.     pusha ; remove hd1 reservation
  2158.     mov   edx,esi
  2159.     shl   edx, 5 ;imul  edx,0x20
  2160.     add   edx,0x3000
  2161.     mov   edx,[edx+4]
  2162.     cmp   [hd1_status],edx
  2163.     jne   no_hd1_s_remove
  2164.     mov   [hd1_status],0
  2165.   no_hd1_s_remove:
  2166.     popa
  2167.  
  2168.     pusha ; remove all irq reservations
  2169.     mov   edx,esi
  2170.     shl   edx, 5 ;imul  edx,0x20
  2171.     add   edx,0x3000
  2172.     mov   edx,[edx+4]
  2173.     mov   edi,irq_owner
  2174.     mov   ecx,16
  2175.   newirqfree:
  2176.     cmp   [edi],edx
  2177.     jne   nofreeirq
  2178.     mov   [edi],dword 0
  2179.   nofreeirq:
  2180.     add    edi,4
  2181.     loop   newirqfree
  2182.     popa
  2183.  
  2184.  
  2185.     pusha                     ; remove all port reservations
  2186.  
  2187.     mov   edx,esi
  2188.     shl   edx, 5 ;imul  edx,0x20
  2189.     add   edx,0x3000
  2190.     mov   edx,[edx+4]
  2191.  
  2192.   rmpr0:
  2193.  
  2194.     mov   esi,[0x2d0000]
  2195.  
  2196.     cmp   esi,0
  2197.     je    rmpr9
  2198.  
  2199.   rmpr3:
  2200.  
  2201.     mov   edi,esi
  2202.     shl   edi,4
  2203.     add   edi,0x2d0000
  2204.  
  2205.     cmp   edx,[edi]
  2206.     je    rmpr4
  2207.  
  2208.     dec   esi
  2209.     jnz   rmpr3
  2210.  
  2211.     jmp   rmpr9
  2212.  
  2213.   rmpr4:
  2214.  
  2215.     mov   ecx,256
  2216.     sub   ecx,esi
  2217.     shl   ecx,4
  2218.  
  2219.     mov   esi,edi
  2220.     add   esi,16
  2221.     cld
  2222.     rep   movsb
  2223.  
  2224.     dec   dword [0x2d0000]
  2225.  
  2226.     jmp   rmpr0
  2227.  
  2228.   rmpr9:
  2229.  
  2230.     popa
  2231.     mov  edi,esi         ; do not run this process slot
  2232.     shl  edi, 5 ;imul edi,0x20
  2233. ;    add  edi,0x3000
  2234.     mov  [edi+0x300A],byte 9
  2235. ;    call  systest
  2236.     sti  ; .. and life goes on
  2237.  
  2238. ;    movzx eax,word [dlx]
  2239. ;    movzx ebx,word [dly]
  2240. ;    movzx ecx,word [dlxe]
  2241. ;    movzx edx,word [dlye]
  2242.     call  calculatescreen
  2243.  
  2244.     xor   eax, eax
  2245.     xor   esi, esi
  2246.     call  redrawscreen
  2247.  
  2248.     mov   [0xfff4],byte 0  ; no mouse background
  2249.     mov   [0xfff5],byte 0  ; draw mouse
  2250.  
  2251.     mov   [application_table_status],0
  2252.  
  2253.     mov   esi,process_terminated
  2254.     call  sys_msg_board_str
  2255.  
  2256. ;* start code - fix error redraw for terminate (2) - Mario79
  2257. ;     cmp  [draw_present],1
  2258. ;     je  no_draw_background_temp
  2259. ;     mov   [0xfff0],byte 1
  2260. ;no_draw_background_temp:
  2261. ;    mov   [draw_present],0
  2262.     ret
  2263. ;draw_present db 0
  2264. ;* end code - fix error redraw for terminate (2) - Mario79
  2265.  
  2266. iglobal
  2267.   boot_sched_1    db   'Building gdt tss pointer',0
  2268.   ;boot_sched_2    db   'Building gdt gate pointer',0
  2269.   boot_sched_3    db   'Building interrupt table - TSS',0
  2270.   boot_sched_3_2  db   'Building interrupt table - GDT',0
  2271.   boot_sched_3_3  db   'Building interrupt table - IDT',0
  2272.   boot_sched_4    db   'Building syscall interrupt table',0
  2273. endg
  2274.  
  2275.  
  2276. build_scheduler:
  2277.       ; { Ivan 06.03.2005
  2278.         mov    edi, usedi40
  2279.         mov    ecx, 256/4
  2280.         xor    eax, eax
  2281.         rep    stosd
  2282.       ; } Ivan 06.03.2005
  2283.  
  2284.         mov    esi,boot_sched_1
  2285.         call   boot_log
  2286.         call   build_process_gdt_tss_pointer
  2287.  
  2288. ;        mov    esi,boot_sched_2
  2289. ;        call   boot_log
  2290. ;        call   build_process_gdt_gate_pointer
  2291.  
  2292.         mov    esi,boot_sched_3
  2293.         call   boot_log
  2294.         call   build_interrupt_table
  2295.  
  2296.         mov    esi,boot_sched_4
  2297.         call   boot_log
  2298.         call   build_syscall_interrupt_table
  2299.  
  2300.         ret
  2301.  
  2302.