Subversion Repositories Kolibri OS

Rev

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

  1.  
  2. init_fpu:
  3.            clts
  4.            fninit
  5.  
  6.            bt [cpu_caps], CAPS_SSE
  7.            jnc .no_SSE
  8.  
  9.            stdcall kernel_alloc, 512*256
  10.            mov [fpu_data], eax
  11.  
  12.            mov ebx, cr4
  13.            mov ecx, cr0
  14.            or ebx, CR4_OSFXSR+CR4_OSXMMEXPT
  15.            mov cr4, ebx
  16.  
  17.            and ecx, not (CR0_MP+CR0_EM)
  18.            or ecx, CR0_NE
  19.            mov cr0, ecx
  20.  
  21.            mov dword [esp-4], SSE_INIT
  22.            ldmxcsr [esp-4]
  23.  
  24.            xorps xmm0, xmm0
  25.            xorps xmm1, xmm1
  26.            xorps xmm2, xmm2
  27.            xorps xmm3, xmm3
  28.            xorps xmm4, xmm4
  29.            xorps xmm5, xmm5
  30.            xorps xmm6, xmm6
  31.            xorps xmm7, xmm7
  32.            fxsave [eax]
  33.            ret
  34. .no_SSE:
  35.            stdcall kernel_alloc, 112*256
  36.            mov [fpu_data], eax
  37.            mov ecx, cr0
  38.            and ecx, not CR0_EM
  39.            or ecx, CR0_MP+CR0_NE
  40.            mov cr0, ecx
  41.            fnsave [eax]
  42.            ret
  43.  
  44. align 4
  45. proc fpu_save
  46.            clts
  47.            mov ebx, [fpu_owner]
  48.            shl ebx, 8
  49.            mov eax, [ebx+PROC_BASE+0x10]
  50.            mov ebx, [CURRENT_TASK]
  51.            mov [fpu_owner], ebx
  52.  
  53.            bt [cpu_caps], CAPS_SSE
  54.            jnc .no_SSE
  55.  
  56.            fxsave [eax]
  57.            fninit            ;re-init fpu
  58.            ret
  59. .no_SSE:
  60.            fnsave [eax]
  61.            ret
  62. endp
  63.  
  64. align 4
  65. proc fpu_restore
  66.            mov ebx, [CURRENT_TASK]
  67.            shl ebx, 8
  68.            mov eax, [ebx+PROC_BASE+0x10]
  69.            bt [cpu_caps], CAPS_SSE
  70.            jnc .no_SSE
  71.  
  72.            fxrstor [eax]
  73.            ret
  74. .no_SSE:
  75.            fnclex               ;fix possible problems
  76.            frstor [eax]
  77.            ret
  78. endp
  79.  
  80. align 4
  81. e7:                        ;#NM exception handler
  82.         save_ring3_context
  83.         clts
  84.         mov ax, os_data
  85.         mov ds, ax
  86.         mov es, ax
  87.  
  88.         mov ebx, [fpu_owner]
  89.         cmp ebx, [CURRENT_TASK]
  90.         je .exit
  91.  
  92.         shl ebx, 8
  93.         mov eax, [ebx+PROC_BASE+APPDATA.fpu_state]
  94.         bt [cpu_caps], CAPS_SSE
  95.         jnc .no_SSE
  96.  
  97.         fxsave [eax]
  98.         mov ebx, [CURRENT_TASK]
  99.         mov [fpu_owner], ebx
  100.         shl ebx, 8
  101.         mov eax, [ebx+PROC_BASE+APPDATA.fpu_state]
  102.         fxrstor [eax]
  103. .exit:
  104.         restore_ring3_context
  105.         iret
  106.  
  107. .no_SSE:
  108.         fnsave [eax]
  109.         mov ebx, [CURRENT_TASK]
  110.         mov [fpu_owner], ebx
  111.         shl ebx, 8
  112.         mov eax, [ebx+PROC_BASE+APPDATA.fpu_state]
  113.         frstor [eax]
  114.         restore_ring3_context
  115.         iret
  116.  
  117. iglobal
  118.   fpu_owner dd 1
  119.  endg
  120.  
  121.  
  122.  
  123. reg_eip       equ ebp+4
  124. reg_cs        equ ebp+8
  125. reg_eflags    equ ebp+12
  126. reg_esp       equ ebp+16
  127. reg_ss        equ ebp+20
  128.  
  129. align 4
  130. except_16:           ;fpu native exceptions handler
  131.            push ebp
  132.            mov ebp, esp
  133.  
  134.            push eax
  135.            push ebx
  136.            push ecx
  137.            push edx
  138.  
  139.            mov ebx, [ss:CURRENT_TASK]
  140.            shl ebx, 8
  141.  
  142.            mov eax, [ss:ebx+PROC_BASE+APPDATA.fpu_handler]
  143.            test eax, eax
  144.            jz .default
  145.  
  146.            mov ecx, [reg_eip]
  147.            mov edx, [reg_esp]
  148.            sub edx, 4
  149.            mov [ss:edx+new_app_base], ecx
  150.            mov [reg_esp], edx
  151.            mov dword [reg_eip], eax
  152.  
  153.            pop edx
  154.            pop ecx
  155.            pop ebx
  156.            pop eax
  157.  
  158.            leave
  159.            iretd
  160.  
  161. .default:
  162.            pop edx
  163.            pop ecx
  164.            pop ebx
  165.            pop eax
  166.            leave
  167.  
  168.            save_ring3_context     ;debugger support
  169.  
  170.            mov bl, 16
  171.            jmp exc_c
  172.  
  173. align 4
  174. except_19:          ;sse exceptions handler
  175.            push ebp
  176.            mov ebp, esp
  177.  
  178.            push eax
  179.            push ebx
  180.            push ecx
  181.            push edx
  182.  
  183.            mov ebx, [ss:CURRENT_TASK]
  184.            shl ebx, 8
  185.  
  186.            mov eax, [ss:ebx+PROC_BASE+APPDATA.sse_handler]
  187.            test eax, eax
  188.            jz .default
  189.  
  190.            mov ecx, [reg_eip]
  191.            mov edx, [reg_esp]
  192.            sub edx, 4
  193.            mov [ss:edx+new_app_base], ecx
  194.            mov [reg_esp], edx
  195.            mov dword [reg_eip], eax
  196.  
  197.            pop edx
  198.            pop ecx
  199.            pop ebx
  200.            pop eax
  201.  
  202.            leave
  203.            iretd
  204.  
  205. .default:
  206.            pop edx
  207.            pop ecx
  208.            pop ebx
  209.            pop eax
  210.            leave
  211.  
  212.            save_ring3_context     ;debugger support
  213.  
  214.            mov bl, 19
  215.            jmp exc_c
  216.  
  217. restore reg_eip
  218. restore reg_cs
  219. restore reg_eflags
  220. restore reg_esp
  221. restore reg_ss
  222.  
  223.  
  224.