Subversion Repositories Kolibri OS

Rev

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