; Example DLL that returns:
; * 48-char processor name
; * AVX supported or not

format PE GUI 4.0 DLL
entry DllEntryPoint

include 'win32a.inc'

section '.text' code readable executable

proc DllEntryPoint hinstDLL,fdwReason,lpvReserved
        mov     eax,TRUE
        ret
endp

proc GetCpuName
     push    ebx
     mov     eax, 0x80000002
     cpuid
     mov     dword [_name], eax
     mov     dword [_name + 4], ebx
     mov     dword [_name + 8], ecx
     mov     dword [_name + 12], edx
     mov     eax, 0x80000003
     cpuid
     mov     dword [_name + 16], eax
     mov     dword [_name + 20], ebx
     mov     dword [_name + 24], ecx
     mov     dword [_name + 28], edx
     mov     eax, 0x80000004
     cpuid
     mov     dword [_name + 32], eax
     mov     dword [_name + 36], ebx
     mov     dword [_name + 40], ecx
     mov     dword [_name + 44], edx
     mov     eax, _name
     pop     ebx
     ret
endp

proc IsAvxSupported     ;code from Tomasz FASMW example '\EXAMPLES\WIN64\WIN64AVX'
; EAX = 1 = No AVX support
; EAX = 2 = AVX supported
     push ebx
     mov eax,1
     cpuid
     and ecx,18000000h
     cmp ecx,18000000h
     jne no_AVX
     xor ecx,ecx
     xgetbv
     and eax,110b
     cmp eax,110b
     jne no_AVX
     mov eax, 2
     pop ebx
     ret
no_AVX:
     mov eax, 1
     pop ebx
     ret
endp

section '.data' data readable writeable
align 16

_name   rb      48

section '.idata' import data readable writeable

  library kernel,'KERNEL32.DLL'

  import kernel,\
         GetLastError,'GetLastError'

section '.edata' export data readable

  export 'cpuname.DLL',\
         GetCpuName,'GetCpuName',\
         IsAvxSupported, 'IsAvxSupported'

section '.reloc' fixups data readable discardable

  if $=$$
    dd 0,8              ; if there are no fixups, generate dummy entry
  end if
