flat assembler
Message board for the users of flat assembler.
Index
> Windows > CPUID MM Info |
Author |
|
windwakr 29 Sep 2009, 03:16
Works fine for me.
I made something just like this a few months back, but it only tested for all the SSE's. Last edited by windwakr on 29 Sep 2009, 03:17; edited 2 times in total |
|||
29 Sep 2009, 03:16 |
|
revolution 29 Sep 2009, 03:17
It is not enough just to test the CPUID flags for extensions. You also need to check that the OS supports them. A reasonable way to do that is to execute one of the instructions with dummy parameters and catch any exceptions. Indeed by doing the exception catching you can test both the CPU capability and the OS capability at the same time so using the CPUID method becomes redundant.
However, if you do still want to use CPUID then you should also check that the CPU supports it before trying to execute it. Or perhaps instead, just execute it blindly and catch any exception there also. |
|||
29 Sep 2009, 03:17 |
|
windwakr 29 Sep 2009, 03:21
If you want to be sure your code runs good on early 90's computers that OH SO many people use nowadays(right revolution?), then read up on this document.
|
|||
29 Sep 2009, 03:21 |
|
revolution 29 Sep 2009, 03:25
windwakr wrote: If you want to be sure your code runs good on early 90's computers that OH SO many people use nowadays(right revolution?) |
|||
29 Sep 2009, 03:25 |
|
bitshifter 29 Sep 2009, 03:28
windwakr wrote: I made something just like this a few months back... Cool! You sure got your moneys worth out of all those lstrcat's Thanks for the info revolution. I thought all Win32 would be ok? _________________ Coding a 3D game engine with fasm is like trying to eat an elephant, you just have to keep focused and take it one 'byte' at a time. |
|||
29 Sep 2009, 03:28 |
|
revolution 29 Sep 2009, 03:32
bitshifter wrote: I thought all Win32 would be ok? |
|||
29 Sep 2009, 03:32 |
|
revolution 29 Sep 2009, 03:41
Here is a small snippet from some really old code:
Code: macro _try { local .handler,.catch,.finally push .handler push dword[fs:0] mov [fs:0],esp try@finally equ .finally macro _catch \{ jmp .finally .handler: mov eax,pContext mov [eax+CONTEXT.Eip],.catch if EXCEPTION_CONTINUABLE<>0 mov eax,EXCEPTION_CONTINUABLE else xor eax,eax end if ret 16 .catch: mov esp,[fs:0] \} } macro _finally { try@finally: pop dword[fs:0] lea esp,[esp+4] restore try@finally purge _catch } macro _assert_sse_capable_OS exec { _try or eax,-1 exec xmm0,xmm0 _catch xor eax,eax _finally test eax,eax } ;SSE _assert_sse_capable_OS xorps jz .not_support_SSE ;SSE2 _assert_sse_capable_OS xorpd jz .not_support_SSE2 ;SSE3 _assert_sse_capable_OS addsubpd jz .not_support_SSE3 |
|||
29 Sep 2009, 03:41 |
|
rugxulo 29 Sep 2009, 08:56
(blah blah blah, snipped a long semi-useless bunch of boring info)
Code: .global _is_cpuid_supported _is_cpuid_supported: push ebx pushfd # get extended flags pop eax mov ebx,eax # save current flags # xor eax,1 shl CPUID_FLAG xor eax,0x200000 push eax # put new flags on stack popfd # flags updated now in flags pushfd # get extended flags pop eax xor eax,ebx # if bit 21 r/w then supports CPUID mov eax,0 jz _is_cpuid_supported_bye inc eax _is_cpuid_supported_bye: pop ebx ret Code: .global _get_cpu_flags _get_cpu_flags: pushad # save all (better safe than sorry!) xor eax,eax inc eax cpuid xor eax,eax # bt edx,MMX_FLAG # bit 23 bt edx,23 adc eax,0 # if Carry mov al, 1 # bt edx,SSE2_FLAG # bit 26 bt edx,26 adc eax,0 # if Carry, set eax = 2 mov [esp+0x1C],eax # replace soon-popped EAX on stack popad # restore all standard 386 registers ret (suggested by Agner Fog, works for me) Code: _sse_supported: fxsave [xmm_save] mov dword ptr [xmm_save+160],0x45443043 # 'C0DE' fxrstor [xmm_save] mov dword ptr [xmm_save+160],0x44303044 # 'D00D' fxsave [xmm_save] cmp dword ptr [xmm_save+160],0x45443043 # 'C0DE' mov eax,0 jnz _sse_supported_bye inc al # if OSFXSR not turned on, XMM* are not saved _sse_supported_bye: ret EDIT: Oh well, attachment of my conversion of fastpaq2.s (from PAQ7/PAQ8 series) didn't work. You guys probably don't need/want it anyways. |
|||
29 Sep 2009, 08:56 |
|
rugxulo 29 Sep 2009, 09:05
windwakr wrote: If you want to be sure your code runs good on early 90's computers that OH SO many people use nowadays(right revolution?), then read up on this document. Wow, you have a very common name. Last Sunday I also was watching the Family Guy etc. shows on Fox, and immediately after American Dad (whose son's name you share) the news mentioned something with some Corporal (military dude) also named the same thing. Heh. Crazy world. |
|||
29 Sep 2009, 09:05 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.