Subversion Repositories Kolibri OS

Rev

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