Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

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