Subversion Repositories Kolibri OS

Rev

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

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